tizen 2.3 release tizen_2.3 submit/tizen_2.3/20150202.062421 tizen_2.3_release
authorjk7744.park <jk7744.park@samsung.com>
Sun, 1 Feb 2015 04:42:54 +0000 (13:42 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sun, 1 Feb 2015 04:42:54 +0000 (13:42 +0900)
239 files changed:
AUTHORS
CMakeLists.txt
LICENSE.APLv2 [new file with mode: 0755]
LICENSE.Flora [deleted file]
NOTICE
SLP_MessagingFW_PG.h [deleted file]
config/alert_on_call.mp3 [deleted file]
config/message_tone/Sherbet.wav [deleted file]
config/msg-service-db.sql [new file with mode: 0755]
config/sysinfo-message.xml [moved from sysinfo-message.xml with 57% similarity]
doc/msg_service_doc.h [new file with mode: 0644]
externals/CMakeLists.txt [new file with mode: 0755]
externals/MsgAlarm.cpp [new file with mode: 0755]
externals/MsgDevicedWrapper.cpp [new file with mode: 0644]
externals/MsgLbs.cpp [new file with mode: 0755]
externals/MsgNotificationWrapper.cpp [new file with mode: 0755]
externals/MsgSensorWrapper.cpp [moved from msg_helper/MsgSensorWrapper.cpp with 69% similarity]
externals/MsgSoundPlayer.cpp [new file with mode: 0755]
externals/MsgSpamFilter.cpp [moved from utils/MsgSpamFilter.cpp with 56% similarity]
framework/CMakeLists.txt
framework/deliver-handler/MsgDeliverHandler.cpp
framework/main.cpp
framework/plugin-manager/MsgPluginConfig.cpp
framework/plugin-manager/MsgPluginManager.cpp
framework/setting-handler/MsgSettingHandler.cpp
framework/storage-handler/MsgStorageFilter.cpp
framework/storage-handler/MsgStorageFolder.cpp
framework/storage-handler/MsgStorageManager.cpp
framework/storage-handler/MsgStorageMessage.cpp
framework/storage-handler/MsgStorageMms.cpp
framework/storage-handler/MsgStorageSim.cpp
framework/storage-handler/MsgStorageUtil.cpp
framework/submit-handler/MsgSubmitHandler.cpp
framework/transaction-manager/MsgCmdHandlerFilter.cpp
framework/transaction-manager/MsgCmdHandlerSetting.cpp
framework/transaction-manager/MsgCmdHandlerStorage.cpp
framework/transaction-manager/MsgCmdHandlerTransport.cpp
framework/transaction-manager/MsgTransManager.cpp
image/messaging_image001.png [deleted file]
include/common/MsgCmdTypes.h
include/common/MsgCppTypes.h
include/common/MsgFilterTypes.h
include/common/MsgInternalTypes.h
include/common/MsgMmsTypes.h
include/common/MsgPluginInterface.h
include/common/MsgQueue.h
include/common/MsgSettingTypes.h
include/common/MsgSmil.h [new file with mode: 0755]
include/common/MsgStorageTypes.h
include/common/MsgThread.h
include/common/MsgTransportTypes.h
include/common/MsgTypes.h
include/externals/MsgAlarm.h [new file with mode: 0755]
include/externals/MsgDevicedWrapper.h [new file with mode: 0644]
include/externals/MsgLbs.h [new file with mode: 0755]
include/externals/MsgNotificationWrapper.h [new file with mode: 0755]
include/externals/MsgSensorWrapper.h [new file with mode: 0755]
include/externals/MsgSoundPlayer.h [new file with mode: 0755]
include/externals/MsgSpamFilter.h [moved from include/utils/MsgSpamFilter.h with 56% similarity]
include/framework/MsgCmdHandler.h
include/framework/MsgDeliverHandler.h
include/framework/MsgPluginConfig.h
include/framework/MsgPluginManager.h
include/framework/MsgSettingHandler.h
include/framework/MsgStorageHandler.h
include/framework/MsgSubmitHandler.h
include/framework/MsgTransManager.h
include/mapi/msg.h
include/mapi/msg_private.h
include/mapi/msg_storage.h
include/mapi/msg_storage_types.h
include/mapi/msg_transport.h
include/mapi/msg_transport_types.h
include/mapi/msg_types.h
include/msg_helper/MsgHelper.h [deleted file]
include/proxy/MsgHandle.h
include/proxy/MsgProxyListener.h
include/utils/MsgContact.h
include/utils/MsgDebug.h
include/utils/MsgDrmWrapper.h
include/utils/MsgException.h
include/utils/MsgGconfWrapper.h
include/utils/MsgIpcSocket.h
include/utils/MsgJsonParser.h [new file with mode: 0755]
include/utils/MsgMemory.h
include/utils/MsgMmsMessage.h
include/utils/MsgMutex.h
include/utils/MsgNotificationWrapper.h [deleted file]
include/utils/MsgSerialize.h [new file with mode: 0755]
include/utils/MsgSoundPlayer.h [deleted file]
include/utils/MsgSqliteWrapper.h
include/utils/MsgTextConvert.h
include/utils/MsgUtilFile.h
include/utils/MsgUtilFunction.h
include/utils/MsgUtilStorage.h
include/utils/MsgVMessage.h
mapi/CMakeLists.txt
mapi/msg_control.cpp
mapi/msg_filter.cpp
mapi/msg_message.cpp
mapi/msg_mms.cpp
mapi/msg_setting.cpp
mapi/msg_storage.cpp
mapi/msg_svc.cpp
mapi/msg_transport.cpp
msg-server [new file with mode: 0755]
msg-service-tools.manifest
msg-service.manifest
msg-service.pc.in
msg-service.rule [changed mode: 0644->0755]
msg_helper/CMakeLists.txt [deleted file]
msg_helper/MsgSoundPlayer.cpp [deleted file]
msg_helper/main.cpp [deleted file]
packaging/msg-server.service [new file with mode: 0755]
packaging/msg-service.service [deleted file]
packaging/msg-service.spec [changed mode: 0644->0755]
plugin/mms_plugin/CMakeLists.txt
plugin/mms_plugin/MmsPluginAppBase.cpp [new file with mode: 0755]
plugin/mms_plugin/MmsPluginAvCodec.cpp [deleted file]
plugin/mms_plugin/MmsPluginCodecCommon.cpp
plugin/mms_plugin/MmsPluginComposer.cpp [new file with mode: 0755]
plugin/mms_plugin/MmsPluginConnManWrapper.cpp
plugin/mms_plugin/MmsPluginDecode.cpp
plugin/mms_plugin/MmsPluginDrm.cpp
plugin/mms_plugin/MmsPluginEncode.cpp
plugin/mms_plugin/MmsPluginEventHandler.cpp
plugin/mms_plugin/MmsPluginHttp.cpp
plugin/mms_plugin/MmsPluginInternal.cpp
plugin/mms_plugin/MmsPluginMIME.cpp
plugin/mms_plugin/MmsPluginMain.cpp
plugin/mms_plugin/MmsPluginMessage.cpp
plugin/mms_plugin/MmsPluginSMILValidate.cpp
plugin/mms_plugin/MmsPluginSmil.cpp [deleted file]
plugin/mms_plugin/MmsPluginStorage.cpp
plugin/mms_plugin/MmsPluginTcs.cpp [new file with mode: 0755]
plugin/mms_plugin/MmsPluginTextConvert.cpp
plugin/mms_plugin/MmsPluginTransport.cpp
plugin/mms_plugin/MmsPluginUserAgent.cpp
plugin/mms_plugin/MmsPluginUtil.cpp
plugin/mms_plugin/include/MmsPluginAppBase.h [new file with mode: 0755]
plugin/mms_plugin/include/MmsPluginAvCodec.h [deleted file]
plugin/mms_plugin/include/MmsPluginCodec.h
plugin/mms_plugin/include/MmsPluginCodecCommon.h
plugin/mms_plugin/include/MmsPluginCodecTypes.h
plugin/mms_plugin/include/MmsPluginComposer.h [new file with mode: 0755]
plugin/mms_plugin/include/MmsPluginConnManWrapper.h
plugin/mms_plugin/include/MmsPluginDebug.h
plugin/mms_plugin/include/MmsPluginDecode.h
plugin/mms_plugin/include/MmsPluginDrm.h
plugin/mms_plugin/include/MmsPluginEncode.h
plugin/mms_plugin/include/MmsPluginEventHandler.h
plugin/mms_plugin/include/MmsPluginHttp.h
plugin/mms_plugin/include/MmsPluginInternal.h
plugin/mms_plugin/include/MmsPluginMIME.h
plugin/mms_plugin/include/MmsPluginMain.h
plugin/mms_plugin/include/MmsPluginMessage.h
plugin/mms_plugin/include/MmsPluginSMILValidate.h [deleted file]
plugin/mms_plugin/include/MmsPluginSmil.h [deleted file]
plugin/mms_plugin/include/MmsPluginStorage.h
plugin/mms_plugin/include/MmsPluginTcs.h [new file with mode: 0755]
plugin/mms_plugin/include/MmsPluginTextConvert.h
plugin/mms_plugin/include/MmsPluginTransport.h
plugin/mms_plugin/include/MmsPluginTypes.h
plugin/mms_plugin/include/MmsPluginUserAgent.h
plugin/mms_plugin/include/MmsPluginUtil.h
plugin/sms_plugin/CMakeLists.txt
plugin/sms_plugin/SmsPluginCallback.cpp
plugin/sms_plugin/SmsPluginCbMsgHandler.cpp
plugin/sms_plugin/SmsPluginConcatHandler.cpp
plugin/sms_plugin/SmsPluginDSHandler.cpp [new file with mode: 0755]
plugin/sms_plugin/SmsPluginEventHandler.cpp
plugin/sms_plugin/SmsPluginMain.cpp
plugin/sms_plugin/SmsPluginParamCodec.cpp
plugin/sms_plugin/SmsPluginSatHandler.cpp
plugin/sms_plugin/SmsPluginSetting.cpp
plugin/sms_plugin/SmsPluginSimMsg.cpp
plugin/sms_plugin/SmsPluginStorage.cpp
plugin/sms_plugin/SmsPluginTpduCodec.cpp
plugin/sms_plugin/SmsPluginTransport.cpp
plugin/sms_plugin/SmsPluginUAManager.cpp
plugin/sms_plugin/SmsPluginUDCodec.cpp
plugin/sms_plugin/SmsPluginWapPushHandler.cpp
plugin/sms_plugin/include/SmsPluginCallback.h
plugin/sms_plugin/include/SmsPluginCbMsgHandler.h
plugin/sms_plugin/include/SmsPluginConcatHandler.h
plugin/sms_plugin/include/SmsPluginDSHandler.h [new file with mode: 0755]
plugin/sms_plugin/include/SmsPluginEventHandler.h
plugin/sms_plugin/include/SmsPluginMain.h
plugin/sms_plugin/include/SmsPluginParamCodec.h
plugin/sms_plugin/include/SmsPluginSatHandler.h
plugin/sms_plugin/include/SmsPluginSetting.h
plugin/sms_plugin/include/SmsPluginSimMsg.h
plugin/sms_plugin/include/SmsPluginStorage.h
plugin/sms_plugin/include/SmsPluginTpduCodec.h
plugin/sms_plugin/include/SmsPluginTransport.h
plugin/sms_plugin/include/SmsPluginTypes.h
plugin/sms_plugin/include/SmsPluginUAManager.h
plugin/sms_plugin/include/SmsPluginUDCodec.h
plugin/sms_plugin/include/SmsPluginWapPushHandler.h
proxy/CMakeLists.txt
proxy/MsgHandleControl.cpp
proxy/MsgHandleFilter.cpp
proxy/MsgHandleSetting.cpp
proxy/MsgHandleStorage.cpp
proxy/MsgHandleTransport.cpp
proxy/MsgProxyListener.cpp
sysinfo-message.emul.xml [deleted file]
utils/CMakeLists.txt
utils/MsgContact.cpp
utils/MsgDebug.cpp
utils/MsgDrmWrapper.cpp
utils/MsgException.cpp
utils/MsgGconfWrapper.cpp
utils/MsgIpcSocket.cpp
utils/MsgJsonParser.cpp [new file with mode: 0755]
utils/MsgMemory.cpp
utils/MsgMmsMessage.cpp
utils/MsgMutex.cpp
utils/MsgNotificationWrapper.cpp [deleted file]
utils/MsgSerialize.cpp [new file with mode: 0755]
utils/MsgSmil.cpp [new file with mode: 0755]
utils/MsgSoundPlayer.cpp [deleted file]
utils/MsgSqliteWrapper.cpp
utils/MsgTextConvert.cpp
utils/MsgUtilFile.cpp
utils/MsgUtilFunction.cpp
utils/MsgUtilStorage.cpp
utils/MsgVMessage.cpp
vobject-engine/CMakeLists.txt
vobject-engine/VCard.c
vobject-engine/VCardCalUtil.c
vobject-engine/VMessage.c
vobject-engine/include/VCard.h
vobject-engine/include/VMessage.h
vobject-engine/include/VTypes.h
vobject-engine/include/vobject.h
vobject-engine/test_code/CQ_VCARD.c [deleted file]
vobject-engine/test_code/uts_vdata_vcard_decode.c [deleted file]
vobject-engine/test_code/uts_vdata_vcard_encode.c [deleted file]

diff --git a/AUTHORS b/AUTHORS
index fd16fcc..2ebd567 100755 (executable)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,4 +1,4 @@
-Chang-Seok Oh <seok.oh@samsung.com>\r
-Sangkoo Kim <sangkoo.kim@samsung.com>\r
-Seunghwan Lee <sh.cat.lee@samsung.com>\r
-KeeBum Kim <keebum.kim@samsung.com>
\ No newline at end of file
+Sanghun Chung <sanghun.chung@samsung.com>
+Sangkoo Kim <sangkoo.kim@samsung.com>
+
+
index 774f421..3ee8af5 100755 (executable)
@@ -1,9 +1,11 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 ##########################################################
 # Set Variables
 ##########################################################
 SET(VOBJECT-LIB msg_vobject)
 SET(UTILS-LIB msg_utils)
+SET(EXTERNALS-LIB msg_externals)
 SET(PLUGIN-MANAGER-LIB msg_plugin_manager)
 SET(FW-HANDLER-LIB msg_framework_handler)
 SET(TRANS-MANAGER-LIB msg_transaction_manager)
@@ -12,19 +14,20 @@ SET(MAPI-LIB msg_mapi)
 SET(SMS-PLUGIN-LIB msg_sms_plugin)
 SET(MMS-PLUGIN-LIB msg_mms_plugin)
 
+ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
+ADD_DEFINITIONS("-DMSG_PENDING_PUSH_MESSAGE")
 
 ##########################################################
 # Add Subdirectories
 ##########################################################
 ADD_SUBDIRECTORY(vobject-engine)
 ADD_SUBDIRECTORY(utils)
+ADD_SUBDIRECTORY(externals)
 ADD_SUBDIRECTORY(framework)
 ADD_SUBDIRECTORY(proxy)
 ADD_SUBDIRECTORY(mapi)
 ADD_SUBDIRECTORY(plugin/sms_plugin)
 ADD_SUBDIRECTORY(plugin/mms_plugin)
-ADD_SUBDIRECTORY(msg_helper)
-
 
 ##########################################################
 # Install Header Files
@@ -36,7 +39,7 @@ SET(MAPI-HEADERS
        ${CMAKE_CURRENT_SOURCE_DIR}/include/mapi/msg_storage_types.h
        ${CMAKE_CURRENT_SOURCE_DIR}/include/mapi/msg_transport.h
        ${CMAKE_CURRENT_SOURCE_DIR}/include/mapi/msg_transport_types.h
-       ${CMAKE_CURRENT_SOURCE_DIR}/SLP_MessagingFW_PG.h )
+       )
 INSTALL(FILES ${MAPI-HEADERS} DESTINATION include/msg-service)
 
 
@@ -46,23 +49,21 @@ INSTALL(FILES ${MAPI-HEADERS} DESTINATION include/msg-service)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config/plugin.cfg DESTINATION /usr/share/msg-service)
 
-SET(RINGTONE-FILES
-       ${CMAKE_CURRENT_SOURCE_DIR}/config/message_tone/Sherbet.wav
-)
-
-INSTALL(FILES ${RINGTONE-FILES} DESTINATION /usr/share/media/)
+#INSTALL(FILES ${MMS-FILES} DESTINATION /opt/etc/msg-service)
 
 CONFIGURE_FILE(msg-service.pc.in msg-service.pc @ONLY)
-INSTALL(FILES ${CMAKE_BINARY_DIR}/msg-service.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/msg-service.pc DESTINATION lib/pkgconfig)
 
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/msg-service.service DESTINATION /usr/lib/systemd/system)
+SET(RC_LOCAL_SCRIPT msg-server)
+INSTALL(PROGRAMS ${RC_LOCAL_SCRIPT} DESTINATION /etc/rc.d/init.d)
 
-# LICENSE file
-#INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE.Flora DESTINATION /usr/share/license/msg-service)
+# systemd
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/msg-server.service DESTINATION /usr/lib/systemd/system)
 
-# SMACK rule file
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/msg-service.rule DESTINATION /opt/etc/smack/accesses.d/)
+# LICENSE file
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE.APLv2 DESTINATION /usr/share/license/msg-service)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/msg-service.rule DESTINATION /etc/smack/accesses.d/)
 
 #Install sysinfo file to provide which features are supported.
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/sysinfo-message.xml DESTINATION /etc/config)
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/sysinfo-message.emul.xml DESTINATION /etc/config)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/config/msg-service-db.sql DESTINATION /usr/share/msg-service RENAME msg-service-db.sql)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/config/sysinfo-message.xml DESTINATION /etc/config)
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100755 (executable)
index 0000000..74f474e
--- /dev/null
@@ -0,0 +1,203 @@
+Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/LICENSE.Flora b/LICENSE.Flora
deleted file mode 100755 (executable)
index 03f0c77..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-Flora License
-
-Version 1.1, April, 2013
-
-http://floralicense.org/license/
-
-TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-1. Definitions.
-
-"License" shall mean the terms and conditions for use, reproduction,
-and distribution as defined by Sections 1 through 9 of this document.
-
-"Licensor" shall mean the copyright owner or entity authorized by
-the copyright owner that is granting the License.
-
-"Legal Entity" shall mean the union of the acting entity and
-all other entities that control, are controlled by, or are
-under common control with that entity. For the purposes of
-this definition, "control" means (i) the power, direct or indirect,
-to cause the direction or management of such entity,
-whether by contract or otherwise, or (ii) ownership of fifty percent (50%)
-or more of the outstanding shares, or (iii) beneficial ownership of
-such entity.
-
-"You" (or "Your") shall mean an individual or Legal Entity
-exercising permissions granted by this License.
-
-"Source" form shall mean the preferred form for making modifications,
-including but not limited to software source code, documentation source,
-and configuration files.
-
-"Object" form shall mean any form resulting from mechanical
-transformation or translation of a Source form, including but
-not limited to compiled object code, generated documentation,
-and conversions to other media types.
-
-"Work" shall mean the work of authorship, whether in Source or Object form,
-made available under the License, as indicated by a copyright notice
-that is included in or attached to the work (an example is provided
-in the Appendix below).
-
-"Derivative Works" shall mean any work, whether in Source or Object form,
-that is based on (or derived from) the Work and for which the editorial
-revisions, annotations, elaborations, or other modifications represent,
-as a whole, an original work of authorship. For the purposes of this License,
-Derivative Works shall not include works that remain separable from,
-or merely link (or bind by name) to the interfaces of, the Work and
-Derivative Works thereof.
-
-"Contribution" shall mean any work of authorship, including the original
-version of the Work and any modifications or additions to that Work or
-Derivative Works thereof, that is intentionally submitted to Licensor
-for inclusion in the Work by the copyright owner or by an individual or
-Legal Entity authorized to submit on behalf of the copyright owner.
-For the purposes of this definition, "submitted" means any form of
-electronic, verbal, or written communication sent to the Licensor or
-its representatives, including but not limited to communication on
-electronic mailing lists, source code control systems, and issue
-tracking systems that are managed by, or on behalf of, the Licensor
-for the purpose of discussing and improving the Work, but excluding
-communication that is conspicuously marked or otherwise designated
-in writing by the copyright owner as "Not a Contribution."
-
-"Contributor" shall mean Licensor and any individual or Legal Entity
-on behalf of whom a Contribution has been received by Licensor and
-subsequently incorporated within the Work.
-
-"Tizen Certified Platform" shall mean a software platform that complies
-with the standards set forth in the Tizen Compliance Specification
-and passes the Tizen Compliance Tests as defined from time to time
-by the Tizen Technical Steering Group and certified by the Tizen
-Association or its designated agent.
-
-2. Grant of Copyright License.  Subject to the terms and conditions of
-this License, each Contributor hereby grants to You a perpetual,
-worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-copyright license to reproduce, prepare Derivative Works of,
-publicly display, publicly perform, sublicense, and distribute the
-Work and such Derivative Works in Source or Object form.
-
-3. Grant of Patent License.  Subject to the terms and conditions of
-this License, each Contributor hereby grants to You a perpetual,
-worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-(except as stated in this section) patent license to make, have made,
-use, offer to sell, sell, import, and otherwise transfer the Work
-solely as incorporated into a Tizen Certified Platform, where such
-license applies only to those patent claims licensable by such
-Contributor that are necessarily infringed by their Contribution(s)
-alone or by combination of their Contribution(s) with the Work solely
-as incorporated into a Tizen Certified Platform to which such
-Contribution(s) was submitted. If You institute patent litigation
-against any entity (including a cross-claim or counterclaim
-in a lawsuit) alleging that the Work or a Contribution incorporated
-within the Work constitutes direct or contributory patent infringement,
-then any patent licenses granted to You under this License for that
-Work shall terminate as of the date such litigation is filed.
-
-4. Redistribution.  You may reproduce and distribute copies of the
-Work or Derivative Works thereof pursuant to the copyright license
-above, in any medium, with or without modifications, and in Source or
-Object form, provided that You meet the following conditions:
-
-  1. You must give any other recipients of the Work or Derivative Works
-     a copy of this License; and
-  2. You must cause any modified files to carry prominent notices stating
-     that You changed the files; and
-  3. You must retain, in the Source form of any Derivative Works that
-     You distribute, all copyright, patent, trademark, and attribution
-     notices from the Source form of the Work, excluding those notices
-     that do not pertain to any part of the Derivative Works; and
-  4. If the Work includes a "NOTICE" text file as part of its distribution,
-     then any Derivative Works that You distribute must include a readable
-     copy of the attribution notices contained within such NOTICE file,
-     excluding those notices that do not pertain to any part of
-     the Derivative Works, in at least one of the following places:
-     within a NOTICE text file distributed as part of the Derivative Works;
-     within the Source form or documentation, if provided along with the
-     Derivative Works; or, within a display generated by the Derivative Works,
-     if and wherever such third-party notices normally appear.
-     The contents of the NOTICE file are for informational purposes only
-     and do not modify the License.
-
-You may add Your own attribution notices within Derivative Works
-that You distribute, alongside or as an addendum to the NOTICE text
-from the Work, provided that such additional attribution notices
-cannot be construed as modifying the License. You may add Your own
-copyright statement to Your modifications and may provide additional or
-different license terms and conditions for use, reproduction, or
-distribution of Your modifications, or for any such Derivative Works
-as a whole, provided Your use, reproduction, and distribution of
-the Work otherwise complies with the conditions stated in this License.
-
-5. Submission of Contributions. Unless You explicitly state otherwise,
-any Contribution intentionally submitted for inclusion in the Work
-by You to the Licensor shall be under the terms and conditions of
-this License, without any additional terms or conditions.
-Notwithstanding the above, nothing herein shall supersede or modify
-the terms of any separate license agreement you may have executed
-with Licensor regarding such Contributions.
-
-6. Trademarks.  This License does not grant permission to use the trade
-names, trademarks, service marks, or product names of the Licensor,
-except as required for reasonable and customary use in describing the
-origin of the Work and reproducing the content of the NOTICE file.
-
-7. Disclaimer of Warranty. Unless required by applicable law or
-agreed to in writing, Licensor provides the Work (and each
-Contributor provides its Contributions) on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-implied, including, without limitation, any warranties or conditions
-of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-PARTICULAR PURPOSE. You are solely responsible for determining the
-appropriateness of using or redistributing the Work and assume any
-risks associated with Your exercise of permissions under this License.
-
-8. Limitation of Liability. In no event and under no legal theory,
-whether in tort (including negligence), contract, or otherwise,
-unless required by applicable law (such as deliberate and grossly
-negligent acts) or agreed to in writing, shall any Contributor be
-liable to You for damages, including any direct, indirect, special,
-incidental, or consequential damages of any character arising as a
-result of this License or out of the use or inability to use the
-Work (including but not limited to damages for loss of goodwill,
-work stoppage, computer failure or malfunction, or any and all
-other commercial damages or losses), even if such Contributor
-has been advised of the possibility of such damages.
-
-9. Accepting Warranty or Additional Liability. While redistributing
-the Work or Derivative Works thereof, You may choose to offer,
-and charge a fee for, acceptance of support, warranty, indemnity,
-or other liability obligations and/or rights consistent with this
-License. However, in accepting such obligations, You may act only
-on Your own behalf and on Your sole responsibility, not on behalf
-of any other Contributor, and only if You agree to indemnify,
-defend, and hold each Contributor harmless for any liability
-incurred by, or claims asserted against, such Contributor by reason
-of your accepting any such warranty or additional liability.
-
-END OF TERMS AND CONDITIONS
-
-APPENDIX: How to apply the Flora License to your work
-
-To apply the Flora License to your work, attach the following
-boilerplate notice, with the fields enclosed by brackets "[]"
-replaced with your own identifying information. (Don't include
-the brackets!) The text should be enclosed in the appropriate
-comment syntax for the file format. We also recommend that a
-file or class name and description of purpose be included on the
-same "printed page" as the copyright notice for easier
-identification within third-party archives.
-
-   Copyright [yyyy] [name of copyright owner]
-
-   Licensed under the Flora License, Version 1.1 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://floralicense.org/license/
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
diff --git a/NOTICE b/NOTICE
index 092bc04..a718085 100755 (executable)
--- a/NOTICE
+++ b/NOTICE
@@ -1,4 +1,3 @@
-Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
-Except as noted, this software is licensed under Flora License, Version 1.1
-Please, see the LICENSE.Flora file for Flora License, Version 1.1 terms and conditions.
-
+Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License, Version 2 terms and conditions.
diff --git a/SLP_MessagingFW_PG.h b/SLP_MessagingFW_PG.h
deleted file mode 100755 (executable)
index ecff3d7..0000000
+++ /dev/null
@@ -1,869 +0,0 @@
-/**
- *
- * @ingroup   SLP_PG
- * @defgroup   MESSAGE MessagingFW
-@{
-<h1 class="pg">Introduction</h1>
-       <h2 class="pg">Purpose</h2>
-The purpose of this document is to describe how applications can use the Messaging Framework APIs to send and receive SMS and MMS messages. This document gives programming guidelines to application engineers.
-
-       <h2 class="pg">Scope</h2>
-The scope of this document is limited to Messaging Framework APIs usage.
-
-       <h2 class="pg">Abbreviations</h2>
-<table>
-<tr><td>API</td><td>Application Programming Interface</td></tr>
-</table>
-@}
-
-@defgroup Message_Architecture 1.Archtecture
-@ingroup MESSAGE
-@{
-<h1>Messaging Framework Architecture</h1>
-The Messaging framework supports various messaging services such as SMS, MMS, Cell Broadcast, WAP Push, and Provisioning message. The Messaging framework architecture consists of a Messaging daemon and a library. The messaging library works on application process and provides various APIs to support transport, control, storage, filter and setting services for application. The messaging daemon has three components (transaction manager, transaction handler, and plug-in manager) to provide message services. The socket IPC is used to communicate (request & event) between Messaging daemon and library.
-@image html messaging_image001.png
-
-- Transaction Manager
-       - Receive the IPC message (request) on socket.
-       - Manage list of pairs (request ID, transaction proxy) for synchronous return.
-       - Determine the transaction flow based on request/event information. (Mapping the request to one of the handlers)
-       - Store the transaction information for asynchronous events (Find which transaction proxy want to receive SMS)
-- Transaction Handler
-       - Submit handler deals with submit requests.
-       - Deliver handler deals with the incoming message from plug-ins.
-       - Storage handler deals with the messages, accounts and folder requests
-       - Filter handler deals with the filter requests
-       - Setting handler deals with the service-specific attributes
-- Plug-in Manager
-       - Initialize all plug-ins after loading plug-in configuration files
-       - Holding the list of plug-ins and the state of plug-ins
-       - Providing the interface between handlers and plug-ins
-- Transaction Handlers
-       - Initialize all plug-ins after loading plug-in configuration files
-       - Receiving IPC messages from messaging daemon.
-       - Handling synchronous calls
-               - Condition variable is used for waiting the return from msg. server)
-       - Handling asynchronous calls or events
-               - Proxy listener is a component of transaction proxy
-               - Proxy listener is waiting for the event
-               - Invoking callback function in the msg. handle list
-               - i.e. calling incoming callback function of MSG APP handle, when incoming msg
-       - Holding list of message handles
-               - Message handle is created by MsgOpenMsgHandle(msgHandle)
-               - Message handle holds some info such as callback func
-- Message API
-       - Transport & control API
-       - Storage API
-       - Filter API
-       - Setting API
-@}
-
-@defgroup Message_Feature 2.Feature
-@ingroup MESSAGE
-@{
-       <h2 class="pg">Messaging Framework Features</h2>
--# Message Control Features:
-       -# Open/Close message handle
--# Message Transport Features:
-       -# Submit request to send, forward, reply, retrieve message.
-       -# Register callback functions to listen to invoked events from messaging daemon. (message status callback, incoming message callback)
--# Message Storage Features:
-       -# Add / Update / Move / Delete / Count / Get message or message list.
-       -# Add / Update / Delete / Get folder or folder list.
--# Message Filter Features:
-       -# Add / Update / Delete filter or filter list.
--# Message Setting Features:
-       -# Set / Get various message setting (i.e. whether to send read/delivery report or not)
-@}
-
-@defgroup MESSAGE_USECASES_1 Initialize/Finalization
-@ingroup MESSAGE_USECASES
-@{
-       <h2 class="pg">Messaging Framework Functions</h2>
-
-               <h3 class="pg">Initialization / Finalization to use Messaging Service </h3>
-- int msg_open_msg_handle(MSG_HANDLE_T *handle);
-@n msg_open_msg_handle() should be called before using the messaging service. This function opens a channel between the application and the messaging framework.
-- int msg_close_msg_handle(MSG_HANDLE_T *handle);
-@n msg_close_msg_handle() should be called after using the messaging service. This function closes a channel between the application and the messaging framework.
-- int msg_reg_sent_status_callback(MSG_HANDLE_T handle, msg_sent_status_cb cb);
-@n Application should implement a msg_sent_status_cb function and register it into message handle. If the application sends a message, this callback function will be called to report its sending status. msg_reg_set_status_callback function should be called after creation of message handle.
-- int msg_reg_sms_message_callback(MSG_HANDLE_T handle, msg_sms_incoming_cb cb, unsigned short port);
-@n Application should implement a msg_sms_incoming_cb function and register it into message handle. It’s used to listen to the SMS incoming event invoked by messaging daemon. The incoming message information structure (MSG_MESSAGE_S) can be delivered as a parameter of the callback function.
-- int msg_reg_mms_conf_message_callback(MSG_HANDLE_T handle, msg_mms_conf_msg_incoming_cb cb, char *app_id);
-@n Application should implement a msg_mms_conf_msg_incoming_cb function and register it into message handle. It’s used to listen to the MMS incoming event invoked by messaging daemon. The incoming message information structure (MSG_MESSAGE_S) can be delivered as a parameter of the callback function.
-@code
-#include <stdio.h>
-#include <glib.h>
-#include <MapiControl.h>
-#include <MapiTransport.h>
-
-void sentStatusCB(MSG_HANDLE_T hMsgHandle, MSG_SENT_STATUS_S *pMsgStatus, void *user_param)
-{
-       // Application can handle message sent status event
-}
-
-void incomingSmsMessageCB (MSG_HANDLE_T hMsgHandle, msg_message_t msg, void *user_param)
-{
-       // Application can handle SMS incoming message.
-}
-
-void incomingMmsConfMessageCB(MSG_HANDLE_T hMsgHandle, msg_message_t msg, void *user_param)
-{
-       // Application can handle MMS incoming message.
-}
-
-int main(void)
-{
-       MSG_HANDLE_T msgHandle = NULL;
-
-       err = msg_open_msg_handle(&msgHandle);
-
-       if (err != MSG_SUCCESS)
-       {
-               printf("msg_open_msg_handle() Fail [%d]", err);
-               return err;
-       }
-
-       // Register sent status handler
-       err = msg_reg_sent_status_callback(msgHandle, &sentStatusCB, NULL);
-
-       if (err != MSG_SUCCESS)
-       {
-               printf("msg_reg_sent_status_callback() Fail [%d]", err);
-               return err;
-       }
-
-       // Register SMS incoming message handler
-       err = msg_reg_sms_message_callback(msgHandle, &incomingSmsMessageCB, 0, NULL);
-
-       if (err != MSG_SUCCESS)
-       {
-               printf("msg_reg_sms_message_callback() Fail [%d]", err);
-               return err;
-       }
-
-       // Register MMS incoming message handler
-       err = msg_reg_mms_conf_message_callback(msgHandle, &incomingMmsConfMessageCB, NULL, NULL);
-
-       if (err != MSG_SUCCESS)
-       {
-               printf("msg_reg_mms_conf_message_callback() Fail [%d]", err);
-               return err;
-       }
-
-       // g_main_loop should be used to listen CB event from messaging daemon
-       mainloop = g_main_loop_new(NULL, FALSE);
-       g_main_loop_run(mainloop);
-
-       msg_close_msg_handle(&msgHandle);
-
-       return err;
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_2 Adding a SMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Adding a SMS Message</h3>
-- msg_message_t msg_new_message();
-@n msg_new_message() is a function to create a message object which can store the message information. You should call this function to set the message that you want to add or send.
-- int msg_set_message_type(msg_message_t msg, MSG_MESSAGE_TYPE_T msg_type);
-@n msg_set_message_type() is a function to set the message type such as SMS or MMS. The first parameter is the message object which is created by msg_new_message(). The second parameter is the message type you want to set. It should be one of enum type ( _MSG_MESSAGE_TYPE_E). If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-- int msg_sms_set_message_body(msg_message_t msg, const char* mdata, int size);
-@n msg_sms_set_message_body() is a function to set the SMS body data. The first parameter is the message object which is created by msg_new_message(). The second parameter is the SMS body data you want to set. The third parameter is the length of SMS body data. If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-- int msg_add_address(msg_message_t msg, const char* phone_num_list, MSG_RECIPIENT_TYPE_T to_type);
-@n msg_add_address() is a function to add the phone numbers for the message. The first parameter is the message object which is created by msg_new_message(). The second parameter is the list of phone number you want to set. You can add several phone numbers at once. The phone numbers should be separated by ','. The third parameter is the recipient type of phone number. It should be one of enum type (_MSG_RECIPIENT_TYPE_E). If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-- int msg_add_message(MSG_HANDLE_T handle, const msg_message_t msg, const MSG_SENDINGOPT_S *send_opt);
-@n msg_add_message() is a function to add a composed message into the database of messaging framework. Before calling this function, the application should set the message object and the sending option structure and then pass them as parameters. If you don't want to change the current sending option, set the variable 'bSetting' to false. If saving a message is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-- int msg_release_message(msg_message_t *msg);
-@n msg_release_message() is a function to free the memory of a message object which is create by msg_new_message(). If freeing the memory is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-@code
-#include <string.h>
-#include <MapiStorage.h>
-#include <MapiMessage.h>
-
-void test_add_sms_message(MSG_HANDLE_T hMsgHandle)
-{
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       MSG_SENDINGOPT_S sendOpt = {0, };
-       sendOpt.bSetting = false;
-
-       msg_message_t msgInfo = msg_new_message();
-
-       // Set Message Type
-       err = msg_set_message_type(msgInfo, MSG_TYPE_SMS);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       char msgText[1024];
-
-       memset(msgText, 0x00, 1024);
-       strncpy(msgText, "Test SMS Message", sizeof(msgText)-1);
-       int dataSize = strlen(msgText);
-
-       // Set SMS text
-       err = msg_sms_set_message_body(msgInfo, msgText, dataSize);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       char number[MAX_ADDRESS_VAL_LEN];
-
-       memset(number, 0x00, MAX_ADDRESS_VAL_LEN);
-       strncpy(number, "+821030011234", sizeof(number)-1);
-
-       // Set Recipient Address
-       err = msg_add_address(msgInfo, number, MSG_RECIPIENTS_TYPE_TO);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       err = msg_add_message(hMsgHandle, msgInfo, &sendOpt);
-
-       if (err == MSG_SUCCESS)
-               printf("Saving Message is OK!");
-       else
-               printf("Saving Message is failed!");
-
-free_memory:
-       msg_release_message(&msgInfo);
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_3 Adding a MMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Adding a MMS Message</h3>
-- int msg_set_subject(msg_message_t msg, const char* subject);
-@n msg_set_subject() is a function to set the subject of MMS. The first parameter is the message object which is created by msg_new_message(). The second parameter is the subject you want to set. If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- MMS_MESSAGE_DATA_S* msg_mms_create_message(void);
-@n msg_mms_create_message() allocates a MMS_MESSAGE_DATA_S structure and returns it’s address. MMS_MESSAGE_DATA_S is needed to represent mms specific data and transfer it to the messaging daemon in the pData parameter of the MSG_MESSAGE_S structure.
-
-- MMS_SMIL_ROOTLAYOUT* msg_mms_set_rootlayout(MMS_MESSAGE_DATA_S* msg, const int width, const int height, const int bgcolor);
-@n msg_mms_set_rootlayout() is a function to set smil root layout. The parameters representing the size and background color of smil root layout should be set.
-
-- MMS_SMIL_REGION* msg_mms_add_region(MMS_MESSAGE_DATA_S *msg_data, const char* szID, const int x, const int y, const int width, const int height, const int bgcolor);
-@n msg_mms_add_region() is a function to add a smil region. Smil region is needed to display text message, image, and video data (Each content has its own region). This function is called to allocate a region for each contents.
-
-- MMS_PAGE_S* msg_mms_add_page(MMS_MESSAGE_DATA_S *msg_data, const int duration);
-@n msg_mms_add_page() is a function to add a smil page.
-
-- MMS_MEDIA_S* msg_mms_add_media(MMS_PAGE_S *page, const MmsSmilMediaType mediatype, const char* regionid, char* filepath);
-@n msg_mms_add_media() is a function to add multimedia content to a mms message. If some content should be played with smil player, this function can be used.
-
-- MMS_ATTACH_S* msg_mms_add_attachment(MMS_MESSAGE_DATA_S *msg_data, char *filepath);
-@n msg_mms_add_attachment() is a function to add a content as an attached file. With this function a content might be attached as a multipart mixed type.
-
-- int msg_mms_set_message_body(msg_message_t msg, const MMS_MESSAGE_DATA_S *msg_data);
-@n msg_mms_set_message_body() is a function to set the MMS body data. The first parameter is the message object which is created by msg_new_message(). The second parameter is the structure which is allocated by msg_mms_create_message() and is set by the APIs for MMS.
-
-- int msg_mms_destroy_message(MMS_MESSAGE_DATA_S* msg);
-@n msg_mms_destroy_message() should be called to deallocate the MMS_MESSAGE_DATA_S structure and internal region, page, media, and attach list.
-@code
-#include <string.h>
-#include <MapiStorage.h>
-#include <MapiMessage.h>
-
-void test_add_mms_message(MSG_HANDLE_T hMsgHandle)
-{
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       MSG_SENDINGOPT_S sendOpt = {0, };
-       sendOpt.bSetting = false;
-
-       msg_message_t msgInfo = msg_new_message();
-
-       // Set Message Type
-       err = msg_set_message_type(msgInfo, MSG_TYPE_MMS);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       MMS_MESSAGE_DATA_S* data;
-       MMS_PAGE_S* page;
-       MMS_MEDIA_S* media[3];
-       MMS_ATTACH_S* attach;
-       int nSize = 0;
-
-       // Set MMS subject
-       char subject[MAX_SUBJECT_LEN];
-
-       memset(subject, 0x00, MAX_SUBJECT_LEN);
-       strncpy(subject, "hello mms", sizeof(subject)-1);
-
-       err = msg_set_subject(msgInfo, subject);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       // Set MMS Body data
-       data = msg_mms_create_message();
-       msg_mms_set_rootlayout(data, 100, 100, 0xffffff);
-       msg_mms_add_region(data, "Image", 0, 50, 100, 50, 0xffffff);
-       msg_mms_add_region(data, "Text", 0, 0, 100, 50, 0xffffff);
-       page = msg_mms_add_page(data, 5000);
-       media[0] = msg_mms_add_media(page, MMS_SMIL_MEDIA_IMG, "Image", "/tmp/image.jpg");
-       media[1] = msg_mms_add_media(page, MMS_SMIL_MEDIA_AUDIO, NULL, "/tmp/audio.amr");
-       media[2] = msg_mms_add_media(page, MMS_SMIL_MEDIA_TEXT, "Text", "/tmp/message.txt");
-       attach = msg_mms_add_attachment(data, "attachment.3gp");
-
-       err = msg_mms_set_message_body(msgInfo, data);
-
-       if (err != MSG_SUCCESS)
-       {
-               msg_mms_destroy_message(data);
-               goto free_memory;
-       }
-
-       msg_mms_destroy_message(data);
-
-       // Set Recipient Address
-       char number[MAX_ADDRESS_VAL_LEN];
-
-       memset(number, 0x00, MAX_ADDRESS_VAL_LEN);
-       strncpy(number, "+821030011234", sizeof(number)-1);
-
-       err = msg_add_address(msgInfo, number, MSG_RECIPIENTS_TYPE_TO);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       err = msg_add_message(hMsgHandle, msgInfo, &sendOpt);
-
-       if (err == MSG_SUCCESS)
-               printf("Saving Message is OK!");
-       else
-               printf("Saving Message is failed!");
-
-free_memory:
-       msg_release_message(&msgInfo);
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_4 Sending a SMS/MMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Sending a SMS/MMS Message</h3>
-
-- bool msg_is_sms(msg_message_t msg);
-@n msg_is_sms() is a function to check whether the message type of message object is SMS or not. The first parameter is the message object which is created by msg_new_message(). The function returns true if the message object is a SMS message. Otherwise, it returns false.
-
-- bool msg_is_mms(msg_message_t msg);
-@n msg_is_mms() is a function to check whether the message type of message object is MMS or not. The first parameter is the message object which is created by msg_new_message(). The function returns true if the message object is a MMS message. Otherwise, it returns false.
-
-- int msg_sms_send_message(MSG_HANDLE_T handle, MSG_REQUEST_S* req);
-@n msg_sms_send_message() is a function to send SMS through messaging framework. The first parameter is the handle which is created by msg_open_msg_handle (). The second parameter is the structure that includes the message information to send. You can get the result of sending on sent status callback.
-
-- int msg_mms_send_message(MSG_HANDLE_T handle, MSG_REQUEST_S* req);
-@n msg_sms_send_message() is a function to send SMS through messaging framework. The first parameter is the handle which is created by msg_open_msg_handle (). The second parameter is the structure that includes the message information to send. You can get the result of sending on sent status callback.
-@code
-#include <MapiTransport.h>
-#include <MapiMessage.h>
-
-int MsgTestSendMsg(MSG_HANDLE_T hMsgHandle, msg_message_t pMsg)
-{
-       if (hMsgHandle == NULL)
-       {
-               printf("Handle is NULL\n");
-               return MSG_ERR_NULL_MSGHANDLE;
-       }
-
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       MSG_REQUEST_S req = {0};
-
-       if (pMsg == NULL)
-       {
-               printf("Message is NULL\n");
-               return MSG_ERR_NULL_MESSAGE;
-       }
-
-       req.msg = pMsg;
-
-       if (msg_is_sms(req.msg))
-               err = msg_sms_send_message(hMsgHandle, &req);
-       else if (msg_is_mms(req.msg))
-               err = msg_mms_send_message(hMsgHandle, &req);
-
-       if (err == MSG_SUCCESS)
-               printf("Request to Send Message is successful!!!");
-       else
-               printf("Request to Send Message is failed!!!");
-
-       return err;
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_5 Sending Simple SMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Simple SMS Sending</h3>
-- int msg_sms_send(const char *phone_num_list, const char *sms_text, msg_simple_sent_status_cb cb, void *user_param);
-@n msg_sms_send() is a simple function to send an SMS message. Without this API, in order to send a message the application should allocate a channel with messaging daemon for IPC, register sent-status callback function to monitor the sending result, and fulfill many member variables of MSG_MESSAGE_S. This function implicitly makes a connection with messaging daemon and registers the callback function. In addition, member variables of the MSG_MESSAGE_S structure are filled with default values except for the recipient phone_number and sms_text.
-@code
-#include <stdio.h>
-#include <string.h>
-#include <glib.h>
-#include <MapiTransport.h>
-
-GMainLoop *mainloop;
-
-typedef struct {
-       char number[256];
-       char text[256];
-       char userdata[256];
-} send_data;
-
-void sent_status_cb(MSG_SENT_STATUS_S *pMsgStatus, void *userData)
-{
-       if (pMsgStatus->status == MSG_NETWORK_SEND_SUCCESS)
-               printf("reqId : %d  MSG SENT SUCCESS !!!\n", pMsgStatus->reqId);
-       else
-               printf("reqId : %d  MSG SENT FAIL !!! [%d]\n", pMsgStatus->reqId, pMsgStatus->status);
-}
-
-// count from here
-gboolean send_func(gpointer data)
-{
-       send_data* sms_input = (send_data*)data;
-
-       printf("Begin to send [%s] to [%s]\n", sms_input->number, sms_input->text);
-       MSG_ERROR_T err = msg_sms_send(sms_input->number, sms_input->text, &sent_status_cb, (void*)sms_input->userdata);
-
-       if (err != MSG_SUCCESS)
-               printf("Send failed [%d]\n", err);
-
-       return FALSE;
-}
-// end
-
-int main(int argc, char* argv[])
-{
-       if (argc != 3 && argc != 4)
-       {
-               printf("Usage: %s  {phone_num_list} {sms_text} [user_data]\n", argv[0]);
-               printf("phone_num_list: phone_num1, phone_num2, ..., phone_numN\n");
-               return 0;
-       }
-
-       // Set sms input parameters : phone numbers and text
-       send_data sms_input = {};
-       strncpy(sms_input.number, argv[1], sizeof(sms_input.number)-1);
-       strncpy(sms_input.text, argv[2], sizeof(sms_input.text)-1);
-       if (argc == 4)
-               strncpy(sms_input.userdata, argv[3], sizeof(sms_input.userdata)-1);
-
-       // Add Sending Function to GMainLoop
-       g_idle_add(&send_func, (gpointer) &sms_input);
-
-       // start GMainLoop
-       mainloop = g_main_loop_new(NULL, FALSE);
-
-       printf("Entering GMain Loop to Receive Notifications in Thread...\n");
-
-       g_main_loop_run(mainloop);
-
-       printf("==== End Test App. Bye...===\n");
-
-       return 0;
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_6 Retrieving a MMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Retrieving a MMS Message</h3>
-- int msg_mms_retrieve_message(MSG_HANDLE_T handle, MSG_REQUEST_S* req);
-@n msg_mms_retrieve_message() is a function to submit a retrieve MMS request.
-@code
-void MsgTestRetrieveMessage(MSG_HANDLE_T hMsgHandle, MSG_MESSAGE_ID_T nMsgId)
-{
-       if (hMsgHandle == NULL)
-       {
-               printf("Handle is NULL");
-               return;
-       }
-
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       msg_message_t msg = msg_new_message();
-       MSG_SENDINGOPT_S sendOpt = {0, };
-
-       err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)nMsgId, msg, &sendOpt);
-
-       if (err != MSG_SUCCESS)
-               printf("Get Message Failed!");
-
-       MSG_REQUEST_S req = {0, msg, sendOpt};
-
-       err = msg_mms_retrieve_message(hMsgHandle, &req);
-
-       if (err != MSG_SUCCESS)
-               printf("Retrieve MMS Message Failed!");
-
-       msg_release_message(&msg);
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_7 Getting a SMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Getting a SMS Message</h3>
-- int msg_get_message(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, msg_message_t msg, MSG_SENDINGOPT_S *send_opt);
-@n msg_get_message() is a function to get a message. The first parameter is the handle which is created by msg_open_msg_handle (). The second parameter is the message ID you want to get. The third parameter is the message object to receive the message information. The last parameter is the structure to receive the message sending options.
-
-- int msg_get_message_id(msg_message_t msg);
-@n msg_get_message_id() is a function to get the message ID. The parameter is the message object. If the function is successful, it returns the message ID. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- int msg_get_folder_id(msg_message_t msg);
-@n msg_get_folder_id() is a function to get the ID of the folder  that the message is saved within. The parameter is the message object. If the function is successful, it returns one of the enum type in (_MSG_FOLDER_ID_E) . Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- int msg_get_message_type(msg_message_t msg);
-@n msg_get_message_type() is a function to get the message type. The parameter is the message object. If the function is successful, it returns one of the enum type in (_MSG_MESSAGE_TYPE_E). Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- int msg_get_address_count(msg_message_t msg);
-@n msg_get_address_count() is a function to get the number of addresses. The parameter is the message object. If the function is successful, it returns the number of addresses. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- const char* msg_get_ith_address(msg_message_t msg, int ith);
-@n msg_get_ith_address() is a function to get the ith address of message. The first parameter is the message object. The second parameter is the index of address you want to get. If the function is successful, it returns the address string. Otherwise it returns NULL.
-
-- time_t* msg_get_time(msg_message_t msg);
-@n msg_get_time() is a function to get the time value of message. The parameter is the message object. If the function is successful, it returns the time value. Otherwise it returns NULL.
-
-- int msg_get_network_status(msg_message_t msg);
-@n msg_get_network_status() is a function to get the network status of message. The parameter is the message object. If the function is successful, it returns one of the enum type in (_MSG_NETWORK_STATUS_E). Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- bool msg_is_read(msg_message_t msg);
-@n msg_is_read() is a function to check whether the message was read or not. The parameter is the message object. If the message was read, it returns true. Otherwise it returns false.
-
-- bool msg_is_protected(msg_message_t msg);
-@n msg_is_protected() is a function to check whether the message is protected or not. The parameter is the message object. If the the message was protected, it returns true. Otherwise it returns false.
-
-- int msg_get_message_body_size(msg_message_t msg);
-@n msg_get_message_body_size() is a function to get the byte size of message. The parameter is the message object. If the function is successful, it returns the byte size of message. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-
-- const char* msg_sms_get_message_body(msg_message_t msg);
-@n msg_sms_get_message_body() is a function to get the body data of message. The first parameter is the message object. If the function is successful, it returns the body data. Otherwise it returns NULL.
-@code
-void MsgTestGetSmsMessage(MSG_HANDLE_T hMsgHandle, int MsgId)
-{
-       if (hMsgHandle == NULL)
-       {
-               printf("Handle is NULL\n");
-               return;
-       }
-
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       msg_message_t msg = msg_new_message();
-       MSG_SENDINGOPT_S sendOpt = {0, };
-
-       // Get Message
-       err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)MsgId, msg, &sendOpt);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       printf("msgId = %d\n", msg_get_message_id(msg));
-       printf("folderId = %d\n", msg_get_folder_id(msg));
-       printf("msgType = %d\n", msg_get_message_type(msg));
-       printf("phone number = %s\n", msg_get_ith_address(msg, 0));
-       printf("displayTime = %s\n", ctime(msg_get_time(msg)));
-       printf("networkStatus = %d\n", msg_get_network_status(msg));
-       printf("bRead = %d\n", msg_is_read(msg));
-       printf("bProtected = %d\n", msg_is_protected(msg));
-       printf("dataSize = %d\n", msg_get_message_body_size(msg));
-       printf("msgData = %s\n", msg_sms_get_message_body(msg));
-
-free_memory:
-       msg_release_message(&msg);
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_8 Getting a MMS Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Getting a MMS Message</h3>
-- int msg_mms_get_message_body(msg_message_t msg, MMS_MESSAGE_DATA_S *body);
-@n msg_get_address_count. The parameter is the message object. The second parameter is the structure to receive MMS data as output. If the function is successful, it returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
-- MMS_SMIL_REGION* msg_mms_get_smil_region(MMS_MESSAGE_DATA_S msgBody, int region_idx);
-@n msg_mms_get_smil_region() is a function to get a SMIL region information. The first parameter is the structure of MMS data. The second parameter is the index of SMIL region you want to get. If the function is successful, it returns the structure which contains the SMIL region information. Otherwise it returns NULL.
-- MMS_PAGE_S* msg_mms_get_page(MMS_MESSAGE_DATA_S msgBody, int page_idx);
-@n msg_mms_get_page() is a function to get a SMIL page information. The first parameter is the structure of MMS data. The second parameter is the index of SMIL page you want to get. If the function is successful, it returns the structure which contains the SMIL page information. Otherwise it returns NULL.
-- MMS_MEDIA_S* msg_mms_get_media(MMS_PAGE_S *page, int media_idx);
-@n msg_mms_get_media() is a function to get a media information in a SMIL page. The first parameter is the structure of SMIL page you want to get the media from. The second parameter is the index of media you want to get. If the function is successful, it returns the structure which contains the media information. Otherwise it returns NULL.
-- MMS_ATTACH_S* msg_mms_get_attachment(MMS_MESSAGE_DATA_S msgBody, int attach_idx);
-@n msg_mms_get_attachment() is a function to get the file information of  an attachment. The first parameter is the structure of MMS data. The second parameter is the index of attachment you want to get. If the function is successful, it returns the structure which contains the attachment file information. Otherwise it returns NULL.
-- const char* msg_get_subject(msg_message_t msg);
-@n msg_get_subject() is a function to get the subject of MMS. The parameter is the message object. If the function is successful, it returns the subject string. Otherwise it returns NULL.
-@code
-void MsgTestGetMmsMessage(MSG_HANDLE_T hMsgHandle, int MsgId)
-{
-       if (hMsgHandle == NULL)
-       {
-               printf("Handle is NULL\n");
-               return;
-       }
-
-       MSG_ERROR_T err = MSG_SUCCESS;
-
-       msg_message_t msg = msg_new_message();
-       MSG_SENDINGOPT_S sendOpt = {0, };
-
-       // Get Message
-       err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)MsgId, msg, &sendOpt);
-
-       if (err != MSG_SUCCESS) goto free_memory;
-
-       if (msg_is_mms(msg) == false)
-       {
-               printf("It is not MMS Message!");
-               goto free_memory;
-       }
-
-       MMS_MESSAGE_DATA_S* msgBody = msg_mms_create_message();
-
-       // Get MMS Body Data
-       msg_mms_get_message_body(msg, msgBody);
-
-       //Print root-layout info
-       printf("width: %d \n
-               height: %d \n
-               nbgColor:%x \n",
-               msgBody->rootlayout.width.value,
-               msgBody->rootlayout.height.value,
-               msgBody->rootlayout.bgColor);
-
-       // Print Region Info
-       for (int i = 0; i < msgBody->regionCnt; ++i)
-       {
-               MMS_SMIL_REGION* pRegion = msg_mms_get_smil_region(msgBody, i);
-
-               printf("region id: %s\n
-                       region left : %d\n
-                       region top : %d\n
-                       region width : %d\n
-                       region height : %d\n
-                       region bgColor : %x\n
-                       region fit : %d\n",
-                       pRegion->szID,pRegion->nLeft.value,
-                       pRegion->nTop.value,pRegion->width.value,
-                       pRegion->height.value, pRegion->bgColor,
-                       pRegion->fit);
-       }
-
-       // Print Page info
-       for (int i = 0; i< msgBody->pageCnt; ++i)
-       {
-               MMS_PAGE_S* pPage = msg_mms_get_page(msgBody, i);
-
-               printf("page's duration: %d msec\n
-                       page's media count: %d\n",
-                       pPage->nDur, pPage->mediaCnt);
-
-               // Print Contents Info
-               for(int j = 0; j < pPage->mediaCnt; ++j)
-               {
-                       MMS_MEDIA_S* pMedia = msg_mms_get_media(pPage, j);
-                       printf("media's filename: %s\n
-                               media's filepath: %s\n
-                               media's regionId: %s\n
-                               Bold: %d Italic: %d\n",
-                               pMedia->szFileName,
-                               pMedia->szFilePath,
-                               pMedia->regionId,
-                               pMedia->sMedia.sText.bBold,
-                               pMedia->sMedia.sText.bItalic);
-
-                       if(pMedia->drmType != MSG_DRM_TYPE_NONE)
-                       {
-                               printf("media's drmtype: %d\n
-                                       media's drmpath: %s\n",
-                                       pMedia->drmType, pMedia->szDrm2FullPath);
-                       }
-               }
-       }
-
-       for (int i = 0; i < msgBody->attachCnt; ++i)
-       {
-               MMS_ATTACH_S* pAttach = msg_mms_get_attachment(msgBody, i);
-
-               printf("Attachment file Name: %s\n
-                       Attachment file Path: %s\n
-                       Attached file size: %d\n",
-                       pAttach->szFileName,
-                       pAttach->szFilePath,
-                       pAttach->fileSize);
-
-               if(pAttach->drmType != MSG_DRM_TYPE_NONE)
-                       printf("media's drmtype: %d\n
-                               media's drmpath: %s\n",
-                               pAttach->drmType, pAttach->szDrm2FullPath);
-       }
-
-       printf("Subject: %s\n", msg_get_subject(pMsg));
-
-       printf("msgId = %d", msg_get_message_id(msg));
-       printf("folderId = %d", msg_get_folder_id(msg));
-       printf("phone number = %s", msg_get_ith_address(msg, 0));
-       printf("displayTime = %s", ctime(msg_get_time(msg)));
-       printf("networkStatus = %d", msg_get_network_status(msg));
-       printf("bRead = %d", msg_is_read(msg));
-       printf("bProtected = %d", msg_is_protected(msg));
-
-free_memory:
-       msg_mms_destroy_message(msgBody);
-
-       msg_release_message(&msg);
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_9 Delete a Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Delete a Message</h3>
-- int msg_delete_message(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id);
-@n msg_delete_message() is a function to delete a message from message box by msg_id.
-@code
-void MsgTestDeleteMessage(MSG_HANDLE_T hMsgHandle, MSG_MESSAGE_ID_T nMsgId)
-{
-       MSG_ERROR_T err;
-
-       if (msg_delete_message(hMsgHandle, nMsgId) != MSG_SUCCESS)
-               printf("Failed to delete Message");
-
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_10 Set/Get Message Setting
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Set / Get Message setting</h3>
-msg_set_config() and msg_get_cofig() is used to set or to get the message setting options. MSG_SETTING_S structure includes various setting information and is shared between message application and messaging daemon.
-
-- int msg_set_config(MSG_HANDLE_T handle, const MSG_SETTING_S *setting);
-@n msg_set_config() sets a message option.
-- int msg_get_config(MSG_HANDLE_T handle, MSG_SETTING_S *setting);
-@n msg_get_config() gets a message option.
-@code
-void MsgTestSetGeneralOpt(MSG_HANDLE_T hMsgHandle)
-{
-       MSG_ERROR_T err = MSG_SUCCESS;
-       MSG_SETTING_S setting = {0, };
-
-       setting.type = MSG_GENERAL_OPT;
-
-       setting.option.generalOpt.bKeepCopy = true;
-       setting.option.generalOpt.alertTone = MSG_ALERT_TONE_ONCE;
-
-       err = msg_set_config(hMsgHandle, &setting);
-
-       if (err == MSG_SUCCESS)
-               printf("Setting Config Data is OK!");
-       else
-               printf("Setting Config Data is failed!");
-}
-
-void MsgTestGetGeneralOpt(MSG_HANDLE_T hMsgHandle)
-{
-       MSG_ERROR_T err = MSG_SUCCESS;
-       MSG_SETTING_S setting = {0, };
-
-       err = msg_get_config(hMsgHandle, &setting);
-
-       if (err == MSG_SUCCESS)
-       {
-               printf("Setting Config Data is OK!\n");
-               printf("bKeepCopy : [%d], AlertTone : [%d]\n", setting.option.generalOpt.bKeepCopy, setting.option.generalOpt.alertTone);
-       }
-       else
-               printf("Setting Config Data is failed!\n");
-}
-@endcode
-@}
-
-@defgroup MESSAGE_USECASES_11 Filtering a Message
-@ingroup MESSAGE_USECASES
-@{
-               <h3 class="pg">Filtering a Message</h3>
-Messaging framework provides a filtering function for incoming message. New incoming message can be blocked (Move to spam-box or discard) by adding a filtering rule. A incoming message can be blocked by its originating address or by subject matching. If address matching filter rule is applied, only messages with exactly the same phone number can be blocked. Whereas, if a subject matching filter rule is applied, all messages that include the registered subject string might be blocked. An application can add or remove a filtering rule by calling msg_add_filter() or msg_delete_filter().
-
-- int msg_add_filter(MSG_HANDLE_T handle, const MSG_FILTER_S *filter);
-@n msg_add_filter() inserts a filtering rule to filter list and returns filter id.
-- int msg_delete_filter(MSG_HANDLE_T handle, MSG_FILTER_ID_T filter_id);
-@n msg_delete_filter()removes a filtering rule from filter list by filter id
-@code
-void MsgTestAddFilter(MSG_HANDLE_T hMsgHandle)
-{
-       if (hMsgHandle == NULL)
-       {
-               printf("Handle is NULL");
-               return;
-       }
-
-       MSG_ERROR_T err = MSG_SUCCESS;
-       MSG_FILTER_S filter[2]= {0, };
-
-       // Add filter by address
-       filter[0].filterType = MSG_FILTER_BY_ADDRESS;
-       strncpy(filter[0].filterValue, "+821234567890", MAX_FILTER_VALUE_LEN);
-
-       err = msg_add_filter(hMsgHandle, &filter[0]);
-
-       if (err == MSG_SUCCESS)
-               printf("msg_add_filter success");
-       else
-               printf("msg_add_filter fail - err [%d]", err);
-
-       // Add filter by subject
-       filter[1].filterType = MSG_FILTER_BY_SUBJECT;
-       strncpy(filter[1].filterValue, "test filter", MAX_FILTER_VALUE_LEN);
-
-       err = msg_add_filter(hMsgHandle, &filter[1]);
-
-       if (err == MSG_SUCCESS)
-               printf("msg_add_filter success");
-       else
-               printf("msg_add_filter fail - err [%d]", err);
-
-       return;
-}
-
-void MsgTestDeleteFilter(MSG_HANDLE_T hMsgHandle, MSG_FILTER_ID_T filterId)
-{
-       if (hMsgHandle == NULL)
-       {
-               printf("Handle is NULL");
-               return;
-       }
-
-       MSG_ERROR_T err = MSG_SUCCESS;
-       err = msg_delete_filter(hMsgHandle, filterId);
-
-       if (MSG_SUCCESS == err)
-       {
-               printf("msg_delete_filter success");
-       }
-       else
-       {
-               printf("msg_delete_filter fail - err [%d]", err);
-       }
-
-       return;
-}
-@endcode
-@}
-*/
-
-/**
-@addtogroup MESSAGE
-@{
-       @defgroup MESSAGE_USECASES Use Cases
-@}
-*/
diff --git a/config/alert_on_call.mp3 b/config/alert_on_call.mp3
deleted file mode 100755 (executable)
index c7c77d1..0000000
Binary files a/config/alert_on_call.mp3 and /dev/null differ
diff --git a/config/message_tone/Sherbet.wav b/config/message_tone/Sherbet.wav
deleted file mode 100755 (executable)
index 3d352e4..0000000
Binary files a/config/message_tone/Sherbet.wav and /dev/null differ
diff --git a/config/msg-service-db.sql b/config/msg-service-db.sql
new file mode 100755 (executable)
index 0000000..9f9499a
--- /dev/null
@@ -0,0 +1,308 @@
+PRAGMA user_version=1;
+
+CREATE TABLE MSG_CONVERSATION_TABLE
+(
+       CONV_ID INTEGER PRIMARY KEY ,
+       UNREAD_CNT INTEGER DEFAULT 0 ,
+       SMS_CNT INTEGER DEFAULT 0 ,
+       MMS_CNT INTEGER DEFAULT 0 ,
+       MAIN_TYPE INTEGER DEFAULT 0 ,
+       SUB_TYPE INTEGER DEFAULT 0 ,
+       MSG_DIRECTION INTEGER DEFAULT 0 ,
+       DISPLAY_TIME DATETIME ,
+       DISPLAY_NAME TEXT NOT NULL DEFAULT '' ,
+       MSG_TEXT TEXT NOT NULL DEFAULT '' ,
+       TRANSLATION INTEGER DEFAULT 0,
+       SENDER_LANG INTEGER DEFAULT 0,
+       RECEIVER_LANG INTEGER DEFAULT 0,
+       ONLY_RECEIVE INTEGER DEFAULT 0,
+       INCLUDE_ORGMSG INTEGER DEFAULT 0,
+       LAST_MSG_ID INTEGER DEFAULT 0,
+        TAG_TYPE INTEGER DEFAULT 1
+);
+
+CREATE TABLE MSG_ADDRESS_TABLE
+(
+       ADDRESS_ID INTEGER PRIMARY KEY ,
+       CONV_ID INTEGER  NOT NULL ,
+       ADDRESS_TYPE INTEGER ,
+       RECIPIENT_TYPE INTEGER ,
+       ADDRESS_VAL TEXT NOT NULL DEFAULT '' ,
+       CONTACT_ID INTEGER ,
+       ADDR_BOOK_ID INTEGER ,
+       FIRST_NAME TEXT NOT NULL DEFAULT '' ,
+       LAST_NAME TEXT NOT NULL DEFAULT '' ,
+       MIDDLE_NAME TEXT NOT NULL DEFAULT '' ,
+       PREFIX TEXT NOT NULL DEFAULT '' ,
+       SUFFIX TEXT NOT NULL DEFAULT '' ,
+       IMAGE_PATH TEXT NOT NULL DEFAULT '' ,
+       SYNC_TIME DATETIME ,
+
+       FOREIGN KEY (CONV_ID) REFERENCES MSG_CONVERSATION_TABLE (CONV_ID)
+);
+
+CREATE TABLE MSG_FOLDER_TABLE
+(
+       FOLDER_ID INTEGER PRIMARY KEY ,
+       FOLDER_NAME TEXT NOT NULL ,
+       FOLDER_TYPE INTEGER DEFAULT 0
+);
+
+CREATE TABLE MSG_MESSAGE_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       CONV_ID INTEGER NOT NULL ,
+       FOLDER_ID INTEGER NOT NULL ,
+       STORAGE_ID INTEGER NOT NULL ,
+       MAIN_TYPE INTEGER NOT NULL ,
+       SUB_TYPE INTEGER NOT NULL ,
+       DISPLAY_TIME DATETIME ,
+       DATA_SIZE INTEGER DEFAULT 0 ,
+       NETWORK_STATUS INTEGER DEFAULT 0 ,
+       READ_STATUS INTEGER DEFAULT 0 ,
+       PROTECTED INTEGER DEFAULT 0 ,
+       PRIORITY INTEGER DEFAULT 0 ,
+       MSG_DIRECTION INTEGER NOT NULL ,
+       SCHEDULED_TIME DATETIME ,
+       BACKUP INTEGER DEFAULT 0 ,
+       SUBJECT TEXT NOT NULL DEFAULT '' ,
+       MSG_DATA TEXT NOT NULL DEFAULT '' ,
+       THUMB_PATH TEXT NOT NULL DEFAULT '' ,
+       MSG_TEXT TEXT NOT NULL DEFAULT '' ,
+       ATTACHMENT_COUNT INTEGER DEFAULT 0 ,
+       SIM_INDEX INTEGER DEFAULT 0 ,
+       SIM_IMSI TEXT ,
+
+       FOREIGN KEY (CONV_ID) REFERENCES MSG_CONVERSATION_TABLE (CONV_ID) ,
+       FOREIGN KEY (FOLDER_ID) REFERENCES MSG_FOLDER_TABLE (FOLDER_ID)
+);
+
+CREATE TABLE MSG_SIM_TABLE
+(
+       SIM_SLOT_ID INTEGER ,
+       SIM_ID INTEGER ,
+       MSG_ID INTEGER NOT NULL ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_PUSH_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       ACTION INTEGER ,
+       CREATED INTEGER ,
+       EXPIRES INTEGER ,
+       ID TEXT NOT NULL DEFAULT '' ,
+       HREF TEXT NOT NULL DEFAULT '' ,
+       CONTENT TEXT NOT NULL DEFAULT '' ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_CBMSG_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       CB_MSG_ID INTEGER NOT NULL ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_SYNCML_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       EXT_ID INTEGER NOT NULL ,
+       PINCODE INTEGER NOT NULL ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_SCHEDULED_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       ALARM_ID INTEGER NOT NULL ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_SMS_SENDOPT_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       DELREP_REQ INTEGER NOT NULL ,
+       KEEP_COPY INTEGER NOT NULL ,
+       REPLY_PATH INTEGER NOT NULL ,
+       ENCODE_TYPE INTEGER NOT NULL ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_FILTER_TABLE
+(
+       FILTER_ID INTEGER PRIMARY KEY ,
+       FILTER_TYPE INTEGER NOT NULL ,
+       FILTER_VALUE TEXT NOT NULL ,
+       FILTER_ACTIVE INTEGER DEFAULT 0
+);
+
+CREATE TABLE MSG_MMS_MESSAGE_TABLE
+(
+       MSG_ID INTEGER PRIMARY KEY ,
+       TRANSACTION_ID TEXT NOT NULL DEFAULT '' ,
+       MESSAGE_ID TEXT NOT NULL DEFAULT '' ,
+       FWD_MESSAGE_ID TEXT NOT NULL DEFAULT '' ,
+       CONTENTS_LOCATION TEXT NOT NULL DEFAULT '' ,
+       FILE_PATH TEXT NOT NULL DEFAULT '' ,
+       VERSION INTEGER NOT NULL ,
+       DATA_TYPE INTEGER DEFAULT -1 ,
+       DATE DATETIME ,
+       HIDE_ADDRESS INTEGER DEFAULT 0 ,
+       ASK_DELIVERY_REPORT INTEGER DEFAULT 0 ,
+       REPORT_ALLOWED INTEGER DEFAULT 0 ,
+       READ_REPORT_ALLOWED_TYPE INTEGER DEFAULT 0 ,
+       ASK_READ_REPLY INTEGER DEFAULT 0 ,
+       READ INTEGER DEFAULT 0 ,
+       READ_REPORT_SEND_STATUS INTEGER DEFAULT 0 ,
+       READ_REPORT_SENT INTEGER DEFAULT 0 ,
+       PRIORITY INTEGER DEFAULT 0 ,
+       KEEP_COPY INTEGER DEFAULT 0 ,
+       MSG_SIZE INTEGER NOT NULL ,
+       MSG_CLASS INTEGER DEFAULT -1 ,
+       EXPIRY_TIME DATETIME ,
+       CUSTOM_DELIVERY_TIME INTEGER DEFAULT 0 ,
+       DELIVERY_TIME DATETIME ,
+       MSG_STATUS INTEGER DEFAULT -1 ,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_MMS_PREVIEW_INFO_TABLE
+(
+       MSG_ID INTEGER NOT NULL ,
+       TYPE INTEGER,
+       VALUE TEXT,
+       COUNT INTEGER,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_SMS_REPORT_TABLE
+(
+       MSG_ID INTEGER NOT NULL ,
+       ADDRESS_VAL TEXT NOT NULL DEFAULT '' ,
+       MSG_REF INTEGER ,
+       STATUS_TYPE INTEGER ,
+       STATUS INTEGER DEFAULT 0 ,
+       TIME DATETIME
+);
+
+CREATE TABLE MSG_REPORT_TABLE
+(
+       MSG_ID INTEGER NOT NULL ,
+       ADDRESS_VAL TEXT NOT NULL DEFAULT '' ,
+       STATUS_TYPE INTEGER ,
+       STATUS INTEGER DEFAULT 0 ,
+       TIME DATETIME
+);
+
+CREATE TABLE MSG_PUSHCFG_TABLE
+(
+       PUSH_ID INTEGER PRIMARY KEY ,
+       CONTENT_TYPE TEXT NOT NULL DEFAULT '' ,
+       APP_ID TEXT NOT NULL DEFAULT '' ,
+       PKG_NAME TEXT NOT NULL DEFAULT '' ,
+       LAUNCH INTEGER,
+       APPCODE INTEGER,
+       SECURE INTEGER
+);
+
+CREATE TABLE MSG_TMP_MSGID_TABLE
+(
+       MSG_ID INTEGER
+);
+
+CREATE TABLE MSG_CB_CHANNEL_INFO_TABLE
+(
+       CHANNEL_ID INTEGER PRIMARY KEY AUTOINCREMENT,
+       CHANNEL_ACTIVATION INTEGER DEFAULT 0,
+       CHANNEL_FROM INTEGER DEFAULT 0,
+       CHANNEL_TO INTEGER DEFAULT 0,
+       CHANNEL_NAME TEXT NOT NULL DEFAULT '',
+       SIM_INDEX INTEGER DEFAULT 0
+);
+
+CREATE TABLE MSG_MULTIPART_TABLE
+(
+       _ID INTEGER PRIMARY KEY AUTOINCREMENT,
+       MSG_ID INTEGER NOT NULL ,
+       SEQ INTEGER DEFAULT 0,
+       CONTENT_TYPE TEXT,
+       NAME TEXT,
+       CHARSET INTEGER,
+       CONTENT_ID TEXT,
+       CONTENT_LOCATION TEXT,
+       FILE_PATH TEXT,
+       TEXT TEXT,
+       TCS_LEVEL INTEGER DEFAULT -1,
+       MALWARE_ALLOW INTEGER DEFAULT 0,
+       THUMB_FILE_PATH TEXT,
+
+       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID)
+);
+
+CREATE TABLE MSG_ADDRESS_TEMP_TABLE
+(
+       ADDRESS_VAL TEXT NOT NULL DEFAULT ''
+);
+
+CREATE INDEX MSG_CONVERSATION_INDEX ON MSG_CONVERSATION_TABLE(CONV_ID);
+CREATE INDEX MSG_FOLDER_INDEX ON MSG_FOLDER_TABLE(FOLDER_ID);
+CREATE INDEX MSG_MESSAGE_INDEX ON MSG_MESSAGE_TABLE(MSG_ID, CONV_ID, FOLDER_ID);
+
+INSERT INTO MSG_FOLDER_TABLE VALUES (1, 'INBOX', 1);
+INSERT INTO MSG_FOLDER_TABLE VALUES (2, 'OUTBOX', 2);
+INSERT INTO MSG_FOLDER_TABLE VALUES (3, 'SENTBOX', 2);
+INSERT INTO MSG_FOLDER_TABLE VALUES (4, 'DRAFT', 3);
+INSERT INTO MSG_FOLDER_TABLE VALUES (5, 'CBMSGBOX', 1);
+INSERT INTO MSG_FOLDER_TABLE VALUES (6, 'SPAMBOX', 4);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (1, 'text/vnd.wap.si', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 1, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (2, 'application/vnd.wap.sic', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 2, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (3, 'text/vnd.wap.sl', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 3, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (4, 'application/vnd.wap.slc', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 4, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (5, 'text/vnd.wap.co', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 5, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (6, 'application/vnd.wap.coc', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 6, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (7, 'application/vnd.wap.mms-message', 'X-Wap-Application-Id: x-wap-application:mms.ua', '', 0, 7, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (8, 'application/vnd.wap.sia', 'X-Wap-Application-Id: x-wap-application:push.sia', '', 0, 8, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (9, 'application/vnd.syncml.dm+wbxml', 'X-Wap-Application-Id: x-wap-application:push.syncml.dm', '', 0, 9, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (10, 'application/vnd.syncml.dm+xml', 'X-Wap-Application-Id: x-wap-application:push.syncml.dm', '', 0, 10, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (11, 'application/vnd.syncml.notification', 'X-Wap-Application-Id: x-wap-application:push.syncml.dm', '', 0, 11, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (12, 'application/vnd.syncml.ds.notification', 'X-Wap-Application-Id: x-wap-application:push.syncml.ds', '', 0, 12, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (13, 'application/vnd.syncml+wbxml', 'X-Wap-Application-Id:x-wap-application:push.syncml', '', 0, 13, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (14, 'application/vnd.wap.locc+wbxml', 'X-Wap-Application-Id: x-wap-application:loc.ua', '', 0, 14, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (15, 'application/vnd.wap.loc+xml', 'X-Wap-Application-Id: x-wap-application:loc.ua', '', 0, 15, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (16, 'application/vnd.oma.dd+xml', 'X-Wap-Application-Id: x-wap-application:loc.ua', '', 0, 16, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (17, 'application/vnd.oma.drm.message', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 17, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (18, 'application/vnd.oma.drm.content', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 18, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (19, 'application/vnd.oma.drm.rights+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 19, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (20, 'application/vnd.oma.drm.rights+wbxml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 20, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (21, 'application/vnd.oma.drm.ro+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 21, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (22, 'application/vnd.oma.drm.roap-pdu+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 22, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (23, 'application/vnd.oma.drm.roap-trigger+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 23, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (24, 'application/vnd.oma.drm.roap-trigger+wbxml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 24, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (25, 'text/vnd.wap.connectivity-xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 26, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (26, 'application/vnd.wap.connectivity-wbxml', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 27, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (27, 'application/x-wap-prov.browser-settings', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 28, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (28, 'application/x-wap-prov.browser-bookmarks', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 29, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (29, 'application/x-wap-prov.syncset+xml', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 30, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (30, 'application/x-wap-prov.syncset+wbxml', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 31, 0);
+
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (33, 'application/vnd.wv.csp.cir', 'X-Wap-Application-Id: x-wap-application:wv.ua', '', 0, 34, 0);
+INSERT INTO MSG_PUSHCFG_TABLE VALUES (34, 'application/vnd.omaloc-supl-init', 'X-Wap-Application-Id: x-oma-application:ulp.ua', '', 0, 44, 0);
+
+INSERT INTO MSG_CB_CHANNEL_INFO_TABLE VALUES (0, 1, 0, 65535, '', 1);
+INSERT INTO MSG_CB_CHANNEL_INFO_TABLE VALUES (1, 1, 0, 65535, '', 2);
similarity index 57%
rename from sysinfo-message.xml
rename to config/sysinfo-message.xml
index e26ebf0..be1ef51 100755 (executable)
@@ -1,7 +1,8 @@
 <?xml version="1.0"?>
 <sys-info>
        <default>
+               <key id="sms-support" string="true"/>
                <key id="mms-support" string="true"/>
-               <key id="cbs-support" string="false"/>
+               <key id="cbs-support" string="true"/>
        </default>
 </sys-info>
diff --git a/doc/msg_service_doc.h b/doc/msg_service_doc.h
new file mode 100644 (file)
index 0000000..6617947
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+
+#ifndef __MSG_SERVICE_DOC_H__
+#define __MSG_SERVICE_DOC_H__
+
+
+/**
+ * @internal
+ * @ingroup CAPI_MESSAGING_FRAMEWORK
+ * @defgroup MSG_SERVICE_FRAMEWORK msg-service
+ * @brief The @ref MSG_SERVICE_FRAMEWORK API provides functions to create, set properties and send or receive a SMS/MMS message.
+ *
+ * @addtogroup MSG_SERVICE_FRAMEWORK
+ *
+ * @section MSG_SERVICE_FRAMEWORK_OVERVIEW Overview
+ *
+ * The Messages API provides the following functionalities:
+ *
+ * - Creating a message
+ * - Setting the message properties
+ * - Sending a message
+ * - Getting a message information(s)
+ * - Searching for messages
+ * - Registering/Unregistering a callback function to check whether a message is sent successfully or not
+ * - Registering/Unregistering a callback function to receive notifications when an incoming message is received
+ *
+ * <BR>
+ *
+ */
+
+
+#endif /* __MSG_SERVICE_DOC_H__ */
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..aecc33a
--- /dev/null
@@ -0,0 +1,54 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(msg-server CXX)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+       SET(CMAKE_BUILD_TYPE "Debug")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -O0 -g -Wall")
+
+##########################################################
+# Define Framework Utils
+##########################################################
+
+SET(EXTERNALS-SRCS
+       ${CMAKE_SOURCE_DIR}/externals/MsgSoundPlayer.cpp
+       ${CMAKE_SOURCE_DIR}/externals/MsgNotificationWrapper.cpp
+       ${CMAKE_SOURCE_DIR}/externals/MsgSpamFilter.cpp
+       ${CMAKE_SOURCE_DIR}/externals/MsgLbs.cpp
+       ${CMAKE_SOURCE_DIR}/externals/MsgSensorWrapper.cpp
+       ${CMAKE_SOURCE_DIR}/externals/MsgAlarm.cpp
+       ${CMAKE_SOURCE_DIR}/externals/MsgDevicedWrapper.cpp
+)
+
+INCLUDE_DIRECTORIES(
+       ${CMAKE_SOURCE_DIR}/include/mapi
+       ${CMAKE_SOURCE_DIR}/include/common
+       ${CMAKE_SOURCE_DIR}/include/utils
+       ${CMAKE_SOURCE_DIR}/include/externals
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(externals_pkgs REQUIRED glib-2.0 deviced mm-session alarm-service notification secure-storage badge iniparser capi-appfw-application lbs-dbus mm-fileinfo mm-player mm-sound sensor feedback db-util)
+
+FOREACH(flag ${externals_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DFEATURE_JAVA_MMS")
+IF(_TIZEN_I586_ENABLED)
+ADD_DEFINITIONS("-DTIZEN_I586_ENABLED")
+ENDIF(_TIZEN_I586_ENABLED)
+SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+ADD_LIBRARY(${EXTERNALS-LIB} SHARED ${EXTERNALS-SRCS})
+TARGET_LINK_LIBRARIES(${EXTERNALS-LIB} ${externals_pkgs_LDFLAGS} rt ${UTILS-LIB} ${VOBJECT-LIB})
+
+INSTALL(TARGETS ${EXTERNALS-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
+
diff --git a/externals/MsgAlarm.cpp b/externals/MsgAlarm.cpp
new file mode 100755 (executable)
index 0000000..a70aac3
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+
+#include <map>
+
+#include "MsgDebug.h"
+#include "MsgAlarm.h"
+
+#include <alarm.h>
+
+
+/*==================================================================================================
+                                     DEFINES
+==================================================================================================*/
+typedef std::map<int, msg_alarm_cb> callBackMap;
+
+/*==================================================================================================
+                                     VARIABLES
+==================================================================================================*/
+bool alarmInit = false;
+callBackMap alarmCBMap;
+
+/*==================================================================================================
+                                     INTERNAL FUNCTION IMPLEMENTATION
+==================================================================================================*/
+int MsgAlarmCB(int alarmId, void *pUserParam)
+{
+       MSG_DEBUG("MsgAlarmCB is called. alarmId [%d]", alarmId);
+
+       callBackMap::iterator it = alarmCBMap.find(alarmId);
+
+       if (it == alarmCBMap.end()) {
+               MSG_DEBUG("alarmId is not found.");
+       } else {
+               msg_alarm_cb alarmCBfunction = it->second;
+               if (alarmCBfunction)
+                       alarmCBfunction(alarmId);
+
+               alarmCBMap.erase(it);
+       }
+
+       return 0;
+}
+
+
+msg_error_t MsgAlarmInit()
+{
+       MSG_BEGIN();
+
+       alarmCBMap.clear();
+
+       int retval = alarmmgr_init("msg-service-tools");
+       if (retval != ALARMMGR_RESULT_SUCCESS) {
+               MSG_DEBUG("alarmmgr_init error [%d]", retval);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       retval = alarmmgr_set_cb(MsgAlarmCB, NULL);
+       if (retval != ALARMMGR_RESULT_SUCCESS) MSG_DEBUG("alarmmgr_set_cb() [%d]", retval);
+
+       alarmInit = true;
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+msg_error_t MsgAlarmRegistration(struct tm *timeInfo, msg_alarm_cb userCB, int *alarmId)
+{
+       MSG_BEGIN();
+
+       if (!alarmInit) {
+               MSG_DEBUG("alarm manager is not initialized. Retry once.");
+               MsgAlarmInit();
+               if (!alarmInit) {
+                       MSG_DEBUG("alarm manager is still not initialized. So return error.");
+                       return MSG_ERR_UNKNOWN;
+               }
+       }
+
+       if (timeInfo == NULL || alarmId == NULL) {
+               MSG_DEBUG("(timeInfo == NULL || alarmId == NULL)");
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       *alarmId = 0;
+       alarm_info_t* alarm_info = NULL;
+       alarm_id_t      alarm_id = -1;
+       alarm_date_t    target_time;
+
+       int retval = ALARMMGR_RESULT_SUCCESS;
+
+       alarm_info = alarmmgr_create_alarm();
+       if (alarm_info == NULL) {
+               MSG_DEBUG("alarmmgr_create_alarm error.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+       target_time.year = timeInfo->tm_year + 1900;
+       target_time.month = timeInfo->tm_mon + 1;
+       target_time.day = timeInfo->tm_mday;
+       target_time.hour = timeInfo->tm_hour;
+       target_time.min = timeInfo->tm_min;
+       target_time.sec = timeInfo->tm_sec;
+
+       MSG_DEBUG( "Alarm Time : [%d-%d-%d %d:%d:%d] ",
+                       target_time.year, target_time.month, target_time.day,
+                       target_time.hour, target_time.min, target_time.sec);
+
+       retval = alarmmgr_set_time(alarm_info, target_time);
+       if (retval != ALARMMGR_RESULT_SUCCESS) MSG_DEBUG("alarmmgr_set_time ret[%d]", retval);
+       retval = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
+       if (retval != ALARMMGR_RESULT_SUCCESS) MSG_DEBUG("alarmmgr_set_repeat_mode ret[%d]", retval);
+       retval = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
+       if (retval != ALARMMGR_RESULT_SUCCESS) MSG_DEBUG("alarmmgr_set_type ret[%d]", retval);
+       retval = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &alarm_id);
+       MSG_DEBUG("alarmmgr_add_alarm_with_localtime ret[%d], alarm_id[%d]", retval, alarm_id);
+
+       retval = alarmmgr_free_alarm(alarm_info);
+       if (retval != ALARMMGR_RESULT_SUCCESS) MSG_DEBUG("alarmmgr_free_alarm ret[%d]", retval);
+
+       *alarmId = (int)alarm_id;
+
+       alarmCBMap[*alarmId] = userCB;
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgAlarmRemove(int alarmId)
+{
+       MSG_BEGIN();
+
+       if (!alarmInit) {
+               MSG_DEBUG("alarm manager is not initialized. Retry once.");
+               MsgAlarmInit();
+               if (!alarmInit) {
+                       MSG_DEBUG("alarm manager is still not initialized. So return error.");
+                       return MSG_ERR_UNKNOWN;
+               }
+       }
+
+       if (alarmmgr_remove_alarm(alarmId) != ALARMMGR_RESULT_SUCCESS) {
+               MSG_DEBUG("alarmmgr_remove_alarm faild.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
diff --git a/externals/MsgDevicedWrapper.cpp b/externals/MsgDevicedWrapper.cpp
new file mode 100644 (file)
index 0000000..005aa77
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+
+#include <dd-display.h>
+
+#include "MsgDebug.h"
+#include "MsgMutex.h"
+#include "MsgGconfWrapper.h"
+#include "MsgDevicedWrapper.h"
+
+int g_lock_cnt = 0;
+Mutex mx;
+
+void MsgDisplayLock()
+{
+       MSG_BEGIN();
+
+       int ret = 0;
+
+       mx.lock();
+
+       if (g_lock_cnt <= 0) {
+               ret = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
+               if (ret < 0) {
+                       MSG_DEBUG("display_lock_state() is failed [%d]", ret);
+               }
+       }
+
+       g_lock_cnt++;
+
+       mx.unlock();
+
+       MSG_DEBUG("Display lock count = [%d]", g_lock_cnt);
+
+       MSG_END();
+}
+
+
+void MsgDisplayUnlock()
+{
+       MSG_BEGIN();
+
+       int ret = 0;
+
+       mx.lock();
+
+       g_lock_cnt--;
+
+       MSG_DEBUG("Display lock count = [%d]", g_lock_cnt);
+
+       if (g_lock_cnt <= 0) {
+               ret = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
+               if (ret < 0) {
+                       MSG_DEBUG("display_lock_state() is failed [%d]", ret);
+               }
+       }
+
+       mx.unlock();
+
+       MSG_END();
+}
+
+
+void MsgChangePmState()
+{
+       MSG_BEGIN();
+       int callStatus = 0;
+
+       callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
+       MSG_DEBUG("Call Status = %d", callStatus);
+
+       if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
+               MSG_DEBUG("Call is activated. Do not turn on the lcd.");
+       } else {
+               MSG_DEBUG("Call is not activated. Turn on the lcd.");
+               display_change_state(LCD_NORMAL);
+       }
+
+       MSG_END();
+}
diff --git a/externals/MsgLbs.cpp b/externals/MsgLbs.cpp
new file mode 100755 (executable)
index 0000000..7ffe63d
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+
+#include "MsgDebug.h"
+
+extern "C"
+{
+       #include <lbs_agps.h>
+}
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
+
+void MsgLbsSms(const char *msgBody, int msgSize) {
+
+       int ret = LBS_AGPS_ERROR_NONE;
+
+       ret = lbs_agps_sms(msgBody, msgSize);
+
+       if (ret != LBS_AGPS_ERROR_NONE)
+               MSG_DEBUG("lbs_agps_sms failed. [%d]", ret);
+}
+
+
+void MsgLbsWapPush(const char *pushHeader, const char *pushBody, int pushBodySize) {
+
+       int ret = LBS_AGPS_ERROR_NONE;
+
+       ret = lbs_agps_wap_push(pushHeader, pushBody, pushBodySize);
+
+       if (ret != LBS_AGPS_ERROR_NONE)
+               MSG_DEBUG("lbs_agps_wap_push failed. [%d]", ret);
+}
diff --git a/externals/MsgNotificationWrapper.cpp b/externals/MsgNotificationWrapper.cpp
new file mode 100755 (executable)
index 0000000..c01100b
--- /dev/null
@@ -0,0 +1,2804 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+
+#include "MsgDebug.h"
+#include "MsgCppTypes.h"
+#include "MsgDrmWrapper.h"
+#include "MsgContact.h"
+#include "MsgStorageTypes.h"
+#include "MsgUtilFile.h"
+#include "MsgUtilFunction.h"
+#include "MsgUtilStorage.h"
+#include "MsgAlarm.h"
+#include "MsgGconfWrapper.h"
+#include "MsgNotificationWrapper.h"
+#include "MsgSoundPlayer.h"
+#include "MsgDevicedWrapper.h"
+#include <libintl.h>
+#include <locale.h>
+#include <stdarg.h>
+
+extern "C"
+{
+#include <app_control.h>
+#include <notification.h>
+#include <notification_internal.h>
+#include <feedback.h>
+#include <badge.h>
+}
+
+
+/*======================================================================================*/
+/*                                                             VARIABLES AND STRUCTURES                                                                */
+/*======================================================================================*/
+
+int g_alarmId = 0;
+bool bFeedbackInit;
+
+GList *msg_report_notification_list;
+
+
+typedef struct _msg_noti_info_s
+{
+       msg_notification_type_t                 type;
+       int                     id;
+       int                     layout;
+       int                     count;
+       time_t          time;
+       char            sender[MSG_NOTI_TEXT_LEN_S];
+       char            text[MSG_NOTI_TEXT_LEN];
+       char            number[MSG_NOTI_TEXT_LEN_S];
+       char            imagePath[MAX_IMAGE_PATH_LEN + 1];              /**< Indicates the image path of contact. */
+       int                     applist;
+       app_control_h           svc_h;
+       msg_message_id_t        msg_id;
+       unsigned char           extra_data;
+       int             sim_idx;
+}MSG_NOTI_INFO_S;
+
+typedef struct _report_notification_s
+{
+       int priv_id;
+       char addressVal[MAX_ADDRESS_VAL_LEN+1];
+}report_notification_s;
+
+/*======================================================================================*/
+/*                                                                     FUNCTION DEFINE                                                                         */
+/*======================================================================================*/
+
+notification_h getHandle(int *noti_id);
+
+int getPrivId(msg_notification_type_t noti_type, int sim_idx);
+void updatePrivId(msg_notification_type_t noti_type, int noti_id, int sim_idx);
+
+void createInfoData(MSG_NOTI_INFO_S *noti_info, MSG_MESSAGE_INFO_S *msg_info); // For addNoti()
+void createInfoData(MSG_NOTI_INFO_S *noti_info, bool bTicker); // For refreshNoti()
+void clearInfoData(notification_h noti_h, MSG_NOTI_INFO_S *noti_info);
+
+msg_error_t getLatestMsgInfo(MSG_NOTI_INFO_S *noti_info, bool isForInstantMessage);
+
+void setProperty(notification_h noti_h, MSG_NOTI_INFO_S *noti_info);
+void setTextDomain(notification_h noti_h, msg_notification_type_t noti_type);
+void setText(notification_h noti_h, MSG_NOTI_INFO_S *noti_info);
+void setIcon(notification_h noti_h, MSG_NOTI_INFO_S *noti_info);
+void setPkgName(notification_h noti_h, msg_notification_type_t noti_type);
+void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail);
+
+void setNotification(notification_h noti_h, MSG_NOTI_INFO_S *noti_info, bool bFeedback);
+
+void MsgDeleteNotiCb(void *data);
+void MsgRefreshNotiCb(void *data);
+
+bool isExistAddressInReportTable(const char *addr);
+
+// Wrapper
+void createServiceHandle(app_control_h *svc_h);
+void setServiceAppId(app_control_h svc_h, const char* app_id);
+void setServiceOperation(app_control_h svc_h, const char* operation);
+void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val);
+void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val);
+void setServicePackageName(app_control_h svc_h, const char* pkg_name);
+void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data);
+
+void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir);
+void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key);
+void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time);
+void setNotiTime(notification_h noti_h, time_t time);
+void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path);
+void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path);
+void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path);
+void setFlashNoti(void);
+
+char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text);
+
+
+// Alarm
+void MsgNotiSoundRepeatAlarmCB(int alarmId);
+void MsgSoundCreateRepeatAlarm(int RepeatTime);
+void MsgSoundSetRepeatAlarm();
+
+void sendMsgReplyPopup(MSG_NOTI_INFO_S *noti_info);
+
+/*======================================================================================*/
+/*                                                             FUNCTION IMPLEMENTATION                                                                 */
+/*======================================================================================*/
+
+
+msg_error_t MsgInsertNotification(MSG_MESSAGE_INFO_S *msg_info)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+       msg_notification_type_t noti_type;
+
+       switch (msg_info->msgType.subType)
+       {
+#ifdef MSG_NOTI_INTEGRATION
+               case MSG_NORMAL_SMS :
+               case MSG_CB_SMS :
+                       {
+                               if (msg_info->msgType.classType == MSG_CLASS_0) {
+                                       noti_type = MSG_NOTI_TYPE_CLASS0;
+                               } else {
+                                       noti_type = MSG_NOTI_TYPE_NORMAL;
+                               }
+                       }
+                       break;
+#else
+               case MSG_NORMAL_SMS :
+                       {
+                               if (msg_info->msgType.classType == MSG_CLASS_0) {
+                                       noti_type = MSG_NOTI_TYPE_CLASS0;
+                               } else if (msg_info->msgType.classType == MSG_CLASS_2) {
+                                       noti_type = MSG_NOTI_TYPE_SIM;
+                               } else {
+                                       noti_type = MSG_NOTI_TYPE_NORMAL;
+                               }
+                       }
+                       break;
+               case MSG_CB_SMS :
+                       noti_type = MSG_NOTI_TYPE_CB;
+                       break;
+#endif
+               case MSG_MWI_FAX_SMS :
+               case MSG_MWI_EMAIL_SMS :
+               case MSG_MWI_OTHER_SMS :
+                       noti_type = MSG_NOTI_TYPE_MWI;
+                       break;
+               case MSG_MWI_VOICE_SMS :
+                       noti_type = MSG_NOTI_TYPE_VOICE_1;
+                       break;
+               case MSG_MWI_VOICE2_SMS :
+                       noti_type = MSG_NOTI_TYPE_VOICE_2;
+                       break;
+               case MSG_STATUS_REPORT_SMS :
+                       noti_type = MSG_NOTI_TYPE_SMS_DELIVERY_REPORT;
+                       break;
+               case MSG_DELIVERYIND_MMS :
+                       noti_type = MSG_NOTI_TYPE_MMS_DELIVERY_REPORT;
+                       break;
+               case MSG_READORGIND_MMS :
+                       noti_type = MSG_NOTI_TYPE_MMS_READ_REPORT;
+                       break;
+               default :
+               {
+#ifdef MSG_NOTI_INTEGRATION
+                       noti_type = MSG_NOTI_TYPE_NORMAL;
+#else
+                       if (msg_info->msgType.classType == MSG_CLASS_2) {
+                               noti_type = MSG_NOTI_TYPE_SIM;
+                       } else {
+                               noti_type = MSG_NOTI_TYPE_NORMAL;
+                       }
+#endif
+               }
+               break;
+       }
+
+       MSG_DEBUG("Notification type = [%d]", noti_type);
+
+       switch (noti_type)
+       {
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_SIM :
+               case MSG_NOTI_TYPE_CB :
+                       err = MsgRefreshNotification(noti_type, true, true);
+                       break;
+               case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT :
+               case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT :
+               case MSG_NOTI_TYPE_MMS_READ_REPORT :
+                       err = MsgAddReportNotification(noti_type, msg_info);
+                       break;
+               case MSG_NOTI_TYPE_VOICE_1 :
+               case MSG_NOTI_TYPE_VOICE_2 :
+               case MSG_NOTI_TYPE_MWI :
+               case MSG_NOTI_TYPE_CLASS0 :
+                       err = MsgAddNotification(noti_type, msg_info);
+                       break;
+               default :
+                       MSG_DEBUG("No matching type [%d]");
+                       break;
+       }
+
+       MSG_END();
+
+       return err;
+
+}
+
+msg_error_t MsgDeleteReportNotification(const char *addr)
+{
+       MSG_BEGIN();
+
+       msg_error_t msg_err = MSG_SUCCESS;
+       notification_h noti_h = NULL;
+       bool bNotification = true;
+
+       MSG_NOTI_INFO_S noti_info;
+       memset(&noti_info, 0x00, sizeof(MSG_NOTI_INFO_S));
+
+       if (MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bNotification) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgSettingGetBool is failed.");
+       }
+
+       if (bNotification == false) {
+               MSG_DEBUG("Msg Alert notification is off.");
+               return msg_err;
+       }
+
+       char normalAddr[MAX_ADDRESS_VAL_LEN+1];
+       unsigned int list_length = g_list_length(msg_report_notification_list);
+       bool isDelete = false;
+
+       MSG_DEBUG("list length [%d]", list_length);
+
+       if (list_length > 0) {
+               GList *iter = g_list_first(msg_report_notification_list);
+
+               while (iter != NULL)
+               {
+                       isDelete = false;
+                       report_notification_s *info = (report_notification_s*)(iter->data);
+                       if (info == NULL) {
+                               MSG_DEBUG("info is NULL!");
+                               return MSG_ERR_UNKNOWN;
+                       }
+
+                       MSG_DEBUG("list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
+
+                       noti_h = notification_load(NULL, info->priv_id);
+                       if (noti_h == NULL)
+                       {
+                               MSG_DEBUG("notification with priv_id [%d] is NULL", info->priv_id);
+                               isDelete = true;
+                       } else {
+                               memset(normalAddr, 0x00, sizeof(normalAddr));
+                               MsgConvertNumber(info->addressVal, normalAddr, sizeof(normalAddr));
+                               MSG_DEBUG("normalized number = %s", normalAddr);
+
+                               if (g_str_has_suffix(addr, normalAddr)) {
+                                       if (notification_delete(noti_h) == NOTIFICATION_ERROR_NONE) {
+                                               MSG_DEBUG("delete report notification address [%s]", info->addressVal);
+                                               isDelete = true;
+                                       }
+                                       else {
+                                               MSG_DEBUG("delete notification failed");
+                                       }
+                               }
+
+                               notification_free(noti_h);
+                               noti_h = NULL;
+                       }
+
+                       iter = g_list_next(iter);
+
+                       if (isDelete) {
+                               msg_report_notification_list = g_list_remove(msg_report_notification_list, (void *)info);
+                               if(info) {
+                                       delete info;
+                                       info = NULL;
+                               }
+                       }
+               }
+       }
+
+       MSG_END();
+
+       return msg_err;
+}
+
+msg_error_t MsgAddReportNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
+{
+       msg_error_t msg_err = MSG_SUCCESS;
+       notification_h noti_h = NULL;
+
+       MSG_NOTI_INFO_S noti_info;
+       memset(&noti_info, 0x00, sizeof(MSG_NOTI_INFO_S));
+
+       report_notification_s *info = new report_notification_s;
+       memset(info, 0x00, sizeof(report_notification_s));
+
+       noti_info.type = noti_type;
+
+       createInfoData(&noti_info, msg_info);
+
+       noti_h = getHandle(&noti_info.id);
+
+       if (noti_h == NULL) {
+               MSG_DEBUG("Notification handle is NULL");
+               msg_err = MSG_ERR_NULL_POINTER;
+               goto __END_OF_REFRESH_NOTI;
+       }
+
+       setNotification(noti_h, &noti_info, true);
+
+       info->priv_id = noti_info.id;
+       snprintf(info->addressVal, sizeof(info->addressVal), "%s", msg_info->addressList->addressVal);
+       msg_report_notification_list = g_list_append(msg_report_notification_list, (void *)info);
+       MSG_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
+
+__END_OF_REFRESH_NOTI :
+       clearInfoData(noti_h, &noti_info);
+       return msg_err;
+}
+
+msg_error_t MsgRefreshNotification(msg_notification_type_t noti_type, bool bFeedback, bool bTicker)
+{
+       notification_h noti_h = NULL;
+       msg_error_t msg_err = MSG_SUCCESS;
+       bool bNotification = true;
+       bool bReplyPopup = false;
+
+       MSG_NOTI_INFO_S noti_info;
+       memset(&noti_info, 0x00, sizeof(MSG_NOTI_INFO_S));
+
+       noti_info.type = noti_type;
+
+       noti_info.id = getPrivId(noti_info.type, -1);
+
+       msg_err = getLatestMsgInfo(&noti_info, false);
+
+       if (msg_err != MSG_SUCCESS) {
+               MSG_DEBUG("getLatestMsgInfo() err = [%d]", msg_err);
+               goto __END_OF_REFRESH_NOTI;
+       }
+
+       if (bTicker) {
+               msg_err = MsgInsertInstantMessage(noti_type);
+
+               if (msg_err != MSG_SUCCESS) {
+                       MSG_DEBUG(" MsgInsertInstantMessage() err = [%d]", msg_err);
+                       goto __END_OF_REFRESH_NOTI;
+               }
+       }
+
+       if (MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bNotification) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgSettingGetBool is failed.");
+       }
+
+       if (bNotification == false) {
+               MSG_DEBUG("Msg Alert notification is off.");
+               return msg_err;
+       }
+
+       createInfoData(&noti_info, bTicker);
+
+       noti_h = getHandle(&noti_info.id);
+
+       if (noti_h == NULL) {
+               MSG_DEBUG("Notification handle is NULL");
+               msg_err = MSG_ERR_NULL_POINTER;
+               goto __END_OF_REFRESH_NOTI;
+       }
+
+       setNotification(noti_h, &noti_info, bFeedback);
+
+       if (MsgSettingGetBool(VCONFKEY_MESSAGE_POPUP_DISPLAY_ENABLE , &bReplyPopup) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgSettingGetBool is failed.");
+       }
+
+       if (bReplyPopup == true && bFeedback == true && noti_info.type == MSG_NOTI_TYPE_NORMAL) {
+               MSG_DEBUG("Msg reply popup is on.");
+               sendMsgReplyPopup(&noti_info);
+       }
+
+__END_OF_REFRESH_NOTI :
+       clearInfoData(noti_h, &noti_info);
+       return msg_err;
+}
+
+
+msg_error_t MsgAddNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
+{
+       msg_error_t msg_err = MSG_SUCCESS;
+       notification_h noti_h = NULL;
+
+       MSG_NOTI_INFO_S noti_info = {0,};
+
+       noti_info.type = noti_type;
+
+       createInfoData(&noti_info, msg_info);
+
+       noti_h = getHandle(&noti_info.id);
+
+       if (noti_h == NULL) {
+               MSG_DEBUG("Notification handle is NULL");
+               msg_err = MSG_ERR_NULL_POINTER;
+               goto __END_OF_ADD_NOTI;
+       }
+
+       setNotification(noti_h, &noti_info, true);
+
+__END_OF_ADD_NOTI :
+       clearInfoData(noti_h, &noti_info);
+       return msg_err;
+}
+
+
+void MsgRefreshAllNotification(bool bWithSimNoti, bool bFeedback, bool bTickerNoti)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+//     MsgDeleteNotification(MSG_NOTI_TYPE_SIM);
+
+#ifdef MSG_NOTI_INTEGRATION
+       err = MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, bFeedback, bTickerNoti);
+       if (err != MSG_SUCCESS)
+               MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_NORMAL, err);
+#else
+       err = MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, bFeedback, bTickerNoti);
+       if (err != MSG_SUCCESS)
+               MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_NORMAL, err);
+
+       err = MsgRefreshNotification(MSG_NOTI_TYPE_CB, bFeedback, bTickerNoti);
+       if (err != MSG_SUCCESS)
+               MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_CB, err);
+
+       if (bWithSimNoti) {
+               err = MsgRefreshNotification(MSG_NOTI_TYPE_SIM, bFeedback, bTickerNoti);
+               if (err != MSG_SUCCESS)
+                       MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_SIM, err);
+       }
+#endif
+
+       err = MsgRefreshNotification(MSG_NOTI_TYPE_FAILED, bFeedback, bTickerNoti);
+       if (err != MSG_SUCCESS)
+               MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_FAILED, err);
+
+       MSG_END();
+}
+
+
+void MsgDeleteNotification(msg_notification_type_t noti_type)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       if (noti_type == MSG_NOTI_TYPE_ALL) {
+
+               noti_err = notification_delete_all_by_type(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI);
+
+       } else if (noti_type == MSG_NOTI_TYPE_VOICE_1 || noti_type == MSG_NOTI_TYPE_VOICE_2 || noti_type == MSG_NOTI_TYPE_SIM) {
+               int notiId = 0;
+
+               notiId = getPrivId(noti_type, -1);
+               MSG_DEBUG("deleted notification ID = [%d] Type = [%d]", notiId, noti_type);
+
+               if (notiId > 0)
+                       noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiId);
+
+       } else {
+               MSG_DEBUG("No matching type [%d]", noti_type);
+       }
+
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_delete_all_by_type noti_err [%d]", noti_err);
+       }
+
+       updatePrivId(noti_type, 0, -1);
+}
+
+
+bool isExistAddressInReportTable(const char *addr)
+{
+       char sqlQuery[MAX_QUERY_LEN+1];
+       char normalAddr[MAX_ADDRESS_VAL_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
+       int rowCnt = 0;
+
+       memset(normalAddr, 0x00, sizeof(normalAddr));
+       MsgConvertNumber(addr, normalAddr, sizeof(normalAddr));
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s'", MSGFW_SMS_REPORT_TABLE_NAME, normalAddr);
+       if (dbHandle->getTable(sqlQuery, &rowCnt) == MSG_SUCCESS) {
+               dbHandle->freeTable();
+               return true;
+       }
+
+       dbHandle->freeTable();
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s'", MSGFW_REPORT_TABLE_NAME, normalAddr);
+       if (dbHandle->getTable(sqlQuery, &rowCnt) == MSG_SUCCESS) {
+               dbHandle->freeTable();
+               return true;
+       }
+
+       dbHandle->freeTable();
+
+       return false;
+}
+
+
+void MsgInitReportNotiList()
+{
+       MSG_BEGIN();
+
+       msg_report_notification_list = NULL;
+
+       notification_h noti = NULL;
+       notification_list_h noti_list = NULL;
+       notification_list_h head_noti_list = NULL;
+       int noti_err = NOTIFICATION_ERROR_NONE;
+       bundle *b = NULL;
+
+       noti_err = notification_get_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
+       if(noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("notification_get_list() is failed!!");
+               return;
+       }
+
+       head_noti_list = noti_list;
+
+       while (noti_list != NULL) {
+               noti = notification_list_get_data(noti_list);
+
+               char tempAddr[MAX_ADDRESS_VAL_LEN+1];
+               memset(tempAddr, 0x00, sizeof(tempAddr));
+
+               noti_err  = notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &b);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("notification_get_excute_option() failed!!");
+                       break;
+               }
+
+               const char *bundle_addr = bundle_get_val(b, "address");
+
+               if (bundle_addr != NULL) {
+                       if (isExistAddressInReportTable(bundle_addr)) {
+                               report_notification_s *info = new report_notification_s;
+                               memset(info, 0x00, sizeof(report_notification_s));
+
+                               notification_get_id(noti, NULL, &(info->priv_id));
+                               snprintf(info->addressVal, sizeof(info->addressVal), "%s", bundle_addr);
+
+                               msg_report_notification_list = g_list_append(msg_report_notification_list, (void *)info);
+                               MSG_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
+                       }
+               }
+
+               noti_list = notification_list_get_next(noti_list);
+       }
+
+       if (head_noti_list)
+               notification_free_list(head_noti_list);
+
+       MSG_END();
+}
+
+
+msg_error_t MsgInitNoti()
+{
+       bool bNotiSvcReady = false;
+
+       bNotiSvcReady = notification_is_service_ready();
+
+       if (bNotiSvcReady == true) {
+               MSG_DEBUG("Notification server is available");
+#ifndef MSG_NOTI_INTEGRATION
+               MsgDeleteNotification(MSG_NOTI_TYPE_SIM);
+#endif
+               MsgRefreshAllNotification(false, true, true);           // On Booting
+               MsgInitReportNotiList();
+       }
+       else {
+               MSG_DEBUG("Notification server is not available. Init is defered");
+#ifndef MSG_NOTI_INTEGRATION
+               msg_notification_type_t *delNotiType = (msg_notification_type_t *)calloc(1, sizeof(msg_notification_type_t));
+               *delNotiType = MSG_NOTI_TYPE_SIM;
+               notification_add_deferred_task(MsgDeleteNotiCb, (void *)delNotiType);
+#endif
+               notification_add_deferred_task(MsgRefreshNotiCb, (void *)NULL);
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDeleteNoti(msg_notification_type_t noti_type)
+{
+       bool bNotiSvcReady = false;
+
+       msg_notification_type_t *delNotiType = (msg_notification_type_t *)calloc(1, sizeof(msg_notification_type_t));
+       *delNotiType = noti_type;
+
+       bNotiSvcReady = notification_is_service_ready();
+
+       if (bNotiSvcReady == true) {
+               MSG_DEBUG("Notification server is available");
+               MsgDeleteNotiCb((void *)delNotiType);
+       } else {
+               MSG_DEBUG("Notification server is not available. Delete is defered");
+               notification_add_deferred_task(MsgDeleteNotiCb, (void *)delNotiType);
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
+{
+
+       MSG_DEBUG("pTickerMsg=[%s], pLocaleTickerMsg=[%s]", pTickerMsg, pLocaleTickerMsg);
+       MSG_DEBUG("play feedback=[%d], msgId=[%d]", bPlayFeedback, msgId);
+
+       MsgChangePmState();
+
+       char *notiMsg = NULL;
+       bool bTicker = false;
+
+       notiMsg = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, pLocaleTickerMsg);
+       MSG_DEBUG("notiMsg %s", notiMsg);
+
+       if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) != 0 &&
+               g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) != 0 &&
+               g_strcmp0(pLocaleTickerMsg, MESSAGE_RETRIEVED) != 0) {
+               if (g_strcmp0(pLocaleTickerMsg, notiMsg) == 0) {
+                       notification_status_message_post(pTickerMsg);
+               } else {
+                       notification_status_message_post(notiMsg);
+               }
+       } else {
+               //Show ticker popup for sending failed msg.
+               bTicker = true;
+       }
+
+       if (notiMsg) {
+               free(notiMsg);
+               notiMsg = NULL;
+       }
+
+       if (bPlayFeedback) {
+               if (msgId > 0 && \
+                       (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) == 0 || g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) == 0))
+               {
+                       msg_error_t err = MSG_SUCCESS;
+                       err = MsgRefreshNotification(MSG_NOTI_TYPE_FAILED, true, bTicker);
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgRefreshFailedNoti err=[%d]", err);
+                       }
+               } else if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SIM_MESSAGE_FULL) == 0) {
+                       msg_error_t err = MSG_SUCCESS;
+                       err = MsgRefreshNotification(MSG_NOTI_TYPE_SIM_FULL, true, false);
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgRefreshSimFullNoti err=[%d]", err);
+                       }
+               }
+               else {
+                       MsgSoundPlayer::instance()->MsgSoundPlayStart(NULL, MSG_SOUND_PLAY_DEFAULT);
+               }
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt)
+{
+       MSG_DEBUG("Start to set badge to [%d].", unreadMsgCnt);
+
+       int err = BADGE_ERROR_NONE;
+       bool exist = false;
+
+       err = badge_is_existing(MSG_DEFAULT_APP_ID, &exist);
+
+       if (err != BADGE_ERROR_NONE) {
+               MSG_DEBUG("Fail to badge_is_existing : %d", err);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       if (!exist) {
+               /* create badge */
+               err = badge_new(MSG_DEFAULT_APP_ID);
+               if (err != BADGE_ERROR_NONE) {
+                       MSG_DEBUG("Fail to badge_new : %d", err);
+                       return MSG_ERR_UNKNOWN;
+               }
+       }
+
+       err = badge_set_count(MSG_DEFAULT_APP_ID, unreadMsgCnt);
+
+       if (err != BADGE_ERROR_NONE) {
+               MSG_DEBUG("Fail to badge_set_count : %d", err);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgRefreshNotiCb(void *data)
+{
+       MsgRefreshAllNotification(false, true, true);
+       MsgInitReportNotiList();
+
+       if (data) {
+               free(data);
+               data = NULL;
+       }
+
+       return;
+}
+
+
+void MsgDeleteNotiCb(void *data)
+{
+       //CID 47261: Moved null check to begining.
+       if (data) {
+               msg_notification_type_t delNotiType = *(msg_notification_type_t *)data;
+
+               MsgDeleteNotification(delNotiType);
+
+               free(data);
+               data = NULL;
+       }
+
+       return;
+}
+
+
+notification_h getHandle(int *noti_id)
+{
+       notification_h noti_h = NULL;
+
+       if (*noti_id > 0) {
+               MSG_DEBUG("Notification load");
+               noti_h = notification_load(NULL, *noti_id);
+               if (noti_h == NULL)
+                       MSG_DEBUG("notification_load is failed.");
+       }
+
+       if (noti_h == NULL) {
+               MSG_DEBUG("Notification create");
+               noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
+               if (noti_h == NULL) {
+                       MSG_DEBUG("notification_create is failed.");
+                       return NULL;
+               }
+
+               *noti_id = 0;
+       }
+
+       return noti_h;
+}
+
+
+int getPrivId(msg_notification_type_t noti_type, int sim_idx)
+{
+       MSG_BEGIN();
+
+       int noti_id = 0;
+
+       switch (noti_type)
+       {
+#ifdef MSG_NOTI_INTEGRATION
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_SIM :
+               case MSG_NOTI_TYPE_CB :
+                       noti_id = MsgSettingGetInt(NOTIFICATION_PRIV_ID);
+                       break;
+#else
+               case MSG_NOTI_TYPE_NORMAL :
+                       noti_id = MsgSettingGetInt(NOTIFICATION_PRIV_ID);
+                       break;
+               case MSG_NOTI_TYPE_SIM :
+                       noti_id = MsgSettingGetInt(SIM_MSG_NOTI_PRIV_ID);
+                       break;
+               case MSG_NOTI_TYPE_CB :
+                       noti_id = MsgSettingGetInt(CB_NOTI_PRIV_ID);
+                       break;
+#endif
+               case MSG_NOTI_TYPE_FAILED :
+                       noti_id = MsgSettingGetInt(MSG_SENTFAIL_NOTI_ID);
+                       break;
+               case MSG_NOTI_TYPE_VOICE_1 :
+                       {
+                               char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
+                               noti_id = MsgSettingGetInt(keyName);
+                       }
+                       break;
+               case MSG_NOTI_TYPE_VOICE_2 :
+                       {
+                               char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
+                               noti_id = MsgSettingGetInt(keyName);
+                       }
+                       break;
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       noti_id = MsgSettingGetInt(SIM_FULL_NOTI_PRIV_ID);
+                       break;
+               default :
+                       MSG_DEBUG("No matching noti type [%d]", noti_type);
+                       break;
+       }
+
+       MSG_DEBUG("Get noti type = %d, id = %d, sim_idx:%d", noti_type, noti_id, sim_idx);
+
+       MSG_END();
+
+       return noti_id;
+}
+
+
+void updatePrivId(msg_notification_type_t noti_type, int noti_id, int sim_idx)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+       MSG_DEBUG("Update noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
+
+       switch (noti_type)
+       {
+#ifdef MSG_NOTI_INTEGRATION
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_SIM :
+               case MSG_NOTI_TYPE_CB :
+                       err = MsgSettingSetInt(NOTIFICATION_PRIV_ID, noti_id);
+                       break;
+#else
+               case MSG_NOTI_TYPE_NORMAL :
+                       err = MsgSettingSetInt(NOTIFICATION_PRIV_ID, noti_id);
+                       break;
+               case MSG_NOTI_TYPE_SIM :
+                       err = MsgSettingSetInt(SIM_MSG_NOTI_PRIV_ID, noti_id);
+                       break;
+               case MSG_NOTI_TYPE_CB :
+                       err = MsgSettingSetInt(CB_NOTI_PRIV_ID, noti_id);
+                       break;
+#endif
+               case MSG_NOTI_TYPE_FAILED :
+                       err = MsgSettingSetInt(MSG_SENTFAIL_NOTI_ID, noti_id);
+                       break;
+               case MSG_NOTI_TYPE_VOICE_1 :
+                       {
+                               char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
+                               err = MsgSettingSetInt(keyName, noti_id);
+                       }
+                       break;
+               case MSG_NOTI_TYPE_VOICE_2 :
+                       {
+                               char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
+                               err = MsgSettingSetInt(keyName, noti_id);
+                       }
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       err = MsgSettingSetInt(SIM_FULL_NOTI_PRIV_ID, noti_id);
+                       break;
+               default:
+                       MSG_DEBUG("No matching type [%d]", noti_type);
+                       break;
+       }
+
+       if (err != MSG_SUCCESS)
+               MSG_INFO("MsgSettingSetInt fail : noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
+
+       MSG_END();
+}
+
+
+void createInfoData(MSG_NOTI_INFO_S *noti_info, bool bTicker)
+{
+       MSG_BEGIN();
+
+       createServiceHandle(&noti_info->svc_h);
+
+       switch (noti_info->type)
+       {
+               case MSG_NOTI_TYPE_NORMAL :
+                       {
+                               if (noti_info->count > 1) {
+                                       noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
+                               } else {
+                                       noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               }
+
+                               setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                               addServiceExtraData(noti_info->svc_h, "type", "new_msg");
+                               addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+                               addServiceExtraData(noti_info->svc_h, "http://tizen.org/appcontrol/data/notification", "new_message");
+
+                               bool bReplyPopup = false;
+                               if (MsgSettingGetBool(VCONFKEY_MESSAGE_POPUP_DISPLAY_ENABLE , &bReplyPopup) != MSG_SUCCESS) {
+                                       MSG_DEBUG("MsgSettingGetBool is failed.");
+                               }
+
+                               noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER;
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_CB :
+                       {
+                               if (noti_info->count > 1) {
+                                       noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
+                               } else {
+                                       noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               }
+
+                               setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                               addServiceExtraData(noti_info->svc_h, "type", "new_msg");
+                               addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+
+                               if (bTicker)
+                                       noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
+                               else
+                                       noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               if (noti_info->count > 1) {
+                                       noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
+                               } else {
+                                       noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               }
+
+                               setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                               addServiceExtraData(noti_info->svc_h, "type", "new_msg");
+                               addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+
+                               if (bTicker)
+                                       noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
+                               else
+                                       noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_FAILED :
+                       {
+                               noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+
+                               setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                               addServiceExtraData(noti_info->svc_h, "type", "send_failed_msg");
+                               addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+
+                               noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER^NOTIFICATION_DISPLAY_APP_LOCK;
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       {
+                               noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+
+                               setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                               addServiceExtraData(noti_info->svc_h, "sim_list_show", "sim_setting");
+
+                               noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
+                       }
+               break;
+
+               default :
+                       break;
+       }
+
+       MSG_END();
+}
+
+
+void createInfoData(MSG_NOTI_INFO_S *noti_info, MSG_MESSAGE_INFO_S *msg_info)
+{
+       MSG_BEGIN();
+
+       if (msg_info) {
+               noti_info->id = getPrivId(noti_info->type, msg_info->sim_idx);
+               noti_info->msg_id = msg_info->msgId;
+       } else {
+               MSG_DEBUG("msg_info is NULL");
+               return;
+       }
+
+       noti_info->sim_idx = msg_info->sim_idx;
+
+       createServiceHandle(&noti_info->svc_h);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+
+       switch (noti_info->type)
+       {
+               case MSG_NOTI_TYPE_VOICE_1 :
+               case MSG_NOTI_TYPE_VOICE_2 :
+                       {
+                               memset(keyName, 0x00, sizeof(keyName));
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, msg_info->sim_idx);
+                               noti_info->count = MsgSettingGetInt(keyName);
+                               noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               noti_info->time = msg_info->displayTime;
+
+                               memset(keyName, 0x00, sizeof(keyName));
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msg_info->sim_idx);
+                               char *voiceNumber = MsgSettingGetString(keyName);
+                               memset(keyName, 0x00, sizeof(keyName));
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msg_info->sim_idx);
+                               char *voiceAlphaId = MsgSettingGetString(keyName);
+                               char *dialNumber = NULL;
+
+                               MSG_SEC_DEBUG("Voice mail server - alpha id = [%s], default num = [%s]", voiceAlphaId, voiceNumber);
+
+                               if (voiceNumber && strlen(voiceNumber))
+                                       dialNumber = voiceNumber;
+
+                               if (voiceAlphaId && strlen(voiceAlphaId) > 0) {
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", voiceAlphaId);
+                               } else if(dialNumber && strlen(dialNumber) > 0){
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", dialNumber);
+                               }
+
+                               if(dialNumber && strlen(dialNumber) > 0)
+                                       snprintf(noti_info->number, sizeof(noti_info->number), "%s", dialNumber);
+
+                               setServiceAppId(noti_info->svc_h, "org.tizen.call");
+
+                               addServiceExtraData(noti_info->svc_h, "launch-type", "MO");
+
+                               addServiceExtraData(noti_info->svc_h, "number", "VOICEMAIL");
+
+                               char slot_id[5] = {0,};
+                               snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
+                               addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
+
+                               MSG_FREE(voiceNumber);
+                               MSG_FREE(voiceAlphaId);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_MWI :
+               case MSG_NOTI_TYPE_CLASS0 :
+                       {
+                               noti_info->count = 1;
+                               noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               noti_info->time = msg_info->displayTime;
+
+                               if (msg_info->addressList[0].displayName[0] == '\0')
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressList[0].addressVal);
+                               else
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressList[0].displayName);
+
+                               snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressList[0].addressVal);
+
+                               snprintf(noti_info->text, sizeof(noti_info->text), "%s", msg_info->msgText);
+
+                               if (noti_info->type == MSG_NOTI_TYPE_MWI) {
+                                       setServiceAppId(noti_info->svc_h, "org.tizen.call");
+                                       addServiceExtraData(noti_info->svc_h, "launch-type", "MO");
+                                       addServiceExtraData(noti_info->svc_h, "number", "VOICEMAIL");
+
+                                       char slot_id[5] = {0,};
+                                       snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
+                                       addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
+
+                               } else {
+                                       setServiceAppId(noti_info->svc_h, "org.tizen.msg-ui-class0");
+                                       addServiceExtraData(noti_info->svc_h, "type", "new_msg");
+                                       addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+                               }
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT :
+                       {
+                               noti_info->count = 1;
+                               noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               noti_info->time = msg_info->displayTime;
+                               noti_info->extra_data = msg_info->networkStatus;
+
+                               MSG_CONTACT_INFO_S contactInfo;
+                               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                               if (MsgGetContactInfo(&(msg_info->addressList[0]), &contactInfo) != MSG_SUCCESS) {
+                                       MSG_DEBUG("MsgGetContactInfo() fail.");
+                               }
+
+                               snprintf(msg_info->addressList[0].displayName, sizeof(msg_info->addressList[0].displayName), "%s", contactInfo.firstName);
+
+                               if (msg_info->addressList[0].displayName[0] == '\0')
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s",msg_info->addressList[0].addressVal);
+                               else
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s",msg_info->addressList[0].displayName);
+
+                               snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressList[0].addressVal);
+
+                               if (noti_info->msg_id > 0) {
+                                       setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                                       addServiceExtraData(noti_info->svc_h, "type", "new_msg");
+                                       addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+                                       addServiceExtraData(noti_info->svc_h, "address", msg_info->addressList[0].addressVal);
+                               }
+                       }
+                       break;
+               case MSG_NOTI_TYPE_MMS_READ_REPORT :
+               case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT :
+                       {
+                               noti_info->count = 1;
+                               noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
+                               noti_info->time = msg_info->displayTime;
+
+                               MSG_CONTACT_INFO_S contactInfo;
+                               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                               if (MsgGetContactInfo(&(msg_info->addressList[0]), &contactInfo) != MSG_SUCCESS) {
+                                       MSG_DEBUG("MsgGetContactInfo() fail.");
+                               }
+
+                               snprintf(msg_info->addressList[0].displayName, sizeof(msg_info->addressList[0].displayName), "%s", contactInfo.firstName);
+
+                               if (msg_info->addressList[0].displayName[0] == '\0')
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s",msg_info->addressList[0].addressVal);
+                               else
+                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s",msg_info->addressList[0].displayName);
+
+                               snprintf(noti_info->number, sizeof(noti_info->number), "%s",msg_info->addressList[0].addressVal);
+
+                               MsgDbHandler *dbhandler = getDbHandle();
+                               char sqlQuery[MAX_QUERY_LEN+1];
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                               int report_status_type;
+                               int report_status_value;
+
+                               if (noti_info->type == MSG_NOTI_TYPE_MMS_READ_REPORT) {
+                                       report_status_type = MSG_REPORT_TYPE_READ;
+                               } else {
+                                       report_status_type = MSG_REPORT_TYPE_DELIVERY;
+                               }
+
+                               char *normalNum = NULL;
+                               if (msg_info->addressList[0].addressVal[0] != '\0') {
+                                       normalNum = msg_normalize_number(msg_info->addressList[0].addressVal);
+                               }
+
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                               "STATUS "
+                                               "FROM %s "
+                                               "WHERE MSG_ID=%d AND STATUS_TYPE=%d AND ADDRESS_VAL LIKE '%%%s';",
+                                               MSGFW_REPORT_TABLE_NAME, msg_info->msgId, report_status_type, normalNum);
+
+                               MSG_DEBUG("sqlQuery = [%s]", sqlQuery);
+
+                               if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                                       MSG_DEBUG("prepareQuery is failed");
+                                       return;
+                               }
+
+                               if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
+                                       report_status_value = dbhandler->columnInt(0);
+                                       MSG_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
+                               } else {
+                                       MSG_DEBUG("DB Query Result Fail");
+                                       dbhandler->finalizeQuery();
+                                       return;
+                               }
+
+                               dbhandler->finalizeQuery();
+
+                               if (noti_info->msg_id > 0) {
+                                       setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
+                                       addServiceExtraData(noti_info->svc_h, "type", "new_msg");
+                                       addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
+                                       addServiceExtraData(noti_info->svc_h, "address", msg_info->addressList[0].addressVal);
+                               }
+
+                               noti_info->extra_data = (unsigned char)report_status_value;
+                       }
+                       break;
+
+               default:
+                       MSG_DEBUG("No matching type [%d]", noti_info->type);
+                       break;
+       }
+
+       noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
+
+       MSG_END();
+}
+
+
+void clearInfoData(notification_h noti_h, MSG_NOTI_INFO_S *noti_info)
+{
+       MSG_BEGIN();
+
+       if (noti_h) {
+               notification_free(noti_h);
+               noti_h = NULL;
+       }
+
+       if (noti_info->svc_h) {
+               app_control_destroy(noti_info->svc_h);
+               noti_info->svc_h = NULL;
+       }
+
+       MSG_END();
+}
+
+
+void setProperty(notification_h noti_h, MSG_NOTI_INFO_S *noti_info)
+{
+       MSG_BEGIN();
+
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       // set layout
+       noti_err = notification_set_layout(noti_h, (notification_ly_type_e)noti_info->layout);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
+       }
+
+       // set led
+       noti_err = notification_set_led(noti_h, NOTIFICATION_LED_OP_ON, 0x00);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_set_led.");
+       }
+
+       // set execute option
+       bundle *bundle_data = NULL;
+       bundle *reply_msg = NULL;
+
+       app_control_to_bundle(noti_info->svc_h, &bundle_data);
+
+       if (bundle_data == NULL) {
+               MSG_DEBUG("bundle is NULL");
+       }
+
+       // set execute option and property
+       switch (noti_info->type)
+       {
+               case MSG_NOTI_TYPE_NORMAL :
+                       {
+                               if (noti_info->count > 1) {
+                                       notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, bundle_data);
+                                       notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, NULL);
+                               } else {
+                                       if (noti_info->svc_h){ // overwrite bundle key "type"
+                                               //addServiceExtraData(noti_info->svc_h, "type", "reply");
+                                               addServiceExtraData(noti_info->svc_h, "show_list", "list_show");
+
+                                               app_control_to_bundle(noti_info->svc_h, &reply_msg);
+                                       }
+                                       notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
+                                       notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, reply_msg);
+                               }
+
+                               notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_CB :
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               if (noti_info->count > 1) {
+                                       notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, bundle_data);
+                               } else {
+                                       notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
+                               }
+
+                               notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE|NOTIFICATION_PROP_VOLATILE_DISPLAY);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_FAILED :
+                       {
+                               notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
+                               notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       {
+                               notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_VOICE_1 :
+               case MSG_NOTI_TYPE_VOICE_2 :
+               case MSG_NOTI_TYPE_MWI :
+               case MSG_NOTI_TYPE_CLASS0 :
+               case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT :
+               case MSG_NOTI_TYPE_MMS_READ_REPORT :
+               case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT :
+                       {
+                               notification_set_execute_option(noti_h, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, bundle_data);
+                       }
+                       break;
+               default:
+                       MSG_DEBUG("No matching type for notification_set_execute_option() [%d]", noti_info->type);
+                       break;
+       }
+
+       // set applist
+       noti_err = notification_set_display_applist(noti_h, noti_info->applist);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_set_display_applist");
+       }
+
+
+       MSG_END();
+}
+
+
+void setTextDomain(notification_h noti_h, msg_notification_type_t noti_type)
+{
+       MSG_BEGIN();
+
+       setNotiTextDomain(noti_h, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
+       MSG_END();
+}
+
+
+void setText(notification_h noti_h, MSG_NOTI_INFO_S *noti_info)
+{
+       MSG_BEGIN();
+
+       char unreadMsgCntStr[10] = {0,};
+       bool bPreview;
+
+       if (MsgSettingGetBool(MSG_SETTING_PREVIEW, &bPreview) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgSettingGetBool is failed.");
+       }
+
+       // set title and content
+       switch (noti_info->type)
+       {
+#ifdef MSG_NOTI_INTEGRATION
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_CB :
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               if (noti_info->count > 1) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+
+                                       snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
+
+                               } else {
+                                       if (bPreview) {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
+                                       } else {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       }
+                                       setNotiTime(noti_h, noti_info->time);
+                               }
+                       }
+                       break;
+#else
+               case MSG_NOTI_TYPE_NORMAL :
+                       {
+                               if (noti_info->count > 1) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+
+                                       snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
+
+                               } else {
+                                       if (bPreview) {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
+                                       } else {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       }
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+                               }
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_CB :
+                       {
+                               if (noti_info->count > 1) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
+                                       snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+
+                               } else {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+
+                                       if (bPreview) {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
+                                       } else {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       }
+                               }
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               if (noti_info->count > 1) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
+                                       snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
+
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+                               } else {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
+                                       setNotiTime(noti_h, noti_info->time);
+
+                                       if (bPreview) {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
+                                       } else {
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
+                                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                                       }
+                               }
+                       }
+                       break;
+#endif
+               case MSG_NOTI_TYPE_FAILED :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MSG_MESSAGE);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Failed to send message.", FAILED_TO_SEND_MESSAGE);
+                               snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
+                               setNotiTime(noti_h, noti_info->time);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_VOICE_1 :
+               case MSG_NOTI_TYPE_VOICE_2 :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Voicemail", VOICE_MAIL);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                               setNotiTime(noti_h, noti_info->time);
+
+                               if (noti_info->count == 1) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
+                               } else if (noti_info->count > 1) {
+                                       snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
+                               } else {
+                                       MSG_DEBUG("Invalid notification count, [cnt = %d]", noti_info->count);
+                               }
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_MWI :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "MWI Message", NULL);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                               setNotiTime(noti_h, noti_info->time);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_CLASS0 :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+                               setNotiTime(noti_h, noti_info->time);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery report", DELIVERY_MESSAGE);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+
+                               if(noti_info->extra_data == MSG_NETWORK_DELIVER_SUCCESS) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", DELIVERED_MESSAGE);
+                               } else if(noti_info->extra_data == MSG_NETWORK_DELIVER_EXPIRED) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", EXPIRED_MESSAGE);
+                               } else {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deferred", DEFERRED_MESSAGE);
+                               }
+
+                               setNotiTime(noti_h, noti_info->time);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_MMS_READ_REPORT :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Read Report", READ_REPORT_MESSAGE);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+
+                               if (noti_info->extra_data == MSG_READ_REPORT_IS_DELETED) {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deleted", READ_REPORT_DELETE);
+                               }
+                               //CID 45672: noti_info->extra_data in unsigned char but MSG_READ_REPORT_NONE is -1. So the expression is always false
+#if 0
+                               else if (noti_info->extra_data == MSG_READ_REPORT_NONE) {
+                                       //notification free
+                               }
+#endif
+                               else {
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message read", READ_REPORT_READ);
+                               }
+
+                               setNotiTime(noti_h, noti_info->time);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Report", DELIVERY_MESSAGE);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
+
+                               if (noti_info->extra_data == MSG_DELIVERY_REPORT_EXPIRED)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", EXPIRED_MESSAGE);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_REJECTED)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message rejected", REJECTED_MESSAGE);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_DEFERRED)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deferred", DEFERRED_MESSAGE);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNRECOGNISED)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message unrecognised", UNRECOGNISED_MESSAGE);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_INDETERMINATE)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message indeterminate", INDETEMINATE_MESSAGE);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_FORWARDED)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message forwarded", NULL);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNREACHABLE)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message unreachable", UNREACHABLE_MESSAGE);
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_ERROR)
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message error", NULL);
+
+                               //CID 45672: noti_info->extra_data in unsigned char but MSG_READ_REPORT_NONE is -1. So the expression is always false
+#if 0
+                               else if (noti_info->extra_data == MSG_DELIVERY_REPORT_NONE) {
+                                       //notification free
+                               }
+#endif
+                               else
+                                       setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", DELIVERED_MESSAGE);
+
+                               setNotiTime(noti_h, noti_info->time);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       {
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card full", SMS_SIM_CARD_FULL);
+                               setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Not enough memory. Delete some items.", SMS_MESSAGE_MEMORY_FULL);
+                       }
+                       break;
+               default:
+                       MSG_DEBUG("No matching type [%d]", noti_info->type);
+                       break;
+       }
+
+       MSG_END();
+
+}
+
+
+void setIcon(notification_h noti_h, MSG_NOTI_INFO_S *noti_info)
+{
+       MSG_BEGIN();
+
+       switch(noti_info->type)
+       {
+#ifdef MSG_NOTI_INTEGRATION
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_CB :
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                       }
+                       break;
+#else
+               case MSG_NOTI_TYPE_NORMAL :
+                       {
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
+
+                               if (noti_info->count > 1) {
+                                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                               } else {
+                                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_REPLY_ICON_PATH);
+                               }
+                       }
+                       break;
+               case MSG_NOTI_TYPE_CB :
+                       {
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_CB_ICON_PATH);
+                       }
+                       break;
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SIM_ICON_PATH);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_SIM_ICON_PATH);
+                       }
+                       break;
+#endif
+               case MSG_NOTI_TYPE_FAILED :
+                       {
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                       }
+                       break;
+               case MSG_NOTI_TYPE_VOICE_1 :
+               case MSG_NOTI_TYPE_VOICE_2 :
+               case MSG_NOTI_TYPE_MWI :
+                       {
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_VOICE_MSG_STATUS_ICON);
+                               setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_VOICE_ICON_PATH);
+                       }
+                       break;
+               case MSG_NOTI_TYPE_CLASS0 :
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                       break;
+               case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT :
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                       break;
+               case MSG_NOTI_TYPE_MMS_READ_REPORT :
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                       break;
+               case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT :
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                       break;
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                       setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
+                       break;
+               default:
+                       MSG_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
+                       break;
+       }
+
+       MSG_END();
+}
+
+msg_error_t MsgInsertInstantMessage(msg_notification_type_t noti_type)
+{
+       MSG_BEGIN();
+
+       msg_error_t msg_err = MSG_SUCCESS;
+       char *notiMsg = NULL;
+
+       notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
+
+       switch (noti_type)
+       {
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_SIM :
+               case MSG_NOTI_TYPE_CB :
+                         {
+                               MSG_NOTI_INFO_S noti_info;
+                               memset(&noti_info, 0x00, sizeof(MSG_NOTI_INFO_S));
+
+                               noti_info.type = noti_type;
+                               msg_err = getLatestMsgInfo(&noti_info, true);
+
+                               if (msg_err  == MSG_SUCCESS)
+                               {
+                                       MSG_DEBUG("Unread count [%d]", noti_info.count);
+                                       if (noti_info.count == 1) {
+                                               MSG_DEBUG("noti_info.sender [%s]",noti_info.sender);
+                                               setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE,  noti_info.sender, NULL);
+                                               setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.text, NULL);
+                                       }
+                                       else if (noti_info.count  > 1) {
+                                               gchar *cnt_string = g_strdup_printf("%i", noti_info.count);
+
+                                               notiMsg = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, NEW_MESSAGES);
+                                               gchar *outString = g_strconcat(cnt_string, " ", notiMsg, NULL);
+                                               setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, outString, NULL);
+                                               setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.sender, NULL);
+                                               g_free(outString);
+                                               g_free(cnt_string);
+                                       }
+                                       setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                               }
+
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_FAILED:
+                        {
+                               notiMsg = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, FAILED_TO_SEND_MESSAGE);
+                               setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, notiMsg, NULL);
+                               setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
+                        }
+                        break;
+
+               default:
+                       MSG_DEBUG("No matching type for MsgNotiType%d]", noti_type);
+                       goto _END_OF_INSTANT_NOTI;
+                       break;
+
+       }
+
+       notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER);
+       notification_post(noti);
+
+_END_OF_INSTANT_NOTI:
+
+       notification_delete(noti);
+
+       if (notiMsg) {
+               free(notiMsg);
+               notiMsg = NULL;
+       }
+
+       if (noti) {
+               notification_free(noti);
+               noti = NULL;
+       }
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
+
+void setPkgName(notification_h noti_h, msg_notification_type_t noti_type)
+{
+       MSG_BEGIN();
+
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       switch (noti_type)
+       {
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_CB :
+               case MSG_NOTI_TYPE_SIM :
+               case MSG_NOTI_TYPE_FAILED :
+               case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT :
+               case MSG_NOTI_TYPE_MMS_READ_REPORT :
+               case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT :
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       {
+                               noti_err = notification_set_pkgname(noti_h, MSG_DEFAULT_APP_ID);
+                               if (noti_err != NOTIFICATION_ERROR_NONE)
+                                       MSG_DEBUG("notification_set_pkgname() is failed, [%d]", noti_err);
+                       }
+                       break;
+               default:
+                       MSG_DEBUG("No matching type for notification_set_pkgname() [%d]", noti_type);
+                       break;
+       }
+
+       MSG_END();
+}
+
+
+void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail)
+{
+       MSG_BEGIN();
+
+       bool bBlockingMode = false;
+
+       MSG_ADDRESS_INFO_S addrInfo;
+       memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+       MSG_CONTACT_INFO_S contactInfo;
+       memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+       if (addressVal != NULL) {
+               snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", addressVal);
+               // Get Contact Info
+               if (MsgGetContactInfo(&addrInfo, &contactInfo) != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgGetContactInfo() fail.");
+               }
+               bBlockingMode = checkBlockingMode(addressVal, NULL);
+       } else {
+               MSG_DEBUG("addressVal is NULL.");
+       }
+
+       char *msg_tone_file_path = NULL;
+       AutoPtr<char> buf(&msg_tone_file_path);
+
+       MsgSoundPlayer::instance()->MsgGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
+
+       MSG_SEC_DEBUG("Sound File [%s]", msg_tone_file_path);
+
+       bool bPlaySound = false;
+       bool bPlayVibration = false;
+       bool bOnCall = false;
+
+       MsgSoundPlayer::instance()->MsgGetPlayStatus(bVoiceMail, &bPlaySound, &bPlayVibration, &bOnCall);
+
+       if (!bBlockingMode) { // check blocking mode.
+               if (bPlaySound) {
+                       if (msg_tone_file_path)
+                               setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_USER_DATA, msg_tone_file_path);
+                       else
+                               setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
+               } else {
+                       setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
+               }
+
+               if (bPlayVibration) {
+                       if (contactInfo.vibrationPath[0] == '\0')
+                               setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
+                       else
+                               setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_USER_DATA, contactInfo.vibrationPath);
+               } else {
+                       setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
+               }
+       } else {
+               setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
+               setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
+       }
+       MSG_END();
+}
+
+
+void setNotification(notification_h noti_h, MSG_NOTI_INFO_S *noti_info, bool bFeedback)
+{
+       MSG_BEGIN();
+
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       setPkgName(noti_h, noti_info->type);
+
+       setProperty(noti_h, noti_info);
+
+       setTextDomain(noti_h, noti_info->type);
+
+       setText(noti_h, noti_info);
+
+       setIcon(noti_h, noti_info);
+
+       if (bFeedback) {
+               setFlashNoti();
+
+               if (noti_info->type == MSG_NOTI_TYPE_VOICE_1 || noti_info->type == MSG_NOTI_TYPE_VOICE_2)
+                       setSoundAndVibration(noti_h, noti_info->number, true);
+               else
+                       setSoundAndVibration(noti_h, noti_info->number, false);
+
+       } else {
+               setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
+               setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
+       }
+
+       if (noti_info->id > 0) {
+               MSG_DEBUG("Notification update");
+               noti_err = notification_update(noti_h);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_update");
+               }
+       } else {
+               MSG_DEBUG("Notification insert");
+               noti_err = notification_insert(noti_h, &noti_info->id);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_insert");
+               }
+
+               updatePrivId(noti_info->type, noti_info->id, noti_info->sim_idx);
+       }
+
+       MSG_END();
+}
+
+
+msg_error_t getLatestMsgInfo(MSG_NOTI_INFO_S *noti_info, bool isForInstantMessage)
+{
+       MSG_BEGIN();
+
+       MsgDbHandler *dbhandler = getDbHandle();
+       int noti_err = NOTIFICATION_ERROR_NONE;
+       msg_error_t msg_err = MSG_SUCCESS;
+
+       switch (noti_info->type)
+       {
+#ifdef MSG_NOTI_INTEGRATION
+               case MSG_NOTI_TYPE_NORMAL :
+               case MSG_NOTI_TYPE_CB :
+               case MSG_NOTI_TYPE_SIM :
+#else
+               case MSG_NOTI_TYPE_NORMAL :
+#endif
+                       {
+                               int smsUnreadCnt = 0;
+                               int mmsUnreadCnt = 0;
+
+                               char sqlQuery[MAX_QUERY_LEN+1];
+                               MSG_MAIN_TYPE_T mainType;
+                               MSG_SUB_TYPE_T subType;
+
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+#ifdef MSG_NOTI_INTEGRATION
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.SUB_TYPE "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
+                                               "AND B.STORAGE_ID = %d  "
+                                               "GROUP BY A.ADDRESS_VAL "
+                                               "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_INBOX_ID, MSG_CBMSGBOX_ID,
+                                               MSG_STORAGE_PHONE);
+#else
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.SUB_TYPE "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
+                                               "AND B.STORAGE_ID = %d  "
+                                               "GROUP BY A.ADDRESS_VAL "
+                                               "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_INBOX_ID,
+                                               MSG_STORAGE_PHONE);
+#endif
+                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+
+                               int rowCnt = 0;
+                               int index = 2;
+
+                               msg_err = dbhandler->getTable(sqlQuery, &rowCnt);
+                               MSG_DEBUG("getTable() ret=[%d], rowCnt=[%d]", msg_err, rowCnt);
+
+                               MSG_ADDRESS_INFO_S tmpAddressInfo;
+
+                               for (int i = 1; i <= rowCnt; i++) {
+                                       memset(&tmpAddressInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                                       char *address = dbhandler->getColumnToString(index++);
+                                       if (address) {
+                                               snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", address);
+                                               if (msg_is_valid_email(address)) {
+                                                   tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
+                                               }
+                                               else {
+                                                   tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
+                                               }
+                                       }
+                                       subType = dbhandler->getColumnToInt(index++);
+
+                                       MSG_CONTACT_INFO_S tmpContact;
+                                       memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                                       MsgGetContactInfo(&tmpAddressInfo, &tmpContact);
+
+                                       if (rowCnt == 1) {
+                                               snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
+                                       }
+
+                                       if (i > 1) {
+                                               g_strlcat(noti_info->sender, ", ", sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                       }
+
+                                       if (tmpContact.firstName[0] != '\0')
+                                               g_strlcat(noti_info->sender, tmpContact.firstName, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                       else if (tmpAddressInfo.addressVal[0] == '\0') {
+                                               char *senderStr = NULL;
+                                               senderStr = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
+                                               g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                               if (senderStr) {
+                                                       free(senderStr);
+                                                       senderStr = NULL;
+                                               }
+                                       } else {
+                                               char *senderStr = NULL;
+                                               if (subType == MSG_CB_SMS)
+                                               {
+                                                       senderStr = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CB_MESSAGE);
+                                                       g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                               }
+                                               else if (subType == MSG_WAP_SI_SMS || subType == MSG_WAP_SL_SMS) {
+                                                       senderStr = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
+                                                       g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                               }
+                                               else {
+                                                       g_strlcat(noti_info->sender, tmpAddressInfo.addressVal, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                               }
+                                               if (senderStr) {
+                                                       free(senderStr);
+                                                       senderStr = NULL;
+                                               }
+                                       }
+                               }
+
+                               dbhandler->freeTable();
+
+                               MSG_DEBUG("sender info = [%s]", noti_info->sender);
+
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+#ifdef MSG_NOTI_INTEGRATION
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.DISPLAY_TIME, "
+                                               "B.MSG_ID, "
+                                               "B.SUBJECT, "
+                                               "B.MSG_TEXT, "
+                                               "B.MAIN_TYPE, "
+                                               "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT, "
+                                               "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS MMS_UNREAD_CNT "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
+                                               "AND B.STORAGE_ID = %d  "
+                                               "ORDER BY B.DISPLAY_TIME DESC;",
+                                               MSG_SMS_TYPE,
+                                               MSG_MMS_TYPE,
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_INBOX_ID, MSG_CBMSGBOX_ID,
+                                               MSG_STORAGE_PHONE);
+#else
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.DISPLAY_TIME, "
+                                               "B.MSG_ID, "
+                                               "B.SUBJECT, "
+                                               "B.MSG_TEXT, "
+                                               "B.MAIN_TYPE, "
+                                               "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT, "
+                                               "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS MMS_UNREAD_CNT "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
+                                               "AND B.STORAGE_ID = %d  "
+                                               "ORDER BY B.DISPLAY_TIME DESC;",
+                                               MSG_SMS_TYPE,
+                                               MSG_MMS_TYPE,
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_INBOX_ID,
+                                               MSG_STORAGE_PHONE);
+#endif
+                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+
+                               if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_PREPARE;
+
+                               if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
+
+                                       smsUnreadCnt = dbhandler->columnInt(6);
+                                       mmsUnreadCnt = dbhandler->columnInt(7);
+
+                                       noti_info->count = smsUnreadCnt + mmsUnreadCnt;
+
+                                       if (noti_info->count > 0) {
+                                               snprintf(noti_info->number, sizeof(noti_info->number), "%s", (char*)dbhandler->columnText(0));
+
+                                               noti_info->time = (time_t)dbhandler->columnInt(1);
+
+                                               noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
+
+                                               mainType = (MSG_MAIN_TYPE_T)dbhandler->columnInt(5);
+
+                                               if (mainType == MSG_MMS_TYPE) {
+                                                       snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
+                                                       if (noti_info->text[0] == '\0') {
+                                                               char *noti_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_NO_SUBJECT);
+                                                               snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text);
+                                                               g_free(noti_text);
+                                                       }
+                                               } else {
+                                                       snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(4));
+                                               }
+
+                                               MSG_DEBUG("unread message ID [%d].", noti_info->msg_id);
+
+                                               if (!isForInstantMessage) {
+                                                       if (noti_info->id > 0 && noti_info->count == 1 ) {
+                                                               noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
+                                                               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                                                                       MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                                                               }
+                                                               noti_info->id = 0;
+                                                               if(MsgSettingSetInt(NOTIFICATION_PRIV_ID, noti_info->id) != MSG_SUCCESS)
+                                                                       MSG_DEBUG("MsgSettingSetInt fail : NOTIFICATION_PRIV_ID");
+                                                       }
+                                                       MsgSettingHandleNewMsg(smsUnreadCnt, mmsUnreadCnt);
+                                                       MsgInsertBadge(noti_info->count);
+                                                       MsgSoundSetRepeatAlarm();
+                                               }
+                                       } else {
+
+                                               MSG_DEBUG("No unread message.");
+                                               MSG_DEBUG("notiPrivId [%d]", noti_info->id);
+
+                                               dbhandler->finalizeQuery();
+
+                                               if (!isForInstantMessage) {
+                                                       // No unread message.
+                                                       if (noti_info->id > 0) {
+                                                               noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
+                                                               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                                                                       MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                                                               }
+                                                       }
+
+                                                       noti_info->id = 0;
+
+                                                       if(MsgSettingSetInt(NOTIFICATION_PRIV_ID, noti_info->id) != MSG_SUCCESS)
+                                                               MSG_DEBUG("MsgSettingSetInt fail : NOTIFICATION_PRIV_ID");
+
+                                                       MsgSettingHandleNewMsg(0,0);
+                                                       MsgInsertBadge(0);
+                                                       MsgSoundSetRepeatAlarm();
+                                               }
+
+                                               return MSG_ERR_DB_STEP;
+                                       }
+                               } else {
+                                       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+                                       dbhandler->finalizeQuery();
+                                       return MSG_ERR_DB_STEP;
+                               }
+
+                               dbhandler->finalizeQuery();
+                       }
+                       break;
+
+#ifndef MSG_NOTI_INTEGRATION
+               case MSG_NOTI_TYPE_CB :
+                       {
+                               char sqlQuery[MAX_QUERY_LEN+1];
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.DISPLAY_TIME, "
+                                               "B.MSG_ID, "
+                                               "B.MSG_TEXT "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 "
+                                               "AND B.FOLDER_ID=%d "
+                                               "AND B.STORAGE_ID = %d "
+                                               "ORDER BY B.DISPLAY_TIME DESC;",
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_CBMSGBOX_ID,
+                                               MSG_STORAGE_PHONE);
+
+                               if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_PREPARE;
+
+                               if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
+                                       MSG_ADDRESS_INFO_S addrInfo;
+                                       memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                                       if (dbhandler->columnText(0) != NULL)
+                                               snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
+
+                                       MSG_CONTACT_INFO_S tmpContact;
+                                       memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                                       MsgGetContactInfo(&addrInfo, &tmpContact);
+
+                                       if (tmpContact.firstName[0] != '\0') {
+                                               snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
+                                       } else if (addrInfo.addressVal[0] == '\0') {
+                                               char *senderStr = NULL;
+                                               senderStr = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
+                                               g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                               if (senderStr) {
+                                                       free(senderStr);
+                                                       senderStr = NULL;
+                                               }
+                                       } else {
+                                               snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
+                                       }
+
+                                       snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
+
+                                       noti_info->time = (time_t)dbhandler->columnInt(1);
+
+                                       noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
+
+                                       snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
+
+                                       MSG_DEBUG("unread CB message [%d].", noti_info->msg_id);
+                               } else {
+
+                                       MSG_DEBUG("No unread CB message.");
+                                       MSG_DEBUG("notiCbId [%d]", noti_info->id);
+
+                                       dbhandler->finalizeQuery();
+
+                                       if (!isForInstantMessage) {
+                                       // No unread message.
+                                               if (noti_info->id > 0) {
+                                                       noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_info->id);
+                                                       if (noti_err != NOTIFICATION_ERROR_NONE) {
+                                                               MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                                                       }
+                                               }
+
+                                               noti_info->id = 0;
+
+                                               if(MsgSettingSetInt(CB_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
+                                                       MSG_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
+                                       }
+
+                                       return MSG_ERR_DB_STEP;
+                               }
+
+                               dbhandler->finalizeQuery();
+
+                               if (dbhandler->getTable(sqlQuery, &noti_info->count) != MSG_SUCCESS) {
+                                       MSG_DEBUG("getTable is failed");
+                                       dbhandler->freeTable();
+                                       return MSG_ERR_DB_GETTABLE;
+                               }
+
+                               dbhandler->freeTable();
+                               MSG_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", noti_info->id, noti_info->count);
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM :
+                       {
+                               char sqlQuery[MAX_QUERY_LEN+1];
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.DISPLAY_TIME, "
+                                               "B.MSG_ID, "
+                                               "B.MSG_TEXT, "
+                                               "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
+                                               "AND B.STORAGE_ID = %d "
+                                               "ORDER BY B.DISPLAY_TIME DESC;",
+                                               MSG_SMS_TYPE,
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_INBOX_ID,
+                                               MSG_STORAGE_SIM);
+
+                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+
+                               if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_PREPARE;
+
+                               if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
+
+                                       noti_info->count = dbhandler->columnInt(4);
+
+                                       if (noti_info->count > 0) {
+                                               MSG_ADDRESS_INFO_S addrInfo;
+                                               memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                                               if (dbhandler->columnText(0) != NULL)
+                                                       snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
+
+                                               MSG_CONTACT_INFO_S tmpContact;
+                                               memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                                               MsgGetContactInfo(&addrInfo, &tmpContact);
+
+                                               if (tmpContact.firstName[0] != '\0') {
+                                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
+                                               } else if (addrInfo.addressVal[0] == '\0') {
+                                                       char *senderStr = NULL;
+                                                       senderStr = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
+                                                       g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                                       if (senderStr) {
+                                                               free(senderStr);
+                                                               senderStr = NULL;
+                                                       }
+                                               } else {
+                                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
+                                               }
+
+                                               snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
+
+                                               noti_info->time = (time_t)dbhandler->columnInt(1);
+
+                                               noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
+
+                                               snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
+
+                                               MSG_DEBUG("unread SIM message [%d].", noti_info->msg_id);
+                                       } else {
+
+                                               MSG_DEBUG("No unread SIM message.");
+                                               MSG_DEBUG("notiPrivId [%d]", noti_info->id);
+
+                                               dbhandler->finalizeQuery();
+
+                                               if (!isForInstantMessage) {
+                                                       // No unread message.
+                                                       if (noti_info->id > 0) {
+                                                               noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
+                                                               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                                                                       MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                                                               }
+                                                       }
+
+                                                       noti_info->id = 0;
+
+                                                       if(MsgSettingSetInt(SIM_MSG_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
+                                                               MSG_DEBUG("MsgSettingSetInt fail : SIM_MSG_NOTI_PRIV_ID");
+                                               }
+
+                                               return MSG_ERR_DB_STEP;
+                                       }
+                               } else {
+                                       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+                                       dbhandler->finalizeQuery();
+                                       return MSG_ERR_DB_STEP;
+                               }
+
+                               dbhandler->finalizeQuery();
+                       }
+                       break;
+#endif
+               case MSG_NOTI_TYPE_FAILED :
+                       {
+                               MSG_MAIN_TYPE_T mainType;
+                               char sqlQuery[MAX_QUERY_LEN+1];
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                               "A.ADDRESS_VAL, "
+                                               "B.DISPLAY_TIME, "
+                                               "B.MSG_ID, "
+                                               "B.MSG_TEXT, "
+                                               "B.SUBJECT, "
+                                               "B.MAIN_TYPE, "
+                                               "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENT_FAILED_CNT "
+                                               "FROM %s A, %s B "
+                                               "WHERE A.CONV_ID=B.CONV_ID "
+                                               "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
+                                               "AND B.STORAGE_ID = %d  "
+                                               "ORDER BY B.DISPLAY_TIME DESC;",
+                                               MSG_NETWORK_SEND_FAIL,
+                                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSG_OUTBOX_ID,
+                                               MSG_STORAGE_PHONE);
+
+                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+
+                               if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_PREPARE;
+
+                               if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
+
+                                       noti_info->count = dbhandler->columnInt(6);
+
+                                       if (noti_info->count > 0) {
+                                               MSG_ADDRESS_INFO_S addrInfo;
+                                               memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                                               if (dbhandler->columnText(0) != NULL)
+                                                       snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
+
+                                               MSG_CONTACT_INFO_S tmpContact;
+                                               memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                                               MsgGetContactInfo(&addrInfo, &tmpContact);
+
+                                               if (tmpContact.firstName[0] != '\0') {
+                                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
+                                               } else if (addrInfo.addressVal[0] == '\0') {
+                                                       char *senderStr = NULL;
+                                                       senderStr = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
+                                                       g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
+                                                       if (senderStr) {
+                                                               free(senderStr);
+                                                               senderStr = NULL;
+                                                       }
+                                               } else {
+                                                       snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
+                                               }
+
+                                               snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
+
+                                               noti_info->time = (time_t)dbhandler->columnInt(1);
+
+                                               noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
+
+                                               mainType = (MSG_MAIN_TYPE_T)dbhandler->columnInt(5);
+
+                                               if (mainType == MSG_TYPE_MMS)
+                                                       snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(4));
+                                               else
+                                                       snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
+
+                                               MSG_DEBUG("Sent failed message ID [%d].", noti_info->msg_id);
+                                       } else {
+
+                                               MSG_DEBUG("No sent failed message.");
+                                               MSG_DEBUG("failedNotiId [%d]", noti_info->id);
+
+                                               dbhandler->finalizeQuery();
+
+                                               if (!isForInstantMessage) {
+                                                       // No unread message.
+                                                       if (noti_info->id > 0) {
+                                                               noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
+                                                               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                                                                       MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                                                               }
+                                                       }
+
+                                                       noti_info->id = 0;
+
+                                                       if (MsgSettingSetInt(MSG_SENTFAIL_NOTI_ID, noti_info->id) != MSG_SUCCESS)
+                                                               MSG_DEBUG("MsgSettingSetInt fail : MSG_SENTFAIL_NOTI_ID");
+                                               }
+
+                                               return MSG_ERR_DB_STEP;
+                                       }
+                               } else {
+                                       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+                                       dbhandler->finalizeQuery();
+                                       return MSG_ERR_DB_STEP;
+                               }
+
+                               dbhandler->finalizeQuery();
+                       }
+                       break;
+
+               case MSG_NOTI_TYPE_SIM_FULL :
+                       break;
+
+               default:
+                       {
+                               MSG_DEBUG("No matching type [%d]", noti_info->type);
+                               return MSG_ERR_UNKNOWN;
+                       }
+                       break;
+       }
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+void setFlashNoti(void)
+{
+       MSG_BEGIN();
+
+       int ret = 0;
+
+       if (!bFeedbackInit) {
+               int ret = feedback_initialize();
+
+               if (ret != FEEDBACK_ERROR_NONE) {
+                       MSG_DEBUG("Fail to feedback_initialize : [%d]", ret);
+                       bFeedbackInit = false;
+                       return;
+               } else {
+                       MSG_DEBUG("Success to feedback_initialize.");
+                       bFeedbackInit = true;
+               }
+       }
+
+       ret = feedback_play_type(FEEDBACK_TYPE_LED, FEEDBACK_PATTERN_MESSAGE);
+       if (ret != FEEDBACK_ERROR_NONE)
+               MSG_DEBUG("Fail to feedback_play_type");
+
+       MSG_END();
+}
+
+
+void createServiceHandle(app_control_h *svc_h)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       svc_err = app_control_create(svc_h);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_create() is failed, [%d]", svc_err);
+}
+
+
+void setServiceAppId(app_control_h svc_h, const char* app_id)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       svc_err = app_control_set_app_id(svc_h, app_id);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
+}
+
+
+void setServiceOperation(app_control_h svc_h, const char* operation)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       svc_err = app_control_set_operation(svc_h, operation);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_set_operation() was failed, [%d]", svc_err);
+}
+
+
+void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       svc_err = app_control_add_extra_data(svc_h, bundle_key, bundle_val);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
+}
+
+
+void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       char tempId[10];
+       memset(&tempId, 0x00, sizeof(tempId));
+       snprintf(tempId, sizeof(tempId), "%d", bundle_val);
+
+       svc_err = app_control_add_extra_data(svc_h, bundle_key, (const char *)tempId);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
+}
+
+
+void setServicePackageName(app_control_h svc_h, const char* pkg_name)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       svc_err = app_control_set_app_id(svc_h, pkg_name);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
+}
+
+
+void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data)
+{
+       int svc_err = APP_CONTROL_ERROR_NONE;
+
+       svc_err = app_control_send_launch_request(svc_h, callback, user_data);
+
+       if (svc_err != APP_CONTROL_ERROR_NONE)
+               MSG_DEBUG("app_control_send_launch_request() is failed : %d", svc_err);
+}
+
+
+void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_text_domain(noti_h, pkg_name, loc_dir);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("notification_set_text_domain() was failed. [%d]", noti_err);
+       }
+}
+
+
+void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_text(noti_h, type, text, key, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("notification_set_text() was failed. [%d]", noti_err);
+}
+
+
+void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_time_to_text(noti_h, type, time);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("notification_set_time_to_text() was failed. [%d]", noti_err);
+}
+
+
+void setNotiTime(notification_h noti_h, time_t time)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_time(noti_h, time);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("notification_set_time() was failed. [%d]", noti_err);
+}
+
+
+
+void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_image(noti_h, type, image_path);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("notification_set_image() was failed. [%d]", noti_err);
+}
+
+
+void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_sound(noti_h, type, path);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("notification_set_sound() was failed. [%d]", noti_err);
+}
+
+
+void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+
+       noti_err = notification_set_vibration(noti_h, type, path);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("notification_set_vibration() was failed. [%d]", noti_err);
+}
+
+
+char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text)
+{
+       char *notiMsg = NULL;
+       char *lang = NULL;
+
+       lang = vconf_get_str(VCONFKEY_LANGSET);
+
+       setlocale(LC_MESSAGES, lang);
+
+       bindtextdomain(pkg_name, locale_dir);
+
+       notiMsg = dgettext(pkg_name, text);
+
+       if (lang) {
+               free(lang);
+               lang = NULL;
+       }
+
+       return g_strdup(notiMsg);
+}
+
+void MsgNotiSoundRepeatAlarmCB(int alarmId)
+{
+       MSG_BEGIN();
+
+       MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, true, true);
+
+#ifndef MSG_NOTI_INTEGRATION
+       MsgRefreshNotification(MSG_NOTI_TYPE_SIM, true, true);
+       MsgRefreshNotification(MSG_NOTI_TYPE_CB, true, true);
+#endif
+
+       MSG_END();
+       return;
+}
+
+
+void MsgSoundCreateRepeatAlarm(int RepeatTime)
+{
+       MSG_BEGIN();
+
+       int tmpAlarmId = 0;
+       time_t tmp_time;
+       struct tm repeat_tm;
+
+       time(&tmp_time);
+
+       tmp_time += (RepeatTime*60);
+       tzset();
+       localtime_r(&tmp_time, &repeat_tm);
+
+       if (MsgAlarmRegistration(&repeat_tm, MsgNotiSoundRepeatAlarmCB, &tmpAlarmId) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgAlarmRegistration fail.");
+               return;
+       }
+
+       g_alarmId = tmpAlarmId;
+       MSG_DEBUG("Set alarmId to [%d]", g_alarmId);
+
+       MSG_END();
+
+       return;
+}
+
+
+void MsgSoundSetRepeatAlarm()
+{
+       int nRepeatValue = 0;
+       long    nRepeatTime = 0;
+
+       nRepeatValue = MsgSettingGetInt(MSG_ALERT_REP_TYPE);
+
+       switch (nRepeatValue)
+       {
+               case MSG_ALERT_TONE_ONCE:
+                       nRepeatTime = 0;
+                       break;
+
+               case MSG_ALERT_TONE_2MINS:
+                       nRepeatTime = 2;
+                       break;
+
+               case MSG_ALERT_TONE_5MINS:
+                       nRepeatTime = 5;
+                       break;
+
+               case MSG_ALERT_TONE_10MINS:
+                       nRepeatTime = 10;
+                       break;
+
+               default:
+                       MSG_DEBUG("Invalid Repetition time");
+                       break;
+       }
+
+       MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
+
+       if (nRepeatTime > 0) {
+               if (g_alarmId > 0) {
+                       if (MsgAlarmRemove(g_alarmId) != MSG_SUCCESS) {
+                               MSG_FATAL("MsgAlarmRemove fail.");
+                       }
+                       g_alarmId = 0;
+               }
+               MsgSoundCreateRepeatAlarm(nRepeatTime);
+       }
+
+       return;
+}
+
+
+void sendMsgReplyPopup(MSG_NOTI_INFO_S *noti_info)
+{
+       app_control_h svc_h = NULL;
+
+       createServiceHandle(&svc_h);
+
+       if (svc_h) {
+               setServicePackageName(svc_h, "org.tizen.msg-ui-reply");
+
+               MSG_DEBUG("Reply-popup display - Msg Id = [%d]", noti_info->msg_id);
+               addServiceExtraData(svc_h, "msgId", noti_info->msg_id);
+
+               sendServicelaunchRequest(svc_h, NULL, NULL);
+
+               app_control_destroy(svc_h);
+       }
+}
similarity index 69%
rename from msg_helper/MsgSensorWrapper.cpp
rename to externals/MsgSensorWrapper.cpp
index 5f24c92..1dc502d 100755 (executable)
@@ -1,32 +1,33 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
+
 #include "MsgDebug.h"
 #include "MsgCppTypes.h"
 #include "MsgGconfWrapper.h"
-#include "MsgHelper.h"
+#include "MsgSensorWrapper.h"
 
-#include <sensor.h>
+#include <sensor_internal.h>
 
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
 int sensorHandler = -1;
 
-msg_sensor_cb cbFunction = NULL;
+msg_sensor_cb SensorCBFunction = NULL;
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
@@ -42,8 +43,9 @@ void MsgSensorCB(unsigned int event_type, sensor_event_data_t *event_data , void
                if(*my_event_data == MOTION_ENGIEN_TOP_TO_BOTTOM_DETECTION) {
                        MSG_DEBUG("top to bottom event detected.");
                        if(MsgSettingGetInt(VCONFKEY_SETAPPL_MOTION_ACTIVATION))
-                               if(MsgSettingGetInt(VCONFKEY_SETAPPL_USE_TURN_OVER))
-                                       cbFunction();
+                               if(MsgSettingGetInt(VCONFKEY_SETAPPL_USE_TURN_OVER)) {
+                                       if(SensorCBFunction) SensorCBFunction();
+                               }
                }
 }
 
@@ -62,8 +64,8 @@ msg_error_t MsgSensorConnect()
 
 void MsgSensorDisconnect()
 {
-       if(cbFunction != NULL)
-               cbFunction = NULL;
+       if(SensorCBFunction != NULL)
+               SensorCBFunction = NULL;
 
        if (sensorHandler < 0)
                return;
@@ -91,7 +93,7 @@ msg_error_t MsgRegSensorCB(msg_sensor_cb cb)
 
        if(cb != NULL) {
                // regist cb.
-               cbFunction = cb;
+               SensorCBFunction = cb;
        } else {
                MSG_DEBUG("cb is NULL.");
                return MSG_ERR_UNKNOWN;
diff --git a/externals/MsgSoundPlayer.cpp b/externals/MsgSoundPlayer.cpp
new file mode 100755 (executable)
index 0000000..f91a1e5
--- /dev/null
@@ -0,0 +1,792 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include <wait.h>
+
+#include "MsgDebug.h"
+#include "MsgCppTypes.h"
+#include "MsgGconfWrapper.h"
+#include "MsgSettingTypes.h"
+#include "MsgDrmWrapper.h"
+#include "MsgSensorWrapper.h"
+#include "MsgUtilFile.h"
+#include "MsgStorageTypes.h"
+#include "MsgContact.h"
+#include "MsgAlarm.h"
+#include "MsgNotificationWrapper.h"
+#include "MsgSoundPlayer.h"
+
+#include <mm_error.h>
+#include <mm_player.h>
+#include <mm_session_private.h>
+#include <mm_sound.h>
+
+#include <feedback.h>
+
+/*==================================================================================================
+                                    DEFINES
+==================================================================================================*/
+#define MAX_SOUND_FILE_LEN 1024
+
+#define DEFAULT_ALERT_FILE             "/opt/usr/share/settings/Alerts/notification_sdk.wav"
+
+#define HAPTIC_TEST_ITERATION 1
+#define MSG_VIBRATION_INTERVAL 3000
+#define MSG_SOUND_TIMEOUT 5500
+
+
+/*==================================================================================================
+                                     VARIABLES
+==================================================================================================*/
+MMHandleType hPlayerHandle = 0;
+
+pthread_mutex_t muMmPlay = PTHREAD_MUTEX_INITIALIZER;
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF Functions
+==================================================================================================*/
+void MsgSoundRepeatAlarmCB(int alarmId)
+{
+       MSG_BEGIN();
+
+       MsgSoundPlayer::instance()->MsgSoundInitRepeatAlarm();
+
+       MSG_END();
+       return;
+}
+
+
+void MsgSensorCBStop()
+{
+       MSG_BEGIN();
+
+#if 0
+       MsgSoundPlayer::instance()->MsgSoundPlayStop();
+#else
+       MsgDeleteNotification(MSG_NOTI_TYPE_ALL);
+
+       MsgRefreshNotification(MSG_NOTI_TYPE_ALL, false, false);
+
+#ifndef MSG_NOTI_INTEGRATION
+       MsgRefreshNotification(MSG_NOTI_TYPE_SIM, false, false);
+#endif
+
+#endif
+
+       MSG_END();
+}
+
+
+//static gboolean MsgSoundMelodyTimeout(gpointer data)
+//{
+//     MSG_BEGIN();
+//
+//     MsgSoundPlayer::instance()->MsgSoundPlayStop();
+//
+//     MSG_END();
+//
+//     return FALSE;
+//}
+
+
+static int MsgSoundPlayCallback(int message, void *param, void *user_param)
+{
+       switch (message)
+       {
+               case MM_MESSAGE_BEGIN_OF_STREAM:
+                       MSG_DEBUG("Play is started.");
+                       break;
+               case MM_MESSAGE_END_OF_STREAM:
+               case MM_MESSAGE_STATE_INTERRUPTED:
+                       MSG_DEBUG("EOS or Interrupted.");
+                       MsgSoundPlayer::instance()->MsgSoundPlayStop();
+                       break;
+               case MM_MESSAGE_FILE_NOT_SUPPORTED:
+               case MM_MESSAGE_FILE_NOT_FOUND:
+               case MM_MESSAGE_DRM_NOT_AUTHORIZED:
+               case MM_MESSAGE_ERROR:
+                       MSG_DEBUG("message [%d] & play with default", message);
+                       MsgSoundPlayer::instance()->MsgSoundPlayStart(NULL, MSG_SOUND_PLAY_DEFAULT);
+                       break;
+               default:
+                       MSG_DEBUG("message [%d]", message);
+                       break;
+       }
+
+       return 1;
+}
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF MsgSoundPlayer - Member Functions
+==================================================================================================*/
+MsgSoundPlayer* MsgSoundPlayer::pInstance = NULL;
+
+
+MsgSoundPlayer::MsgSoundPlayer()
+{
+       bPlaying = false;
+       bVibrating = false;
+       bFeedbackInit = false;
+       g_alarmId = 0;
+
+       defaultRingtonePath = NULL;
+
+       defaultRingtonePath = MsgSettingGetString(VCONFKEY_SETAPPL_NOTI_RINGTONE_DEFAULT_PATH_STR);
+
+       if (defaultRingtonePath == NULL || MsgGetFileSize(defaultRingtonePath) < 1) {
+               defaultRingtonePath = (char *)DEFAULT_ALERT_FILE;
+       }
+
+       MSG_DEBUG("defaultRingtonePath [%s]", defaultRingtonePath);
+
+       if (MsgSensorConnect() == MSG_SUCCESS) {
+               if (MsgRegSensorCB(&MsgSensorCBStop) != MSG_SUCCESS) {
+                       MSG_DEBUG("Fail to MsgRegSensorCB.");
+                       MsgSensorDisconnect();
+               }
+       } else {
+               MSG_DEBUG("Fail to MsgSensorConnect.");
+       }
+}
+
+
+MsgSoundPlayer::~MsgSoundPlayer()
+{
+
+}
+
+
+MsgSoundPlayer* MsgSoundPlayer::instance()
+{
+       if (!pInstance) {
+               MSG_DEBUG("pInstance is NULL. Now creating instance.");
+               pInstance = new MsgSoundPlayer();
+       }
+
+       return pInstance;
+}
+
+
+void MsgSoundPlayer::MsgGetRingtonePath(char *userRingtonePath, char **msg_tone_file_path_p)
+{
+       char *tmpFilePath = NULL;
+       *msg_tone_file_path_p = new char[MSG_FILEPATH_LEN_MAX+1];
+
+       char *msg_tone_file_path = *msg_tone_file_path_p;
+
+       MSG_RINGTONE_TYPE_T ringtoneType = (MSG_RINGTONE_TYPE_T)MsgSettingGetInt(MSG_SETTING_RINGTONE_TYPE);
+
+       MSG_DEBUG("Ringtone type = [%d]", ringtoneType);
+
+       if (ringtoneType == MSG_RINGTONE_TYPE_SILENT) {
+               *msg_tone_file_path_p = NULL;
+               return;
+       }
+
+       if(userRingtonePath && userRingtonePath[0] != '\0') {
+               tmpFilePath = userRingtonePath;
+       } else {
+               if (ringtoneType == MSG_RINGTONE_TYPE_DEFAULT) {
+                       tmpFilePath = MsgSettingGetString(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
+               } else {
+                       tmpFilePath = MsgSettingGetString(MSG_SETTING_RINGTONE_PATH);
+               }
+       }
+
+       memset(msg_tone_file_path, 0x00, sizeof(char)*(MSG_FILEPATH_LEN_MAX+1));
+
+       if ((tmpFilePath == NULL || MsgGetFileSize(tmpFilePath) < 1) || // wrong ringtone file path
+                       (MsgDrmIsDrmFile(tmpFilePath) && !MsgDrmCheckRingtone(tmpFilePath))) { // check DRM
+               if (tmpFilePath && (strcmp(tmpFilePath, "silent") == 0)) {
+                       MSG_DEBUG("Set ringtone to NONE(Silent)");
+                       msg_tone_file_path = NULL;
+               } else {
+                       MSG_DEBUG("Set ringtone to defaultRingtonePath.");
+                       strncpy(msg_tone_file_path, defaultRingtonePath, MSG_FILEPATH_LEN_MAX);
+               }
+       } else {
+               MSG_DEBUG("Set ringtone to tmpFilePath.");
+               strncpy(msg_tone_file_path, tmpFilePath, MSG_FILEPATH_LEN_MAX);
+       }
+
+       if (tmpFilePath && userRingtonePath[0] == '\0') {
+               free(tmpFilePath);
+               tmpFilePath = NULL;
+       }
+}
+
+
+bool MsgIsSoundPlayOnCall(void)
+{
+       bool bPlayOnCall = false;
+       int err = MM_ERROR_NONE;
+
+       mm_sound_device_in soundIn = MM_SOUND_DEVICE_IN_NONE;
+       mm_sound_device_out soundOut = MM_SOUND_DEVICE_OUT_NONE;
+
+       err = mm_sound_get_active_device(&soundIn, &soundOut);
+
+       if (err == MM_ERROR_NONE) {
+               if (soundOut & (MM_SOUND_DEVICE_OUT_RECEIVER|MM_SOUND_DEVICE_OUT_SPEAKER))
+                       bPlayOnCall = false;
+               else
+                       bPlayOnCall = true;
+
+               MSG_DEBUG("mm_sound_device_out=[%04x],bPlayOnCall=[%d]", soundOut, bPlayOnCall);
+       } else {
+               MSG_DEBUG("mm_sound_get_active_device() err=[%d]", err);
+       }
+
+       return bPlayOnCall;
+}
+
+
+void MsgSoundPlayer::MsgGetPlayStatus(bool bVoiceMail, bool *bPlaySound, bool *bPlayVibration, bool *bOnCall)
+{
+       MSG_BEGIN();
+
+       if (!bPlaySound || !bPlayVibration || !bOnCall) {
+               MSG_DEBUG("IN parameter is NULL.");
+               return;
+       }
+
+       *bPlaySound = false;
+       *bPlayVibration = false;
+       *bOnCall = false;
+
+       /* Global setting */
+       bool bSoundOn = false; // sound setting on notification panel
+       bool bVibrationOn = false; // vibration setting on notification panel
+
+       /* Alert setting */
+#if 0  //not used value
+       bool bNotiVibrationOn = false; // alert vibration
+       MsgSettingGetBool(VCONFKEY_SETAPPL_VIBRATE_WHEN_NOTIFICATION_BOOL, &bNotiVibrationOn);
+#endif
+
+       bool bMsgSettingNoti = true; // Alert for message notification
+       bool bMsgSettingVibration = false; // vibration for message notification
+
+       MsgSettingGetBool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn);
+       MsgSettingGetBool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn);
+
+       MsgSettingGetBool(MSG_SETTING_VIBRATION, &bMsgSettingVibration);
+       MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bMsgSettingNoti);
+
+       MSG_SEC_DEBUG("Sound status : Sound mode=[%d], Manner mode=[%d]", bSoundOn, bVibrationOn);
+       MSG_SEC_DEBUG("Msg Setting : Noti Alert=[%d], With vibration=[%d]", bMsgSettingNoti, bMsgSettingVibration);
+
+       int callStatus = 0;
+       int alertOnCall = 0;
+
+       callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
+       MSG_DEBUG("Call Status [%d]", callStatus);
+
+       /* Check call status */
+       if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
+               /* 1. On Call */
+
+               *bOnCall = true; // set call status;
+
+               alertOnCall = MsgSettingGetInt(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT);
+               MSG_DEBUG("Alert On Call [%d]", alertOnCall);
+
+               if (alertOnCall == 0) {
+                       MSG_DEBUG("Call is active & Alert on Call - Off");
+               } else if (alertOnCall == 1) {
+                       /* set default value to true, while on Call  alert sound to be played  and vibration to be off. */
+                       bool bPlayOnCall = true;
+
+                       if (!bSoundOn) {
+                               /* check whther sound should be on when sound setting on notification panel is off */
+                               bPlayOnCall = MsgIsSoundPlayOnCall();
+                       }
+
+                       if (bVoiceMail) {       /* 1-1. Voice message */
+                               if (bPlayOnCall && bMsgSettingNoti) {
+                                       MSG_DEBUG("On call, Play sound - voice message");
+                                       *bPlaySound = true;
+                               } else {
+                                       MSG_DEBUG("On call, It doesn't play sound - voice message");
+                               }
+
+                               MSG_DEBUG("On call, It doesn't play vibration - voice message");
+                       } else {        /* 1-2. Normal message */
+                               if (bMsgSettingNoti) {
+                                       if (bPlayOnCall) {
+                                               MSG_DEBUG("On call, Play sound");
+                                               *bPlaySound = true;
+                                       } else {
+                                               MSG_DEBUG("On call, It doesn't play sound");
+                                       }
+
+                                       MSG_DEBUG("On call, It doesn't play vibration");
+                               }
+                       }
+               }
+       } else {
+               /* 2. Call is not active */
+
+               MSG_DEBUG("Call is not active.");
+               int voiceRecording = MsgSettingGetInt(VCONFKEY_VOICERECORDER_STATE);
+
+               if (bVoiceMail) {       /* 2-1. Voice message */
+                       if (bMsgSettingNoti) {
+                               if (bSoundOn || bVibrationOn) {
+                                       MSG_DEBUG("Play vibration - voice message.");
+                                       *bPlayVibration = true;
+                               } else {
+                                       MSG_DEBUG("It doesn't play vibration - voice message.");
+                               }
+
+                               MSG_DEBUG("Play sound - voice message.");
+                               *bPlaySound = true;
+
+                       } else {
+                               MSG_DEBUG("It doesn't play sound/vibration - voice message.");
+                       }
+               } else {        /* 2-1. Normal message */
+                       if (bMsgSettingNoti) {
+                               if (voiceRecording != VCONFKEY_VOICERECORDER_RECORDING) {
+                                       if (bSoundOn) {
+                                               MSG_DEBUG("Play sound.");
+                                               *bPlaySound = true;
+                                       } else {
+                                               MSG_DEBUG("It doesn't play vibration.");
+                                       }
+
+                                       if ((bSoundOn || bVibrationOn) && bMsgSettingVibration) {
+                                               MSG_DEBUG("Play vibration.");
+                                               *bPlayVibration = true;
+                                       } else {
+                                               MSG_DEBUG("It doesn't play vibration.");
+                                       }
+                               } else {
+                                       MSG_DEBUG("It doesn't play sound/vibration.");
+                               }
+                       } else {
+                               MSG_DEBUG("It doesn't play sound/vibration.");
+                       }
+               }
+       }
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayStart(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_SOUND_TYPE_T soundType)
+{
+       MSG_BEGIN();
+       MSG_DEBUG("soundType [%d]", soundType);
+
+       /* check camera state */
+       int cameraState = 0;    // camera recording state
+       cameraState = MsgSettingGetInt(VCONFKEY_CAMERA_STATE);
+       MSG_SEC_DEBUG("Camera state [%d]", cameraState);
+
+       if (cameraState == VCONFKEY_CAMERA_STATE_RECORDING) {
+               MSG_END();
+               return;
+       }
+
+       /* get contact information */
+       MSG_CONTACT_INFO_S contactInfo;
+       memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+       if(pAddrInfo) {
+               // Get Contact Info
+               if (MsgGetContactInfo(pAddrInfo, &contactInfo) != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgGetContactInfo() fail.");
+               }
+       }
+
+       /* get ringtone file path */
+       char *msg_tone_file_path = NULL;
+       AutoPtr<char> buf(&msg_tone_file_path);
+
+       if (soundType == MSG_SOUND_PLAY_EMERGENCY) {
+               msg_tone_file_path = new char[MAX_SOUND_FILE_LEN+1];
+               memset(msg_tone_file_path, 0x00, sizeof(char)*(MAX_SOUND_FILE_LEN+1));
+       } else if (soundType == MSG_SOUND_PLAY_DEFAULT) {
+               msg_tone_file_path = new char[MAX_SOUND_FILE_LEN+1];
+               memset(msg_tone_file_path, 0x00, sizeof(char)*(MAX_SOUND_FILE_LEN+1));
+               strncpy(msg_tone_file_path, DEFAULT_ALERT_FILE, MAX_SOUND_FILE_LEN);
+       } else {
+               MsgGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
+       }
+
+       MSG_SEC_DEBUG("soundType [%d], Sound File [%s]", soundType, msg_tone_file_path);
+
+       /* get sound play status */
+       bool bPlaySound = false;
+       bool bPlayVibration = false;
+       bool bVoiceMsg = (soundType == MSG_SOUND_PLAY_VOICEMAIL)?true:false;
+       bool bOnCall = false;
+
+       MsgGetPlayStatus(bVoiceMsg, &bPlaySound, &bPlayVibration, &bOnCall);
+
+       MSG_SEC_DEBUG("sound=[%d], vibration=[%d], voice_msg?[%d], on_call?[%d]", \
+                       bPlaySound, bPlayVibration, bVoiceMsg, bOnCall);
+
+       /* play sound */
+       if (bPlaySound) {
+               int err = MM_ERROR_NONE;
+
+               if (soundType == MSG_SOUND_PLAY_EMERGENCY)
+                       err = mm_session_init(MM_SESSION_TYPE_EMERGENCY);
+               else
+                       err = mm_session_init(MM_SESSION_TYPE_NOTIFY);
+
+               if (err != MM_ERROR_NONE)
+                       MSG_DEBUG("MM Session Init Failed");
+               else
+                       MSG_DEBUG("MM Session Init Success : %d", err);
+
+
+               MsgSoundPlayMelody(msg_tone_file_path);
+
+               err = mm_session_finish();
+
+               if (err != MM_ERROR_NONE)
+                       MSG_DEBUG("MM Session Finish Failed.");
+               else
+                       MSG_DEBUG("MM Session Finish Success : %d", err);
+       }
+
+       /* play vibration */
+       if (bPlayVibration) {
+               MsgSoundPlayVibration(contactInfo.vibrationPath, bOnCall);
+       }
+
+       // For repeatition.
+//     MsgSoundSetRepeatAlarm();
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayStop()
+{
+       MSG_BEGIN();
+
+       pthread_mutex_lock(&muMmPlay);
+
+       if (bPlaying == true && hPlayerHandle != 0 ) {
+               MSG_DEBUG("stopping the player.");
+               /* Stop playing media contents */
+               int err = mm_player_stop(hPlayerHandle);
+
+               if (err != MM_ERROR_NONE) {
+                       MSG_DEBUG("stopping the player handle failed");
+               }
+
+       }
+
+       if (hPlayerHandle != 0) {
+               MSG_DEBUG("destroy the player.");
+
+               /* Uninitializing the player module */
+               mm_player_unrealize(hPlayerHandle);
+
+               /* Destroying the player handle */
+               mm_player_destroy(hPlayerHandle);
+       }
+
+       hPlayerHandle = 0;
+       bPlaying = false;
+
+       pthread_mutex_unlock(&muMmPlay);
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayMelody(char *pMsgToneFilePath)
+{
+       int err = MM_ERROR_NONE;
+
+       if (!pMsgToneFilePath) {
+               MSG_DEBUG("Ringtone path is NULL");
+               return;
+       }
+
+       pthread_mutex_lock(&muMmPlay);
+
+       if (hPlayerHandle != 0) {
+               mm_player_unrealize(hPlayerHandle);
+               mm_player_destroy(hPlayerHandle);
+               hPlayerHandle = 0;
+       }
+
+       err = mm_player_create(&hPlayerHandle);
+
+       pthread_mutex_unlock(&muMmPlay);
+
+       if (err != MM_ERROR_NONE) {
+               MSG_DEBUG("creating the player handle failed");
+               return;
+       }
+
+       /* Setting the call back function msg_callback */
+       mm_player_set_message_callback(hPlayerHandle, MsgSoundPlayCallback, NULL);
+
+       do {
+               /* Setting fade in/out, Volume */
+               err = mm_player_set_attribute(hPlayerHandle, NULL,
+                               "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION,
+                               "profile_uri", pMsgToneFilePath, strlen(pMsgToneFilePath),
+                               "sound_priority", 2,
+                               NULL);
+
+               if (err != MM_ERROR_NONE) {
+                       MSG_DEBUG("error setting the profile attr [%d]", err);
+               }
+
+               err = mm_player_realize(hPlayerHandle);
+
+               if (err != MM_ERROR_NONE) {
+                       MSG_DEBUG("mm_player_realize() error : [%d]", err);
+                       if (pMsgToneFilePath != defaultRingtonePath) {
+                               pMsgToneFilePath = defaultRingtonePath;
+                       } else {
+                               return;
+                       }
+               }
+       } while(err != MM_ERROR_NONE);
+
+
+       pthread_mutex_lock(&muMmPlay);
+       MSG_DEBUG("mm_player_start with [%s]", pMsgToneFilePath);
+       err = mm_player_start(hPlayerHandle);
+
+       if (err != MM_ERROR_NONE) {
+               MSG_DEBUG("mm_player_start, FAIL [%x]", err);
+       } else {
+               /* Add Timer to stop playing after 5 sec. */
+//             int g_contact_timer = -1;
+//             g_contact_timer = g_timeout_add(MSG_SOUND_TIMEOUT, (GSourceFunc)MsgSoundMelodyTimeout, NULL);
+
+               bPlaying = true;
+       }
+       pthread_mutex_unlock(&muMmPlay);
+
+       return;
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayVibration(char *vibrationPath, bool isOnCall)
+{
+       MSG_BEGIN();
+
+       int ret = 0;
+
+       if (!bFeedbackInit) {
+               int ret = feedback_initialize();
+
+               if (ret != FEEDBACK_ERROR_NONE) {
+                       MSG_DEBUG("Fail to feedback_initialize : [%d]", ret);
+                       bFeedbackInit = false;
+                       return;
+               } else {
+                       MSG_DEBUG("Success to feedback_initialize.");
+                       bFeedbackInit = true;
+               }
+       }
+
+       if(vibrationPath && strlen(vibrationPath))
+       {
+               MSG_DEBUG("vibrationPath: [%s]", vibrationPath);
+               ret = feedback_set_resource_path(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE, vibrationPath);
+               if (ret != FEEDBACK_ERROR_NONE)
+                       MSG_DEBUG("Fail to feedback_set_resource_path");
+               ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
+
+               if (ret != FEEDBACK_ERROR_NONE)
+                       MSG_DEBUG("Fail to feedback_play_type");
+       }
+       else
+       {
+               if (isOnCall)
+                       ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE_ON_CALL);
+               else
+               {
+                       ret = feedback_set_resource_path(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE, NULL);
+                       if (ret != FEEDBACK_ERROR_NONE)
+                               MSG_DEBUG("Fail to feedback_set_resource_path");
+                       ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
+               }
+
+               if (ret != FEEDBACK_ERROR_NONE)
+                       MSG_DEBUG("Fail to feedback_play_type");
+       }
+
+       MSG_END();
+}
+
+void MsgSoundPlayer::MsgSoundPlayDtmf()
+{
+       MSG_BEGIN();
+
+       int ret = 0;
+       int hToneHandle = 0;
+
+       ret = mm_sound_play_tone(MM_SOUND_TONE_PROP_BEEP2, VOLUME_TYPE_SYSTEM, 1.0, 300, &hToneHandle);
+
+       if(ret < 0) {
+               MSG_DEBUG("play tone failed.");
+       } else {
+               MSG_DEBUG("play tone success.");
+       }
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundSetRepeatAlarm()
+{
+       int nRepeatValue = 0;
+       long    nRepeatTime = 0;
+
+       nRepeatValue = MsgSettingGetInt(MSG_ALERT_REP_TYPE);
+
+       switch (nRepeatValue)
+       {
+               case MSG_ALERT_TONE_ONCE:
+                       nRepeatTime = 0;
+               break;
+
+               case MSG_ALERT_TONE_2MINS:
+                       nRepeatTime = 2;
+               break;
+
+               case MSG_ALERT_TONE_5MINS:
+                       nRepeatTime = 5;
+               break;
+
+               case MSG_ALERT_TONE_10MINS:
+                       nRepeatTime = 10;
+               break;
+
+               default:
+                       MSG_DEBUG("Invalid Repetition time");
+               break;
+       }
+
+       MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
+
+       if (nRepeatTime > 0) {
+               if (g_alarmId > 0) {
+                       if (MsgAlarmRemove(g_alarmId) != MSG_SUCCESS) {
+                               MSG_FATAL("MsgAlarmRemove fail.");
+                       }
+                       g_alarmId = 0;
+               }
+               MsgSoundCreateRepeatAlarm(nRepeatTime);
+       }
+
+       return;
+}
+
+
+void MsgSoundPlayer::MsgSoundCreateRepeatAlarm(int RepeatTime)
+{
+       MSG_BEGIN();
+
+       int alarmId = 0;
+       time_t tmp_time;
+       struct tm repeat_tm;
+
+       time(&tmp_time);
+
+       tmp_time += (RepeatTime*60);
+       tzset();
+       localtime_r(&tmp_time, &repeat_tm);
+
+       if (MsgAlarmRegistration(&repeat_tm, MsgSoundRepeatAlarmCB, &alarmId) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgAlarmRegistration fail.");
+               return;
+       }
+
+       g_alarmId = alarmId;
+       MSG_DEBUG("Set g_alarmId to [%d]", alarmId);
+
+       MSG_END();
+
+       return;
+}
+
+
+int MsgSoundPlayer::MsgSoundGetUnreadMsgCnt()
+{
+       int unreadCnt = 0;
+
+       // Get SMS Count
+       unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
+
+       // Get MMS Count
+       unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
+
+       MSG_DEBUG("unread count : [%d]", unreadCnt);
+
+       return unreadCnt;
+}
+
+void MsgSoundPlayer::MsgSoundInitRepeatAlarm()
+{
+       MSG_BEGIN();
+
+       int nRepeatValue = 0;
+       long    nRepeatTime = 0;
+
+       g_alarmId = 0;
+
+       if (MsgSoundGetUnreadMsgCnt() <= 0) {
+               MSG_DEBUG("no unread msg");
+               return;
+       }
+
+       nRepeatValue = MsgSettingGetInt(MSG_ALERT_REP_TYPE);
+
+       switch (nRepeatValue)
+       {
+               case MSG_ALERT_TONE_ONCE:
+                       nRepeatTime = 0;
+               break;
+
+               case MSG_ALERT_TONE_2MINS:
+                       nRepeatTime = 2;
+               break;
+
+               case MSG_ALERT_TONE_5MINS:
+                       nRepeatTime = 5;
+               break;
+
+               case MSG_ALERT_TONE_10MINS:
+                       nRepeatTime = 10;
+               break;
+
+               default:
+                       MSG_DEBUG("Invalid Repetition time");
+               break;
+       }
+
+       MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
+
+       if (nRepeatTime > 0)
+               MsgSoundPlayStart(NULL, MSG_SOUND_PLAY_USER);
+
+       MSG_END();
+}
similarity index 56%
rename from utils/MsgSpamFilter.cpp
rename to externals/MsgSpamFilter.cpp
index 18c1ca1..6c2919c 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -58,6 +58,18 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
        msg_error_t err = MSG_SUCCESS;
 
        // =======================================================================
+       // Check Unknown Sender
+       // =======================================================================
+       bool bBlockUnknown = false;
+
+       if (MsgSettingGetBool(MSG_BLOCK_UNKNOWN_MSG, &bBlockUnknown) == MSG_SUCCESS) {
+               if (bBlockUnknown == true && pMsgInfo->addressList[0].addressVal[0] == '\0') {
+                       MSG_DEBUG("Unknown sender message!!");
+                       return true;
+               }
+       }
+
+       // =======================================================================
        // Check Filter Operation
        // =======================================================================
        bool filterFlag = false;
@@ -80,26 +92,24 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND '%s' LIKE (CASE WHEN LENGTH(FILTER_VALUE)>%d-1 THEN '%%'||SUBSTR(FILTER_VALUE, LENGTH(FILTER_VALUE)-%d-1) ELSE FILTER_VALUE END) AND FILTER_ACTIVE = 1 \
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND '%s' LIKE (CASE WHEN LENGTH(FILTER_VALUE)>%d-1 THEN '%%'||SUBSTR(FILTER_VALUE, LENGTH(FILTER_VALUE)-%d+1) ELSE FILTER_VALUE END) AND FILTER_ACTIVE = 1 \
                        UNION SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND '%s' LIKE SUBSTR(FILTER_VALUE,1)||'%%' AND FILTER_ACTIVE = 1 \
-                       UNION SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND '%s' LIKE '%%'||SUBSTR(FILTER_VALUE,1)||'%%' AND FILTER_ACTIVE = 1;",
-                       MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_ADDRESS_SAME, pMsgInfo->addressList[0].addressVal, MAX_PRECONFIG_NUM, MAX_PRECONFIG_NUM,
+                       UNION SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND '%s' LIKE '%%'||SUBSTR(FILTER_VALUE,1)||'%%' AND FILTER_ACTIVE = 1 \
+                       UNION SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND '%s' LIKE '%%'||SUBSTR(FILTER_VALUE,1) AND FILTER_ACTIVE = 1;",
+                       MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_ADDRESS_SAME, pMsgInfo->addressList[0].addressVal, MsgContactGetMinMatchDigit(), MsgContactGetMinMatchDigit(),
                        MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_ADDRESS_START, pMsgInfo->addressList[0].addressVal,
-                       MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_ADDRESS_INCLUDE, pMsgInfo->addressList[0].addressVal);
+                       MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_ADDRESS_INCLUDE, pMsgInfo->addressList[0].addressVal,
+                       MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_ADDRESS_END, pMsgInfo->addressList[0].addressVal);
 
        err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
-       if (err == MSG_ERR_DB_GETTABLE) {
-               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-       }
-
        if (rowCnt > 0) {
-               MSG_DEBUG("Msg is Filtered by Address : [%s]", pMsgInfo->addressList[0].addressVal);
+               MSG_SEC_DEBUG("Msg is Filtered by Address : [%s]", pMsgInfo->addressList[0].addressVal);
                pDbHandle->freeTable();
                pMsgInfo->folderId = MSG_SPAMBOX_ID;
                return true;
        } else {
-               MSG_DEBUG("Msg is NOT Filtered by Address : [%s]", pMsgInfo->addressList[0].addressVal);
+               MSG_SEC_DEBUG("Msg is NOT Filtered by Address : [%s]", pMsgInfo->addressList[0].addressVal);
                pDbHandle->freeTable();
        }
 
@@ -117,10 +127,8 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
        err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS) {
-               MSG_DEBUG("MsgGetTable() Error [%d] : [%s]", err, sqlQuery);
-
+               MSG_DEBUG("Fail to getTable().");
                pDbHandle->freeTable();
-
                return false;
        }
 
@@ -140,10 +148,16 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
 
                MSG_DEBUG("filterValue [%s]", filterValue);
 
-               if (strlen(filterValue) <= 0) continue;
+               if (strlen(filterValue) <= 0)
+                       continue;
 
                if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE && pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
                        if (pMsgInfo->bTextSms == false) {
+                               if (pData) {
+                                       delete[] pData;
+                                       pData = NULL;
+                               }
+
                                if (MsgOpenAndReadFile(pMsgInfo->msgData, &pData, &fileSize) == false) {
                                        pDbHandle->freeTable();
                                        return false;
@@ -151,6 +165,11 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
                                MSG_DEBUG("file data [%s]", pData);
                        } else {
                                if (pMsgInfo->dataSize > 0) {
+                                       if (pData) {
+                                               delete[] pData;
+                                               pData = NULL;
+                                       }
+
                                        pData = new char[pMsgInfo->dataSize+1];
 
                                        strncpy(pData, pMsgInfo->msgText, pMsgInfo->dataSize);
@@ -159,6 +178,11 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
                        }
                } else if(pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
                        if (strlen(pMsgInfo->subject) > 0) {
+                               if (pData) {
+                                       delete[] pData;
+                                       pData = NULL;
+                               }
+
                                pData = new char[strlen(pMsgInfo->subject)+1];
 
                                strncpy(pData, pMsgInfo->subject, strlen(pMsgInfo->subject));
@@ -177,14 +201,14 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
                MSG_DEBUG("pData [%s]", pData);
 
                if (strcasestr(pData, filterValue) != NULL) {
-
+#if 0
                        MSG_CONTACT_INFO_S contactInfo;
                        memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
 
                        // Get Contact Info
                        if (MsgGetContactInfo(&(pMsgInfo->addressList[0]), &contactInfo) == MSG_SUCCESS) {
                                if (contactInfo.contactId > 0) {
-                                       MSG_DEBUG("Msg is Filtered by Subject [%s] Data [%s], but address is in contact. Skip.", filterValue, pData);
+                                       MSG_SEC_DEBUG("Msg is Filtered by Subject [%s] Data [%s], but address is in contact. Skip.", filterValue, pData);
                                } else {
                                        MSG_DEBUG("Msg is Filtered by Subject [%s] Data [%s]", filterValue, pData);
                                        bFiltered = true;
@@ -193,6 +217,11 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
                        } else {
                                MSG_DEBUG("MsgGetContactInfo() fail.");
                        }
+#else
+                       MSG_DEBUG("Msg is Filtered by Subject [%s] Data [%s]", filterValue, pData);
+                       bFiltered = true;
+                       break;
+#endif
                }
        }
 
@@ -212,3 +241,79 @@ bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
 
        return false;
 }
+
+
+bool MsgCheckFilterByWord(MsgDbHandler *pDbHandle, const char *pMsgText)
+{
+       MSG_BEGIN();
+
+       if (!pMsgText) {
+               MSG_DEBUG("pMsgText is NULL");
+               return false;
+       }
+
+       msg_error_t err = MSG_SUCCESS;
+
+       // =======================================================================
+       // Check Filter Operation
+       // =======================================================================
+       bool filterFlag = false;
+
+       MsgGetFilterOperation(&filterFlag);
+
+       if (filterFlag == false) {
+               MSG_DEBUG("filter operation is not working");
+               return false;
+       }
+
+       int rowCnt = 0;
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+
+       // =======================================================================
+       // Check Filter by Word
+       // =======================================================================
+       // Get Filter List
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILTER_VALUE FROM %s WHERE FILTER_TYPE = %d;",
+                       MSGFW_FILTER_TABLE_NAME, MSG_FILTER_BY_WORD);
+
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               pDbHandle->freeTable();
+               return false;
+       }
+
+       char filterValue[MAX_FILTER_VALUE_LEN+1];
+       bool bFiltered = false;
+
+       for (int i = 1; i <= rowCnt; i++)
+       {
+               memset(filterValue, 0x00, sizeof(filterValue));
+
+               pDbHandle->getColumnToString(i, MAX_FILTER_VALUE_LEN, filterValue);
+
+               MSG_DEBUG("filterValue [%s]", filterValue);
+
+               if (strlen(filterValue) <= 0) continue;
+
+               if (strcasestr(pMsgText, filterValue) != NULL) {
+                       MSG_DEBUG("Msg is Filtered by Word [%s] ", filterValue);
+                       bFiltered = true;
+                       break;
+               }
+       }
+
+       pDbHandle->freeTable();
+
+       MSG_END();
+
+       return bFiltered;
+}
+
+
index ef2ad7f..ed20a98 100755 (executable)
@@ -42,7 +42,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 ADD_LIBRARY(${PLUGIN-MANAGER-LIB} SHARED ${PLUGIN-MANAGER-SRCS})
 TARGET_LINK_LIBRARIES(${PLUGIN-MANAGER-LIB} ${plugin_manager_pkgs_LDFLAGS} ${UTILS-LIB} dl)
 
-INSTALL(TARGETS ${PLUGIN-MANAGER-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${PLUGIN-MANAGER-LIB} LIBRARY DESTINATION lib)
 
 ##########################################################
 # Define Messaging Framework Handler
@@ -66,6 +66,7 @@ INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/include/common
        ${CMAKE_SOURCE_DIR}/include/framework
        ${CMAKE_SOURCE_DIR}/include/utils
+       ${CMAKE_SOURCE_DIR}/include/externals
        ${CMAKE_SOURCE_DIR}/vobject-engine/include      
 )
 
@@ -83,9 +84,9 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${FW-HANDLER-LIB} SHARED ${FW-HANDLER-SRCS})
-TARGET_LINK_LIBRARIES(${FW-HANDLER-LIB} ${fw_handler_pkgs_LDFLAGS} ${UTILS-LIB} ${PLUGIN-MANAGER-LIB})
+TARGET_LINK_LIBRARIES(${FW-HANDLER-LIB} ${fw_handler_pkgs_LDFLAGS} ${UTILS-LIB} ${EXTERNALS-LIB} ${PLUGIN-MANAGER-LIB})
 
-INSTALL(TARGETS ${FW-HANDLER-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${FW-HANDLER-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 
 ##########################################################
 # Define Transaction Manager
@@ -103,6 +104,7 @@ INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/include/mapi
        ${CMAKE_SOURCE_DIR}/include/common
        ${CMAKE_SOURCE_DIR}/include/framework
+       ${CMAKE_SOURCE_DIR}/include/externals
        ${CMAKE_SOURCE_DIR}/include/utils
 )
 
@@ -120,9 +122,9 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${TRANS-MANAGER-LIB} SHARED ${TRANS-MANAGER-SRCS})
-TARGET_LINK_LIBRARIES(${TRANS-MANAGER-LIB} ${trans_manager_pkgs_LDFLAGS} ${UTILS-LIB} ${FW-HANDLER-LIB})
+TARGET_LINK_LIBRARIES(${TRANS-MANAGER-LIB} ${trans_manager_pkgs_LDFLAGS} ${UTILS-LIB} ${EXTERNALS-LIB} ${FW-HANDLER-LIB})
 
-INSTALL(TARGETS ${TRANS-MANAGER-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${TRANS-MANAGER-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 
 ##########################################################
 # Define Execute File
@@ -133,14 +135,15 @@ SET(MAIN-SRCS
 )
 
 INCLUDE_DIRECTORIES(
-    ${CMAKE_SOURCE_DIR}/include/mapi
+       ${CMAKE_SOURCE_DIR}/include/mapi
        ${CMAKE_SOURCE_DIR}/include/common
        ${CMAKE_SOURCE_DIR}/include/framework
+       ${CMAKE_SOURCE_DIR}/include/externals
        ${CMAKE_SOURCE_DIR}/include/utils
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(main_pkgs REQUIRED glib-2.0 dbus-glib-1 dlog vconf)
+pkg_check_modules(main_pkgs REQUIRED glib-2.0 dbus-glib-1 dlog vconf db-util)
 
 FOREACH(flag ${main_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -153,7 +156,7 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${MAIN-SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${main_pkgs_LDFLAGS} ${UTILS-LIB} ${PLUGIN-MANAGER-LIB} ${TRANS-MANAGER-LIB} ${FW-HANDLER-LIB})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${main_pkgs_LDFLAGS} ${UTILS-LIB} ${EXTERNALS-LIB} ${PLUGIN-MANAGER-LIB} ${TRANS-MANAGER-LIB} ${FW-HANDLER-LIB})
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 
index 241803e..d8a06cd 100755 (executable)
@@ -1,21 +1,20 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
-// for sl message browser launch
-#include <app_service.h>
+#include <app_control.h>
 
 #include "MsgDebug.h"
 #include "MsgUtilFile.h"
 #include "MsgStorageHandler.h"
 #include "MsgDeliverHandler.h"
 #include "MsgNotificationWrapper.h"
+#include "MsgDevicedWrapper.h"
 
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
-
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
+
+void MsgPlayTTSMode(MSG_SUB_TYPE_T msgSubType, msg_message_id_t msgId, bool isFavorites)
+{
+       MSG_BEGIN();
+
+       bool bNotification = true;
+
+       if (MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bNotification) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgSettingGetBool is failed.");
+       }
+
+       if (bNotification == false) {
+               MSG_DEBUG("Msg Alert notification is off.");
+               return;
+       }
+
+       bool isTTSOn = false;
+       MsgSettingGetBool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, &isTTSOn);
+       MSG_DEBUG("VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE [%d]", isTTSOn);
+
+       if(isTTSOn) {
+
+               bool isVoiceMail = false;
+
+               if (msgSubType == MSG_MWI_VOICE_SMS) {
+                       bool isVoiceMailOn = false;
+                       MsgSettingGetBool(VCONFKEY_SETAPPL_DRIVINGMODE_NEWVOICEMAILS, &isVoiceMailOn);
+                       MSG_DEBUG("VCONFKEY_SETAPPL_DRIVINGMODE_NEWVOICEMAILS [%d]", isVoiceMailOn);
+                       if (isVoiceMailOn) {
+                               isVoiceMail = true;
+                       } else {
+                               return;
+                       }
+               } else {
+                       bool isTTSMsgOn = false;
+                       MsgSettingGetBool(VCONFKEY_SETAPPL_DRIVINGMODE_MESSAGE, &isTTSMsgOn);
+                       MSG_DEBUG("VCONFKEY_SETAPPL_DRIVINGMODE_MESSAGE [%d]", isTTSMsgOn);
+                       if (!isTTSMsgOn || !isFavorites) {
+                               return;
+                       }
+               }
+
+               app_control_h svc_h;
+
+               int ret = APP_CONTROL_ERROR_NONE;
+
+               ret = app_control_create(&svc_h);
+               if (ret != APP_CONTROL_ERROR_NONE) {
+                       MSG_DEBUG("app_control_create() is failed : %d", ret);
+                       app_control_destroy(svc_h);
+                       return;
+               }
+
+               ret = app_control_set_app_id(svc_h, "org.tizen.msg-ui-tts-play");
+               if (ret != APP_CONTROL_ERROR_NONE) {
+                       MSG_DEBUG("app_control_set_app_id() is failed : %d", ret);
+                       app_control_destroy(svc_h);
+                       return;
+               }
+
+               if (isVoiceMail) {
+                       ret = app_control_add_extra_data(svc_h, "type", "voicemail");
+               } else {
+                       char tmpStrMsgId[10];
+                       memset(&tmpStrMsgId, 0x00, sizeof(tmpStrMsgId));
+                       snprintf(tmpStrMsgId, sizeof(tmpStrMsgId), "%d", msgId);
+                       MSG_DEBUG("tmpStrMsgId [%s]", tmpStrMsgId);
+                       ret = app_control_add_extra_data(svc_h, "msgId", tmpStrMsgId);
+               }
+
+               if (ret != APP_CONTROL_ERROR_NONE) {
+                       MSG_DEBUG("app_control_add_extra_data() is failed : %d", ret);
+                       app_control_destroy(svc_h);
+                       return;
+               }
+
+               ret = app_control_send_launch_request(svc_h, NULL, NULL);
+               if (ret != APP_CONTROL_ERROR_NONE) {
+                       MSG_DEBUG("app_control_send_launch_request() is failed : %d", ret);
+                       app_control_destroy(svc_h);
+                       return;
+               }
+
+               app_control_destroy(svc_h);
+       }
+
+       MsgChangePmState();
+
+       MSG_END();
+}
+
+
+void MsgLaunchClass0(msg_message_id_t msgId)
+{
+       MSG_BEGIN();
+
+       app_control_h svc_h;
+
+       int ret = APP_CONTROL_ERROR_NONE;
+
+       ret = app_control_create(&svc_h);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               MSG_DEBUG("app_control_create() is failed : %d", ret);
+               app_control_destroy(svc_h);
+               return;
+       }
+
+       ret = app_control_set_app_id(svc_h, "org.tizen.msg-ui-class0");
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               MSG_DEBUG("app_control_set_app_id() is failed : %d", ret);
+               app_control_destroy(svc_h);
+               return;
+       }
+
+       ret = app_control_add_extra_data(svc_h, "type", "msg_id");
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               MSG_DEBUG("app_control_add_extra_data() is failed : %d", ret);
+               app_control_destroy(svc_h);
+               return;
+       }
+
+       char tmpStrMsgId[10];
+       memset(&tmpStrMsgId, 0x00, sizeof(tmpStrMsgId));
+       snprintf(tmpStrMsgId, sizeof(tmpStrMsgId), "%d", msgId);
+       MSG_DEBUG("tmpStrMsgId [%s]", tmpStrMsgId);
+       ret = app_control_add_extra_data(svc_h, "msgId", tmpStrMsgId);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               MSG_DEBUG("app_control_add_extra_data() is failed : %d", ret);
+               app_control_destroy(svc_h);
+               return;
+       }
+
+       ret = app_control_send_launch_request(svc_h, NULL, NULL);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               MSG_DEBUG("app_control_send_launch_request() is failed : %d", ret);
+               app_control_destroy(svc_h);
+               return;
+       }
+
+       app_control_destroy(svc_h);
+
+       MSG_END();
+}
+
+
 msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_request_id_t reqID)
 {
        MSG_BEGIN();
 
        msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
        MSG_DEBUG(" msgtype subtype is [%d]", pMsgInfo->msgType.subType);
 
@@ -51,13 +195,15 @@ msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_reques
                MSG_SUB_TYPE_T subType = pMsgInfo->msgType.subType;
 
                /* If Retrieve Failed, Msg SubType is remained as Notification Ind */
-               if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL)
+               if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL) {
+                       pMsgInfo->folderId = MSG_INBOX_ID;
                        pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
+               }
 
-               err = MsgStoUpdateMMSMessage(pMsgInfo);
-
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
+//             err = MsgStoUpdateMMSMessage(pMsgInfo);
+//
+//             if (err == MSG_SUCCESS)
+//                     MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
 
                if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
                        MSG_DEBUG("### MSG_NETWORK_RETRIEVE_SUCCESS ###");
@@ -73,6 +219,12 @@ msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_reques
                                return MSG_ERR_STORAGE_ERROR;
                }
 
+               err = MsgStoUpdateMMSMessage(pMsgInfo);//For Text Update
+
+               if (err == MSG_SUCCESS)
+                       MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
+
+
                MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");
 
                bool readStatus = false;
@@ -84,37 +236,33 @@ msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_reques
                if (subType == MSG_RETRIEVE_MANUALCONF_MMS && pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
                        MSG_DEBUG("###2. subType = %d ###", pMsgInfo->msgType.subType);
 
-                       if (readStatus == true)
-                               MsgStoSetReadStatus(&dbHandle, pMsgInfo->msgId, false);
-               }
-
-               // update badge
-               if (subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
-                       int smsCnt = 0;
-                       int mmsCnt = 0;
-
-                       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-                       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-                       MsgSettingHandleNewMsg(smsCnt, mmsCnt);
+                       if (readStatus == true) {
+                               MsgStoSetReadStatus(dbHandle, pMsgInfo->msgId, false);
+                               MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, false, false);
+                       }
                }
 
                if (subType == MSG_RETRIEVE_AUTOCONF_MMS) {
-                       // play message-tone when MMS retrieved
-                       MsgSoundPlayStart(false);
+                       bool isFavorites = false;
+                       if (!checkBlockingMode(pMsgInfo->addressList[0].addressVal, &isFavorites)) {
+                               MsgPlayTTSMode(subType, pMsgInfo->msgId, isFavorites);
+                       }
 
                        // add phone log
                        MSG_DEBUG("Enter MsgAddPhoneLog() for mms message.");
                        MsgAddPhoneLog(pMsgInfo);
 
-                       MsgInsertNoti(pMsgInfo);
+                       if (pMsgInfo->folderId == MSG_INBOX_ID)
+                               MsgInsertNotification(pMsgInfo);
+
                }  else if (subType == MSG_RETRIEVE_MANUALCONF_MMS) {
                        if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
                                MSG_DEBUG("Manual success");
-                               MsgInsertTicker("Message Retrieved", MESSAGE_RETRIEVED);
+                               if (pMsgInfo->folderId == MSG_INBOX_ID)
+                                       MsgInsertTicker("Message Retrieved", MESSAGE_RETRIEVED, true, 0);
                        } else if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL) {
                                MSG_DEBUG("Manual failed");
-                               MsgInsertTicker("Retrieving message failed", RETRIEVING_MESSAGE_FAILED);
+                               MsgInsertTicker("Retrieving message failed", RETRIEVING_MESSAGE_FAILED, true, pMsgInfo->msgId);
                        }
                }
        }
@@ -133,7 +281,7 @@ msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_reques
                        return MSG_ERR_STORAGE_ERROR;
 
                MSG_DEBUG("pMsg->networkStatus : %d", pMsgInfo->networkStatus);
-               err = MsgStoUpdateNetworkStatus(&dbHandle, pMsgInfo, pMsgInfo->networkStatus);
+               err = MsgStoUpdateNetworkStatus(dbHandle, pMsgInfo, pMsgInfo->networkStatus);
                if (err != MSG_SUCCESS)
                        return MSG_ERR_STORAGE_ERROR;
 
@@ -158,25 +306,20 @@ msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
 
        msg_error_t err = MSG_SUCCESS;
 
+       MsgDisplayLock();
+
        if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
 
                bool bOnlyNoti = false;
 
                err = MsgHandleSMS(pMsgInfo, pSendNoti, &bOnlyNoti);
 
-               if (err == MSG_SUCCESS&& ((*pSendNoti)||bOnlyNoti)) {
-                       MsgSoundPlayStart(false);
-                       if (*pSendNoti == true) {
-                               int smsCnt = 0, mmsCnt = 0;
-
-                               smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-                               mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-                               MsgSettingHandleNewMsg(smsCnt, mmsCnt);
-                               MsgInsertNoti(pMsgInfo);
-                       } else if (bOnlyNoti == true) {
-                               MsgInsertNoti(pMsgInfo);
+               if (err == MSG_SUCCESS && ((*pSendNoti)||bOnlyNoti)) {
+                       bool isFavorites = false;
+                       if (!checkBlockingMode(pMsgInfo->addressList[0].addressVal, &isFavorites)) {
+                               MsgPlayTTSMode(pMsgInfo->msgType.subType, pMsgInfo->msgId, isFavorites);
                        }
+                       MsgInsertNotification(pMsgInfo);
                }
        }
        else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
@@ -184,6 +327,8 @@ msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
                err = MsgHandleMMS(pMsgInfo, pSendNoti);
        }
 
+       MsgDisplayUnlock();
+
        //Add Phone Log Data
        if ((err == MSG_SUCCESS) &&
                (pMsgInfo->folderId == MSG_INBOX_ID || pMsgInfo->folderId == MSG_SPAMBOX_ID) &&
@@ -195,6 +340,9 @@ msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
                MsgAddPhoneLog(pMsgInfo);
        }
 
+       // Auto delete
+       //MsgStoAutoDeleteConversation(pMsgInfo->threadId);
+
        MSG_END();
 
        return err;
@@ -204,14 +352,112 @@ msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
 msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bOnlyNoti)
 {
        msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
        if (pMsgInfo->msgPort.valid == true) {
-                       *pSendNoti = false;
-                       *bOnlyNoti = false;
-                       return MSG_SUCCESS;
+               *pSendNoti = false;
+               *bOnlyNoti = false;
+               return MSG_SUCCESS;
        }
+
+       // Add SMS message
+       MSG_SENDINGOPT_INFO_S send_opt;
+       memset(&send_opt, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
+
+       if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
+#ifdef MSG_NOTI_INTEGRATION
+               MSG_DEBUG("Copy Class2 message to phone storage.");
+               pMsgInfo->msgType.classType = MSG_CLASS_NONE;
+               pMsgInfo->storageId = MSG_STORAGE_PHONE;
+               pMsgInfo->msgId = 0;
+#else
+               MSG_DEBUG("Class2 message is already added.");
+               return MSG_SUCCESS;
+#endif
+       }
+
        if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
-               if (MsgCheckFilter(&dbHandle, pMsgInfo) == true) {
+               MSG_DEBUG("Add Normal Message");
+               err = MsgStoAddMessage(pMsgInfo, &send_opt);
+       } else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
+               MSG_DEBUG("Add Replace Message");
+
+               pMsgInfo->msgId = 0;
+               MsgStoGetReplaceMsgId(pMsgInfo);
+
+               if (pMsgInfo->msgId > 0) {
+                       err = MsgStoUpdateMessage(pMsgInfo, &send_opt);
+               } else {
+                       err = MsgStoAddMessage(pMsgInfo, &send_opt);
+                       pMsgInfo->msgType.subType = MSG_NORMAL_SMS; // To make 'insert' type for storage change callback.
+               }
+       } else if ((pMsgInfo->msgType.subType == MSG_WAP_SI_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_CO_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_SL_SMS)) {
+               MSG_DEBUG("Add WAP Push Message");
+               switch (pMsgInfo->msgType.subType)
+               {
+                       case MSG_WAP_SI_SMS:
+                       case MSG_WAP_SL_SMS:
+                               err = MsgStoAddWAPMsg(pMsgInfo);
+                               break;
+                       case MSG_WAP_CO_SMS:
+                               err = MsgStoAddCOWAPMsg(pMsgInfo);
+                               break;
+                       default :
+                               break;
+               }
+       } else if ((pMsgInfo->msgType.subType == MSG_CB_SMS) || (pMsgInfo->msgType.subType == MSG_JAVACB_SMS)) {
+               /** check add message option */
+       }
+       else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
+               MSG_DEBUG("Add Report Message");
+       }
+       else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, pMsgInfo->sim_idx);
+               char *number = MsgSettingGetString(keyName);
+               int addrSize = strlen(pMsgInfo->addressList[0].addressVal);
+               char newPhoneNum[addrSize+1];
+               memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+               MsgConvertNumber(pMsgInfo->addressList[0].addressVal, newPhoneNum, addrSize);
+
+               if (g_str_has_suffix(number, newPhoneNum)) {
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, pMsgInfo->sim_idx);
+                       char *alphaid = MsgSettingGetString(keyName);
+                       if(alphaid)
+                       {
+                               memset(pMsgInfo->addressList->displayName, 0x00, sizeof(pMsgInfo->addressList->displayName));
+                               memcpy(pMsgInfo->addressList->displayName, alphaid, sizeof(pMsgInfo->addressList->displayName));
+                               g_free(alphaid);
+                               alphaid = NULL;
+                       }
+               }
+
+               if(number)
+               {
+                       g_free(number);
+                       number = NULL;
+               }
+
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, pMsgInfo->sim_idx);
+               int voicecnt = MsgSettingGetInt(keyName);
+               memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
+               snprintf(pMsgInfo->msgText, sizeof(pMsgInfo->msgText), "%d", voicecnt);
+               pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
+               MSG_DEBUG("Add Voice or other Message");
+       }
+       else {
+               MSG_DEBUG("No matching type [%d]", pMsgInfo->msgType.subType);
+               return err;
+       }
+
+       if (err != MSG_SUCCESS)
+               MSG_DEBUG("Add message - Error : [%d]", err);
+
+       if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
+               if (MsgCheckFilter(dbHandle, pMsgInfo) == true) {
                        // Move to SpamBox
                        err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);
 
@@ -221,12 +467,15 @@ msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bO
                                pMsgInfo->folderId = MSG_SPAMBOX_ID;
                        }
 
-                       // Update Conversation table
-                       err = MsgStoUpdateConversation(&dbHandle, pMsgInfo->threadId);
-
-                       if (err != MSG_SUCCESS)
-                               MSG_DEBUG("MsgStoUpdateConversation() Error : [%d]", err);
-
+                       *pSendNoti = false;
+                       *bOnlyNoti = false;
+               } else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
+                       MsgLaunchClass0(pMsgInfo->msgId);
+                       bool isFavorites = false;
+                       if (!checkBlockingMode(pMsgInfo->addressList[0].addressVal, &isFavorites)) {
+                               MsgPlayTTSMode(pMsgInfo->msgType.subType, pMsgInfo->msgId, isFavorites);
+                               MsgSoundPlayer::instance()->MsgSoundPlayStart(&(pMsgInfo->addressList[0]), MSG_SOUND_PLAY_USER);
+                       }
                        *pSendNoti = false;
                        *bOnlyNoti = false;
                }
@@ -234,15 +483,15 @@ msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bO
                MSG_DEBUG("Starting WAP Message Incoming.");
 
                MSG_PUSH_SERVICE_TYPE_T serviceType = (MSG_PUSH_SERVICE_TYPE_T)MsgSettingGetInt(PUSH_SERVICE_TYPE);
-               service_h svc_handle = NULL;
+               app_control_h svc_handle = NULL;
 
                switch (pMsgInfo->msgType.subType) {
                        case MSG_WAP_SL_SMS:
                        {
-                               *pSendNoti = false;
+                               *pSendNoti = true;
 
                                if (serviceType == MSG_PUSH_SERVICE_ALWAYS) {
-                                       if (service_create(&svc_handle) < 0) {
+                                       if (app_control_create(&svc_handle) < 0) {
                                                MSG_DEBUG("Fail to create service handle");
                                                break;
                                        }
@@ -250,38 +499,78 @@ msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bO
                                                MSG_DEBUG("Service handle is NULL");
                                                break;
                                        }
-                                       if (service_set_operation(svc_handle, SERVICE_OPERATION_VIEW) < 0) {
+                                       if (app_control_set_operation(svc_handle, APP_CONTROL_OPERATION_VIEW) < 0) {
                                                MSG_DEBUG("Fail to create service handle");
-                                               service_destroy(svc_handle);
+                                               app_control_destroy(svc_handle);
                                                break;
                                        }
-                                       if (service_set_uri(svc_handle, pMsgInfo->msgText) < 0) {
+                                       if (app_control_set_uri(svc_handle, pMsgInfo->msgText) < 0) {
                                                MSG_DEBUG("Fail to set uri");
-                                               service_destroy(svc_handle);
+                                               app_control_destroy(svc_handle);
                                                break;
                                        }
-                                       if (service_set_package(svc_handle, MSG_SVC_PKG_NAME_BROWSER) < 0) {
+                                       if (app_control_set_app_id(svc_handle, MSG_SVC_PKG_NAME_BROWSER) < 0) {
                                                MSG_DEBUG("Fail to set package");
-                                               service_destroy(svc_handle);
+                                               app_control_destroy(svc_handle);
                                                break;
                                        }
-                                       if (service_send_launch_request(svc_handle, NULL, NULL) < 0) {
+                                       if (app_control_send_launch_request(svc_handle, NULL, NULL) < 0) {
                                                MSG_DEBUG("Fail to launch browser");
-                                               service_destroy(svc_handle);
+                                               app_control_destroy(svc_handle);
                                                break;
                                        }
 
-                                       service_destroy(svc_handle);
+                                       app_control_destroy(svc_handle);
 
                                } else if (serviceType == MSG_PUSH_SERVICE_PROMPT) {
-                                       char urlString[MAX_COMMAND_LEN+1];
-                                       memset(urlString, 0x00, sizeof(urlString));
 
-                                       snprintf(urlString, MAX_COMMAND_LEN, "/usr/apps/org.tizen.message/bin/message-dialog -m PUSH_MSG_ALWAYS_ASK -u %s &", pMsgInfo->msgText);
+                                       MSG_DEBUG("WAP Message SL(Always Ask) start.");
 
-                                       system(urlString);
-                               }
+                                       app_control_h svc_h;
+                                       int ret = APP_CONTROL_ERROR_NONE;
+
+                                       ret = app_control_create(&svc_h);
+                                       if (ret != APP_CONTROL_ERROR_NONE) {
+                                               MSG_DEBUG("app_control_create() is failed : %d", ret);
+                                               break;
+                                       }
+
+                                       ret = app_control_set_app_id(svc_h, "org.tizen.message-dialog");
+                                       if (ret != APP_CONTROL_ERROR_NONE) {
+                                               MSG_DEBUG("app_control_set_app_id() is failed : %d", ret);
+                                               app_control_destroy(svc_h);
+                                               break;
+                                       }
+
+                                       ret = app_control_add_extra_data(svc_h, "mode", "WAP_PUSH_SL");
+                                       if (ret != APP_CONTROL_ERROR_NONE) {
+                                               MSG_DEBUG("app_control_add_extra_data() is failed : %d", ret);
+                                               app_control_destroy(svc_h);
+                                               break;
+                                       }
+
+                                       ret = app_control_add_extra_data(svc_h, "url", pMsgInfo->msgText);
+                                       if (ret != APP_CONTROL_ERROR_NONE) {
+                                               MSG_DEBUG("app_control_add_extra_data() is failed : %d", ret);
+                                               app_control_destroy(svc_h);
+                                               break;
+                                       }
 
+                                       ret = app_control_add_extra_data(svc_h, "address", pMsgInfo->addressList[0].addressVal);
+                                       if (ret != APP_CONTROL_ERROR_NONE) {
+                                               MSG_DEBUG("app_control_add_extra_data() is failed : %d", ret);
+                                               app_control_destroy(svc_h);
+                                               break;
+                                       }
+
+                                       ret = app_control_send_launch_request(svc_h, NULL, NULL);
+                                       if (ret != APP_CONTROL_ERROR_NONE) {
+                                               MSG_DEBUG("app_control_send_launch_request() is failed : %d", ret);
+                                       }
+
+                                       app_control_destroy(svc_h);
+                                       MSG_DEBUG("app_control_destroy() returns : %d", ret);
+                               }
                        }
                        break;
 
@@ -300,8 +589,13 @@ msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bO
                        *pSendNoti = false;
                        *bOnlyNoti = true;
                }
-       } 
+       }
+
+       // Update Conversation table
+       err = MsgStoUpdateConversation(dbHandle, pMsgInfo->threadId);
 
+       if (err != MSG_SUCCESS)
+               MSG_DEBUG("MsgStoUpdateConversation() Error : [%d]", err);
 
        return err;
 }
@@ -310,7 +604,7 @@ msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bO
 msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
 {
        msg_error_t err = MSG_SUCCESS;
-
+       MsgDbHandler *dbHandle = getDbHandle();
        MSG_REQUEST_INFO_S request = {0};
        bool bReject = false;
        bool bFiltered = false;
@@ -319,6 +613,28 @@ msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
        MSG_MAIN_TYPE_T msgMainType = pMsgInfo->msgType.mainType;
        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
 
+       //Read the default network SIM
+       MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
+
+       if (sms_plg == NULL)
+               return MSG_ERR_NULL_POINTER;
+
+       int defaultNetworkSimId = 0;
+
+       err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
+
+       MSG_DEBUG("######defaultNetworkSimId = %d, err = %d", defaultNetworkSimId, err);
+
+       if (err != MSG_SUCCESS) {
+               MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
+               return err;
+       }
+
+       err = MsgSettingSetInt(MSG_NETWORK_SIM, (int)defaultNetworkSimId);
+       if (err != MSG_SUCCESS) {
+               MSG_ERR("Error to set config data [%s], err = %d", MSG_NETWORK_SIM, err);
+               return err;
+       }
        // Need to process m-delivery-ind, m-notification-ind, m-read-orig-ind
        err = plg->processReceivedInd(pMsgInfo, &request, &bReject);
 
@@ -326,16 +642,35 @@ msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
                MSG_DEBUG("Process Message Success : processReceivedInd(), btextsms %d", pMsgInfo->bTextSms);
        } else {
                MSG_DEBUG("Process Message Fail : processReceivedInd()");
+               *pSendNoti = false;
                return err;
        }
 
        // Add into DB
        if ((pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) && bReject == false) {
-               bFiltered = MsgCheckFilter(&dbHandle, pMsgInfo);
+               //bFiltered = MsgCheckFilter(dbHandle, pMsgInfo);
+               if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
+                       bFiltered = true;
+               }
 
                if (bFiltered == true) {
+                       err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);
+
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
+                       } else {
+                               pMsgInfo->folderId = MSG_SPAMBOX_ID;
+                       }
+
                        pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
                        *pSendNoti = false;
+               } else {/* If it is not SPAM message, it should be check whether filter option is enable or not. */
+                       bool filterFlag = false;
+                       MsgGetFilterOperation(&filterFlag);
+                       if (filterFlag == true && request.msgInfo.msgType.subType == MSG_GET_MMS) {
+                                /* Not to show MMS notification msg until it retrieves. */
+                               pMsgInfo->folderId = MSG_IOSBOX_ID;
+                       }
                }
 
                err = MsgStoAddMessage(pMsgInfo, NULL);
@@ -345,37 +680,56 @@ msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
                        return err;
                }
        } else if (pMsgInfo->msgType.subType == MSG_READORGIND_MMS || pMsgInfo->msgType.subType == MSG_DELIVERYIND_MMS) {
-               if (MsgInsertMmsReportToNoti(&dbHandle, pMsgInfo) == MSG_SUCCESS) {
-                       MsgSoundPlayStart(false);
+               if (MsgInsertNotification(pMsgInfo) == MSG_SUCCESS) {
+                       bool isFavorites = false;
+                       if (!checkBlockingMode(pMsgInfo->addressList[0].addressVal, &isFavorites)) {
+                               MsgPlayTTSMode(pMsgInfo->msgType.subType, pMsgInfo->msgId, isFavorites);
+                       }
                        *pSendNoti = false;
                }
        }
 
+#if 0
+       if (pMsgInfo->bTextSms == false) {
+               MsgDeleteFile(pMsgInfo->msgData); //ipc
+               memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
+       }
+#endif
        //In the case of m-notification-ind, we should decide whether to send m-notify-response-ind or http 'Get'
        //submit request
-       if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS && bFiltered == false) {
-               if (request.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS && bReject == false) {
-                       MsgSoundPlayStart(false);
-
-                       int smsCnt = 0;
-                       int mmsCnt = 0;
 
-                       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-                       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
+       if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
+               if (request.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS && bReject == false && bFiltered == false) {
+                       bool isFavorites = false;
+                       if (!checkBlockingMode(pMsgInfo->addressList[0].addressVal, &isFavorites)) {
+                               MsgPlayTTSMode(pMsgInfo->msgType.subType, pMsgInfo->msgId, isFavorites);
+                       }
 
-                       MsgSettingHandleNewMsg(smsCnt, mmsCnt);
-                       MsgInsertNoti(pMsgInfo);
+                       MsgInsertNotification(pMsgInfo);
+               } else {
+                       *pSendNoti = false;
                }
 
-               request.msgInfo.msgId = pMsgInfo->msgId;
+               MSG_DEBUG("default_sim = %d, pMsgInfo->sim_idx = %d", defaultNetworkSimId, pMsgInfo->sim_idx);
 
-               MSG_DEBUG("-=====================[[[ %s ]]]] =========================", pMsgInfo->msgData);
-               err = plg->submitReq(&request);
+               if (defaultNetworkSimId == pMsgInfo->sim_idx) {
+                       request.msgInfo.msgId = pMsgInfo->msgId;
+
+                       MSG_DEBUG("-=====================[[[ %s ]]]] =========================", request.msgInfo.msgData);
+                       err = plg->submitReq(&request);
+
+                       if (err == MSG_SUCCESS) {
+                               MSG_DEBUG("Process Message Success : processReceivedInd()");
+
+                               if (request.msgInfo.msgType.subType == MSG_GET_MMS) {
+                                       MSG_DEBUG("Auto Retrieve Mode : update network status retrieving");
+                                       MsgStoUpdateNetworkStatus(dbHandle, &(request.msgInfo), MSG_NETWORK_RETRIEVING);
+                               }
+
+                       } else {
+                               MSG_DEBUG("Process Message Fail : processReceivedInd()");
+                       }
 
-               if (err == MSG_SUCCESS) {
-                       MSG_DEBUG("Process Message Success : processReceivedInd()");
-               } else {
-                       MSG_DEBUG("Process Message Fail : processReceivedInd()");
                }
        }
 
index 9f182c1..b431e8c 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 /*==================================================================================================
@@ -31,6 +31,7 @@
 #include "MsgStorageTypes.h"
 #include "MsgSoundPlayer.h"
 #include "MsgCmdHandler.h"
+#include "MsgUtilFile.h"
 #include "MsgUtilStorage.h"
 #include "MsgNotificationWrapper.h"
 
 
 static GMainLoop* mainloop = NULL;
 
-
-/*==================================================================================================
-                                     DEFINES
-==================================================================================================*/
-#define MSG_MOBILE_TRACKER_MSG "Mobile Tracker Alert"
-
-
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
@@ -71,11 +65,11 @@ msg_error_t InitMmsDir()
        {
                if (errno == EEXIST)
                {
-                       MSG_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
+                       MSG_SEC_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
                }
                else
                {
-                       MSG_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
+                       MSG_SEC_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
                        return MSG_ERR_DB_MAKE_DIR;
                }
        }
@@ -107,11 +101,8 @@ msg_error_t InitMmsDir()
                if (errno == EEXIST)
                {
                        MSG_DEBUG("The %s already exists", MSG_IPC_DATA_PATH);
-
                        // if IPC data path is already exist, clear all files in folder.
-                       char exeStr[1024];
-                       snprintf(exeStr, 1024, "rm %s*.DATA", MSG_IPC_DATA_PATH);
-                       system(exeStr);
+                       MsgRmRf((char *)MSG_IPC_DATA_PATH);
                }
                else
                {
@@ -120,164 +111,49 @@ msg_error_t InitMmsDir()
                }
        }
 
-       if(chmod( MSG_IPC_DATA_PATH, S_IRWXU | S_IRWXG ) !=0) { //public shared file: pass data by file
+       if(MsgChmod( MSG_IPC_DATA_PATH, S_IRWXU | S_IRWXG ) == 0) { //public shared file: pass data by file
                MSG_DEBUG("Fail to chmod [%s].", MSG_IPC_DATA_PATH);
        }
-       chown( MSG_IPC_DATA_PATH, 0, 6502 );
-
-       return MSG_SUCCESS;
-}
-
-
-void SendMobileTrackerMsg()
-{
-       MSG_BEGIN();
-
-       bool bEnabled = false;
-
-       if (MsgSettingGetBool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_SIM_CHANGE_ALERT_BOOL, &bEnabled) < 0)
-       {
-               MSG_DEBUG("Can't read VCONFKEY_SETAPPL_FIND_MY_MOBILE_SIM_CHANGE_ALERT_BOOL");
-               return;
-       }
-
-       if (bEnabled == false)
-       {
-               MSG_DEBUG("Mobile Tracker Option [%d]", bEnabled);
-               return;
-       }
-       // to wait modem init
-       // temporary code.
-       else
-       {
-               MSG_DEBUG("Waiting for modem ready, 22 sec.");
-               sleep(22);
+       if(MsgChown( MSG_DATA_ROOT_PATH, 0, 5000 ) == 0) {
+               MSG_DEBUG("Fail to chown [%s].", MSG_DATA_ROOT_PATH);
        }
-
-       MSG_REQUEST_INFO_S req = {0};
-
-       req.sendOptInfo.bSetting = false;
-
-       req.msgInfo.msgId = 0;
-       req.msgInfo.threadId = 0;
-       req.msgInfo.folderId = MSG_DRAFT_ID;
-       req.msgInfo.msgType.mainType = MSG_SMS_TYPE;
-       req.msgInfo.msgType.subType = MSG_NORMAL_SMS;
-       req.msgInfo.msgType.classType = MSG_CLASS_NONE;
-       req.msgInfo.storageId = MSG_STORAGE_PHONE;
-       req.msgInfo.displayTime = 0;
-       req.msgInfo.networkStatus = MSG_NETWORK_NOT_SEND;
-       req.msgInfo.encodeType = MSG_ENCODE_AUTO;
-       req.msgInfo.bRead = false;
-       req.msgInfo.bProtected = false;
-       req.msgInfo.priority = MSG_MESSAGE_PRIORITY_NORMAL;
-       req.msgInfo.direction = MSG_DIRECTION_TYPE_MO;
-       req.msgInfo.msgPort.valid = false;
-       req.msgInfo.bTextSms = true;
-
-       // Get Message Text
-       char* msgText = NULL;
-
-       msgText = MsgSettingGetString(VCONFKEY_SETAPPL_FIND_MY_MOBILE_MESSAGE_STR);
-
-       if (msgText == NULL)
-       {
-               MSG_DEBUG("Assign Default Msg");
-               msgText = strdup(MSG_MOBILE_TRACKER_MSG);
-               if (msgText == NULL) {
-                       MSG_DEBUG("msgText is NULL.");
-                       return;
-               }
+       if(MsgChown( MSG_DATA_PATH, 0, 5000 ) == 0) {
+               MSG_DEBUG("Fail to chown [%s].", MSG_DATA_PATH);
        }
-
-       MSG_DEBUG("mobile tracker msg : [%s]", msgText);
-
-       req.msgInfo.dataSize = strlen(msgText);
-       strncpy(req.msgInfo.msgText, msgText, req.msgInfo.dataSize);
-
-       // Get Address List
-       char *orgRecipientList = NULL;
-
-       orgRecipientList = MsgSettingGetString(VCONFKEY_SETAPPL_FIND_MY_MOBILE_RECIPIENTS_STR);
-
-       if (orgRecipientList == NULL)
-       {
-               MSG_DEBUG("recipient list is NULL");
-               free(msgText);
-               msgText = NULL;
-               return;
-       }
-
-       int len = strlen(orgRecipientList);
-       char recipientList[len + 1];
-
-       memset(recipientList, 0, len + 1);
-       memcpy(recipientList, orgRecipientList, len);
-
-       MSG_DEBUG("recipient list : [%s]", recipientList);
-
-       req.msgInfo.nAddressCnt = 1;
-
-       char *token;
-
-       token = strtok(recipientList, "|");
-
-       MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
-       MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
-
-       msg_error_t err = MSG_SUCCESS;
-
-       while (token)
-       {
-               req.msgInfo.addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
-               req.msgInfo.addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
-
-               memset(req.msgInfo.addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN);
-               strncpy(req.msgInfo.addressList[0].addressVal, token, MAX_ADDRESS_VAL_LEN);
-
-               MSG_DEBUG("address : [%s]", req.msgInfo.addressList[0].addressVal);
-
-               if (plg != NULL)
-               {
-                       MSG_DEBUG("mobile tracker msg : [%s]", msgText);
-
-                       err = plg->submitReq(&req);
-
-                       if (err != MSG_SUCCESS)
-                       {
-                               MSG_DEBUG("fail to send mobile tracker msg : [%d]", err);
-                               break;
-                       }
-               }
-
-               token = strtok(NULL, "|");
+       if(MsgChown( MSG_SMIL_FILE_PATH, 0, 5000 ) == 0) {
+               MSG_DEBUG("Fail to chown [%s].", MSG_SMIL_FILE_PATH);
        }
-
-       if (msgText) {
-               free(msgText);
-               msgText = NULL;
+       if(MsgChown( MSG_IPC_DATA_PATH, 0, 5000 ) == 0) {
+               MSG_DEBUG("Fail to chown [%s].", MSG_IPC_DATA_PATH);
        }
-
-       if (orgRecipientList) {
-               free(orgRecipientList);
-               orgRecipientList = NULL;
+       if(MsgChown( MSG_THUMBNAIL_PATH, 0, 5000 ) == 0) {
+               MSG_DEBUG("Fail to chown [%s].", MSG_THUMBNAIL_PATH);
        }
-
-
-       MSG_END();
-
-       return;
+       return MSG_SUCCESS;
 }
 
 
-void* StartMsgServer(void*)
+void* InitMsgServer(void*)
 {
+       msg_error_t err = MSG_SUCCESS;
+       MSG_DEBUG("Start InitMsgServer.");
 
-       MsgOpenContactSvc();
+       // Register Callback to get the change of contact
+       MsgInitContactSvc(&MsgContactChangedCallback);
 
+       //CID 356902: Moving try block up to include MsgStoInitDB which also throws MsgException
        try
        {
-               MsgTransactionManager::instance()->run();
+               // storage handler initialize
+               err = MsgStoInitDB(false);
+               if (err != MSG_SUCCESS) {
+                       MSG_ERR("FAIL TO INITIALIZE STORAGE HANDLER [%d]", err);
+               }
+
+               MsgInitNoti();
+
+               // plugin manager initialize
+               MsgPluginManager::instance()->initialize();
        }
        catch (MsgException& e)
        {
@@ -288,25 +164,44 @@ void* StartMsgServer(void*)
                MSG_FATAL("%s", e.what());
        }
 
-       if (g_main_loop_is_running(mainloop))
-               g_main_loop_quit(mainloop);
 
-       MsgCloseContactSvc();
+//     MsgSoundPlayer::instance()->MsgSoundInitRepeatAlarm();
+
+       MsgStoDisconnectDB();
+
+       MsgReleaseMemory();
+       MSG_DEBUG("End InitMsgServer.");
 
        return (void*)0;
 }
 
 
-void* InitMsgServer(void*)
-{
-       msg_error_t err = MSG_SUCCESS;
+//static gboolean InitThreadFunc(void* pData)
+//{
+//     MSG_BEGIN();
+//
+//     pthread_t initThreadId;
+//
+//     // initialize msg fw
+//     if (pthread_create(&initThreadId, NULL, InitMsgServer, NULL) != 0)
+//     {
+//             MSG_DEBUG("InitMsgFw not invoked: %s", strerror(errno));
+//             return -1;
+//     }
+//
+//     pthread_detach(initThreadId);
+//
+//     MSG_END();
+//
+//     return FALSE;
+//}
 
-       MsgOpenContactSvc();
 
+void* StartMsgServer(void*)
+{
        try
        {
-               // plugin manager initialize
-               MsgPluginManager::instance()->initialize();
+               MsgTransactionManager::instance()->run();
        }
        catch (MsgException& e)
        {
@@ -317,104 +212,13 @@ void* InitMsgServer(void*)
                MSG_FATAL("%s", e.what());
        }
 
-       MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
-       MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
-
-       // storage handler initialize
-       err = MsgStoInitDB(false);
-
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("FAIL TO INITIALIZE STORAGE HANDLER [%d]", err);
-       }
-
-       // Set Msg FW Ready Flag
-       if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true) != MSG_SUCCESS)
-               MSG_DEBUG("MsgSettingSetBool FAIL : VCONFKEY_MSG_SERVER_READY");
-       MSG_DEBUG("### VCONFKEY_MSG_SERVER_READY ###");
-
-       if (plg == NULL) {
-               MSG_DEBUG("No plugin for %d type", mainType);
-
-               MsgReleaseMemory();
-               return (void*)0;
-       }
-
-       // Clear and reset notification
-       MsgCleanAndResetNoti();
-
-       MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NORMAL;
-
-       // Check Sim Status
-       if (plg->checkSimStatus(&simStatus) == MSG_SUCCESS) {
-
-               // Add the change of SIM to vconf
-               if (MsgSettingSetInt(MSG_SIM_CHANGED, (int)simStatus) != MSG_SUCCESS) {
-                       MSG_DEBUG("Error to set config data [%s]", MSG_SIM_CHANGED);
-               }
-
-               if (simStatus != MSG_SIM_STATUS_NOT_FOUND) {
-                       // Check Device Status
-                       if (plg->checkDeviceStatus() != MSG_SUCCESS) {
-                               MSG_DEBUG("checkDeviceStatus() error");
-
-                               MsgReleaseMemory();
-
-                               return (void*)0;
-                       }
-               }
-
-               // Init SIM Message
-               if (MsgInitSimMessage(simStatus) != MSG_SUCCESS) {
-                       MSG_DEBUG("Fail to Initialize SIM Message");
-               }
-
-               // Init SIM Configuration
-               if (MsgInitSimConfig(simStatus) != MSG_SUCCESS) {
-                       MSG_DEBUG("Fail to Initialize SIM Configuration");
-               }
-
-               // Add SendMobileTrackerMsg() to GMainLoop
-               if (simStatus == MSG_SIM_STATUS_CHANGED) {
-                       MSG_DEBUG("Send Mobile Tracker Message");
-
-                       SendMobileTrackerMsg();
-               }
-       } else {
-               MSG_DEBUG("checkSimStatus() error");
-       }
-
-       MsgReleaseMemory();
-
-       // Register Callback to get the change of contact
-       MsgInitContactSvc(&MsgContactChangedCallback);
-
-       MsgSoundInitRepeatAlarm();
+       if (g_main_loop_is_running(mainloop))
+               g_main_loop_quit(mainloop);
 
        return (void*)0;
 }
 
 
-static gboolean InitThreadFunc(void* pData)
-{
-       MSG_BEGIN();
-
-       pthread_t initThreadId;
-
-       // initialize msg fw
-       if (pthread_create(&initThreadId, NULL, InitMsgServer, NULL) != 0)
-       {
-               MSG_DEBUG("InitMsgFw not invoked: %s", strerror(errno));
-               return -1;
-       }
-
-       pthread_detach(initThreadId);
-
-       MSG_END();
-
-       return FALSE;
-}
-
-
 int main(void)
 {
 #if !GLIB_CHECK_VERSION(2, 31, 0)
@@ -430,7 +234,7 @@ signal( SIGCHLD, SIG_IGN );
 ////////////////////////////////////
 
 
-       MSG_DEBUG("===========START MESSAGING FRAMEWORK==========");
+       MSG_INFO("===========START MESSAGING FRAMEWORK==========");
 
        // Reset message server ready flag
        if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, false) != MSG_SUCCESS)
@@ -439,14 +243,13 @@ signal( SIGCHLD, SIG_IGN );
        // Connect to DB
        //      MsgStoConnectDB();
 
-       // Open Contact Service
-       MsgOpenContactSvc();
-
        // Clean up mms dir
        InitMmsDir();
 
-       // Regist vconf CB.
-       MsgSettingRegVconfCB();
+       g_type_init();
+
+       // init server
+       InitMsgServer(NULL);
 
        pthread_t startThreadId;
 
@@ -457,15 +260,14 @@ signal( SIGCHLD, SIG_IGN );
                return -1;
        }
 
-       MsgTransactionManager::instance()->getTMStatus();
+       // Regist vconf CB.
+       MsgSettingRegVconfCB();
+
+//     MsgTransactionManager::instance()->getTMStatus();
 
        mainloop = g_main_loop_new(NULL, FALSE);
 
-#if !GLIB_CHECK_VERSION(2,35,0)
-       g_type_init ();
-#endif
-
-       g_idle_add(InitThreadFunc, NULL);
+//     g_idle_add(InitThreadFunc, NULL);
 
        if (mainloop != NULL)
        {
index bd0820f..5f30bbe 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgPluginConfig.h"
index b3d1fe0..02ac3fb 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -21,6 +21,7 @@
 #include "MsgUtilFile.h"
 #include "MsgException.h"
 #include "MsgIpcSocket.h"
+#include "MsgUtilFunction.h"
 #include "MsgCmdTypes.h"
 #include "MsgGconfWrapper.h"
 #include "MsgPluginManager.h"
@@ -38,7 +39,17 @@ void MsgSentStatusListener(MSG_SENT_STATUS_S *pSentStatus)
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
+
+
 
        // composing command
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SENT_STATUS_S); // cmd type, MSG_SENT_STATUS
@@ -81,7 +92,15 @@ void MsgStorageChangeListener(msg_storage_change_type_t storageChangeType, MSG_M
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
+       try
+       {
        client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
 
        // composing command
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(msg_storage_change_type_t);
@@ -123,7 +142,15 @@ msg_error_t MsgIncomingMessageListener(MSG_MESSAGE_INFO_S *pMsg)
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
 
        // Check Invalid Message Structure
        if (pMsg == NULL)
@@ -133,8 +160,13 @@ msg_error_t MsgIncomingMessageListener(MSG_MESSAGE_INFO_S *pMsg)
                return MSG_ERR_NULL_MESSAGE;
        }
 
+       // Allocate Memory to Command Data
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(pMsg, &encodedData);
+
        // composing command
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S); // cmd type, MSG_MESSAGE_INFO_S
+       int cmdSize = sizeof(MSG_CMD_S) + dataSize; // cmd type, MSG_MESSAGE_INFO_S
 
        MSG_DEBUG("cmdSize: %d", cmdSize);
 
@@ -148,7 +180,7 @@ msg_error_t MsgIncomingMessageListener(MSG_MESSAGE_INFO_S *pMsg)
 
        memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
 
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsg, sizeof(MSG_MESSAGE_INFO_S));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
 
        // Send Command to Messaging FW
        client.write(cmdBuf, cmdSize);
@@ -167,7 +199,8 @@ msg_error_t MsgIncomingMessageListener(MSG_MESSAGE_INFO_S *pMsg)
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
 
        if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_MSG_IND)
-               THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -181,7 +214,15 @@ msg_error_t MsgIncomingSyncMLMessageListener(MSG_SYNCML_MESSAGE_DATA_S *pSyncMLD
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
 
        // composing command
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SYNCML_MESSAGE_DATA_S); // cmd type, MSG_SYNCML_MESSAGE_DATA_S
@@ -216,7 +257,8 @@ msg_error_t MsgIncomingSyncMLMessageListener(MSG_SYNCML_MESSAGE_DATA_S *pSyncMLD
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
 
        if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND)
-               THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -229,7 +271,15 @@ msg_error_t MsgIncomingPushMessageListener(MSG_PUSH_MESSAGE_DATA_S *pPushData)
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
 
        // composing command
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_MESSAGE_DATA_S); // cmd type, MSG_SYNCML_MESSAGE_DATA_S
@@ -264,7 +314,8 @@ msg_error_t MsgIncomingPushMessageListener(MSG_PUSH_MESSAGE_DATA_S *pPushData)
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
 
        if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND)
-               THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -272,13 +323,21 @@ msg_error_t MsgIncomingPushMessageListener(MSG_PUSH_MESSAGE_DATA_S *pPushData)
 }
 
 
-msg_error_t MsgIncomingCBMessageListener(MSG_CB_MSG_S *pCbMsg)
+msg_error_t MsgIncomingCBMessageListener(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
 
        // Check Invalid Message Structure
        if (pCbMsg == NULL)
@@ -287,9 +346,18 @@ msg_error_t MsgIncomingCBMessageListener(MSG_CB_MSG_S *pCbMsg)
 
                return MSG_ERR_NULL_MESSAGE;
        }
+       int cmdSize = 0;
+
+       // Allocate Memory to Command Data
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(pMsgInfo, &encodedData);
 
        // composing command
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CB_MSG_S); // cmd type, MSG_CB_MSG_S
+       if(pCbMsg->type == MSG_ETWS_SMS)
+               cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CB_MSG_S); // cmd type, MSG_CB_MSG_S
+       else
+               cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CB_MSG_S) + dataSize; // cmd type, MSG_CB_MSG_S
 
        MSG_DEBUG("cmdSize: %d", cmdSize);
 
@@ -305,6 +373,9 @@ msg_error_t MsgIncomingCBMessageListener(MSG_CB_MSG_S *pCbMsg)
 
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pCbMsg, sizeof(MSG_CB_MSG_S));
 
+       if(pCbMsg->type != MSG_ETWS_SMS)
+               memcpy((void*)((char*)pCmd + sizeof(MSG_CMD_TYPE_T)+ MAX_COOKIE_LEN + sizeof(MSG_CB_MSG_S)), encodedData, dataSize);
+
        // Send Command to Messaging FW
        client.write(cmdBuf, cmdSize);
 
@@ -322,7 +393,8 @@ msg_error_t MsgIncomingCBMessageListener(MSG_CB_MSG_S *pCbMsg)
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
 
        if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_CB_MSG_IND)
-               THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -336,7 +408,15 @@ msg_error_t MsgIncomingLBSMessageListener(MSG_LBS_MESSAGE_DATA_S *pLBSData)
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
 
        // composing command
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_LBS_MESSAGE_DATA_S); // cmd type, MSG_LBS_MESSAGE_DATA_S
@@ -371,7 +451,8 @@ msg_error_t MsgIncomingLBSMessageListener(MSG_LBS_MESSAGE_DATA_S *pLBSData)
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
 
        if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_LBS_MSG_IND)
-               THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -385,7 +466,15 @@ msg_error_t MsgInitSimBySatListener()
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
 
        // composing command
        int cmdSize = sizeof(MSG_CMD_S);
@@ -414,7 +503,8 @@ msg_error_t MsgInitSimBySatListener()
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
 
        if (pEvent->eventType != MSG_EVENT_PLG_INIT_SIM_BY_SAT)
-               THROW(MsgException::INVALID_RESULT, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INVALID_RESULT, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -429,10 +519,23 @@ msg_error_t MsgMmsConfIncomingListener(MSG_MESSAGE_INFO_S *pMsg, msg_request_id_
 
        // establish connection to msgfw daemon
        MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
+
+       // Allocate Memory to Command Data
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(pMsg, &encodedData);
 
        // composing command
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(msg_request_id_t); // cmd type, MSG_MESSAGE_INFO_S, msg_request_id_t
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t) + dataSize; // cmd type, MSG_MESSAGE_INFO_S, msg_request_id_t
        MSG_DEBUG("cmdSize : %d", cmdSize);
 
        char cmdBuf[cmdSize];
@@ -446,8 +549,8 @@ msg_error_t MsgMmsConfIncomingListener(MSG_MESSAGE_INFO_S *pMsg, msg_request_id_
        memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN); // cmd cookie
 
        // cmd data
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsg, sizeof(MSG_MESSAGE_INFO_S));
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), pReqId, sizeof(msg_request_id_t));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pReqId, sizeof(msg_request_id_t));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_request_id_t)), encodedData, dataSize);
 
        // Send Command to Messaging FW
        client.write(cmdBuf, cmdSize);
@@ -461,12 +564,212 @@ msg_error_t MsgMmsConfIncomingListener(MSG_MESSAGE_INFO_S *pMsg, msg_request_id_
        // close connection to msgfw daemon
        client.close();
 
-       //Decoding the result from FW and Returning it to plugin
-       // the result is used for making delivery report
+       // Decoding the result from FW and Returning it to plugin
        MSG_EVENT_S *pEvent = (MSG_EVENT_S *)retBuf;
 
-       if(pEvent->eventType != MSG_EVENT_PLG_INCOMING_MMS_CONF && pEvent->eventType != MSG_EVENT_PLG_SENT_STATUS_CNF)
-               THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+       if(pEvent->eventType != MSG_EVENT_PLG_INCOMING_MMS_CONF)
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+
+       MSG_END();
+
+       return (pEvent->result);
+}
+
+
+msg_error_t MsgSimMessageListener(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, msg_message_id_t *retMsgId, int size)
+{
+       MSG_BEGIN();
+
+       // establish connection to msgfw daemon
+       MsgIpcClientSocket client;
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
+
+       // Check Invalid Message Structure
+       if (pMsg == NULL)
+       {
+               MSG_DEBUG("pMsg is NULL !!");
+
+               return MSG_ERR_NULL_MESSAGE;
+       }
+
+       // Allocate Memory to Command Data
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(pMsg, &encodedData);
+
+       char* encodedData2 = NULL;
+       AutoPtr<char> buf2(&encodedData2);
+       encodedData2 = (char*)new char[dataSize + sizeof(int) + (sizeof(int)*size) + 1];
+
+       char *offset = NULL;
+       memcpy(encodedData2, encodedData, dataSize);
+       offset = encodedData2+dataSize;
+
+       memcpy(offset, &size, sizeof(int));
+       offset += sizeof(int);
+       MSG_DEBUG("size [%d]", size);
+
+       memcpy(offset, simIdList, (sizeof(int)*size));
+
+       MSG_DEBUG("simIdList[0] [%d]", simIdList[0]);
+
+       dataSize += ((sizeof(int)*size) + 1);
+
+       // composing command
+       int cmdSize = sizeof(MSG_CMD_S) + dataSize; // cmd type, MSG_MESSAGE_INFO_S
+
+       MSG_DEBUG("cmdSize: %d", cmdSize);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+
+       MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_ADD_SIM_MSG;
+
+       memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
+
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData2, dataSize);
+
+       // Send Command to Messaging FW
+       client.write(cmdBuf, cmdSize);
+
+       char* retBuf = NULL;
+       AutoPtr<char> wrap(&retBuf);
+       unsigned int retSize;
+
+       client.read(&retBuf, &retSize);
+
+       // close connection to msgfw daemon
+       client.close();
+
+       // Decoding the result from FW and Returning it to plugin
+       // the result is used for making delivery report
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
+
+       if (pEvent->eventType != MSG_EVENT_ADD_SIM_MSG)
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+
+       //CID 48645: pEvent->data is an array hence null check is not required on it.
+       if (retMsgId) {
+               memcpy(retMsgId, pEvent->data, sizeof(msg_message_id_t));;
+               MSG_DEBUG("Saved SIM message ID = [%d]", *retMsgId);
+       }
+
+       MSG_END();
+
+       return (pEvent->result);
+}
+
+msg_error_t MsgResendMessageListener(void)
+{
+       // establish connection to msgfw daemon
+       MsgIpcClientSocket client;
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
+
+       // composing command
+       int cmdSize = sizeof(MSG_CMD_S);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+
+       MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_PLG_RESEND_MESSAGE;
+
+       // Send Command to Transaction Manager
+       client.write(cmdBuf, cmdSize);
+
+       // Receive result from Transaction Manager
+       char* retBuf = NULL;
+       AutoPtr<char> wrap(&retBuf);
+       unsigned int retSize;
+       client.read(&retBuf, &retSize);
+
+       // close connection to msgfw daemon
+       client.close();
+
+       // Decoding the result from FW and Returning it to plugin
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
+
+       if (pEvent->eventType != MSG_EVENT_PLG_RESEND_MESSAGE)
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INVALID_RESULT, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+
+       MSG_END();
+
+       return (pEvent->result);
+}
+
+
+msg_error_t MsgSimImsiListener(int sim_idx)
+{
+       MSG_BEGIN();
+
+       // establish connection to msgfw daemon
+       MsgIpcClientSocket client;
+       try
+       {
+               client.connect(MSG_SOCKET_PATH);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_UNKNOWN;
+       }
+
+       // composing command
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(int);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+
+       MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_UPDATE_IMSI;
+
+       memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (const void *)&sim_idx, sizeof(int));
+
+       // Send Command to Transaction Manager
+       client.write(cmdBuf, cmdSize);
+
+       // Receive result from Transaction Manager
+       char* retBuf = NULL;
+       AutoPtr<char> wrap(&retBuf);
+       unsigned int retSize;
+       client.read(&retBuf, &retSize);
+
+       // close connection to msgfw daemon
+       client.close();
+
+       // Decoding the result from FW and Returning it to plugin
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
+
+       if (pEvent->eventType != MSG_EVENT_UPDATE_IMSI)
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INVALID_RESULT, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
 
        MSG_END();
 
@@ -508,24 +811,26 @@ MsgPlugin::MsgPlugin(MSG_MAIN_TYPE_T mainType, const char *libPath): mSupportedM
        if ((*pFunc)(&mPlgHandler) != MSG_SUCCESS)
                THROW(MsgException::PLUGIN_ERROR, "ERROR to create plugin handle");
 
-       // Initialize Plug-in
-       if (initialize() != MSG_SUCCESS)
-               THROW(MsgException::PLUGIN_ERROR, "ERROR to initialize plugin");
-
        MSG_PLUGIN_LISTENER_S fwListener = {0};
-       fwListener.pfSentStatusCb                       = &MsgSentStatusListener;
-       fwListener.pfStorageChangeCb            = &MsgStorageChangeListener;
-       fwListener.pfMsgIncomingCb              = &MsgIncomingMessageListener;
-       fwListener.pfInitSimBySatCb                     = &MsgInitSimBySatListener;
+       fwListener.pfSentStatusCb                                       = &MsgSentStatusListener;
+       fwListener.pfStorageChangeCb                    = &MsgStorageChangeListener;
+       fwListener.pfMsgIncomingCb                              = &MsgIncomingMessageListener;
+       fwListener.pfInitSimBySatCb                             = &MsgInitSimBySatListener;
        fwListener.pfSyncMLMsgIncomingCb        = &MsgIncomingSyncMLMessageListener;
        fwListener.pfLBSMsgIncomingCb           = &MsgIncomingLBSMessageListener;
-       fwListener.pfMmsConfIncomingCb = &MsgMmsConfIncomingListener;
+       fwListener.pfMmsConfIncomingCb          = &MsgMmsConfIncomingListener;
        fwListener.pfPushMsgIncomingCb          = &MsgIncomingPushMessageListener;
-       fwListener.pfCBMsgIncomingCb            = &MsgIncomingCBMessageListener;
+       fwListener.pfCBMsgIncomingCb                    = &MsgIncomingCBMessageListener;
+       fwListener.pfSimMsgIncomingCb           = &MsgSimMessageListener;
+       fwListener.pfResendMessageCb            = &MsgResendMessageListener;
+       fwListener.pfSimInitImsiCb              = &MsgSimImsiListener;
 
        if (registerListener(&fwListener) != MSG_SUCCESS)
                THROW(MsgException::PLUGIN_ERROR, "ERROR to register listener");
 
+       // Initialize Plug-in
+       if (initialize() != MSG_SUCCESS)
+               THROW(MsgException::PLUGIN_ERROR, "ERROR to initialize plugin");
 }
 
 
@@ -572,33 +877,6 @@ msg_error_t MsgPlugin::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
 }
 
 
-msg_error_t MsgPlugin::checkSimStatus(MSG_SIM_STATUS_T *pStatus)
-{
-       if (mPlgHandler.pfRegisterListener != NULL)
-               return mPlgHandler.pfCheckSimStatus(pStatus);
-       else
-               return MSG_ERR_INVALID_PLUGIN_HANDLE;
-}
-
-
-msg_error_t MsgPlugin::checkDeviceStatus()
-{
-       if (mPlgHandler.pfRegisterListener != NULL)
-               return mPlgHandler.pfCheckDeviceStatus();
-       else
-               return MSG_ERR_INVALID_PLUGIN_HANDLE;
-}
-
-
-msg_error_t MsgPlugin::initSimMessage()
-{
-       if (mPlgHandler.pfInitSimMessage != NULL)
-               return mPlgHandler.pfInitSimMessage();
-       else
-               return MSG_ERR_INVALID_PLUGIN_HANDLE;
-}
-
-
 msg_error_t MsgPlugin::saveSimMessage(MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
 {
        if (mPlgHandler.pfSaveSimMessage != NULL)
@@ -608,37 +886,28 @@ msg_error_t MsgPlugin::saveSimMessage(MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_L
 }
 
 
-msg_error_t MsgPlugin::deleteSimMessage(msg_sim_id_t SimMsgId)
+msg_error_t MsgPlugin::deleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
 {
        if (mPlgHandler.pfDeleteSimMessage != NULL)
-               return mPlgHandler.pfDeleteSimMessage(SimMsgId);
+               return mPlgHandler.pfDeleteSimMessage(sim_idx, SimMsgId);
        else
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
 }
 
 
-msg_error_t MsgPlugin::setReadStatus(msg_sim_id_t SimMsgId)
+msg_error_t MsgPlugin::setReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
 {
        if (mPlgHandler.pfSetReadStatus != NULL)
-               return mPlgHandler.pfSetReadStatus(SimMsgId);
+               return mPlgHandler.pfSetReadStatus(sim_idx, SimMsgId);
        else
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
 }
 
 
-msg_error_t MsgPlugin::setMemoryStatus(msg_error_t Error)
+msg_error_t MsgPlugin::setMemoryStatus(msg_sim_slot_id_t sim_idx, msg_error_t Error)
 {
        if (mPlgHandler.pfSetMemoryStatus != NULL)
-               return mPlgHandler.pfSetMemoryStatus(Error);
-       else
-               return MSG_ERR_INVALID_PLUGIN_HANDLE;
-}
-
-
-msg_error_t MsgPlugin::initConfigData(MSG_SIM_STATUS_T SimStatus)
-{
-       if (mPlgHandler.pfInitConfigData != NULL)
-               return mPlgHandler.pfInitConfigData(SimStatus);
+               return mPlgHandler.pfSetMemoryStatus(sim_idx, Error);
        else
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
 }
@@ -690,10 +959,10 @@ msg_error_t MsgPlugin::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQU
 }
 
 
-msg_error_t MsgPlugin::getMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo,  MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg)
+msg_error_t MsgPlugin::getMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
 {
        if (mPlgHandler.pfGetMmsMessage != NULL) {
-               return mPlgHandler.pfGetMmsMessage(pMsg, pSendOptInfo, pMmsMsg, pDestMsg);
+               return mPlgHandler.pfGetMmsMessage(pMsg, pSendOptInfo, pDestMsg);
        } else {
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
        }
@@ -728,6 +997,14 @@ msg_error_t MsgPlugin::restoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char* pRecvBody,
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
 }
 
+msg_error_t MsgPlugin::getDefaultNetworkSimId(int *SimId)
+{
+       if (mPlgHandler.pfGetDefaultNetworkSimId != NULL)
+               return mPlgHandler.pfGetDefaultNetworkSimId(SimId);
+       else
+               return MSG_ERR_INVALID_PLUGIN_HANDLE;
+}
+
 
 /*==================================================================================================
                                      IMPLEMENTATION OF MsgPluginManager - Member Functions
@@ -795,21 +1072,34 @@ void MsgPluginManager::loadPlugins(const char* path)
                plgConf.token(i, 1, tok);
                const char* libPath = tok.getVal();
 
-               MsgPlugin* pDupPlgCheck = getPlugin(mainType);
+               MsgPlugin* pDupPlgCheck = checkPlugin(mainType);
 
-               if (pDupPlgCheck)
-                       THROW(MsgException::PLUGIN_ERROR, "Plugin for type %d is duplicated", mainType);
+               if (pDupPlgCheck) {
+                       MSG_DEBUG("Plugin for type %d is duplicated", mainType);
+                       continue;
+               }
 
-               MsgPlugin *newPlg = new MsgPlugin(mainType, libPath);
+               MsgPlugin *newPlg = NULL;
 
-               plgMap.insert(make_pair(mainType, newPlg));
+               try
+               {
+                       newPlg = new MsgPlugin(mainType, libPath);
+               }
+               catch (MsgException& e)
+               {
+                       MSG_FATAL("%s", e.what());
+                       continue;
+               }
+
+               if (newPlg)
+                       plgMap.insert(make_pair(mainType, newPlg));
        }
 
        MsgCloseFile(fp);
 }
 
 
-MsgPlugin* MsgPluginManager::getPlugin(MSG_MAIN_TYPE_T mainType)
+MsgPlugin* MsgPluginManager::checkPlugin(MSG_MAIN_TYPE_T mainType)
 {
        /* Implementing the content */
        MsgPluginMap::iterator it = plgMap.find(mainType);
@@ -820,3 +1110,18 @@ MsgPlugin* MsgPluginManager::getPlugin(MSG_MAIN_TYPE_T mainType)
        return it->second;
 }
 
+
+MsgPlugin* MsgPluginManager::getPlugin(MSG_MAIN_TYPE_T mainType)
+{
+       MsgPlugin *plugin = NULL;
+
+       if (plgMap.size() == 0) {
+               MSG_INFO("Msg plugin is initializing again");
+               initialize();
+       }
+
+       plugin = checkPlugin(mainType);
+
+       return plugin;
+}
+
index 88cf11c..a6d590d 100755 (executable)
@@ -1,23 +1,26 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
 #include "MsgPluginManager.h"
 #include "MsgSettingHandler.h"
 #include "MsgGconfWrapper.h"
+#include "MsgUtilFunction.h"
+#include "MsgSqliteWrapper.h"
+#include "MsgUtilStorage.h"
 
 
 #define DEF_BUF_LEN    128
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
-msg_error_t MsgInitSimConfig(MSG_SIM_STATUS_T SimStatus)
-{
-       MSG_DEBUG("Start to initialize SIM Configuration");
-
-       msg_error_t err = MSG_SUCCESS;
-
-       if (SimStatus != MSG_SIM_STATUS_NOT_FOUND)
-       {
-               MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
-               MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
-
-               if (plg == NULL)
-               {
-                       MSG_DEBUG("No plugin for %d type", mainType);
-                       return MSG_ERR_INVALID_PLUGIN_HANDLE;
-               }
-
-               // Check SIM Status
-               MSG_DEBUG(" ** SIM is available - status : [%d] ** ", SimStatus);
-
-               err = plg->initConfigData(SimStatus);
-       }
-
-       return err;
-}
-
-
 msg_error_t MsgSetConfigData(const MSG_SETTING_S *pSetting)
 {
        msg_error_t err = MSG_SUCCESS;
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NOT_FOUND;
 
 #ifdef USE_GCONF
        err = MsgGconfGetClient();
@@ -81,6 +60,14 @@ msg_error_t MsgSetConfigData(const MSG_SETTING_S *pSetting)
                        err = MsgSetSMSSendOpt(pSetting);
                        break;
                case MSG_SMSC_LIST :
+                       // Check SIM is present or not
+                       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pSetting->option.smscList.simIndex);
+                       simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
+                       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
+                               MSG_DEBUG("SIM is not present..");
+                               return MSG_ERR_NO_SIM;
+                       }
                        err = MsgSetSMSCList(pSetting, true);
                        break;
                case MSG_MMS_SENDOPT :
@@ -96,9 +83,28 @@ msg_error_t MsgSetConfigData(const MSG_SETTING_S *pSetting)
                        err = MsgSetPushMsgOpt(pSetting);
                        break;
                case MSG_CBMSG_OPT :
+                       if(pSetting->option.cbMsgOpt.simIndex != 0)
+                       {
+                               // Check SIM is present or not
+                               sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pSetting->option.cbMsgOpt.simIndex);
+                               simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
+                               if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
+                                       MSG_DEBUG("SIM is not present..");
+                                       return MSG_ERR_NO_SIM;
+                               }
+                       }
                        err = MsgSetCBMsgOpt(pSetting, true);
                        break;
                case MSG_VOICEMAIL_OPT :
+                       // Check SIM is present or not
+                       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pSetting->option.voiceMailOpt.simIndex);
+                       simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
+                       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
+                               MSG_DEBUG("SIM is not present..");
+                               return MSG_ERR_NO_SIM;
+                       }
                        err = MsgSetVoiceMailOpt(pSetting, true);
                        break;
                case MSG_MSGSIZE_OPT:
@@ -127,9 +133,8 @@ msg_error_t MsgGetConfigData(MSG_SETTING_S *pSetting)
                return MSG_ERR_NULL_POINTER;
        }
 #endif
-
-       // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+       MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NOT_FOUND;
 
        switch (pSetting->type)
        {
@@ -141,6 +146,10 @@ msg_error_t MsgGetConfigData(MSG_SETTING_S *pSetting)
                        break;
                case MSG_SMSC_LIST :
                {
+                       // Check SIM is present or not
+                       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pSetting->option.smscList.simIndex);
+                       simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
                        if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                                MSG_DEBUG("SIM is not present..");
                                return MSG_ERR_NO_SIM;
@@ -162,6 +171,10 @@ msg_error_t MsgGetConfigData(MSG_SETTING_S *pSetting)
                        break;
                case MSG_CBMSG_OPT :
                {
+                       // Check SIM is present or not
+                       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pSetting->option.cbMsgOpt.simIndex);
+                       simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
                        if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                                MSG_DEBUG("SIM is not present..");
                                return MSG_ERR_NO_SIM;
@@ -170,6 +183,19 @@ msg_error_t MsgGetConfigData(MSG_SETTING_S *pSetting)
                }
                break;
                case MSG_VOICEMAIL_OPT :
+                       // Check SIM is present or not
+                       if (pSetting->option.voiceMailOpt.simIndex == 0) {
+                               MSG_DEBUG("Invalid SIM Index [%d]", pSetting->option.voiceMailOpt.simIndex);
+                               return MSG_ERR_INVALID_PARAMETER;
+                       }
+
+                       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pSetting->option.voiceMailOpt.simIndex);
+                       simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
+                       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
+                               MSG_DEBUG("SIM is not present..");
+                               return MSG_ERR_NO_SIM;
+                       }
                        MsgGetVoiceMailOpt(pSetting);
                        break;
                case MSG_MSGSIZE_OPT :
@@ -192,6 +218,8 @@ msg_error_t MsgSetGeneralOpt(const MSG_SETTING_S *pSetting)
 {
        MSG_GENERAL_OPT_S generalOpt;
        bool bValue = false;
+       int iValue = 0;
+       char *strValue = NULL;
 
        memcpy(&generalOpt, &(pSetting->option.generalOpt), sizeof(MSG_GENERAL_OPT_S));
 
@@ -211,15 +239,99 @@ msg_error_t MsgSetGeneralOpt(const MSG_SETTING_S *pSetting)
                }
        }
 
-#ifdef __NOT_USED_BY_DESIGN_CHANGE__
-       iValue = MsgSettingGetInt(MSG_ALERT_TONE);
+       MsgSettingGetBool(MSG_BLOCK_UNKNOWN_MSG, &bValue);
+       if (bValue != generalOpt.bBlockUnknownMsg) {
+               if (MsgSettingSetBool(MSG_BLOCK_UNKNOWN_MSG, generalOpt.bBlockUnknownMsg) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_BLOCK_UNKNOWN_MSG);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       iValue = MsgSettingGetInt(MSG_SMS_LIMIT);
+       if (iValue != (int)generalOpt.smsLimitCnt) {
+               if (MsgSettingSetInt(MSG_SMS_LIMIT, (int)generalOpt.smsLimitCnt) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SMS_LIMIT);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       iValue = MsgSettingGetInt(MSG_MMS_LIMIT);
+       if (iValue != (int)generalOpt.mmsLimitCnt) {
+               if (MsgSettingSetInt(MSG_MMS_LIMIT, (int)generalOpt.mmsLimitCnt) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_MMS_LIMIT);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bValue);
+       if (bValue != generalOpt.bNotification) {
+               if (MsgSettingSetBool(MSG_SETTING_NOTIFICATION, generalOpt.bNotification) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SETTING_NOTIFICATION);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       MsgSettingGetBool(MSG_SETTING_VIBRATION, &bValue);
+       if (bValue != generalOpt.bVibration) {
+               if (MsgSettingSetBool(MSG_SETTING_VIBRATION, generalOpt.bVibration) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SETTING_VIBRATION);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       MsgSettingGetBool(MSG_SETTING_PREVIEW, &bValue);
+       if (bValue != generalOpt.bPreview) {
+               if (MsgSettingSetBool(MSG_SETTING_PREVIEW, generalOpt.bPreview) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SETTING_PREVIEW);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       iValue = MsgSettingGetInt(MSG_SETTING_RINGTONE_TYPE);
+       if (iValue != generalOpt.ringtoneType) {
+               if (MsgSettingSetInt(MSG_SETTING_RINGTONE_TYPE, generalOpt.ringtoneType) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SETTING_RINGTONE_TYPE);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       if (generalOpt.ringtoneType == MSG_RINGTONE_TYPE_SILENT) {
+               if (MsgSettingSetString(MSG_SETTING_RINGTONE_PATH, "") != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SETTING_RINGTONE_PATH);
+                       return MSG_ERR_SET_SETTING;
+               }
+       } else {
+               strValue = MsgSettingGetString(MSG_SETTING_RINGTONE_PATH);
+               MSG_DEBUG("strValue=[%s], ringtone=[%s]", strValue, generalOpt.ringtonePath);
+
+               if (g_strcmp0(strValue, generalOpt.ringtonePath) != 0) {
+                       if (MsgSettingSetString(MSG_SETTING_RINGTONE_PATH, generalOpt.ringtonePath) != MSG_SUCCESS) {
+                               MSG_DEBUG("Error to set config data [%s]", MSG_SETTING_RINGTONE_PATH);
+                               return MSG_ERR_SET_SETTING;
+                       }
+               }
+       }
+
+       if (strValue) {
+               free(strValue);
+               strValue = NULL;
+       }
+
+       iValue = MsgSettingGetInt(MSG_ALERT_REP_TYPE);
        if (iValue != (int)generalOpt.alertTone) {
-               if (MsgSettingSetInt(MSG_ALERT_TONE, (int)generalOpt.alertTone) != MSG_SUCCESS) {
-                       MSG_DEBUG("Error to set config data [%s]", MSG_ALERT_TONE);
+               if (MsgSettingSetInt(MSG_ALERT_REP_TYPE, (int)generalOpt.alertTone) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_ALERT_REP_TYPE);
+                       return MSG_ERR_SET_SETTING;
+               }
+       }
+
+       iValue = MsgSettingGetInt(MSG_SEARCH_TAGS);
+       if (iValue != (int)generalOpt.searchTags) {
+               if (MsgSettingSetInt(MSG_SEARCH_TAGS, (int)generalOpt.searchTags) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", MSG_SEARCH_TAGS);
                        return MSG_ERR_SET_SETTING;
                }
        }
-#endif /* __NOT_USED_BY_DESIGN_CHANGE__ */
 
        return MSG_SUCCESS;
 }
@@ -281,96 +393,46 @@ msg_error_t MsgSetSMSCList(const MSG_SETTING_S *pSetting, bool bSetSim)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       for (int index = 0; index < pSetting->option.smscList.totalCnt; index++)
-       {
-               if(strlen(pSetting->option.smscList.smscData[index].smscAddr.address) > SMSC_ADDR_MAX)
-               {
-                       MSG_DEBUG("SMSC address is too long [%d]", strlen(pSetting->option.smscList.smscData[index].smscAddr.address));
-                       return MSG_ERR_SET_SIM_SET;
-               }
-       }
-
-       if (bSetSim == true)
-       {
-               err = MsgSetConfigInSim(pSetting);
-
-               if (err != MSG_SUCCESS)
-               {
-                       MSG_DEBUG("Error to set config data in sim [%d]", err);
-                       return err;
-               }
-       }
-
-       MSG_SMSC_LIST_S smscList;
+       int addrLen = 0;
+       int index = 0;
 
+       MSG_SMSC_LIST_S smscList = {0,};
        memcpy(&smscList, &(pSetting->option.smscList), sizeof(MSG_SMSC_LIST_S));
 
-       char keyName[DEF_BUF_LEN] = {0, };
+//     int sel_id = smscList.selected;
 
-       // No selected SMSC Info. in SIM.
-       if (bSetSim == true)
-       {
-               if (MsgSettingSetInt(SMSC_SELECTED, smscList.selected) != MSG_SUCCESS)
-               {
-                       MSG_DEBUG("Error to set config data [%s]", SMSC_SELECTED);
-                       return MSG_ERR_SET_SETTING;
-               }
-       }
+       index = smscList.index;
 
-       if (MsgSettingSetInt(SMSC_TOTAL_COUNT, smscList.totalCnt) != MSG_SUCCESS)
-       {
-               MSG_DEBUG("Error to set config data [%s]", SMSC_TOTAL_COUNT);
-               return MSG_ERR_SET_SETTING;
+       if (index < 0 || index >= smscList.totalCnt) {
+               MSG_DEBUG("Update SMSC index is invalid [id=%d]", index);
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
-       for (int i = 0; i < smscList.totalCnt; i++)
-       {
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_PID, i);
-
-               if ((err = MsgSettingSetInt(keyName, (int)smscList.smscData[i].pid)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_VAL_PERIOD, i);
-
-               if ((err = MsgSettingSetInt(keyName, (int)smscList.smscData[i].valPeriod)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_NAME, i);
-
-               if ((err = MsgSettingSetString(keyName, smscList.smscData[i].name)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_TON, i);
-
-               if (smscList.smscData[i].smscAddr.address[0] == '+')
-                       smscList.smscData[i].smscAddr.ton = MSG_TON_INTERNATIONAL;
-               else
-                       smscList.smscData[i].smscAddr.ton = MSG_TON_NATIONAL;
-
-               if ((err = MsgSettingSetInt(keyName, (int)smscList.smscData[i].smscAddr.ton)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_NPI, i);
-
-               smscList.smscData[i].smscAddr.npi = MSG_NPI_ISDN; // app cannot set this value
-
-               if ((err = MsgSettingSetInt(keyName, (int)smscList.smscData[i].smscAddr.npi)) != MSG_SUCCESS)
-                       break;
+       if (pSetting->option.smscList.smscData[index].smscAddr.address[0] == '+')
+               addrLen = strlen(pSetting->option.smscList.smscData[index].smscAddr.address) - 1;
+       else
+               addrLen = strlen(pSetting->option.smscList.smscData[index].smscAddr.address);
 
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_ADDRESS, i);
+       if(addrLen > SMSC_ADDR_MAX) {
+               MSG_DEBUG("SMSC address is too long [%d]", strlen(pSetting->option.smscList.smscData[index].smscAddr.address));
+               return MSG_ERR_SET_SIM_SET;
+       } else if(addrLen < 2) {
+               MSG_DEBUG("SMSC address is too short [%d]", addrLen);
+               return MSG_ERR_SET_SIM_SET;
+       }
 
-               if ((err = MsgSettingSetString(keyName, smscList.smscData[i].smscAddr.address)) != MSG_SUCCESS)
-                       break;
+       if (pSetting->option.smscList.simIndex == 0) {
+               MSG_DEBUG("SIM Index for Setting SMSC List = 0");
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
-       if (err != MSG_SUCCESS)
-       {
-               MSG_DEBUG("Error to set config data [%s]", keyName);
+       if (bSetSim == true) {
+               err = MsgSetConfigInSim(pSetting);
+
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data in sim [%d]", err);
+                       return err;
+               }
        }
 
        return err;
@@ -735,17 +797,26 @@ msg_error_t MsgSetCBMsgOpt(const MSG_SETTING_S *pSetting, bool bSetSim)
        MSG_CBMSG_OPT_S cbOpt;
        int iValue = 0;
        bool bValue = false;
+       char keyName[DEF_BUF_LEN];
+       msg_sim_slot_id_t simIndex;
 
        memcpy(&cbOpt, &(pSetting->option.cbMsgOpt), sizeof(MSG_CBMSG_OPT_S));
 
-       if (bSetSim == true) {
-               cbOpt.maxSimCnt = MsgSettingGetInt(CB_MAX_SIM_COUNT);
+       simIndex = cbOpt.simIndex;
 
-               if (cbOpt.channelData.channelCnt > cbOpt.maxSimCnt) {
-                       MSG_DEBUG("Channel Count is over Max SIM Count [%d]", cbOpt.channelData.channelCnt);
-                       return MSG_ERR_SET_SIM_SET;
-               }
+       MSG_DEBUG("SIM Index = [%d]", simIndex);
 
+       if (bSetSim == true ) {//if (bSetSim == true && simIndex != 0) {
+               if(simIndex != 0) {
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
+                       cbOpt.maxSimCnt = MsgSettingGetInt(keyName);
+
+                       if (cbOpt.channelData.channelCnt > cbOpt.maxSimCnt) {
+                               MSG_DEBUG("Channel Count is over Max SIM Count [%d]", cbOpt.channelData.channelCnt);
+                               return MSG_ERR_SET_SIM_SET;
+                       }
+               }
                err = MsgSetConfigInSim(pSetting);
                if (err != MSG_SUCCESS) {
                        MSG_DEBUG("Error to set config data in sim [%d]", err);
@@ -753,6 +824,8 @@ msg_error_t MsgSetCBMsgOpt(const MSG_SETTING_S *pSetting, bool bSetSim)
                }
        }
 
+//     memset(keyName, 0x00, sizeof(keyName));
+//     snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
        MsgSettingGetBool(CB_RECEIVE, &bValue);
        if (bValue != cbOpt.bReceive) {
                if (MsgSettingSetBool(CB_RECEIVE, cbOpt.bReceive) != MSG_SUCCESS) {
@@ -761,49 +834,25 @@ msg_error_t MsgSetCBMsgOpt(const MSG_SETTING_S *pSetting, bool bSetSim)
                }
        }
 
-       iValue = MsgSettingGetInt(CB_MAX_SIM_COUNT);
-       if (iValue != cbOpt.maxSimCnt) {
-               if (MsgSettingSetInt(CB_MAX_SIM_COUNT, cbOpt.maxSimCnt) != MSG_SUCCESS) {
-                       MSG_DEBUG("Error to set config data [%s]", CB_MAX_SIM_COUNT);
-                       return MSG_ERR_SET_SETTING;
-               }
+       if (simIndex == 0) {
+               MSG_DEBUG("SIM Index for Setting CB Option = 0, Setting for CB_RECEIVE success");
+               return MSG_SUCCESS;
        }
 
-       iValue = MsgSettingGetInt(CB_CHANNEL_COUNT);
-       if (iValue != cbOpt.channelData.channelCnt) {
-               if (MsgSettingSetInt(CB_CHANNEL_COUNT, cbOpt.channelData.channelCnt) != MSG_SUCCESS) {
-                       MSG_DEBUG("Error to set config data [%s]", CB_CHANNEL_COUNT);
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
+       iValue = MsgSettingGetInt(keyName);
+       if (iValue != cbOpt.maxSimCnt) {
+               if (MsgSettingSetInt(CB_MAX_SIM_COUNT, cbOpt.maxSimCnt) != MSG_SUCCESS) {
+                       MSG_DEBUG("Error to set config data [%s]", keyName);
                        return MSG_ERR_SET_SETTING;
                }
        }
 
-       char keyName[DEF_BUF_LEN] = {0, };
+       MsgDbHandler *dbHandle = getDbHandle();;
 
-       for (int i = 0; i < cbOpt.channelData.channelCnt; i++)
-       {
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_ACTIVATE, i);
-
-               if ((err = MsgSettingSetBool(keyName, cbOpt.channelData.channelInfo[i].bActivate)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_ID_FROM, i);
-
-               if ((err = MsgSettingSetInt(keyName, cbOpt.channelData.channelInfo[i].from)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_ID_TO, i);
-
-               if ((err = MsgSettingSetInt(keyName, cbOpt.channelData.channelInfo[i].to)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_NAME, i);
-
-               if ((err = MsgSettingSetString(keyName, cbOpt.channelData.channelInfo[i].name)) != MSG_SUCCESS)
-                       break;
-       }
+       err = MsgStoAddCBChannelInfo(dbHandle, &cbOpt.channelData, simIndex);
+       MSG_DEBUG("MsgStoAddCBChannelInfo : err=[%d]", err);
 
        if (bSetSim == true)
        {
@@ -828,31 +877,43 @@ msg_error_t MsgSetVoiceMailOpt(const MSG_SETTING_S *pSetting, bool bSetSim)
 {
        MSG_VOICEMAIL_OPT_S voiceMailOpt;
        char *pValue = NULL;
+       char keyName[DEF_BUF_LEN];
+       msg_sim_slot_id_t simIndex = 0;
        msg_error_t err = MSG_SUCCESS;
 
        memcpy(&voiceMailOpt, &(pSetting->option.voiceMailOpt), sizeof(MSG_VOICEMAIL_OPT_S));
 
-       pValue = MsgSettingGetString(VOICEMAIL_NUMBER);
+       simIndex = pSetting->option.voiceMailOpt.simIndex;
+
+       if (simIndex == 0) {
+               MSG_DEBUG("SIM Index for Setting Voicemail Option = 0");
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
+
+       pValue = MsgSettingGetString(keyName);
+
        if (pValue != NULL && strcmp(pValue, voiceMailOpt.mailNumber) == 0) {
                /* Value is same with previous one. Therefore, we don't need to save it. */
        } else {
                if (bSetSim == true) {
                        err = MsgSetConfigInSim(pSetting);
+                       /* Even if err is not Success, no need to return error. */
+                       MSG_DEBUG("MsgSetConfigInSim return [%d]", err);
+               }
 
-                       if (err == MSG_SUCCESS) {
-                               err = MsgSettingSetString(VOICEMAIL_NUMBER, voiceMailOpt.mailNumber);
-                               if (err != MSG_SUCCESS)
-                                       MSG_DEBUG("Error to set config data [%s]", VOICEMAIL_NUMBER);
-                       } else {
-                               MSG_DEBUG("Error to set config data in sim [%d]", err);
-                       }
-               } else {
-                       err = MsgSettingSetString(VOICEMAIL_NUMBER, voiceMailOpt.mailNumber);
-                       if (err != MSG_SUCCESS)
-                               MSG_DEBUG("Error to set config data [%s]", VOICEMAIL_NUMBER);
+               if (err != MSG_SUCCESS) {
+                       goto _END_OF_SET_VOICE_OPT;
                }
+
+               err = MsgSettingSetString(keyName, voiceMailOpt.mailNumber);
+               if (err != MSG_SUCCESS)
+                       MSG_DEBUG("Error to set config data [%s]", keyName);
        }
 
+_END_OF_SET_VOICE_OPT:
        if (pValue != NULL) {
                free(pValue);
                pValue = NULL;
@@ -883,15 +944,39 @@ msg_error_t MsgSetMsgSizeOpt(const MSG_SETTING_S *pSetting)
 
 void MsgGetGeneralOpt(MSG_SETTING_S *pSetting)
 {
+       char *tmpValue = NULL;
+
        memset(&(pSetting->option.generalOpt), 0x00, sizeof(MSG_GENERAL_OPT_S));
 
        MsgSettingGetBool(MSG_KEEP_COPY, &pSetting->option.generalOpt.bKeepCopy);
 
-#ifdef __NOT_USED_BY_DESIGN_CHANGE__
-       pSetting->option.generalOpt.alertTone = (MSG_ALERT_TONE_T)MsgSettingGetInt(MSG_ALERT_TONE);
+       MsgSettingGetBool(MSG_BLOCK_UNKNOWN_MSG, &pSetting->option.generalOpt.bBlockUnknownMsg);
+
+       pSetting->option.generalOpt.smsLimitCnt = MsgSettingGetInt(MSG_SMS_LIMIT);
+
+       pSetting->option.generalOpt.mmsLimitCnt = MsgSettingGetInt(MSG_MMS_LIMIT);
+
+       MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &pSetting->option.generalOpt.bNotification);
+
+       MsgSettingGetBool(MSG_SETTING_VIBRATION, &pSetting->option.generalOpt.bVibration);
+
+       MsgSettingGetBool(MSG_SETTING_PREVIEW, &pSetting->option.generalOpt.bPreview);
 
        MsgSettingGetBool(MSG_AUTO_ERASE, &pSetting->option.generalOpt.bAutoErase);
-#endif /* __NOT_USED_BY_DESIGN_CHANGE__ */
+
+       pSetting->option.generalOpt.ringtoneType = MsgSettingGetInt(MSG_SETTING_RINGTONE_TYPE);
+
+       tmpValue = MsgSettingGetString(MSG_SETTING_RINGTONE_PATH);
+       if (tmpValue != NULL) {
+               strncpy(pSetting->option.generalOpt.ringtonePath, tmpValue, MSG_FILEPATH_LEN_MAX);
+               free(tmpValue);
+               tmpValue = NULL;
+       }
+
+       pSetting->option.generalOpt.alertTone = (MSG_ALERT_TONE_T)MsgSettingGetInt(MSG_ALERT_REP_TYPE);
+
+       pSetting->option.generalOpt.searchTags = MsgSettingGetInt(MSG_SEARCH_TAGS);
+
 }
 
 
@@ -913,68 +998,11 @@ void MsgGetSMSSendOpt(MSG_SETTING_S *pSetting)
 
 void MsgGetSMSCList(MSG_SETTING_S *pSetting)
 {
-       char keyName[DEF_BUF_LEN] = {0, };
-       char *tmpValue = NULL;
+       MSG_BEGIN();
 
-       memset(&(pSetting->option.smscList), 0x00, sizeof(MSG_SMSC_LIST_S));
+       MsgGetConfigInSim(pSetting);
 
-       pSetting->option.smscList.selected = MsgSettingGetInt(SMSC_SELECTED);
-
-       pSetting->option.smscList.totalCnt = MsgSettingGetInt(SMSC_TOTAL_COUNT);
-
-       for (int i = 0; i < pSetting->option.smscList.totalCnt; i++)
-       {
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_PID, i);
-
-               pSetting->option.smscList.smscData[i].pid = (MSG_SMS_PID_T)MsgSettingGetInt(keyName);
-
-#ifdef __NOT_USED_BY_DESIGN_CHANGE__
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_DCS, i);
-
-               pSetting->option.smscList.smscData[i].dcs = (msg_encode_type_t)MsgSettingGetInt(keyName);
-#endif /* __NOT_USED_BY_DESIGN_CHANGE__ */
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_VAL_PERIOD, i);
-
-               pSetting->option.smscList.smscData[i].valPeriod = (MSG_VAL_PERIOD_T)MsgSettingGetInt(keyName);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_NAME, i);
-
-               memset(pSetting->option.smscList.smscData[i].name, 0x00, SMSC_NAME_MAX+1);
-
-               tmpValue = MsgSettingGetString(keyName);
-               if (tmpValue != NULL) {
-                       strncpy(pSetting->option.smscList.smscData[i].name, tmpValue, SMSC_NAME_MAX);
-                       free(tmpValue);
-                       tmpValue = NULL;
-               }
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_TON, i);
-
-               pSetting->option.smscList.smscData[i].smscAddr.ton = (MSG_SMS_TON_T)MsgSettingGetInt(keyName);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_NPI, i);
-
-               pSetting->option.smscList.smscData[i].smscAddr.npi = (MSG_SMS_NPI_T)MsgSettingGetInt(keyName);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", SMSC_ADDRESS, i);
-
-               memset(pSetting->option.smscList.smscData[i].smscAddr.address, 0x00, sizeof(pSetting->option.smscList.smscData[i].smscAddr.address));
-
-               tmpValue = MsgSettingGetString(keyName);
-               if (tmpValue != NULL) {
-                       strncpy(pSetting->option.smscList.smscData[i].smscAddr.address, tmpValue, SMSC_ADDR_MAX);
-                       free(tmpValue);
-                       tmpValue = NULL;
-               }
-       }
+       MSG_END();
 }
 
 
@@ -1082,45 +1110,35 @@ void MsgGetPushMsgOpt(MSG_SETTING_S *pSetting)
 
 void MsgGetCBMsgOpt(MSG_SETTING_S *pSetting)
 {
+       msg_error_t err = MSG_SUCCESS;
+
        char keyName[DEF_BUF_LEN] = {0, };
-       char *tmpValue = NULL;
+       MsgDbHandler *dbHandle = getDbHandle();
+       msg_sim_slot_id_t simIndex = pSetting->option.cbMsgOpt.simIndex;
 
        memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
 
-       MsgSettingGetBool(CB_RECEIVE, &pSetting->option.cbMsgOpt.bReceive);
-
-       pSetting->option.cbMsgOpt.maxSimCnt = MsgSettingGetInt(CB_MAX_SIM_COUNT);
+       MSG_DEBUG("Sim index = [%d]", simIndex);
 
-       pSetting->option.cbMsgOpt.channelData.channelCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
+       /* Keep simIndex */
+       pSetting->option.cbMsgOpt.simIndex = simIndex;
 
-       for (int i = 0; i < pSetting->option.cbMsgOpt.channelData.channelCnt; i++)
-       {
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_ACTIVATE, i);
-
-               MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.channelData.channelInfo[i].bActivate);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_ID_FROM, i);
-               pSetting->option.cbMsgOpt.channelData.channelInfo[i].from = MsgSettingGetInt(keyName);
-               MSG_DEBUG("channel[%d]: from: %d", i, pSetting->option.cbMsgOpt.channelData.channelInfo[i].from);
+//     memset(keyName, 0x00, sizeof(keyName));
+//     snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
+       MsgSettingGetBool(CB_RECEIVE, &pSetting->option.cbMsgOpt.bReceive);
 
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_ID_TO, i);
-               pSetting->option.cbMsgOpt.channelData.channelInfo[i].to = MsgSettingGetInt(keyName);
-               MSG_DEBUG("channel[%d]: to: %d", i, pSetting->option.cbMsgOpt.channelData.channelInfo[i].to);
+       if (simIndex == 0) {
+               MSG_DEBUG("SIM Index = 0, bReceive is gotten");
+               return;
+       }
 
-               memset(keyName, 0x00, sizeof(keyName));
-               snprintf(keyName, DEF_BUF_LEN, "%s/%d", CB_CHANNEL_NAME, i);
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
+       pSetting->option.cbMsgOpt.maxSimCnt = MsgSettingGetInt(keyName);
 
-               tmpValue = MsgSettingGetString(keyName);
-               if (tmpValue != NULL) {
-                       strncpy(pSetting->option.cbMsgOpt.channelData.channelInfo[i].name, tmpValue, CB_CHANNEL_NAME_MAX);
-                       MSG_DEBUG("channel[%d]: channel_name: %s", i, pSetting->option.cbMsgOpt.channelData.channelInfo[i].name);
-                       free(tmpValue);
-                       tmpValue = NULL;
-               }
-       }
+       err = MsgStoGetCBChannelInfo(dbHandle, &pSetting->option.cbMsgOpt.channelData, simIndex);
+       if (err != MSG_SUCCESS)
+               MSG_ERR("MsgStoGetCBChannelInfo : err=[%d]", err);
 
        for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++)
        {
@@ -1131,15 +1149,34 @@ void MsgGetCBMsgOpt(MSG_SETTING_S *pSetting)
        }
 }
 
+
 void MsgGetVoiceMailOpt(MSG_SETTING_S *pSetting)
 {
        char *tmpValue = NULL;
+       char keyName[DEF_BUF_LEN];
+       msg_sim_slot_id_t simIndex;
 
-       memset(&(pSetting->option.voiceMailOpt), 0x00, sizeof(MSG_VOICEMAIL_OPT_S));
+       simIndex = pSetting->option.voiceMailOpt.simIndex;
+       MSG_DEBUG("sim index = [%d]", simIndex);
 
-       tmpValue = MsgSettingGetString(VOICEMAIL_NUMBER);
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
+       tmpValue = MsgSettingGetString(keyName);
+       memset(pSetting->option.voiceMailOpt.mailNumber, 0x00, sizeof(pSetting->option.voiceMailOpt.mailNumber));
        if (tmpValue != NULL) {
                strncpy(pSetting->option.voiceMailOpt.mailNumber, tmpValue, MAX_PHONE_NUMBER_LEN);
+               MSG_DEBUG("Voicemail number = [%s]", pSetting->option.voiceMailOpt.mailNumber);
+               free(tmpValue);
+               tmpValue = NULL;
+       }
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, simIndex);
+       tmpValue = MsgSettingGetString(keyName);
+       memset(pSetting->option.voiceMailOpt.alpahId, 0x00, sizeof(pSetting->option.voiceMailOpt.alpahId));
+       if (tmpValue != NULL) {
+               strncpy(pSetting->option.voiceMailOpt.alpahId, tmpValue, MAX_SIM_XDN_ALPHA_ID_LEN);
+               MSG_DEBUG("Voicemail alpha ID = [%s]", pSetting->option.voiceMailOpt.alpahId);
                free(tmpValue);
                tmpValue = NULL;
        }
@@ -1175,253 +1212,24 @@ msg_error_t MsgSetConfigInSim(const MSG_SETTING_S *pSetting)
        return err;
 }
 
-#ifdef __NOT_USED_BY_ENV_CHANGE__
-void MsgSetDefaultConfig()
-{
-       bool bTmp = false;
-       char keyName[128];
-
-       // Set Default General SendOpt
-       if (MsgSettingGetBool(MSG_KEEP_COPY, &bTmp) < 0)
-               MsgSettingSetBool(MSG_KEEP_COPY, true);
-
-       if (MsgSettingGetInt(MSG_ALERT_TONE) < 0)
-               MsgSettingSetInt(MSG_ALERT_TONE, (int)MSG_ALERT_TONE_ONCE);
-
-       if (MsgSettingGetBool(MSG_AUTO_ERASE, &bTmp) < 0)
-               MsgSettingGetBool(MSG_AUTO_ERASE, false);
-
-       // Set Default SMS SendOpt
-       if (MsgSettingGetInt(SMS_SEND_DCS) < 0)
-               MsgSettingSetInt(SMS_SEND_DCS, (int)MSG_ENCODE_AUTO);
-
-       if (MsgSettingGetInt(SMS_SEND_NETWORK_MODE) < 0)
-               MsgSettingSetInt(SMS_SEND_NETWORK_MODE, (int)MSG_SMS_NETWORK_CS_ONLY);
-
-       if (MsgSettingGetBool(SMS_SEND_REPLY_PATH, &bTmp) < 0)
-               MsgSettingSetBool(SMS_SEND_REPLY_PATH, false);
-
-       if (MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &bTmp) < 0)
-               MsgSettingSetBool(SMS_SEND_DELIVERY_REPORT, false);
-
-       if (MsgSettingGetInt(SMS_SEND_SAVE_STORAGE) < 0)
-               MsgSettingSetInt(SMS_SEND_SAVE_STORAGE, (int)MSG_SMS_SAVE_STORAGE_PHONE);
-
-       // Set Default SMSC List
-       if (MsgSettingGetInt(SMSC_SELECTED) < 0)
-               MsgSettingSetInt(SMSC_SELECTED, 0);
 
-       if (MsgSettingGetInt(SMSC_TOTAL_COUNT) < 0)
-               MsgSettingSetInt(SMSC_TOTAL_COUNT, 1);
-
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_PID, 0);
-
-       if (MsgSettingGetInt(keyName) < 0)
-               MsgSettingSetInt(keyName, (int)MSG_PID_TEXT);
-
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_VAL_PERIOD, MSG_VAL_MAXIMUM);
-
-       if (MsgSettingGetInt(keyName) < 0)
-               MsgSettingSetInt(keyName, 0);
-
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_NAME, 0);
-
-       char *smscName = NULL;
-
-       smscName = MsgSettingGetString(keyName);
-
-       if (smscName == NULL) {
-               MsgSettingSetString(keyName, (char*)"SMS Centre 1");
-       } else {
-               free(smscName);
-               smscName = NULL;
-       }
-
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_TON, 0);
-
-       if (MsgSettingGetInt(keyName) < 0)
-               MsgSettingSetInt(keyName, (int)MSG_TON_INTERNATIONAL);
-
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_NPI, 0);
-
-       if (MsgSettingGetInt(keyName) < 0)
-               MsgSettingSetInt(keyName, (int)MSG_NPI_ISDN);
-
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_ADDRESS, 0);
-
-       char *smscAddress = NULL;
-
-       smscAddress = MsgSettingGetString(keyName);
-
-       if (smscAddress == NULL) {
-               MsgSettingSetString(keyName, (char*)"8210911111");
-       } else {
-               free(smscAddress);
-               smscAddress = NULL;
-       }
-
-       // Set Default MMS Send Opt
-       if (MsgSettingGetInt(MMS_SEND_MSG_CLASS) < 0)
-               MsgSettingSetInt(MMS_SEND_MSG_CLASS, (int)MSG_CLASS_AUTO);
-
-       if (MsgSettingGetInt(MMS_SEND_PRIORITY) < 0)
-               MsgSettingSetInt(MMS_SEND_PRIORITY, (int)MSG_MESSAGE_PRIORITY_NORMAL);
-
-       if (MsgSettingGetInt(MMS_SEND_EXPIRY_TIME) < 0)
-               MsgSettingSetInt(MMS_SEND_EXPIRY_TIME, 86400);
-
-       if (MsgSettingGetInt(MMS_SEND_DELIVERY_TIME) < 0)
-               MsgSettingSetInt(MMS_SEND_DELIVERY_TIME, 0);
-
-       if (MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY) < 0)
-               MsgSettingSetInt(MMS_SEND_CUSTOM_DELIVERY, 0);
-
-       if (MsgSettingGetBool(MMS_SEND_SENDER_VISIBILITY, &bTmp) < 0)
-               MsgSettingSetBool(MMS_SEND_SENDER_VISIBILITY, false);
-
-       if (MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &bTmp) < 0)
-               MsgSettingSetBool(MMS_SEND_DELIVERY_REPORT, true);
-
-       if (MsgSettingGetBool(MMS_SEND_READ_REPLY, &bTmp) < 0)
-               MsgSettingSetBool(MMS_SEND_READ_REPLY, false);
-
-       if (MsgSettingGetBool(MMS_SEND_KEEP_COPY, &bTmp) < 0)
-               MsgSettingSetBool(MMS_SEND_KEEP_COPY, false);
-
-       if (MsgSettingGetBool(MMS_SEND_BODY_REPLYING, &bTmp) < 0)
-               MsgSettingSetBool(MMS_SEND_BODY_REPLYING, false);
-
-       if (MsgSettingGetBool(MMS_SEND_HIDE_RECIPIENTS, &bTmp) < 0)
-               MsgSettingSetBool(MMS_SEND_HIDE_RECIPIENTS, false);
-
-       if (MsgSettingGetInt(MMS_SEND_REPLY_CHARGING) < 0)
-               MsgSettingSetInt(MMS_SEND_REPLY_CHARGING, (int)MSG_REPLY_CHARGING_NONE);
-
-       if (MsgSettingGetInt(MMS_SEND_REPLY_CHARGING_DEADLINE) < 0)
-               MsgSettingSetInt(MMS_SEND_REPLY_CHARGING_DEADLINE, 0);
-
-       if (MsgSettingGetInt(MMS_SEND_REPLY_CHARGING_SIZE) < 0)
-               MsgSettingSetInt(MMS_SEND_REPLY_CHARGING_SIZE, 0);
-
-       // Set Default MMS Recv Opt
-       if (MsgSettingGetInt(MMS_RECV_HOME_NETWORK) < 0)
-               MsgSettingSetInt(MMS_RECV_HOME_NETWORK, (int)MSG_HOME_AUTO_DOWNLOAD);
-
-       if (MsgSettingGetInt(MMS_RECV_ABROAD_NETWORK) < 0)
-               MsgSettingSetInt(MMS_RECV_ABROAD_NETWORK, (int)MSG_ABROAD_RESTRICTED);
-
-       if (MsgSettingGetInt(MMS_RECV_READ_RECEIPT) < 0)
-               MsgSettingSetInt(MMS_RECV_READ_RECEIPT, (int)MSG_SEND_READ_REPORT_NEVER);
-
-       if (MsgSettingGetBool(MMS_RECV_DELIVERY_RECEIPT, &bTmp) < 0)
-               MsgSettingSetBool(MMS_RECV_DELIVERY_RECEIPT, true);
-
-       if (MsgSettingGetBool(MMS_RECV_REJECT_UNKNOWN, &bTmp) < 0)
-               MsgSettingSetBool(MMS_RECV_REJECT_UNKNOWN, false);
-
-       if (MsgSettingGetBool(MMS_RECV_REJECT_ADVERTISE, &bTmp) < 0)
-               MsgSettingSetBool(MMS_RECV_REJECT_ADVERTISE, false);
-
-       // Set Default MMS Style Opt
-       if (MsgSettingGetInt(MMS_STYLE_FONT_SIZE) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_SIZE, 30);
-
-       if (MsgSettingGetInt(MMS_STYLE_FONT_STYLE) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_STYLE, 0);
-
-       if (MsgSettingGetInt(MMS_STYLE_FONT_COLOR_RED) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_COLOR_RED, 0);
-
-       if (MsgSettingGetInt(MMS_STYLE_FONT_COLOR_GREEN) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_COLOR_GREEN, 0);
-
-       if (MsgSettingGetInt(MMS_STYLE_FONT_COLOR_BLUE) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_COLOR_BLUE, 0);
-
-       if (MsgSettingGetInt(MMS_STYLE_FONT_COLOR_HUE) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_COLOR_HUE, 255);
-
-       if (MsgSettingGetInt(MMS_STYLE_BG_COLOR_RED) < 0)
-               MsgSettingSetInt(MMS_STYLE_BG_COLOR_RED, 255);
-
-       if (MsgSettingGetInt(MMS_STYLE_BG_COLOR_GREEN) < 0)
-               MsgSettingSetInt(MMS_STYLE_BG_COLOR_GREEN, 255);
-
-       if (MsgSettingGetInt(MMS_STYLE_BG_COLOR_BLUE) < 0)
-               MsgSettingSetInt(MMS_STYLE_BG_COLOR_BLUE, 255);
-
-       if (MsgSettingGetInt(MMS_STYLE_BG_COLOR_HUE) < 0)
-               MsgSettingSetInt(MMS_STYLE_FONT_COLOR_HUE, 255);
-
-       if (MsgSettingGetInt(MMS_STYLE_PAGE_DUR) < 0)
-               MsgSettingSetInt(MMS_STYLE_PAGE_DUR, 2);
-
-       if (MsgSettingGetInt(MMS_STYLE_PAGE_CUSTOM_DUR) < 0)
-               MsgSettingSetInt(MMS_STYLE_PAGE_CUSTOM_DUR, 0);
-
-       if (MsgSettingGetInt(MMS_STYLE_PAGE_DUR_MANUAL) < 0)
-               MsgSettingSetInt(MMS_STYLE_PAGE_DUR_MANUAL, 0);
-
-       // Set Default Push Msg Opt
-       if (MsgSettingGetBool(PUSH_RECV_OPTION, &bTmp) < 0)
-               MsgSettingSetBool(PUSH_RECV_OPTION, false);
-
-       if (MsgSettingGetInt(PUSH_SERVICE_TYPE) < 0)
-               MsgSettingSetInt(PUSH_SERVICE_TYPE, (int)MSG_PUSH_SERVICE_PROMPT);
-
-       // Set Default Cb Msg Opt
-       if (MsgSettingGetBool(CB_RECEIVE, &bTmp) < 0)
-               MsgSettingSetBool(CB_RECEIVE, false);
-
-       if (MsgSettingGetBool(CB_ALL_CHANNEL, &bTmp) < 0)
-               MsgSettingSetBool(CB_ALL_CHANNEL, false);
+msg_error_t MsgGetConfigInSim(MSG_SETTING_S *pSetting)
+{
+       msg_error_t err = MSG_SUCCESS;
 
-       if (MsgSettingGetInt(CB_MAX_SIM_COUNT) < 0)
-               MsgSettingSetInt(CB_MAX_SIM_COUNT, 0);
+       MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
 
-       if (MsgSettingGetInt(CB_CHANNEL_COUNT) < 0)
-               MsgSettingSetInt(CB_CHANNEL_COUNT, 0);
+       // Get Setting Data from SIM
+       if (plg != NULL)
+               err = plg->getConfigData(pSetting);
+       else
+               err = MSG_ERR_NULL_POINTER;
 
-       for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++)
+       if (err != MSG_SUCCESS)
        {
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_LANGUAGE, i);
-
-               if (MsgSettingGetBool(keyName, &bTmp) < 0)
-                       MsgSettingSetBool(keyName, false);
-       }
-
-       // Set Default SOS Msg Opt
-       if (MsgSettingGetBool(SOS_SEND_OPTION, &bTmp) < 0)
-               MsgSettingSetBool(SOS_SEND_OPTION, false);
-
-       if (MsgSettingGetInt(SOS_RECIPIENT_COUNT) < 0)
-               MsgSettingSetInt(SOS_RECIPIENT_COUNT, 0);
-
-       if (MsgSettingGetInt(SOS_REPEAT_COUNT) < 0)
-               MsgSettingSetInt(SOS_REPEAT_COUNT, (int)MSG_SOS_REPEAT_ONCE);
-
-       char *tmpValue = NULL;
-
-       tmpValue = MsgSettingGetString(keyName);
-
-       if (tmpValue == NULL) {
-               MsgSettingSetString(keyName, NULL);
-       } else {
-               free(tmpValue);
-               tmpValue = NULL;
+               MSG_DEBUG("Error. Error code is %d.", err);
+               return err;
        }
 
-       if (MsgSettingGetInt(SOS_ALERT_TYPE) < 0)
-               MsgSettingSetInt(SOS_ALERT_TYPE, (int)MSG_SOS_ALERT_TYPE_SOS);
-
-       if (MsgSettingGetInt(MSGSIZE_OPTION) < 0)
-               MsgSettingSetInt(MSGSIZE_OPTION, 300);
+       return err;
 }
-#endif /* __NOT_USED_BY_ENV_CHANGE__ */
\ No newline at end of file
index e38676a..eb72217 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -22,7 +22,6 @@
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
 
 
 /*==================================================================================================
@@ -31,7 +30,7 @@ extern MsgDbHandler dbHandle;
 msg_error_t MsgStoCheckDuplicatedFilter(const MSG_FILTER_S *pFilter)
 {
        MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
 
        char *filterStr = NULL;
@@ -45,16 +44,16 @@ msg_error_t MsgStoCheckDuplicatedFilter(const MSG_FILTER_S *pFilter)
 
        MSG_DEBUG("sql : %s", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
        {
-               if (filterStr)
-                       free(filterStr);
+               if (filterStr)
+                       free(filterStr);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.bindText(filterStr, 1);
+       dbHandle->bindText(filterStr, 1);
 
-       err = dbHandle.stepQuery();
+       err = dbHandle->stepQuery();
 
        if (err == MSG_ERR_DB_ROW) {
                err = MSG_ERR_FILTER_DUPLICATED;
@@ -62,7 +61,7 @@ msg_error_t MsgStoCheckDuplicatedFilter(const MSG_FILTER_S *pFilter)
                err = MSG_SUCCESS;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        if (filterStr)
                free(filterStr);
@@ -76,7 +75,7 @@ msg_error_t MsgStoCheckDuplicatedFilter(const MSG_FILTER_S *pFilter)
 msg_error_t MsgStoAddFilter(const MSG_FILTER_S *pFilter)
 {
        MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
 
        //check duplication
@@ -91,7 +90,7 @@ msg_error_t MsgStoAddFilter(const MSG_FILTER_S *pFilter)
 
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       err = dbHandle.getRowId(MSGFW_FILTER_TABLE_NAME, &rowId);
+       err = dbHandle->getRowId(MSGFW_FILTER_TABLE_NAME, &rowId);
 
        if (err != MSG_SUCCESS)
                return err;
@@ -104,17 +103,17 @@ msg_error_t MsgStoAddFilter(const MSG_FILTER_S *pFilter)
 
        MSG_DEBUG("sql : %s", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
-       dbHandle.bindText(pFilter->filterValue, 1);
+       dbHandle->bindText(pFilter->filterValue, 1);
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        MSG_END();
 
@@ -125,7 +124,7 @@ msg_error_t MsgStoAddFilter(const MSG_FILTER_S *pFilter)
 msg_error_t MsgStoUpdateFilter(const MSG_FILTER_S *pFilter)
 {
        MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
 
        //check duplication
@@ -144,17 +143,17 @@ msg_error_t MsgStoUpdateFilter(const MSG_FILTER_S *pFilter)
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FILTER_TYPE = %d, FILTER_VALUE = ? WHERE FILTER_ID = %d;",
                        MSGFW_FILTER_TABLE_NAME, pFilter->filterType, pFilter->filterId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       dbHandle.bindText(pFilter->filterValue, 1);
+       dbHandle->bindText(pFilter->filterValue, 1);
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        MSG_END();
 
@@ -167,20 +166,20 @@ msg_error_t MsgStoDeleteFilter(msg_filter_id_t filterId)
        MSG_BEGIN();
 
        char sqlQuery[MAX_QUERY_LEN+1];
-
-       dbHandle.beginTrans();
+       MsgDbHandler *dbHandle = getDbHandle();
+       dbHandle->beginTrans();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE FILTER_ID = %d;", MSGFW_FILTER_TABLE_NAME, filterId);
 
        // Delete Filter
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        MSG_END();
 
@@ -196,7 +195,7 @@ msg_error_t MsgStoGetFilterList(msg_struct_list_s *pFilterList)
                MSG_DEBUG("pFilterList is NULL");
                return MSG_ERR_NULL_POINTER;
        }
-
+       MsgDbHandler *dbHandle = getDbHandle();
        int rowCnt = 0, index = 4;
 
        char sqlQuery[MAX_QUERY_LEN+1];
@@ -208,17 +207,17 @@ msg_error_t MsgStoGetFilterList(msg_struct_list_s *pFilterList)
 
        msg_error_t err = MSG_SUCCESS;
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err == MSG_ERR_DB_NORECORD) {
                pFilterList->nCount = 0;
                pFilterList->msg_struct_info = NULL;
 
-               dbHandle.freeTable();
+               dbHandle->freeTable();
 
                return MSG_SUCCESS;
        } else if (err != MSG_SUCCESS) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return err;
        }
 
@@ -239,15 +238,15 @@ msg_error_t MsgStoGetFilterList(msg_struct_list_s *pFilterList)
                pTmp->data = new char [sizeof(MSG_FILTER_S)];
                MSG_FILTER_S *pFilter = (MSG_FILTER_S *)pTmp->data;
                memset(pFilter, 0x00, sizeof(MSG_FILTER_S));
-               pFilter->filterId = dbHandle.getColumnToInt(index++);
-               pFilter->filterType = dbHandle.getColumnToInt(index++);
+               pFilter->filterId = dbHandle->getColumnToInt(index++);
+               pFilter->filterType = dbHandle->getColumnToInt(index++);
                memset(pFilter->filterValue, 0x00, sizeof(pFilter->filterValue));
-               dbHandle.getColumnToString(index++, MAX_FILTER_VALUE_LEN, pFilter->filterValue);
-               pFilter->bActive = dbHandle.getColumnToInt(index++);
+               dbHandle->getColumnToString(index++, MAX_FILTER_VALUE_LEN, pFilter->filterValue);
+               pFilter->bActive = dbHandle->getColumnToInt(index++);
        }
 
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        MSG_END();
 
@@ -258,7 +257,7 @@ msg_error_t MsgStoGetFilterList(msg_struct_list_s *pFilterList)
 msg_error_t MsgStoSetFilterActivation(msg_filter_id_t filterId, bool bActive)
 {
        MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        // Set Filter Activation
@@ -269,7 +268,7 @@ msg_error_t MsgStoSetFilterActivation(msg_filter_id_t filterId, bool bActive)
 
        MSG_DEBUG("sqlQuery [%s]", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                return MSG_ERR_DB_EXEC;
        }
 
index 3cd2368..3013f4a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -23,8 +23,6 @@
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
-
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
@@ -32,12 +30,12 @@ extern MsgDbHandler dbHandle;
 msg_error_t MsgStoAddFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
 {
        msg_error_t err = MSG_SUCCESS;
-
+       MsgDbHandler *dbHandle = getDbHandle();
        unsigned int rowId = 0;
 
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       err = dbHandle.getRowId(MSGFW_FOLDER_TABLE_NAME, &rowId);
+       err = dbHandle->getRowId(MSGFW_FOLDER_TABLE_NAME, &rowId);
 
        if (err != MSG_SUCCESS)
                return err;
@@ -47,7 +45,7 @@ msg_error_t MsgStoAddFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
        snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', %d);",
                        MSGFW_FOLDER_TABLE_NAME, rowId, pFolderInfo->folderName, pFolderInfo->folderType);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -57,13 +55,13 @@ msg_error_t MsgStoAddFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
 msg_error_t MsgStoUpdateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
-
+       MsgDbHandler *dbHandle = getDbHandle();
        // Update Folder
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_NAME = '%s', FOLDER_TYPE = %d WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, pFolderInfo->folderName, pFolderInfo->folderType, pFolderInfo->folderId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -73,16 +71,16 @@ msg_error_t MsgStoUpdateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
 msg_error_t MsgStoDeleteFolder(const msg_folder_id_t folderId)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
-
-       dbHandle.beginTrans();
+       MsgDbHandler *dbHandle = getDbHandle();
+       dbHandle->beginTrans();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, folderId);
 
        // Delete Message in the folder from msg table
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
@@ -91,18 +89,18 @@ msg_error_t MsgStoDeleteFolder(const msg_folder_id_t folderId)
                        MSGFW_FOLDER_TABLE_NAME, folderId);
 
        // Delete Message in the folder from msg table
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
        // Clear Conversation table
-       if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        return MSG_SUCCESS;
 }
@@ -114,7 +112,7 @@ msg_error_t MsgStoGetFolderList(msg_struct_list_s *pFolderList)
                MSG_DEBUG("pFolderList is NULL");
                return MSG_ERR_NULL_POINTER;
        }
-
+       MsgDbHandler *dbHandle = getDbHandle();
        int rowCnt = 0;
        int index = 3;
 
@@ -124,8 +122,8 @@ msg_error_t MsgStoGetFolderList(msg_struct_list_s *pFolderList)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FOLDER_ID, FOLDER_TYPE, FOLDER_NAME FROM %s;",
                        MSGFW_FOLDER_TABLE_NAME);
 
-       if (dbHandle.getTable(sqlQuery, &rowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &rowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
@@ -146,16 +144,16 @@ msg_error_t MsgStoGetFolderList(msg_struct_list_s *pFolderList)
                MSG_FOLDER_INFO_S * pFolder = (MSG_FOLDER_INFO_S *)pTmp->data;
                memset(pFolder, 0x00, sizeof(MSG_FOLDER_INFO_S));
 
-               pFolder->folderId = dbHandle.getColumnToInt(index++);
+               pFolder->folderId = dbHandle->getColumnToInt(index++);
 
-               pFolder->folderType = dbHandle.getColumnToInt(index++);
+               pFolder->folderType = dbHandle->getColumnToInt(index++);
 
                memset(pFolder->folderName, 0x00, sizeof(pFolder->folderName));
-               dbHandle.getColumnToString(index++, MAX_FOLDER_NAME_SIZE, pFolder->folderName);
+               dbHandle->getColumnToString(index++, MAX_FOLDER_NAME_SIZE, pFolder->folderName);
 
        }
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return MSG_SUCCESS;
 }
index 72d4c83..462724d 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -19,6 +19,8 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <sys/mman.h>
+#include <fcntl.h>
 
 #include <VMessage.h>
 #include <VCard.h>
 #include "MsgStorageHandler.h"
 
 
+#define MSG_DB_VERSION 1
+
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-MsgDbHandler dbHandle;
-
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
@@ -50,7 +52,8 @@ msg_error_t MsgStoConnectDB()
 
 msg_error_t MsgStoDisconnectDB()
 {
-       if (dbHandle.disconnect() != MSG_SUCCESS) {
+       MsgDbHandler *dbHandle = getDbHandle();
+       if (dbHandle->disconnect() != MSG_SUCCESS) {
                MSG_DEBUG("DB Disconnect Fail");
                return MSG_ERR_DB_DISCONNECT;
        }
@@ -61,444 +64,174 @@ msg_error_t MsgStoDisconnectDB()
 }
 
 
-msg_error_t MsgStoInitDB(bool bSimChanged)
+void MsgUpdateDBtoVer1()
 {
-       MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
-
-#ifdef MSG_DB_CREATE
-       if (MsgCreateConversationTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateAddressTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateFolderTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateMsgTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateSimMessageTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateWAPMessageTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateCBMessageTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateSyncMLMessageTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateSmsSendOptTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateFilterTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-       if (MsgCreateMmsTable() != MSG_SUCCESS)
-               return MSG_ERR_DB_STORAGE_INIT;
-
-       // Add Default Folders
-       if (MsgAddDefaultFolders() != MSG_SUCCESS) {
-               MSG_DEBUG("Add Default Folders Fail");
-               return MSG_ERR_DB_STORAGE_INIT;
-       }
-
-       // Add Default Address
-       if (MsgAddDefaultAddress() != MSG_SUCCESS) {
-               MSG_DEBUG("Add Default Address Fail");
-               return MSG_ERR_DB_STORAGE_INIT;
-       }
-#endif
-
-       // Delete Msgs in Hidden Folder
-       MsgStoDeleteAllMessageInFolder(0, true, NULL);
-
-       // Reset network status
-       MsgStoResetNetworkStatus();
-
-       //clear abnormal mms message
-       MsgStoCleanAbnormalMmsData();
-
-       // Clear all old Sim data
-       MsgStoClearSimMessageInDB();
-
-       int smsCnt = 0, mmsCnt = 0;
-
-       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-       // Set Indicator
-       MsgSettingSetIndicator(smsCnt, mmsCnt);
-
-       MSG_END();
-
-       return err;
-}
-
-
-msg_error_t MsgCreateConversationTable()
-{
-       msg_error_t err = MSG_SUCCESS;
-
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       if (!dbHandle.checkTableExist(MSGFW_ADDRESS_TABLE_NAME)) {
+       if (!dbHandle->checkTableExist(MSGFW_MMS_MULTIPART_TABLE_NAME)) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
                snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               CONV_ID INTEGER NOT NULL , \
-                               UNREAD_CNT INTEGER DEFAULT 0 , \
-                               SMS_CNT INTEGER DEFAULT 0 , \
-                               MMS_CNT INTEGER DEFAULT 0 , \
-                               MAIN_TYPE INTEGER NOT NULL , \
-                               SUB_TYPE INTEGER NOT NULL , \
-                               MSG_DIRECTION INTEGER NOT NULL , \
-                               DISPLAY_TIME INTEGER , \
-                               DISPLAY_NAME TEXT , \
-                               MSG_TEXT TEXT );",
-                               MSGFW_CONVERSATION_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
+                               "CREATE TABLE %s ( "
+                               "_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+                               "MSG_ID INTEGER NOT NULL , "
+                               "SEQ INTEGER DEFAULT 0, "
+                               "CONTENT_TYPE TEXT, "
+                               "NAME TEXT, "
+                               "CHARSET INTEGER, "
+                               "CONTENT_ID TEXT, "
+                               "CONTENT_LOCATION TEXT, "
+                               "FILE_PATH TEXT, "
+                               "TEXT TEXT, "
+                               "TCS_LEVEL INTEGER DEFAULT -1, "
+                               "MALWARE_ALLOW INTEGER DEFAULT 0, "
+                               "THUMB_FILE_PATH TEXT, "
+                               "FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID));",
+                               MSGFW_MMS_MULTIPART_TABLE_NAME);
+
+               err = dbHandle->execQuery(sqlQuery);
 
                if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_CONVERSATION_TABLE_NAME);
+                       MSG_SEC_DEBUG("SUCCESS : create %s.", MSGFW_MMS_MULTIPART_TABLE_NAME);
                else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_CONVERSATION_TABLE_NAME, err);
+                       MSG_SEC_DEBUG("FAIL : create %s [%d].", MSGFW_MMS_MULTIPART_TABLE_NAME, err);
        }
-
-       return err;
 }
 
 
-msg_error_t MsgCreateAddressTable()
+void MsgStoUpdateDBVersion()
 {
-       msg_error_t err = MSG_SUCCESS;
-
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       if (!dbHandle.checkTableExist(MSGFW_ADDRESS_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               ADDRESS_ID INTEGER PRIMARY KEY , \
-                               CONV_ID INTEGER  NOT NULL , \
-                               ADDRESS_TYPE INTEGER , \
-                               RECIPIENT_TYPE INTEGER , \
-                               ADDRESS_VAL TEXT , \
-                               CONTACT_ID INTEGER , \
-                               DISPLAY_NAME TEXT , \
-                               FIRST_NAME TEXT , \
-                               LAST_NAME TEXT , \
-                               IMAGE_PATH TEXT , \
-                               SYNC_TIME DATETIME , \
-                               FOREIGN KEY(CONV_ID) REFERENCES %s (CONV_ID) );",
-                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_CONVERSATION_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
+       snprintf(sqlQuery, sizeof(sqlQuery), "PRAGMA user_version=%d;", MSG_DB_VERSION);
 
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_ADDRESS_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_ADDRESS_TABLE_NAME, err);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to prepareQuery.");
+               return;
        }
 
-       return err;
-}
-
-
-msg_error_t MsgCreateFolderTable()
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       if (!dbHandle.checkTableExist(MSGFW_FOLDER_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               FOLDER_ID INTEGER PRIMARY KEY, \
-                               FOLDER_NAME TEXT NOT NULL, \
-                               FOLDER_TYPE INTEGER DEFAULT 0 );",
-                               MSGFW_FOLDER_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
-
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_FOLDER_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_FOLDER_TABLE_NAME, err);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_STEP) {
+               MSG_DEBUG("Fail to stepQuery.");
+               return;
        }
 
-       return err;
+       dbHandle->finalizeQuery();
 }
 
-
-msg_error_t MsgCreateMsgTable()
+msg_error_t MsgStoDBVerCheck()
 {
-       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       int dbVersion = 0;
 
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       if (!dbHandle.checkTableExist(MSGFW_MESSAGE_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER PRIMARY KEY , \
-                               CONV_ID INTEGER NOT NULL , \
-                               FOLDER_ID INTEGER NOT NULL , \
-                               STORAGE_ID INTEGER NOT NULL , \
-                               MAIN_TYPE INTEGER NOT NULL , \
-                               SUB_TYPE INTEGER NOT NULL , \
-                               DISPLAY_TIME DATETIME , \
-                               DATA_SIZE INTEGER DEFAULT 0 , \
-                               NETWORK_STATUS INTEGER DEFAULT 0 , \
-                               READ_STATUS INTEGER DEFAULT 0 , \
-                               PROTECTED INTEGER DEFAULT 0 , \
-                               PRIORITY INTEGER DEFAULT 0 , \
-                               MSG_DIRECTION INTEGER NOT NULL , \
-                               SCHEDULED_TIME DATETIME , \
-                               BACKUP INTEGER DEFAULT 0 , \
-                               SUBJECT TEXT , \
-                               MSG_DATA TEXT , \
-                               THUMB_PATH TEXT , \
-                               MSG_TEXT TEXT , \
-                               ATTACHMENT_COUNT INTEGER DEFAULT 0 , \
-                               FOREIGN KEY(CONV_ID) REFERENCES %s (CONV_ID) , \
-                               FOREIGN KEY(FOLDER_ID) REFERENCES %s (FOLDER_ID) );",
-                               MSGFW_MESSAGE_TABLE_NAME, MSGFW_CONVERSATION_TABLE_NAME, MSGFW_FOLDER_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
+       snprintf(sqlQuery, sizeof(sqlQuery), "PRAGMA user_version;");
 
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_MESSAGE_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_MESSAGE_TABLE_NAME, err);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to prepareQuery.");
+               return MSG_ERR_DB_EXEC;
        }
 
-       return err;
-}
-
-
-msg_error_t MsgCreateSimMessageTable()
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       if (!dbHandle.checkTableExist(MSGFW_SIM_MSG_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER , \
-                               SIM_ID INTEGER NOT NULL , \
-                               FOREIGN KEY(MSG_ID) REFERENCES %s (MSG_ID) );",
-                               MSGFW_SIM_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
-
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_SIM_MSG_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_SIM_MSG_TABLE_NAME, err);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_STEP) {
+               MSG_DEBUG("Fail to stepQuery.");
+               return MSG_ERR_DB_EXEC;
        }
 
-       return err;
-}
-
+       dbVersion = dbHandle->columnInt(0);
 
-msg_error_t MsgCreateWAPMessageTable()
-{
-       msg_error_t err = MSG_SUCCESS;
+       dbHandle->finalizeQuery();
 
-       char sqlQuery[MAX_QUERY_LEN+1];
+       MSG_DEBUG("dbVersion [%d]", dbVersion);
 
-       if (!dbHandle.checkTableExist(MSGFW_PUSH_MSG_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER , \
-                               ACTION INTEGER , \
-                               CREATED INTEGER , \
-                               EXPIRES INTEGER , \
-                               ID TEXT , \
-                               HREF TEXT , \
-                               CONTENT TEXT , \
-                               FOREIGN KEY(MSG_ID) REFERENCES %s(MSG_ID) );",
-                               MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
-
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_PUSH_MSG_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_PUSH_MSG_TABLE_NAME, err);
+       switch (dbVersion)
+       {
+       case 0 :
+               MsgUpdateDBtoVer1();
+               /* no break */
+       default :
+               MsgStoUpdateDBVersion();
+               /* no break */
        }
 
-       return err;
+       return MSG_SUCCESS;
 }
 
-
-msg_error_t MsgCreateCBMessageTable()
+void MsgInitMmapMutex(const char *shm_file_name)
 {
-       msg_error_t err = MSG_SUCCESS;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       if (!dbHandle.checkTableExist(MSGFW_CB_MSG_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER , \
-                               CB_MSG_ID INTEGER NOT NULL , \
-                               FOREIGN KEY(MSG_ID) REFERENCES %s (MSG_ID) );",
-                               MSGFW_CB_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
+       MSG_BEGIN();
 
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_CB_MSG_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_CB_MSG_TABLE_NAME, err);
+       if(!shm_file_name) {
+               MSG_FATAL("EMAIL_ERROR_INVALID_PARAM");
+               return;
        }
 
-       return err;
-}
-
+       int fd = shm_open (shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /*  note: permission is not working */
 
-msg_error_t MsgCreateSyncMLMessageTable()
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       if (!dbHandle.checkTableExist(MSGFW_SYNCML_MSG_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER , \
-                               EXT_ID INTEGER NOT NULL , \
-                               PINCODE INTEGER NOT NULL , \
-                               FOREIGN KEY(MSG_ID) REFERENCES %s(MSG_ID) );",
-                               MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
-
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MSGFW_SYNCML_MSG_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MSGFW_SYNCML_MSG_TABLE_NAME, err);
+       if (fd < 0) {
+               MSG_FATAL("shm_open errno [%d]", errno);
+               return;
        }
 
-       return err;
-}
-
-msg_error_t MsgCreateSmsSendOptTable()
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       if (!dbHandle.checkTableExist(MSGFW_SMS_SENDOPT_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER , \
-                               DELREP_REQ INTEGER NOT NULL , \
-                               KEEP_COPY INTEGER NOT NULL , \
-                               REPLY_PATH INTEGER NOT NULL , \
-                               FOREIGN KEY(MSG_ID) REFERENCES %s (MSG_ID) );",
-                               MSGFW_SMS_SENDOPT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
+       fchmod(fd, 0666);
+       MSG_DEBUG("** Create SHM FILE **");
+       if (ftruncate(fd, sizeof(pthread_mutex_t)) != 0) {
+               MSG_FATAL("ftruncate errno [%d]", errno);
+               return;
+       }
 
-               if (err == MSG_SUCCESS)
-                               MSG_DEBUG("SUCCESS : create %s.", MSGFW_SMS_SENDOPT_TABLE_NAME);
-               else
-                               MSG_DEBUG("FAIL : create %s [%d].", MSGFW_SMS_SENDOPT_TABLE_NAME, err);
+       pthread_mutex_t *mx = (pthread_mutex_t *)mmap(NULL, sizeof(pthread_mutex_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+       if (mx == MAP_FAILED) {
+               MSG_FATAL("mmap errno [%d]", errno);
+               return ;
        }
 
-       return err;
-}
+       // initialize the data on mmap
+       pthread_mutexattr_t mattr;
+       pthread_mutexattr_init(&mattr);
+       pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
+       pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+       pthread_mutex_init(mx, &mattr);
+       pthread_mutexattr_destroy(&mattr);
 
+       close (fd);
+       MSG_END();
+}
 
-msg_error_t MsgCreateFilterTable()
+msg_error_t MsgStoInitDB(bool bSimChanged)
 {
+       MSG_BEGIN();
+//     MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
 
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       if (!dbHandle.checkTableExist(MSGFW_FILTER_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               FILTER_ID INTEGER PRIMARY KEY , \
-                               FILTER_TYPE INTEGER NOT NULL , \
-                               FILTER_VALUE TEXT NOT NULL , \
-                               FILTER_ACTIVE INTEGER DEFAULT 0);",
-                               MSGFW_FILTER_TABLE_NAME);
+       // Init mmap mutex for DB access
+       MsgInitMmapMutex(SHM_FILE_FOR_DB_LOCK);
 
-               err = dbHandle.execQuery(sqlQuery);
+       // Check DB version.
+       MsgStoDBVerCheck();
 
-               if (err == MSG_SUCCESS)
-                               MSG_DEBUG("SUCCESS : create %s.", MSGFW_FILTER_TABLE_NAME);
-               else
-                               MSG_DEBUG("FAIL : create %s [%d].", MSGFW_FILTER_TABLE_NAME, err);
-       }
-
-       return err;
-}
+       // Delete Msgs in Hidden Folder
+       MsgStoDeleteAllMessageInFolder(0, true, NULL);
 
+       // Reset network status
+       MsgStoResetNetworkStatus();
 
-msg_error_t MsgCreateMmsTable()
-{
-       msg_error_t err = MSG_SUCCESS;
+#if 0
+       // Reset Cb Message
+       MsgStoResetCBMessage();
+#endif
 
-       char sqlQuery[MAX_QUERY_LEN+1];
+       //clear abnormal mms message
+       MsgStoCleanAbnormalMmsData();
 
-       if (!dbHandle.checkTableExist(MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       // Clear all old Sim data
+       MsgStoClearSimMessageInDB();
 
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "CREATE TABLE %s ( \
-                               MSG_ID INTEGER , \
-                               TRANSACTION_ID TEXT , \
-                               MESSAGE_ID TEXT , \
-                               FWD_MESSAGE_ID TEXT , \
-                               CONTENTS_LOCATION TEXT , \
-                               FILE_PATH TEXT , \
-                               VERSION INTEGER NOT NULL , \
-                               DATA_TYPE INTEGER DEFAULT -1 , \
-                               DATE DATETIME , \
-                               HIDE_ADDRESS INTEGER DEFAULT 0 , \
-                               ASK_DELIVERY_REPORT INTEGER DEFAULT 0 , \
-                               REPORT_ALLOWED INTEGER DEFAULT 0 , \
-                               READ_REPORT_ALLOWED_TYPE INTEGER DEFAULT 0 , \
-                               ASK_READ_REPLY INTEGER DEFAULT 0 , \
-                               READ INTEGER DEFAULT 0 , \
-                               READ_REPORT_SEND_STATUS INTEGER DEFAULT 0 , \
-                               READ_REPORT_SENT INTEGER DEFAULT 0 , \
-                               PRIORITY INTEGER DEFAULT 0 , \
-                               KEEP_COPY INTEGER DEFAULT 0 , \
-                               MSG_SIZE INTEGER NOT NULL , \
-                               MSG_CLASS INTEGER DEFAULT -1 , \
-                               EXPIRY_TIME DATETIME , \
-                               CUSTOM_DELIVERY_TIME INTEGER DEFAULT 0 , \
-                               DELIVERY_TIME DATETIME , \
-                               MSG_STATUS INTEGER DEFAULT -1 , \
-                               FOREIGN KEY(MSG_ID) REFERENCES %s (MSG_ID) );",
-                               MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
-
-               err = dbHandle.execQuery(sqlQuery);
+       //update sim index to 0 for all messages
+       MsgStoUpdateIMSI(0);
 
-               if (err == MSG_SUCCESS)
-                       MSG_DEBUG("SUCCESS : create %s.", MMS_PLUGIN_MESSAGE_TABLE_NAME);
-               else
-                       MSG_DEBUG("FAIL : create %s [%d].", MMS_PLUGIN_MESSAGE_TABLE_NAME, err);
-       }
+       MSG_END();
 
        return err;
 }
@@ -510,27 +243,27 @@ msg_error_t MsgAddDefaultFolders()
        int nResult = 0;
 
        char sqlQuery[MAX_QUERY_LEN+1];
-
+       MsgDbHandler *dbHandle = getDbHandle();
        // INBOX
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, MSG_INBOX_ID);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'INBOX', %d);",
                                MSGFW_FOLDER_TABLE_NAME, MSG_INBOX_ID, MSG_FOLDER_TYPE_INBOX);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -539,21 +272,21 @@ msg_error_t MsgAddDefaultFolders()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, MSG_OUTBOX_ID);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'OUTBOX', %d);",
                                MSGFW_FOLDER_TABLE_NAME, MSG_OUTBOX_ID, MSG_FOLDER_TYPE_OUTBOX);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -562,21 +295,21 @@ msg_error_t MsgAddDefaultFolders()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, MSG_SENTBOX_ID);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'SENTBOX', %d);",
                                MSGFW_FOLDER_TABLE_NAME, MSG_SENTBOX_ID, MSG_FOLDER_TYPE_OUTBOX);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -585,21 +318,21 @@ msg_error_t MsgAddDefaultFolders()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, MSG_DRAFT_ID);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'DRAFT', %d);",
                                MSGFW_FOLDER_TABLE_NAME, MSG_DRAFT_ID, MSG_FOLDER_TYPE_DRAFT);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -608,21 +341,21 @@ msg_error_t MsgAddDefaultFolders()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, MSG_CBMSGBOX_ID);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'CBMSGBOX', %d);",
                                MSGFW_FOLDER_TABLE_NAME, MSG_CBMSGBOX_ID, MSG_FOLDER_TYPE_INBOX);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -631,67 +364,21 @@ msg_error_t MsgAddDefaultFolders()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
                        MSGFW_FOLDER_TABLE_NAME, MSG_SPAMBOX_ID);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'SPAMBOX', %d);",
                                MSGFW_FOLDER_TABLE_NAME, MSG_SPAMBOX_ID, MSG_FOLDER_TYPE_SPAMBOX);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-                       return MSG_ERR_DB_EXEC;
-       }
-
-       // SMS TEMPLATE
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
-                       MSGFW_FOLDER_TABLE_NAME, MSG_SMS_TEMPLATE_ID);
-
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
-               return MSG_ERR_DB_GETTABLE;
-       }
-
-       nResult = dbHandle.getColumnToInt(1);
-
-       dbHandle.freeTable();
-
-       if (nResult == 0) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'SMS TEMPLATE', %d);",
-                               MSGFW_FOLDER_TABLE_NAME, MSG_SMS_TEMPLATE_ID, MSG_FOLDER_TYPE_TEMPLATE);
-
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-                       return MSG_ERR_DB_EXEC;
-       }
-
-       // MMS TEMPLATE
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE FOLDER_ID = %d;",
-                       MSGFW_FOLDER_TABLE_NAME, MSG_MMS_TEMPLATE_ID);
-
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
-               return MSG_ERR_DB_GETTABLE;
-       }
-
-       nResult = dbHandle.getColumnToInt(1);
-
-       dbHandle.freeTable();
-
-       if (nResult == 0) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 'MMS TEMPLATE', %d);",
-                               MSGFW_FOLDER_TABLE_NAME, MSG_MMS_TEMPLATE_ID, MSG_FOLDER_TYPE_TEMPLATE);
-
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -702,7 +389,7 @@ msg_error_t MsgAddDefaultFolders()
 msg_error_t MsgAddDefaultAddress()
 {
        MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        int nRowCnt = 0, nResult = 0;
 
        char sqlQuery[MAX_QUERY_LEN+1];
@@ -711,23 +398,23 @@ msg_error_t MsgAddDefaultAddress()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s WHERE ADDRESS_ID = 0;",
                        MSGFW_ADDRESS_TABLE_NAME);
 
-       if (dbHandle.getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &nRowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
-       nResult = dbHandle.getColumnToInt(1);
+       nResult = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        if (nResult == 0) {
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (0, 0, 0, '', 0, '', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '');",
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (0, 0, 0, 0, '', 0, 0, '', '', '', '', '', '', 0);",
                                MSGFW_ADDRESS_TABLE_NAME);
 
                MSG_DEBUG("%s", sqlQuery);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_EXEC;
        }
 
@@ -739,6 +426,7 @@ msg_error_t MsgAddDefaultAddress()
 
 msg_error_t MsgStoResetDatabase()
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
@@ -750,7 +438,7 @@ msg_error_t MsgStoResetDatabase()
 
        int listCnt = sizeof(tableList)/sizeof(char*);
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
 
        // Delete Database
        for (int i = 0; i < listCnt; i++)
@@ -758,8 +446,8 @@ msg_error_t MsgStoResetDatabase()
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", tableList[i]);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
        }
@@ -769,34 +457,34 @@ msg_error_t MsgStoResetDatabase()
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE STORAGE_ID <> %d;",
                        MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
        // Delete Conversation Table
-       err = MsgStoClearConversationTable(&dbHandle);
+       err = MsgStoClearConversationTable(dbHandle);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return err;
        }
 
        // Add Default Folders
        if (MsgAddDefaultFolders() != MSG_SUCCESS) {
                MSG_DEBUG("Add Default Folders Fail");
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_STORAGE_INIT;
        }
 
        // Add Default Address
        if (MsgAddDefaultAddress() != MSG_SUCCESS) {
                MSG_DEBUG("Add Default Address Fail");
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_STORAGE_INIT;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        // Delete MMS Files
        MsgRmRf((char*)MSG_DATA_PATH);
@@ -820,6 +508,7 @@ msg_error_t MsgStoResetDatabase()
 
 msg_error_t MsgStoBackupMessage(msg_message_backup_type_t type, const char *filepath)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t     err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
@@ -832,12 +521,12 @@ msg_error_t MsgStoBackupMessage(msg_message_backup_type_t type, const char *file
        memset(fileName, 0x00, sizeof(fileName));
        strncpy(fileName, filepath, MSG_FILENAME_LEN_MAX);
        if (remove(fileName) != 0) {
-               MSG_DEBUG("Fail to delete [%s].", fileName);
+               MSG_SEC_DEBUG("Fail to delete [%s].", fileName);
        }
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       MSG_DEBUG("backup type = %d, path = %s", type, filepath);
+       MSG_SEC_DEBUG("backup type = %d, path = %s", type, filepath);
 
        if (type == MSG_BACKUP_TYPE_SMS) {
                snprintf(sqlQuery, sizeof(sqlQuery),
@@ -857,26 +546,35 @@ msg_error_t MsgStoBackupMessage(msg_message_backup_type_t type, const char *file
 
        }
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return err;
        }
        MSG_DEBUG("backup number = %d", rowCnt);
 
        for (int i = 0; i < rowCnt; i++) {
-               err = MsgStoGetMessage(dbHandle.getColumnToInt(++index), &msgInfo, NULL);
+               int msgid = dbHandle->getColumnToInt(++index);
+
+               msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+               err = MsgStoGetMessage(msgid, &msgInfo, NULL);
                if(err != MSG_SUCCESS) {
-                       dbHandle.freeTable();
+                       dbHandle->freeTable();
                        return err;
                }
 
-               encoded_data = MsgVMessageAddRecord(&dbHandle, &msgInfo);
+               encoded_data = MsgVMessageAddRecord(dbHandle, &msgInfo);
 
+               if (msgInfo.bTextSms == false)
+               {
+                       MsgDeleteFile(msgInfo.msgData); //ipc
+               }
                if (encoded_data != NULL) {
                        if (MsgAppendFile(fileName, encoded_data, strlen(encoded_data)) == false) {
-                               dbHandle.freeTable();
+                               dbHandle->freeTable();
                                free(encoded_data);
                                return MSG_ERR_STORAGE_ERROR;
                        }
@@ -887,7 +585,7 @@ msg_error_t MsgStoBackupMessage(msg_message_backup_type_t type, const char *file
                memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
        }
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
        MSG_END();
        return MSG_SUCCESS;
 
@@ -895,49 +593,77 @@ msg_error_t MsgStoBackupMessage(msg_message_backup_type_t type, const char *file
 
 msg_error_t MsgStoUpdateMms(MSG_MESSAGE_INFO_S *pMsg)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+       msg_error_t err = MSG_SUCCESS;
        char sqlQuery[MAX_QUERY_LEN+1];
+       unsigned int fileSize = 0;
+       char *pFileData = NULL;
 
        if (pMsg->msgType.subType == MSG_SENDCONF_MMS) {
+
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-               dbHandle.beginTrans();
+               dbHandle->beginTrans();
                snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET THUMB_PATH = ?, MSG_TEXT = ? WHERE MSG_ID = %d;",
                                MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
 
 
-               dbHandle.bindText(pMsg->thumbPath, 1);
-               dbHandle.bindText(pMsg->msgText, 2);
-               MSG_DEBUG("thumbPath = %s , msgText = %s" , pMsg->thumbPath, pMsg->msgText);
+               dbHandle->bindText(pMsg->thumbPath, 1);
+
+               if (pMsg->msgText[0] != '\0' && g_file_get_contents(pMsg->msgText, &pFileData, &fileSize, NULL) == true) {
+                       dbHandle->bindText(pFileData, 2);
+               }
+
+               MSG_DEBUG("thumbPath = %s , msgText = %s" , pMsg->thumbPath, pFileData);
+
                MSG_DEBUG("%s", sqlQuery);
 
-               if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-                       dbHandle.finalizeQuery();
-                       dbHandle.endTrans(false);
+               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                       dbHandle->finalizeQuery();
+                       dbHandle->endTrans(false);
+                       if (pFileData) {
+                               free(pFileData);
+                               pFileData = NULL;
+                       }
+
                        return MSG_ERR_DB_EXEC;
                }
 
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(true);
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(true);
+
+               if (pFileData) {
+                       free(pFileData);
+                       pFileData = NULL;
+               }
        } else {
-               if (MsgStoUpdateMMSMessage(pMsg) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgStoUpdateMMSMessage is failed");
+
+               err = MsgStoUpdateMMSMessage(pMsg);
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgStoUpdateMMSMessage() error : %d", err);
+               }
+
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
-msg_error_t MsgStoRestoreMessage(const char *filepath)
+msg_error_t MsgStoRestoreMessage(const char *filepath, msg_id_list_s**result_id_list)
 {
        msg_error_t err = MSG_SUCCESS;
        MSG_MESSAGE_INFO_S msgInfo = {0,};
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
        VTree* vMsg = NULL;
        VObject* pObject = NULL;
 
+       msg_id_list_s *msgIdList = NULL;
+       msgIdList = (msg_id_list_s *)calloc(1, sizeof(msg_id_list_s));
+
        int dataSize = 0;
 
        char fileName[MSG_FILENAME_LEN_MAX+1];
@@ -967,6 +693,10 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                MSG_DEBUG("Start Position2: %s", pCurrent);
 
                vMsg = vmsg_decode(pCurrent);
+               if (vMsg == NULL) {
+                       err = MSG_ERR_STORAGE_ERROR;
+                       goto __RETURN;
+               }
 #endif
 
                pObject = vMsg->pTop;
@@ -997,7 +727,8 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                        msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
                                                } else {
                                                        vmsg_free_vtree_memory(vMsg);
-                                                       return MSG_ERR_STORAGE_ERROR;
+                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                       goto __RETURN;
                                                }
                                        }
                                        break;
@@ -1008,7 +739,13 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                        msgInfo.folderId= MSG_INBOX_ID;
                                                        msgInfo.direction=MSG_DIRECTION_TYPE_MT;
 
-                                                       msgInfo.networkStatus=MSG_NETWORK_RECEIVED;
+                                                       if (msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS)
+                                                               msgInfo.networkStatus=MSG_NETWORK_RETRIEVE_SUCCESS;
+                                                       else if (msgInfo.msgType.subType == MSG_SENDCONF_MMS)
+                                                               msgInfo.networkStatus=MSG_NETWORK_SEND_SUCCESS;
+                                                       else
+                                                               msgInfo.networkStatus=MSG_NETWORK_RECEIVED;
+
                                                } else if(!strncmp(pObject->pszValue[0], "OUTBOX", strlen("OUTBOX"))) {
                                                        msgInfo.folderId= MSG_OUTBOX_ID;
                                                        msgInfo.direction=MSG_DIRECTION_TYPE_MO;
@@ -1026,7 +763,8 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                        msgInfo.networkStatus=MSG_NETWORK_NOT_SEND;
                                                } else {
                                                        vmsg_free_vtree_memory(vMsg);
-                                                       return MSG_ERR_STORAGE_ERROR;
+                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                       goto __RETURN;
                                                }
                                        }
                                        break;
@@ -1039,7 +777,8 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                        msgInfo.bRead = false;
                                                } else {
                                                        vmsg_free_vtree_memory(vMsg);
-                                                       return MSG_ERR_STORAGE_ERROR;
+                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                       goto __RETURN;
                                                }
                                        }
                                        break;
@@ -1050,7 +789,8 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
 
                                                if (!_convert_vdata_str_to_tm(pObject->pszValue[0], &displayTime)) {
                                                        vmsg_free_vtree_memory( vMsg );
-                                                       return MSG_ERR_STORAGE_ERROR;
+                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                       goto __RETURN;
                                                }
 
                                                msgInfo.displayTime = mktime(&displayTime);
@@ -1079,12 +819,14 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
 
                                                                if (MsgCreateFileName(fileName) == false) {
                                                                        vmsg_free_vtree_memory(vMsg);
-                                                                       return MSG_ERR_STORAGE_ERROR;
+                                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                                       goto __RETURN;
                                                                }
 
                                                                if (MsgWriteIpcFile(fileName, pObject->pszValue[0], pObject->numOfBiData) == false) {
                                                                        vmsg_free_vtree_memory(vMsg);
-                                                                       return MSG_ERR_STORAGE_ERROR;
+                                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                                       goto __RETURN;
                                                                }
 
                                                                strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
@@ -1101,6 +843,7 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                        }
                                                } else {
                                                        msgInfo.bTextSms = true;
+#if 0
                                                        if(msgInfo.msgType.subType == MSG_NOTIFICATIONIND_MMS) {
 
                                                                        msgInfo.bTextSms = true;
@@ -1138,7 +881,7 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                                        vmsg_free_vtree_memory(vMsg);
                                                                        return MSG_ERR_STORAGE_ERROR;
                                                                }
-                                                               MSG_DEBUG("fileName: %s, retrievedFilePath: %s (%d)", fileName, retrievedFilePath, strlen(retrievedFilePath));
+                                                               MSG_SEC_DEBUG("fileName: %s, retrievedFilePath: %s (%d)", fileName, retrievedFilePath, strlen(retrievedFilePath));
 
                                                                if (MsgWriteIpcFile(fileName, retrievedFilePath, strlen(retrievedFilePath)+ 1) == false) {
                                                                        vmsg_free_vtree_memory(vMsg);
@@ -1151,18 +894,57 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                                                                        return vmsg_free_vtree_memory(vMsg);
 ///////////////////////////
                                                        }
+#else
+
+                                                       msgInfo.bTextSms = false;
+
+                                                       char fileName[MAX_COMMON_INFO_SIZE+1];
+                                                       memset(fileName, 0x00, sizeof(fileName));
+
+                                                       if (MsgCreateFileName(fileName) == false) {
+                                                               vmsg_free_vtree_memory(vMsg);
+                                                               err = MSG_ERR_STORAGE_ERROR;
+                                                               goto __RETURN;
+                                                       }
+
+                                                       if (MsgWriteIpcFile(fileName, pObject->pszValue[0], pObject->numOfBiData) == false) {
+                                                               vmsg_free_vtree_memory(vMsg);
+                                                               err = MSG_ERR_STORAGE_ERROR;
+                                                               goto __RETURN;
+                                                       }
+
+                                                       //set serialized mms data ipcfilename
+                                                       strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
+#endif
                                                }
                                        }
                                        break;
 
                                        case VCARD_TYPE_TEL :
                                        {
+                                               MSG_ADDRESS_INFO_S * addrInfo = NULL;
+
                                                msgInfo.nAddressCnt++;
 
+                                               if (msgInfo.addressList == NULL) {
+                                                       addrInfo = (MSG_ADDRESS_INFO_S *)calloc(1, sizeof(MSG_ADDRESS_INFO_S));
+                                               } else {
+                                                       addrInfo = (MSG_ADDRESS_INFO_S *)realloc(msgInfo.addressList, msgInfo.nAddressCnt * sizeof(MSG_ADDRESS_INFO_S));
+                                               }
+
+                                               if (addrInfo == NULL) {
+                                                       vmsg_free_vtree_memory(vMsg);
+                                                       err = MSG_ERR_STORAGE_ERROR;
+                                                       goto __RETURN;
+
+                                               }
+
+                                               msgInfo.addressList = addrInfo;
+
                                                msgInfo.addressList[msgInfo.nAddressCnt-1].addressType = MSG_ADDRESS_TYPE_PLMN;
                                                msgInfo.addressList[msgInfo.nAddressCnt-1].recipientType = MSG_RECIPIENTS_TYPE_TO;
-
                                                strncpy(msgInfo.addressList[msgInfo.nAddressCnt-1].addressVal, pObject->pszValue[0], MAX_ADDRESS_VAL_LEN);
+
                                        }
                                        break;
                                }
@@ -1193,40 +975,77 @@ msg_error_t MsgStoRestoreMessage(const char *filepath)
                if (msgInfo.msgType.mainType == MSG_MMS_TYPE)
                        MsgStoUpdateMms(&msgInfo);
 
+               if (msgIdList->nCount == 0) {
+                       msgIdList->msgIdList = (msg_message_id_t*)calloc(1, sizeof(msg_message_id_t));
+               } else {
+                       msg_message_id_t * msg_id_list;
+                       msg_id_list = (msg_message_id_t*)realloc(msgIdList->msgIdList, sizeof(msg_message_id_t)*(msgIdList->nCount+1));
+
+                       if (msg_id_list)
+                               msgIdList->msgIdList = msg_id_list;
+                       else {
+                               MSG_DEBUG("realloc failed");
+                               err = MSG_ERR_UNKNOWN;
+                               goto __RETURN;
+                       }
+               }
+
+               msgIdList->msgIdList[msgIdList->nCount] = msgInfo.msgId;
+               msgIdList->nCount++;
+
                vmsg_free_vtree_memory(vMsg);
 
                vMsg = NULL;
                pCurrent = pTemp + strlen("END:VMSG");
        }
 
-       return MSG_SUCCESS;
+       if (result_id_list)
+               *result_id_list = msgIdList;
+__RETURN:
+       if(pData)
+       {
+               free( pData );
+               pData = NULL;
+               pCurrent = NULL;
+       }
+
+       return err;
 }
 
 msg_error_t MsgStoAddPushEvent(MSG_PUSH_EVENT_INFO_S* pPushEvent)
 {
-       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
        unsigned int rowId = 0;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
        // Check whether Same record exists or not.
+#if 0
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE CONTENT_TYPE LIKE '%s' AND APP_ID LIKE '%s' AND (PKG_NAME LIKE '%s' OR SECURE = 1);",
                        MSGFW_PUSH_CONFIG_TABLE_NAME, pPushEvent->contentType, pPushEvent->appId, pPushEvent->pkgName);
+#else
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE CONTENT_TYPE LIKE '%s' AND APP_ID LIKE '%s';",
+                       MSGFW_PUSH_CONFIG_TABLE_NAME, pPushEvent->contentType, pPushEvent->appId);
+#endif
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("Query Failed [%s]", sqlQuery);
                return MSG_ERR_DB_PREPARE;
        }
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               dbHandle.finalizeQuery();
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_ROW;
        }
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
+
+       dbHandle->beginTrans();
+
+       if (dbHandle->getRowId(MSGFW_PUSH_CONFIG_TABLE_NAME, &rowId) != MSG_SUCCESS) {
+               MSG_DEBUG("getRowId is failed!!!");
+       }
 
-       dbHandle.beginTrans();
-       err = dbHandle.getRowId(MSGFW_PUSH_CONFIG_TABLE_NAME, &rowId);
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
        snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, ?, ?, ?, %d, 0, 0);",
@@ -1235,23 +1054,23 @@ msg_error_t MsgStoAddPushEvent(MSG_PUSH_EVENT_INFO_S* pPushEvent)
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.bindText(pPushEvent->contentType, 1);
-       dbHandle.bindText(pPushEvent->appId, 2);
-       dbHandle.bindText(pPushEvent->pkgName, 3);
+       dbHandle->bindText(pPushEvent->contentType, 1);
+       dbHandle->bindText(pPushEvent->appId, 2);
+       dbHandle->bindText(pPushEvent->pkgName, 3);
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.finalizeQuery();
-       dbHandle.endTrans(true);
+       dbHandle->finalizeQuery();
+       dbHandle->endTrans(true);
 
        return MSG_SUCCESS;
 }
@@ -1259,45 +1078,47 @@ msg_error_t MsgStoAddPushEvent(MSG_PUSH_EVENT_INFO_S* pPushEvent)
 
 msg_error_t MsgStoDeletePushEvent(MSG_PUSH_EVENT_INFO_S* pPushEvent)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE CONTENT_TYPE LIKE '%s' AND APP_ID LIKE '%s' AND PKG_NAME LIKE '%s';",
                        MSGFW_PUSH_CONFIG_TABLE_NAME, pPushEvent->contentType, pPushEvent->appId, pPushEvent->pkgName);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
        return MSG_SUCCESS;
 }
 
 msg_error_t MsgStoUpdatePushEvent(MSG_PUSH_EVENT_INFO_S* pSrc, MSG_PUSH_EVENT_INFO_S* pDst)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONTENT_TYPE = ?, APP_ID = ?, PKG_NAME = ?, LAUNCH = %d WHERE CONTENT_TYPE LIKE '%s' AND APP_ID LIKE '%s' AND PKG_NAME LIKE '%s';",
                        MSGFW_PUSH_CONFIG_TABLE_NAME, pDst->bLaunch, pSrc->contentType, pSrc->appId, pSrc->pkgName);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.bindText(pDst->contentType, 1);
-       dbHandle.bindText(pDst->appId, 2);
-       dbHandle.bindText(pDst->pkgName, 3);
+       dbHandle->bindText(pDst->contentType, 1);
+       dbHandle->bindText(pDst->appId, 2);
+       dbHandle->bindText(pDst->pkgName, 3);
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.finalizeQuery();
-       dbHandle.endTrans(true);
+       dbHandle->finalizeQuery();
+       dbHandle->endTrans(true);
 
        return MSG_SUCCESS;
 }
index 834ce08..bb10251 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -35,6 +35,8 @@
 #include "MsgStorageHandler.h"
 #include "MsgNotificationWrapper.h"
 #include "MsgMmsMessage.h"
+#include "MsgDevicedWrapper.h"
+
 
 using namespace std;
 
@@ -42,7 +44,6 @@ using namespace std;
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
 
 Mutex delNotiMx;
 CndVar delNoticv;
@@ -56,17 +57,11 @@ bool delLogRunning = false;
 /*==================================================================================================
                                      FUNCTION FOR THREAD
 ==================================================================================================*/
-static gboolean updateUnreadMsgCount(void *pVoid)
+static gboolean resetNotification(void *pVoid)
 {
        MSG_BEGIN();
 
-       int smsCnt = 0;
-       int mmsCnt = 0;
-
-       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-       MsgSettingSetIndicator(smsCnt, mmsCnt);
+       MsgRefreshAllNotification(true, false, false);
 
        MSG_END();
 
@@ -77,6 +72,7 @@ static gboolean updateUnreadMsgCount(void *pVoid)
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
+
 msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
 {
        MSG_BEGIN();
@@ -88,114 +84,217 @@ msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pS
 
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       dbHandle.beginTrans();
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       dbHandle->beginTrans();
 
        if (pMsg->nAddressCnt > 0) {
-               err = MsgStoAddAddress(&dbHandle, pMsg, &convId);
+               err = MsgStoAddAddress(dbHandle, pMsg, &convId);
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
 
                pMsg->threadId = convId;
        }
 
-       err = dbHandle.getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
-
-       if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return err;
+       if (pMsg->msgId > 0) {
+               rowId = pMsg->msgId;
+       } else {
+               // get rowId
+               err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
+               if (err != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return err;
+               }
+               pMsg->msgId = (msg_message_id_t)rowId;
        }
 
-       pMsg->msgId = (msg_message_id_t)rowId;
-
        int fileSize = 0;
+       gchar *contents = NULL;
 
        char *pFileData = NULL;
        AutoPtr<char> buf(&pFileData);
 
-       // Get File Data
-       if (pMsg->bTextSms == false) {
-               if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
-                       dbHandle.endTrans(false);
-                       return MSG_ERR_STORAGE_ERROR;
-               }
-               MSG_DEBUG("file size [%d]", fileSize);
-       }
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       sprintf(keyName, "%s/%d", MSG_SIM_IMSI, pMsg->sim_idx);
+
+       char *imsi = MsgSettingGetString(keyName);
 
        // Add Message
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %ld, %d, %d, %d, %d, %d, %d, %ld, %d, ?, ?, ?, ?, 0);",
+       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');",
                        MSGFW_MESSAGE_TABLE_NAME, rowId, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
-                       pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
-                       0, pMsg->bBackup);
+                       (unsigned int)pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
+                       0, pMsg->bBackup, pMsg->sim_idx, imsi);
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       g_free(imsi);
+       imsi = NULL;
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.bindText(pMsg->subject, 1);
+       dbHandle->bindText(pMsg->subject, 1);
 
-       dbHandle.bindText(pMsg->msgData, 2);
+       if (pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
+               dbHandle->bindText("", 2);
+       } else {
+               if (pMsg->bTextSms == false) {
+                       //CID 47860: pMsg->msgData is an array, hence null check is not required
+                       char fn[MSG_FILEPATH_LEN_MAX];
+                       memset(fn,0x00,MSG_FILEPATH_LEN_MAX);
+                       snprintf(fn, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_IPC_DATA_PATH, pMsg->msgData);
+
+                       if (g_file_get_contents(fn, &contents, NULL, NULL)) {
+                               MSG_DEBUG("g_file_get_contents() Success!!");
+                               dbHandle->bindText(contents, 2);
+                       } else {
+                               MSG_DEBUG("g_file_get_contents() Failed!!");
+                               dbHandle->bindText("", 2);
+                       }
 
-       dbHandle.bindText(pMsg->thumbPath, 3);
+               } else
+                       dbHandle->bindText(pMsg->msgText, 2);
+       }
 
-       if (pMsg->bTextSms == false)
-               dbHandle.bindText(pFileData, 4);
-       else
-               dbHandle.bindText(pMsg->msgText, 4);
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
+               //free contents
+               if (contents) {
+                       g_free(contents);
+                       contents = NULL;
+               }
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
+
+       //free contents
+       if (contents) {
+               g_free(contents);
+               contents = NULL;
+       }
 
        if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
-               err = MsgStoUpdateConversation(&dbHandle, convId);
+               err = MsgStoUpdateConversation(dbHandle, convId);
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
        }
 
+#if 0
        /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
        if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
-               MMS_MESSAGE_DATA_S mmsMsg;
-               memset(&mmsMsg, 0x00, sizeof(MMS_MESSAGE_DATA_S));
 
                if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
+
                        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
 
+                       if (pFileData == NULL) {
+                               if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
+                                       dbHandle->endTrans(false);
+                                       return MSG_ERR_STORAGE_ERROR;
+                               }
+
+                               MSG_DEBUG("file size [%d]", fileSize);
+                       }
+
                        err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
 
                        if (err != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
+                               dbHandle->endTrans(false);
                                return MSG_ERR_STORAGE_ERROR;
                        }
 
-                       if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
+                       if (pMsg->msgType.subType == MSG_SENDREQ_MMS
+                                       || pMsg->msgType.subType == MSG_RETRIEVE_MMS
+                                       || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
+                                       || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
+
                                MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
 
                                err = MsgStoUpdateMMSMessage(pMsg);
 
                                if (err != MSG_SUCCESS) {
-                                       dbHandle.endTrans(false);
+                                       dbHandle->endTrans(false);
                                        return MSG_ERR_STORAGE_ERROR;
                                }
+
                        }
                }
+       } else if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
+               MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
+               if (plg) err = plg->addMessage(pMsg, pSendOptInfo, NULL);
+               if (err != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_STORAGE_ERROR;
+               }
        }
+#else
+       if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
+               char *pMmsSerializedData = NULL;
+               AutoPtr<char> buf_mms(&pMmsSerializedData);
+
+               if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
+
+                       MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
+
+                       if (pMmsSerializedData == NULL) {
+                               if (MsgOpenAndReadFile(pMsg->msgData, &pMmsSerializedData, &fileSize) == false) {
+                                       dbHandle->endTrans(false);
+                                       return MSG_ERR_STORAGE_ERROR;
+                               }
+
+                               MSG_DEBUG("file size [%d]", fileSize);
+                       }
+
+                       err = plg->addMessage(pMsg, pSendOptInfo, pMmsSerializedData);
+
+                       if (err != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
+                               return MSG_ERR_STORAGE_ERROR;
+                       }
+
+//                     if (pMsg->msgText[0] != '\0') {
+//                             g_file_get_contents(pMsg->msgText, &pFileData, (gsize *)&fileSize, NULL);
+//                             MSG_DEBUG("file size [%d]", fileSize);
+//                     }
+
+                       if (pMsg->msgType.subType == MSG_SENDREQ_MMS
+                               || pMsg->msgType.subType == MSG_RETRIEVE_MMS
+                               || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
+                               || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)
+                       {
+                               MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
+
+                               err = MsgStoUpdateMMSMessage(pMsg);
+                       }
+
+               }
+       } else {
 
-       dbHandle.endTrans(true);
+               // Get File Data
+               if (pMsg->bTextSms == false) {
+                       if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
+                               dbHandle->endTrans(false);
+                               return MSG_ERR_STORAGE_ERROR;
+                       }
+                       MSG_DEBUG("file size [%d]", fileSize);
+               }
+       }
+#endif
+       dbHandle->endTrans(true);
 
        MSG_END();
 
@@ -210,8 +309,8 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
        char sqlQuery[MAX_QUERY_LEN+1];
 
        msg_thread_id_t convId = 0;
-
-       dbHandle.beginTrans();
+       MsgDbHandler *dbHandle = getDbHandle();
+       dbHandle->beginTrans();
 
        MSG_MAIN_TYPE_T prevType;
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -220,19 +319,19 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_PREPARE;
        }
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_ROW) {
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
+       if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       prevType = dbHandle.columnInt(0);
-       dbHandle.finalizeQuery();
+       prevType = dbHandle->columnInt(0);
+       dbHandle->finalizeQuery();
 
        //check msg type with previous type
        if (prevType != pMsg->msgType.mainType) {
@@ -240,25 +339,26 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
 
                err = MsgStoDeleteMessage(pMsg->msgId, false);
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
 
                err = MsgStoAddMessage(pMsg, pSendOptInfo);
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
 
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return err;
        }
 
        if (pMsg->nAddressCnt > 0) {
-               err = MsgStoAddAddress(&dbHandle, pMsg, &convId);
+               pMsg->threadId = 0;
+               err = MsgStoAddAddress(dbHandle, pMsg, &convId);
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
        }
@@ -271,7 +371,7 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
        // Get File Data
        if (pMsg->bTextSms == false) {
                if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return MSG_ERR_STORAGE_ERROR;
                }
        }
@@ -309,48 +409,51 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
 
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
                        DISPLAY_TIME = %lu, DATA_SIZE = %d, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
-                       BACKUP = %d, SUBJECT = ?, MSG_DATA = ?, THUMB_PATH = ?, MSG_TEXT = ? \
+                       BACKUP = %d, SUBJECT = ?, MSG_TEXT = ? \
                        WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
                        pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.bindText(pMsg->subject, 1);
-
-       dbHandle.bindText(pMsg->msgData, 2);
-
-       dbHandle.bindText(pMsg->thumbPath, 3);
+       dbHandle->bindText(pMsg->subject, 1);
 
        if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
-               dbHandle.bindText(pFileData, 4);
+               dbHandle->bindText(pFileData, 2);
        else
-               dbHandle.bindText(pMsg->msgText, 4);
+               dbHandle->bindText(pMsg->msgText, 2);
 
        MSG_DEBUG("%s", sqlQuery);
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL) {
                if (pSendOptInfo->bSetting == true) {
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET \
-                                       DELREP_REQ = %d, KEEP_COPY = %d, REPLY_PATH = %d \
-                                       WHERE MSG_ID = %d;",
-                                       MSGFW_SMS_SENDOPT_TABLE_NAME, pSendOptInfo->bDeliverReq,
-                                       pSendOptInfo->bKeepCopy, pSendOptInfo->option.smsSendOptInfo.bReplyPath, pMsg->msgId);
-
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
+                       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
+                                       "DELREP_REQ = %d, "
+                                       "KEEP_COPY = %d, "
+                                       "REPLY_PATH = %d, "
+                                       "ENCODE_TYPE = %d "
+                                       "WHERE MSG_ID = %d;",
+                                       MSGFW_SMS_SENDOPT_TABLE_NAME,
+                                       pSendOptInfo->bDeliverReq,
+                                       pSendOptInfo->bKeepCopy,
+                                       pSendOptInfo->option.smsSendOptInfo.bReplyPath,
+                                       pMsg->encodeType,
+                                       pMsg->msgId);
+
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
                                return MSG_ERR_DB_EXEC;
                        }
                }
@@ -360,7 +463,7 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
                err = plg->updateMessage(pMsg, pSendOptInfo, pFileData);
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return MSG_ERR_STORAGE_ERROR;
                }
 
@@ -375,21 +478,21 @@ msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S
                }
        }
 
-       err = MsgStoUpdateConversation(&dbHandle, convId);
+       err = MsgStoUpdateConversation(dbHandle, convId);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       err = MsgStoClearConversationTable(&dbHandle);
+       err = MsgStoClearConversationTable(dbHandle);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        return MSG_SUCCESS;
 }
@@ -401,30 +504,34 @@ msg_error_t MsgStoUpdateReadStatus(msg_message_id_t msgId, bool bRead)
 
        msg_storage_id_t storageId;
 
-       if (MsgStoSetReadStatus(&dbHandle, msgId, bRead) != MSG_SUCCESS) {
+       MsgDbHandler *dbHandle = getDbHandle();
+       if (MsgStoSetReadStatus(dbHandle, msgId, bRead) != MSG_SUCCESS) {
                MSG_DEBUG("MsgStoSetReadStatus() Error");
                return MSG_ERR_STORAGE_ERROR;
        }
 
+       MsgRefreshAllNotification(true, false, false);
+
        // Get STORAGE_ID
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               storageId = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               storageId = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        MSG_DEBUG("StorageId:[%d]", storageId);
 
+
        // Update Read Status for SIM Msg
        if (storageId == MSG_STORAGE_SIM) {
                MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
@@ -436,80 +543,100 @@ msg_error_t MsgStoUpdateReadStatus(msg_message_id_t msgId, bool bRead)
 
                // Get SIM Msg ID
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_ID FROM %s WHERE MSG_ID = %d;",
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
                                MSGFW_SIM_MSG_TABLE_NAME, msgId);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_PREPARE;
 
                msg_sim_id_t simId;
+               msg_sim_slot_id_t sim_idx;
 
-               while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-                       simId = dbHandle.columnInt(0);
+               while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       sim_idx = dbHandle->columnInt(0);
+                       simId = dbHandle->columnInt(1);
 
-                       if (plg->setReadStatus(simId) != MSG_SUCCESS) {
+                       if (plg->setReadStatus(sim_idx, simId) != MSG_SUCCESS) {
                                MSG_DEBUG("Fail to Set Read Status for SIM SMS");
                                continue;
                        }
                }
-
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
        }
 
        return MSG_SUCCESS;
 }
 
 
-msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId)
+msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId, msg_id_list_s *pMsgIdList)
 {
        MSG_BEGIN();
 
        msg_error_t err = MSG_SUCCESS;
 
-       int rowCnt = 0;
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       // Get sim MSG_ID
+       /*** Get msg id list **/
+       int rowCnt = 0;
+       int index = 1;
+       pMsgIdList->nCount = 0;
+       MsgDbHandler *dbHandle = getDbHandle();
+
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s A \
-                       WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d;",
-                       MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_STORAGE_SIM);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s "
+                       "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
+                       MSGFW_MESSAGE_TABLE_NAME,
+                       threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
 
-       rowCnt = 0;
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
                return err;
        }
 
-       for (int i = 1; i <= rowCnt; i++) {
-               MsgStoUpdateReadStatus(dbHandle.getColumnToInt(i), true);
+       if (rowCnt <= 0) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
        }
 
-       dbHandle.freeTable();
+       pMsgIdList->nCount = rowCnt;
+       MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
+
+       pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
+
+       for (int i = 0; i < rowCnt; i++)
+               pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
+
+       dbHandle->freeTable();
+       /*** **/
 
        // set read status
+       dbHandle->beginTrans();
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_STATUS = %d \
-                       WHERE CONV_ID = %d AND READ_STATUS = 0;",
-                       MSGFW_MESSAGE_TABLE_NAME, 1, threadId);
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_STATUS = %d "
+                       "WHERE CONV_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d AND FOLDER_ID < %d;",
+                       MSGFW_MESSAGE_TABLE_NAME, 1,
+                       threadId, MSG_STORAGE_PHONE, MSG_SPAMBOX_ID);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
+       }
 
 
-       if (MsgStoUpdateConversation(&dbHandle, threadId) != MSG_SUCCESS) {
+       if (MsgStoUpdateConversation(dbHandle, threadId) != MSG_SUCCESS) {
                MSG_DEBUG("MsgStoUpdateConversation() Error");
+               dbHandle->endTrans(false);
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       if (g_idle_add(updateUnreadMsgCount, NULL) == 0) {
-               MSG_DEBUG("updateUnreadMsgCount() Error");
+       dbHandle->endTrans(true);
+       if (g_idle_add(resetNotification, NULL) == 0) {
+               MSG_DEBUG("resetNotification() Error");
        }
 
-       MsgRefreshNoti(false);
-
        MSG_END();
 
        return MSG_SUCCESS;
@@ -519,12 +646,29 @@ msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t threadId)
 msg_error_t MsgStoUpdateProtectedStatus(msg_message_id_t msgId, bool bProtected)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET PROTECTED = %d WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, (int)bProtected, msgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_EXEC;
+
+       return MSG_SUCCESS;
+}
+
+msg_error_t MsgStoUpdateConversationTagType(msg_thread_id_t threadId, int tagType)
+{
+       char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET TAG_TYPE = %d WHERE CONV_ID = %d;",
+                       MSGFW_CONVERSATION_TABLE_NAME, (int)tagType, threadId);
+       MSG_DEBUG("Updated tag = %d and conv_id = %d", tagType,threadId);
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -540,13 +684,37 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       // delete report notification
+       char tempAddr[MAX_ADDRESS_VAL_LEN+1];
+       memset(tempAddr, 0x00, sizeof(tempAddr));
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       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;"
+                       , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, msgId);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
+
+       if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
+               dbHandle->finalizeQuery();
+               return MSG_ERR_DB_DONE;
+       }
+
+       snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
+
+       MSG_DEBUG("Updated address = %s", tempAddr);
+
+       MsgDeleteReportNotification(tempAddr);
+
+       dbHandle->finalizeQuery();
 
        // Get SUB_TYPE, STORAGE_ID
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, STORAGE_ID, READ_STATUS, CONV_ID \
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, STORAGE_ID, READ_STATUS, CONV_ID, SIM_INDEX \
                        FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("Query Failed [%s]", sqlQuery);
                return MSG_ERR_DB_PREPARE;
        }
@@ -555,26 +723,28 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
        msg_folder_id_t folderId;
        msg_storage_id_t storageId;
        msg_thread_id_t convId;
+       msg_sim_slot_id_t simIndex;
        bool bRead;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               msgType.mainType = dbHandle.columnInt(0);
-               msgType.subType = dbHandle.columnInt(1);
-               folderId = dbHandle.columnInt(2);
-               storageId = dbHandle.columnInt(3);
-               bRead = dbHandle.columnInt(4);
-               convId = dbHandle.columnInt(5);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               msgType.mainType = dbHandle->columnInt(0);
+               msgType.subType = dbHandle->columnInt(1);
+               folderId = dbHandle->columnInt(2);
+               storageId = dbHandle->columnInt(3);
+               bRead = dbHandle->columnInt(4);
+               convId = dbHandle->columnInt(5);
+               simIndex = dbHandle->columnInt(6);
 
-               MSG_DEBUG("Main Type:[%d] SubType:[%d] FolderId:[%d] StorageId:[%d] ConversationId:[%d]", msgType.mainType, msgType.subType, folderId, storageId, convId);
+               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);
        } else {
                MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
 
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
 
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
 
@@ -584,49 +754,57 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                return MSG_ERR_NULL_POINTER;
        }
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
 
        // Check sim message
        if (storageId == MSG_STORAGE_SIM) {
-               // get sim message id
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_ID FROM %s WHERE MSG_ID = %d;",
-                               MSGFW_SIM_MSG_TABLE_NAME, msgId);
+               msg_sim_id_t simMsgId;
+               msg_sim_slot_id_t sim_idx;
+
+               while (true) {
+                       // get sim message id
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
+                                       MSGFW_SIM_MSG_TABLE_NAME, msgId);
 
-               MSG_DEBUG("sqlQuery is [%s]", sqlQuery);
+                       MSG_DEBUG("sqlQuery is [%s]", sqlQuery);
 
-               msg_sim_id_t simMsgId;
+                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
+                               return MSG_ERR_DB_PREPARE;
+                       }
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       return MSG_ERR_DB_PREPARE;
-               }
+                       if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
+                               break;
+                       }
 
-               while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-                       simMsgId = dbHandle.columnInt(0);
+                       sim_idx = dbHandle->columnInt(0);
+                       simMsgId = dbHandle->columnInt(1);
 
                        MSG_DEBUG("SIM Msg Id : [%d]", simMsgId);
 
-                       err = plg->deleteSimMessage(simMsgId);
+                       err = plg->deleteSimMessage(sim_idx, simMsgId);
 
                        if (err != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
                                return err;
                        }
 
+                       dbHandle->finalizeQuery();
+
                        //Sim message delete in db table
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d;", MSGFW_SIM_MSG_TABLE_NAME, simMsgId);
+                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID =%d;", MSGFW_SIM_MSG_TABLE_NAME, simMsgId, sim_idx);
 
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
                                return MSG_ERR_DB_EXEC;
                        }
                }
 
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
        }
 
        /* each type has to be handled in plug in ? */
@@ -636,8 +814,18 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
 
                // Delete SMS Send Option
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
+                               MSGFW_SMS_REPORT_TABLE_NAME, msgId);
+
+               // Delete Data from SMS_REPORT table
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
 
@@ -647,8 +835,8 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                        MSGFW_CB_MSG_TABLE_NAME, msgId);
 
                        // Delete Push Message from push table
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
                                return MSG_ERR_DB_EXEC;
                        }
                } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
@@ -657,8 +845,8 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                        MSGFW_PUSH_MSG_TABLE_NAME, msgId);
 
                        // Delete Push Message from push table
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
                                return MSG_ERR_DB_EXEC;
                        }
                } else if (msgType.subType == MSG_SYNCML_CP) {
@@ -667,34 +855,66 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                        MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
 
                        // Delete SyncML Message from syncML table
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
                                return MSG_ERR_DB_EXEC;
                        }
                }
        } else if (msgType.mainType == MSG_MMS_TYPE) {
 
-               char filePath[MSG_FILEPATH_LEN_MAX+1] = {0,};
-               char dirPath[MSG_FILEPATH_LEN_MAX+1]= {0,};
+               char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0,};
+               char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0,};
+
+               {//remove multipart
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
+                                       MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
+
+                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
+                               return MSG_ERR_DB_PREPARE;
+                       }
+
+                       while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                               memset(filePath, 0x00, sizeof(filePath));
+                               strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
+                               if (remove(filePath) == -1)
+                                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
+                               else
+                                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
+                       }
+                       dbHandle->finalizeQuery();
+
+                       // Delete Data from Multipart table
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
+                                       MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
+
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
+                               return MSG_ERR_DB_EXEC;
+                       }
+               }
+
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
                                MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_PREPARE;
                }
 
-               if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-                       strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+               if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
 
                        snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
 
                        if (remove(filePath) == -1)
-                               MSG_DEBUG("Fail to delete file [%s]", filePath);
+                               MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                        else
-                               MSG_DEBUG("Success to delete file [%s]", filePath);
+                               MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
 
                        MsgRmRf(dirPath);
 
@@ -702,12 +922,12 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
 
                } else {
                        MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
-                       dbHandle.finalizeQuery();
-                       dbHandle.endTrans(false);
+                       dbHandle->finalizeQuery();
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_STEP;
                }
 
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
 
                // remove thumbnail file
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -716,28 +936,28 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
                                MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_PREPARE;
                }
 
-               while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+               while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
                        memset(filePath, 0x00, sizeof(filePath));
-                       strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+                       strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
                        if (remove(filePath) == -1)
-                               MSG_DEBUG("Fail to delete file [%s]", filePath);
+                               MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                        else
-                               MSG_DEBUG("Success to delete file [%s]", filePath);
+                               MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
                }
 
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
                                MSGFW_MMS_PREVIEW_TABLE_NAME, msgId);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
 
@@ -746,8 +966,8 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
                // Delete Data from MMS table
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
 
@@ -756,8 +976,8 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                                MSGFW_REPORT_TABLE_NAME, msgId);
 
                // Delete Data from MMS STATUS table
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
        }
@@ -766,49 +986,40 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
 
        // Delete Message from msg table
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
        if (convId > 0) {
                // Clear Conversation table
-               if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
 
                // Update conversation table.
-               if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_STORAGE_ERROR;
                }
        }
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        if (msgType.mainType == MSG_SMS_TYPE && folderId == MSG_INBOX_ID) {
                msgType.classType = MSG_CLASS_NONE;
 
                // Set memory status in SIM
-               if (MsgStoCheckMsgCntFull(&dbHandle, &msgType, folderId) == MSG_SUCCESS) {
+               if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId, simIndex) == MSG_SUCCESS) {
                        MSG_DEBUG("Set Memory Status");
 
-                       plg->setMemoryStatus(MSG_SUCCESS);
+                       plg->setMemoryStatus(simIndex, MSG_SUCCESS);
                }
        }
 
        if (bCheckIndication == true) {
                MSG_DEBUG("bCheckIndication is true.");
-
-               int smsCnt = 0;
-               int mmsCnt = 0;
-
-               smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-               mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-               MsgSettingSetIndicator(smsCnt, mmsCnt);
-
-               MsgRefreshNoti(false);
+               MsgRefreshAllNotification(true, false, false);
        }
 
        return MSG_SUCCESS;
@@ -830,6 +1041,7 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
 
        int listCnt = sizeof(tableList)/sizeof(char *);
        int rowCnt = 0;
+       MsgDbHandler *dbHandle = getDbHandle();
 
        // Get conversation ID from Folder
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -837,27 +1049,25 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE FOLDER_ID = %d",
                        MSGFW_MESSAGE_TABLE_NAME, folderId);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               MSG_DEBUG("sql query is %s.", sqlQuery);
-
-               dbHandle.freeTable();
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
                return err;
        }
 
        if (rowCnt <= 0) {
-               dbHandle.freeTable();
-
+               dbHandle->freeTable();
                return MSG_SUCCESS;
        }
 
        for (int i = 1; i <= rowCnt; i++) {
-               MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
-               threadList.push((msg_thread_id_t)dbHandle.getColumnToInt(i));
+               MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
+               threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
        }
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        /*** Get msg id list **/
        msg_id_list_s *pToDeleteMsgIdList = NULL;
@@ -875,18 +1085,16 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
        rowCnt = 0;
        int index = 1;
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-
-               dbHandle.freeTable();
-
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
                goto FREE_MEMORY;
        }
 
        if (rowCnt <= 0) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                err = MSG_SUCCESS;
 
                goto FREE_MEMORY;
@@ -899,9 +1107,9 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
        pToDeleteMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
 
        for (int i = 0; i < rowCnt; i++)
-               pToDeleteMsgIdList->msgIdList[i] = dbHandle.getColumnToInt(index++);
+               pToDeleteMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
        /*** **/
 
        /*** Delete Sim Message In Folder **/
@@ -911,37 +1119,33 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
                snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d AND STORAGE_ID = %d",
                                MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_SIM);
 
-               MSG_DEBUG("sql query is %s.", sqlQuery);
-
                rowCnt = 0;
 
-               err = dbHandle.getTable(sqlQuery, &rowCnt);
-
+               err = dbHandle->getTable(sqlQuery, &rowCnt);
                if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-                       dbHandle.freeTable();
-
+                       dbHandle->freeTable();
                        goto FREE_MEMORY;
                }
 
                for (int i = 1; i <= rowCnt; i++) {
-                       err = MsgStoDeleteMessage(dbHandle.getColumnToInt(i), false);
+                       err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
 
                        if (err != MSG_SUCCESS) {
                                MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
 
-                               dbHandle.freeTable();
+                               dbHandle->freeTable();
 
                                goto FREE_MEMORY;
                        }
 
                        //Delete phone log
-//                     MsgDeletePhoneLog(dbHandle.getColumnToInt(i));
+//                     MsgDeletePhoneLog(dbHandle->getColumnToInt(i));
                }
 
-               dbHandle.freeTable();
+               dbHandle->freeTable();
        }
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
 
        for (int i = 0; i < listCnt; i++) {
                if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
@@ -951,22 +1155,51 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
                        char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
                        char dirPath[MSG_FILEPATH_LEN_MAX] = {0,};
 
+                       {//remove multipart
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s;",
+                                               MSGFW_MMS_MULTIPART_TABLE_NAME);
+
+                               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
+                                       return MSG_ERR_DB_PREPARE;
+                               }
+
+                               while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                                       memset(filePath, 0x00, sizeof(filePath));
+                                       strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
+                                       if (remove(filePath) == -1)
+                                               MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
+                                       else
+                                               MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
+                               }
+                               dbHandle->finalizeQuery();
+
+                               // Delete Data from Multipart table
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;",
+                                               MSGFW_MMS_MULTIPART_TABLE_NAME);
+
+                               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                                       err = MSG_ERR_DB_EXEC;
+                                       goto FREE_MEMORY;
+                               }
+                       }
+
                        //get mms msg id list
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
                        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.FILE_PATH FROM %s A, %s B \
                                        WHERE A.FOLDER_ID = %d AND A.MAIN_TYPE = %d AND A.MSG_ID = B.MSG_ID",
                                        MSGFW_MESSAGE_TABLE_NAME, MMS_PLUGIN_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
 
-                       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-
-                       err = dbHandle.getTable(sqlQuery, &rowCnt);
+                       err = dbHandle->getTable(sqlQuery, &rowCnt);
                        MSG_DEBUG("rowCnt %d", rowCnt);
 
                        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+                               MSG_DEBUG("Fail to getTable().");
 
-                               dbHandle.freeTable();
-                               dbHandle.endTrans(false);
+                               dbHandle->freeTable();
+                               dbHandle->endTrans(false);
 
                                goto FREE_MEMORY;
                        }
@@ -974,17 +1207,17 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
                        for (int i = 1; i <= rowCnt; i++) {
 
                                memset(filePath, 0x00, sizeof(filePath));
-                               dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
+                               dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
 
-                               MSG_DEBUG("filePath [%s]", filePath);
+                               MSG_SEC_DEBUG("filePath [%s]", filePath);
 
                                //delete raw file
                                snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
 
                                if (remove(filePath) == -1)
-                                       MSG_DEBUG("Fail to delete file [%s]", filePath);
+                                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                                else
-                                       MSG_DEBUG("Success to delete file [%s]", filePath);
+                                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
 
                                MsgRmRf(dirPath);
 
@@ -992,7 +1225,7 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
 
                        }
 
-                       dbHandle.freeTable();
+                       dbHandle->freeTable();
                }
 
                // delete thumbnail
@@ -1004,21 +1237,21 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
                                "AND (MSG_ID IN (SELECT MSG_ID FROM %s WHERE FOLDER_ID = %d));",
                                MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_MESSAGE_TABLE_NAME, folderId);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_PREPARE;
                }
 
-               while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+               while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
                        memset(filePath, 0x00, sizeof(filePath));
-                       strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+                       strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
                        if (remove(filePath) == -1)
-                               MSG_DEBUG("Fail to delete file [%s]", filePath);
+                               MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                        else
-                               MSG_DEBUG("Success to delete file [%s]", filePath);
+                               MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
                }
 
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -1027,9 +1260,9 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
                                tableList[i], MSGFW_MESSAGE_TABLE_NAME, folderId);
 
                // Delete Message in specific folder from table
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                        MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        err = MSG_ERR_DB_EXEC;
 
                        goto FREE_MEMORY;
@@ -1037,8 +1270,8 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
        }
 
        // Clear Conversation table
-       if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                err = MSG_ERR_DB_EXEC;
 
                goto FREE_MEMORY;
@@ -1046,28 +1279,18 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
 
        // Update Address
        while (!threadList.empty()) {
-               err = MsgStoUpdateConversation(&dbHandle, threadList.front());
+               err = MsgStoUpdateConversation(dbHandle, threadList.front());
 
                threadList.pop();
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
 
                        goto FREE_MEMORY;
                }
        }
 
-       dbHandle.endTrans(true);
-
-       if (folderId == MSG_INBOX_ID) {
-               int smsCnt = 0;
-               int mmsCnt = 0;
-
-               smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-               mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-               MsgSettingSetIndicator(smsCnt, mmsCnt);
-       }
+       dbHandle->endTrans(true);
 
 /*** Set pMsgIdList **/
        if (pMsgIdList != NULL && pToDeleteMsgIdList->nCount > 0) {
@@ -1094,7 +1317,7 @@ msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t folderId, bool bOnlyD
 //                             err = MSG_ERR_UNKNOWN;
 //                     }
 
-                       MsgRefreshNoti(false);
+                       MsgRefreshAllNotification(true, false, false);
                }
        }
 /*** **/
@@ -1125,6 +1348,8 @@ FREE_MEMORY:
 
 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
 {
+       std::string q;
+
        MSG_BEGIN();
 
        msg_error_t err = MSG_SUCCESS;
@@ -1133,110 +1358,145 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
                return err;
        }
 
-       MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
-
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       queue<msg_thread_id_t> threadList;
+       queue<msg_thread_id_t> threadList1, threadList2;
 
-       const char *tableList[] = {MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
+       const char *tableList[] = {MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MMS_PREVIEW_TABLE_NAME,
+                                               MSGFW_PUSH_MSG_TABLE_NAME, MSGFW_CB_MSG_TABLE_NAME,
                                                MSGFW_SYNCML_MSG_TABLE_NAME, MSGFW_SMS_SENDOPT_TABLE_NAME,
-                                               MSGFW_MMS_PREVIEW_TABLE_NAME, MSGFW_REPORT_TABLE_NAME,
-                                               MMS_PLUGIN_MESSAGE_TABLE_NAME,  MSGFW_MESSAGE_TABLE_NAME};
+                                               MSGFW_REPORT_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                               MSGFW_SMS_REPORT_TABLE_NAME, MSGFW_MMS_MULTIPART_TABLE_NAME};
 
        int listCnt = sizeof(tableList)/sizeof(char *);
        int rowCnt = 0;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       // Clear tmp table
+       dbHandle->beginTrans();
+       // reset msgid temp table
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
-       err = dbHandle.execQuery(sqlQuery);
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to execQuery().");
-               return err;
+       MSG_DEBUG("[%s]", sqlQuery);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_EXEC;
+
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               return MSG_ERR_DB_EXEC;
        }
-       // Insert tmp msg ids to delete.
-       dbHandle.beginTrans();
-       for (int i = 0; i < pMsgIdList->nCount; i++)
-       {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d);",
-                               MSGFW_TMP_MSGID_TABLE_NAME, pMsgIdList->msgIdList[i]);
-               err = dbHandle.execQuery(sqlQuery);
-               if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery().");
+
+       dbHandle->finalizeQuery();
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (?)", MSGFW_TMP_MSGID_TABLE_NAME);
+       MSG_DEBUG("[%s]", sqlQuery);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_PREPARE;
        }
-       err = dbHandle.endTrans(true);
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to endTrans(true).");
-               dbHandle.endTrans(false);
-               return err;
+
+       for (int i = 0; i < pMsgIdList->nCount; i++) {
+               dbHandle->resetQuery();
+               dbHandle->bindInt(pMsgIdList->msgIdList[i], 1);
+               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                       dbHandle->finalizeQuery();
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
        }
 
-       // Get conversation ID from Folder
+       dbHandle->finalizeQuery();
+       dbHandle->endTrans(true);
+
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
-                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN %s;", MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
                MSG_DEBUG("Fail to getTable().");
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return err;
        }
 
        MSG_DEBUG("rowCnt [%d]", rowCnt);
 
        if (rowCnt < 1) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return MSG_SUCCESS;
        }
 
        for (int i = 1; i <= rowCnt; i++) {
-               MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
-               threadList.push((msg_thread_id_t)dbHandle.getColumnToInt(i));
+               MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
+               threadList1.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
+               threadList2.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
        }
-       dbHandle.freeTable();
+       dbHandle->freeTable();
+
+       // delete report notification
+       char tempAddr[MAX_ADDRESS_VAL_LEN+1];
+       while (!threadList1.empty()) {
+               memset(tempAddr, 0x00, sizeof(tempAddr));
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               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;"
+                               , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadList1.front());
+
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                       return MSG_ERR_DB_PREPARE;
+
+               if (dbHandle->stepQuery() != MSG_ERR_DB_ROW) {
+                       dbHandle->finalizeQuery();
+                       return MSG_ERR_DB_DONE;
+               }
+
+               snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
+
+               MSG_DEBUG("Updated address = %s", tempAddr);
+
+               MsgDeleteReportNotification(tempAddr);
+
+               dbHandle->finalizeQuery();
+
+               threadList1.pop();
+       }
+
 
-       /*** Delete Sim Message In Folder **/
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN (SELECT MSG_ID FROM %s);",
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN %s;",
                        MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
 
        rowCnt = 0;
-
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
                MSG_DEBUG("Fail to getTable().");
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                rowCnt = 0;
        }
 
        for (int i = 1; i <= rowCnt; i++) {
-               err = MsgStoDeleteMessage(dbHandle.getColumnToInt(i), false);
+               err = MsgStoDeleteMessage(dbHandle->getColumnToInt(i), false);
                if (err != MSG_SUCCESS) {
                        MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
                }
        }
-       dbHandle.freeTable();
+       dbHandle->freeTable();
        /*** **/
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
        for (int i = 0; i < listCnt; i++) {
-               if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
+               if ( !i ) {
 
                        char filePath[MSG_FILEPATH_LEN_MAX];
                        char dirPath[MSG_FILEPATH_LEN_MAX];
 
                        rowCnt = 0;
 
-                       // MMS file path to delete.
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
-                                       MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
+                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
 
-                       err = dbHandle.getTable(sqlQuery, &rowCnt);
+                       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
                        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
                                MSG_DEBUG("Fail to getTable().");
@@ -1246,42 +1506,35 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
                        MSG_DEBUG("rowCnt %d", rowCnt);
 
                        for (int i = 1; i <= rowCnt; i++) {
-                               memset(filePath, 0x00, sizeof(filePath));
-                               memset(dirPath, 0x00, sizeof(dirPath));
-                               dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
+                               dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
 
-                               MSG_DEBUG("filePath [%s]", filePath);
+                               MSG_SEC_DEBUG("filePath [%s]", filePath);
 
                                // Delete raw file.
                                snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
 
                                if (remove(filePath) == -1)
-                                       MSG_DEBUG("Fail to delete file [%s]", filePath);
+                                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                                else
-                                       MSG_DEBUG("Success to delete file [%s]", filePath);
+                                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
 
                                MsgRmRf(dirPath);
 
                                rmdir(dirPath);
                        }
-                       dbHandle.freeTable();
+                       dbHandle->freeTable();
 
-               } else if (!strcmp(tableList[i], MSGFW_MMS_PREVIEW_TABLE_NAME)) {
+               } else if (i == 1) {
 
                        char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
 
                        rowCnt = 0;
 
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery),
-                                       "SELECT VALUE FROM %s "
-                                       "WHERE (TYPE=%d OR TYPE=%d) "
-                                       "AND MSG_ID IN (SELECT MSG_ID FROM %s);",
-                                       MSGFW_MMS_PREVIEW_TABLE_NAME,
-                                       MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO,
-                                       MSGFW_TMP_MSGID_TABLE_NAME);
+                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VALUE FROM %s WHERE (TYPE = %d OR TYPE = %d) AND MSG_ID IN %s;",
+                                       MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO, MSGFW_TMP_MSGID_TABLE_NAME);
 
-                       err = dbHandle.getTable(sqlQuery, &rowCnt);
+                       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
                        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
                                MSG_DEBUG("Fail to getTable().");
@@ -1292,58 +1545,100 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
 
                        for (int i = 1; i <= rowCnt; i++) {
                                memset(filePath, 0x00, sizeof(filePath));
-                               dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
+                               dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
                                if (remove(filePath) == -1)
-                                       MSG_DEBUG("Fail to delete file [%s]", filePath);
+                                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                                else
-                                       MSG_DEBUG("Success to delete file [%s]", filePath);
+                                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
                        }
-                       dbHandle.freeTable();
+                       dbHandle->freeTable();
+               } else if (!strcmp(tableList[i], MSGFW_MMS_MULTIPART_TABLE_NAME)) {
+                               // MMS file path to delete.
+                               char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
+
+                               rowCnt = 0;
+
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN %s;", MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
+
+                               err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+                               if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+                                       MSG_DEBUG("Fail to getTable().");
+                                       rowCnt = 0;
+                               }
+
+                               MSG_DEBUG("rowCnt %d", rowCnt);
+
+                               for (int i = 1; i <= rowCnt; i++) {
+                                       memset(filePath, 0x00, sizeof(filePath));
+                                       dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
+                                       if (filePath[0] != '\0') {
+                                               if (remove(filePath) == -1)
+                                                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
+                                               else
+                                                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
+                                       }
+                               }
+                               dbHandle->freeTable();
+
+                               // MMS thumbnail path to delete
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               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);
+
+                               err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+                               if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+                                       MSG_DEBUG("Fail to getTable().");
+                                       rowCnt = 0;
+                               }
+
+                               MSG_DEBUG("rowCnt %d", rowCnt);
+
+                               for (int i = 1; i <= rowCnt; i++) {
+                                       memset(filePath, 0x00, sizeof(filePath));
+                                       dbHandle->getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
+                                       if (filePath[0] != '\0') {
+                                               if (remove(filePath) == -1)
+                                                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
+                                               else
+                                                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
+                                       }
+                               }
+
+                               dbHandle->freeTable();
                }
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
-                               tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
+               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN %s;", tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
 
                // Delete Message in specific folder from table
-               err = dbHandle.execQuery(sqlQuery);
+               err = dbHandle->execQuery(sqlQuery);
                if (err != MSG_SUCCESS) {
                        MSG_DEBUG("Fail to execQuery().");
                }
        }
 
        // Clear Conversation table
-       err = MsgStoClearConversationTable(&dbHandle);
+       err = MsgStoClearConversationTable(dbHandle);
        if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
 
        // Update Address
-       while (!threadList.empty()) {
-               err = MsgStoUpdateConversation(&dbHandle, threadList.front());
+       while (!threadList2.empty()) {
+               err = MsgStoUpdateConversation(dbHandle, threadList2.front());
                if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
-               threadList.pop();
+               threadList2.pop();
        }
-       err = dbHandle.endTrans(true);
+       err = dbHandle->endTrans(true);
        if (err != MSG_SUCCESS) {
                MSG_DEBUG("Fail to endTrans(true).");
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return err;
        }
 
-       int smsCnt = 0;
-       int mmsCnt = 0;
-
-       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-       MsgSettingSetIndicator(smsCnt, mmsCnt);
-
-       MsgRefreshNoti(false);
-
-       // Clear tmp table
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
-       err = dbHandle.execQuery(sqlQuery);
-       if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery().");
+       if (g_idle_add(resetNotification, NULL) == 0) {
+               MSG_DEBUG("resetNotification() Error");
+       }
 
        MSG_END();
        return MSG_SUCCESS;
@@ -1359,6 +1654,7 @@ msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t de
        MsgStoGetMsgType(msgId, &msgType);
 
        char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -1367,7 +1663,7 @@ msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t de
        else
                snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET FOLDER_ID = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, destFolderId, msgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        /* get conversation id */
@@ -1376,31 +1672,21 @@ msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t de
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
                                                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW)
-               convId = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
+               convId = dbHandle->columnInt(0);
 
        MSG_DEBUG("convId : %d",  convId);
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        /* update conversation table */
-       err = MsgStoUpdateConversation(&dbHandle, convId);
+       err = MsgStoUpdateConversation(dbHandle, convId);
 
-
-       if (destFolderId == MSG_INBOX_ID) {
-               int smsCnt = 0;
-               int mmsCnt = 0;
-
-               smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-               mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-               MsgSettingSetIndicator(smsCnt, mmsCnt);
-
-               MsgRefreshNoti(false);
-       }
+       /* update notification */
+       MsgRefreshAllNotification(true, false, false);
 
        return err;
 }
@@ -1413,11 +1699,13 @@ msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
 
        MSG_DEBUG("msgId : %d, destStorageId : %d", msgId, destStorageId);
 
        switch (destStorageId) {
        case MSG_STORAGE_SIM : // Move message to sim card
+       case MSG_STORAGE_SIM2 :
                {
                        MSG_MESSAGE_INFO_S msgInfo;
                        SMS_SIM_ID_LIST_S simIdList;
@@ -1430,32 +1718,39 @@ msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t
 
                        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
 
+                       if (destStorageId == MSG_STORAGE_SIM)
+                               msgInfo.sim_idx = 1;
+                       else if (destStorageId == MSG_STORAGE_SIM2)
+                               msgInfo.sim_idx = 2;
+
                        if ((err = plg->saveSimMessage(&msgInfo, &simIdList)) != MSG_SUCCESS)
                                return err;
 
-                       dbHandle.beginTrans();
+                       dbHandle->beginTrans();
 
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
-                                       MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
+                       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d, SIM_INDEX = %d WHERE MSG_ID = %d;",
+                                       MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, msgInfo.sim_idx, msgId);
+                       MSG_DEBUG("SQL query=[%s]", sqlQuery);
 
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->endTrans(false);
                                return MSG_ERR_DB_EXEC;
                        }
 
                        for (unsigned int i = 0; i < simIdList.count; i++) {
                                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
-                                               MSGFW_SIM_MSG_TABLE_NAME, msgId, simIdList.simId[i]);
+                               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
+                                               MSGFW_SIM_MSG_TABLE_NAME, msgInfo.sim_idx, simIdList.simId[i], msgId);
+                               MSG_DEBUG("SQL query=[%s]", sqlQuery);
 
-                               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                                       dbHandle.endTrans(false);
+                               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
                                        return MSG_ERR_DB_EXEC;
                                }
                        }
 
-                       dbHandle.endTrans(true);
+                       dbHandle->endTrans(true);
                }
        break;
 
@@ -1468,65 +1763,67 @@ msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t
                        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT STORAGE_ID FROM %s WHERE MSG_ID = %d;",
                                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-                       err = dbHandle.getTable(sqlQuery, &rowCnt);
+                       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
                        if (err != MSG_SUCCESS) {
-                               dbHandle.freeTable();
+                               MSG_DEBUG("Fail to getTable().");
+                               dbHandle->freeTable();
                                return err;
                        }
 
-                       if (dbHandle.getColumnToInt(1) == MSG_STORAGE_SIM) {
+                       if (dbHandle->getColumnToInt(1) == MSG_STORAGE_SIM) {
                                MSG_DEBUG("It is SIM Message");
                                bSimMsg = true;
                        }
 
-                       dbHandle.freeTable();
+                       dbHandle->freeTable();
 
                        if (bSimMsg == true) {
                                msg_sim_id_t simMsgId;
+                               msg_sim_slot_id_t sim_idx;
 
                                // get sim message id
                                memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_ID FROM %s WHERE MSG_ID = %d;",
+                               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_SLOT_ID, SIM_ID FROM %s WHERE MSG_ID = %d;",
                                                MSGFW_SIM_MSG_TABLE_NAME, msgId);
 
-                               MSG_DEBUG("sqlQuery is %s.", sqlQuery);
-
-                               err = dbHandle.getTable(sqlQuery, &rowCnt);
+                               err = dbHandle->getTable(sqlQuery, &rowCnt);
 
                                if (err != MSG_SUCCESS) {
-                                       dbHandle.freeTable();
+                                       MSG_DEBUG("Fail to getTable().");
+                                       dbHandle->freeTable();
                                        return err;
                                }
 
                                //Delete messages in sim card
                                MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
+                               int index = 2;
 
                                for (int i = 0; i < rowCnt; i++) {
-                                       simMsgId = dbHandle.getColumnToInt(i+1);
+                                       sim_idx =  dbHandle->getColumnToInt(index++);
+                                       simMsgId = dbHandle->getColumnToInt(index++);
 
                                        MSG_DEBUG("simMsgId is %d.", simMsgId);
 
-                                       if ((err = plg->deleteSimMessage(simMsgId)) != MSG_SUCCESS) {
-                                               dbHandle.freeTable();
+                                       if ((err = plg->deleteSimMessage(sim_idx, simMsgId)) != MSG_SUCCESS) {
+                                               dbHandle->freeTable();
                                                return err;
                                        }
                                }
 
-                               dbHandle.freeTable();
+                               dbHandle->freeTable();
 
-                               dbHandle.beginTrans();
+                               dbHandle->beginTrans();
 
                                //Delete Messages in SIM Msg table
                                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                                snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
                                                MSGFW_SIM_MSG_TABLE_NAME, msgId);
+                               MSG_DEBUG("SQL query=[%s]", sqlQuery);
 
-                               MSG_DEBUG("sqlQuery is %s.", sqlQuery);
-
-                               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                                       dbHandle.endTrans(false);
+                               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
                                        return MSG_ERR_DB_EXEC;
                                }
 
@@ -1534,15 +1831,17 @@ msg_error_t MsgStoMoveMessageToStorage(msg_message_id_t msgId, msg_storage_id_t
                                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                                snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET STORAGE_ID = %d WHERE MSG_ID = %d;",
                                                MSGFW_MESSAGE_TABLE_NAME, destStorageId, msgId);
+                               MSG_DEBUG("SQL query=[%s]", sqlQuery);
 
-                               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                                       dbHandle.endTrans(false);
+                               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
                                        return MSG_ERR_DB_EXEC;
                                }
 
-                               dbHandle.endTrans(true);
+                               dbHandle->endTrans(true);
                        }
                }
+               break;
        }
 
        return MSG_SUCCESS;
@@ -1557,49 +1856,50 @@ msg_error_t MsgStoCountMessage(msg_folder_id_t folderId, MSG_COUNT_INFO_S *pCoun
        }
 
        char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 \
-                       UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 \
-                       UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d \
-                       UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d;",
-                       MSGFW_MESSAGE_TABLE_NAME, folderId,
-                       MSGFW_MESSAGE_TABLE_NAME, folderId,
-                       MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE,
-                       MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE);
-
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 1 AND STORAGE_ID = %d "
+                       "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d "
+                       "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d "
+                       "UNION ALL SELECT COUNT(MSG_ID) FROM %s WHERE FOLDER_ID = %d AND MAIN_TYPE = %d AND STORAGE_ID = %d;",
+                       MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
+                       MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_STORAGE_PHONE,
+                       MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_SMS_TYPE, MSG_STORAGE_PHONE,
+                       MSGFW_MESSAGE_TABLE_NAME, folderId, MSG_MMS_TYPE, MSG_STORAGE_PHONE);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pCountInfo->nReadCnt = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pCountInfo->nReadCnt = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pCountInfo->nUnreadCnt = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pCountInfo->nUnreadCnt = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pCountInfo->nSms = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pCountInfo->nSms = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pCountInfo->nMms = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pCountInfo->nMms = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -1617,6 +1917,7 @@ msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCo
        char sqlQuery[MAX_QUERY_LEN+1];
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
+       MsgDbHandler *dbHandle = getDbHandle();
        // SMS
        if ((pMsgType->mainType == MSG_SMS_TYPE) &&
                        (pMsgType->subType == MSG_NORMAL_SMS || pMsgType->subType == MSG_STATUS_REPORT_SMS || pMsgType->subType == MSG_CONCAT_SIM_SMS)) {
@@ -1636,17 +1937,17 @@ msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCo
                return MSG_ERR_INVALID_PARAMETER;
        }
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               *pMsgCount = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               *pMsgCount = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -1655,36 +1956,35 @@ msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCo
 msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
-
-       int order = MsgGetContactNameOrder();
-
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, \
                        SUB_TYPE, DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       BACKUP, PRIORITY, MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH \
+                       BACKUP, PRIORITY, MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, THUMB_PATH, SIM_INDEX \
                        FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pMsg->msgId = dbHandle.columnInt(0);
-               pMsg->threadId = dbHandle.columnInt(1);
-               pMsg->folderId = dbHandle.columnInt(2);
-               pMsg->storageId = dbHandle.columnInt(3);
-               pMsg->msgType.mainType = dbHandle.columnInt(4);
-               pMsg->msgType.subType = dbHandle.columnInt(5);
-               pMsg->displayTime = (time_t)dbHandle.columnInt(6);
-               pMsg->dataSize = dbHandle.columnInt(7);
-               pMsg->networkStatus = dbHandle.columnInt(8);
-               pMsg->bRead = dbHandle.columnInt(9);
-               pMsg->bProtected = dbHandle.columnInt(10);
-               pMsg->bBackup = dbHandle.columnInt(11);
-               pMsg->priority = dbHandle.columnInt(12);
-               pMsg->direction= dbHandle.columnInt(13);
-
-               strncpy(pMsg->subject, (char *)dbHandle.columnText(15), MAX_SUBJECT_LEN);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pMsg->msgId = dbHandle->columnInt(0);
+               pMsg->threadId = dbHandle->columnInt(1);
+               pMsg->folderId = dbHandle->columnInt(2);
+               pMsg->storageId = dbHandle->columnInt(3);
+               pMsg->msgType.mainType = dbHandle->columnInt(4);
+               pMsg->msgType.subType = dbHandle->columnInt(5);
+               pMsg->displayTime = (time_t)dbHandle->columnInt(6);
+               pMsg->dataSize = dbHandle->columnInt(7);
+               pMsg->networkStatus = dbHandle->columnInt(8);
+               pMsg->bRead = dbHandle->columnInt(9);
+               pMsg->bProtected = dbHandle->columnInt(10);
+               pMsg->bBackup = dbHandle->columnInt(11);
+               pMsg->priority = dbHandle->columnInt(12);
+               pMsg->direction= dbHandle->columnInt(13);
+
+               strncpy(pMsg->subject, (char *)dbHandle->columnText(15), MAX_SUBJECT_LEN);
 
                /* Temp_File_Handling */
                if (pMsg->msgType.mainType == MSG_SMS_TYPE || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
@@ -1692,21 +1992,21 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                                char msgData[pMsg->dataSize+1];
                                memset(msgData, 0x00, sizeof(msgData));
 
-                               strncpy(msgData, (char *)dbHandle.columnText(16), pMsg->dataSize);
+                               strncpy(msgData, (char *)dbHandle->columnText(16), pMsg->dataSize);
 
                                // Save Message Data into File
                                char fileName[MSG_FILENAME_LEN_MAX+1];
                                memset(fileName, 0x00, sizeof(fileName));
 
                                if (MsgCreateFileName(fileName) == false) {
-                                       dbHandle.finalizeQuery();
+                                       dbHandle->finalizeQuery();
                                        return MSG_ERR_STORAGE_ERROR;
                                }
 
-                               MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
+                               MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, fileName);
 
                                if (MsgWriteIpcFile(fileName, msgData, pMsg->dataSize) == false) {
-                                       dbHandle.finalizeQuery();
+                                       dbHandle->finalizeQuery();
                                        return MSG_ERR_STORAGE_ERROR;
                                }
 
@@ -1715,7 +2015,7 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                                pMsg->bTextSms = false;
                        } else {
                                memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
-                               strncpy(pMsg->msgText, (char *)dbHandle.columnText(16), pMsg->dataSize);
+                               strncpy(pMsg->msgText, (char *)dbHandle->columnText(16), pMsg->dataSize);
 
                                // For WAP PUSH SI Message
                                if (pMsg->msgType.subType == MSG_WAP_SI_SMS) {
@@ -1728,40 +2028,40 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                                pMsg->bTextSms = true;
                        }
                } else {
-                       if (dbHandle.columnText(16) != NULL)
-                               strncpy(pMsg->msgText, (char *)dbHandle.columnText(16), MAX_MSG_TEXT_LEN);
+                       if (dbHandle->columnText(16) != NULL)
+                               strncpy(pMsg->msgText, (char *)dbHandle->columnText(16), MAX_MSG_TEXT_LEN);
                }
 
                // thumbnail path
-               if (dbHandle.columnText(17)!=NULL && ((char *)dbHandle.columnText(17))[0] != '\0') {
-                       strncpy(pMsg->thumbPath, (char *)dbHandle.columnText(17), MSG_FILEPATH_LEN_MAX);
+               if (dbHandle->columnText(17)!=NULL && ((char *)dbHandle->columnText(17))[0] != '\0') {
+                       strncpy(pMsg->thumbPath, (char *)dbHandle->columnText(17), MSG_FILEPATH_LEN_MAX);
                        MSG_DEBUG("pMsg->thumbPath : [%s]", pMsg->thumbPath);
                }
+               pMsg->sim_idx= dbHandle->columnInt(18);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                MSG_DEBUG("%s", sqlQuery);
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
 
        // get address information.
-       MsgStoGetAddressByMsgId(&dbHandle, pMsg->msgId, order, &pMsg->nAddressCnt, pMsg->addressList);
+       MsgStoGetAddressByMsgId(dbHandle, pMsg->msgId, MsgGetContactNameOrder(), &pMsg->nAddressCnt, &pMsg->addressList);
 
        // Get MMS body if it is MMS.
        if ((pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS &&
-                       (pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
-                       pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS) {
+                       (pMsg->msgType.subType == MSG_RETRIEVE_MMS || pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS)) ||
+                       pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_SENDCONF_MMS || pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
                msg_error_t err = MSG_SUCCESS;
-               MMS_MESSAGE_DATA_S      mmsMsg;
                char *pDestMsg = NULL;
                int temp_size = pMsg->dataSize;//save raw file size;
+
                // call mms plugin to get mms specific message data
                MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsg->msgType.mainType);
-               memset(&mmsMsg, 0, sizeof(MMS_MESSAGE_DATA_S));
-               err =  plg->getMmsMessage(pMsg, pSendOptInfo, &mmsMsg, &pDestMsg);
 
+               err =  plg->getMmsMessage(pMsg, pSendOptInfo, &pDestMsg);
                if (err != MSG_SUCCESS) {
                        if (pDestMsg) {
                                free(pDestMsg);
@@ -1785,7 +2085,7 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
                                }
                                return MSG_ERR_STORAGE_ERROR;
                        }
-                       MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
+                       MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsg->dataSize, tempFileName);
 
                        if (MsgWriteIpcFile(tempFileName, pDestMsg, pMsg->dataSize) == false) {
                                if(pDestMsg) {
@@ -1811,134 +2111,44 @@ msg_error_t MsgStoGetMessage(msg_message_id_t msgId, MSG_MESSAGE_INFO_S *pMsg, M
 
        // Get SMS Sending Options
        if (pMsg->msgType.mainType == MSG_SMS_TYPE && pSendOptInfo != NULL)
-               MsgStoGetSmsSendOpt(pMsg->msgId, pSendOptInfo);
+               MsgStoGetSmsSendOpt(pMsg, pSendOptInfo);
 
        return MSG_SUCCESS;
 }
 
-
-msg_error_t MsgStoGetFolderViewList(msg_folder_id_t folderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList)
+msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count)
 {
-       if (pMsgFolderViewList == NULL) {
-               MSG_DEBUG("pMsgFolderViewList is NULL");
-               return MSG_ERR_NULL_POINTER;
-       }
-
-       int rowCnt = 0;
-       int index = 19; // numbers of index
-
+       MSG_BEGIN();
 
+       msg_error_t err = MSG_SUCCESS;
        char sqlQuery[MAX_QUERY_LEN+1];
-       char sqlSort[64];
-
-       // Get Name Order
-       int order = MsgGetContactNameOrder();
+       int rowCnt = 0;
+       int index = 1;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       // Get Message In Folder
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       if (folderId == MSG_ALLBOX_ID) {
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
-                               DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, BACKUP, PRIORITY, \
-                               MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, THUMB_PATH \
-                               FROM %s WHERE FOLDER_ID < %d ",
-                               MSGFW_MESSAGE_TABLE_NAME, MSG_SPAMBOX_ID);
-       } else {
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
-                               DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, BACKUP, PRIORITY, \
-                               MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, THUMB_PATH \
-                               FROM %s WHERE FOLDER_ID = %d ",
-                               MSGFW_MESSAGE_TABLE_NAME, folderId);
-       }
-
-       memset(sqlSort, 0x00, sizeof(sqlSort));
-       MsgMakeSortRule(pSortRule, sqlSort);
-       strncat(sqlQuery, sqlSort, strlen(sqlSort));
-
-       msg_error_t  err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (err == MSG_ERR_DB_NORECORD) {
-               pMsgFolderViewList->nCount = 0;
-               pMsgFolderViewList->msg_struct_info = NULL;
-
-               dbHandle.freeTable();
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE NETWORK_STATUS = %d AND FOLDER_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_PENDING, MSG_OUTBOX_ID);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
+       if(err == MSG_ERR_DB_NORECORD){
+               dbHandle->freeTable();
                return MSG_SUCCESS;
-       } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("sqlQuery is - %s", sqlQuery);
-               dbHandle.freeTable();
-               return err;
        }
+       *count = rowCnt;
+       int *list = new int[rowCnt];
 
-       pMsgFolderViewList->nCount = rowCnt;
-
-       MSG_DEBUG("pMsgCommInfoList->nCount [%d]", pMsgFolderViewList->nCount);
-
-       pMsgFolderViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
-
-       msg_struct_s *msg = NULL;
-       MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
-
-       for (int i = 0; i < rowCnt; i++) {
-               pMsgFolderViewList->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];;
-
-               msg = (msg_struct_s *)pMsgFolderViewList->msg_struct_info[i];
-
-               msg->type = MSG_STRUCT_MESSAGE_INFO;
-               msg->data = new char[sizeof(MSG_MESSAGE_HIDDEN_S)];
-
-               pTmp = (MSG_MESSAGE_HIDDEN_S *)msg->data;
-
-               pTmp->pData = NULL;
-               pTmp->pMmsData = NULL;
-
-               pTmp->msgId = dbHandle.getColumnToInt(index++);
-               pTmp->threadId = dbHandle.getColumnToInt(index++);
-               pTmp->folderId = dbHandle.getColumnToInt(index++);
-               pTmp->storageId = dbHandle.getColumnToInt(index++);
-               pTmp->mainType = dbHandle.getColumnToInt(index++);
-               pTmp->subType = dbHandle.getColumnToInt(index++);
-               pTmp->displayTime = (time_t)dbHandle.getColumnToInt(index++);
-               pTmp->dataSize = dbHandle.getColumnToInt(index++);
-               pTmp->networkStatus = dbHandle.getColumnToInt(index++);
-               pTmp->bRead = dbHandle.getColumnToInt(index++);
-               pTmp->bProtected = dbHandle.getColumnToInt(index++);
-               pTmp->bBackup = dbHandle.getColumnToInt(index++);
-               pTmp->priority = dbHandle.getColumnToInt(index++);
-               pTmp->direction= dbHandle.getColumnToInt(index++);
-               index++; // This field is reserved.
-
-               dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
-
-               if (pTmp->mainType == MSG_MMS_TYPE &&
-                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
-                       pTmp->pData = NULL;
-                       index++;
-               } else {
-                       pTmp->pData = (void *)new char[pTmp->dataSize + 2];
-                       memset(pTmp->pData, 0x00, pTmp->dataSize + 2);
-
-                       dbHandle.getColumnToString(index++, pTmp->dataSize+1, (char *)pTmp->pData);
-               }
-
-               // get address information from db.
-               msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
-
-               MsgStoGetAddressByMsgId(&dbHandle, pTmp->msgId, order, addr_list);
-
-               pTmp->addr_list = addr_list;
-
-               pTmp->attachCount = dbHandle.getColumnToInt(index++);
-
-               dbHandle.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pTmp->thumbPath);
+       for(int i=0; i<rowCnt; ++i){
+               list[i] = dbHandle->getColumnToInt(index++);
        }
+       *failed_msg_list = list;
+       dbHandle->freeTable();
 
-       dbHandle.freeTable();
-
-       return MSG_SUCCESS;
+       MSG_END();
+       return err;
 }
 
-
 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int pinCode)
 {
        MSG_BEGIN();
@@ -1949,24 +2159,25 @@ msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int
 
        unsigned int rowId = 0;
        msg_thread_id_t convId = 0;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
 
        if (pMsgInfo->nAddressCnt > 0) {
-               err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
+               err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
        }
 
        // Add Message Table
        pMsgInfo->threadId = convId;
-       rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
+       rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
 
        if (rowId <= 0) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_ROW;
        }
 
@@ -1974,31 +2185,22 @@ msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int
        snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
                        MSGFW_SYNCML_MSG_TABLE_NAME, rowId, extId, pinCode);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
-       if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        pMsgInfo->msgId = (msg_message_id_t)rowId;
 
-       MsgSoundPlayStart(false);
-
-       int smsCnt = 0;
-       int mmsCnt = 0;
-
-       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-       MsgSettingHandleNewMsg(smsCnt, mmsCnt);
-
-       MsgInsertNoti(pMsgInfo);
+       MsgInsertNotification(pMsgInfo);
+       MsgChangePmState();
 
        MSG_END();
 
@@ -2008,6 +2210,7 @@ msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int extId, int
 
 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgType)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -2015,15 +2218,15 @@ msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S *pMsgTyp
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pMsgType->mainType = dbHandle.columnInt(0);
-               pMsgType->subType = dbHandle.columnInt(1);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pMsgType->mainType = dbHandle->columnInt(0);
+               pMsgType->subType = dbHandle->columnInt(1);
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -2033,6 +2236,7 @@ msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_IN
 {
        msg_error_t     err = MSG_SUCCESS;
 
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -2060,17 +2264,17 @@ msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_IN
        // Get Message ID
        msg_message_id_t msgId;
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               msgId = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               msgId = dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        // Get Message Info
        err = MsgStoGetMessage(msgId, pMsg, NULL);
@@ -2079,326 +2283,11 @@ msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t QPtype, MSG_MESSAGE_IN
 }
 
 
-msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
-{
-       pThreadViewList->nCount = 0;
-       pThreadViewList->msg_struct_info = NULL;
-
-       int rowCnt = 0;
-       int index = 11; // numbers of index
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, \
-                       A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, \
-                       (SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED \
-                       FROM %s A WHERE A.SMS_CNT > 0 OR A.MMS_CNT > 0 ORDER BY A.DISPLAY_TIME DESC;",
-                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_CONVERSATION_TABLE_NAME);
-
-       msg_error_t  err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-               return MSG_SUCCESS;
-       } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
-               dbHandle.freeTable();
-               return err;
-       }
-
-       if (rowCnt < 1) {
-               MSG_DEBUG("rowCnt is %d", rowCnt);
-               dbHandle.freeTable();
-               return err;
-       }
-
-       pThreadViewList->nCount = rowCnt;
-
-       MSG_DEBUG("pThreadViewList->nCount [%d]", pThreadViewList->nCount);
-
-       pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*rowCnt];
-
-       MSG_THREAD_VIEW_S *pTmp = NULL;
-       msg_struct_s *thread_t = NULL;
-
-       for (int i = 0; i < rowCnt; i++) {
-               thread_t = (msg_struct_s *)new msg_struct_s;
-               pThreadViewList->msg_struct_info[i] = (msg_struct_t)thread_t;
-
-               thread_t->type = MSG_STRUCT_THREAD_INFO;
-               thread_t->data = new MSG_THREAD_VIEW_S;
-
-               pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
-               memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
-
-               pTmp->threadId = dbHandle.getColumnToInt(index++);
-
-               pTmp->unreadCnt = dbHandle.getColumnToInt(index++);
-               pTmp->smsCnt = dbHandle.getColumnToInt(index++);
-               pTmp->mmsCnt = dbHandle.getColumnToInt(index++);
-
-               pTmp->mainType = dbHandle.getColumnToInt(index++);
-               pTmp->subType = dbHandle.getColumnToInt(index++);
-
-               pTmp->direction = dbHandle.getColumnToInt(index++);
-               pTmp->threadTime = (time_t)dbHandle.getColumnToInt(index++);
-
-               memset(pTmp->threadName, 0x00, sizeof(pTmp->threadName));
-               dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, pTmp->threadName);
-
-               memset(pTmp->threadData, 0x00, sizeof(pTmp->threadData));
-               dbHandle.getColumnToString(index++, MAX_THREAD_DATA_LEN, pTmp->threadData);
-
-               int protectedCnt = dbHandle.getColumnToInt(index++);
-               if (protectedCnt > 0)
-                       pTmp->bProtected = true;
-       }
-
-       dbHandle.freeTable();
-
-       return MSG_SUCCESS;
-}
-
-msg_error_t MsgStoGetConversationPreview(MSG_CONVERSATION_VIEW_S *pConv)
-{
-       MsgDbHandler dbHandleForInner;
-       char sqlQuery[MAX_QUERY_LEN + 1];
-       int rowCnt;
-       int index = 3;
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       if (pConv == NULL)
-               return MSG_ERR_NULL_POINTER;
-
-       //(MSG_ID INTEGER, TYPE INTEGER, VALUE TEXT, COUNT INTEGER)
-       snprintf(sqlQuery, sizeof(sqlQuery),
-                       "SELECT TYPE, VALUE, COUNT "
-                       "FROM %s WHERE MSG_ID=%d;",
-                       MSGFW_MMS_PREVIEW_TABLE_NAME, pConv->msgId);
-
-       MSG_DEBUG("QUERY : [%s]", sqlQuery);
-
-       msg_error_t err = dbHandleForInner.getTable(sqlQuery, &rowCnt);
-       if (err == MSG_SUCCESS) {
-               for (int i = 0; i < rowCnt; i++) {
-                       int type = dbHandleForInner.getColumnToInt(index++);
-                       if (type == MSG_MMS_ITEM_TYPE_IMG) {
-                               dbHandleForInner.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pConv->imageThumbPath);
-                               dbHandleForInner.getColumnToInt(index++);
-                       } else if (type == MSG_MMS_ITEM_TYPE_VIDEO) {
-                               dbHandleForInner.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pConv->videoThumbPath);
-                               dbHandleForInner.getColumnToInt(index++);
-                       } else if (type == MSG_MMS_ITEM_TYPE_AUDIO) {
-                               dbHandleForInner.getColumnToString(index++, MSG_FILENAME_LEN_MAX, pConv->audioFileName);
-                               dbHandleForInner.getColumnToInt(index++);
-                       } else if (type == MSG_MMS_ITEM_TYPE_ATTACH) {
-                               dbHandleForInner.getColumnToString(index++, MSG_FILENAME_LEN_MAX, pConv->attachFileName);
-                               dbHandleForInner.getColumnToInt(index++);
-                       } else if (type == MSG_MMS_ITEM_TYPE_PAGE) {
-                               index++;
-                               pConv->pageCount = dbHandleForInner.getColumnToInt(index++);
-                       } else {
-                               MSG_DEBUG("Unknown item type [%d]", type);
-                               index+=2;
-                       }
-               }
-       }
-
-       dbHandleForInner.freeTable();
-       return MSG_SUCCESS;
-}
-
-msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATION_VIEW_S *pConv)
-{
-       int rowCnt = 0;
-       int index = 16; /** numbers of index */
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
-                       DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT \
-                       FROM %s WHERE MSG_ID=%d;",
-                       MSGFW_MESSAGE_TABLE_NAME, msgId);
-
-       msg_error_t err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-               return MSG_SUCCESS;
-       } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
-               dbHandle.freeTable();
-               return err;
-       }
-
-       memset(pConv, 0x00, sizeof(MSG_CONVERSATION_VIEW_S));
-       pConv->pText = NULL;
-
-       pConv->msgId = dbHandle.getColumnToInt(index++);
-       pConv->threadId = dbHandle.getColumnToInt(index++);
-       pConv->folderId = dbHandle.getColumnToInt(index++);
-       pConv->storageId = dbHandle.getColumnToInt(index++);
-       pConv->mainType = dbHandle.getColumnToInt(index++);
-       pConv->subType = dbHandle.getColumnToInt(index++);
-       pConv->displayTime = (time_t)dbHandle.getColumnToInt(index++);
-       pConv->textSize = dbHandle.getColumnToInt(index++);
-       pConv->networkStatus = dbHandle.getColumnToInt(index++);
-       pConv->bRead = dbHandle.getColumnToInt(index++);
-       pConv->bProtected = dbHandle.getColumnToInt(index++);
-       pConv->direction = dbHandle.getColumnToInt(index++);
-       pConv->scheduledTime = (time_t)dbHandle.getColumnToInt(index++);
-
-       dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pConv->subject);
-
-       if (pConv->mainType == MSG_MMS_TYPE &&
-               (pConv->networkStatus == MSG_NETWORK_RETRIEVING || pConv->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pConv->subType == MSG_NOTIFICATIONIND_MMS)) {
-               pConv->pText = NULL;
-               pConv->textSize = 0;
-               index++;
-       } else {
-               if (pConv->mainType == MSG_SMS_TYPE) {
-                       pConv->pText = new char[pConv->textSize+2];
-                       memset(pConv->pText, 0x00, pConv->textSize+2);
-                       dbHandle.getColumnToString(index++, pConv->textSize+1, pConv->pText);
-               } else {
-                       char tmpMmsText[MAX_MMS_TEXT_LEN+1];
-                       memset(tmpMmsText, 0x00, MAX_MMS_TEXT_LEN+1);
-
-                       dbHandle.getColumnToString(index++, MAX_MMS_TEXT_LEN, tmpMmsText);
-
-                       pConv->textSize = strlen(tmpMmsText);
-
-                       pConv->pText = new char[pConv->textSize+2];
-                       memset(pConv->pText, 0x00, pConv->textSize+2);
-
-                       strncpy(pConv->pText, tmpMmsText, pConv->textSize+1);
-
-                       MsgStoGetConversationPreview(pConv);
-               }
-       }
-
-       pConv->attachCount = dbHandle.getColumnToInt(index++);
-
-       MSG_END();
-
-       return MSG_SUCCESS;
-}
-
-msg_error_t MsgStoGetConversationViewList(msg_thread_id_t threadId, msg_struct_list_s *pConvViewList)
-{
-       MSG_BEGIN();
-
-       pConvViewList->nCount = 0;
-       pConvViewList->msg_struct_info = NULL;
-
-       int rowCnt = 0;
-       int index = 16; /** numbers of index */
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
-                       DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
-                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT \
-                       FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME, MSG_ID ASC;",
-                       MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
-
-       msg_error_t err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-               return MSG_SUCCESS;
-       } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
-               dbHandle.freeTable();
-               return err;
-       }
-
-       pConvViewList->nCount = rowCnt;
-
-       MSG_DEBUG("pConvViewList->nCount [%d]", pConvViewList->nCount);
-
-       pConvViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
-       memset(pConvViewList->msg_struct_info, 0x00, sizeof(msg_struct_t) * rowCnt);
-
-       msg_struct_s *conv = NULL;
-       MSG_CONVERSATION_VIEW_S *pTmp = NULL;
-
-       for (int i = 0; i < rowCnt; i++) {
-               pConvViewList->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];;
-               memset(pConvViewList->msg_struct_info[i], 0x00, sizeof(msg_struct_s));
-
-               conv = (msg_struct_s *)pConvViewList->msg_struct_info[i];
-
-               conv->type = MSG_STRUCT_CONV_INFO;
-               conv->data = new char[sizeof(MSG_CONVERSATION_VIEW_S)];
-               memset(conv->data, 0x00, sizeof(MSG_CONVERSATION_VIEW_S));
-
-               pTmp = (MSG_CONVERSATION_VIEW_S *)conv->data;
-
-               pTmp->pText = NULL;
-
-               pTmp->msgId = dbHandle.getColumnToInt(index++);
-               pTmp->threadId = dbHandle.getColumnToInt(index++);
-               pTmp->folderId = dbHandle.getColumnToInt(index++);
-               pTmp->storageId = dbHandle.getColumnToInt(index++);
-               pTmp->mainType = dbHandle.getColumnToInt(index++);
-               pTmp->subType = dbHandle.getColumnToInt(index++);
-               pTmp->displayTime = (time_t)dbHandle.getColumnToInt(index++);
-               pTmp->textSize = dbHandle.getColumnToInt(index++);
-               pTmp->networkStatus = dbHandle.getColumnToInt(index++);
-               pTmp->bRead = dbHandle.getColumnToInt(index++);
-               pTmp->bProtected = dbHandle.getColumnToInt(index++);
-               pTmp->direction = dbHandle.getColumnToInt(index++);
-               index++; // This field is reserved.
-
-               dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
-
-               if (pTmp->mainType == MSG_MMS_TYPE &&
-                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
-                       pTmp->pText = NULL;
-                       pTmp->textSize = 0;
-                       index++;
-               } else {
-                       if (pTmp->mainType == MSG_SMS_TYPE) {
-                               pTmp->pText = new char[pTmp->textSize+2];
-                               memset(pTmp->pText, 0x00, pTmp->textSize+2);
-                               dbHandle.getColumnToString(index++, pTmp->textSize+1, pTmp->pText);
-                       } else {
-                               char tmpMmsText[MAX_MMS_TEXT_LEN+1];
-                               memset(tmpMmsText, 0x00, MAX_MMS_TEXT_LEN+1);
-
-                               dbHandle.getColumnToString(index++, MAX_MMS_TEXT_LEN, tmpMmsText);
-
-                               pTmp->textSize = strlen(tmpMmsText);
-
-                               pTmp->pText = new char[pTmp->textSize+2];
-                               memset(pTmp->pText, 0x00, pTmp->textSize+2);
-
-                               strncpy(pTmp->pText, tmpMmsText, pTmp->textSize+1);
-                       }
-               }
-
-               pTmp->attachCount = dbHandle.getColumnToInt(index++);
-
-               MsgStoGetConversationPreview(pTmp);
-       }
-
-       dbHandle.freeTable();
-
-       MSG_END();
-
-       return MSG_SUCCESS;
-}
-
-
 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList)
 {
        msg_error_t err = MSG_SUCCESS;
 
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        /*** Get msg id list **/
@@ -2407,6 +2296,17 @@ msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bInclud
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
+#ifdef MSG_NOTI_INTEGRATION
+       if (bIncludeProtect) {
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
+                               CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+       } else {
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
+                               CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
+                               MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+       }
+#else
        if (bIncludeProtect) {
                snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE \
                                CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
@@ -2416,16 +2316,17 @@ msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bInclud
                                CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0;",
                                MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
        }
+#endif
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-               dbHandle.freeTable();
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
        }
 
        if (rowCnt <= 0) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                err = MSG_SUCCESS;
        }
 
@@ -2436,9 +2337,9 @@ msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bInclud
        pMsgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
 
        for (int i = 0; i < rowCnt; i++)
-               pMsgIdList->msgIdList[i] = dbHandle.getColumnToInt(index++);
+               pMsgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
        /*** **/
 
        err = MsgStoDeleteMessageByList(pMsgIdList);
@@ -2449,6 +2350,7 @@ msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t threadId, bool bInclud
 
 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -2458,860 +2360,661 @@ msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MS
                                SUM(CASE WHEN READ_STATUS=0 AND FOLDER_ID=%d THEN 1 ELSE 0 END), \
                                SUM(CASE WHEN MAIN_TYPE=%d THEN 1 ELSE 0 END), \
                                SUM(CASE WHEN MAIN_TYPE=%d THEN 1 ELSE 0 END) \
-                               FROM (SELECT * FROM %s A  JOIN %s B ON A.ADDRESS_ID = B.ADDRESS_ID WHERE B.CONTACT_ID = %d)",
+                               FROM (SELECT * FROM %s A  JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.CONTACT_ID = %d)",
                                MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->contactId);
        } else {
                snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) AS TOTAL, \
                                SUM(CASE WHEN READ_STATUS=0 AND FOLDER_ID=%d THEN 1 ELSE 0 END), \
                                SUM(CASE WHEN MAIN_TYPE=%d THEN 1 ELSE 0 END), \
                                SUM(CASE WHEN MAIN_TYPE=%d THEN 1 ELSE 0 END) \
-                               FROM (SELECT * FROM %s A  JOIN %s B ON A.ADDRESS_ID = B.ADDRESS_ID WHERE B.ADDRESS_VAL = '%s')",
+                               FROM (SELECT * FROM %s A  JOIN %s B ON A.CONV_ID = B.CONV_ID WHERE B.ADDRESS_VAL = '%s')",
                                MSG_INBOX_ID, MSG_SMS_TYPE, MSG_MMS_TYPE, MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pAddrInfo->msgAddrInfo.addressVal);
        }
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pThreadCountInfo->totalCount = dbHandle.columnInt(0);
-               pThreadCountInfo->unReadCount = dbHandle.columnInt(1);
-               pThreadCountInfo->smsMsgCount = dbHandle.columnInt(2);
-               pThreadCountInfo->mmsMsgCount = dbHandle.columnInt(3);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pThreadCountInfo->totalCount = dbHandle->columnInt(0);
+               pThreadCountInfo->unReadCount = dbHandle->columnInt(1);
+               pThreadCountInfo->smsMsgCount = dbHandle->columnInt(2);
+               pThreadCountInfo->mmsMsgCount = dbHandle->columnInt(3);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
 
 
-msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
+msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
 {
-       if (!pSearchString)
-               return MSG_ERR_NULL_POINTER;
+       MsgDbHandler *dbHandle = getDbHandle();
+       char sqlQuery[MAX_QUERY_LEN+1];
 
-       // Clear Out Parameter
-       pThreadViewList->nCount = 0;
-       pThreadViewList->msg_struct_info = NULL;
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       tr1::unordered_set<msg_thread_id_t> IdList;
-       queue<MSG_THREAD_VIEW_S> searchList;
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
 
-       MSG_THREAD_VIEW_S threadView;
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
 
-       char sqlQuery[MAX_QUERY_LEN+1];
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               *extId = dbHandle->columnInt(0);
+       } else {
+               dbHandle->finalizeQuery();
+               return MSG_ERR_DB_STEP;
+       }
 
-       // Replace string for '%' and '_' character
-       char *ext1_str = NULL;
-       char *ext2_str = NULL;
-       char *ext3_str = NULL;
+       dbHandle->finalizeQuery();
 
-       ext1_str = MsgStoReplaceString(pSearchString, "_", "\\_");
-       ext2_str = MsgStoReplaceString(ext1_str, "%", "\\%");
-       ext3_str = MsgStoReplaceString(ext2_str, "'", "''");
+       return MSG_SUCCESS;
+}
 
-       // Search - Address, Name
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID, UNREAD_CNT, SMS_CNT, MMS_CNT, DISPLAY_NAME, \
-                       MAIN_TYPE, SUB_TYPE, MSG_DIRECTION, DISPLAY_TIME, MSG_TEXT \
-                       FROM %s WHERE DISPLAY_NAME LIKE '%%%s%%' ESCAPE '\\' ORDER BY DISPLAY_TIME DESC;",
-                       MSGFW_CONVERSATION_TABLE_NAME, ext3_str);
+msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+       char sqlQuery[MAX_QUERY_LEN+1];
+       msg_error_t err = MSG_SUCCESS;
 
-       if (ext1_str) {
-               free(ext1_str);
-               ext1_str = NULL;
-       }
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
+                       "FROM %s "
+                       "WHERE MSG_ID = %d "
+                       "order by TIME ASC;"
+                       , MSGFW_SMS_REPORT_TABLE_NAME, msgId);
 
-       if (ext2_str) {
-               free(ext2_str);
-               ext2_str = NULL;
-       }
+       int rowCnt;
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
-       if (ext3_str) {
-               free(ext3_str);
-               ext3_str = NULL;
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
        }
 
-       MSG_DEBUG("[%s]", sqlQuery);
+       int index = 4;
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               MSG_DEBUG("Prepare query fail. [%s]", sqlQuery);
-               return MSG_ERR_DB_PREPARE;
-       }
+       *count =  rowCnt;
+       MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
+       memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
 
-       while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               memset(&threadView, 0x00, sizeof(threadView));
+       for (int i = 0; i < rowCnt; i++) {
+               dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
+               report_status[i].type = dbHandle->getColumnToInt(index++);
+               report_status[i].status = dbHandle->getColumnToInt(index++);
+               report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
 
-               threadView.threadId = dbHandle.columnInt(0);
-               threadView.unreadCnt = dbHandle.columnInt(1);
-               threadView.smsCnt = dbHandle.columnInt(2);
-               threadView.mmsCnt = dbHandle.columnInt(3);
+               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);
+       }
 
-               strncpy(threadView.threadName, (char *)dbHandle.columnText(4), MAX_THREAD_NAME_LEN);
+       *pReportStatus = report_status;
 
-               threadView.mainType = dbHandle.columnInt(5);
-               threadView.subType = dbHandle.columnInt(6);
+       dbHandle->freeTable();
 
-               threadView.direction = dbHandle.columnInt(7);
-               threadView.threadTime = (time_t)dbHandle.columnInt(8);
+       return MSG_SUCCESS;
+}
 
-               strncpy(threadView.threadData, (char *)dbHandle.columnText(9), MAX_THREAD_DATA_LEN);
+msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+       char sqlQuery[MAX_QUERY_LEN+1];
 
-               tr1::unordered_set<msg_thread_id_t>::iterator it;
+       msg_direction_type_t    direction = MSG_DIRECTION_TYPE_MO;
 
-               it = IdList.find(threadView.threadId);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_DIRECTION FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-               if (it == IdList.end()) {
-                       IdList.insert(threadView.threadId);
-                       searchList.push(threadView);
-               }
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
 
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               direction = dbHandle->columnInt(0);
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
-       // Add data to Out Parameter
-       pThreadViewList->nCount = searchList.size();
-       pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * searchList.size()];
+       if (direction == MSG_DIRECTION_TYPE_MO) {//get received report list of MO message
 
-       MSG_THREAD_VIEW_S *pTmp = NULL;
-       msg_struct_s *thread_t = NULL;
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               //MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME)
+               //select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC;
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
+                               "FROM %s "
+                               "WHERE MSG_ID = %d "
+                               "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
+                               , MSGFW_REPORT_TABLE_NAME, msgId);
+
+               int rowCnt;
+               msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("Fail to getTable().");
+                       dbHandle->freeTable();
+                       return err;
+               }
 
-       int index = 0;
+               int index = 4;
 
-       while (!searchList.empty()) {
-               thread_t = (msg_struct_s *)new msg_struct_s;
-               pThreadViewList->msg_struct_info[index] = (msg_struct_t)thread_t;
+               *count =  rowCnt;
+               MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
+               memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
 
-               thread_t->type = MSG_STRUCT_THREAD_INFO;
-               thread_t->data = new MSG_THREAD_VIEW_S;
+               for (int i = 0; i < rowCnt; i++) {
+                       dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
+                       report_status[i].type = dbHandle->getColumnToInt(index++);
+                       report_status[i].status = dbHandle->getColumnToInt(index++);
+                       report_status[i].statusTime = (time_t)dbHandle->getColumnToInt(index++);
 
-               pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
-               memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
+                       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 );
+               }
 
-               memcpy(pTmp, &(searchList.front()), sizeof(MSG_THREAD_VIEW_S));
+               *pReportStatus = report_status;
 
-               searchList.pop();
+               dbHandle->freeTable();
 
-               index++;
-       }
+       } else if (direction == MSG_DIRECTION_TYPE_MT) {//read report sent status of MT message
 
-       return MSG_SUCCESS;
-}
+               int readReportSentStatus;
 
+               if (MsgStoCheckReadReportRequested(dbHandle, msgId) == false) {
+                       *count = 0;
+                       *pReportStatus = NULL;
+                       return MSG_ERR_READREPORT_NOT_REQUESTED;
+               }
 
-msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList)
-{
-       // Clear Out Parameter
-       pMsgList->nCount = 0;
-       pMsgList->msg_struct_info = NULL;
+               MsgStoGetReadReportSendStatus(msgId, &readReportSentStatus);
 
-       int rowCnt = 0;
-       int index = 19; // numbers of index
+               *count =  1;
 
-       unsigned int tmpSize = 0;
+               MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)];
+               memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S));
 
-       unsigned int searchValSize = 0;
-       unsigned int addrValSize = 0;
+               report_status->addressVal[0] = '\0';
+               report_status->type = MSG_REPORT_TYPE_READ_REPORT_SENT;
+               report_status->status = readReportSentStatus;
+               report_status->statusTime = 0;
 
-       if (pSearchCon->pSearchVal)
-               searchValSize = strlen(pSearchCon->pSearchVal);
+               MSG_DEBUG("report_type = %d, report_status = %d", report_status->type, report_status->status);
 
-       if (pSearchCon->pAddressVal)
-               addrValSize = strlen(pSearchCon->pAddressVal);
+               *pReportStatus = report_status;
 
-       MSG_DEBUG("searchValSize [%d]", searchValSize);
-       MSG_DEBUG("addrValSize [%d]", addrValSize);
 
-       unsigned int maxQuerySize = MAX_QUERY_LEN+(searchValSize*6)+addrValSize+1;
+       }
 
-       MSG_DEBUG("MAX_QUERY_LEN+(searchValSize*6)+addrValSize+1 [%d]", maxQuerySize);
-
-       char sqlQuery[maxQuerySize];
-
-       char *ext1_str = NULL;
-       char *ext2_str = NULL;
-       char *ext3_str = NULL;
-
-       // Get Name Order
-       int order = MsgGetContactNameOrder();
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
-                       "A.MSG_ID, "
-                       "A.CONV_ID, "
-                       "A.FOLDER_ID, "
-                       "A.STORAGE_ID, "
-                       "A.MAIN_TYPE, "
-                       "A.SUB_TYPE, "
-                       "A.DISPLAY_TIME, "
-                       "A.DATA_SIZE, "
-                       "A.NETWORK_STATUS, "
-                       "A.READ_STATUS, "
-                       "A.PROTECTED, "
-                       "A.BACKUP, "
-                       "A.PRIORITY, "
-                       "A.MSG_DIRECTION, "
-                       "A.SCHEDULED_TIME, "
-                       "A.SUBJECT, "
-                       "A.MSG_TEXT, "
-                       "A.ATTACHMENT_COUNT, "
-                       "A.THUMB_PATH "
-                       "FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.ADDRESS_ID <> 0 ",
-                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME);
-
-       tmpSize = strlen(sqlQuery);
-       if (pSearchCon->folderId == MSG_ALLBOX_ID)
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_CBMSGBOX_ID);
-       else if (pSearchCon->folderId == MSG_IOSBOX_ID)
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_DRAFT_ID);
-       else
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.FOLDER_ID = %d ", pSearchCon->folderId);
-
-
-       //// msg type
-       tmpSize = strlen(sqlQuery);
-       switch (pSearchCon->msgType) {
-               case MSG_TYPE_SMS:
-                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_NORMAL_SMS);
-                       break;
-
-               case MSG_TYPE_MMS:
-                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d ", MSG_MMS_TYPE);
-                       break;
-
-               case MSG_TYPE_MMS_JAVA:
-                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_MMS_TYPE, MSG_SENDREQ_JAVA_MMS);
-                       break;
+       return MSG_SUCCESS;
+}
 
-               case MSG_TYPE_SMS_SYNCML:
-                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_SYNCML_CP);
-                       break;
 
-               case MSG_TYPE_SMS_REJECT:
-                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_REJECT_SMS);
-                       break;
+msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+       if(pMsg->nAddressCnt > 0) {
+               if (MsgExistAddress(dbHandle, pMsg, pThreadId) == true) {
+                       MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
 
-               default:
-                       MSG_DEBUG("msg type is not set.");
-                       break;
+                       // check thread count
+                       MSG_THREAD_VIEW_S threadInfo;
+                       memset(&threadInfo, 0x00, sizeof(MSG_THREAD_VIEW_S));
+                       MsgStoGetThreadInfo(*pThreadId, &threadInfo);
+                       MSG_DEBUG("threadInfo.smsCnt [%d], threadInfo.mmsCnt [%d]", threadInfo.smsCnt, threadInfo.mmsCnt);
+                       if ((threadInfo.smsCnt + threadInfo.mmsCnt) > 0) {
+                               return MSG_SUCCESS;
+                       }
+               }
        }
 
+       *pThreadId = 0;
+       return MSG_SUCCESS;
+}
 
-       /// string
-       if (pSearchCon->pSearchVal != NULL) {
 
-               tmpSize = strlen(sqlQuery);
+msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
+{
+       MSG_BEGIN();
 
-               // Replace string for '%' and '_' character
-               ext1_str = MsgStoReplaceString(pSearchCon->pSearchVal, "_", "\\_");
-               ext2_str = MsgStoReplaceString(ext1_str, "%", "\\%");
-               ext3_str = MsgStoReplaceString(ext2_str, "'", "''");
+       MsgDbHandler *dbHandle = getDbHandle();
+       int msgCnt = 0;
+       *cnt = 0;
 
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize,
-                               "AND ( A.MSG_TEXT LIKE '%%%s%%' ESCAPE '\\' "
-                               "OR A.SUBJECT LIKE '%%%s%%' ESCAPE '\\' "
-                               "OR B.ADDRESS_VAL LIKE '%%%s%%' ESCAPE '\\' "
-                               "OR B.DISPLAY_NAME LIKE '%%%s%%' ESCAPE '\\' "
-                               "OR B.FIRST_NAME LIKE '%%%s%%' ESCAPE '\\' "
-                               "OR B.LAST_NAME LIKE '%%%s%%' ESCAPE '\\') ",
-                               ext3_str, ext3_str, ext3_str, ext3_str, ext3_str, ext3_str);
+       char sqlQuery[MAX_QUERY_LEN+1];
 
-               if (ext1_str) {
-                       free(ext1_str);
-                       ext1_str = NULL;
-               }
+       // Get MSG_ID
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
+                       WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
 
-               if (ext2_str) {
-                       free(ext2_str);
-                       ext2_str = NULL;
-               }
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
 
-               if (ext3_str) {
-                       free(ext3_str);
-                       ext3_str = NULL;
-               }
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               msgCnt = dbHandle->columnInt(0);
        }
 
-       /// address
-       if (pSearchCon->pAddressVal != NULL) {
+       dbHandle->finalizeQuery();
 
-               tmpSize = strlen(sqlQuery);
+       *cnt = msgCnt;
 
-               // Replace string for '%' and '_' character
-               ext1_str = MsgStoReplaceString(pSearchCon->pAddressVal, "_", "\\_");
-               ext2_str = MsgStoReplaceString(ext1_str, "%", "\\%");
-               ext3_str = MsgStoReplaceString(ext2_str, "'", "''");
+       MSG_END();
 
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND B.ADDRESS_VAL LIKE '%%%s%%' ESCAPE '\\' ", ext3_str);
+       return MSG_SUCCESS;
+}
 
-               if (ext1_str) {
-                       free(ext1_str);
-                       ext1_str = NULL;
-               }
 
-               if (ext2_str) {
-                       free(ext2_str);
-                       ext2_str = NULL;
-               }
+msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
+{
+       MSG_BEGIN();
 
-               if (ext3_str) {
-                       free(ext3_str);
-                       ext3_str = NULL;
-               }
-       }
+       MsgDbHandler *dbHandle = getDbHandle();
+       int rowCnt;
+       int index = 22; // numbers of index
 
-       /// limit, offset
-       tmpSize = strlen(sqlQuery);
-       if (offset >= 0 && limit > 0)
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "GROUP BY A.MSG_ID ORDER BY A.DISPLAY_TIME DESC LIMIT %d OFFSET %d;", limit, offset);
-       else
-               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "GROUP BY A.MSG_ID ORDER BY A.DISPLAY_TIME DESC;");
+       char sqlQuery[MAX_QUERY_LEN+1];
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       msg_error_t err = dbHandle.getTable(sqlQuery, &rowCnt);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, "
+                       "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
+                       "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED, "
+                       "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.FOLDER_ID = %d) AS DRAFT, "
+                       "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS FAILED, "
+                       "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS SENDING, "
+                       "A.TRANSLATION, A.SENDER_LANG, A.RECEIVER_LANG, A.ONLY_RECEIVE, A.INCLUDE_ORGMSG, A.LAST_MSG_ID, "
+                       "(SELECT SIM_INDEX FROM %s B WHERE B.CONV_ID = A.CONV_ID), A.TAG_TYPE "
+                       "FROM %s A WHERE A.CONV_ID = %d AND A.SMS_CNT + A.MMS_CNT > 0;",
+                       MSGFW_MESSAGE_TABLE_NAME,
+                       MSGFW_MESSAGE_TABLE_NAME, MSG_DRAFT_ID,
+                       MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL,
+                       MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SENDING,
+                       MSGFW_MESSAGE_TABLE_NAME,
+                       MSGFW_CONVERSATION_TABLE_NAME, threadId);
+
+       msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-
+               dbHandle->freeTable();
                return MSG_SUCCESS;
        } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Get table fail. [%s]", sqlQuery);
-
-               dbHandle.freeTable();
-
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
                return err;
        }
 
-       pMsgList->nCount = rowCnt;
+       if (rowCnt < 1) {
+               MSG_DEBUG("rowCnt is %d", rowCnt);
+               dbHandle->freeTable();
+               return err;
+       } else {
+               pThreadInfo->threadId = dbHandle->getColumnToInt(index++);
 
-       MSG_DEBUG("pMsgList->nCount [%d]", pMsgList->nCount);
+               pThreadInfo->unreadCnt = dbHandle->getColumnToInt(index++);
+               pThreadInfo->smsCnt = dbHandle->getColumnToInt(index++);
+               pThreadInfo->mmsCnt = dbHandle->getColumnToInt(index++);
 
-       pMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
+               pThreadInfo->mainType = dbHandle->getColumnToInt(index++);
+               pThreadInfo->subType = dbHandle->getColumnToInt(index++);
 
-       MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
-       msg_struct_s *msg = NULL;
+               pThreadInfo->direction = dbHandle->getColumnToInt(index++);
+               pThreadInfo->threadTime = (time_t)dbHandle->getColumnToInt(index++);
 
-       for (int i = 0; i < rowCnt; i++) {
-               pMsgList->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
-
-               msg = (msg_struct_s *)pMsgList->msg_struct_info[i];
-
-               msg->type = MSG_STRUCT_MESSAGE_INFO;
-               msg->data = (int *)new char[sizeof(MSG_MESSAGE_HIDDEN_S)];
-
-               pTmp = (MSG_MESSAGE_HIDDEN_S *)msg->data;
-
-               memset(pTmp, 0x00, sizeof(MSG_MESSAGE_HIDDEN_S));
-
-               pTmp->pData = NULL;
-               pTmp->pMmsData = NULL;
-
-               pTmp->msgId = dbHandle.getColumnToInt(index++);
-               pTmp->threadId = dbHandle.getColumnToInt(index++);
-               pTmp->folderId = dbHandle.getColumnToInt(index++);
-               pTmp->storageId = dbHandle.getColumnToInt(index++);
-               pTmp->mainType = dbHandle.getColumnToInt(index++);
-               pTmp->subType = dbHandle.getColumnToInt(index++);
-               pTmp->displayTime = (time_t)dbHandle.getColumnToInt(index++);
-               pTmp->dataSize = dbHandle.getColumnToInt(index++);
-               pTmp->networkStatus = dbHandle.getColumnToInt(index++);
-               pTmp->bRead = dbHandle.getColumnToInt(index++);
-               pTmp->bProtected = dbHandle.getColumnToInt(index++);
-               pTmp->bBackup = dbHandle.getColumnToInt(index++);
-               pTmp->priority = dbHandle.getColumnToInt(index++);
-               pTmp->direction= dbHandle.getColumnToInt(index++);
-               index++; // This field is reserved.
-
-               dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
-
-               if (pTmp->mainType == MSG_MMS_TYPE &&
-                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
-                       pTmp->pData = NULL;
-                       index++;
-               } else {
-                       MSG_DEBUG("pTmp->dataSize [%d]", pTmp->dataSize);
-                       pTmp->pData = (void *)new char[pTmp->dataSize + 2];
-                       memset(pTmp->pData, 0x00, pTmp->dataSize + 2);
+               memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
+               dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
 
-                       dbHandle.getColumnToString(index++, pTmp->dataSize+1, (char *)pTmp->pData);
-               }
+               memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
+               dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
 
-               msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
+               int protectedCnt = dbHandle->getColumnToInt(index++);
+               if (protectedCnt > 0)
+                       pThreadInfo->bProtected = true;
 
-               MsgStoGetAddressByMsgId(&dbHandle, pTmp->msgId, order, addr_list);
+               int draftCnt = dbHandle->getColumnToInt(index++);
+               if (draftCnt > 0)
+                       pThreadInfo->bDraft = true;
 
-               pTmp->addr_list = addr_list;
+               int failedCnt = dbHandle->getColumnToInt(index++);
+               if (failedCnt > 0)
+                       pThreadInfo->bSendFailed = true;
 
-               pTmp->attachCount = dbHandle.getColumnToInt(index++);
+               int sendingCnt = dbHandle->getColumnToInt(index++);
+               if (sendingCnt > 0)
+                       pThreadInfo->bSending = true;
 
-               dbHandle.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pTmp->thumbPath);
+               pThreadInfo->msgTranslation.bTranslation = dbHandle->getColumnToInt(index++);
+               pThreadInfo->msgTranslation.senderLang = dbHandle->getColumnToInt(index++);
+               pThreadInfo->msgTranslation.receiverLang = dbHandle->getColumnToInt(index++);
+               pThreadInfo->msgTranslation.bOnlyReceive = dbHandle->getColumnToInt(index++);
+               pThreadInfo->msgTranslation.bIncludeOrgMsg = dbHandle->getColumnToInt(index++);
 
+               pThreadInfo->lastMsgId = dbHandle->getColumnToInt(index++);
+               pThreadInfo->simIndex = dbHandle->getColumnToInt(index++);
+               pThreadInfo->tagType = dbHandle->getColumnToInt(index++);
        }
-       dbHandle.freeTable();
-
-       return MSG_SUCCESS;
-}
-
-
-void MsgConvertNumber(const char *pSrcNum, char *pDestNum)
-{
-       int overLen = 0;
-       int i = 0;
 
-       overLen = strlen(pSrcNum) - MAX_PRECONFIG_NUM;
+       dbHandle->freeTable();
 
-       for (i = 0; i < MAX_PRECONFIG_NUM; i++)
-               pDestNum[i] = pSrcNum[i+overLen];
+       MSG_END();
 
-       pDestNum[i] = '\0';
+       return MSG_SUCCESS;
 }
 
 
-msg_error_t MsgStoGetRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
+msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
 {
-       // Clear Out Parameter
-       pRejectMsgList->nCount = 0;
-       pRejectMsgList->msg_struct_info = NULL;
-
-       int rowCnt = 0;
-       int index = 3; // numbers of index
+       MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+       msg_error_t err = MSG_SUCCESS;
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       // Search Reject Msg
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       if(MsgExistConversation(dbHandle, pMsg->threadId))
+       {
+               // add message to address table  which having same thread_id and datetime;
+               for (int i=0; i<pMsg->nAddressCnt; i++) {
+                       if(MsgExistAddress(dbHandle, pMsg, pMsg->threadId, i) == false)
+                       {
+                               unsigned int addrId;
+                               MSG_CONTACT_INFO_S contactInfo;
+                               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+                               // Get Contact Info
+//                             if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) {
+//                                     MSG_DEBUG("MsgGetContactInfo() fail.");
+//                             }
+                               err = dbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
+                               if (err != MSG_SUCCESS) {
+                                       MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
+                                       return err;
+                               }
 
-       if (pNumber != NULL) {
-               char phoneNumber[MAX_PRECONFIG_NUM+1];
-               memset(phoneNumber, 0x00, sizeof(phoneNumber));
-
-               if (strlen(pNumber) > MAX_PRECONFIG_NUM)
-                       MsgConvertNumber(pNumber, phoneNumber);
-               else
-                       strncpy(phoneNumber, pNumber, MAX_PRECONFIG_NUM);
-
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.MSG_ID, B.MSG_TEXT, B.DISPLAY_TIME \
-                               FROM %s A, %s B \
-                               WHERE A.CONV_ID = B.CONV_ID AND B.MAIN_TYPE = %d \
-                               AND B.SUB_TYPE = %d AND A.ADDRESS_VAL LIKE '%%%s' \
-                               ORDER BY B.DISPLAY_TIME DESC;",
-                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
-                               MSG_SMS_TYPE, MSG_REJECT_SMS, phoneNumber);
-       } else {
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.MSG_ID, B.MSG_TEXT, B.DISPLAY_TIME \
-                               FROM %s A, %s B \
-                               WHERE A.CONV_ID = B.CONV_ID AND B.MAIN_TYPE = %d AND B.SUB_TYPE = %d \
-                               ORDER BY B.DISPLAY_TIME DESC;",
-                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
-                               MSG_SMS_TYPE, MSG_REJECT_SMS);
-       }
+                               // Add Address
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
+                                                       MSGFW_ADDRESS_TABLE_NAME, addrId, pMsg->threadId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
+                                                       contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
 
-       msg_error_t  err = dbHandle.getTable(sqlQuery, &rowCnt);
+                               MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
 
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
+                               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_PREPARE;
 
-               dbHandle.freeTable();
+                               dbHandle->bindText(contactInfo.firstName, 1);
+                               dbHandle->bindText(contactInfo.lastName, 2);
+                               dbHandle->bindText(contactInfo.middleName, 3);
+                               dbHandle->bindText(contactInfo.prefix, 4);
+                               dbHandle->bindText(contactInfo.suffix, 5);
 
-               return err;
-       }
+                               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                                       dbHandle->finalizeQuery();
+                                       return MSG_ERR_DB_STEP;
+                               }
 
-       pRejectMsgList->nCount = rowCnt;
+                               dbHandle->finalizeQuery();
 
-       MSG_DEBUG("pRejectMsgList->nCount [%d]", pRejectMsgList->nCount);
+                               // set conversation display name by conv id
+                               MsgStoSetConversationDisplayName(dbHandle, pMsg->threadId);
+                       }
+               }
 
-       pRejectMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(MSG_REJECT_MSG_INFO_S *)*rowCnt];
 
-       msg_struct_s* pTmp = NULL;
+               if(!MsgExistMessage(dbHandle, pMsg))
+               {
+                       unsigned int rowId = 0;
 
-       for (int i = 0; i < rowCnt; i++) {
-               pRejectMsgList->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
+                       if(pMsg->threadId > 0 && pMsg->folderId == MSG_DRAFT_ID) {
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-               pTmp = (msg_struct_s *)pRejectMsgList->msg_struct_info[i];
-               pTmp->type = MSG_STRUCT_REJECT_MSG_INFO;
-               pTmp->data = new char[sizeof(MSG_FOLDER_INFO_S)];
-               MSG_REJECT_MSG_INFO_S * pMsg = (MSG_REJECT_MSG_INFO_S *)pTmp->data;
-               memset(pMsg, 0x00, sizeof(MSG_REJECT_MSG_INFO_S));
+                               snprintf(sqlQuery, sizeof(sqlQuery),
+                                               "DELETE FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d;",
+                                               MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, MSG_DRAFT_ID);
 
-               pMsg->msgId = dbHandle.getColumnToInt(index++);
-               memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
-               dbHandle.getColumnToString(index++, MAX_MSG_TEXT_LEN, pMsg->msgText);
+                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
 
-               pMsg->displayTime = (time_t)dbHandle.getColumnToInt(index++);
-       }
+                               err = dbHandle->execQuery(sqlQuery);
 
-       dbHandle.freeTable();
+                               if (err != MSG_SUCCESS) {
+                                       MSG_DEBUG("fail to delete draft messages.");
+                               }
+                       }
 
-       return MSG_SUCCESS;
-}
+                       err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &rowId);
 
+                       pMsg->msgId = (msg_message_id_t)rowId;
 
-msg_error_t MsgStoGetSyncMLExtId(msg_message_id_t msgId, int *extId)
-{
-       char sqlQuery[MAX_QUERY_LEN+1];
+                       int fileSize = 0;
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       char *pFileData = NULL;
+                       AutoPtr<char> buf(&pFileData);
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXT_ID FROM %s WHERE MSG_ID = %d;",
-                       MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
+                       // Get File Data
+                       if (pMsg->bTextSms == false) {
+                               if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
+                                       return MSG_ERR_STORAGE_ERROR;
+                               }
+                               MSG_DEBUG("file size [%d]", fileSize);
+                       }
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
+                       char keyName[MAX_VCONFKEY_NAME_LEN];
+                       memset(keyName, 0x00, sizeof(keyName));
+                       sprintf(keyName, "%s/%d", MSG_SIM_IMSI, pMsg->sim_idx);
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               *extId = dbHandle.columnInt(0);
-       } else {
-               dbHandle.finalizeQuery();
-               return MSG_ERR_DB_STEP;
-       }
+                       char *imsi = MsgSettingGetString(keyName);
 
-       dbHandle.finalizeQuery();
+                       // Add Message
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       return MSG_SUCCESS;
-}
+                       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');",
+                                       MSGFW_MESSAGE_TABLE_NAME, rowId, pMsg->threadId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType,
+                                       pMsg->displayTime, pMsg->dataSize, pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction,
+                                       pMsg->bBackup, pMsg->sim_idx, imsi);
 
-msg_error_t MsgStoGetReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus)
-{
-       char sqlQuery[MAX_QUERY_LEN+1];
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       //MSG_ID INTEGER , ADDRESS_VAL TEXT , STATUS_TYPE INTEGER , STATUS INTEGER DEFAULT 0 , TIME DATETIME)
-       //select * from MSG_REPORT_TABLE where MSG_ID=38 order by ADDRESS_VAL DESC, STATUS_TYPE ASC;
-       snprintf(sqlQuery, sizeof(sqlQuery),
-                       "SELECT ADDRESS_VAL, STATUS_TYPE, STATUS, TIME "
-                       "FROM %s "
-                       "WHERE MSG_ID = %d "
-                       "order by ADDRESS_VAL DESC, STATUS_TYPE ASC;"
-                       , MSGFW_REPORT_TABLE_NAME, msgId);
+                       MSG_DEBUG("QUERY : %s", sqlQuery);
 
-       int rowCnt;
-       msg_error_t  err = dbHandle.getTable(sqlQuery, &rowCnt);
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
-               dbHandle.freeTable();
-               return err;
-       }
+                       if (imsi) {
+                               free(imsi);
+                               imsi = NULL;
+                       }
 
-       int index = 4;
+                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                               return MSG_ERR_DB_EXEC;
+                       }
 
-       *count =  rowCnt;
-       MSG_REPORT_STATUS_INFO_S *report_status = (MSG_REPORT_STATUS_INFO_S*)new char[sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt];
-       memset(report_status, 0x00, sizeof(MSG_REPORT_STATUS_INFO_S)*rowCnt);
+                       dbHandle->bindText(pMsg->subject, 1);
 
-       for (int i = 0; i < rowCnt; i++) {
-               dbHandle.getColumnToString(index++, MAX_ADDRESS_VAL_LEN, report_status[i].addressVal);
-               report_status[i].type = dbHandle.getColumnToInt(index++);
-               report_status[i].status = dbHandle.getColumnToInt(index++);
-               report_status[i].statusTime = (time_t)dbHandle.getColumnToInt(index++);
+                       if (pMsg->bTextSms == false)
+                               dbHandle->bindText(pFileData, 2);
+                       else
+                               dbHandle->bindText(pMsg->msgText, 2);
 
-               MSG_DEBUG("(%d/%d) addr = %s, report_type = %d, report_status = %d, report_time = %d", i, rowCnt, report_status[i].addressVal, report_status[i].type, report_status[i].status, report_status[i].statusTime );
-       }
+                       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                               dbHandle->finalizeQuery();
+                               return MSG_ERR_DB_EXEC;
+                       }
 
-       *pReportStatus = report_status;
+                       dbHandle->finalizeQuery();
 
-       return MSG_SUCCESS;
-}
+                       if (pMsg->msgType.subType != MSG_SENDREQ_MMS) {
+                               err = MsgStoUpdateConversation(dbHandle, pMsg->threadId);
 
+                               if (err != MSG_SUCCESS) {
+                                       return err;
+                               }
+                       }
 
-msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId)
-{
-       if(pMsg->nAddressCnt > 0) {
-               if (MsgExistAddress(&dbHandle, pMsg, pThreadId) == true) {
-                       MSG_DEBUG("Conversation ID : [%d]", *pThreadId);
-               } else {
-                       *pThreadId = 0;
-                       return MSG_ERR_STORAGE_ERROR;
-               }
-       } else {
-               *pThreadId = 0;
-       }
-       return MSG_SUCCESS;
-}
+                       /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
+                       if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
+                               MMS_MESSAGE_DATA_S mmsMsg;
+                               memset(&mmsMsg, 0x00, sizeof(MMS_MESSAGE_DATA_S));
 
+                               if (pMsg->msgType.subType != MSG_DELIVERYIND_MMS && pMsg->msgType.subType != MSG_READORGIND_MMS) {
+                                       MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(MSG_MMS_TYPE);
 
-msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t threadId, int *cnt)
-{
-       MSG_BEGIN();
+                                       err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
 
-       int msgCnt = 0;
-       *cnt = 0;
+                                       if (err != MSG_SUCCESS)
+                                               return MSG_ERR_STORAGE_ERROR;
 
-       char sqlQuery[MAX_QUERY_LEN+1];
+                                       if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
+                                               MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                                               err = MsgStoUpdateMMSMessage(pMsg);
 
-       // Get MSG_ID
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s A \
-                       WHERE CONV_ID = %d AND READ_STATUS = 0;", MSGFW_MESSAGE_TABLE_NAME, threadId);
+                                               if (err != MSG_SUCCESS)
+                                                       return MSG_ERR_STORAGE_ERROR;
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
+                                       }
+                               }
+                       }
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               msgCnt = dbHandle.columnInt(0);
+               }
+       }
+       else
+       {
+               // add message to conversation, message, address table;
+               pMsg->msgId = 0;
+               err = MsgStoAddMessage(pMsg, pSendOptInfo);
        }
-
-       dbHandle.finalizeQuery();
-
-       *cnt = msgCnt;
 
        MSG_END();
 
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgStoGetAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       int order = MsgGetContactNameOrder();
-
-       err = MsgStoGetAddressByConvId(&dbHandle, threadId, order, pAddrList);
-
        return err;
 }
 
 
-msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo)
+msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize)
 {
        MSG_BEGIN();
-
-       int rowCnt;
-       int index = 11; // numbers of index
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, \
-                       A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, \
-                       (SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED \
-                       FROM %s A WHERE A.CONV_ID = %d;",
-                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_CONVERSATION_TABLE_NAME, threadId);
-
-       msg_error_t  err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-               return MSG_SUCCESS;
-       } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
-               dbHandle.freeTable();
-               return err;
+       MsgDbHandler *dbHandle = getDbHandle();
+       if (pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE) {
+               MSG_DEBUG("pMsg == NULL || pMsg->msgType.mainType == MSG_MMS_TYPE");
+               return 0;
        }
 
-       if (rowCnt < 1) {
-               MSG_DEBUG("rowCnt is %d", rowCnt);
-               dbHandle.freeTable();
-               return err;
+       if ((pMsg->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsg->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
+               if (pMsg->msgId > 0) {
+                       pMsg->bRead = false;
+                       if (MsgStoUpdateMessage(pMsg, NULL) != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgStoUpdateMessage is failed!!!");
+                       }
+               } else {
+                       if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgStoAddMessage is failed!!!");
+                       }
+               }
        } else {
-               pThreadInfo->threadId = dbHandle.getColumnToInt(index++);
-
-               pThreadInfo->unreadCnt = dbHandle.getColumnToInt(index++);
-               pThreadInfo->smsCnt = dbHandle.getColumnToInt(index++);
-               pThreadInfo->mmsCnt = dbHandle.getColumnToInt(index++);
+               pMsg->msgId = 0;
+               if (MsgStoAddMessage(pMsg, NULL) != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgStoAddMessage is failed!!!");
+               }
+       }
 
-               pThreadInfo->mainType = dbHandle.getColumnToInt(index++);
-               pThreadInfo->subType = dbHandle.getColumnToInt(index++);
+       if(simIdList) {
+               dbHandle->beginTrans();
 
-               pThreadInfo->direction = dbHandle.getColumnToInt(index++);
-               pThreadInfo->threadTime = (time_t)dbHandle.getColumnToInt(index++);
+               MSG_DEBUG("simIdList exist.");
+               int simId = 0;
+               for(int i=0; i < listSize; ++i)
+               {
+                       if(simIdList[i]) {
+                               simId = simIdList[i] - 1;
+                               char sqlQuery[MAX_QUERY_LEN+1];
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d);",
+                                               MSGFW_SIM_MSG_TABLE_NAME, pMsg->sim_idx, simId, pMsg->msgId);
 
-               memset(pThreadInfo->threadName, 0x00, sizeof(pThreadInfo->threadName));
-               dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, pThreadInfo->threadName);
+                               MSG_DEBUG("QUERY : %s", sqlQuery);
 
-               memset(pThreadInfo->threadData, 0x00, sizeof(pThreadInfo->threadData));
-               dbHandle.getColumnToString(index++, MAX_THREAD_DATA_LEN, pThreadInfo->threadData);
+                               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
+                                       return 0;
+                               }
+                       } else {
+                               break;
+                       }
+               }
 
-               int protectedCnt = dbHandle.getColumnToInt(index++);
-               if (protectedCnt > 0)
-                       pThreadInfo->bProtected = true;
+               dbHandle->endTrans(true);
        }
 
-       dbHandle.freeTable();
-
        MSG_END();
 
-       return MSG_SUCCESS;
+       return pMsg->msgId;
 }
 
-
-msg_error_t MsgStoGetMessageList(msg_folder_id_t folderId, msg_thread_id_t threadId, msg_message_type_t msgType, msg_storage_id_t storageId, msg_struct_list_s *pMsgList)
+msg_error_t MsgStoUpdateIMSI(int sim_idx)
 {
-       // Clear Out Parameter
-       pMsgList->nCount = 0;
-       pMsgList->msg_struct_info = NULL;
+       MSG_BEGIN();
+       MSG_DEBUG("sim_idx = %d", sim_idx);
 
-       int rowCnt = 0;
-       int index = 19; // numbers of index
+//     msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
        char sqlQuery[MAX_QUERY_LEN+1];
-       char sqlQuerySubset[(MAX_QUERY_LEN/5)+1];
-
-       // Get Name Order
-       int order = MsgGetContactNameOrder();
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
-                       DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, BACKUP, PRIORITY, \
-                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, THUMB_PATH \
-                       FROM %s WHERE ", MSGFW_MESSAGE_TABLE_NAME);
-
-
-       //// folder
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
-       if (folderId == MSG_ALLBOX_ID)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FOLDER_ID > 0 AND FOLDER_ID < %d ", MSG_CBMSGBOX_ID);
-       else if (folderId == MSG_IOSBOX_ID)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FOLDER_ID > 0 AND FOLDER_ID < %d ", MSG_DRAFT_ID);
-       else
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FOLDER_ID = %d ", folderId);
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
-
-
-       //// thread
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
-       if (threadId > 0)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND CONV_ID = %d ", threadId);
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
-
-
-       //// msg type
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
-       switch (msgType) {
-               case MSG_TYPE_SMS:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND MAIN_TYPE = %d AND SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_NORMAL_SMS);
-                       break;
+       char keyName[MAX_VCONFKEY_NAME_LEN];
 
-               case MSG_TYPE_MMS:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND MAIN_TYPE = %d ", MSG_MMS_TYPE);
-                       break;
+       dbHandle->beginTrans();
 
-               case MSG_TYPE_MMS_JAVA:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND MAIN_TYPE = %d AND SUB_TYPE = %d ", MSG_MMS_TYPE, MSG_SENDREQ_JAVA_MMS);
-                       break;
-
-               case MSG_TYPE_SMS_SYNCML:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND MAIN_TYPE = %d AND SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_SYNCML_CP);
-                       break;
-
-               case MSG_TYPE_SMS_REJECT:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND MAIN_TYPE = %d AND SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_REJECT_SMS);
-                       break;
-
-               default:
-                       MSG_DEBUG("msg type is not set.");
-       }
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
-
-       //// storage
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
-       if (storageId > MSG_STORAGE_UNKNOWN)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND STORAGE_ID = %d ", storageId);
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
-
-
-       /// order
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY DISPLAY_TIME DESC;");
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
-
-       msg_error_t err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+       if(sim_idx == 0){
+               MSG_DEBUG("sim index is 0");
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-               return MSG_SUCCESS;
-       } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Get table fail. [%s]", sqlQuery);
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = 0;",
+                               MSGFW_MESSAGE_TABLE_NAME);
 
-               dbHandle.freeTable();
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
 
-               return err;
+               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                       dbHandle->finalizeQuery();
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
        }
+       else
+       {
+               MSG_DEBUG("sim index is %d", sim_idx);
 
-       pMsgList->nCount = rowCnt;
+               memset(keyName, 0x00, sizeof(keyName));
+               sprintf(keyName, "%s/%d", MSG_SIM_IMSI, sim_idx);
 
-       MSG_DEBUG("pMsgList->nCount [%d]", pMsgList->nCount);
+               char *imsi = MsgSettingGetString(keyName);
 
-       pMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
+               MSG_DEBUG("imsi value exist -> %s", imsi);
 
-       MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
-       msg_struct_s *msg = NULL;
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       for (int i = 0; i < rowCnt; i++) {
-               pMsgList->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
-
-               msg = (msg_struct_s *)pMsgList->msg_struct_info[i];
-
-               msg->type = MSG_STRUCT_MESSAGE_INFO;
-               msg->data = (int *)new char[sizeof(MSG_MESSAGE_HIDDEN_S)];
-
-               pTmp = (MSG_MESSAGE_HIDDEN_S *)msg->data;
-
-               memset(pTmp, 0x00, sizeof(MSG_MESSAGE_HIDDEN_S));
-
-               pTmp->pData = NULL;
-               pTmp->pMmsData = NULL;
-
-               pTmp->msgId = dbHandle.getColumnToInt(index++);
-               pTmp->threadId = dbHandle.getColumnToInt(index++);
-               pTmp->folderId = dbHandle.getColumnToInt(index++);
-               pTmp->storageId = dbHandle.getColumnToInt(index++);
-               pTmp->mainType = dbHandle.getColumnToInt(index++);
-               pTmp->subType = dbHandle.getColumnToInt(index++);
-               pTmp->displayTime = (time_t)dbHandle.getColumnToInt(index++);
-               pTmp->dataSize = dbHandle.getColumnToInt(index++);
-               pTmp->networkStatus = dbHandle.getColumnToInt(index++);
-               pTmp->bRead = dbHandle.getColumnToInt(index++);
-               pTmp->bProtected = dbHandle.getColumnToInt(index++);
-               pTmp->bBackup = dbHandle.getColumnToInt(index++);
-               pTmp->priority = dbHandle.getColumnToInt(index++);
-               pTmp->direction = dbHandle.getColumnToInt(index++);
-               index++; // This field is reserved.
-
-               dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
-
-               if (pTmp->mainType == MSG_MMS_TYPE &&
-                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
-                       pTmp->pData = NULL;
-                       index++;
-               } else {
-                       pTmp->pData = (void *)new char[pTmp->dataSize+2];
-                       memset(pTmp->pData, 0x00, pTmp->dataSize+2);
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET SIM_INDEX = %d \
+                               WHERE SIM_IMSI LIKE '%s';",
+                               MSGFW_MESSAGE_TABLE_NAME, sim_idx, imsi);
 
-                       dbHandle.getColumnToString(index++, pTmp->dataSize+1, (char *)pTmp->pData);
+               if (imsi) {
+                       free(imsi);
+                       imsi = NULL;
                }
 
-               pTmp->attachCount = dbHandle.getColumnToInt(index++);
-
-               dbHandle.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pTmp->thumbPath);
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
 
-               // add address information.
-               order = MsgGetContactNameOrder();
+               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                       dbHandle->finalizeQuery();
+                       dbHandle->endTrans(false);
+                       return MSG_ERR_DB_EXEC;
+               }
+       }
 
-               msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
-               MsgStoGetAddressByMsgId(&dbHandle, pTmp->msgId, order, addr_list);
+       dbHandle->finalizeQuery();
+       dbHandle->endTrans(true);
 
-               pTmp->addr_list = addr_list;
-       }
-       dbHandle.freeTable();
+       MSG_END();
 
        return MSG_SUCCESS;
 }
index 2b19b07..1b69cbd 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -26,7 +26,6 @@
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
 
 
 /*==================================================================================================
@@ -34,6 +33,7 @@ extern MsgDbHandler dbHandle;
 ==================================================================================================*/
 msg_error_t MsgStoGetText(msg_message_id_t msgId, char *pSubject, char *pMsgText)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -41,24 +41,24 @@ msg_error_t MsgStoGetText(msg_message_id_t msgId, char *pSubject, char *pMsgText
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SUBJECT, MSG_TEXT FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if(dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if(dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if(dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+       if(dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
 
-               char *subject = (char*)dbHandle.columnText(0);
-               char *text = (char*)dbHandle.columnText(1);
+               char *subject = (char*)dbHandle->columnText(0);
+               char *text = (char*)dbHandle->columnText(1);
 
                if(subject)
                        strncpy(pSubject, subject, MAX_SUBJECT_LEN);
                if(text)
                        strncpy(pMsgText, text, MAX_MSG_TEXT_LEN);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 
@@ -70,6 +70,13 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
 {
        MSG_BEGIN();
 
+       MSG_DEBUG("pMsg->msgText [%s]", pMsg->msgText);
+       MsgDbHandler *dbHandle = getDbHandle();
+       msg_error_t err = MSG_SUCCESS;
+
+       unsigned int fileSize = 0;
+       char *pFileData = NULL;
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -77,54 +84,212 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
        if(pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
                if( pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS ) {
                        snprintf(sqlQuery, sizeof(sqlQuery),
-                                       "UPDATE %s SET MAIN_TYPE = %d, SUB_TYPE = %d, DISPLAY_TIME = %lu, SUBJECT = ?, NETWORK_STATUS = %d, MSG_TEXT = ?, THUMB_PATH = '%s', DATA_SIZE = %d WHERE MSG_ID = %d;",
-                                       MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->networkStatus, pMsg->thumbPath,  pMsg->dataSize, pMsg->msgId);
+                                       "UPDATE %s SET MAIN_TYPE = %d, SUB_TYPE = %d, FOLDER_ID = %d, DISPLAY_TIME = %lu, SUBJECT = ?, NETWORK_STATUS = %d, MSG_TEXT = ?, THUMB_PATH = '%s', DATA_SIZE = %d WHERE MSG_ID = %d;",
+                                       MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->folderId, pMsg->displayTime, pMsg->networkStatus, pMsg->thumbPath,  pMsg->dataSize, pMsg->msgId);
 
-                       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                                return MSG_ERR_DB_PREPARE;
                        }
 
-                       dbHandle.bindText(pMsg->subject, 1);
-                       dbHandle.bindText(pMsg->msgText, 2);
+                       dbHandle->bindText(pMsg->subject, 1);
+
+                       if (pMsg->msgText[0] != '\0' && g_file_get_contents(pMsg->msgText, &pFileData, &fileSize, NULL) == true) {
+                               dbHandle->bindText(pFileData, 2);
+                       } else {
+                               dbHandle->bindText("", 2);
+                       }
+
                } else if( pMsg->networkStatus == MSG_NETWORK_RETRIEVE_FAIL) {
                        snprintf(sqlQuery, sizeof(sqlQuery),
                                        "UPDATE %s SET MAIN_TYPE = %d, SUB_TYPE = %d, SUBJECT = ?, NETWORK_STATUS = %d, MSG_TEXT = ?, THUMB_PATH = '%s' WHERE MSG_ID = %d;",
                                        MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->networkStatus, pMsg->thumbPath,  pMsg->msgId);
 
-                       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                                return MSG_ERR_DB_PREPARE;
                        }
 
-                       dbHandle.bindText(pMsg->subject, 1);
-                       dbHandle.bindText(pMsg->msgText, 2);
+//                     if (MsgOpenAndReadFile(pMsg->msgText, &pFileData, &fileSize) == false) {
+                       if (g_file_get_contents(pMsg->msgText, &pFileData, &fileSize, NULL) == false) {
+                               return MSG_ERR_STORAGE_ERROR;
+                       }
+
+                       dbHandle->bindText(pMsg->subject, 1);
+
+                       if (pMsg->msgText[0] != '\0' && g_file_get_contents(pMsg->msgText, &pFileData, &fileSize, NULL) == true) {
+                               dbHandle->bindText(pFileData, 2);
+                       } else {
+                               dbHandle->bindText("", 2);
+                       }
                }
-       } else if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
+       } else if (pMsg->msgType.subType == MSG_SENDREQ_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MMS) {
                snprintf(sqlQuery, sizeof(sqlQuery),
-                               "UPDATE %s SET MSG_DATA = '%s', MSG_TEXT = ?, THUMB_PATH = '%s', DATA_SIZE = %d WHERE MSG_ID = %d;",
-                               MSGFW_MESSAGE_TABLE_NAME, pMsg->msgData, pMsg->thumbPath, pMsg->dataSize, pMsg->msgId);
+                               "UPDATE %s SET MSG_TEXT = ?, THUMB_PATH = '%s', DATA_SIZE = %d WHERE MSG_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME, pMsg->thumbPath, pMsg->dataSize, pMsg->msgId);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                        return MSG_ERR_DB_PREPARE;
                }
 
-               dbHandle.bindText(pMsg->msgText, 1);
+               if (pMsg->msgText[0] != '\0' && g_file_get_contents(pMsg->msgText, &pFileData, &fileSize, NULL) == true) {
+                       dbHandle->bindText(pFileData, 1);
+               } else {
+                       dbHandle->bindText("", 1);
+               }
        } else {
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "UPDATE %s SET MAIN_TYPE = %d, SUB_TYPE = %d, FOLDER_ID = %d, NETWORK_STATUS = %d WHERE MSG_ID = %d;",
-                               MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->folderId, pMsg->networkStatus, pMsg->msgId);
+               if (pMsg->msgType.subType == MSG_SENDCONF_MMS && pMsg->networkStatus == MSG_NETWORK_SEND_FAIL) {
+                       snprintf(sqlQuery, sizeof(sqlQuery),
+                                       "UPDATE %s SET MAIN_TYPE = %d, SUB_TYPE = %d, FOLDER_ID = %d, NETWORK_STATUS = %d, DISPLAY_TIME = %lu, READ_STATUS = 0 WHERE MSG_ID = %d;",
+                                       MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->folderId, pMsg->networkStatus, pMsg->displayTime, pMsg->msgId);
 
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               } else {
+                       snprintf(sqlQuery, sizeof(sqlQuery),
+                                       "UPDATE %s SET MAIN_TYPE = %d, SUB_TYPE = %d, FOLDER_ID = %d, NETWORK_STATUS = %d, DISPLAY_TIME = %lu WHERE MSG_ID = %d;",
+                                       MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->folderId, pMsg->networkStatus, pMsg->displayTime, pMsg->msgId);
+               }
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                        return MSG_ERR_DB_PREPARE;
                }
        }
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.finalizeQuery();
-               MSG_DEBUG("Update MMS Message. Fail [%s]", sqlQuery);
+       MSG_DEBUG("[%s]", sqlQuery);
+
+       err = dbHandle->stepQuery();
+
+       if (pFileData != NULL) {
+               g_free(pFileData);
+       }
+
+       if (err != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               MSG_DEBUG("Update MMS Message. Fail.");
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
+
+       /* PLM P141008-05143  :  Notification.Ind address is 1, but MMS retreived Conf address is correct.
+        * So adding code for comparing exist address and new address and replace with new address(MMSconf) address */
+
+       if(pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
+               if (pMsg->nAddressCnt == 1 && pMsg->addressList) {
+                       char tmpAddressVal[MAX_ADDRESS_VAL_LEN+1] = {0,};
+                       msg_address_type_t tmpAddressType;
+                       msg_recipient_type_t tmpRecipientType;
+                       int tmpConvId;
+
+                       //compare stored address and currnt address
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                                       "A.CONV_ID, "
+                                       "A.ADDRESS_TYPE, "
+                                       "A.RECIPIENT_TYPE, "
+                                       "A.ADDRESS_VAL "
+                                       "FROM %s A, %s B "
+                                       "WHERE A.CONV_ID = B.CONV_ID "
+                                       "AND B.MSG_ID = %d;",
+                                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                                       pMsg->msgId);
+
+                       MSG_DEBUG("[%s]", sqlQuery);
+
+                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                               return MSG_ERR_DB_PREPARE;
+                       }
+
+                       err = dbHandle->stepQuery();
+
+                       if (err == MSG_ERR_DB_ROW) {
+                               tmpConvId = dbHandle->columnInt(0);
+                               tmpAddressType = dbHandle->columnInt(1);
+                               tmpRecipientType = dbHandle->columnInt(2);
+                               strncpy(tmpAddressVal, (char*)dbHandle->columnText(3), MAX_ADDRESS_VAL_LEN);
+
+                               dbHandle->finalizeQuery();
+
+                               //compare stored addressList and current addressList
+                               if (tmpAddressType != pMsg->addressList->addressType ||
+                                       tmpRecipientType != pMsg->addressList->recipientType ||
+                                       (strncmp(tmpAddressVal, pMsg->addressList->addressVal, MAX_ADDRESS_VAL_LEN) != 0)) {
+
+                                       MSG_WARN("AddressList of NotiInd and MMSConf are different!!, Replace AddressList to MMSConf data");
+                                       MSG_WARN("AddType [NotiInd : %d], [MMSConf : %d]", tmpAddressType, pMsg->addressList->addressType);
+                                       MSG_WARN("RcptType [NotiInd : %d], [MMSConf : %d]", tmpRecipientType, pMsg->addressList->recipientType);
+                                       MSG_WARN("AddressVal [NotiInd : %s], [MMSConf : %s]", tmpAddressVal, pMsg->addressList->addressVal);
+
+                                       // If MMSConf AddressList is already exist, Replace exist ConvId with matching msgId
+                                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                                       snprintf(sqlQuery, sizeof(sqlQuery),
+                                               "SELECT CONV_ID FROM %s WHERE ADDRESS_VAL = '%s'",
+                                               MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList->addressVal);
+
+                                       MSG_DEBUG("[%s]", sqlQuery);
+
+                                       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                                               return MSG_ERR_DB_PREPARE;
+                                       }
+
+                                       err = dbHandle->stepQuery();
+
+                                       if (err == MSG_ERR_DB_ROW) {
+                                               tmpConvId = dbHandle->columnInt(0);
+
+                                               dbHandle->finalizeQuery();
+
+                                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                                               snprintf(sqlQuery, sizeof(sqlQuery),
+                                                       "UPDATE %s SET CONV_ID = %d WHERE MSG_ID = %d;",
+                                                       MSGFW_MESSAGE_TABLE_NAME, tmpConvId, pMsg->msgId);
+
+                                               MSG_DEBUG("[%s]", sqlQuery);
+
+                                               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                                                       return MSG_ERR_DB_PREPARE;
+                                               }
+
+                                               err = dbHandle->stepQuery();
+
+                                               if (err != MSG_ERR_DB_DONE) {
+                                                       dbHandle->finalizeQuery();
+                                                       MSG_ERR("Replacing CONV_ID with exist one. Fail.");
+                                                       return MSG_ERR_DB_STEP;
+                                               }
+
+                                               dbHandle->finalizeQuery();
+                                       } else {
+                                               dbHandle->finalizeQuery();
+
+                                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+                                               snprintf(sqlQuery, sizeof(sqlQuery),
+                                                       "UPDATE %s SET ADDRESS_TYPE = %d, RECIPIENT_TYPE = %d, ADDRESS_VAL = '%s' WHERE CONV_ID = %d;",
+                                                       MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList->addressType, pMsg->addressList->recipientType, pMsg->addressList->addressVal, tmpConvId);
+
+                                               MSG_DEBUG("[%s]", sqlQuery);
+
+                                               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                                                       return MSG_ERR_DB_PREPARE;
+                                               }
+
+                                               err = dbHandle->stepQuery();
+
+                                               if (err != MSG_ERR_DB_DONE) {
+                                                       dbHandle->finalizeQuery();
+                                                       MSG_ERR("Replacing Address with MMSConf Address. Fail.");
+                                                       return MSG_ERR_DB_STEP;
+                                               }
+
+                                               dbHandle->finalizeQuery();
+                                       }
+                               }
+                       } else {
+                               dbHandle->finalizeQuery();
+                               return MSG_ERR_DB_STEP;
+                       }
+               }
+       }
 
        msg_thread_id_t convId = 0;
        int row = 0;
@@ -134,29 +299,33 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
 
-       if (dbHandle.getTable(sqlQuery, &row) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       if (dbHandle->getTable(sqlQuery, &row) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_PREPARE;
        }
 
        if (row > 0) {
-               convId = dbHandle.getColumnToInt(1);
+               convId = dbHandle->getColumnToInt(1);
 
                MSG_DEBUG("Conversation id:[%d]", convId);
 
-               if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
+               if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
                        MSG_DEBUG("MsgStoUpdateConversation() Error");
-                       dbHandle.freeTable();
+                       dbHandle->freeTable();
+
                        return MSG_ERR_STORAGE_ERROR;
                }
 
+               if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgStoClearConversationTable() Error");
+               }
+
        } else {
-               MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        MSG_END();
 
@@ -166,6 +335,7 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
 
 msg_error_t MsgStoGetContentLocation(MSG_MESSAGE_INFO_S* pMsgInfo)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -173,23 +343,23 @@ msg_error_t MsgStoGetContentLocation(MSG_MESSAGE_INFO_S* pMsgInfo)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONTENTS_LOCATION FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsgInfo->msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               if (dbHandle.columnText(0) != NULL) {
-                       strncpy(pMsgInfo->msgData, (char*)dbHandle.columnText(0), MAX_MSG_DATA_LEN);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               if (dbHandle->columnText(0) != NULL) {
+                       strncpy(pMsgInfo->msgData, (char*)dbHandle->columnText(0), MAX_MSG_DATA_LEN);
                        pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
                } else {
-                       dbHandle.finalizeQuery();
+                       dbHandle->finalizeQuery();
                        return MSG_ERR_DB_NORECORD;
                }
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -197,6 +367,7 @@ msg_error_t MsgStoGetContentLocation(MSG_MESSAGE_INFO_S* pMsgInfo)
 
 msg_error_t MsgStoSetReadReportSendStatus(msg_message_id_t msgId, int readReportSendStatus)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        bool bReadReportSent = false;
 
        if((MmsRecvReadReportSendStatus)readReportSendStatus == MMS_RECEIVE_READ_REPORT_SENT)
@@ -211,7 +382,7 @@ msg_error_t MsgStoSetReadReportSendStatus(msg_message_id_t msgId, int readReport
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_REPORT_SEND_STATUS = %d, READ_REPORT_SENT = %d WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, (MmsRecvReadReportSendStatus)readReportSendStatus, (int)bReadReportSent, msgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -220,33 +391,39 @@ msg_error_t MsgStoSetReadReportSendStatus(msg_message_id_t msgId, int readReport
 
 msg_error_t MsgStoGetOrgAddressList(MSG_MESSAGE_INFO_S *pMsg)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
        char sqlQuery[MAX_QUERY_LEN+1];
        int rowCnt = 0;
        int index = 3;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_TYPE, A.RECIPIENT_TYPE, A.ADDRESS_VAL FROM %s A, %s B \
-                       WHERE A.CONV_ID = B.CONV_ID AND B.MSG_ID = %d;",
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "A.ADDRESS_TYPE, "
+                       "A.RECIPIENT_TYPE, "
+                       "A.ADDRESS_VAL "
+                       "FROM %s A, %s B "
+                       "WHERE A.CONV_ID = B.CONV_ID "
+                       "AND B.MSG_ID = %d;",
                        MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, pMsg->msgId);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return err;
        }
 
        for(int i = 0; i < rowCnt; i++)
        {
-               pMsg->addressList[i].addressType = dbHandle.getColumnToInt(index++);
-               pMsg->addressList[i].recipientType = dbHandle.getColumnToInt(index++);
-               dbHandle.getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pMsg->addressList[i].addressVal);
+               pMsg->addressList[i].addressType = dbHandle->getColumnToInt(index++);
+               pMsg->addressList[i].recipientType = dbHandle->getColumnToInt(index++);
+               dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pMsg->addressList[i].addressVal);
        }
 
        pMsg->nAddressCnt = rowCnt;
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return MSG_SUCCESS;
 }
@@ -254,6 +431,7 @@ msg_error_t MsgStoGetOrgAddressList(MSG_MESSAGE_INFO_S *pMsg)
 
 msg_error_t MsgStoGetSubject(msg_message_id_t msgId, char *pSubject)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -261,17 +439,17 @@ msg_error_t MsgStoGetSubject(msg_message_id_t msgId, char *pSubject)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SUBJECT FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               strncpy(pSubject, (char*)dbHandle.columnText(0), MAX_SUBJECT_LEN);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               strncpy(pSubject, (char*)dbHandle->columnText(0), MAX_SUBJECT_LEN);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -282,20 +460,23 @@ msg_error_t MsgStoGetRecipientList(msg_message_id_t msgId, MSG_RECIPIENTS_LIST_S
                MSG_DEBUG("pRecipientList is NULL");
                return MSG_ERR_NULL_POINTER;
        }
-
-       int rowCnt = 0, index = 7;
-
+       MsgDbHandler *dbHandle = getDbHandle();
+       int rowCnt = 0, index = 3;
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT B.ADDRESS_TYPE, B.RECIPIENT_TYPE, \
-                       B.ADDRESS_VAL, B.CONTACT_ID, B.DISPLAY_NAME, B.FIRST_NAME, B.LAST_NAME \
-                       FROM %s A, %s B WHERE A.MSG_ID = %d AND A.CONV_ID = B.CONV_ID;",
-                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, msgId);
-
-       if (dbHandle.getTable(sqlQuery, &rowCnt) != MSG_SUCCESS) {
-               dbHandle.freeTable();
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "B.ADDRESS_TYPE, "
+                       "B.RECIPIENT_TYPE, "
+                       "B.ADDRESS_VAL "
+                       "FROM %s A, %s B "
+                       "WHERE A.MSG_ID = %d "
+                       "AND A.CONV_ID = B.CONV_ID;",
+                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME,
+                       msgId);
+
+       if (dbHandle->getTable(sqlQuery, &rowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
                return MSG_ERR_DB_GETTABLE;
        }
 
@@ -307,57 +488,20 @@ msg_error_t MsgStoGetRecipientList(msg_message_id_t msgId, MSG_RECIPIENTS_LIST_S
 
        MSG_ADDRESS_INFO_S* pTmp = pRecipientList->recipientAddr;
 
-       char firstName[MAX_THREAD_NAME_LEN+1], lastName[MAX_THREAD_NAME_LEN+1];
-       char displayName[MAX_DISPLAY_NAME_LEN+1];
-
-       int order = MsgGetContactNameOrder();
-
        for (int i = 0; i < rowCnt; i++)
        {
-               pTmp->addressType = dbHandle.getColumnToInt(index++);
-               pTmp->recipientType= dbHandle.getColumnToInt(index++);
+               pTmp->addressType = dbHandle->getColumnToInt(index++);
+               pTmp->recipientType= dbHandle->getColumnToInt(index++);
 
                memset(pTmp->addressVal, 0x00, sizeof(pTmp->addressVal));
-               dbHandle.getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pTmp->addressVal);
-
-               pTmp->contactId= dbHandle.getColumnToInt(index++);
-
-               memset(displayName, 0x00, sizeof(displayName));
-               dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, displayName);
-
-               memset(firstName, 0x00, sizeof(firstName));
-               dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, firstName);
-
-               memset(lastName, 0x00, sizeof(lastName));
-               dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, lastName);
-
-               if (strlen(displayName) <= 0) {
-                       if (order == 0) {
-                               if (firstName[0] != '\0')
-                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
+               dbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pTmp->addressVal);
 
-                               if (lastName[0] != '\0') {
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       } else if (order == 1) {
-                               if (lastName[0] != '\0') {
-                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-
-                               if (firstName[0] != '\0')
-                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                       }
-               }
-
-               memset(pTmp->displayName, 0x00, sizeof(pTmp->displayName));
-               strncpy(pTmp->displayName, displayName, MAX_DISPLAY_NAME_LEN);
+               strncpy(pTmp->displayName, pTmp->addressVal, MAX_DISPLAY_NAME_LEN);
 
                pTmp++;
        }
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return MSG_SUCCESS;
 }
@@ -365,6 +509,7 @@ msg_error_t MsgStoGetRecipientList(msg_message_id_t msgId, MSG_RECIPIENTS_LIST_S
 
 msg_error_t MsgStoGetReadStatus(msg_message_id_t msgId, bool *pReadStatus)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -372,17 +517,17 @@ msg_error_t MsgStoGetReadStatus(msg_message_id_t msgId, bool *pReadStatus)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT READ_STATUS FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               *pReadStatus = (bool)dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               *pReadStatus = (bool)dbHandle->columnInt(0);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -390,30 +535,69 @@ msg_error_t MsgStoGetReadStatus(msg_message_id_t msgId, bool *pReadStatus)
 
 msg_error_t MsgStoGetAddrInfo(msg_message_id_t msgId, MSG_ADDRESS_INFO_S *pAddrInfo)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        // Add Address
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_TYPE, A.RECIPIENT_TYPE, A.CONTACT_ID, A.ADDRESS_VAL \
-                       FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.MSG_ID = %d;",
-                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, msgId);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "A.ADDRESS_TYPE, "
+                       "A.RECIPIENT_TYPE, "
+                       "A.CONTACT_ID, "
+                       "A.ADDRESS_VAL "
+                       "FROM %s A, %s B "
+                       "WHERE A.CONV_ID = B.CONV_ID "
+                       "AND B.MSG_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                       msgId);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
+
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pAddrInfo->addressType = dbHandle->columnInt(0);
+               pAddrInfo->recipientType = dbHandle->columnInt(1);
+               pAddrInfo->contactId = dbHandle->columnInt(2);
+
+               strncpy(pAddrInfo->addressVal, (char*)dbHandle->columnText(3), MAX_ADDRESS_VAL_LEN);
+       } else {
+               dbHandle->finalizeQuery();
+               return MSG_ERR_DB_STEP;
+       }
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       dbHandle->finalizeQuery();
+
+       return MSG_SUCCESS;
+}
+
+msg_error_t MsgStoGetReadReportSendStatus(msg_message_id_t msgId, int *pReadReportSendStatus)
+{
+       MmsRecvReadReportSendStatus readReportSendStatus = MMS_RECEIVE_READ_REPORT_NO_SEND;
+       MsgDbHandler *dbHandle = getDbHandle();
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "READ_REPORT_SEND_STATUS "
+                       "FROM %s WHERE MSG_ID = %d;",
+                       MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pAddrInfo->addressType = dbHandle.columnInt(0);
-               pAddrInfo->recipientType = dbHandle.columnInt(1);
-               pAddrInfo->contactId = dbHandle.columnInt(2);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle->columnInt(0);
+
+               *pReadReportSendStatus = readReportSendStatus;
 
-               strncpy(pAddrInfo->addressVal, (char*)dbHandle.columnText(3), MAX_ADDRESS_VAL_LEN);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
index fbe4662..80f9c2b 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <queue>
@@ -31,48 +31,14 @@ using namespace std;
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
 
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
-msg_error_t MsgInitSimMessage(MSG_SIM_STATUS_T SimStatus)
-{
-       MSG_DEBUG("Start SIM Message Initialization");
-
-       msg_error_t err = MSG_SUCCESS;
-
-       // Set SIM count of vconf to 0
-       if (MsgSettingSetInt(SIM_USED_COUNT, 0) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
-       }
-
-       if (MsgSettingSetInt(SIM_TOTAL_COUNT, 0) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", SIM_TOTAL_COUNT);
-       }
-
-       if (SimStatus != MSG_SIM_STATUS_NOT_FOUND) {
-               MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
-               MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
-
-               if (plg == NULL) {
-                       MSG_DEBUG("No plugin for %d type", mainType);
-                       return MSG_ERR_INVALID_PLUGIN_HANDLE;
-               }
-
-               // Check SIM Status
-               MSG_DEBUG(" ** SIM is available - status : [%d] ** ", SimStatus);
-
-               err = plg->initSimMessage();
-       }
-
-       return err;
-}
-
-
 msg_error_t MsgStoClearSimMessageInDB()
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
@@ -87,33 +53,32 @@ msg_error_t MsgStoClearSimMessageInDB()
 
        int rowCnt = 0;
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               MSG_DEBUG("sql query is %s.", sqlQuery);
-
-               dbHandle.freeTable();
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
                return err;
        }
 
        if (rowCnt <= 0) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return MSG_SUCCESS;
        }
 
        for (int i = 1; i <= rowCnt; i++)
        {
-               MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
-               threadList.push((msg_thread_id_t)dbHandle.getColumnToInt(i));
+               MSG_DEBUG("thread ID : %d", dbHandle->getColumnToInt(i));
+               threadList.push((msg_thread_id_t)dbHandle->getColumnToInt(i));
        }
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        const char* tableList[] = {MSGFW_SMS_SENDOPT_TABLE_NAME, MSGFW_SIM_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
 
        int listCnt = sizeof(tableList)/sizeof(char*);
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
 
        for (int i = 0; i < listCnt; i++)
        {
@@ -124,32 +89,32 @@ msg_error_t MsgStoClearSimMessageInDB()
                                tableList[i], MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
 
                // Delete SIM Message in tables
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
        }
 
        // Clear Conversation table
-       if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
        // Update Address
        while (!threadList.empty())
        {
-               err = MsgStoUpdateConversation(&dbHandle, threadList.front());
+               err = MsgStoUpdateConversation(dbHandle, threadList.front());
 
                threadList.pop();
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        return MSG_SUCCESS;
 }
index a0bb9f0..d0d39d3 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-extern MsgDbHandler dbHandle;
 
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
-msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
-{
-       char sql[128];
-       char order[6];
-
-       memset(sql, 0x00, sizeof(sql));
-       memset(order, 0x00, sizeof(order));
-
-       if (pSortRule->bAscending == true)
-               strncpy(order, "ASC", 5);
-       else
-               strncpy(order, "DESC", 5);
-
-       int nameOrder = MsgGetContactNameOrder();
-
-       switch (pSortRule->sortType)
-       {
-               case MSG_SORT_BY_DISPLAY_FROM :
-                       if (nameOrder == 0)
-                               snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
-                       else
-                               snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
-                       break;
-               case MSG_SORT_BY_DISPLAY_TO :
-                       if (nameOrder == 0)
-                               snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
-                       else
-                               snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
-                       break;
-               case MSG_SORT_BY_DISPLAY_TIME :
-                       snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
-                       break;
-               case MSG_SORT_BY_MSG_TYPE :
-                       snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
-                       break;
-               case MSG_SORT_BY_READ_STATUS :
-                       snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
-                       break;
-               case MSG_SORT_BY_STORAGE_TYPE :
-                       snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
-                       break;
-               case MSG_SORT_BY_THREAD_NAME :
-                       if (nameOrder == 0)
-                               snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
-                       else
-                               snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
-                       break;
-               case MSG_SORT_BY_THREAD_DATE :
-                       snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
-                       break;
-               case MSG_SORT_BY_THREAD_COUNT :
-                       snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
-                       break;
-               default :
-                       snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
-                       break;
-       }
-
-       memcpy(pSqlSort, sql, strlen(sql));
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgStoGetSmsSendOpt(msg_message_id_t msgId, MSG_SENDINGOPT_INFO_S* pSendOpt)
+msg_error_t MsgStoGetSmsSendOpt(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S* pSendOpt)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DELREP_REQ, KEEP_COPY, REPLY_PATH FROM %s WHERE MSG_ID = %d;",
-                       MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DELREP_REQ, KEEP_COPY, REPLY_PATH, ENCODE_TYPE FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_SMS_SENDOPT_TABLE_NAME, pMsg->msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
                pSendOpt->bSetting = true;
-               pSendOpt->bDeliverReq = (bool)dbHandle.columnInt(0);
-               pSendOpt->bKeepCopy = (bool)dbHandle.columnInt(1);
-               pSendOpt->option.smsSendOptInfo.bReplyPath = (bool)dbHandle.columnInt(2);
+               pSendOpt->bDeliverReq = (bool)dbHandle->columnInt(0);
+               pSendOpt->bKeepCopy = (bool)dbHandle->columnInt(1);
+               pSendOpt->option.smsSendOptInfo.bReplyPath = (bool)dbHandle->columnInt(2);
+               pMsg->encodeType = dbHandle->columnInt(3);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -132,6 +69,7 @@ msg_error_t MsgStoGetSmsSendOpt(msg_message_id_t msgId, MSG_SENDINGOPT_INFO_S* p
 
 msg_error_t MsgStoGetMmsSendOpt(msg_message_id_t msgId, MSG_SENDINGOPT_INFO_S* pSendOpt)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -139,32 +77,32 @@ msg_error_t MsgStoGetMmsSendOpt(msg_message_id_t msgId, MSG_SENDINGOPT_INFO_S* p
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ASK_DELIVERY_REPORT, KEEP_COPY, ASK_READ_REPLY, EXPIRY_TIME, PRIORITY FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
                pSendOpt->bSetting = true;
-               pSendOpt->bDeliverReq = (bool)dbHandle.columnInt(0);
-               pSendOpt->bKeepCopy = (bool)dbHandle.columnInt(1);
-               pSendOpt->option.mmsSendOptInfo.bReadReq = (bool)dbHandle.columnInt(2);
-               pSendOpt->option.mmsSendOptInfo.expiryTime.time = (unsigned int)dbHandle.columnInt(3);
-               pSendOpt->option.mmsSendOptInfo.priority = (msg_priority_type_t)dbHandle.columnInt(4);
+               pSendOpt->bDeliverReq = (bool)dbHandle->columnInt(0);
+               pSendOpt->bKeepCopy = (bool)dbHandle->columnInt(1);
+               pSendOpt->option.mmsSendOptInfo.bReadReq = (bool)dbHandle->columnInt(2);
+               pSendOpt->option.mmsSendOptInfo.expiryTime.time = (unsigned int)dbHandle->columnInt(3);
+               pSendOpt->option.mmsSendOptInfo.priority = (msg_priority_type_t)dbHandle->columnInt(4);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
 
+
 bool MsgStoCheckSyncMLMsgInThread(msg_thread_id_t threadId)
 {
-       msg_error_t err = MSG_SUCCESS;
        int rowCnt = 0;
        bool isSyncMLMsg = false;
-
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -172,15 +110,15 @@ bool MsgStoCheckSyncMLMsgInThread(msg_thread_id_t threadId)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE = %d AND CONV_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, MSG_SYNCML_CP, threadId);
 
-       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       if (dbHandle->getTable(sqlQuery, &rowCnt) != MSG_SUCCESS) {
+               MSG_DEBUG("getTable is failed!!!");
+       }
 
        if (rowCnt > 0) isSyncMLMsg = true;
 
        MSG_DEBUG("rowCnt [%d]", rowCnt);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return isSyncMLMsg;
 }
@@ -189,7 +127,7 @@ bool MsgStoCheckSyncMLMsgInThread(msg_thread_id_t threadId)
 msg_error_t MsgStoResetNetworkStatus()
 {
        MSG_BEGIN();
-
+       MsgDbHandler *dbHandle = getDbHandle();
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -199,7 +137,7 @@ msg_error_t MsgStoResetNetworkStatus()
                        MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL, MSG_NETWORK_SENDING,
                        MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_RETRIEVE_FAIL, MSG_NETWORK_RETRIEVING);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        MSG_END();
@@ -207,13 +145,34 @@ msg_error_t MsgStoResetNetworkStatus()
        return MSG_SUCCESS;
 }
 
+#if 0
+msg_error_t MsgStoResetCBMessage()
+{
+       MSG_BEGIN();
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s",
+                       MSGFW_RECEIVED_CB_MSG_TABLE_NAME);
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("Delete Received CB Msg Fail!!");
+               return MSG_ERR_DB_EXEC;
+       }
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
+#endif
+
 
 msg_error_t MsgStoCleanAbnormalMmsData()
 {
        MSG_BEGIN();
 
        int rowCnt = 0, index = 2; // numbers of index
-
+       MsgDbHandler *dbHandle = getDbHandle();
        msg_message_id_t msgId;
 
        char sqlQuery[MAX_QUERY_LEN+1];
@@ -224,14 +183,14 @@ msg_error_t MsgStoCleanAbnormalMmsData()
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.MSG_ID, A.FILE_PATH FROM %s A, %s B WHERE A.MSG_ID = B.MSG_ID AND (B.SUB_TYPE = %d OR B.SUB_TYPE = %d OR B.SUB_TYPE = %d);",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_SENDCONF_MMS, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS);
 
-       msg_error_t  err = dbHandle.getTable(sqlQuery, &rowCnt);
+       msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return MSG_SUCCESS;
        } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("%s", sqlQuery);
-               dbHandle.freeTable();
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
                return err;
        }
 
@@ -240,13 +199,13 @@ msg_error_t MsgStoCleanAbnormalMmsData()
        {
                memset(filePath, 0x00, sizeof(filePath));
 
-               msgId = dbHandle.getColumnToInt(index++);
+               msgId = dbHandle->getColumnToInt(index++);
 
-               dbHandle.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, filePath);
+               dbHandle->getColumnToString(index++, MSG_FILEPATH_LEN_MAX, filePath);
 
                if(strlen(filePath) > 1) {
                        MSG_DEBUG("strlen(filePath) [%d]", strlen(filePath));
-                       MSG_DEBUG("filePath [%s]", filePath);
+                       MSG_SEC_DEBUG("filePath [%s]", filePath);
 
                        if(MsgGetFileSize(filePath) < 0) {
                                // abnormal mms message
@@ -258,7 +217,7 @@ msg_error_t MsgStoCleanAbnormalMmsData()
                }
 
        }
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        MSG_END();
 
@@ -271,12 +230,12 @@ msg_error_t MsgStoCheckReadReportStatus(msg_message_id_t msgId)
 
        bool    bReadReportRequested;
        bool    bReadReportIsSent;
-
-       bReadReportRequested = MsgStoCheckReadReportRequested(&dbHandle, msgId);
+       MsgDbHandler *dbHandle = getDbHandle();
+       bReadReportRequested = MsgStoCheckReadReportRequested(dbHandle, msgId);
        if(bReadReportRequested == false)
                return MSG_ERR_READREPORT_NOT_REQUESTED;
 
-       bReadReportIsSent = MsgStoCheckReadReportIsSent(&dbHandle, msgId);
+       bReadReportIsSent = MsgStoCheckReadReportIsSent(dbHandle, msgId);
        if(bReadReportIsSent == true)
                return MSG_ERR_READREPORT_ALEADY_SENT;
 
@@ -285,3 +244,613 @@ msg_error_t MsgStoCheckReadReportStatus(msg_message_id_t msgId)
        return MSG_SUCCESS;
 }
 
+
+msg_error_t MsgStoAutoDeleteConversation(msg_thread_id_t threadId, msg_id_list_s *msgIdList)
+{
+       MSG_BEGIN();
+       MsgDbHandler *dbHandle = getDbHandle();
+       msg_error_t err = MSG_SUCCESS;
+
+       bool bAutoErase = false;
+       MsgSettingGetBool(MSG_AUTO_ERASE, &bAutoErase);
+
+       if (bAutoErase) {
+
+               MSG_DEBUG("threadId [%d]", threadId);
+
+               //msg_id_list_s msgIdList;
+               int currentSmsCnt = 0;
+               int currentMmsCnt = 0;
+               int limitSmsCnt = 0;
+               int limitMmsCnt = 0;
+
+               char sqlQuery[MAX_QUERY_LEN+1];
+
+               int rowCnt = 0;
+               unsigned int index = 1;
+
+               //memset(msgIdList, 0x00, sizeof(msg_id_list_s));
+
+               // Get current count of messages
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+#ifdef MSG_NOTI_INTEGRATION
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT COUNT(MSG_ID) FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND MAIN_TYPE = %d "
+                               "UNION ALL "
+                               "SELECT COUNT(MSG_ID) FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE NOT IN (%d, %d, %d);",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE, MSG_SMS_TYPE,
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE, MSG_MMS_TYPE, MSG_DELIVERYIND_MMS, MSG_READRECIND_MMS, MSG_READORGIND_MMS);
+#else
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT COUNT(MSG_ID) FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND MAIN_TYPE = %d "
+                               "UNION ALL "
+                               "SELECT COUNT(MSG_ID) FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE NOT IN (%d, %d, %d);",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE, MSG_SMS_TYPE,
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE, MSG_MMS_TYPE, MSG_DELIVERYIND_MMS, MSG_READRECIND_MMS, MSG_READORGIND_MMS);
+#endif
+
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
+                       return MSG_ERR_DB_PREPARE;
+               }
+
+               if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       currentSmsCnt = dbHandle->columnInt(0);
+               } else {
+                       dbHandle->finalizeQuery();
+                       return MSG_ERR_DB_STEP;
+               }
+
+               if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       currentMmsCnt = dbHandle->columnInt(0);
+               } else {
+                       dbHandle->finalizeQuery();
+                       return MSG_ERR_DB_STEP;
+               }
+
+               dbHandle->finalizeQuery();
+
+               MSG_DEBUG("currentSmsCnt [%d], currentMmsCnt [%d]", currentSmsCnt, currentMmsCnt);
+
+               if (currentSmsCnt > 0 || currentMmsCnt > 0) {
+                       limitSmsCnt = MsgSettingGetInt(MSG_SMS_LIMIT);
+                       limitMmsCnt = MsgSettingGetInt(MSG_MMS_LIMIT);
+
+                       if (limitSmsCnt < 0 || limitMmsCnt < 0) {
+                               MSG_DEBUG("limitSmsCnt [%d], limitMmsCnt [%d]", limitSmsCnt, limitMmsCnt);
+                               return MSG_SUCCESS;
+                       }
+               } else { // !(currentSmsCnt > 0 || currentMmsCnt > 0)
+                       return MSG_SUCCESS;
+               }
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+#ifdef MSG_NOTI_INTEGRATION
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT DISTINCT(MSG_ID) FROM %s "
+                               "WHERE MSG_ID IN "
+                               "(SELECT MSG_ID FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0 "
+                               "AND MAIN_TYPE = %d ORDER BY MSG_ID ASC LIMIT %d) "
+                               "OR MSG_ID IN "
+                               "(SELECT MSG_ID FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0 "
+                               "AND MAIN_TYPE = %d AND SUB_TYPE NOT IN (%d, %d, %d) ORDER BY MSG_ID ASC LIMIT %d);",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE,
+                               MSG_SMS_TYPE, ((currentSmsCnt-limitSmsCnt)>0)?(currentSmsCnt-limitSmsCnt):0,
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE,
+                               MSG_MMS_TYPE, MSG_DELIVERYIND_MMS, MSG_READRECIND_MMS, MSG_READORGIND_MMS, ((currentMmsCnt-limitMmsCnt)>0)?(currentMmsCnt-limitMmsCnt):0);
+#else
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT DISTINCT(MSG_ID) FROM %s "
+                               "WHERE MSG_ID IN "
+                               "(SELECT MSG_ID FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0 "
+                               "AND MAIN_TYPE = %d ORDER BY MSG_ID ASC LIMIT %d) "
+                               "OR MSG_ID IN "
+                               "(SELECT MSG_ID FROM %s "
+                               "WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND PROTECTED = 0 "
+                               "AND MAIN_TYPE = %d AND SUB_TYPE NOT IN (%d, %d, %d) ORDER BY MSG_ID ASC LIMIT %d);",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE,
+                               MSG_SMS_TYPE, ((currentSmsCnt-limitSmsCnt)>0)?(currentSmsCnt-limitSmsCnt):0,
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE,
+                               MSG_MMS_TYPE, MSG_DELIVERYIND_MMS, MSG_READRECIND_MMS, MSG_READORGIND_MMS, ((currentMmsCnt-limitMmsCnt)>0)?(currentMmsCnt-limitMmsCnt):0);
+#endif
+               err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+               if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+                       MSG_DEBUG("Fail to getTable().");
+                       dbHandle->freeTable();
+                       return err;
+               }
+
+               if (rowCnt <= 0) {
+                       MSG_DEBUG("rowCnt <= 0");
+                       dbHandle->freeTable();
+                       return MSG_SUCCESS;
+               }
+
+               msgIdList->nCount = rowCnt;
+
+               MSG_DEBUG("msgIdList.nCount [%d]", msgIdList->nCount);
+
+               msgIdList->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t) * rowCnt];
+
+               for (int i = 0; i < rowCnt; i++) {
+                       msgIdList->msgIdList[i] = dbHandle->getColumnToInt(index++);
+               }
+
+               dbHandle->freeTable();
+
+               // delete message
+               err = MsgStoDeleteMessageByList(msgIdList);
+
+               //delete [] (char*)msgIdList.msgIdList;
+
+       } else {
+               MSG_DEBUG("bAutoErase [%d]", bAutoErase);
+       }
+
+       MSG_END();
+
+       return err;
+}
+
+
+msg_error_t MsgStoGetReplaceMsgId(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       msg_thread_id_t convId = 0;
+
+       /** Check if new address or not */
+       if (MsgExistAddress(dbHandle, pMsgInfo, &convId) == true) {
+               MSG_DEBUG("Address Info. exists [%d]", convId);
+
+               /**  Find Replace Type Msg : Same Replace Type, Same Origin Address, Same Storage ID */
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE SUB_TYPE = %d AND CONV_ID = %d AND STORAGE_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME, pMsgInfo->msgType.subType, convId, pMsgInfo->storageId);
+
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                       return MSG_ERR_DB_PREPARE;
+
+               if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       pMsgInfo->msgId = dbHandle->columnInt(0);
+               } else {
+                       dbHandle->finalizeQuery();
+                       return MSG_ERR_DB_STEP;
+               }
+
+               dbHandle->finalizeQuery();
+       }
+
+       return err;
+}
+
+
+msg_error_t MsgStoAddWAPMsg(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       MSG_PUSH_MESSAGE_S pushMsg = {};
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       int fileSize = 0;
+
+       char* pFileData = NULL;
+       AutoPtr<char> buf(&pFileData);
+
+       if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false)
+               return MSG_ERR_STORAGE_ERROR;
+
+       MSG_DEBUG("fileSize : %d", fileSize);
+
+       memcpy(&pushMsg, pFileData, fileSize);
+
+       /** Delete temporary file */
+       MsgDeleteFile(pMsgInfo->msgData);
+
+       /** check pPushMsg data */
+
+       MSG_DEBUG("check pushMsg data");
+       MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
+       MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
+       MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
+       MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
+       MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
+       MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
+       MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
+
+       bool bProceed = true;
+
+       /**  check validation of contents */
+       if (MsgStoCheckPushMsgValidation(&pushMsg, &bProceed) != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to check Push Message validation.");
+       }
+
+       /**  if validation check value is false */
+       /** return and drop message. */
+       if (bProceed == false)
+               return MSG_ERR_INVALID_MESSAGE;
+
+
+       /**  Update Msg Text - remove */
+       strncpy(pMsgInfo->msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
+
+       if (pushMsg.contents[0] != '\0') {
+               strncat(pMsgInfo->msgText, " ", MAX_MSG_TEXT_LEN - strlen(pMsgInfo->msgText));
+               strncat(pMsgInfo->msgText, pushMsg.contents, MAX_MSG_TEXT_LEN - strlen(pMsgInfo->msgText));
+       }
+
+       pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
+
+       pMsgInfo->bTextSms = true;
+       pMsgInfo->folderId = MSG_INBOX_ID;
+       pMsgInfo->storageId = MSG_STORAGE_PHONE;
+
+       msg_thread_id_t convId = 0;
+
+       dbHandle->beginTrans();
+
+       if (pMsgInfo->nAddressCnt > 0) {
+
+               err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
+
+               if (err != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return err;
+               }
+
+               pMsgInfo->threadId = convId;
+       }
+
+       /**  get last row count for Message id */
+       unsigned int rowId = 0;
+
+       /** Add Message Table */
+       rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
+
+       if (rowId <= 0) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_ROW;
+       }
+
+       pMsgInfo->msgId = (msg_message_id_t)rowId;
+
+       /**  add msg_push_table */
+       snprintf (sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %lu, %lu, ?, ?, ?)",
+                       MSGFW_PUSH_MSG_TABLE_NAME, pMsgInfo->msgId, pushMsg.action, pushMsg.created, pushMsg.expires);
+
+       if ((err = dbHandle->prepareQuery(sqlQuery)) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return err;
+       }
+
+       dbHandle->bindText(pushMsg.id, 1);
+
+       dbHandle->bindText(pushMsg.href, 2);
+
+       dbHandle->bindText(pushMsg.contents, 3);
+
+       if ((err = dbHandle->stepQuery()) != MSG_ERR_DB_DONE) {
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
+               return err;
+       }
+
+       dbHandle->finalizeQuery();
+
+       /** Update conversation table. */
+       if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_STORAGE_ERROR;
+       }
+
+       dbHandle->endTrans(true);
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoAddCOWAPMsg(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       char href[MAX_PUSH_CACHEOP_MAX_URL_LEN+1];
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       int fileSize = 0;
+
+       char* pFileData = NULL;
+       AutoPtr<char> buf(&pFileData);
+
+       if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false)
+               return MSG_ERR_STORAGE_ERROR;
+
+       MSG_PUSH_CACHEOP_S *pPushMsg;
+
+       pPushMsg = (MSG_PUSH_CACHEOP_S*)pFileData;
+
+       for (int i = 0; i < pPushMsg->invalObjectCnt; i++) {
+
+               int msgid = -1;
+
+               memset(href, 0x00, sizeof(href));
+               strncpy(href, &(pPushMsg->invalObjectUrl[i][0]), MAX_PUSH_CACHEOP_MAX_URL_LEN);
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf (sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE HREF LIKE '%%%s%%';", MSGFW_PUSH_MSG_TABLE_NAME, href);
+
+               dbHandle->beginTrans();
+
+               err = dbHandle->prepareQuery(sqlQuery);
+
+               if ((dbHandle->stepQuery() == MSG_ERR_DB_ROW) && err == MSG_SUCCESS) {
+
+                       msgid = dbHandle->getColumnToInt(1);
+
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID= %d;", MSGFW_PUSH_MSG_TABLE_NAME, msgid);
+
+                       /** Delete Message from Push table */
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgid);
+
+                       /** Delete Message from msg table */
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+
+                       /** Update all Address */
+                       if (MsgStoUpdateAllAddress() != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+
+                       /** Clear Conversation table */
+                       if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+               }
+
+               dbHandle->finalizeQuery();
+
+               dbHandle->endTrans(true);
+       }
+
+       for (int i = 0; i < pPushMsg->invalServiceCnt; i++) {
+
+               int msgid = -1;
+
+               memset(href, 0x00, sizeof(href));
+               strncpy(href, &(pPushMsg->invalObjectUrl[i][0]), MAX_PUSH_CACHEOP_MAX_URL_LEN);
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE HREF LIKE '%%%s%%'", MSGFW_PUSH_MSG_TABLE_NAME, href);
+
+               dbHandle->beginTrans();
+
+               err = dbHandle->prepareQuery(sqlQuery);
+
+               if ((dbHandle->stepQuery() == MSG_ERR_DB_ROW) && err == MSG_SUCCESS) {
+
+                       msgid = dbHandle->getColumnToInt(1);
+
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID='%d'", MSGFW_PUSH_MSG_TABLE_NAME, msgid);
+
+                       /** Delete Message from Push table */
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgid);
+
+                       /** Delete Message from msg table */
+                       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+
+                       /**  Update all Address */
+                       if (MsgStoUpdateAllAddress() != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+
+                       /** Clear Address table */
+                       if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(false);
+                               continue;
+                       }
+               }
+
+               dbHandle->finalizeQuery();
+
+               dbHandle->endTrans(true);
+       }
+
+       /** delete temporary file */
+       MsgDeleteFile(pMsgInfo->msgData);
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoAddCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       unsigned int rowId = 0;
+       msg_thread_id_t convId = 0;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       dbHandle->beginTrans();
+
+       if (pMsgInfo->nAddressCnt > 0) {
+               err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
+
+               if (err != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
+                       return err;
+               }
+
+               pMsgInfo->threadId = convId;
+       }
+
+       /**  Add Message Table */
+       rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
+
+       if (rowId <= 0) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_ROW;
+       }
+
+       /**  Get CB Msg ID */
+       unsigned short cbMsgId = (unsigned short)pMsgInfo->msgId;
+
+       /** Add CB Msg in MSG_CBMSG_TABLE */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
+                       MSGFW_CB_MSG_TABLE_NAME, rowId, cbMsgId);
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
+       }
+
+       /**  Update conversation table. */
+       if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_STORAGE_ERROR;
+       }
+
+       dbHandle->endTrans(true);
+
+       /** Assign Msg ID */
+       pMsgInfo->msgId = (msg_message_id_t)rowId;
+
+       return err;
+}
+
+
+msg_error_t MsgStoCheckPushMsgValidation(MSG_PUSH_MESSAGE_S *pPushMsg, bool *pbProceed)
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       unsigned long oldExpireTime = 0;
+       int rowCnt = 0;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       /**  is push message is expired?? */
+       if (pPushMsg->received > pPushMsg->expires) {
+               MSG_DEBUG("Push Message is expired.");
+               pbProceed = false;
+               return err;
+       }
+
+       if (pPushMsg->action == MSG_PUSH_SL_ACTION_EXECUTE_LOW) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXPIRES FROM %s WHERE ID = '%s' AND ACTION = %d",
+                               MSGFW_PUSH_MSG_TABLE_NAME, pPushMsg->id, pPushMsg->action);
+       } else {
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXPIRES FROM %s WHERE ID = '%s'",
+                               MSGFW_PUSH_MSG_TABLE_NAME, pPushMsg->id);
+       }
+
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (rowCnt < 1) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
+       }
+
+       oldExpireTime = dbHandle->getColumnToInt(1);
+
+       dbHandle->freeTable();
+
+       if (pPushMsg->created < oldExpireTime) {
+               MSG_DEBUG("Push Message is expired.");
+               pbProceed = false;
+               return err;
+       }
+
+       return err;
+}
+
+
+msg_error_t MsgStoUpdateAllAddress()
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+       int rowCnt = 0, index = 1;
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_ID FROM %s", MSGFW_ADDRESS_TABLE_NAME);
+
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if ( err != MSG_SUCCESS) {
+               dbHandle->freeTable();
+               return err;
+       }
+
+       for (int i = 0; i < rowCnt; i++) {
+
+               err = MsgStoUpdateConversation(dbHandle, index++);
+
+               if (err != MSG_SUCCESS)
+                       break;
+       }
+
+       dbHandle->freeTable();
+
+       return err;
+}
+
index 7cf32bc..ce7e5b9 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -27,7 +27,6 @@
 #include "MsgSubmitHandler.h"
 
 
-extern MsgDbHandler dbHandle;
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
@@ -35,7 +34,6 @@ extern MsgDbHandler dbHandle;
 msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
 {
        msg_error_t err = MSG_SUCCESS;
-
        static int reqId = 1;
 
        pReqInfo->reqId = reqId;
@@ -43,11 +41,12 @@ msg_error_t MsgSubmitReq(MSG_REQUEST_INFO_S *pReqInfo, bool bScheduled)
 
        MSG_DEBUG("==== Msg ID = [%d] ====", pReqInfo->msgInfo.msgId);
        MSG_DEBUG("==== Folder ID = [%d] ====", pReqInfo->msgInfo.folderId);
-       MSG_DEBUG("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
-       MSG_DEBUG("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
+       MSG_INFO("==== Main Type = [%d] ====", pReqInfo->msgInfo.msgType.mainType);
+       MSG_INFO("==== Sub Type = [%d] ====", pReqInfo->msgInfo.msgType.subType);
        MSG_DEBUG("==== Class Type = [%d] ====", pReqInfo->msgInfo.msgType.classType);
        MSG_DEBUG("==== Message Data = [%s] ====", pReqInfo->msgInfo.msgData);
        MSG_DEBUG("==== Message Text = [%s] ====", pReqInfo->msgInfo.msgText);
+       MSG_INFO("==== SIM Index = [%d] ====", pReqInfo->msgInfo.sim_idx);
 
        MSG_DEBUG("==== bSetting = [%d] ====", pReqInfo->sendOptInfo.bSetting);
 
@@ -82,10 +81,8 @@ msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
        MSG_MAIN_TYPE_T mainType = pReqInfo->msgInfo.msgType.mainType;
        MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
 
-       if (plg == NULL) {
-               MSG_DEBUG("No Plugin for %d type", mainType);
-               return MSG_ERR_UNKNOWN;
-       }
+       if (plg == NULL)
+               THROW(MsgException::PLUGIN_ERROR, "No plugin for %d type", mainType);
 
        // If MSG ID > 0 -> MSG in DRAFT
        // Move Folder to OUTBOX
@@ -101,19 +98,32 @@ msg_error_t MsgSubmitReqSMS(MSG_REQUEST_INFO_S *pReqInfo)
        return err;
 }
 
-
 msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
 {
        msg_error_t err = MSG_SUCCESS;
-
+       MsgDbHandler *dbHandle = getDbHandle();
        MSG_RECIPIENTS_LIST_S pRecipientList;
 
+       MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
+
+       int defaultNetworkSimId = 0;
+
+       err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
+       if (err != MSG_SUCCESS) {
+               MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
+               return err;
+       } else if (pReqInfo->msgInfo.sim_idx != defaultNetworkSimId) {
+               MSG_ERR("It is not default network SIM ID, request SIM=[%d], activated SIM=[%d]", pReqInfo->msgInfo.sim_idx, defaultNetworkSimId);
+               return MSG_ERR_INVALID_PARAMETER;
+
+       }
+
        MSG_MAIN_TYPE_T msgMainType = pReqInfo->msgInfo.msgType.mainType;
        MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
 
        if(!plg)
        {
-               MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
                MSG_DEBUG("No Plugin for %d type", msgMainType);
 
                return MSG_ERR_INVALID_PLUGIN_HANDLE;
@@ -131,9 +141,9 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
                // copy whole of MMS PDU filepath to msgData
                strncpy(fileName, pReqInfo->msgInfo.msgData, MAX_COMMON_INFO_SIZE);
                memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
-               snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_IPC_DATA_PATH"%s", fileName);
+               snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%s", MSG_IPC_DATA_PATH, fileName);
 
-               MSG_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
+               MSG_SEC_DEBUG("JAVA MMS PDU filepath:%s", pReqInfo->msgInfo.msgData);
 
                // submit request
                err = plg->submitReq(pReqInfo);
@@ -141,72 +151,59 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
                if(err != MSG_SUCCESS)
                {
                        MSG_DEBUG("Update Network Status : [%d]", err);
-                       MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo),MSG_NETWORK_SEND_FAIL);
                }
 
                return err;
        }
        else if((pReqInfo->msgInfo.msgType.subType == MSG_SENDREQ_MMS) || (pReqInfo->msgInfo.msgType.subType == MSG_FORWARD_MMS))
        {
-               // update address list in the ase of existing message
-               if(pReqInfo->msgInfo.msgId > 0)
-               {
-                       err = MsgStoGetOrgAddressList(&(pReqInfo->msgInfo));
-
-                       if(err != MSG_SUCCESS)
-                               MSG_DEBUG("[WARNING]MsgStoGetOrgAddressList returned not a MSG_SUCCESS");
-               }
-
                if(pReqInfo->msgInfo.msgId > 0 && (pReqInfo->msgInfo.folderId == MSG_DRAFT_ID || pReqInfo->msgInfo.folderId == MSG_OUTBOX_ID)) {
-                       MSG_ADDRESS_INFO_S addrInfo = {0,};
-                       int addrIdx = 0;
-
-                       err = MsgStoGetAddrInfo(pReqInfo->msgInfo.msgId, &addrInfo);
-
-                       if (err == MSG_SUCCESS) {
-                               for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) {
-                                       //if (pReqInfo->msgInfo.addressList[i].threadId == addrInfo.threadId) {
-                                       if (!strcmp(pReqInfo->msgInfo.addressList[i].addressVal, addrInfo.addressVal)) {
-                                               addrIdx = i;
-                                               MSG_DEBUG("addrIdx = %d, address = [%s]", addrIdx, pReqInfo->msgInfo.addressList[i].addressVal);
-                                               break;
-                                       }
-                               }
-                       } else {
-                               MSG_DEBUG("[Error]MsgStoGetAddrInfo is failed");
-                       }
-
+                       MSG_DEBUG("Not New Message.");
                        pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
                        err = MsgStoUpdateMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
-
-                       MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
                } else {
-                       //new message case
-                       MSG_DEBUG("New Message");
+                       MSG_DEBUG("New Message.");
+                       pReqInfo->msgInfo.msgId = 0;
                        pReqInfo->msgInfo.folderId = MSG_OUTBOX_ID;
                        err = MsgStoAddMessage(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo));
-                       //pReqInfo->msgInfo.msgId = 0;
                }
        }
        else if(pReqInfo->msgInfo.msgType.subType == MSG_READREPLY_MMS)
        {
+               msg_read_report_status_t readStatus;
+
                err = MsgStoCheckReadReportStatus(pReqInfo->msgInfo.msgId);
-               if(err != MSG_SUCCESS)
+               if(err != MSG_SUCCESS) {
+
+                       MSG_INFO("msg id [%d], read report could NOT send [%d]", pReqInfo->msgInfo.msgId, err);
+                       return err;
+               }
+
+               memcpy(&readStatus, pReqInfo->msgInfo.msgData, sizeof(msg_read_report_status_t));
+               if (readStatus == MSG_READ_REPORT_REJECT_BY_USER) {
+
+                       MSG_INFO("msg id [%d], read report reject by user", pReqInfo->msgInfo.msgId);
+
+                       err = MsgStoSetReadReportSendStatus(pReqInfo->msgInfo.msgId, MMS_RECEIVE_READ_REPORT_NO_SENT);
+
                        return err;
+               }
 
                err = MsgStoGetRecipientList(pReqInfo->msgInfo.msgId, &pRecipientList);
                if(err != MSG_SUCCESS)
                        return MSG_ERR_PLUGIN_STORAGE;
 
                pReqInfo->msgInfo.nAddressCnt = pRecipientList.recipientCnt;
+               pReqInfo->msgInfo.addressList = pRecipientList.recipientAddr;
 
-               for(int i = 0; i < pRecipientList.recipientCnt; i++)
-               {
-                       pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
-                       pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
-                       pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
-                       strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
-               }
+//                     for(int i = 0; i < pRecipientList.recipientCnt; i++)
+//                     {
+//                             pReqInfo->msgInfo.addressList[i].addressType = pRecipientList.recipientAddr[i].addressType;
+//                             pReqInfo->msgInfo.addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
+//                             pReqInfo->msgInfo.addressList[i].contactId = pRecipientList.recipientAddr[i].contactId;
+//                             strncpy(pReqInfo->msgInfo.addressList[i].addressVal, pRecipientList.recipientAddr[i].addressVal, MAX_ADDRESS_VAL_LEN);
+//                     }
 
                char subject[MAX_SUBJECT_LEN+1];
 
@@ -220,7 +217,7 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
        }
        else if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS)
        {
-               MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), pReqInfo->msgInfo.networkStatus);
        }
 
        /* reject_msg_support */
@@ -237,7 +234,7 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
                case MSG_FORWARD_MMS:
                        MsgDeleteFile(pReqInfo->msgInfo.msgData);
                        memset(pReqInfo->msgInfo.msgData, 0x00, MAX_MSG_DATA_LEN+1);
-                       snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pReqInfo->msgInfo.msgId);
+                       snprintf(pReqInfo->msgInfo.msgData, MAX_MSG_DATA_LEN+1, "%s%d.mms", MSG_DATA_PATH, pReqInfo->msgInfo.msgId);
                        break;
 
                case MSG_READREPLY_MMS:
@@ -256,12 +253,15 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
        /* reject_msg_support */
 
        // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
 
        if(simStatus == MSG_SIM_STATUS_NOT_FOUND)
        {
                MSG_DEBUG("SIM is not present...");
-               MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+               MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
 
                return MSG_ERR_NO_SIM;
        }
@@ -275,16 +275,15 @@ msg_error_t MsgSubmitReqMMS(MSG_REQUEST_INFO_S *pReqInfo)
        if (err != MSG_SUCCESS)
        {
                if(pReqInfo->msgInfo.msgType.subType == MSG_RETRIEVE_MMS )
-                       MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_RETRIEVE_FAIL);
                else
-                       MsgStoUpdateNetworkStatus(&dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+                       MsgStoUpdateNetworkStatus(dbHandle, &(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
        }
 
 
        return err;
 }
 
-
 msg_error_t MsgCancelReq(msg_request_id_t reqId)
 {
        msg_error_t err = MSG_SUCCESS;
index 1313a57..d1a6730 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
index 3c039b8..00c4229 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -97,11 +97,30 @@ int MsgGetConfigHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        int eventType = -1;
 
        // Get Option Type
-       MSG_OPTION_TYPE_T* type = (MSG_OPTION_TYPE_T*)pCmd->cmdData;
+       MSG_OPTION_TYPE_T type = 0;
+       memcpy((void *)&type, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_OPTION_TYPE_T));
 
        // Get Config Data
        MSG_SETTING_S setting;
-       setting.type = *type;
+       setting.type = type;
+
+       msg_sim_slot_id_t simIndex = 0;
+       switch(setting.type) {
+       case MSG_CBMSG_OPT :
+               memcpy(&simIndex, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), sizeof(msg_sim_slot_id_t));
+               setting.option.cbMsgOpt.simIndex = simIndex;
+               break;
+       case MSG_VOICEMAIL_OPT :
+               memcpy(&simIndex, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), sizeof(msg_sim_slot_id_t));
+               setting.option.voiceMailOpt.simIndex = simIndex;
+               break;
+       case MSG_SMSC_LIST :
+               memcpy(&simIndex, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), sizeof(msg_sim_slot_id_t));
+               setting.option.smscList.simIndex = simIndex;
+               break;
+       default :
+               break;
+       }
 
        err = MsgGetConfigData(&setting);
 
index 5ba9191..e8b5f56 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdlib.h>
 #include "MsgStorageHandler.h"
 #include "MsgPluginManager.h"
 #include "MsgTransManager.h"
-#include "MsgContact.h"
 #include "MsgCmdHandler.h"
-
+#include "MsgNotificationWrapper.h"
+#include "MsgMutex.h"
+#include <glib.h>
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
+
+Mutex mx;
+int g_job_cnt = 0;
+
+static gboolean  __refresh_noti(void *data)
+{
+       mx.lock();
+
+       g_job_cnt--;
+
+       if (g_job_cnt <= 0) {
+               MSG_DEBUG("## Refresh notification ##");
+               if (MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, false, false) != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgRefreshNoti is failed");
+               }
+               g_job_cnt = 0;
+       }
+
+       mx.unlock();
+
+       return FALSE;
+
+}
+
 int MsgAddMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
        msg_error_t err = MSG_SUCCESS;
@@ -41,27 +66,43 @@ int MsgAddMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        int dataSize = 0, eventSize = 0;
 
-       // Get Message Info
-       MSG_MESSAGE_INFO_S* pMsgInfo = (MSG_MESSAGE_INFO_S*)pCmd->cmdData;
+       MSG_MESSAGE_INFO_S msgInfo;
+       MSG_SENDINGOPT_INFO_S sendOptInfo;
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+       memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
 
-       // Get Sending Option
-       MSG_SENDINGOPT_INFO_S* pSendOptInfo = (MSG_SENDINGOPT_INFO_S*)(pCmd->cmdData + sizeof(MSG_MESSAGE_INFO_S));
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
-       // Add Message
-       err = MsgStoAddMessage(pMsgInfo, pSendOptInfo);
+       MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo, &sendOptInfo);
 
-       if (err == MSG_SUCCESS) {
-                       MSG_DEBUG("Command Handle Success : MsgStoAddMessage()");
+       if(msgInfo.threadId) // threadId is not 0 : message restore from S-Cloud
+       {
+               err = MsgStoRestoreMessage(&msgInfo, &sendOptInfo);
+
+               if (err == MSG_SUCCESS) {
+                               MSG_DEBUG("Command Handle Success : MsgStoRestoreMessage()");
 
+                               // Encoding Message ID
+                               dataSize = MsgEncodeMsgId(&(msgInfo.msgId), &encodedData);
+               } else {
+                       MSG_DEBUG("Command Handle Fail : MsgStoRestoreMessage()");
+               }
+       }
+       else
+       {
+               // Add Message
+               msgInfo.msgId = 0;
+               err = MsgStoAddMessage(&msgInfo, &sendOptInfo);
+
+               if (err == MSG_SUCCESS) {
+                       MSG_DEBUG("Command Handle Success : MsgStoAddMessage()");
                        // Encoding Message ID
-                       dataSize = MsgEncodeMsgId(&(pMsgInfo->msgId), &encodedData);
+                       dataSize = MsgEncodeMsgId(&(msgInfo.msgId), &encodedData);
                } else {
                        MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
                }
-
-       // Delete Temp File for Message Data
-       if (pMsgInfo->bTextSms == false)
-               MsgDeleteFile(pMsgInfo->msgData); //ipc
+       }
 
        //storage change CB
        msg_id_list_s msgIdList;
@@ -69,11 +110,23 @@ int MsgAddMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
 
        msgIdList.nCount = 1;
-       msgIds[0] = pMsgInfo->msgId;
+       msgIds[0] = msgInfo.msgId;
        msgIdList.msgIdList = msgIds;
 
        MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
 
+       // Update unread message status
+       if (msgInfo.folderId == MSG_INBOX_ID && msgInfo.bRead == false) {
+               mx.lock();
+               g_job_cnt++;
+               g_timeout_add(300, __refresh_noti, NULL);
+               mx.unlock();
+       }
+
+       // Delete Temp File for Message Data
+       if (msgInfo.bTextSms == false)
+               MsgDeleteFile(msgInfo.msgData); //ipc
+
        // Make Event Data
        eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_ADD_MSG, err, (void**)ppEvent);
 
@@ -85,16 +138,25 @@ int MsgAddSyncMLMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       int eventSize = 0;
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+
+       int dataSize = 0, eventSize = 0;
 
        int extId = 0, pinCode = 0;
 
-       MSG_MESSAGE_INFO_S msgInfo = {};
+       MSG_MESSAGE_INFO_S msgInfo;
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
        memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
        memcpy(&pinCode, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), sizeof(int));
-       memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), sizeof(MSG_MESSAGE_INFO_S));
 
+       MsgDecodeMsgInfo((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int), &msgInfo);
+
+       msgInfo.msgId = 0;
        // Add Message
        err = MsgStoAddSyncMLMessage(&msgInfo, extId, pinCode);
 
@@ -102,6 +164,9 @@ int MsgAddSyncMLMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        {
                MSG_DEBUG("Command Handle Success : MsgStoAddSyncMLMessage()");
 
+               // Encoding Message ID
+               dataSize = MsgEncodeMsgId(&(msgInfo.msgId), &encodedData);
+
                // broadcast to listener threads, here
                MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
                //storage change CB
@@ -121,7 +186,7 @@ int MsgAddSyncMLMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        }
 
        // Make Event Data
-       eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_SYNCML_MSG, err, (void**)ppEvent);
+       eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_ADD_SYNCML_MSG, err, (void**)ppEvent);
 
        return eventSize;
 }
@@ -133,14 +198,18 @@ int MsgUpdateMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        int eventSize = 0;
 
-       // Get Message Info
-       MSG_MESSAGE_INFO_S* pMsgInfo = (MSG_MESSAGE_INFO_S*)pCmd->cmdData;
+       MSG_MESSAGE_INFO_S msgInfo;
+       MSG_SENDINGOPT_INFO_S sendOptInfo;
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+       memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
-       // Get Sending Option
-       MSG_SENDINGOPT_INFO_S* pSendOptInfo = (MSG_SENDINGOPT_INFO_S*)(pCmd->cmdData + sizeof(MSG_MESSAGE_INFO_S));
+       MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo, &sendOptInfo);
 
        // Update Message
-       err = MsgStoUpdateMessage(pMsgInfo, pSendOptInfo);
+       err = MsgStoUpdateMessage(&msgInfo, &sendOptInfo);
 
        if (err == MSG_SUCCESS)
                MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
@@ -148,8 +217,8 @@ int MsgUpdateMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                MSG_DEBUG("Command Handle Fail : MsgStoUpdateMessage()");
 
        // Delete Temp File for Message Data
-       if (pMsgInfo->bTextSms == false)
-               MsgDeleteFile(pMsgInfo->msgData); //ipc
+       if (msgInfo.bTextSms == false)
+               MsgDeleteFile(msgInfo.msgData); //ipc
 
        //storage change CB
        msg_id_list_s msgIdList;
@@ -157,7 +226,7 @@ int MsgUpdateMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
 
        msgIdList.nCount = 1;
-       msgIds[0] = pMsgInfo->msgId;
+       msgIds[0] = msgInfo.msgId;
        msgIdList.msgIdList = msgIds;
 
        MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
@@ -184,6 +253,8 @@ int MsgUpdateReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        // Update Read Status
        err = MsgStoUpdateReadStatus(msgId, readStatus);
 
+       MSG_DEBUG("message id = [%d], readStatus = [%d]", msgId, readStatus);
+
        if (err == MSG_SUCCESS)
        {
                MSG_DEBUG("Command Handle Success : MsgStoUpdateReadStatus()");
@@ -193,6 +264,17 @@ int MsgUpdateReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                MSG_DEBUG("Command Handle Fail : MsgStoUpdateReadStatus()");
        }
 
+       //storage change CB
+       msg_id_list_s msgIdList;
+       msg_message_id_t msgIds[1];
+       memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+
+       msgIdList.nCount = 1;
+       msgIds[0] = msgId;
+       msgIdList.msgIdList = msgIds;
+
+       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+
        // Make Event Data
        eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_READ, err, (void**)ppEvent);
 
@@ -217,12 +299,47 @@ int MsgUpdateThreadReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        if (unReadCnt > 0) {
 
-               err = MsgStoUpdateThreadReadStatus(threadId);
+               msg_id_list_s msgIdList;
+               memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+
+               err = MsgStoUpdateThreadReadStatus(threadId, &msgIdList);
 
-               if (err == MSG_SUCCESS)
+               if (err == MSG_SUCCESS) {
                        MSG_DEBUG("Command Handle Success : MsgStoUpdateThreadReadStatus()");
-               else
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+               } else {
                        MSG_DEBUG("Command Handle Fail : MsgStoUpdateThreadReadStatus()");
+               }
+
+               if(msgIdList.msgIdList != NULL)
+                       delete [] (char*)msgIdList.msgIdList;
+       }
+
+       // delete report notification
+       if (err == MSG_SUCCESS) {
+               MsgDbHandler *dbHandle = getDbHandle();
+               char tempAddr[MAX_ADDRESS_VAL_LEN+1];
+               char sqlQuery[MAX_QUERY_LEN+1];
+
+               memset(tempAddr, 0x00 ,sizeof(tempAddr));
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               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;"
+                               , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, threadId);
+
+               err = dbHandle->prepareQuery(sqlQuery);
+
+               if (err == MSG_SUCCESS) {
+                       err = dbHandle->stepQuery();
+
+                       if (err == MSG_ERR_DB_ROW) {
+                               snprintf(tempAddr, sizeof(tempAddr), "%s", dbHandle->columnText(0));
+                               MSG_DEBUG("Updated address = %s", tempAddr);
+                               MsgDeleteReportNotification(tempAddr);
+                               err = MSG_SUCCESS;
+                       }
+               }
+
+               dbHandle->finalizeQuery();
        }
 
        // Make Event Data
@@ -257,6 +374,17 @@ int MsgUpdateProtectedStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                MSG_DEBUG("Command Handle Fail : MsgStoUpdateProtectedStatus()");
        }
 
+       //storage change CB
+       msg_id_list_s msgIdList;
+       msg_message_id_t msgIds[1];
+       memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+
+       msgIdList.nCount = 1;
+       msgIds[0] = msgId;
+       msgIdList.msgIdList = msgIds;
+
+       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+
        // Make Event Data
        eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_PROTECTED, err, (void**)ppEvent);
 
@@ -541,6 +669,9 @@ int MsgGetMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
        memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        err = MsgStoGetMessage(*msgId, &msgInfo, &sendOptInfo);
 
        if (err == MSG_SUCCESS)
@@ -566,8 +697,6 @@ int MsgGetMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
 int MsgGetFolderViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
-       msg_error_t err = MSG_SUCCESS;
-
        // Get Folder ID
        msg_folder_id_t folderId;
        MSG_SORT_RULE_S sortRule;
@@ -580,10 +709,11 @@ int MsgGetFolderViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        int dataSize = 0, eventSize = 0;
 
+#if 0
        // Get Message Common Info
        msg_struct_list_s folderViewList;
 
-       err = MsgStoGetFolderViewList(folderId, &sortRule, &folderViewList);
+//     err = MsgStoGetFolderViewList(folderId, &sortRule, &folderViewList);
 
        if (err == MSG_SUCCESS)
        {
@@ -605,7 +735,7 @@ int MsgGetFolderViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                MSG_DEBUG("Command Handle Fail : MsgStoGetFolderViewList()");
                return err;
        }
-
+#endif
        // Make Event Data
        eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FOLDERVIEWLIST, MSG_SUCCESS, (void**)ppEvent);
 
@@ -790,6 +920,7 @@ int MsgGetMsgTypeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
 int MsgGetThreadViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
+
        msg_error_t err = MSG_SUCCESS;
 
        MSG_SORT_RULE_S sortRule = {0};
@@ -800,11 +931,11 @@ int MsgGetThreadViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        AutoPtr<char> buf(&encodedData);
 
        int dataSize = 0, eventSize = 0;
-
+#if 0
        // Get Thread View List
        msg_struct_list_s msgThreadViewList;
 
-       err = MsgStoGetThreadViewList(&sortRule, &msgThreadViewList);
+       //err = MsgStoGetThreadViewList(&sortRule, &msgThreadViewList);
 
        if (err == MSG_SUCCESS)
        {
@@ -826,7 +957,7 @@ int MsgGetThreadViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                MSG_DEBUG("Command Handle Fail : MsgStoGetThreadViewList()");
                return err;
        }
-
+#endif
        // Make Event Data
        eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREADVIEWLIST, err, (void**)ppEvent);
 
@@ -846,10 +977,10 @@ int MsgGetConversationViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        AutoPtr<char> buf(&encodedData);
 
        int dataSize = 0, eventSize = 0;
-
+#if 0
        msg_struct_list_s convViewList;
 
-       err = MsgStoGetConversationViewList(threadId, &convViewList);
+       //err = MsgStoGetConversationViewList(threadId, &convViewList);
 
        if (err == MSG_SUCCESS)
        {
@@ -870,7 +1001,7 @@ int MsgGetConversationViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        {
                MSG_DEBUG("Command Handle Fail : MsgStoGetConversationViewList()");
        }
-
+#endif
        // Make Event Data
        eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_CONVERSATIONVIEWLIST, err, (void**)ppEvent);
 
@@ -978,9 +1109,11 @@ int MsgGetQuickPanelDataHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        // Get Message
        MSG_MESSAGE_INFO_S msgInfo;
-
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        err = MsgStoGetQuickPanelData(*type, &msgInfo);
 
        if (err == MSG_SUCCESS)
@@ -1077,15 +1210,30 @@ int MsgRestoreMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        msg_error_t err = MSG_SUCCESS;
 
        int eventSize = 0;
+       msg_id_list_s *msgIdList = NULL;
        char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
        memcpy(&path, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(path));
        MSG_DEBUG("path = %s", path);
+
        // Reset DB
-       err = MsgStoRestoreMessage(path);
+       err = MsgStoRestoreMessage(path, &msgIdList);
 
-       if (err == MSG_SUCCESS)
+       if (err == MSG_SUCCESS) {
                MSG_DEBUG("Command Handle Success : MsgStoRestoreMessage()");
-       else
+
+               if (msgIdList) {
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, msgIdList);
+
+                       if (msgIdList->msgIdList)
+                               free(msgIdList->msgIdList);
+
+                       free(msgIdList);
+                       msgIdList = NULL;
+               } else {
+                       MSG_DEBUG("Not Exist msg id list to restore");
+               }
+
+       } else
                MSG_DEBUG("Command Handle Fail : MsgStoRestoreMessage()");
 
        // Make Event Data
@@ -1101,6 +1249,7 @@ int MsgGetReportStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        // Get Message ID
        msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
+       MSG_MESSAGE_TYPE_S msgType = {0,};
 
        char* encodedData = NULL;
        AutoPtr<char> buf(&encodedData);
@@ -1110,7 +1259,17 @@ int MsgGetReportStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        MSG_REPORT_STATUS_INFO_S *reportStatus = NULL;
        int report_count = 0;
 
-       err = MsgStoGetReportStatus(*msgId, &report_count, &reportStatus);
+       if (MsgStoGetMsgType(*msgId, &msgType) != MSG_SUCCESS)
+               MSG_DEBUG("MsgStoGetMsgType is failed");
+
+       if (msgType.mainType == MSG_SMS_TYPE) {
+               err = MsgStoGetSmsReportStatus(*msgId, &report_count, &reportStatus);
+       } else if (msgType.mainType == MSG_MMS_TYPE) {
+               err = MsgStoGetMmsReportStatus(*msgId, &report_count, &reportStatus);
+       } else {
+               MSG_DEBUG("Message Type is unknown!");
+               err = MSG_ERR_INVALID_MSG_TYPE;
+       }
 
        if (err == MSG_SUCCESS)
        {
@@ -1138,10 +1297,16 @@ int MsgGetThreadIdByAddressHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        MSG_MESSAGE_INFO_S msgInfo;
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        int *addrCnt = (int *)pCmd->cmdData;
        MSG_DEBUG("*addrCnt [%d]", *addrCnt);
 
        msgInfo.nAddressCnt = *addrCnt;
+
+       msgInfo.addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * msgInfo.nAddressCnt];
+
        for(int i=0; i<msgInfo.nAddressCnt; i++)
                memcpy(&msgInfo.addressList[i], (MSG_ADDRESS_INFO_S *)(pCmd->cmdData+sizeof(int)+(sizeof(MSG_ADDRESS_INFO_S)*i)), sizeof(MSG_ADDRESS_INFO_S));
 
@@ -1413,7 +1578,7 @@ int MsgAddPushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        if (err == MSG_SUCCESS) {
                MSG_DEBUG("Command Handle Success : MsgStoAddPushEvent()");
        } else {
-               MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
+               MSG_DEBUG("Command Handle Fail : MsgStoAddPushEvent()");
        }
 
        // Make Event Data
@@ -1472,18 +1637,105 @@ int MsgUpdatePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        return eventSize;
 }
 
+int MsgAddSimMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       int eventSize = 0;
+
+       MSG_MESSAGE_INFO_S msgInfo;
+       MSG_SENDINGOPT_INFO_S sendOptInfo;
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+       memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+       MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo);
+
+       int *simIdList = NULL;
+       int listSize = 0;
+       char *offset = NULL;
+       offset = ((char *)pCmd->cmdData) + sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S) * msgInfo.nAddressCnt);
+
+       listSize = *(int*)offset;
+       offset += sizeof(int);
+       MSG_DEBUG("listSize [%d]", listSize);
+
+       simIdList = (int *)offset;
+
+       MSG_DEBUG("simIdList[0] [%d]", simIdList[0]);
+
+       // Add Message
+#if 0 // Not to broadcast callback here.
+       bool isReplaceMsg = false;
+
+       if (msgInfo.msgId <= 0)
+               msgInfo.msgId = 0;
+       else
+               isReplaceMsg = true;
+#else
+        if (msgInfo.msgId <= 0)
+                msgInfo.msgId = 0;
+#endif
+
+       msg_message_id_t msg_id = MsgStoAddSimMessage(&msgInfo, simIdList, listSize);
+
+       if (msg_id > 0) {
+               MSG_DEBUG("Command Handle Success : MsgStoAddSimMessage()");
+
+#if 0 // Not to broadcast callback here.
+               //storage change CB
+               msg_id_list_s msgIdList;
+               msg_message_id_t msgIds[1];
+               memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+
+               msgIdList.nCount = 1;
+               msgIds[0] = msgInfo.msgId;
+               msgIdList.msgIdList = msgIds;
+
+               if (isReplaceMsg)
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+               else
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
+#endif
+       } else {
+                       MSG_DEBUG("Command Handle Fail : MsgStoAddSimMessage()");
+                       err = MSG_ERR_INVALID_MESSAGE;
+       }
+
+       // Delete Temp File for Message Data
+       if (msgInfo.bTextSms == false)
+               MsgDeleteFile(msgInfo.msgData); //ipc
+
+       // Make Event Data
+       eventSize = MsgMakeEvent((const void *)&msg_id, sizeof(msg_message_id_t), MSG_EVENT_ADD_SIM_MSG, err, (void**)ppEvent);
+
+       return eventSize;
+}
+
 
-int MsgContactSyncEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
+int MsgUpdateIMSIHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
        msg_error_t err = MSG_SUCCESS;
 
 
        int eventSize = 0;
 
-       MsgSyncContact();
+       int sim_idx = 0;
+       memcpy(&sim_idx, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
+
+       // Add Message
+       err = MsgStoUpdateIMSI(sim_idx);
+
+       if (err == MSG_SUCCESS) {
+               MSG_DEBUG("Command Handle Success : MsgStoUpdatePushEvent()");
+       } else {
+               MSG_DEBUG("Command Handle Fail : MsgStoUpdatePushEvent()");
+       }
 
        // Make Event Data
-       eventSize = MsgMakeEvent(NULL, 0, MSG_EVNET_CONTACT_SYNC, err, (void**)ppEvent);
+       eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_IMSI, err, (void**)ppEvent);
 
        return eventSize;
 }
index 694cbff..6fc4008 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <time.h>
 #include "MsgStorageHandler.h"
 #include "MsgTransManager.h"
 #include "MsgPluginManager.h"
-#include "MsgCmdHandler.h"
 #include "MsgUtilStorage.h"
+#include "MsgAlarm.h"
+#include "MsgCmdHandler.h"
+#include "MsgDevicedWrapper.h"
 
-#include <alarm.h>
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
@@ -47,11 +48,16 @@ int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        MSG_REQUEST_INFO_S reqInfo = {0,};
        MSG_PROXY_INFO_S proxyInfo = {0,};
 
+       reqInfo.msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&reqInfo.msgInfo.addressList);
+
        // Get Message Request
-       memcpy(&reqInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_REQUEST_INFO_S));
+       memcpy(&reqInfo.reqId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
 
        // Storing Request ID, Proxy Info for Sent Status CNF
-       memcpy(&proxyInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), sizeof(MSG_PROXY_INFO_S));
+       memcpy(&proxyInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), sizeof(MSG_PROXY_INFO_S));
+
+       MsgDecodeMsgInfo((char *)(pCmd->cmdData+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), &reqInfo.msgInfo, &reqInfo.sendOptInfo);
 
        if (reqInfo.msgInfo.msgId > 0)
                bNewMsg = false;
@@ -90,7 +96,7 @@ int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                pFileName = strstr(reqInfo.msgInfo.msgData, "MSG_");
                strncpy(trId.pduFileName, pFileName, MAX_COMMON_INFO_SIZE);
 
-               MSG_DEBUG("java MMS msg trId:%s filepath:%s ",trId.id, reqInfo.msgInfo.msgData);
+               MSG_SEC_DEBUG("java MMS msg trId:%s filepath:%s ",trId.id, reqInfo.msgInfo.msgData);
 
                MsgTransactionManager* tm = MsgTransactionManager::instance();
                tm->setJavaMMSList(&trId);
@@ -119,12 +125,19 @@ int MsgSubmitReqHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                } else {
                        MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
                }
-       } else if (err == MSG_ERR_SECURITY_ERROR) { // Case of MDM enabled, it returns MSG_ERR_SECURITY_ERROR.
-               MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
        } else {
                MSG_DEBUG("No need to broadcast storage change CB");
        }
 
+       memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+
+       MsgStoAutoDeleteConversation(reqInfo.msgInfo.threadId, &msgIdList);
+       if(msgIdList.msgIdList)
+       {
+               MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
+               delete [] (char*)msgIdList.msgIdList;
+       }
+
        return eventSize;
 }
 
@@ -228,6 +241,8 @@ int MsgRegIncomingPushMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        // storing dst fd in list
        MsgTransactionManager::instance()->setPushMsgCB(pCmdData);
+       //MsgTransactionManager::instance()->sendPendigPushMsg(pCmdData);
+
 
        // Make Event Data
        int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_INCOMING_PUSH_MSG_CB, MSG_SUCCESS, (void**)ppEvent);
@@ -235,6 +250,8 @@ int MsgRegIncomingPushMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        return eventSize;
 }
 
+
+
 int MsgRegIncomingCBMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
        // input check
@@ -243,7 +260,7 @@ int MsgRegIncomingCBMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        // Get Message Request
        MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCmdData = (MSG_CMD_REG_INCOMING_CB_MSG_CB_S*) pCmd->cmdData;
-       MSG_DEBUG("Registering incoming Push Msg CB for fd:%d mType:%d", pCmdData->listenerFd, pCmdData->msgType);
+       MSG_DEBUG("Registering incoming CB Msg CB for fd:%d mType:%d: bSave: %d", pCmdData->listenerFd, pCmdData->msgType, pCmdData->bsave);
 
        // storing dst fd in list
        MsgTransactionManager::instance()->setCBMsgCB(pCmdData);
@@ -335,6 +352,26 @@ int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 }
 
 
+int MsgRegIncomingReportMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent)
+{
+       // input check
+       if( !pCmd || !ppEvent)
+               THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
+
+       // Get Message Request
+       int listenerFd = *((int*) pCmd->cmdData);
+       MSG_DEBUG("Registering report msg incoming CB for %d", listenerFd);
+
+       // storing dst fd in list
+       MsgTransactionManager::instance()->setReportMsgCB(listenerFd);
+
+       // Make Event Data
+       int eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_REG_REPORT_MSG_INCOMING_CB, MsgException::SUCCESS, (void**)ppEvent);
+
+       return eventSize;
+}
+
+
 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 {
        // input check
@@ -349,9 +386,8 @@ int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        // storing dst fd in list
        MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(pStatus->reqId);
 
-       // when no sent status cb is found (in case of mobile tracker)
-       if (!prxInfo)
-       {
+       // when no sent status cb is found
+       if (!prxInfo) {
                return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
        }
 
@@ -366,11 +402,7 @@ int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
        }
 
-#ifdef __x86_64__
-       uint64_t ret[3] = {0}; //3// reqid, status, object
-#else
        unsigned int ret[3] = {0}; //3// reqid, status, object
-#endif
 
        ret[0] = pStatus->reqId;
        ret[1] = pStatus->status;
@@ -404,7 +436,10 @@ int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        MSG_MESSAGE_INFO_S msgInfo;
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
-       memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+       MsgDecodeMsgInfo((char *)pCmd->cmdData, &msgInfo);
 
        // normal process
        err = MsgHandleIncomingMsg(&msgInfo, &sendNoti);
@@ -420,17 +455,36 @@ int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        if (sendNoti == true) {
                MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
-               MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
-       } else if(msgInfo.msgPort.valid)
-       {
+               if (msgInfo.msgType.subType > MSG_TYPE0_SMS && msgInfo.msgType.subType < MSG_WAP_SI_SMS) { // if it is replacement message.
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+               } else {
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
+               }
+       } else if(msgInfo.msgPort.valid || (msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) {
                MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
-       }
-       else if (msgInfo.folderId == MSG_SPAMBOX_ID) {
+       } else if (msgInfo.folderId == MSG_SPAMBOX_ID) {
                MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
+       } else if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS || msgInfo.msgType.subType == MSG_DELIVERYIND_MMS) {
+               MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_DELIVERY, &msgInfo);
+       } else if (msgInfo.msgType.subType == MSG_READORGIND_MMS) {
+               MsgTransactionManager::instance()->broadcastReportMsgCB(err, MSG_REPORT_TYPE_READ, &msgInfo);
+       }
+
+       memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+       MsgStoAutoDeleteConversation(msgInfo.threadId, &msgIdList);
+       if(msgIdList.msgIdList)
+       {
+               MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
+               delete [] (char*)msgIdList.msgIdList;
        }
 
        eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)ppEvent);
 
+       if (msgInfo.bTextSms == false) {
+               MsgDeleteFile(msgInfo.msgData); //ipc
+               memset(msgInfo.msgData, 0x00, sizeof(msgInfo.msgData));
+       }
+
        MSG_END();
 
        return eventSize;
@@ -442,11 +496,16 @@ int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        msg_error_t err = MSG_SUCCESS;
        int eventsize = 0;
 
-       MSG_MESSAGE_INFO_S msgInfo = {0};
+       MSG_MESSAGE_INFO_S msgInfo;
        msg_request_id_t reqID;
 
-       memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_MESSAGE_INFO_S));
-       memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), sizeof(msg_request_id_t));
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+       memcpy(&reqID, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_request_id_t));
+       MsgDecodeMsgInfo((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t), &msgInfo);
 
        MSG_DEBUG(" pMsg = %s, pReqId = %d ", msgInfo.msgData, reqID);
        MSG_DEBUG(" msgtype subtype is [%d]", msgInfo.msgType.subType);
@@ -460,22 +519,44 @@ int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        msgIds[0] = msgInfo.msgId;
        msgIdList.msgIdList = msgIds;
 
-       //err = MsgStoGetAddrInfo(msgInfo.msgId, &(msgInfo.addressList[0]));
-       err = MsgStoGetOrgAddressList(&msgInfo);
+       MSG_ADDRESS_INFO_S *tmpAddr = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(tmpAddr, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+       err = MsgStoGetAddrInfo(msgInfo.msgId, tmpAddr);
 
        if (err == MSG_SUCCESS) {
-               MSG_DEBUG("MsgStoGetOrgAddressList() success.");
-//             msgInfo.nAddressCnt = 1;
+               MSG_DEBUG("MmsStoGetAddrInfo() success.");
+               msgInfo.nAddressCnt = 1;
        } else {
-               MSG_DEBUG("MsgStoGetOrgAddressList() fail.");
+               msgInfo.nAddressCnt = 0;
+               MSG_DEBUG("MmsStoGetAddrInfo() fail.");
        }
 
-       if(msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
+       if (msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
+
+               /* PLM P141008-05143 : Notification.Ind address is 1, but MMS retreived Conf address is correct.
+               So adding code for comparing exist address and new address and replace with new address(MMSconf) address */
+               if (msgInfo.nAddressCnt == 1 && msgInfo.networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS && (g_strcmp0(tmpAddr->addressVal, msgInfo.addressList[0].addressVal) != 0)) {
+                       MSG_WARN("Address of NotiInd and MMSConf are different!!, Replace [NotiInd : %s] from [MMSConf : %s]", tmpAddr->addressVal, msgInfo.addressList[0].addressVal);
+                       memset(tmpAddr->addressVal, 0x00, MAX_ADDRESS_VAL_LEN);
+                       strncpy(tmpAddr->addressVal, msgInfo.addressList[0].addressVal, MAX_ADDRESS_VAL_LEN);
+               }
+
+               if (msgInfo.addressList) {
+                       delete[] msgInfo.addressList;
+                       msgInfo.addressList = NULL;
+               }
+
+               msgInfo.addressList = tmpAddr;
+
+               MSG_SUB_TYPE_T recv_sub_type = msgInfo.msgType.subType; // Check retrieve mode to determine broadcast type
 
                err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
 
-               if(err != MSG_SUCCESS)
-                       return err;
+               if(err != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgHandleMmsConfIncomingMsg failed.");
+                       return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
+               }
 
                MMS_RECV_DATA_S* pMmsRecvData = (MMS_RECV_DATA_S*)msgInfo.msgData;
 
@@ -487,19 +568,30 @@ int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                        memset(msgInfo.msgData, 0x00, sizeof(MMS_RECV_DATA_S));
                }
 
-               eventsize = MsgMakeEvent(&msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MMS_CONF, msgInfo.networkStatus, (void**)ppEvent);
-
                // broadcast to listener threads, here
                MsgTransactionManager::instance()->broadcastMMSConfCB(msgInfo.networkStatus, &msgInfo, pMmsRecvData);
-               MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+
+               // determine broadcast type with retrieve mode
+               if (recv_sub_type == MSG_RETRIEVE_AUTOCONF_MMS)
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
+               else
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+
+               // make return event
+               eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
+
        } else if (msgInfo.msgType.subType == MSG_SENDREQ_MMS || msgInfo.msgType.subType == MSG_SENDCONF_MMS) {
+               if (msgInfo.addressList) {
+                       delete[] msgInfo.addressList;
+                       msgInfo.addressList = NULL;
+               }
+
+               msgInfo.addressList = tmpAddr;
+
                MSG_PROXY_INFO_S* prxInfo = MsgTransactionManager::instance()->getProxyInfo(reqID);
 
-               // when no sent status cb is found (in case of mobile tracker)
-               if (!prxInfo) {
-                       MSG_DEBUG("prxInfo is NULL");
-                       eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
-               } else {
+               // when no sent status cb is found
+               if (prxInfo) {
                        // No need to update javaMMS sent messages
                        javamms_list& listenerList = MsgTransactionManager::instance()->getJavaMMSList();
                        javamms_list::iterator it = listenerList.begin();
@@ -509,7 +601,7 @@ int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
                        if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL && msgInfo.msgType.subType == MSG_SENDREQ_MMS) {
                                for ( ; it != listenerList.end() ; it++) {
                                        if (strstr(it->pduFileName, "JAVA")) {
-                                               MSG_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
+                                               MSG_SEC_DEBUG("JAVA MMS fileName:%s", it->pduFileName);
                                                MsgDeleteFile(it->pduFileName);         // ipc
                                                listenerList.erase(it);
                                                goto __BYPASS_UPDATE;
@@ -521,27 +613,40 @@ int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
                                for ( ; it != listenerList.end() ; it++) {
                                        if(!strcmp(it->id, pMmsRecvData->szTrID)) {
-                                               MSG_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s",pMmsRecvData->szTrID, it->id);
+                                               MSG_SEC_DEBUG("find sent JAVA MMS message trId:%s from listener list trId:%s",pMmsRecvData->szTrID, it->id);
                                                MsgDeleteFile(it->pduFileName); // ipc
                                                listenerList.erase(it);
                                                goto __BYPASS_UPDATE;
                                        }
                                }
                        }
+               } else {
+                       MSG_DEBUG("prxInfo is NULL");
                }
 
                err = MsgHandleMmsConfIncomingMsg(&msgInfo, reqID);
 
-               if(err != MSG_SUCCESS)
-                       return err;
+               if(err != MSG_SUCCESS) {
+                       return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)ppEvent);
+               }
 
 __BYPASS_UPDATE:
                if (msgInfo.networkStatus == MSG_NETWORK_SEND_FAIL) {
                        MSG_DEBUG("message-dialog: send fail");
-                       MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED);
+                       MsgInsertTicker("Sending multimedia message failed.", SENDING_MULTIMEDIA_MESSAGE_FAILED, true, msgInfo.msgId);
+//                     MsgSoundPlayer::instance()->MsgSoundPlayStart(NULL, MSG_NORMAL_SOUND_PLAY);
                } else {
                        MSG_DEBUG("message-dialog: send success");
-                       MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT);
+
+                       bool bTTS = false;
+
+                       if (MsgSettingGetBool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &bTTS) != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgSettingGetBool is failed.");
+                       }
+
+                       if (bTTS) {
+                               MsgInsertTicker("Multimedia message sent.", MULTIMEDIA_MESSAGE_SENT, false, 0);
+                       }
 
                        MSG_DEBUG("Enter MsgAddPhoneLog() : msgInfo.addressList[0].addressVal [%s]", msgInfo.addressList[0].addressVal);
                        MsgAddPhoneLog(&msgInfo);
@@ -551,31 +656,32 @@ __BYPASS_UPDATE:
                        if (prxInfo->handleAddr == 0) {
                                // just making data which will be passed to plugin. it indicates "handling evt success"
                                MsgTransactionManager::instance()->delProxyInfo(reqID);
+                       } else {
 
-                               return MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
-                       }
-
-#ifdef __x86_64__
-                       uint64_t ret[3] = {0}; //3// reqid, status, object
-#else
-                       unsigned int ret[3] = {0}; //3// reqid, status, object
-#endif
+                               unsigned int ret[3] = {0}; //3// reqid, status, object
 
-                       ret[0] = reqID;
-                       ret[1] = msgInfo.networkStatus;
-                       ret[2] = prxInfo->handleAddr;
+                               ret[0] = reqID;
+                               ret[1] = msgInfo.networkStatus;
+                               ret[2] = prxInfo->handleAddr;
 
-                       // Make Event Data for APP
-                       eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
+                               // Make Event Data for APP
+                               eventsize = MsgMakeEvent(ret, sizeof(ret), MSG_EVENT_PLG_SENT_STATUS_CNF, MSG_SUCCESS, (void**)ppEvent);
 
-                       // Send to listener thread, here
-                       MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
+                               // Send to listener thread, here
+                               MsgTransactionManager::instance()->write(prxInfo->listenerFd, *ppEvent, eventsize);
 
-                       MsgTransactionManager::instance()->delProxyInfo(reqID);
+                               MsgTransactionManager::instance()->delProxyInfo(reqID);
+                       }
                }
 
-               msgInfo.bTextSms = true;
+               eventsize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_MMS_CONF, MSG_SUCCESS, (void**)ppEvent);
                MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+       } else {
+               //To avoid prevent memory leak.. this case will not occur. eventsize will be return as 0.
+               if (tmpAddr) {
+                       delete[] tmpAddr;
+                       tmpAddr = NULL;
+               }
        }
 
        MSG_END();
@@ -627,21 +733,33 @@ int MsgIncomingCBMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        memcpy(&cbMsg, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_CB_MSG_S));
 
+       MSG_MESSAGE_INFO_S msgInfo;
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+       MsgDecodeMsgInfo((char *)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_CB_MSG_S), &msgInfo);
+
+       MSG_DEBUG("CB MSG ADDRESS COUNT=%d", msgInfo.nAddressCnt);
+
+       if (MsgStoAddCBMsg(&msgInfo) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgStoAddCBMsg is fail");
+       }
+
+       MsgInsertNotification(&msgInfo);
+       MsgChangePmState();
+
        msg_id_list_s msgIdList;
        msg_message_id_t msgIds[1];
        memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
 
+       msgIdList.nCount = 1;
+       msgIds[0] = (msg_message_id_t)msgInfo.msgId;
+       msgIdList.msgIdList = msgIds;
+       MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
        MsgTransactionManager::instance()->broadcastCBMsgCB(err, &cbMsg);
 
-       bool bSave = false;
-       MsgSettingGetBool(CB_SAVE, &bSave);
-
-       if(bSave && cbMsg.type!= MSG_ETWS_SMS) {
-               msgIdList.nCount = 1;
-               msgIds[0] = (msg_message_id_t)cbMsg.messageId;
-               msgIdList.msgIdList = msgIds;
-               MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
-       }
        eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INCOMING_CB_MSG_IND, err, (void**)ppEvent);
 
        MSG_END();
@@ -759,6 +877,13 @@ int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        MSG_DEBUG("storageChangeType : [%d], msg Id : [%d]", storageChangeType, msgInfo.msgId);
 
+       if (msgInfo.msgType.mainType == MSG_TYPE_SMS) {
+               if (storageChangeType == MSG_STORAGE_CHANGE_UPDATE)
+                       MsgStoUpdateMessage(&msgInfo, NULL);
+               else if (storageChangeType == MSG_STORAGE_CHANGE_DELETE)
+                       MsgStoDeleteMessage(msgInfo.msgId, true);
+       }
+
        // broadcast to listener threads, here
        msg_id_list_s msgIdList;
        msg_message_id_t msgIds[1];
@@ -775,3 +900,82 @@ int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        return eventSize;
 }
+
+int MsgResendMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
+{
+       msg_error_t err = MSG_SUCCESS;
+       int eventSize = 0;
+
+
+       // Get the msgIdList of sending failed message.
+       int *failed_msg_list = NULL;
+       int count = 0;
+       AutoPtr<int> failed_list(&failed_msg_list);
+
+
+       err = MsgStoGetFailedMessage(&failed_msg_list, &count);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("MsgStoGetFailedMessage() Error!! [%d]", err);
+       }
+
+       for(int i=0; i < count ; ++i)
+       {
+               MSG_REQUEST_INFO_S reqInfo = {0};
+               reqInfo.msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&reqInfo.msgInfo.addressList);
+               reqInfo.msgInfo.msgId = failed_msg_list[i];
+               err = MsgStoGetMessage(reqInfo.msgInfo.msgId, &(reqInfo.msgInfo), &(reqInfo.sendOptInfo));
+
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("MsgStoGetMessage() Error!! [%d]", err);
+               }
+
+               reqInfo.msgInfo.networkStatus = MSG_NETWORK_SENDING;
+
+               msg_id_list_s msgIdList;
+               msg_message_id_t msgIds[1];
+               memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
+
+               msgIdList.nCount = 1;
+               msgIds[0] = reqInfo.msgInfo.msgId;
+               msgIdList.msgIdList = msgIds;
+
+               err = MsgSubmitReq(&reqInfo, false);
+
+               if (err == MSG_SUCCESS) {
+                       MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
+                       if (err == MSG_SUCCESS)
+                               MSG_DEBUG("MsgSubmitReq() Success");
+                       else
+                               MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
+               } else {
+                       MSG_DEBUG("MsgSubmitReq() Fail, [%d]", err);
+               }
+       }
+
+       eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_RESEND_MESSAGE, err, (void**)ppEvent);
+
+       MSG_END();
+       return eventSize;
+}
+
+#ifdef MSG_PENDING_PUSH_MESSAGE
+int MsgSendPendingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
+{
+       MSG_BEGIN();
+
+       int eventSize = 0;
+
+       // input check
+       if (!pCmd || !ppEvent)
+               THROW(MsgException::INVALID_PARAM, "pCmd or ppEvent is null");
+
+       MsgTransactionManager::instance()->sendPendingPushMsg();
+
+       // Make Event Data
+       eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_SEND_PENDING_PUSH_MESSAGE, MSG_SUCCESS, (void**)ppEvent);
+
+       MSG_END();
+       return eventSize;
+}
+#endif
index 59e9e5d..190c6f9 100755 (executable)
@@ -1,23 +1,24 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
+#include <pthread.h>
 
 #include <security-server.h>
 
 #include "MsgIpcSocket.h"
 #include "MsgGconfWrapper.h"
 #include "MsgUtilFunction.h"
+#include "MsgUtilFile.h"
+#include "MsgLbs.h"
 #include "MsgCmdHandler.h"
 #include "MsgSettingHandler.h"
 #include "MsgStorageHandler.h"
 #include "MsgPluginManager.h"
 #include "MsgTransManager.h"
 
+#define MSG_CHECK_PRIVILEGE
+
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
@@ -53,10 +58,12 @@ MsgTransactionManager* MsgTransactionManager::pInstance = NULL;
 MsgIpcServerSocket MsgTransactionManager::servSock;
 
 
-MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv()
+MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv(), eventQueue()
 {
        sentMsgMap.clear();
-
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       pushMsgList.clear();
+#endif
        statusCBFdMap.clear();
        newMsgCBList.clear();
        newMMSConfMsgCBList.clear();
@@ -109,6 +116,7 @@ MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv()
        handlerMap[MSG_CMD_REG_INCOMING_CB_MSG_CB]      = &MsgRegIncomingCBMsgCallbackHandler;
        handlerMap[MSG_CMD_REG_INCOMING_LBS_MSG_CB]     = &MsgRegIncomingLBSMsgCallbackHandler;
        handlerMap[MSG_CMD_REG_SYNCML_MSG_OPERATION_CB] = &MsgRegSyncMLMsgOperationCallbackHandler;
+       handlerMap[MSG_CMD_REG_REPORT_MSG_INCOMING_CB] = &MsgRegIncomingReportMsgCallbackHandler;
 
        handlerMap[MSG_CMD_PLG_SENT_STATUS_CNF] = &MsgSentStatusHandler;
        handlerMap[MSG_CMD_PLG_STORAGE_CHANGE_IND]      = &MsgStorageChangeHandler;
@@ -141,7 +149,6 @@ MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv()
 
        handlerMap[MSG_CMD_GET_THREAD_ID_BY_ADDRESS] = &MsgGetThreadIdByAddressHandler;
        handlerMap[MSG_CMD_GET_THREAD_INFO] = &MsgGetThreadInfoHandler;
-
        handlerMap[MSG_CMD_GET_SMSC_OPT] = &MsgGetConfigHandler;
        handlerMap[MSG_CMD_GET_CB_OPT] = &MsgGetConfigHandler;
        handlerMap[MSG_CMD_GET_SMS_SEND_OPT] = &MsgGetConfigHandler;
@@ -166,8 +173,12 @@ MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv()
        handlerMap[MSG_CMD_DELETE_PUSH_EVENT] = &MsgDeletePushEventHandler;
        handlerMap[MSG_CMD_UPDATE_PUSH_EVENT] = &MsgUpdatePushEventHandler;
        handlerMap[MSG_CMD_DELETE_MESSAGE_BY_LIST] = &MsgDeleteMessageByListHandler;
-
-       handlerMap[MSG_CMD_CONTACT_SYNC] = &MsgContactSyncEventHandler;
+       handlerMap[MSG_CMD_ADD_SIM_MSG] = &MsgAddSimMessageHandler;
+       handlerMap[MSG_CMD_PLG_RESEND_MESSAGE] = &MsgResendMessageHandler;
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       handlerMap[MSG_CMD_SEND_PENDING_PUSH_MESSAGE] = &MsgSendPendingPushMsgHandler;
+#endif
+       handlerMap[MSG_CMD_UPDATE_IMSI] = &MsgUpdateIMSIHandler;
 }
 
 
@@ -186,6 +197,11 @@ MsgTransactionManager* MsgTransactionManager::instance()
        return pInstance;
 }
 
+static void* worker_event_queue(void* arg)
+{
+       MsgTransactionManager::instance()->workerEventQueue();
+       return NULL;
+}
 
 void MsgTransactionManager::run()
 {
@@ -196,6 +212,17 @@ void MsgTransactionManager::run()
 
        MSG_DEBUG("Start Transaction Manager");
 
+       // Set Msg FW Ready Flag
+       if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingSetBool FAIL : VCONFKEY_MSG_SERVER_READY");
+       MSG_INFO("### VCONFKEY_MSG_SERVER_READY ###");
+
+     /* running worker for plg task */
+       pthread_t tv;
+       if (pthread_create (&tv, NULL, &worker_event_queue, NULL) != 0) {
+               THROW(MsgException::SERVER_READY_ERROR, "cannot create thread [%d]", errno);
+       }
+
        while(1)
        {
                readfds = servSock.fdSet();
@@ -204,7 +231,7 @@ void MsgTransactionManager::run()
                MSG_DEBUG("Wait For Select() : nfds %d", nfds);
 
                // set Status;
-               setTMStatus();
+//             setTMStatus();
 
                if(select(nfds, &readfds, NULL, NULL, NULL) == -1) {
                        THROW(MsgException::SELECT_ERROR, "select error : %s", strerror(errno));
@@ -233,7 +260,7 @@ void MsgTransactionManager::run()
                }
 
                // Release Memory
-               //MsgReleaseMemory();
+               MsgReleaseMemory();
        }
 }
 
@@ -267,8 +294,7 @@ MSG_PROXY_INFO_S* MsgTransactionManager::getProxyInfo(int reqId)
 
        if (it == sentMsgMap.end())
        {
-               //THROW(MsgException::SENT_STATUS_ERROR, "No submit request for %d", reqId);
-               MSG_DEBUG("No sent status cb found (exception: mobile tracker)");
+               MSG_DEBUG("No sent status cb found");
                return NULL;
        }
 
@@ -288,6 +314,56 @@ void MsgTransactionManager::delProxyInfo(int reqId)
        sentMsgMap.erase(it);
 }
 
+void MsgTransactionManager::workerEventQueue()
+{
+       MSG_CMD_S* pCmd = NULL;
+       int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
+       char* pEventData = NULL;
+       int fd = -1;
+
+       while (1) {
+               mx.lock();
+               while (!eventQueue.front(&pCmd)) { /* if no item, wait */
+                       MSG_DEBUG ("waiting for task");
+                       cv.wait(mx.pMutex());
+               }
+               eventQueue.pop_front(); /* pop it from queue*/
+               mx.unlock();
+
+               if (!pCmd) {
+                       MSG_FATAL("pCmd NULL");
+                       continue;
+               }
+               
+               memcpy (&fd, pCmd->cmdCookie, sizeof(int));
+               if (fd < 0 ) {
+                       MSG_FATAL("fd [%d] < 0", fd);
+                       g_free (pCmd); pCmd = NULL;
+                       continue;
+               }
+               pfHandler = handlerMap[pCmd->cmdType];
+               if (!pfHandler) {
+                       MSG_FATAL("No handler for %d", pCmd->cmdType);
+                       g_free (pCmd); pCmd = NULL;
+                       continue;
+               }
+               
+               // run handler function
+               int eventSize = pfHandler(pCmd, &pEventData);
+
+               if (eventSize == 0 || pEventData == NULL) {
+                       MSG_FATAL("event size[%d] = 0 or event data = NULL", eventSize);
+                       g_free (pCmd); pCmd = NULL;
+                       g_free (pEventData); pEventData = NULL;
+                       continue;
+               }
+
+               MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
+               servSock.write(fd, pEventData, eventSize);
+               g_free (pCmd); pCmd = NULL;
+               g_free (pEventData); pEventData = NULL;
+       }
+}
 
 void MsgTransactionManager::handleRequest(int fd)
 {
@@ -323,6 +399,7 @@ void MsgTransactionManager::handleRequest(int fd)
                THROW(MsgException::OUT_OF_RANGE, "request CMD is not defined");
 
        // check privilege
+//     if (checkPrivilege(pCmd->cmdType, pCmd->cmdCookie) == false) {
        if (checkPrivilege(fd, pCmd->cmdType) == false) {
                MSG_DEBUG("No Privilege rule. Not allowed.");
 #ifdef MSG_CHECK_PRIVILEGE
@@ -333,7 +410,7 @@ void MsgTransactionManager::handleRequest(int fd)
                MSG_EVENT_S* pMsgEvent = (MSG_EVENT_S*)pEventData;
 
                pMsgEvent->eventType = pCmd->cmdType;
-               pMsgEvent->result = MSG_ERR_SECURITY_ERROR;
+               pMsgEvent->result = MSG_ERR_PERMISSION_DENIED;
 
                MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
                servSock.write(fd, pEventData, eventSize);
@@ -345,20 +422,42 @@ void MsgTransactionManager::handleRequest(int fd)
        // determine the handler based on pCmd->cmdType
        int (*pfHandler)(const MSG_CMD_S*, char**) = NULL;
 
-       pfHandler = handlerMap[pCmd->cmdType];
-
-       if (!pfHandler)
-               THROW(MsgException::INVALID_PARAM, "No handler for %d", pCmd->cmdType);
+       switch (pCmd->cmdType) {
+       case MSG_CMD_PLG_SENT_STATUS_CNF:
+       case MSG_CMD_PLG_STORAGE_CHANGE_IND:
+       case MSG_CMD_PLG_INCOMING_MSG_IND:
+       case MSG_CMD_PLG_INCOMING_MMS_CONF:
+       case MSG_CMD_PLG_INCOMING_SYNCML_IND:
+       case MSG_CMD_PLG_INCOMING_LBS_IND:
+       case MSG_CMD_PLG_INIT_SIM_BY_SAT:
+       case MSG_CMD_PLG_INCOMING_PUSH_IND:
+       case MSG_CMD_PLG_INCOMING_CB_IND: {
+
+               MSG_CMD_S* pCmdDup = (MSG_CMD_S*) calloc (1, len); /* pCmdDup should be freed afterward */
+               memcpy (pCmdDup, pCmd, len);
+               memcpy (pCmdDup->cmdCookie, &fd, sizeof(int)); /* Now, cmdCookie keeps fd for return */
+
+               mx.lock(); /* aquire lock before adding cmd */
+               eventQueue.push_back(pCmdDup);
+               cv.signal(); /* wake up worker */
+               mx.unlock();
+               break;
+       }
+       default:
+               pfHandler = handlerMap[pCmd->cmdType];
+               if (!pfHandler)
+                       THROW(MsgException::INVALID_PARAM, "No handler for %d", pCmd->cmdType);
 
-       // run handler function
-       eventSize = pfHandler(pCmd, &pEventData);
+               // run handler function
+               eventSize = pfHandler(pCmd, &pEventData);
 
-       if (eventSize == 0 || pEventData == NULL)
-               THROW(MsgException::INVALID_RESULT, "event size = 0 or event data = NULL");
+               if (eventSize == 0 || pEventData == NULL)
+                       THROW(MsgException::INVALID_RESULT, "event size = 0 or event data = NULL");
 
-       MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
+               MSG_DEBUG("Replying to fd [%d], size [%d]", fd, eventSize);
 
-       servSock.write(fd, pEventData, eventSize);
+               servSock.write(fd, pEventData, eventSize);
+       }
 
        MSG_END();
 }
@@ -388,6 +487,11 @@ void MsgTransactionManager::cleanup(int fd)
        // remove sent status callback for fd
        statusCBFdMap.erase(fd);
 
+       MSG_DEBUG("After erase fd [%d], statusCBFdMap has below.", fd);
+       fd_map::iterator it = statusCBFdMap.begin();
+       for (; it!=statusCBFdMap.end(); ++it)
+               MSG_DEBUG("[%d]", it->first);
+
        // remove all newMsgCBs for fd
        newmsg_list::iterator newmsg_it = newMsgCBList.begin();
 
@@ -465,7 +569,7 @@ void MsgTransactionManager::cleanup(int fd)
 
        // remove all newCBMsgCBs for fd
        cbmsg_list::iterator cbmsg_it = newCBMsgCBList.begin();
-       bool bSave = false;
+       //bool bSave = false;
 
        while (cbmsg_it != newCBMsgCBList.end())
        {
@@ -475,8 +579,8 @@ void MsgTransactionManager::cleanup(int fd)
                }
                else
                {
-                       if(cbmsg_it->bsave == true)
-                               bSave = true;
+                       //if (cbmsg_it->bsave == true)
+                       //      bSave = true;
                        ++cbmsg_it;
                }
        }
@@ -499,10 +603,24 @@ void MsgTransactionManager::cleanup(int fd)
        // remove storage change callback for fd
        storageChangeFdMap.erase(fd);
 
+       MSG_DEBUG("After erase fd [%d], storageChangeFdMap has below.", fd);
+       it = storageChangeFdMap.begin();
+       for (; it!=storageChangeFdMap.end(); ++it)
+               MSG_DEBUG("[%d]", it->first);
+
+       // remove report msg incoming callback for fd
+       reportMsgCBFdMap.erase(fd);
+
+       MSG_DEBUG("After erase fd [%d], reportMsgCBFdMap has below.", fd);
+       it = reportMsgCBFdMap.begin();
+       for (; it!=reportMsgCBFdMap.end(); ++it)
+               MSG_DEBUG("[%d]", it->first);
+
        MSG_END();
 }
 
 
+#if 1
 bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
 {
        bool bAllowed = true;
@@ -511,6 +629,36 @@ bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
        case MSG_CMD_GET_MSG:
        case MSG_CMD_COUNT_MSG:
        case MSG_CMD_COUNT_BY_MSGTYPE:
+       case MSG_CMD_REG_INCOMING_MSG_CB:
+       case MSG_CMD_REG_INCOMING_CB_MSG_CB:
+       case MSG_CMD_REG_INCOMING_PUSH_MSG_CB:
+       case MSG_CMD_REG_SENT_STATUS_CB:
+       case MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB:
+       case MSG_CMD_REG_INCOMING_SYNCML_MSG_CB:
+       case MSG_CMD_REG_INCOMING_LBS_MSG_CB:
+       case MSG_CMD_REG_SYNCML_MSG_OPERATION_CB:
+       case MSG_CMD_REG_REPORT_MSG_INCOMING_CB:
+       case MSG_CMD_GET_CONTACT_COUNT:
+       case MSG_CMD_GET_FOLDERLIST:
+       case MSG_CMD_GET_QUICKPANEL_DATA:
+       case MSG_CMD_GET_MEMSIZE:
+       case MSG_CMD_BACKUP_MESSAGE:
+       case MSG_CMD_REG_STORAGE_CHANGE_CB:
+       case MSG_CMD_GET_REPORT_STATUS:
+       case MSG_CMD_GET_THREAD_ID_BY_ADDRESS:
+       case MSG_CMD_GET_THREAD_INFO:
+       case MSG_CMD_SYNCML_OPERATION:
+       case MSG_CMD_GET_FILTERLIST:
+       case MSG_CMD_GET_FILTER_OPERATION:
+       case MSG_CMD_GET_SMSC_OPT:
+       case MSG_CMD_GET_CB_OPT:
+       case MSG_CMD_GET_SMS_SEND_OPT:
+       case MSG_CMD_GET_MMS_SEND_OPT:
+       case MSG_CMD_GET_MMS_RECV_OPT:
+       case MSG_CMD_GET_PUSH_MSG_OPT:
+       case MSG_CMD_GET_VOICE_MSG_OPT:
+       case MSG_CMD_GET_GENERAL_MSG_OPT:
+       case MSG_CMD_GET_MSG_SIZE_OPT:
        {
                int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::read", "rw");
                if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
@@ -519,11 +667,41 @@ bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
                }
        }
        break;
-       case MSG_CMD_OPEN_HANDLE:
        case MSG_CMD_SUBMIT_REQ:
        case MSG_CMD_SET_CB_OPT:
        case MSG_CMD_ADD_PUSH_EVENT:
        case MSG_CMD_DELETE_PUSH_EVENT:
+       case MSG_CMD_UPDATE_PUSH_EVENT:
+       case MSG_CMD_ADD_MSG:
+       case MSG_CMD_ADD_SYNCML_MSG:
+       case MSG_CMD_UPDATE_MSG:
+       case MSG_CMD_UPDATE_READ:
+       case MSG_CMD_UPDATE_PROTECTED:
+       case MSG_CMD_DELETE_MSG:
+       case MSG_CMD_DELALL_MSGINFOLDER:
+       case MSG_CMD_MOVE_MSGTOFOLDER:
+       case MSG_CMD_MOVE_MSGTOSTORAGE:
+       case MSG_CMD_DELETE_THREADMESSAGELIST:
+       case MSG_CMD_ADD_FOLDER:
+       case MSG_CMD_UPDATE_FOLDER:
+       case MSG_CMD_DELETE_FOLDER:
+       case MSG_CMD_RESET_DB:
+       case MSG_CMD_RESTORE_MESSAGE:
+       case MSG_CMD_DELETE_MESSAGE_BY_LIST:
+       case MSG_CMD_UPDATE_THREAD_READ:
+       case MSG_CMD_ADD_FILTER:
+       case MSG_CMD_UPDATE_FILTER:
+       case MSG_CMD_DELETE_FILTER:
+       case MSG_CMD_SET_FILTER_OPERATION:
+       case MSG_CMD_SET_FILTER_ACTIVATION:
+       case MSG_CMD_SET_SMSC_OPT:
+       case MSG_CMD_SET_SMS_SEND_OPT:
+       case MSG_CMD_SET_MMS_SEND_OPT:
+       case MSG_CMD_SET_MMS_RECV_OPT:
+       case MSG_CMD_SET_PUSH_MSG_OPT:
+       case MSG_CMD_SET_VOICE_MSG_OPT:
+       case MSG_CMD_SET_GENERAL_MSG_OPT:
+       case MSG_CMD_SET_MSG_SIZE_OPT:
        {
                int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::write", "rw");
                if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
@@ -532,38 +710,85 @@ bool MsgTransactionManager::checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType)
                }
        }
        break;
-       case MSG_CMD_REG_INCOMING_MSG_CB:
+       }
+
+       return bAllowed;
+}
+#else
+bool MsgTransactionManager::checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie)
+{
+       if (CmdType >= MSG_CMD_PLG_SENT_STATUS_CNF && CmdType <= MSG_CMD_PLG_INIT_SIM_BY_SAT)
        {
-               int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::smstrigger", "rw");
-               if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       MSG_DEBUG("No msg-service::smstrigger rw rule.");
-                       bAllowed = false;
-               }
+               MSG_DEBUG("Request from Plug-in");
+               return true;
        }
-       break;
-       case MSG_CMD_REG_INCOMING_CB_MSG_CB:
+
+       // Get Cookie from APP
+       if (pCookie == NULL)
        {
-               int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::cellbroadcast", "rw");
-               if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       MSG_DEBUG("No msg-service::cellbroadcast rw rule.");
-                       bAllowed = false;
-               }
+               MSG_DEBUG("Cookie is NULL");
+               return false;
        }
-       break;
-       case MSG_CMD_REG_INCOMING_PUSH_MSG_CB:
+
+#ifdef MSG_FOR_DEBUG
+       for (int i = 0; i < MAX_COOKIE_LEN; i++)
        {
-               int ret = security_server_check_privilege_by_sockfd(fd, "msg-service::wappush", "rw");
-               if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       MSG_DEBUG("No msg-service::wappush rw rule.");
-                       bAllowed = false;
-               }
+               MSG_DEBUG("cookie : [%02x]", pCookie[i]);
        }
-       break;
+#endif
+
+       // Check Cookie
+       size_t cookieSize;
+       gid_t gid;
+
+       cookieSize = security_server_get_cookie_size();
+
+       MSG_DEBUG("cookie size : [%d]", cookieSize);
+
+//     char cookie[MAX_COOKIE_LEN];
+
+       // Get GID
+       if (CmdType == MSG_CMD_REG_INCOMING_SYNCML_MSG_CB)
+       {
+               MSG_DEBUG("get GID for message_sync");
+               gid = security_server_get_gid("message_sync");
+       }
+       else if (CmdType == MSG_CMD_REG_INCOMING_LBS_MSG_CB)
+       {
+               MSG_DEBUG("get GID for message_lbs");
+               gid = security_server_get_gid("message_lbs");
+       }
+       else
+       {
+               MSG_DEBUG("get GID for message");
+               gid = security_server_get_gid("message");
        }
 
-       return bAllowed;
-}
+       MSG_DEBUG("gid [%d]", gid);
 
+       int retVal = 0;
+
+       retVal = security_server_check_privilege(pCookie, gid);
+
+       if (retVal < 0)
+       {
+               if (retVal == SECURITY_SERVER_API_ERROR_ACCESS_DENIED)
+               {
+                       MSG_DEBUG("access denied !! [%d]", retVal);
+               }
+               else
+               {
+                       MSG_DEBUG("fail to check privilege [%d]", retVal);
+               }
+
+               return false;
+       }
+
+       MSG_DEBUG("privilege check success !!");
+
+       return true;
+}
+#endif
 
 void MsgTransactionManager::setSentStatusCB(int listenerFd)
 {
@@ -632,7 +857,7 @@ void MsgTransactionManager::setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCb
 
        for (; it != newPushMsgCBList.end(); it++)
        {
-               if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType))
+               if ((it->listenerFd == pCbInfo->listenerFd) && (it->msgType == pCbInfo->msgType) && !strncmp(it->appId, pCbInfo->appId, MAX_WAPPUSH_ID_LEN))
                {
                        MSG_DEBUG("Duplicated messageCB info fd %d, mType %d", it->listenerFd, it->msgType);
                        return;
@@ -644,6 +869,7 @@ void MsgTransactionManager::setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCb
 
 void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo)
 {
+       MSG_BEGIN();
        if (!pCbInfo)
        {
                MSG_FATAL("cbinfo NULL");
@@ -660,6 +886,7 @@ void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo
                        return;
                }
        }
+       MSG_DEBUG("bSave : [%d]", pCbInfo->bsave);
 
        if(pCbInfo->bsave)
                if(MsgSettingSetBool(CB_SAVE, pCbInfo->bsave) != MSG_SUCCESS)
@@ -667,8 +894,11 @@ void MsgTransactionManager::setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo
 
 
        newCBMsgCBList.push_back(*pCbInfo);
+
+       MSG_END();
 }
 
+
 void MsgTransactionManager::setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbInfo)
 {
        if (!pCbInfo)
@@ -729,7 +959,7 @@ void MsgTransactionManager::setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *
        {
                if (!strcmp(it->id, pTrId->id))
                {
-                       MSG_DEBUG("Duplicated javaMMS transaction Id:%s", it->id);
+                       MSG_SEC_DEBUG("Duplicated javaMMS transaction Id:%s", it->id);
                        return;
                }
        }
@@ -770,6 +1000,15 @@ void MsgTransactionManager::setStorageChangeCB(int listenerFd)
 }
 
 
+void MsgTransactionManager::setReportMsgCB(int listenerFd)
+{
+       if (listenerFd <= 0)
+               THROW(MsgException::INVALID_PARAM,"InParam Error: listenerFd %d", listenerFd);
+
+       reportMsgCBFdMap[listenerFd] = true;
+}
+
+
 javamms_list& MsgTransactionManager::getJavaMMSList()
 {
        return javaMMSList;
@@ -780,10 +1019,35 @@ void MsgTransactionManager::broadcastIncomingMsgCB(const msg_error_t err, const
 {
        MSG_BEGIN();
 
+       if ((msgInfo->msgPort.valid == true) && (msgInfo->msgPort.dstPort == MSG_LBS_PORT)) {
+               MSG_DEBUG("Message for LBS.");
+
+               if (msgInfo->bTextSms == false) {
+                       MSG_DEBUG("msgInfo->bTextSms == false");
+
+                       int fileSize = 0;
+
+                       char* pFileData = NULL;
+                       AutoPtr<char> buf(&pFileData);
+
+                       if (MsgOpenAndReadFile(msgInfo->msgData, &pFileData, &fileSize) == true)
+                               MsgLbsSms(pFileData, fileSize);
+                       else
+                               MSG_DEBUG("MsgOpenAndReadFile failed.");
+               } else {
+                       MsgLbsSms(msgInfo->msgText, (int)msgInfo->dataSize);
+               }
+               return;
+       }
+
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-       int eventSize = MsgMakeEvent(msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)(&pEventData));
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
+
+       int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MSG_IND, err, (void**)(&pEventData));
 
        MSG_DEBUG("valid %d dstport %d", msgInfo->msgPort.valid, msgInfo->msgPort.dstPort);
 
@@ -793,13 +1057,10 @@ void MsgTransactionManager::broadcastIncomingMsgCB(const msg_error_t err, const
        {
                MSG_DEBUG("fd %d dstport %d",it->listenerFd, it->port);
 
-               if ((msgInfo->msgPort.valid == false) && (it->port == 0))
-               {
+               if ((msgInfo->msgPort.valid == false) && (it->port == 0)) {
                        MSG_DEBUG("Send incoming normal msg to listener %d", it->listenerFd);
                        write(it->listenerFd, pEventData, eventSize);
-               }
-               else if ((msgInfo->msgPort.valid == true) && (it->port == msgInfo->msgPort.dstPort))
-               {
+               } else if ((msgInfo->msgPort.valid == true) && (it->port == msgInfo->msgPort.dstPort)) {
                        MSG_DEBUG("Send incoming port msg to listener %d", it->listenerFd);
                        write(it->listenerFd, pEventData, eventSize);
                }
@@ -816,7 +1077,11 @@ void MsgTransactionManager::broadcastMMSConfCB(const msg_error_t err, const MSG_
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-       int eventSize = MsgMakeEvent(msgInfo, sizeof(MSG_MESSAGE_INFO_S), MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)(&pEventData));
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(msgInfo, &encodedData);
+
+       int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_INCOMING_MMS_CONF, err, (void**)(&pEventData));
 
        mmsconf_list::iterator it = newMMSConfMsgCBList.begin();
 
@@ -853,12 +1118,24 @@ void MsgTransactionManager::broadcastPushMsgCB(const msg_error_t err, const MSG_
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       int bReady = MsgSettingGetInt(VCONFKEY_USER_SERVICE_READY);
+       if(!bReady)
+       {
+               MSG_PUSH_MESSAGE_DATA_S push_msg;
+               memcpy(&push_msg, pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S));
+               pushMsgList.push_back(push_msg);
+               return;
+       }
+#endif
+
        int eventSize = MsgMakeEvent(pushData, sizeof(MSG_PUSH_MESSAGE_DATA_S), MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND, err, (void**)(&pEventData));
 
        pushmsg_list::iterator it = newPushMsgCBList.begin();
 
        for (; it != newPushMsgCBList.end(); it++)
        {
+               MSG_DEBUG("registered_appid : %s, incoming_appid: %s", it->appId, pushData->pushAppId);
                if (!strcmp(it->appId, pushData->pushAppId))
                {
                        MSG_DEBUG("Send incoming Push information to listener %d", it->listenerFd);
@@ -914,6 +1191,7 @@ void MsgTransactionManager::broadcastLBSMsgCB(const msg_error_t err, const MSG_L
 {
        MSG_BEGIN();
 
+#if 0
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
@@ -926,7 +1204,9 @@ void MsgTransactionManager::broadcastLBSMsgCB(const msg_error_t err, const MSG_L
                MSG_DEBUG("Send incoming LBS msg to listener %d", it->listenerFd);
                write(it->listenerFd, pEventData, eventSize);
        }
-
+#else
+       MsgLbsWapPush(lbsData->pushHeader, lbsData->pushBody, lbsData->pushBodyLen);
+#endif
        MSG_END();
 }
 
@@ -994,6 +1274,42 @@ void MsgTransactionManager::broadcastStorageChangeCB(const msg_error_t err, cons
 }
 
 
+void MsgTransactionManager::broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
+
+       if(pMsgInfo == NULL) {
+               MSG_DEBUG("pMsgInfo is NULL.");
+               return;
+       }
+
+       MSG_DEBUG("reportMsgType [%d]", reportMsgType);
+
+       int dataSize = 0;
+
+       char* pEventData = NULL;
+       AutoPtr<char> eventBuf(&pEventData);
+
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+
+       // Encoding Storage Change Data
+       dataSize = MsgEncodeReportMsgData(reportMsgType, pMsgInfo, &encodedData);
+
+       int eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND, err, (void**)(&pEventData));
+
+       fd_map::iterator it = reportMsgCBFdMap.begin();
+
+       for (; it != reportMsgCBFdMap.end(); it++)
+       {
+               MSG_DEBUG("Send Report Message Incoming Callback to listener %d", it->first);
+               write(it->first, pEventData, eventSize);
+       }
+
+       MSG_END();
+}
+
+
 void MsgTransactionManager::setTMStatus()
 {
        MSG_BEGIN();
@@ -1021,3 +1337,23 @@ void MsgTransactionManager::getTMStatus()
        }
        MSG_END();
 }
+
+#ifdef MSG_PENDING_PUSH_MESSAGE
+void MsgTransactionManager::sendPendingPushMsg(void)
+{
+
+       pushpending_list::iterator pushmsg_it = pushMsgList.begin();
+       while(pushmsg_it != pushMsgList.end())
+       {
+               MSG_PUSH_MESSAGE_DATA_S msg;
+               memset(&msg, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
+               memcpy(msg.pushAppId, pushmsg_it->pushAppId, sizeof(msg.pushAppId));
+               memcpy(msg.pushBody, pushmsg_it->pushBody, sizeof(msg.pushBody));
+               memcpy(msg.pushContentType, pushmsg_it->pushContentType, sizeof(msg.pushContentType));
+               memcpy(msg.pushHeader, pushmsg_it->pushHeader, sizeof(msg.pushHeader));
+               msg.pushBodyLen = pushmsg_it->pushBodyLen;
+               MsgTransactionManager::instance()->broadcastPushMsgCB(MSG_SUCCESS, (const MSG_PUSH_MESSAGE_DATA_S *)&msg);
+               pushmsg_it = pushMsgList.erase(pushmsg_it);
+       }
+}
+#endif
diff --git a/image/messaging_image001.png b/image/messaging_image001.png
deleted file mode 100755 (executable)
index 0c575c4..0000000
Binary files a/image/messaging_image001.png and /dev/null differ
index a05eed1..63d1fd0 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_CMD_TYPES_H
@@ -170,13 +170,18 @@ enum _MSG_CMD_TYPE_E
        MSG_CMD_UPDATE_PUSH_EVENT,
        MSG_CMD_DELETE_MESSAGE_BY_LIST,
        MSG_CMD_SET_FILTER_ACTIVATION,
-       MSG_CMD_CONTACT_SYNC,
+       MSG_CMD_ADD_SIM_MSG,
+
+// 85
+       MSG_CMD_PLG_RESEND_MESSAGE,
+       MSG_CMD_SEND_PENDING_PUSH_MESSAGE,
+       MSG_CMD_REG_REPORT_MSG_INCOMING_CB,
+       MSG_CMD_UPDATE_IMSI,
 
 // end of MSG_CMD; new CMD should be defined before MSG_CMD_NUM
        MSG_CMD_NUM
 };
 
-
 enum _MSG_EVENT_TYPE_E
 {
        MSG_EVENT_OPEN_HANDLE = 0,
@@ -287,11 +292,19 @@ enum _MSG_EVENT_TYPE_E
        MSG_EVENT_UPDATE_PUSH_EVENT,
        MSG_EVENT_DELETE_MESSAGE_BY_LIST,
        MSG_EVENT_SET_FILTER_ACTIVATION,
-       MSG_EVNET_CONTACT_SYNC,
+       MSG_EVENT_ADD_SIM_MSG,
+
+// 85
+       MSG_EVENT_PLG_RESEND_MESSAGE,
+       MSG_EVENT_SEND_PENDING_PUSH_MESSAGE,
+       MSG_EVENT_REG_REPORT_MSG_INCOMING_CB,
+       MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND,
+       MSG_EVENT_UPDATE_IMSI,
 
 // end of MSG_EVENT; new EVENT should be defined before MSG_EVENT_NUM
        MSG_EVENT_NUM
 };
 
+
 #endif // MSG_CMD_TYPES_H
 
index f731a4d..d4d63a1 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_CPP_TYPES_H__
index 4999ca5..cb453eb 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_FILTER_TYPES_H
index 9ba43e3..b313e35 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_INTERNAL_TYPES_H
@@ -27,7 +27,7 @@
                                          INCLUDE FILES
 ==================================================================================================*/
 #include "MsgMmsTypes.h"
-#include <inttypes.h>
+
 
 /*==================================================================================================
                                     DEFINES
 #define MSG_SMIL_FILE_PATH             MSG_DATA_ROOT_PATH"smildata/"
 #define MSG_IPC_DATA_PATH                      MSG_DATA_ROOT_PATH"ipcdata/"
 #define MSG_THUMBNAIL_PATH             MSG_DATA_PATH"thumbnails/"
+
+
 // temporary
-#define TPDU_LOG_FILE                          MSG_DATA_ROOT_PATH"tpduLog.txt"
 #define MSG_NATIONAL_SIM       "memory/private/msg-service/national_sim"
 #define MSG_SIM_MSISDN "memory/private/msg-service/msisdn"
+#define MSG_SIM_ICCID  "memory/private/msg-service/iccid"
+#define MSG_FMM_SIM_CHANGE_NUM "db/SyncML/oma-dm-service/fmmSimChangeNum"
+
 #define MAX_FULL_PATH_SIZE             320     // max length for internal file path
-#define MAX_PRECONFIG_NUM              8
 #define MAX_THREAD_ADDR_LEN    40
 #define MAX_THREAD_NAME_LEN    195
 #define MAX_THREAD_DATA_LEN    128
 #define MAX_CB_MSG_TEXT_LEN    4200    // 1page max char(93)*max page(15)*max bytes of UTF8 1 char(3)
 #define MAX_CB_MSG_LANGUAGE_TYPE_LEN   3
 #define MAX_ETWS_WARNING_SECURITY_INFO_LEN     50
+#define MAX_ME_IMEI_LEN                20
+#define MAX_SIM_MSISDN_LEN     26
+#define MAX_COMMON_INFO_SIZE   20
+#define MAX_VCONFKEY_NAME_LEN  128
 
-#define SMS_MINIMUM_SPACE      (3 * 1024)
-#define MMS_MINIMUM_SPACE      (600 * 1024)
+#define SMS_MINIMUM_SPACE      (1 * 1024 * 1024)
+#define MMS_MINIMUM_SPACE      (1 * 1024 * 1024)
 
 /*vconf keys*/
-#define MSG_SIM_IMSI                   "memory/private/msg-service/sim_imsi"
-#define MSG_SIM_CHANGED        "memory/private/msg-service/sim_changed"
-
 #define DEFAULT_SETTING_PATH                           "db/private/msg-service"
+#define DEFAULT_MSG_MEMORY_PATH                                "memory/private/msg-service"
+
+#define MSG_SIM_IMSI                   DEFAULT_MSG_MEMORY_PATH"/sim_imsi"
+#define MSG_SIM_CHANGED                DEFAULT_MSG_MEMORY_PATH"/sim_changed"
+
+#define MSG_SIM_SERVICE_TABLE          DEFAULT_MSG_MEMORY_PATH"/sim_st"
+#define MSG_SIM_MO_CONTROL             DEFAULT_MSG_MEMORY_PATH"/sim_mo_ctrl"
+#define MSG_NETWORK_SIM                DEFAULT_MSG_MEMORY_PATH"/default_network_sim"
 
 #define DEFAULT_GENERAL_OPT_PATH               DEFAULT_SETTING_PATH"/general"
 #define DEFAULT_SMS_SEND_OPT_PATH      DEFAULT_SETTING_PATH"/sms_send"
 #define DEFAULT_SIM_COUNT_PATH                 DEFAULT_SETTING_PATH"/sim_count"
 
 #define MSG_KEEP_COPY                          DEFAULT_GENERAL_OPT_PATH"/keep_copy"
-#define MSG_ALERT_TONE                         VCONFKEY_SETAPPL_NOTI_MSG_ALERT_REP_TYPE_INT
+#define MSG_ALERT_REP_TYPE                     DEFAULT_GENERAL_OPT_PATH"/alert_rep_type"
 #define MSG_AUTO_ERASE                         DEFAULT_GENERAL_OPT_PATH"/auto_erase"
 #define MSG_BLOCK_MESSAGE              DEFAULT_GENERAL_OPT_PATH"/block_msg"
 #define CONTACT_SYNC_TIME              DEFAULT_GENERAL_OPT_PATH"/contact_sync_time"
+#define MSG_SEARCH_TAGS                        DEFAULT_GENERAL_OPT_PATH"/search_tags"
+
+#define MSG_BLOCK_UNKNOWN_MSG          DEFAULT_GENERAL_OPT_PATH"/block_unknown_msg"
+#define MSG_SMS_LIMIT                          DEFAULT_GENERAL_OPT_PATH"/sms_limit"
+#define MSG_MMS_LIMIT                          DEFAULT_GENERAL_OPT_PATH"/mms_limit"
+#define MSG_SETTING_NOTIFICATION       DEFAULT_GENERAL_OPT_PATH"/notification"
+#define MSG_SETTING_VIBRATION          DEFAULT_GENERAL_OPT_PATH"/vibration"
+#define MSG_SETTING_PREVIEW                    DEFAULT_GENERAL_OPT_PATH"/preview"
+#define MSG_SETTING_RINGTONE_PATH                      DEFAULT_GENERAL_OPT_PATH"/ringtone_path"
+#define MSG_SETTING_RINGTONE_TYPE                      DEFAULT_GENERAL_OPT_PATH"/ringtone_type"
+#define MSG_MMS_UA_PROFILE                             DEFAULT_GENERAL_OPT_PATH"/ua_profile"
+#define MSG_MMS_UA_AGENT                               DEFAULT_GENERAL_OPT_PATH"/ua_agent"
 
 #define SMS_SEND_DCS                                                   DEFAULT_SMS_SEND_OPT_PATH"/dcs"
 #define SMS_SEND_NETWORK_MODE  VCONFKEY_MESSAGE_NETWORK_MODE
 #define CB_RECEIVE                                             DEFAULT_CB_MSG_OPT_PATH"/receive"
 #define CB_SAVE                                                DEFAULT_CB_MSG_OPT_PATH"/save"
 #define CB_MAX_SIM_COUNT                       DEFAULT_CB_MSG_OPT_PATH"/max_sim_count"
-#define CB_CHANNEL_COUNT                       DEFAULT_CB_MSG_OPT_PATH"/channel_count"
 #define CB_CHANNEL_ACTIVATE            DEFAULT_CB_MSG_OPT_PATH"/channel_activate"
 #define CB_CHANNEL_ID_FROM             DEFAULT_CB_MSG_OPT_PATH"/channel_id_from"
 #define CB_CHANNEL_ID_TO               DEFAULT_CB_MSG_OPT_PATH"/channel_id_to"
 
 #define VOICEMAIL_NUMBER                               DEFAULT_VOICE_MAIL_OPT_PATH"/voice_mail_number"
 #define VOICEMAIL_COUNT                                DEFAULT_VOICE_MAIL_OPT_PATH"/voice_mail_count"
+#define VOICEMAIL_ALPHA_ID                             DEFAULT_VOICE_MAIL_OPT_PATH"/voice_mail_alphaid"
+#define VOICEMAIL_DEFAULT_NUMBER       ""
+#define VOICEMAIL_DEFAULT_ALPHA_ID     ""
 
 #define MSGSIZE_OPTION                                 DEFAULT_MSGSIZE_OPT_PATH"/msg_size"
 
 #define SIM_USED_COUNT                                 DEFAULT_SIM_COUNT_PATH"/used_cnt"
 #define SIM_TOTAL_COUNT                                DEFAULT_SIM_COUNT_PATH"/total_cnt"
 
+#define MSG_DEFAULT_APP_ID                     "org.tizen.message"
+#define MSG_QUICKPANEL_APP_ID          "org.tizen.quickpanel"
 
 /*==================================================================================================
                                          TYPES
@@ -175,6 +203,15 @@ typedef unsigned char MSG_SUB_TYPE_T;
 
 
 /**
+ *     @brief  Represents a message tag type. \n
+ *     Each main type of a message can be divided into some tag types. \n
+ *     For instance of SMS, the message sub type can be one of the Priority, Finance, and so on. \n
+ *     The values for this type SHOULD be in _MSG_SUB_TYPE_E.
+ */
+typedef unsigned int MSG_TAG_TYPE_T;
+
+
+/**
  *     @brief  Represents a message class. \n
  *     The values for this type SHOULD be in _MSG_CLASS_TYPE_E.
  */
@@ -214,7 +251,8 @@ typedef struct
        MSG_MESSAGE_TYPE_S              msgType;                                                                                /**< Indicates the message type such as SMS and MMS */
        msg_storage_id_t                storageId;                                                                              /**< Indicates where the message is saved. */
        int                                             nAddressCnt;                                                                    /**< Indicates the count of addresses. */
-       MSG_ADDRESS_INFO_S              addressList[MAX_TO_ADDRESS_CNT];                                /**< Indicates the address information list. */
+//     MSG_ADDRESS_INFO_S              addressList[MAX_TO_ADDRESS_CNT];                                /**< Indicates the address information list. */
+       MSG_ADDRESS_INFO_S              *addressList;                           /**< Indicates the address information list. */
        char                                    replyAddress[MAX_PHONE_NUMBER_LEN+1];                   /**< Indicates the reply address. */
        char                                    subject[MAX_SUBJECT_LEN+1];                                             /**< Indicates the message subject. */
        time_t                                  displayTime;                                                                    /**< Indicates the display time related to the specific operation. */
@@ -232,8 +270,10 @@ typedef struct
        char                                    msgText[MAX_MSG_TEXT_LEN+1];
        char                                    thumbPath[MSG_FILEPATH_LEN_MAX+1];
        bool                                    bStore;                                                                                 /**< Indicates whether the message is stored or not if it is MWI message. */
+       int                                             sim_idx;
 } MSG_MESSAGE_INFO_S;
 
+
 typedef struct
 {
        msg_message_id_t                msgId;                                                                  /**< Indicates the message ID of this message. */
@@ -244,6 +284,7 @@ typedef struct
        MSG_CLASS_TYPE_T                classType;                                                              /**< Message class type. See enum _MSG_CLASS_TYPE_E */
        msg_storage_id_t                storageId;                                                              /**< Indicates where the message is saved. see enum _MSG_FOLDER_TYPE_E*/
        msg_struct_list_s               *addr_list;
+       GList                   *addressList;
        char                                    replyAddress[MAX_PHONE_NUMBER_LEN+1];   /**< Indicates the reply address. */
        char                                    subject[MAX_SUBJECT_LEN+1];                             /**< Indicates the message subject. */
        time_t                                  displayTime;                                                    /**< Indicates the display time related to the specific operation. */
@@ -263,9 +304,22 @@ typedef struct
        void                                    *pData;                                                                 /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
        void                                    *pMmsData;                                                              /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
        size_t                                  mmsDataSize;
+       int                                             simIndex;
 } MSG_MESSAGE_HIDDEN_S;
 
 /**
+ *     @brief  Represents translation information for thread view.
+ */
+typedef struct
+{
+       int                                             bTranslation;
+       int                                             senderLang;
+       int                                             receiverLang;
+       int                                             bOnlyReceive;
+       int                                             bIncludeOrgMsg;
+} MSG_TRANSLATION_INFO_S;
+
+/**
  *     @brief  Represents message information for thread view.
  */
 typedef struct
@@ -280,7 +334,15 @@ typedef struct
        int                                             unreadCnt;                                                                                                              /**< Indicates the unread messages from the Peer. */
        int                                             smsCnt;                                                                                                                 /**< Indicates the SMS messages from the Peer. */
        int                                             mmsCnt;                                                                                                                 /**< Indicates the MMS messages from the Peer. */
-       bool                                    bProtected;                                                                                                             /**< Indicates whether the thread includes protected messages.  */
+       bool                                            bProtected;                                                                                                             /**< Indicates whether the thread includes protected messages.  */
+       bool                                            bDraft;
+       bool                                            bSendFailed;
+       bool                                            bSending;
+       msg_message_id_t                        lastMsgId;                                                                      /**< Indicates the last message ID of this thread. */
+       MSG_TRANSLATION_INFO_S  msgTranslation;
+       int                                                     simIndex;
+       MSG_TAG_TYPE_T                tagType;                                                       /**< Message tag type. See enum _MSG_TAG_TYPE_E */
+
 } MSG_THREAD_VIEW_S;
 
 
@@ -310,8 +372,24 @@ typedef struct
        char                                                                    subject[MAX_SUBJECT_LEN+1];                                                     /**< Indicates the message subject. */
        size_t                                                          textSize;                                                               /**< Indicates the data size. The unit is byte. */
        char                                                                    *pText;                                                                 /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
+       int tcs_bc_level;
+       char                                                                    firstMediaPath[MSG_FILEPATH_LEN_MAX+1]; // First Media Path in mms;
+       msg_list_handle_t multipart_list;
+       int                                                             simIndex;
 } MSG_CONVERSATION_VIEW_S;
 
+typedef struct
+{
+       MimeType        type;   /**< Indicates the multipart mime type. see enum MimeType */
+       char            szContentType[MSG_MSG_ID_LEN + 1];              /**< Indicates the content type */
+       char            szFileName[MSG_FILENAME_LEN_MAX + 1];           /**< Indicates the file name */
+       char            szFilePath[MSG_FILEPATH_LEN_MAX + 1];           /**< Indicates the file path */
+       char            szContentID[MSG_MSG_ID_LEN + 1];                /**< Indicates the content id */
+       char            szContentLocation[MSG_MSG_ID_LEN + 1];  /**< Indicates the content Location */
+
+       int             tcs_bc_level;   /** detect malware type **/
+       char            szThumbFilePath[MSG_FILEPATH_LEN_MAX + 1];      /**< Indicates the thumbnail file path */
+} MSG_MMS_MULTIPART_S;
 
 /**
  *     @brief  Represents sim message informatioin list.
@@ -345,15 +423,11 @@ typedef struct
 typedef struct
 {
        int                                             listenerFd;             /**< Rx fd for status cnf */
-#ifdef __x86_64__
-       uint64_t                                handleAddr;             /**< Handle address for status cnf */
-#else
        unsigned int                    handleAddr;             /**< Handle address for status cnf */
-#endif
        msg_message_id_t                sentMsgId;              /**< The ID of a sent message for updating message status */
-
 } MSG_PROXY_INFO_S;
 
+
 /**
  *     @brief  Aux data structure for MSG_CMD_REG_INCOMING_MSG_CB. \n
  *     This stucture contains the information about the receiver for msgType and port.
@@ -470,7 +544,6 @@ typedef struct
        unsigned char                   language_type[MAX_CB_MSG_LANGUAGE_TYPE_LEN];
 } MSG_CB_MSG_S;
 
-
 /*==================================================================================================
                                          ENUMS
 ==================================================================================================*/
@@ -540,8 +613,19 @@ enum _MSG_SUB_TYPE_E
        MSG_SENDREQ_JAVA_MMS,                   /**< MMS Send Request message for JAVA MMS */
 
        MSG_ETWS_SMS,
+       MSG_MWI_VOICE2_SMS,                     /**< MWI Message Voice for line 2(CPHS)*/
+       MSG_UNSAVED_SMS,                /**< Unsaved message, e.g, SIM change alert message*/
+
+       MSG_CMAS_PRESIDENTIAL,          /**< CMAS CLASS */
+       MSG_CMAS_EXTREME,
+       MSG_CMAS_SEVERE,
+       MSG_CMAS_AMBER,
+       MSG_CMAS_TEST,
+       MSG_CMAS_EXERCISE,
+       MSG_CMAS_OPERATOR_DEFINED,
 };
 
+
 /**
  *     @brief  Represents the values of a message transaction type. \n
  *     This enum is used as the value of MSG_MMS_TRANSACTION_TYPE_T.
@@ -564,6 +648,10 @@ enum _MSG_MMS_ITEM_TYPE_E
        MSG_MMS_ITEM_TYPE_VIDEO,                /**< Indicates the video media */
        MSG_MMS_ITEM_TYPE_ATTACH,               /**< Indicates the attach file */
        MSG_MMS_ITEM_TYPE_PAGE, /**< Indicates the page count */
+       MSG_MMS_ITEM_TYPE_MALWARE,              /**< Indicates the tcs bc level*/
+       MSG_MMS_ITEM_TYPE_1ST_MEDIA,    /**< Indicates the 1st media path*/
 };
+
+
 #endif
 
index 6aceaac..2ce1da6 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_MMS_TYPES_H
@@ -45,6 +45,7 @@
  *     @{
  */
 
+typedef GList MMSList;
 
 /*==================================================================================================
                                          STRUCTURES
@@ -105,8 +106,7 @@ typedef struct
 
        char szContentType[MSG_MSG_ID_LEN + 1];
        char szContentLocation[MSG_MSG_ID_LEN + 1];
-
-}MMS_MEDIA_S;
+} MMS_MEDIA_S;
 
 /**
  *     @brief  Represents attachment information.
@@ -121,7 +121,7 @@ typedef struct
        char            szDrm2FullPath[MSG_FILEPATH_LEN_MAX + 1]; /**< Indicates the fullpath of the DRM */
        char szContentType[MSG_MSG_ID_LEN + 1];
 
-}MMS_ATTACH_S;
+} MMS_ATTACH_S;
 
 /**
  *     @brief  Represents SMIL page information.
@@ -146,7 +146,7 @@ typedef struct
 {
        bool    bUnitPercent; /**< Indicates the length is in percentage(%) or not */
        int     value;  /**< Indicates the value for length */
-}MMS_LENGTH;
+} MMS_LENGTH;
 
 /**
  *     @brief  Represents SMIL region information.
@@ -162,7 +162,7 @@ typedef struct
        int                             bgColor;        /**< Indicates the background color of the region */
        REGION_FIT_TYPE_T       fit;    /**< Indicates the fit type. see enum REGION_FIT_TYPE_T */
 
-}MMS_SMIL_REGION;
+} MMS_SMIL_REGION;
 
 /**
  *     @brief  Represents SMIL root layout information.
@@ -221,28 +221,102 @@ typedef struct
        MMS_APPID_INFO_S        msgAppId;
 }MMS_RECV_DATA_S;
 
+typedef struct _MMS_ADDRESS_DATA_S {
+       int address_type;
+       char *address_val;
+} MMS_ADDRESS_DATA_S;
+
+/**
+ *     @brief  Represents MMS header data.
+ */
 typedef struct _MMS_HEADER_DATA_S
 {
-       char messageID[MSG_MSG_ID_LEN + 1];
-       char trID[MSG_MSG_ID_LEN + 1];
-       char contentLocation[MSG_MSG_ID_LEN + 1];
+       MMSList *bcc;// Bcc
+       MMSList *cc;//  Cc
+       char contentLocation[MMS_LOCATION_LEN + 1];
        char szContentType[MSG_MSG_ID_LEN + 1];//string : ex) application/vnd.wap.multipart.related
-       int contentType;//MimeType : ex) application/vnd.wap.multipart.related
+       unsigned long int date;
+       bool bDeliveryReport; //        X-Mms-Delivery-Report
+       MmsTimeStruct delivery; //      X-Mms-Delivery-Time
+       MmsTimeStruct expiry;
+       char szFrom[254 * 3  + 11]; //"/TYPE=PLMN", /"TYPE=IPv4", "/TYPE=IPv6" //       From
+       int messageClass;//Personal | Advertisement | Informational | Auto
+       char messageID[MSG_MSG_ID_LEN + 1];
        int messageType;//MmsMsgType : ex) sendreq
        int mmsVersion;//1.0 1.3
-       int messageClass;//Personal | Advertisement | Informational | Auto
-       int contentClass;//text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich
+       int messageSize; //X-Mms-Message-Size
        int mmsPriority;//_MSG_PRIORITY_TYPE_E : Low | Normal | High
+       bool bReadReport;//     X-Mms-Read-Report
+//     X-Mms-Report-Allowed
+//     X-Mms-Response-Status
+//     X-Mms-Response-Text
+       bool bHideAddress;//    X-Mms-Sender-Visibility
+       msg_delivery_report_status_t mmsStatus;//       X-Mms-Status
+       char szSubject[MAX_SUBJECT_LEN + 1];//  Subject
+       MMSList *to;//  Cc//    To
+       char trID[MSG_MSG_ID_LEN + 1];
+//     X-Mms-Retrieve-Status
+//     X-Mms-Retrieve-Text
+//     X-Mms-Read-Status
+//     X-Mms-Reply-Charging
+//     X-Mms-Reply-Charging-Deadline
+//     X-Mms-Reply-Charging-ID
+//     X-Mms-Reply-Charging-Size
+//     X-Mms-Previously-Sent-By
+//     X-Mms-Previously-Sent-Date
+//     X-Mms-Store
+//     X-Mms-MM-State
+//     X-Mms-MM-Flags
+//     X-Mms-Store-Status
+//     X-Mms-Store-Status-Text
+//     X-Mms-Stored
+//     X-Mms-Attributes
+//     X-Mms-Totals
+//     X-Mms-Mbox-Totals
+//     X-Mms-Quotas
+//     X-Mms-Mbox-Quotas
+//     X-Mms-Message-Count
+//     Content
+//     X-Mms-Start
+//     Additional-headers
+//     X-Mms-Distribution-Indicator
+//     X-Mms-Element-Descriptor
+//     X-Mms-Limit
+//     X-Mms-Recommended-Retrieval-Mode
+//     X-Mms-Recommended-Retrieval-Mode-Text
+//     X-Mms-Status-Text
+//     X-Mms-Applic-ID
+//     X-Mms-Reply-Applic-ID
+//     X-Mms-Aux-Applic-Info
+       int contentClass;//text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich
+//     X-Mms-DRM-Content
+//     X-Mms-Adaptation-Allowed
+//     X-Mms-Replace-ID
+//     X-Mms-Cancel-ID
+//     X-Mms-Cancel-Status
+//------------------------------------------------------------------
+       int contentType;//MimeType : ex) application/vnd.wap.multipart.related
+
 } MMS_HEADER_DATA_S;
 
+/**
+ *     @brief  Represents MMS multipart data.
+ */
 typedef struct
 {
        MimeType        type;   /**< Indicates the multipart mime type. see enum MimeType */
        char            szContentType[MSG_MSG_ID_LEN + 1];              /**< Indicates the content type */
        char            szFileName[MSG_FILENAME_LEN_MAX + 1];           /**< Indicates the file name */
-       char            szFilePath[MSG_FILEPATH_LEN_MAX + 1];           /**< Indicates the file path */
        char            szContentID[MSG_MSG_ID_LEN + 1];                /**< Indicates the content id */
        char            szContentLocation[MSG_MSG_ID_LEN + 1];  /**< Indicates the content Location */
+       MsgDrmType              drmType; /**< Indicates the drm type. see enum MsgDrmType */
+
+       char            szFilePath[MSG_FILEPATH_LEN_MAX + 1];           /**< Indicates the file path */
+       char *pMultipartData;
+       size_t nMultipartDataLen;
+       int             tcs_bc_level;   /** detect malware type **/
+       int     malware_allow;
+       char            szThumbFilePath[MSG_FILEPATH_LEN_MAX + 1];              /**< Indicates the thubnail file path */
 } MMS_MULTIPART_DATA_S;
 
 /**
@@ -264,8 +338,19 @@ typedef struct _MMS_MESSAGE_DATA_S
        GList                                   *metalist;      /**< The pointer to SMIL meta list */
        MMS_SMIL_ROOTLAYOUT             rootlayout;     /**< Indicates the root layout information */
        MMS_APPID_INFO_S                msgAppId;
-       MMS_HEADER_DATA_S header;
-       MMS_MULTIPART_DATA_S smil;
+       MMS_HEADER_DATA_S header;//use for scloud
+       MMS_MULTIPART_DATA_S smil;//use for scloud
 } MMS_MESSAGE_DATA_S;
 
+/**
+ *     @brief  Represents MMS message data.
+ */
+typedef struct
+{
+       int backup_type; //none = 0 || scloud backup = 1 || kies backup = 2;
+       MMS_HEADER_DATA_S *header; /**< The header struct of MMS*/
+       MMS_MULTIPART_DATA_S *smil;
+       MMSList *multipartlist; /**< list of MMS_MULTIPART_DATA_S*/
+} MMS_DATA_S;
+
 #endif
index 2eb4c04..667ae81 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
  /**
@@ -524,7 +524,7 @@ typedef msg_error_t (*MsgPlgSaveSimMessage)(const MSG_MESSAGE_INFO_S *pMsgInfo,
  *
  */
 /*================================================================================================*/
-typedef msg_error_t (*MsgPlgDeleteSimMessage)(msg_sim_id_t SimMsgId);
+typedef msg_error_t (*MsgPlgDeleteSimMessage)(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
 
 
  /**
@@ -565,7 +565,7 @@ typedef msg_error_t (*MsgPlgDeleteSimMessage)(msg_sim_id_t SimMsgId);
  *
  */
 /*================================================================================================*/
-typedef msg_error_t (*MsgPlgSetReadStatus)(msg_sim_id_t SimMsgId);
+typedef msg_error_t (*MsgPlgSetReadStatus)(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
 
 
  /**
@@ -606,7 +606,7 @@ typedef msg_error_t (*MsgPlgSetReadStatus)(msg_sim_id_t SimMsgId);
  *
  */
 /*================================================================================================*/
-typedef msg_error_t (*MsgPlgSetMemoryStatus)(msg_error_t Error);
+typedef msg_error_t (*MsgPlgSetMemoryStatus)(msg_sim_slot_id_t sim_idx, msg_error_t Error);
 
 
 // Setting API
@@ -891,7 +891,6 @@ typedef msg_error_t (*MsgPlgUpdateMessage)(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SEN
 *
 * \param output - pMsg is information of MMS message.
 * \param output - pSendOptInfo is information of sending options.
-* \param output - pMmsMsg is information of MMS messages detail data.
 * \param output - pDestMsg is file path of MMS message.
 *
 * \return Return Type (int(msg_error_t)) \n
@@ -909,7 +908,7 @@ typedef msg_error_t (*MsgPlgUpdateMessage)(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SEN
 *
 */
 /*================================================================================================*/
-typedef msg_error_t (*MsgPlgGetMmsMessage)(MSG_MESSAGE_INFO_S* pMsg,   MSG_SENDINGOPT_INFO_S* pSendOptInfo, MMS_MESSAGE_DATA_S* pMmsMsg, char** pDestMsg);
+typedef msg_error_t (*MsgPlgGetMmsMessage)(MSG_MESSAGE_INFO_S* pMsg,   MSG_SENDINGOPT_INFO_S* pSendOptInfo, char** pDestMsg);
 
 
 /**
@@ -1035,6 +1034,10 @@ typedef msg_error_t (*MsgPlgComposeReadReport)(MSG_MESSAGE_INFO_S *pMsgInfo);
 /*================================================================================================*/
 typedef msg_error_t (*MsgPlgRestoreMsg)(MSG_MESSAGE_INFO_S *pMsg, char* pRcvdBody, int rcvdBodyLen, char* filePath);
 
+typedef msg_error_t (*MsgPlgGetMeImei) (char *pImei);
+
+typedef msg_error_t (*MsgPlgGetDefaultNetworkSimId) (int *simId);
+
 
 // framework defined callbacks.
 typedef void (*MsgPlgOnSentStatus)(MSG_SENT_STATUS_S *pSentStatus);
@@ -1044,24 +1047,29 @@ typedef msg_error_t (*MsgPlgOnInitSimBySat)(void);
 typedef msg_error_t (*MsgPlgOnSyncMLMsgIncoming)(MSG_SYNCML_MESSAGE_DATA_S *pSyncMLData);
 typedef msg_error_t (*MsgPlgOnLBSMsgIncoming)(MSG_LBS_MESSAGE_DATA_S *pLBSData);
 typedef msg_error_t (*MsgPlgOnPushMsgIncoming)(MSG_PUSH_MESSAGE_DATA_S *pPushData);
-typedef msg_error_t (*MsgPlgOnCBMsgIncoming)(MSG_CB_MSG_S *pCbMsg);
+typedef msg_error_t (*MsgPlgOnCBMsgIncoming)(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo);
 typedef msg_error_t (*MsgPlgOnMmsConfIncoming)(MSG_MESSAGE_INFO_S *pMsgInfo, msg_request_id_t *pRequest);
-
+typedef msg_error_t (*MsgPlgOnSimMessageIncoming)(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize);
+typedef msg_error_t (*MsgPlgOnResendMessage)(void);
+typedef msg_error_t (*MsgPlgOnInitImsi)(int sim_idx);
 
 /*==================================================================================================
                                          STRUCTURES
 ==================================================================================================*/
 struct _MSG_PLUGIN_LISTENER_S
 {
-       MsgPlgOnSentStatus                      pfSentStatusCb;                 /** The function pointer of sent status callback. */
-       MsgPlgOnStorageChange           pfStorageChangeCb;              /** The function pointer of storage change callback. */
-       MsgPlgOnMsgIncoming                     pfMsgIncomingCb;                        /** The function pointer of receive message callback. */
-       MsgPlgOnInitSimBySat                    pfInitSimBySatCb;                       /** The function pointer of init SIM callback. */
+       MsgPlgOnSentStatus                                      pfSentStatusCb;                                 /** The function pointer of sent status callback. */
+       MsgPlgOnStorageChange                   pfStorageChangeCb;                      /** The function pointer of storage change callback. */
+       MsgPlgOnMsgIncoming                             pfMsgIncomingCb;                                /** The function pointer of receive message callback. */
+       MsgPlgOnInitSimBySat                            pfInitSimBySatCb;                               /** The function pointer of init SIM callback. */
        MsgPlgOnSyncMLMsgIncoming       pfSyncMLMsgIncomingCb;  /** The function pointer of receive syncML message callback. */
-       MsgPlgOnLBSMsgIncoming          pfLBSMsgIncomingCb;             /** The function pointer of receive LBS message callback. */
+       MsgPlgOnLBSMsgIncoming                  pfLBSMsgIncomingCb;                     /** The function pointer of receive LBS message callback. */
        MsgPlgOnPushMsgIncoming         pfPushMsgIncomingCb;            /** The function pointer of receive Push message callback. */
-       MsgPlgOnCBMsgIncoming           pfCBMsgIncomingCb;                      /** The function pointer of receive cb message callback. */
-       MsgPlgOnMmsConfIncoming         pfMmsConfIncomingCb;    /** The function pointer of receive MMS conf */
+       MsgPlgOnCBMsgIncoming                   pfCBMsgIncomingCb;                      /** The function pointer of receive cb message callback. */
+       MsgPlgOnMmsConfIncoming                 pfMmsConfIncomingCb;            /** The function pointer of receive MMS conf */
+       MsgPlgOnSimMessageIncoming      pfSimMsgIncomingCb;                     /** The function pointer of sim message callback */
+       MsgPlgOnResendMessage           pfResendMessageCb;
+       MsgPlgOnInitImsi                        pfSimInitImsiCb;
 };
 
 
@@ -1070,15 +1078,11 @@ struct _MSG_PLUGIN_HANDLER_S
        MsgPlgInitialize                                pfInitialize;                           /**< The function pointer of initialize. */
        MsgPlgFinalize                                  pfFinalize;                             /**< The function pointer of finalize. */
        MsgPlgRegisterListener                  pfRegisterListener;                     /**< The function pointer of register listener. */
-       MsgPlgCheckSimStatus                    pfCheckSimStatus;               /**< The function pointer of check SIM status. */
-       MsgPlgCheckDeviceStatus         pfCheckDeviceStatus;            /**< The function pointer of check device status. */
        MsgPlgSubmitRequest                     pfSubmitRequest;                /**< The function pointer of submit request. */
-       MsgPlgInitSimMessage                    pfInitSimMessage;                       /**< The function pointer of initialize SIM msg. */
        MsgPlgSaveSimMessage                    pfSaveSimMessage;               /**< The function pointer of save SIM msg. */
        MsgPlgDeleteSimMessage          pfDeleteSimMessage;             /**< The function pointer of delete SIM msg. */
        MsgPlgSetReadStatus                     pfSetReadStatus;                        /**< The function pointer of set read status. */
        MsgPlgSetMemoryStatus           pfSetMemoryStatus;              /**< The function pointer of set memory status. */
-       MsgPlgInitConfigData                    pfInitConfigData;                       /**< The function pointer of initialize of setting. */
        MsgPlgSetConfigData                     pfSetConfigData;                        /**< The function pointer of save setting. */
        MsgPlgGetConfigData                     pfGetConfigData;                        /**< The function pointer of get setting. */
        MsgPlgRestoreMsg                                pfRestoreMsg;
@@ -1088,6 +1092,7 @@ struct _MSG_PLUGIN_HANDLER_S
        MsgPlgGetMmsMessage                     pfGetMmsMessage;
        MsgPlgUpdateRejectStatus                pfUpdateRejectStatus;
        MsgPlgComposeReadReport                 pfComposeReadReport;
+       MsgPlgGetDefaultNetworkSimId    pfGetDefaultNetworkSimId;
 };
 
 #ifdef __cplusplus
index 82ccfed..886f71f 100755 (executable)
@@ -1,30 +1,31 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MsgThdSafeQ_H__
 #define __MsgThdSafeQ_H__
 
-#include <queue>
 #include "MsgMutex.h"
 #include <list>
 
-template <typename T> class MsgThdSafeQ
+
+template <typename T> 
+class MsgSimpleQ
 {
 public:
-       MsgThdSafeQ(){};
+       MsgSimpleQ(){};
        void pop_front ();
        bool front(T* qItem);
        void push_front(T const & input);
@@ -34,27 +35,20 @@ public:
        void clear();
        bool checkExist(T const & qItem, bool(cmp)(T const &, T const &));
 private:
-       Mutex mx;
        std::list <T> q;
 };
 
-/*
-       mx variable guarantees atomic operation in multi-threaded environment.
-       For example, when a thread is executing Pop(), other threads
-       trying to execute one of Pop, Push, Size, Empty are locked.
-*/
-
-template <typename T> void MsgThdSafeQ<T>::pop_front()
+template <typename T> 
+void MsgSimpleQ<T>::pop_front()
 {
-       MutexLocker lock(mx);
        if( q.empty() ) return;
 
        q.pop_front();
 }
 
-template <typename T> bool MsgThdSafeQ<T>::front(T* qItem)
+template <typename T> 
+bool MsgSimpleQ<T>::front(T* qItem)
 {
-       MutexLocker lock(mx);
        if( qItem == NULL || q.empty() )
                return false; // Fail
 
@@ -64,41 +58,40 @@ template <typename T> bool MsgThdSafeQ<T>::front(T* qItem)
 }
 
 
-template <typename T> void MsgThdSafeQ<T>::push_back(T const & qItem)
+template <typename T> 
+void MsgSimpleQ<T>::push_back(T const & qItem)
 {
-       MutexLocker lock(mx);
        q.push_back(qItem);
 }
 
-template <typename T> void MsgThdSafeQ<T>::push_front(T const & qItem)
+template <typename T> void 
+MsgSimpleQ<T>::push_front(T const & qItem)
 {
-       MutexLocker lock(mx);
        q.push_front(qItem);
 }
 
 
-template <typename T> int MsgThdSafeQ<T>::size()
+template <typename T> 
+int MsgSimpleQ<T>::size()
 {
-       MutexLocker lock(mx);
        return q.size();
 }
 
-template <typename T> bool MsgThdSafeQ<T>::empty()
+template <typename T> 
+bool MsgSimpleQ<T>::empty()
 {
-       MutexLocker lock(mx);
        return q.empty();
 }
 
-template <typename T> void MsgThdSafeQ<T>::clear()
+template <typename T> 
+void MsgSimpleQ<T>::clear()
 {
-       MutexLocker lock(mx);
        q.clear();
 }
 
-template <typename T> bool MsgThdSafeQ<T>::checkExist(T const & qItem, bool(cmp)(T const &, T const &))
+template <typename T> 
+bool MsgSimpleQ<T>::checkExist(T const & qItem, bool(cmp)(T const &, T const &))
 {
-       MutexLocker lock(mx);
-
        for(typename list<T>::iterator iterPos = q.begin(); iterPos != q.end(); ++iterPos)      {
 
                if (cmp(qItem, *iterPos) == true)
index 0c39313..3c52ff1 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_SETTING_TYPES_H
@@ -34,6 +34,7 @@
                                          INCLUDE FILES
 ==================================================================================================*/
 #include "MsgTypes.h"
+#include "MsgStorageTypes.h"
 
 /**
  *     @ingroup                MESSAGING_FRAMEWORK
@@ -179,11 +180,18 @@ typedef unsigned char MSG_CB_LANGUAGE_TYPE_T;
 
 /**
  *     @brief  Represents the SIM status from telephony. \n
- *     The values for this type SHOULD be in \ref _MSG_SIM_STATUS_E.
+ *     The values for this type SHOULD be in _MSG_SIM_STATUS_E.
  */
 typedef unsigned char MSG_SIM_STATUS_T;
 
 
+/**
+ *     @brief  Represents the ringtone type of message. \n
+ *     The values for this type SHOULD be in _MSG_RINGTONE_TYPE_E.
+ */
+typedef int MSG_RINGTONE_TYPE_T;
+
+
 /*==================================================================================================
                                          STRUCTURES
 ==================================================================================================*/
@@ -210,25 +218,32 @@ typedef struct
        MSG_SMSC_ADDRESS_S              smscAddr;                                       /**< SMSC address structure */
 } MSG_SMSC_DATA_S;
 
+
 /**
  *     @brief  Represents an SMSC list.
  */
 typedef struct
 {
-       int                                             selected;                                                       /**< Selected SMSC index */
+       int                                             index;                                          /**< SMSC index for Updating information */
+       int                                             selected;                                       /**< Selected SMSC index */
        int                                             totalCnt;                                                       /**< The count of total SMSC addresses */
-       MSG_SMSC_DATA_S                 smscData[SMSC_LIST_MAX];                        /**< SMSC data information list*/
+       MSG_SMSC_DATA_S                 smscData[SMSC_LIST_MAX];                /**< SMSC data information list*/
+       msg_sim_slot_id_t               simIndex;
 }MSG_SMSC_LIST_S;
 
+
 /**
  *     @brief  Represents an SMSC list.
  */
 typedef struct
 {
+       int                                             index;                                  /**< SMSC index for Updating information */
        int                                             selected;                               /**< Selected SMSC index */
-       msg_struct_list_s               *smsc_list;                             /**< SMSC data information list*/
+       msg_struct_list_s               *smsc_list;                     /**< SMSC data information list*/
+       msg_sim_slot_id_t               simIndex;
 }MSG_SMSC_LIST_HIDDEN_S;
 
+
 /**
  *     @brief  Represents the information of a cell broadcasting channel.
  */
@@ -237,6 +252,8 @@ typedef struct
        bool                    bActivate;                                                      /**< Indicates whether the CB channel is activate or passive. */
        unsigned int    from;                                                           /**< Indicates the start ID of a CB channel range. */
        unsigned int    to;                                                                     /**< Indicates the end ID of a CB channel range. */
+       unsigned short ctg;                                                             /**< Indicates the category of a CB. (for 3gpp2)*/
+       unsigned short lang;                                                            /**< Indicates the language of a CB. (for 3gpp2)*/
        char                    name[CB_CHANNEL_NAME_MAX+1];            /**< Indicates the name of a CB channel. */
 } MSG_CB_CHANNEL_INFO_S;
 
@@ -250,14 +267,24 @@ typedef struct
        MSG_CB_CHANNEL_INFO_S   channelInfo[CB_CHANNEL_MAX];    /**< The structure of CB channel information */
 } MSG_CB_CHANNEL_S;
 
+
 /**
  *     @brief  Represents an general option.
  */
 typedef struct
 {
-       bool                                                    bKeepCopy;                      /**< Indicates whether the SMS message copy is kept or not. */
-       MSG_ALERT_TONE_T                        alertTone;                      /**< Indicates the period of playing alert tone. */
-       bool                                                    bAutoErase;                     /**< Indicates whether the auto-erase option is enabled or not. */
+       bool                                    bKeepCopy;                      /**< Indicates whether the SMS message copy is kept or not. */
+       MSG_ALERT_TONE_T                alertTone;                      /**< Indicates the period of playing alert tone. */
+       bool                                    bAutoErase;                     /**< Indicates whether the auto-erase option is enabled or not. */
+       bool                                    bBlockUnknownMsg;               /**< Indicates whether unknown sender message is blocked or not. */
+       int                                             smsLimitCnt;            /**< Indicates the count limitation of sms messages in one conversation */
+       int                                             mmsLimitCnt;            /**< Indicates the count limitation of sms messages in one conversation */
+       bool                                    bNotification;          /**< Indicates whether notification for incoming message is shown or not. */
+       bool                                    bVibration;             /**< Indicates whether vibration for incoming message is run or not. */
+       bool                                    bPreview;                       /**< Indicates whether preview for incoming message is shown or not. */
+       char                                    ringtonePath[MSG_FILEPATH_LEN_MAX+1];           /**< Indicates the message ringtone path */
+       int                                     ringtoneType;           /**< Indicates the message ringtone type. */
+       int                                             searchTags;                     /**< Indicates the tags to be enabled for search ex) MSG_MESSAGE_TAG_PRIMARY | MSG_MESSAGE_TAG_PROMOTION.  See enum _MSG_TAG_TYPE_E  */
 }MSG_GENERAL_OPT_S;
 
 
@@ -356,6 +383,7 @@ typedef struct
        int                                     maxSimCnt;              /**< Indicates the number of channels which can be stored in SIM. */
        MSG_CB_CHANNEL_S        channelData;            /**< Indicates the cell broadcasting channel information. */
        bool                            bLanguage[CB_LANG_TYPE_MAX];            /**< Indicates whether the language name of a cell broadcasting message is set or not. */
+       msg_sim_slot_id_t                                       simIndex;
 } MSG_CBMSG_OPT_S;
 
 typedef struct
@@ -364,14 +392,18 @@ typedef struct
        int                                     maxSimCnt;              /**< Indicates the number of channels which can be stored in SIM. */
        msg_struct_list_s       *channelData;           /**< Indicates the cell broadcasting channel information. */
        bool                                    bLanguage[CB_LANG_TYPE_MAX];            /**< Indicates whether the language name of a cell broadcasting message is set or not. */
+       msg_sim_slot_id_t                                       simIndex;
 } MSG_CBMSG_OPT_HIDDEN_S;
 
+
 /**
  *     @brief  Represents a voice mail number option.
  */
 typedef struct
 {
        char mailNumber[MAX_PHONE_NUMBER_LEN+1];
+       char alpahId[MAX_SIM_XDN_ALPHA_ID_LEN+1];
+       msg_sim_slot_id_t                                       simIndex;
 } MSG_VOICEMAIL_OPT_S;
 
 
diff --git a/include/common/MsgSmil.h b/include/common/MsgSmil.h
new file mode 100755 (executable)
index 0000000..6537e0e
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_SMIL_H
+#define MSG_SMIL_H
+
+#include "MsgMmsTypes.h"
+
+/**    @fn     bool MsgSmilParseSmilDoc(MMS_MESSAGE_DATA_S *pstMsgMmsBody, const char *pSmilDoc)
+ *     @brief  Parse Smil Document using MMS_MESSAGE_DATA_S struct.
+ *     @param[in]      pstMsgMmsBody
+ *     @param[in]      pSmilDoc
+ *     @retval TRUE    In case of Success.
+ *     @retval FALSE   In case of failure.
+ */
+bool MsgSmilParseSmilDoc(MMS_MESSAGE_DATA_S *pstMsgMmsBody, const char *pSmilDoc);
+
+/**    @fn     bool MsgSmilGenerateSmilDoc(MMS_MESSAGE_DATA_S *pstMsgMmsBody, char **ppSmilDoc)
+ *     @brief  Generate Smil Document using MMS_MESSAGE_DATA_S struct.
+ *     @param[in]      pstMsgMmsBody
+ *     @param[out]     ppSmilDoc
+ *     @retval TRUE    In case of Success.
+ *     @retval FALSE   In case of failure.
+ */
+bool MsgSmilGenerateSmilDoc(MMS_MESSAGE_DATA_S *pstMsgMmsBody, char **ppSmilDoc);
+
+#endif//MSG_SMIL_H
index bc0cd25..ca6c3d0 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_STORAGE_TYPES_H
@@ -91,10 +91,15 @@ typedef struct
 typedef struct
 {
        msg_contact_id_t        contactId;                                                      /**< Indicates the unique contact ID. */
-       char                            firstName[MAX_DISPLAY_NAME_LEN+1];              /**< Indicates the first name of contact. */
-       char                            lastName[MAX_DISPLAY_NAME_LEN+1];               /**< Indicates the last name of contact. */
-       char                            displayName[MAX_DISPLAY_NAME_LEN+1];            /**< Indicates the display name of contact. */
-       char                            imagePath[MAX_IMAGE_PATH_LEN+1];                /**< Indicates the image path of contact. */
+       int                                             addrbookId;                                                     /**< Indicates the address book ID. */
+       char                                    firstName[MAX_DISPLAY_NAME_LEN+1];              /**< Indicates the first name of contact. */
+       char                                    lastName[MAX_DISPLAY_NAME_LEN+1];               /**< Indicates the last name of contact. */
+       char                                    middleName[MAX_DISPLAY_NAME_LEN+1];             /**< Indicates the middle name of contact. */
+       char                                    prefix[MAX_DISPLAY_NAME_LEN+1];         /**< Indicates the prefix of contact. */
+       char                                    suffix[MAX_DISPLAY_NAME_LEN+1];         /**< Indicates the suffix of contact. */
+       char                                    imagePath[MAX_IMAGE_PATH_LEN+1];                /**< Indicates the image path of contact. */
+       char                                            alerttonePath[MSG_FILEPATH_LEN_MAX+1];          /**< Indicates the message alert tone path of contact. */
+       char                                            vibrationPath[MSG_FILEPATH_LEN_MAX+1];          /**< Indicates the vibration path of contact. */
 } MSG_CONTACT_INFO_S;
 
 
@@ -105,7 +110,7 @@ typedef struct
  */
 typedef struct
 {
-       msg_sort_type_t sortType;               /**< Indicates the sort type */
+       msg_sort_type_t sortType;               /**< Indicates the sort type, See enum _MSG_SORT_TYPE_E */
        bool                                    bAscending;             /**< Indicates the sort order which is ascending or descending */
 }MSG_SORT_RULE_S;
 
@@ -143,6 +148,29 @@ typedef struct
 } MSG_SEARCH_CONDITION_S;
 
 
+/**
+ *     @brief  Represents Message list condition values.
+ */
+typedef struct
+{
+       msg_folder_id_t                 folderId;
+       msg_thread_id_t                 threadId;
+       msg_storage_id_t                        storageId;
+       msg_message_type_t      msgType;
+       bool                                                            bProtected;
+       bool                                                            bScheduled;
+       char                                                            *pAddressVal;
+       char                                                            *pTextVal;
+       bool                                                            bAnd;
+       time_t                                                  fromTime;
+       time_t                                                  toTime;
+       int                                                             offset;
+       int                                                             limit;
+       msg_struct_t                                    sortRule;
+       int                                                     simIndex;
+} MSG_LIST_CONDITION_S;
+
+
 typedef struct
 {
        int appcode;
index 08e8e21..c3c5ed6 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_THREAD_H__
index 0849f39..e4cf048 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_TRANSPORT_TYPES_H
index aa9b5d2..2cf4fd4 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_TYPES_H
  */
 #define        MMS_V1_2                                                                // MMS Version : MMS_V1_0 / MMS_V1_1 / MMS_V1_2
 
+
+/**
+ * @brief Defines the notification method
+ */
+#define MSG_NOTI_INTEGRATION
+
+/**
+ * @brief Defines the enabled drm
+ */
+#define MSG_DRM_SUPPORT        (0)
+
 /**
  *     @brief  Defines message struct handle.
  */
@@ -275,6 +286,7 @@ typedef struct
        char                                                    pushBody[MAX_WAPPUSH_CONTENTS_LEN + 1];
        int                                                             wspHeaderLen;
        char                                                    wspHeader[MAX_WAPPUSH_CONTENTS_LEN + 1];
+       int                                                     simIndex;
 }MSG_SYNCML_MESSAGE_DATA_S;
 
 
diff --git a/include/externals/MsgAlarm.h b/include/externals/MsgAlarm.h
new file mode 100755 (executable)
index 0000000..954b147
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_ALARM_H
+#define MSG_ALARM_H
+
+#include <time.h>
+#include "MsgTypes.h"
+
+/*==================================================================================================
+                                       DEFINES
+==================================================================================================*/
+
+typedef void (*msg_alarm_cb)(int alarmId);
+
+/*==================================================================================================
+                                       FUNCTION PROTOTYPES
+==================================================================================================*/
+msg_error_t MsgAlarmRegistration(struct tm *timeInfo, msg_alarm_cb userCB, int *alarmId);
+msg_error_t MsgAlarmRemove(int alarmId);
+
+#endif // MSG_ALARM_H
diff --git a/include/externals/MsgDevicedWrapper.h b/include/externals/MsgDevicedWrapper.h
new file mode 100644 (file)
index 0000000..e405e3d
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_DEVICED_WRAPPER_H
+#define MSG_DEVICED_WRAPPER_H
+
+
+void MsgDisplayLock();
+void MsgDisplayUnlock();
+void MsgChangePmState();
+
+#endif /* MSG_DEVICED_WRAPPER_H */
diff --git a/include/externals/MsgLbs.h b/include/externals/MsgLbs.h
new file mode 100755 (executable)
index 0000000..ff24ebf
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSGLBS_H_
+#define MSGLBS_H_
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+
+/*==================================================================================================
+                                         DEFINES
+==================================================================================================*/
+#define MSG_LBS_PORT 7275
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+void MsgLbsSms(const char *msgBody, int msgSize);
+void MsgLbsWapPush(const char *pushHeader, const char *pushBody, int pushBodySize);
+
+
+#endif /* MSGLBS_H_ */
diff --git a/include/externals/MsgNotificationWrapper.h b/include/externals/MsgNotificationWrapper.h
new file mode 100755 (executable)
index 0000000..9f53662
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_NOTIFICATION_WRAPPER_H
+#define MSG_NOTIFICATION_WRAPPER_H
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "MsgInternalTypes.h"
+#include "MsgSqliteWrapper.h"
+
+/*==================================================================================================
+                                         DEFINES
+==================================================================================================*/
+#define MSG_APP_PACKAGE_NAME   "message"
+
+#define MSG_APP_LOCALEDIR                      "/usr/apps/"MSG_DEFAULT_APP_ID"/res/locale"
+
+#define MSG_NOTIFICATION_ICON_DIR                      MSG_QUICKPANEL_APP_ID"/shared/res/noti_icons/Message"
+
+// notification icon
+#define MSG_NORMAL_ICON_PATH   "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message.png"
+#define MSG_SIM_ICON_PATH      "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_sim-card.png"
+#define MSG_VOICE_ICON_PATH            "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_voice_mail.png"
+#define MSG_CB_ICON_PATH                       "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_cb-msg.png"
+#define MSG_READ_ICON_PATH             "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_read_report.png"
+#define MSG_DELIVERY_ICON_PATH "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_delivery_report.png"
+#define MSG_REPLY_ICON_PATH                    "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_reply.png"
+#define MSG_SMS_SENDING_FAILED_ICON_PATH               "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_failed.png"
+#define MSG_MMS_SENDING_FAILED_ICON_PATH               "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_mms_failed.png"
+#define MSG_MMS_RETRIVE_FAILED_ICON_PATH               "/usr/apps/"MSG_NOTIFICATION_ICON_DIR"/noti_message_mms_problem.png"
+#define MSG_EMERGENCY_ICON_PATH                "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/noti_emergency_mode.png"
+#define MSG_NORMAL_MSG_INDICATOR_ICON_PATH             "/usr/apps/"MSG_DEFAULT_APP_ID"/res/images/M01_tab_icon_sms_mms.png"
+
+// status bar icon
+#define MSG_NORMAL_STATUS_ICON                         "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/status_bar_message.png"
+#define MSG_FAILED_STATUS_ICON                         "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/status_bar_cancel_message.png"
+#define MSG_DELIVER_REPORT_STATUS_ICON "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/status_bar_delivery_report_message.png"
+#define MSG_READ_REPORT_STATUS_ICON            "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/status_bar_read_report_message.png"
+#define MSG_VOICE_MSG_STATUS_ICON                      "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/status_bar_voicemail.png"
+#define MSG_SIM_FULL_STATUS_ICON               "/usr/apps/"MSG_DEFAULT_APP_ID"/res/icons/default/small/status_bar_sim_card_full.png"
+
+#ifndef TIZEN_I586_ENABLED
+// system string
+#define NEW_MESSAGE                    "IDS_MSGF_POP_NEW_MESSAGE"
+#define NEW_MESSAGES                   "IDS_MSGF_POP_NEW_MESSAGES"
+#define MSG_UNKNOWN_SENDER     "IDS_MSGF_BODY_UNKNOWN"
+#define MSG_NO_SUBJECT                 "IDS_MSGF_BODY_NO_SUBJECT"
+
+
+// message app string for ticker noti
+#define SENDING_MULTIMEDIA_MESSAGE_FAILED      "IDS_MSGF_POP_SENDING_MULTIMEDIA_MESSAGE_FAILED"
+#define MULTIMEDIA_MESSAGE_SENT                                        "IDS_MSGF_POP_MULTIMEDIA_MESSAGE_SENT"
+#define RETRIEVING_MESSAGE_FAILED                                      "IDS_MSGF_POP_RETRIEVING_MESSAGE_FAILED"
+#define MESSAGE_RETRIEVED                                                              "IDS_MSGF_BODY_MESSAGE_RETRIEVED"
+#define SMS_MESSAGE_SENT                                                               "IDS_MSGC_POP_MESSAGESENT"
+#define SMS_MESSAGE_SENDING_FAIL                                       "IDS_MSGF_POP_SENDING_MESSAGE_FAILED"
+#define SMS_MESSAGE_SENDING_PENDING                                    "IDS_MSG_POP_UNABLE_TO_SEND_MESSAGE_IT_WILL_BE_SENT_WHEN_SERVICE_AVAILABLE"
+#define SMS_MESSAGE_SIM_MESSAGE_FULL                           "IDS_MSGF_BODY_SIM_MEMORY_FULL_DELETE_SOME_ITEMS"
+#define SMS_MESSAGE_MEMORY_FULL                        "IDS_MSGF_POP_NOT_ENOUGH_MEMORY_DELETE_SOME_ITEMS"
+#define SMS_FDN_RESTRICTED                             "IDS_MSGF_POP_FDN_ENABLED_CANT_SEND_MSG"
+#define SMS_SIM_CARD_FULL                              "IDS_MSG_HEADER_SIM_CARD_FULL"
+#define SMS_MESSAGE_SIZE_OVER_SIM_SLOT_SIZE    "IDS_MSGF_BODY_MESSAGE_IS_TOO_LARGE_TO_STORE_AS_A_SINGLE_MESSAGE_TO_SIM_CARD"
+
+// message app string for quickpanel noti
+#define MSG_MESSAGE            "IDS_MSGF_BODY_MESSAGE"
+#define VOICE_MAIL                                     "IDS_MSGF_BODY_VOICEMAIL"
+#define NEW_VOICE_MAIL                 "IDS_MSGF_BODY_NEW_VOICEMAIL"
+#define APP_NEW_MESSAGE "IDS_MSGF_POP_NEW_MESSAGE"
+#define APP_NEW_MESSAGES "IDS_MSGF_POP_NEW_MESSAGES"
+#define CB_MESSAGE "IDS_MSGF_BODY_CB_MESSAGES"
+#define PUSH_MESSAGE "IDS_MSGF_BODY_PUSH_MESSAGES"
+#define DELIVERY_MESSAGE "IDS_MSGF_BODY_DELIVERY_REPORT"
+#define READ_REPORT_MESSAGE "IDS_MSGF_POP_READ_REPORT"
+#define EXPIRED_MESSAGE "IDS_MSGF_BODY_MESSAGE_HAS_EXPIRED"
+#define REJECTED_MESSAGE "IDS_MSGF_BODY_MMSDELIVERYMSGREJECTED"
+#define DEFERRED_MESSAGE "IDS_MSGF_POP_MESSAGE_DEFERRED"
+#define UNRECOGNISED_MESSAGE "IDS_MSGF_POP_MESSAGE_UNRECOGNISED"
+#define INDETEMINATE_MESSAGE "IDS_MSGF_POP_INDETERMINATE"
+#define UNREACHABLE_MESSAGE "IDS_MSGF_POP_UNREACHABLE"
+#define DELIVERED_MESSAGE "IDS_MSGF_BODY_MESSAGE_DELIVERED"
+#define VOICE_1_MESSAGE        "IDS_MSGF_BODY_1_MESSAGE"
+#define VOICE_N_MESSAGE        "IDS_MSGF_BODY_PD_MESSAGES"
+#define SIM_CARD_MESSAGE               "IDS_MSGF_BODY_SIM_CARD_MESSAGES"
+#define READ_REPORT_READ               "IDS_COM_BODY_READ"
+#define READ_REPORT_DELETE     "IDS_COM_POP_DELETED"
+#define FAILED_MSG_EXIST       "IDS_MSG_BODY_FAILED_MESSAGES_EXIST"
+#define ENABLE_EMERGENCY_MODE  "IDS_MSG_BODY_ENABLE_EMERGENCY_MODE_JPN_DCM"
+#define EMERGENCY_MODE_DESCRIPTION     "IDS_MSG_SBODY_TAP_HERE_TO_ENABLE_EMERGENCY_MODE_TO_SAVE_BATTERY_POWER_JPN_DCM"
+#define FAILED_TO_SEND_MESSAGE "IDS_MSG_TPOP_FAILED_TO_SEND_MESSAGE_ABB"
+#else
+// system string
+#define NEW_MESSAGE                    "New message"
+#define NEW_MESSAGES                   "New messages"
+#define MSG_UNKNOWN_SENDER     "New message from Unknown."
+#define MSG_NO_SUBJECT                 "No subject"
+
+
+// message app string for ticker noti
+#define SENDING_MULTIMEDIA_MESSAGE_FAILED      "Sending multimedia message failed"
+#define MULTIMEDIA_MESSAGE_SENT                                        "Multimedia message sent."
+#define RETRIEVING_MESSAGE_FAILED                                      "Retrieving message failed"
+#define MESSAGE_RETRIEVED                                                              "Message retrieved"
+#define SMS_MESSAGE_SENT                                                               "Message sent."
+#define SMS_MESSAGE_SENDING_FAIL                                       "Sending message failed."
+#define SMS_MESSAGE_SENDING_PENDING                                    "Unable to send message. It will be sent when service available."
+#define SMS_MESSAGE_SIM_MESSAGE_FULL                           "SIM memory full. Delete some items."
+#define SMS_MESSAGE_MEMORY_FULL                        "Not enough memory. Delete some items."
+#define SMS_FDN_RESTRICTED                             "Unable to send the message while Fixed dialling mode is enabled."
+#define SMS_SIM_CARD_FULL                              "SIM card full"
+#define SMS_MESSAGE_SIZE_OVER_SIM_SLOT_SIZE    "Message is too large to store as a single message to SIM card." //
+
+// message app string for quickpanel noti
+#define MSG_MESSAGE            "Message"
+#define VOICE_MAIL                                     "Voicemail"
+#define NEW_VOICE_MAIL                 "New voicemail"
+#define APP_NEW_MESSAGE "New message"
+#define APP_NEW_MESSAGES "New messages"
+#define CB_MESSAGE "CB messages"
+#define PUSH_MESSAGE "Push messages"
+#define DELIVERY_MESSAGE "Delivery report"
+#define READ_REPORT_MESSAGE "Read report"
+#define EXPIRED_MESSAGE "Message expired."
+#define REJECTED_MESSAGE "Message rejected."
+#define DEFERRED_MESSAGE "Message deferred"
+#define UNRECOGNISED_MESSAGE "Message unrecognised"
+#define INDETEMINATE_MESSAGE "Indeterminate."
+#define UNREACHABLE_MESSAGE "Unreachable"
+#define DELIVERED_MESSAGE "Message delivered"
+#define VOICE_1_MESSAGE        "1 message"
+#define VOICE_N_MESSAGE        "%d messages"
+#define SIM_CARD_MESSAGE               "SIM card messages"
+#define READ_REPORT_READ               "Read"
+#define READ_REPORT_DELETE     "Deleted."
+#define FAILED_MSG_EXIST       "Failed messages exist."
+#define ENABLE_EMERGENCY_MODE  "Enable Emergency mode"
+#define EMERGENCY_MODE_DESCRIPTION     "Tap here to enable Emergency mode to save battery power."
+#define FAILED_TO_SEND_MESSAGE "Failed to send message." //
+#endif
+
+#define NOTIFICATION_PRIV_ID   DEFAULT_SETTING_PATH"/notification_priv_id"
+#define VOICE_NOTI_ID_1                DEFAULT_SETTING_PATH"/voice_noti_id1"
+#define VOICE_NOTI_ID_2                        DEFAULT_SETTING_PATH"/voice_noti_id2"
+#define CB_NOTI_PRIV_ID                DEFAULT_SETTING_PATH"/cb_noti_priv_id"
+#define SIM_MSG_NOTI_PRIV_ID   DEFAULT_SETTING_PATH"/sim_msg_noti_priv_id"
+#define EMERGENCY_MODE_NOTI_ID         DEFAULT_SETTING_PATH"/emergency_noti_id"
+#define MSG_SENTFAIL_NOTI_ID           DEFAULT_SETTING_PATH"/sentfail_noti_id"
+#define SIM_FULL_NOTI_PRIV_ID  DEFAULT_SETTING_PATH"/sim_full_noti_id"
+
+#define MSG_NOTI_TEXT_LEN      (512)
+#define MSG_NOTI_TEXT_LEN_S    (256)
+
+enum _msg_notification_type_e
+{
+       MSG_NOTI_TYPE_ALL = 0x00,
+
+       // Refresh single/multiple notification
+       MSG_NOTI_TYPE_NORMAL,
+       MSG_NOTI_TYPE_CB,
+       MSG_NOTI_TYPE_SIM,
+       MSG_NOTI_TYPE_FAILED,
+
+       // Add only single notification
+       MSG_NOTI_TYPE_VOICE_1,
+       MSG_NOTI_TYPE_VOICE_2,
+       MSG_NOTI_TYPE_MWI,
+       MSG_NOTI_TYPE_CLASS0,
+       MSG_NOTI_TYPE_SMS_DELIVERY_REPORT,
+       MSG_NOTI_TYPE_MMS_READ_REPORT,
+       MSG_NOTI_TYPE_MMS_DELIVERY_REPORT,
+
+       MSG_NOTI_TYPE_SIM_FULL,
+};
+
+typedef unsigned char msg_notification_type_t; //_msg_notification_type_e
+
+msg_error_t MsgInsertNotification(MSG_MESSAGE_INFO_S *msg_info);
+
+msg_error_t MsgAddNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info);
+msg_error_t MsgRefreshNotification(msg_notification_type_t noti_type, bool bFeedback, bool bTicker);
+msg_error_t MsgAddReportNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info);
+msg_error_t MsgDeleteReportNotification(const char *addr);
+
+msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId);
+msg_error_t MsgInsertInstantMessage(msg_notification_type_t noti_type);
+msg_error_t MsgInitNoti();
+msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt);
+msg_error_t MsgDeleteNoti(msg_notification_type_t noti_type);
+
+void MsgRefreshAllNotification(bool bWithSimNoti, bool bFeedback, bool bTickerNoti);
+void MsgDeleteNotification(msg_notification_type_t noti_type);
+void MsgInitReportNotiList();
+
+#endif
diff --git a/include/externals/MsgSensorWrapper.h b/include/externals/MsgSensorWrapper.h
new file mode 100755 (executable)
index 0000000..ab1e279
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_SENSOR_H
+#define MSG_SENSOR_H
+
+
+#include "MsgTypes.h"
+
+/*==================================================================================================
+                                       DEFINES
+==================================================================================================*/
+
+typedef void (*msg_sensor_cb)();
+
+/*==================================================================================================
+                                       FUNCTION PROTOTYPES
+==================================================================================================*/
+
+msg_error_t MsgSensorConnect();
+void MsgSensorDisconnect();
+msg_error_t MsgRegSensorCB(msg_sensor_cb cb);
+
+#endif // MSG_SENSOR_H
diff --git a/include/externals/MsgSoundPlayer.h b/include/externals/MsgSoundPlayer.h
new file mode 100755 (executable)
index 0000000..0aec565
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_SOUND_PLAYER_H
+#define MSG_SOUND_PLAYER_H
+
+
+/*==================================================================================================
+                                         TYPES
+==================================================================================================*/
+typedef unsigned char MSG_SOUND_TYPE_T;
+
+/*==================================================================================================
+                                         ENUMS
+==================================================================================================*/
+enum _MSG_SOUND_TYPE_E
+{
+       MSG_SOUND_PLAY_DEFAULT = 0,
+       MSG_SOUND_PLAY_USER,
+       MSG_SOUND_PLAY_EMERGENCY,
+       MSG_SOUND_PLAY_VOICEMAIL,
+};
+
+/*==================================================================================================
+                                CLASS DEFINITIONS
+==================================================================================================*/
+class MsgSoundPlayer
+{
+public:
+       static MsgSoundPlayer* instance();
+
+       void MsgSoundPlayStart(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_SOUND_TYPE_T soundType);
+       void MsgSoundPlayStop();
+
+       void MsgSoundInitRepeatAlarm();
+       void MsgSoundPlayDtmf();
+
+       void MsgGetRingtonePath(char *userRingtonePath, char **msg_tone_file_path_p);
+       void MsgGetPlayStatus(bool bVoiceMail, bool *bPlaySound, bool *bPlayVibration, bool *bOnCall);
+
+private:
+       MsgSoundPlayer();
+       ~MsgSoundPlayer();
+
+       void MsgSoundPlayMelody(char *pMsgToneFilePath);
+       void MsgSoundPlayVibration(char *vibrationPath, bool isOnCall);
+
+       void MsgSoundSetRepeatAlarm();
+       void MsgSoundCreateRepeatAlarm(int RepeatTime);
+       int MsgSoundGetUnreadMsgCnt();
+
+       static MsgSoundPlayer* pInstance;
+
+       bool bPlaying;
+       bool bVibrating;
+       bool bFeedbackInit;
+
+       int g_alarmId;
+
+       char *defaultRingtonePath;
+};
+
+#endif // MSG_SOUND_PLAYER_H
+
similarity index 56%
rename from include/utils/MsgSpamFilter.h
rename to include/externals/MsgSpamFilter.h
index cbe765d..ea67d8e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_SPAM_FILTER_H
@@ -33,5 +33,6 @@ msg_error_t MsgSetFilterOperation(bool bSetFlag);
 msg_error_t MsgGetFilterOperation(bool *pSetFlag);
 
 bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo);
+bool MsgCheckFilterByWord(MsgDbHandler *pDbHandle, const char *pMsgText);
 
 #endif // MSG_SPAM_FILTER_H
index 3525ecc..d9974ea 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_CMD_HANDLER_H
@@ -82,6 +82,7 @@ int MsgRegIncomingLBSMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgRegSyncMLMsgOperationCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgRegStorageChangeCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgStorageChangeHandler(const MSG_CMD_S *pCmd, char **ppEvent);
+int MsgRegIncomingReportMsgCallbackHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 
 int MsgSentStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgIncomingMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent);
@@ -104,7 +105,10 @@ int MsgAddPushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgDeletePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgUpdatePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 
-int MsgContactSyncEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
-
-
+int MsgAddSimMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent);
+int MsgResendMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent);
+int MsgUpdateIMSIHandler(const MSG_CMD_S *pCmd, char **ppEvent);
+#ifdef MSG_PENDING_PUSH_MESSAGE
+int MsgSendPendingPushMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent);
+#endif
 #endif // MSG_CMD_HANDLER_H
index 51e4e17..c8f3cb8 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_DELIVER_HANDLER_H
index fac0a1b..3c66b88 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_PLUGIN_CONFIG_H
index 58ea662..14a1fc0 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_PLUGIN_MANAGER_H
@@ -48,24 +48,22 @@ public:
 
        msg_error_t submitReq(MSG_REQUEST_INFO_S *pReqInfo);
        msg_error_t registerListener(MSG_PLUGIN_LISTENER_S *pListener);
-       msg_error_t checkSimStatus(MSG_SIM_STATUS_T *pStatus);
-       msg_error_t checkDeviceStatus();
 
-       msg_error_t initSimMessage();
        msg_error_t saveSimMessage(MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList);
-       msg_error_t deleteSimMessage(msg_sim_id_t SimMsgId);
-       msg_error_t setReadStatus(msg_sim_id_t SimMsgId);
-       msg_error_t setMemoryStatus(msg_error_t Error);
+       msg_error_t deleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
+       msg_error_t setReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
+       msg_error_t setMemoryStatus(msg_sim_slot_id_t sim_idx, msg_error_t Error);
 
-       msg_error_t initConfigData(MSG_SIM_STATUS_T SimStatus);
        msg_error_t setConfigData(const MSG_SETTING_S *pSetting);
        msg_error_t getConfigData(MSG_SETTING_S *pSetting);
 
+       msg_error_t getDefaultNetworkSimId(int *simId);
+
        // MMS handlers
        msg_error_t addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData);
        msg_error_t updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData);
        msg_error_t processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject);
-       msg_error_t getMmsMessage(MSG_MESSAGE_INFO_S *pMsg,  MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg);
+       msg_error_t getMmsMessage(MSG_MESSAGE_INFO_S *pMsg,  MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg);
        msg_error_t updateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo);
        msg_error_t composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo);
 
@@ -99,6 +97,7 @@ public:
 
        void initialize();
        void finalize();
+       MsgPlugin* checkPlugin(MSG_MAIN_TYPE_T mainType);
        MsgPlugin* getPlugin(MSG_MAIN_TYPE_T mainType);
        void loadPlugins(const char* path);
 
index f971636..54ba7ba 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_SETTING_HANDLER_H
@@ -27,8 +27,6 @@
 /*==================================================================================================
                                        FUNCTION PROTOTYPES
 ==================================================================================================*/
-msg_error_t MsgInitSimConfig(MSG_SIM_STATUS_T SimStatus);
-
 msg_error_t MsgSetConfigData(const MSG_SETTING_S *pSetting);
 msg_error_t MsgGetConfigData(MSG_SETTING_S *pSetting);
 
@@ -52,10 +50,12 @@ void MsgGetMMSRecvOpt(MSG_SETTING_S *pSetting);
 void MsgGetMMSStyleOpt(MSG_SETTING_S *pSetting);
 void MsgGetPushMsgOpt(MSG_SETTING_S *pSetting);
 void MsgGetCBMsgOpt(MSG_SETTING_S *pSetting);
+
 void MsgGetVoiceMailOpt(MSG_SETTING_S *pSetting);
 void MsgGetMsgSizeOpt(MSG_SETTING_S *pSetting);
 
 msg_error_t MsgSetConfigInSim(const MSG_SETTING_S *pSetting);
+msg_error_t MsgGetConfigInSim(MSG_SETTING_S *pSetting);
 
 //void MsgSetDefaultConfig();
 
index f4513e1..175ca42 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_STORAGE_HANDLER_H
@@ -51,13 +51,15 @@ msg_error_t MsgAddDefaultAddress();
 msg_error_t MsgStoResetDatabase();
 
 msg_error_t MsgStoBackupMessage(msg_message_backup_type_t type, const char *filepath);
-msg_error_t MsgStoRestoreMessage(const char *filepath);
+msg_error_t MsgStoRestoreMessage(const char *filepath, msg_id_list_s**result_id_list);
 
 msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S* pSendOptInfo);
+msg_error_t MsgStoRestoreMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo);
 msg_error_t MsgStoUpdateMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S* pSendOptInfo);
 msg_error_t MsgStoUpdateReadStatus(msg_message_id_t MsgId, bool bRead);
-msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t ThreadId);
+msg_error_t MsgStoUpdateThreadReadStatus(msg_thread_id_t ThreadId, msg_id_list_s *pMsgIdList);
 msg_error_t MsgStoUpdateProtectedStatus(msg_message_id_t MsgId, bool bProtected);
+msg_error_t MsgStoUpdateConversationTagType(msg_thread_id_t threadId, int tagType);
 msg_error_t MsgStoDeleteMessage(msg_message_id_t MsgId, bool bCheckIndication);
 msg_error_t MsgStoDeleteAllMessageInFolder(msg_folder_id_t FolderId, bool bOnlyDB, msg_id_list_s *pMsgIdList);
 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList);
@@ -66,26 +68,18 @@ msg_error_t MsgStoMoveMessageToStorage(const msg_message_id_t MsgId, const msg_s
 msg_error_t MsgStoCountMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo);
 msg_error_t MsgStoCountMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount);
 msg_error_t MsgStoGetMessage(msg_message_id_t MsgId, MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S* pSendOptInfo);
-msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATION_VIEW_S *pConv);
-msg_error_t MsgStoGetFolderViewList(msg_folder_id_t FolderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList);
 msg_error_t MsgStoAddSyncMLMessage(MSG_MESSAGE_INFO_S *pMsgInfo, int ExtId, int PinCode);
 msg_error_t MsgStoGetMsgType(msg_message_id_t msgId, MSG_MESSAGE_TYPE_S* pMsgType);
 msg_error_t MsgStoGetText(msg_message_id_t MsgId, char *pSubject, char *pMsgText);
 msg_error_t MsgStoGetQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_INFO_S *pMsg);
-msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList);
-msg_error_t MsgStoGetConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList);
 msg_error_t MsgStoDeleteThreadMessageList(msg_thread_id_t ThreadId, bool bIncludeProtect, msg_id_list_s *pMsgIdList);
 msg_error_t MsgStoCountMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pThreadCountInfo);
-msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList);
-msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList);
-msg_error_t MsgStoGetRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList);
-msg_error_t MsgStoGetReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus);
+msg_error_t MsgStoGetSmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus);
+msg_error_t MsgStoGetMmsReportStatus(msg_message_id_t msgId, int *count, MSG_REPORT_STATUS_INFO_S **pReportStatus);
 msg_error_t MsgStoGetThreadIdByAddress(const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pThreadId);
 msg_error_t MsgStoGetThreadUnreadCnt(msg_thread_id_t ThreadId, int *cnt);
 
-msg_error_t MsgStoGetAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList);
 msg_error_t MsgStoGetThreadInfo(msg_thread_id_t threadId, MSG_THREAD_VIEW_S *pThreadInfo);
-msg_error_t MsgStoGetMessageList(msg_folder_id_t folderId, msg_thread_id_t threadId, msg_message_type_t msgType, msg_storage_id_t storageId, msg_struct_list_s *pMsgList);
 
 // Folder
 msg_error_t MsgStoAddFolder(const MSG_FOLDER_INFO_S *pFolderInfo);
@@ -101,12 +95,10 @@ msg_error_t MsgStoGetFilterList(msg_struct_list_s *pFilterList);
 msg_error_t MsgStoSetFilterActivation(msg_filter_id_t filterId, bool bActive);
 
 // Sim Operation related Functions
-msg_error_t MsgInitSimMessage(MSG_SIM_STATUS_T SimStatus);
 msg_error_t MsgStoClearSimMessageInDB();
 
 // Internal Function
-msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort);
-msg_error_t MsgStoGetSmsSendOpt(msg_message_id_t MsgId, MSG_SENDINGOPT_INFO_S* pSendOpt);
+msg_error_t MsgStoGetSmsSendOpt(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S* pSendOpt);
 msg_error_t MsgStoGetMmsSendOpt(msg_message_id_t MsgId, MSG_SENDINGOPT_INFO_S* pSendOpt);
 
 // SyncML Msg
@@ -116,7 +108,7 @@ bool MsgStoCheckSyncMLMsgInThread(msg_thread_id_t threadId);
 msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg);
 msg_error_t MsgStoGetContentLocation(MSG_MESSAGE_INFO_S* pMsgInfo);
 msg_error_t MsgStoSetReadReportSendStatus(msg_message_id_t msgId, int readReportSendStatus);
-
+msg_error_t MsgStoGetReadReportSendStatus(msg_message_id_t msgId, int *pReadReportSendStatus);
 
 ///////////////////////////////////////////////////////////////////////////////////
 // For MMS - will be removed
@@ -129,12 +121,27 @@ msg_error_t MsgStoGetAddrInfo(msg_message_id_t MsgId, MSG_ADDRESS_INFO_S *pAddrI
 ///////////////////////////////////////////////////////////////////////////////////
 
 msg_error_t MsgStoResetNetworkStatus();
+#if 0
+msg_error_t MsgStoResetCBMessage();
+#endif
 msg_error_t MsgStoCleanAbnormalMmsData();
 msg_error_t MsgStoCheckReadReportStatus(msg_message_id_t msgId);
+msg_error_t MsgStoAutoDeleteConversation(msg_thread_id_t threadId, msg_id_list_s *msgIdList);
 
 msg_error_t MsgStoAddPushEvent(MSG_PUSH_EVENT_INFO_S* pPushEvent);
 msg_error_t MsgStoDeletePushEvent(MSG_PUSH_EVENT_INFO_S* pPushEvent);
 msg_error_t MsgStoUpdatePushEvent(MSG_PUSH_EVENT_INFO_S* pSrc, MSG_PUSH_EVENT_INFO_S* pDst);
 
+msg_message_id_t MsgStoAddSimMessage(MSG_MESSAGE_INFO_S *pMsg, int *simIdList, int listSize);
+msg_error_t MsgStoGetFailedMessage(int **failed_msg_list, int *count);
+
+msg_error_t MsgStoGetReplaceMsgId(MSG_MESSAGE_INFO_S *pMsgInfo);
+msg_error_t MsgStoAddWAPMsg(MSG_MESSAGE_INFO_S *pMsgInfo);
+msg_error_t MsgStoAddCOWAPMsg(MSG_MESSAGE_INFO_S *pMsgInfo);
+msg_error_t MsgStoAddCBMsg(MSG_MESSAGE_INFO_S *pMsgInfo);
+msg_error_t MsgStoCheckPushMsgValidation(MSG_PUSH_MESSAGE_S *pPushMsg, bool *pbProceed);
+msg_error_t MsgStoUpdateAllAddress();
+msg_error_t MsgStoUpdateIMSI(int sim_idx);
+
 #endif // MSG_STORAGE_HANDLER_H
 
index 29e708d..d3d9591 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_SUBMIT_HANDLER_H
index 129a411..6b52862 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_TRANSACTION_MANAGER_H
@@ -25,6 +25,7 @@
 #include <map>
 
 #include "MsgMutex.h"
+#include "MsgQueue.h"
 #include "MsgIpcSocket.h"
 #include "MsgCmdTypes.h"
 #include "MsgInternalTypes.h"
 
 
 
+
 /*==================================================================================================
                                          DEFINITION
 ==================================================================================================*/
 typedef std::map<MSG_CMD_TYPE_T, int (*)(const MSG_CMD_S*, char**)> handler_map;
 typedef std::map<int, MSG_PROXY_INFO_S> sentmsg_map;
+#ifdef MSG_PENDING_PUSH_MESSAGE
+typedef std::list<MSG_PUSH_MESSAGE_DATA_S> pushpending_list;
+#endif
 typedef std::map<int, bool> fd_map;
 typedef std::list<MSG_CMD_REG_INCOMING_MSG_CB_S> newmsg_list;
 typedef std::list<MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S>      mmsconf_list;
@@ -62,6 +67,7 @@ public:
        static MsgTransactionManager* instance();
 
        void run();
+      void workerEventQueue();
        void write(int fd, const char* buf, int len);
 
        // methods for sent status event
@@ -79,6 +85,10 @@ public:
        void setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId);
        void setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbinfo);
        void setStorageChangeCB(int listenerFd);
+       void setReportMsgCB(int listenerFd);
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       void sendPendingPushMsg(void);
+#endif
 
        javamms_list& getJavaMMSList();
 
@@ -90,7 +100,7 @@ public:
        void broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData);
        void broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId);
        void broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList);
-
+       void broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo);
        void setTMStatus();
        void getTMStatus();
 
@@ -100,6 +110,7 @@ private:
 
        void handleRequest(int fd);
        void cleanup(int fd);
+//     bool checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie);
        bool checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType);
 
        static MsgTransactionManager* pInstance;
@@ -108,7 +119,9 @@ private:
        bool running;
 
        handler_map handlerMap;
-
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       pushpending_list pushMsgList;
+#endif
        sentmsg_map sentMsgMap;                 // req_id, listener_fd, msghandle_addr
        fd_map statusCBFdMap;           // src_fd, true if registered
 
@@ -122,9 +135,11 @@ private:
        syncmlop_list operationSyncMLMsgCBList;         // src_fd, msgType, port if registered
 
        fd_map storageChangeFdMap;      // src_fd, true if registered
+       fd_map reportMsgCBFdMap;        // src_fd, true if registered
 
        Mutex mx;
        CndVar cv;
+       MsgSimpleQ<MSG_CMD_S*> eventQueue;
 };
 
 #endif //MSG_TRANSACTION_MANAGER_H
index b2866c6..beef18f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_H_
 
 #include "msg_types.h"
 
+/*==================================================================================================
+                                    DEFINES
+==================================================================================================*/
+
+/**
+ *     @brief  Defines macro for privilege name http://tizen.org/privilege/message.read
+ */
+#define MSG_SERVICE_READ_PRIV_NAME             "http://tizen.org/privilege/message.read"
+
+/**
+ *     @brief  Defines macro for privilege name http://tizen.org/privilege/message.write
+ */
+#define MSG_SERVICE_WRITE_PRIV_NAME            "http://tizen.org/privilege/message.write"
+
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
-/**
- *     @ingroup                MESSAGING_FRAMEWORK
- *     @defgroup       MESSAGING_CONTROL_API   Messaging Control API
- *     @{
- */
-
 /*==================================================================================================
                                      FUNCTION PROTOTYPES
 ==================================================================================================*/
 
 /**
-
- * \par Description:
- * Opens a channel between an application and messaging framework.
- *
- * \par Purpose:
- * For application to utilize the services of Messaging Framework, this API should be called to establish connection between the application and Messaging Framework.
+ * @internal
+ * @ingroup MSG_SERVICE_FRAMEWORK
+ * @defgroup MSG_SERVICE_FRAMEWORK_CONTROL_MODULE Control API
+ * @brief The Control API provides functions to manage message handle and set or get each structure.
  *
- * \par Typical use case:
- * Any application which utilizes the services of Messaging Framework needs to call this API.
+ * @internal
+ * @addtogroup MSG_SERVICE_FRAMEWORK_CONTROL_MODULE
+ * @{
  *
- * \par Method of function operation:
- * Check for Message Server ready status. If ready connect to the Messaging Server socket and pass the handle application.
+ * @section MSG_SERVICE_FRAMEWORK_CONTROL_MODULE_HEADER Required Header
+ *   \#include <msg.h>
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @section MSG_SERVICE_FRAMEWORK_CONTROL_MODULE_OVERVIEW Overview
  *
- * \par Important notes:
- * - The handle parameter returned must be used by application for further API calls to Messaging Service \n
- * - memory for the handle need not be allocated by the application \n
- * - An error will be returned in case Messaging Service is not running.
+ * The CONTROL API provides the following functionalities:
+ * - Handles message handle
+ * - Get/Set message and setting values
  *
- * \param msg_handle_t    input - handle to be passed for all Messaging Services .
+ * @section MSG_SERVICE_FRAMEWORK_CONTROL_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ *  - http://tizen.org/feature/network.telephony\n
  *
- * \return Return Type (int) \n
- * - MSG_SUCCESS       - Successfully connected to Messaging Service \n
- * - MSG_ERR_NULL_POINTER      -       Input parameter is NULL.
- * - MSG_ERR_MEMORY_ERROR -    Memory error.
- * - MSG_ERR_COMMUNICATION_ERROR       - Communication error between client and server \n
+ * It is recommended to design feature related codes in your application for reliability.\n
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
  *
- * \par Related functions:
- * None
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
  *
- * \par Known issues/bugs:
- * None
+ * More details on featuring your application can be found from <a href="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
  *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
+ */
+
+/**
+ * @brief Opens a channel between an application and messaging framework.
+ * @details For application to utilize the services of Messaging Framework, this API should be called to establish
+ *          connection between the application and Messaging Framework.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * err = msg_open_msg_handle(&msgHandle);
+ * @remarks The handle parameter returned must be used by application for further API calls to Messaging Service.
+ * @remarks The memory for the handle need not be allocated by the application.
+ * @remarks An error will be returned in case Messaging Service is not running.
  *
- * if (err != MSG_SUCCESS)
- * {
- *     sprintf(str, "msg_open_msg_handle() Fail [%d]", err);
- *     print(str);
+ * @param[in] handle The Message handle to be passed for all messaging services
  *
- *     return err; // if success, return OPERATION_SUCCESS. Or if fail, return related error code.
- * }
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS                 Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER   Input parameter is invalid
+ * @retval MSG_ERR_MEMORY_ERROR        Memory error
+ * @retval MSG_ERR_COMMUNICATION_ERROR Communication error between client and server
+ * @retval MSG_ERR_PERMISSION_DENIED   The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_open_msg_handle(msg_handle_t *handle);
 
 
 /**
-
- * \par Description:
- * Closes the channel between application and messaging framework.
+ * @brief Closes the channel between application and messaging framework.
+ * @details Once application utilizes services of Messaging Service, this API needs to be invoked
+ *          to close the channel between application and Messaging Service.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks The handle parameter returned must be used by application for further API calls to Messaging Service.
+ * @remarks The memory for the handle need not be allocated by the application \n
+ * @remarks An error will be returned in case Messaging Service is not running.
+ *
+ * @param[in] handle The Message handle to be passed for all messaging services
  *
- * \par Purpose:
- * Once application utilizes services of Messaging Service, this API needs to be invoked the close the channel between application and Messaging Service.
+ * @return @c 0 on success,
+ *       otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS                 Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER   Input parameter is invalid
+ * @retval MSG_ERR_COMMUNICATION_ERROR Communication error between client and server
+ * @retval MSG_ERR_PERMISSION_DENIED   The application does not have the privilege to call this method
+ */
+
+int msg_close_msg_handle(msg_handle_t *handle);
+
+
+/**
+ * @brief Create structure pointer to get/set message framework data.
+ * @details Get/set message framework data with this structure pointer.
  *
- * \par Typical use case:
- * Any application which has completed using services of Messaging Framework needs to call this API.
+ * @since_tizen 2.3
  *
- * \par Method of function operation:
- * Closes the connection to Messaging Service and deleted the reference to the handle object
+ * @remarks It should use defined enumerations.
+ * @remarks You must release handle after operations.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in] field The enumerations to create the structure pointer
  *
- * \par Important notes:
- * - The handle parameter returned must be used by application for further API calls to Messaging Service \n
- * - memory for the handle need not be allocated by the application \n
- * - An error will be returned in case Messaging Service is not running.
+ * @return The created structure pointer on success,
+ *         otherwise null value
  *
- * \param msg_handle_t    input - handle to be passed for all Messaging Services .
+ * @retval #msg_struct_t Successfully created structure pointer
+ * @retval NULL          Invalid parameter
  *
- * \return Return Type (int) \n
- * - MSG_SUCCESS       - Successfully connected to Messaging Service \n
- * - MSG_ERR_NULL_POINTER      -       Input parameter is NULL.
- * - MSG_ERR_COMMUNICATION_ERROR       - Communication error between client and server \n
+ */
+
+msg_struct_t msg_create_struct(int field);
+
+
+/**
+ * @brief Release memory for message data structure.
+ * @details You must release memory of message data structure that is allocated by msg_create_struct().
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @since_tizen 2.3
  *
- * \par Related functions:
- * None
+ * @remarks It should not be used after this API.
  *
- * \par Known issues/bugs:
- * None
+ * @param[in] msg_struct_handle The structure pointer to release
  *
- * \par Sample code:
- * \code
- * ...
+ * @return @c 0 on success,
+ *         otherwise a negative error value
  *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
+ * @retval MSG_SUCCESS          Success in operation
+ * @retval MSG_ERR_NULL_POINTER      Input parameter is NULL
  *
- * ...
+ */
+
+int msg_release_struct(msg_struct_t *msg_struct_handle);
+
+
+/**
+ * @brief Release memory for list structure.
+ * @details You must release memory of list structure that is allocated by getting list API.
  *
- * err = msg_open_msg_handle(&msgHandle);
+ * @since_tizen 2.3
  *
- * ...
+ * @remarks It should not be used after this API
  *
- * err = msg_close_msg_handle(&msgHandle);
+ * @param[in] msg_struct_list The list structure pointer to release
  *
- * if (err != MSG_SUCCESS)
- * {
- *     sprintf(str, "msg_close_msg_handle() Fail [%d]", err);
- *     print(str);
+ * @return @c 0 on success,
+ *       otherwise a negative error value
  *
- *     return err; // if success, return OPERATION_SUCCESS. Or if fail, return related error code.
- * }
+ * @retval MSG_SUCCESS          Success in operation
+ * @retval MSG_ERR_NULL_POINTER      Input parameter is NULL
  *
- * ...
- * \endcode
  */
-/*================================================================================================*/
-int msg_close_msg_handle(msg_handle_t *handle);
 
+int msg_release_list_struct(msg_struct_list_s *msg_struct_list);
 
 
-msg_struct_t msg_create_struct(int field);
-int msg_release_struct(msg_struct_t *msg_struct_handle);
-int msg_release_list_struct(msg_struct_list_s *msg_struct_list);
+/**
+ * @brief Get a specific integer value from message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle  A pointer of message structure type
+ * @param[in]  field              The enumeration to get a value of specific field
+ * @param[out] value              The requested integer value
+ *
+ * @return @c 0 on success,
+ *       otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
 
 int msg_get_int_value(msg_struct_t msg_struct_handle, int field, int *value);
+
+
+/**
+ * @brief Gets a specific string value from message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle A pointer of message structure type
+ * @param[in]  field             The enumeration to get a value of specific field
+ * @param[out] value             The requested string value
+ * @param[in]  size              The allocated buffer size of application side
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_get_str_value(msg_struct_t msg_struct_handle, int field, char *value, int size);
+
+
+/**
+ * @brief Gets a specific boolean value from message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle  A pointer of message structure type
+ * @param[in]  field              The enumeration to get a value of specific field
+ * @param[out] value              The requested boolean value
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_get_bool_value(msg_struct_t msg_struct_handle, int field, bool *value);
+
+
+/**
+ * @brief Gets an inner structure handle from message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle  A pointer of message structure type
+ * @param[in]  field              The enumeration to get a value of specific field
+ * @param[out] value              The requested structure handle
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_get_struct_handle(msg_struct_t msg_struct_handle, int field, msg_struct_t *value);
+
+
+/**
+ * @brief Gets a list handle from message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle A pointer of message structure type
+ * @param[in]  field             The enumeration to get a value of specific field
+ * @param[out] value             The requested list handle
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+/*================================================================================================*/
 int msg_get_list_handle(msg_struct_t msg_struct_handle, int field, void **value);
 
+
+/**
+ * @brief Sets a specific integer value to message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle A pointer of message structure type
+ * @param[in]  field             The enumeration to get a value of specific field
+ * @param[out] value             The requested integer value
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_set_int_value(msg_struct_t msg_struct_handle, int field, int value);
+
+
+/**
+ * @brief Sets a specific string to message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle A pointer of message structure type
+ * @param[in]  field             The enumeration to get a value of specific field
+ * @param[out] value             The requested string
+ * @param[in]  size              The requested size of string to set
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_set_str_value(msg_struct_t msg_struct_handle, int field, char *value, int size);
+
+
+/**
+ * @brief Sets a specific boolean value to message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @details Set a specific boolean value to message structure data.
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle  A pointer of message structure type
+ * @param[in]  field              The enumeration to get a value of specific field
+ * @param[out] value              The requested boolean value
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_set_bool_value(msg_struct_t msg_struct_handle, int field, bool value);
+
+
+/**
+ * @brief Sets a inner structure handle to message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle A pointer of message structure type
+ * @param[in]  field             The enumeration to get a value of specific field
+ * @param[out] value             The requested structure handle to set
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_set_struct_handle(msg_struct_t msg_struct_handle, int field, msg_struct_t value);
+
+
+/**
+ * @brief Set a list handle to message structure data.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid enumerations.
+ *
+ * @param[in]  msg_struct_handle A pointer of message structure type
+ * @param[in]  field             The enumeration to get a value of specific field
+ * @param[out] value             The requested list handle to set
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter (msg_struct_handle/value) is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter (field) is not valid
+ *
+ */
+
 int msg_set_list_handle(msg_struct_t msg_struct_handle, int field, void *value);
 
-int msg_mms_add_item(msg_struct_t msg_struct_handle, int field, msg_struct_t *item);
+
+/**
+ * @brief Gets a MMS structure handle from message structure.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid structure handle.
+ *
+ * @param[in]  msg_struct_handle  A pointer of message structure type
+ * @param[out] mms_struct_handle  The MMS structure handle to get
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is not valid
+ *
+ */
 
 int msg_get_mms_struct(msg_struct_t msg_struct_handle, msg_struct_t mms_struct_handle);
+
+
+/**
+ * @brief Sets a MMS structure handle to message structure.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid structure handle.
+ *
+ * @param[in]  msg_struct_handle  A pointer of message structure type
+ * @param[out] mms_struct_handle  The MMS structure handle to set
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is not valid
+ *
+ */
+
 int msg_set_mms_struct(msg_struct_t msg_struct_handle, msg_struct_t mms_struct_handle);
 
-//list
+
+/**
+ * @brief Adds an item to list handle of message structure type.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid list_handle.
+ *
+ * @param[in] msg_struct_handle A pointer of message structure type
+ * @param[in] field             The field to set item
+ * @param[in] item              The #msg_struct_t structure to be added to list handle
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is not valid
+ *
+ */
+
+int msg_list_add_item(msg_struct_t msg_struct_handle, int field, msg_struct_t *item);
+
+
+/**
+ * @brief Gets n-th data from list handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid list_handle.
+ *
+ * @param[in] list_handle A pointer of message structure type
+ * @param[in] index       The index of list structure
+ *
+ * @return  #msg_struct_t value on success,
+ *          otherwise @c NULL value
+ *
+ * @retval #msg_struct_t Successfully done
+ * @retval NULL          Input parameter (list_handle) is not valid
+ *
+ */
+
 msg_struct_t msg_list_nth_data(msg_list_handle_t list_handle, int index);
+
+
+/**
+ * @brief Gets the length(count) of list handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid list_handle.
+ *
+ * @param[in] list_handle A pointer of message structure type
+ *
+ * @return  The length of message list (int)
+ *
+ */
+
 int msg_list_length(msg_list_handle_t list_handle);
 
-// filter
+
+/**
+ * @brief Releases entire data of list handle in message structure.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Use valid msg_struct_handle and enumeration.
+ *
+ * @param[in] msg_struct_handle A pointer of message structure type
+ * @param[in] field             The enumeration to release (list handle)
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_NULL_POINTER      Input parameter is NULL
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ *
+ */
+
+int msg_list_clear(msg_struct_t msg_struct_handle, int field);
+
+
+/**
+ * @brief Adds a filter to block messages by address or word.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_struct_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle  The message handle
+ * @param[in] filter  A pointer to message filter structure
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_add_filter(msg_handle_t handle, const msg_struct_t filter);
+
+
+/**
+ * @brief  Updates filter to block messages by address or word.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ * @remarks #msg_struct_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle The message handle
+ * @param[in] filter A pointer to message filter structure
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_update_filter(msg_handle_t handle, const msg_struct_t filter);
+
+
+/**
+ * @brief Deletes tthe filter to block messages by address or word.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @param[in] handle    The message handle
+ * @param[in] filter_id The filter index to delete from filter DB
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_delete_filter(msg_handle_t handle, msg_filter_id_t filter_id);
+
+
+/**
+ * @brief Gets all filter list.
+ * @details This API is used to get a filter list that is already added filter set.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in]  handle      The message handle
+ * @param[out] filter_list A pointer to list of message filter structure
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_filter_list(msg_handle_t handle, msg_struct_list_s *filter_list);
+
+
+/**
+ * @brief Sets the flag of message blocking.
+ * @details This API is used to set a flag of block operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle    The message handle
+ * @param[in] set_flag  Set @c true to enable block operation,
+ *                      otherwise set @c false to disable block operation
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_filter_operation(msg_handle_t handle, bool set_flag);
+
+
+/**
+ * @brief Gets the flag value of message blocking.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in]  handle    The message handle
+ * @param[out] set_flag  @c true if message blocking is enabled,
+ *                       otherwise @c false if message blocking is not enabled
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_filter_operation(msg_handle_t handle, bool *set_flag);
+
+
+/**
+ * @brief Sets the flag of message blocking for specific filter.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle    The message handle
+ * @param[in] filter_id The specific index to set flag
+ * @param[in] active    Set @c true to enable the block operation,
+ *                      otherwise @c false to not enable the block operation
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_FILTER_ERROR      Filter operation error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_filter_active(msg_handle_t handle, msg_filter_id_t filter_id, bool active);
 
-//setting
+
+/**
+ * @brief Gets SMSC list and informations.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of SMSC data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_smsc_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets SMSC list and informations.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of SMSC data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_smsc_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+
+/**
+ * @brief Gets CB channel list and informations.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of CB data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_cb_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets CB channel list and informations.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of CB data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_cb_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets SMS sending options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of sending option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_sms_send_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets SMS sending options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of sending option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_sms_send_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets MMS sending options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of sending option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_mms_send_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets MMS sending options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of sending option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_mms_send_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets MMS receiving options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of receiving option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_mms_recv_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets MMS receiving options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of receiving option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_mms_recv_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets push message options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of push message option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_push_msg_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets push message options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of push message option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_push_msg_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets voice message options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of voice message option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_voice_msg_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets voice message options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of voice message option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_voice_msg_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets message general options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of message general option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_general_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets message general options.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of message general option data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_general_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
+
+/**
+ * @brief Gets message size.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of message size data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_get_msgsize_opt(msg_handle_t handle, msg_struct_t msg_struct);
+
+
+/**
+ * @brief Sets message size.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in] handle     The message handle
+ * @param[in] msg_struct A structure pointer of message size data
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
 int msg_set_msgsize_opt(msg_handle_t handle, msg_struct_t msg_struct);
 
-// text length calculate
+
+/**
+ * @brief Calculates input text length by encode type.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks #msg_handle_t MUST be valid, otherwise the function will fail.
+ *
+ * @param[in]  msg_text            The string to calculate length
+ * @param[in]  msg_encode_type_to  The current encode type
+ * @param[out] text_size           The calculated text size
+ * @param[out] segment_size        The message segment size
+ * @param[out] msg_encode_type_in  The encode type it should be changed to
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Successfully done
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is not valid.
+ *
+ */
+
 int msg_util_calculate_text_length(const char* msg_text, msg_encode_type_t msg_encode_type_to, unsigned int *text_size, unsigned int *segment_size, msg_encode_type_t *msg_encode_type_in);
 
+
+/**
+ * @}
+*/
+
+
 #ifdef __cplusplus
 }
 #endif
index f905af3..56ef540 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_PRIVATE_H_
@@ -53,6 +53,9 @@ void msg_message_copy_message(MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_HIDDEN_S *
 int msg_cb_message_get_int_value(void *data, int field, int *value);
 int msg_cb_message_get_str_value(void *data, int field, char *value, int size);
 
+int msg_message_list_append(msg_struct_t msg_struct_handle, int field, msg_struct_t *item);
+int msg_message_list_clear(msg_struct_t msg_struct_handle, int field);
+
 
 
 
@@ -82,9 +85,12 @@ int msg_mms_set_bool_value(msg_struct_s *msg_struct, int field, bool value);
 int msg_mms_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value);
 int msg_mms_set_list_handle(msg_struct_s *msg_struct, int field, msg_list_handle_t value);
 
+int msg_mms_list_append(msg_struct_t msg_struct_handle, int field, msg_struct_t *item);
+
 void convert_to_mmsdata(const msg_struct_s *pSrc, MMS_MESSAGE_DATA_S *pDest);
 void convert_from_mmsdata(const MMS_MESSAGE_DATA_S *pSrc, msg_struct_s *pDest);
-
+void convert_to_hidden_mmsdata(MMS_DATA_S *pSrc, msg_struct_s *pDest);
+void convert_from_hidden_mmsdata(msg_struct_s *pSrc, MMS_DATA_S *pDest);
 // setting
 int msg_setting_get_int_value(msg_struct_s *msg_struct, int field, int *value);
 int msg_setting_get_str_value(msg_struct_s *msg_struct, int field, char *src, int size);
@@ -137,6 +143,8 @@ int msg_set_push_msg_opt_int(void *push_msg_opt, int field, int value);
 bool msg_get_push_msg_opt_bool(void *push_msg_opt, int field);
 int msg_set_push_msg_opt_bool(void *push_msg_opt, int field, bool value);
 
+int msg_get_voice_msg_opt_int(void *voice_msg_opt, int field);
+int msg_set_voice_msg_opt_int(void *voice_msg_opt, int field, int value);
 char *msg_get_voice_msg_opt_str(void *voice_msg_opt, int field);
 int msg_set_voice_msg_opt_str(void *voice_msg_opt, int field, char *val, int size);
 
@@ -144,7 +152,8 @@ int msg_get_general_opt_int(void *general_opt, int field);
 int msg_set_general_opt_int(void *general_opt, int field, int value);
 bool msg_get_general_opt_bool(void *general_opt, int field);
 int msg_set_general_opt_bool(void *general_opt, int field, bool value);
-
+char *msg_get_general_opt_str(void *general_opt, int field);
+int msg_set_general_opt_str(void *general_opt, int field, char *val, int size);
 
 int msg_get_msgsize_opt_int(void *size_opt, int field);
 int msg_set_msgsize_opt_int(void *size_opt, int field, int value);
@@ -165,19 +174,23 @@ int msg_folder_info_get_int(void *folder_info, int field);
 int msg_thread_info_get_int(void *data, int field);
 int msg_conv_info_get_int(void *data, int field);
 int msg_search_condition_get_int(void *condition_info, int field);
+int msg_list_condition_get_int(void *condition_info, int field);
 int msg_report_status_get_int(void *report_info, int field);
 char* msg_report_status_get_str(void *report_info, int field);
 char* msg_folder_info_get_str(void *folder_info, int field);
 char *msg_thread_info_get_str(void *data, int field);
 char *msg_conv_info_get_str(void *data, int field);
 char* msg_search_condition_get_str(void *condition_info, int field, int size);
+char* msg_list_condition_get_str(void *condition_info, int field, int size);
 bool msg_sendopt_get_bool(void *send_opt, int field);
 bool msg_sortrule_get_bool(void *sort_rule, int field);
 bool msg_conv_get_bool(void *data, int field);
 bool msg_thread_info_get_bool(void *data, int field);
+bool msg_list_condition_get_bool(void *data, int field);
 int msg_sendopt_get_struct_handle(msg_struct_s *msg_struct, int field, void **value);
 int msg_syncml_get_struct_handle(msg_struct_s *msg_struct, int field, void **value);
 int msg_thread_index_get_struct_handle(msg_struct_s *msg_struct, int field, void **value);
+int msg_list_condition_get_struct_handle(msg_struct_s *msg_struct, int field, void **value);
 int msg_address_info_get_int(void *addr_info, int field);
 int msg_mms_sendopt_get_int(void *opt_info, int field);
 int msg_reject_message_get_int(void *msg_info, int field);
@@ -192,15 +205,21 @@ int msg_thread_count_set_int(void *count_info, int field, int value);
 int msg_thread_index_set_int(void *index_info, int field, int value);
 int msg_sortrule_set_int(void *sort_info, int field, int value);
 int msg_folder_info_set_int(void *folder_info, int field, int value);
+int msg_translation_set_bool(void *thread_info, int field, bool value);
+int msg_translation_set_int(void *thread_info, int field, int value);
 int msg_search_condition_set_int(void *condition_info, int field, int value);
+int msg_list_condition_set_int(void *condition_info, int field, int value);
 int msg_report_status_set_int(void *report_info, int field, int value);
 int msg_folder_info_set_str(void *folder_info, int field, char *value, int size);
 int msg_search_condition_set_str(void *condition_info, int field, char *value, int size);
+int msg_list_condition_set_str(void *condition_info, int field, char *value, int size);
 int msg_sendopt_set_bool(void *send_opt, int field, bool value);
 int msg_sortrule_set_bool(void *sort_rule, int field, bool value);
+int msg_list_condition_set_bool(void *data, int field, bool value);
 int msg_sendopt_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value);
 int msg_syncml_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value);
 int msg_thread_index_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value);
+int msg_list_condition_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value);
 int msg_address_info_set_int(void *addrinfo, int field, int value);
 int msg_mms_sendopt_set_int(void *opt_info, int field, int value);
 int msg_reject_message_set_int(void *msg_info, int field, int value);
@@ -216,5 +235,8 @@ int msg_request_set_int(void *request_info, int field, int value);
 int msg_request_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value);
 int msg_sent_status_get_int(MSG_SENT_STATUS_S *sent_status_info, int field);
 
-
+int msg_conversation_get_list_hnd(void *data, int field, void **value);
+int msg_multipart_get_str_value(void *data, int field, char *value, int size);
+int msg_multipart_get_int_value(void *data, int field, int *value);
+int msg_multipart_set_str_value(void *data, int field, char *value, int size);
 #endif /* MSG_PRIVATE_H_ */
index b28ac17..45441bf 100755 (executable)
@@ -1,35 +1,22 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
-/**
- *     @file           MapiStorage.h
- *     @brief          Defines storage API of messaging framework
- *     @version        1.0
- */
-
 #ifndef MAPI_STORAGE_H
 #define MAPI_STORAGE_H
 
-/**
- *     @section                Introduction
- *     - Introduction : Overview on Messaging Storage API
- *     @section                Program
- *     - Program : Messaging Storage API Reference
- */
-
 /*==================================================================================================
                                          INCLUDE FILES
 ==================================================================================================*/
@@ -41,2073 +28,1035 @@ extern "C"
 {
 #endif
 
-/**
- *     @ingroup                MESSAGING_FRAMEWORK
- *     @defgroup       MESSAGING_STORAGE_API   Messaging Storage API
- *     @{
- */
-
-/*==================================================================================================
-                                     FUNCTION PROTOTYPES
-==================================================================================================*/
 
 /**
-
- * \par Description:
- * Saves a message to the database.
- *
- * \par Purpose:
- * This API is used to save Message object to the database.
+ * @internal
+ * @ingroup MSG_SERVICE_FRAMEWORK
+ * @defgroup MSG_SERVICE_FRAMEWORK_STORAGE_MODULE Storage API
+ * @brief The Storage API provides functions to get message information with multiple types.
  *
- * \par Typical use case:
- * Save Message feature is used when the message is to be stored to persistent memory for later reference.
+ * @internal
+ * @addtogroup MSG_SERVICE_FRAMEWORK_STORAGE_MODULE
+ * @{
  *
- * \par Method of function operation:
- * Sets up the database connection and inserts the message to message table.
+ * @section MSG_SERVICE_FRAMEWORK_STORAGE_MODULE_HEADER Required Header
+ *   \#include <msg_storage.h>
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @section MSG_SERVICE_FRAMEWORK_STORAGE_MODULE_OVERVIEW Overview
  *
- * \par Important notes:
- * - Mandatory fields of a message structure MUST be valid, otherwise the function will be failed.
+ * The Storage API provides the following functionalities:
  *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - msg_message_t  msg is a pointer to an msg_message_t structure.
- * \param input - send_opt is a pointer to an MSG_SENDINGOPT_S structure.
+ * - Get message information
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Successfully connected to Messaging Service \n
- * - MSG_ERR_NULL_POINTER      - Input parameter is NULL.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @section MSG_SERVICE_FRAMEWORK_STORAGE_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ *  - http://tizen.org/feature/network.telephony\n
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * It is recommended to design feature related codes in your application for reliability.\n
  *
- * \par Related functions:
- * None
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
  *
- * \par Known issues/bugs:
- * None
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
  *
- * \par Sample code:
- * \code
- * ...
+ * More details on featuring your application can be found from <a href="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
  *
- * msg_handle_t msgHandle = NULL;
- * msg_message_t               msg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
+ */
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+
+/**
+ * @brief Saves a message to the database.
  *
- * ...
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * err = msg_open_msg_handle(&msgHandle);
+ * @remarks Mandatory fields of a message structure MUST be valid, otherwise the function will fail.
  *
- * ...
+ * @param[in] handle    The Message handle
+ * @param[in] msg       A pointer to a message structure
+ * @param[in] send_opt  A pointer to a message structure for sending option
  *
- * err = msg_add_message(handle, (msg_message_t) &msg, &sendingOpt);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
+ * @return  The message ID on success,
+ *       otherwise a negative error value
  *
- * ...
- * \endcode
+ * @retval MESSAGE_ID                    Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER(-9) Invalid parameter
+ * @retval MSG_ERR_STORAGE_ERROR         Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_add_message(msg_handle_t handle, const msg_struct_t msg, const msg_struct_t send_opt);
 
 
 /**
-
- * \par Description:
- * Adds a SyncML message to the database.
- *
- * \par Purpose:
- * This API is used to save  a SyncML message to the database.
- *
- * \par Typical use case:
- * Save Message feature is used when the message is to be stored to persistent memory for later reference.
- *
- * \par Method of function operation:
- * Sets up the database connection and inserts the syncml message to message table.
+ * @brief Adds a SyncML message to the database.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Important notes:
- * - Mandatory fields of a message structure MUST be valid, otherwise the function will be failed.
+ * @remarks Mandatory fields of a message structure MUST be valid, otherwise the function will fail.
  *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - MSG_SYNCML_MESSAGE_S  syncml_msg is a pointer to an MSG_SYNCML_MESSAGE_S structure.
+ * @param[in] handle      The Message handle
+ * @param[in] syncml_msg  A pointer to a syncml message structure
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_NULL_POINTER - pMsg is NULL.
- * - MSG_ERR_INVALID_MSGHANDLE - Message handle is invalid.
- * - MSG_ERR_MSGHANDLE_NOT_CONNECTED - Message handle is not connected.
- * - MSG_ERR_STORAGE_FULL - Storage is FULL.
- * - MSG_ERR_COMMUNICATION_ERROR - Communication between client and server is error.
- * - MSG_ERR_MEMORY_ERROR - Memory is error.
- * - MSG_ERR_MAX_NUMBER_REACHED - Max number is reached.
- * - MSG_ERR_PLUGIN - Generic error code for plugin.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * int err = msg_add_syncml_message(msgHandle, &syncMLMsg);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_add_syncml_message(msg_handle_t handle, const msg_struct_t syncml_msg);
 
 
 /**
-
- * \par Description:
- * Updates a message in the database.
- *
- * \par Purpose:
- * This API is used to update a message in the database.
- *
- * \par Typical use case:
- * Update message feature is used when a previously saved message is to be updated.
- *
- * \par Method of function operation:
- * Sets up the database connection and set the message's new values to message table.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @brief Updates a message in the database.
  *
- * \par Important notes:
- * - The function is to update message data for the message indentified by the given msgId as long as the given values are valid.
- * - msg->msgId MUST NOT be updated because msg->msgId is a unique Id on platform.
- * - If applications want to move a message between folders, applications SHOULD call msg_move_to_folder.
- * - msg->storageId MUST NOT be updated.
- * - The function will return MSG_ERR_INVALID_MESSAGE, if inputting a new msg->storageId.
- * - If applications want to move the message between storages, applications SHOULD call msg_move_to_storage.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \param input - handle is Message handle.
- * \param input - msg is a pointer to an msg_message_t structure.
- * \param input - send_opt is a pointer to an MSG_SENDINGOPT_S structure.
+ * @remarks The function is to update message data for the message identified by the given msgId as long as the given values are valid.
+ * @remarks Message ID MUST NOT be updated because that is a unique ID on platform.
+ * @remarks If applications want to move a message between folders, applications SHOULD call msg_move_to_folder().
+ * @remarks Storage ID MUST NOT be updated.
+ * @remarks If applications want to move the message between storages, applications SHOULD call msg_move_to_storage().
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @param[in] handle   The Message handle
+ * @param[in] msg      A pointer to a message structure
+ * @param[in] send_opt A pointer to a message sending option structure
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_update_message(hMsgHandle, pMsg, &sendOpt);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_update_message(msg_handle_t handle, const msg_struct_t msg, const msg_struct_t send_opt);
 
 
 /**
-
- * \par Description:
- * Updates a message's read status in the database.
- *
- * \par Purpose:
- * This API is used to Updates a message's read status in the database.
- *
- * \par Typical use case:
- * Update message's read status for a previously saved message.
- *
- * \par Method of function operation:
- * Sets up the database connection and updates the message's read status to message table.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @brief Updates a message's read status in the database.
  *
- * \par Important notes:
- * - None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \param input - handle is Message handle.
- * \param input - msg_id is Message ID.
- * \parem input - read is boolean for indicating whether a message is read or not.
+ * @param[in] handle  The message handle
+ * @param[in] msg_id  The message ID
+ * @param[in] read    Set @c true if the message is read,
+ *                    otherwise set @c false if the message is not read
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_update_message(hMsgHandle, pMsg, &sendOpt);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_update_read_status(msg_handle_t handle, msg_message_id_t msg_id, bool read);
 
 
 /**
-
- * \par Description:
- * Updates a message's protected status in the database.
- *
- * \par Purpose:
- * This API is used to Updates a message's protected status in the database.
- *
- * \par Typical use case:
- * Update message's protected status for a previously saved message.
- *
- * \par Method of function operation:
- * Sets up the database connection and updates the message's protected status to message table.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @brief Updates a message's protected status in the database.
  *
- * \par Important notes:
- * - None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \param input - handle is Message handle.
- * \param input - msg_id is Message ID.
- * \parem input - is_protected is boolean for indicating whether a message is protected or not.
+ * @param[in] handle        The message handle
+ * @param[in] msg_id        The message ID
+ * @parem[in] is_protected  Set @c true if a message is protected,
+ *                          otherwise set @c false if message is not protected
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_update_protected_status(hMsgHandle, 0, true);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_update_protected_status(msg_handle_t handle, msg_message_id_t msg_id, bool is_protected);
 
 
 /**
-
- * \par Description:
- * Deletes a message by Message ID from the database.
- *
- * \par Purpose:
- * This API is used to delete a message by Message ID from the database.
- *
- * \par Typical use case:
- * Deletes a previously saved message from the database.
- *
- * \par Method of function operation:
- * Sets up the database connection and deletes a message by Message ID from the message table.
+ * @brief Deletes a message by Message ID from the database.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Important notes:
- * - None
+ * @param[in] handle  The message handle
+ * @param[in] msg_id  The message ID of the message to be deleted
  *
- * \param input - handle is Message handle.
- * \param input - msg_id is the ID of the Message to be deleted.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_delete_message(msgHandle, 0);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_delete_message(msg_handle_t handle, msg_message_id_t msg_id);
 
 
 /**
-
- * \par Description:
- * Deletes all messages in the specified folder from the database.
- *
- * \par Purpose:
- * This API is used to delete all messages in the specified folder from the database.
- *
- * \par Typical use case:
- * Deletes all messages in the specified folder from the database.
- *
- * \par Method of function operation:
- * Sets up the database connection and Deletes all messages in the specified folder from the message table.
+ * @brief Deletes all messages in the specified folder from the database.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Important notes:
- * - None
+ * @param[in] handle   Message handle
+ * @param[in] msg_id   Message ID of the message to be deleted
+ * @param[in] bOnlyDB  Set @c true to not delete messages in SIM,
+ *                     otherwise set @c false to delete messages in SIM
  *
- * \param input - handle is Message handle.
- * \param input - folder_id is the ID of the folder to be deleted.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_delete_all_msgs_in_folder(msgHandle, MSG_DRAFT_ID);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_delete_all_msgs_in_folder(msg_handle_t handle, msg_folder_id_t folder_id, bool bOnlyDB);
 
 
 
 /**
-
- * \par Description:
- * Moves a message to the specified folder in the database.
- *
- * \par Purpose:
- * This API is used to move a message to the specified folder the database.
- *
- * \par Typical use case:
- * Deletes all messages in the specified folder from the database.
+ * @brief Moves a message to the specified folder in the database.
  *
- * \par Method of function operation:
- * Sets up the database connection and Deletes all messages in the specified folder from the message table.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in] handle         The message handle
+ * @param[in] msg_id         The message ID of the message to be moved
+ * @param[in] dest_folder_id The ID of the destination folder
  *
- * \par Important notes:
- * - None
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \param input - handle is Message handle.
- * \param input - msg_id is the ID of the message to be moved.
- * \param input - dest_folder_id is the ID of the destination folder.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_move_msg_to_folder(hMsgHandle, 0, MSG_OUTBOX_ID);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_move_msg_to_folder(msg_handle_t handle, msg_message_id_t msg_id, msg_folder_id_t dest_folder_id);
 
 
 /**
-
- * \par Description:
- * Moves a message to the other storage.
- *
- * \par Purpose:
- * This API is usd to move a message to the other storage.
- *
- * \par Typical use case:
- * Moves a message to the other storage type.
+ * @brief Moves a message to the other storage.
  *
- * \par Method of function operation:
- * Sets up the database connection and  moves a messages to specified storage type.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in] handle      The message handle
+ * @param[in] msg_id      The message ID of the message to be moved
+ * @param[in] storage_id  The ID of the destination storage
  *
- * \par Important notes:
- * - None
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \param input - handle is Message handle.
- * \param input - msg_id is the ID of the message to be moved.
- * \param input - storage_id is the ID of the destination storage.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_move_msg_to_storage( msgHandle, 0, MSG_STORAGE_PHONE);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_move_msg_to_storage(msg_handle_t handle, msg_message_id_t msg_id, msg_storage_id_t storage_id);
 
 
 /**
-
- * \par Description:
- * Gets the number of messages in the specified folder from the database.
- *
- * \par Purpose:
- * This API is used to get the number of messages in the specified folder from the database.
+ * @brief Gets the number of messages in the specified folder from the database.
  *
- * \par Typical use case:
- * Gets the number of messages in the specified folder from the database.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Method of function operation:
- * Sets up the database connection and Gets the number of messages in the specified folder from the message table.
+ * @param[in]  handle      The message handle
+ * @param[in]  msg_id      The message ID of the message to be counted
+ * @param[out] count_info  A pointer to an #MSG_COUNT_INFO_S structure
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * - None
- *
- * \param input - handle is Message handle.
- * \param input - folder_id is the ID of the folder to be counted.
- * \param output - count_info is a pointer to an MSG_COUNT_INFO_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_COUNT_INFO_S countInfo;
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_count_message(msgHandle, MSG_OUTBOX_ID, &countInfo)
-* if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_count_message(msg_handle_t handle, msg_folder_id_t folder_id, msg_struct_t count_info);
 
 
 /**
-
- * \par Description:
- * Gets the number of messages of specific message type.
- *
- * \par Purpose:
- * This API is used to get the number of messages of specific type.
+ * @brief Gets the number of messages of specific message type.
  *
- * \par Typical use case:
- * Gets the count of message of specific types such as SMS, MMS.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Method of function operation:
- * Sets up the database connection and queries the number of messages in the specified folder from the message table based on required message type.
+ * @param[in]  handle     The message handle
+ * @param[in]  msg_type   The message type to be counted
+ * @param[out] msg_count  A pointer to the number of message
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * - None
- *
- * \param input - handle is Message handle.
- * \param input - msg_type is the message type to be counted.
- * \param output - msg_count is a pointer to the number of message.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_COUNT_INFO_S countInfo;
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_count_msg_by_type(msgHandle, MSG_TYPE_SMS, &countInfo);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_count_msg_by_type(msg_handle_t handle, msg_message_type_t msg_type, int *msg_count);
 
 
 /**
-
- * \par Description:
- * Gets the number of messages of specific address.
+ * @brief Gets the number of messages of specific address.
  *
- * \par Purpose:
- * This API is used to get the number of messages from a specific address.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Typical use case:
- * Get the count of messages from the specified address
+ * @remarks If @a addr_info is @c NULL, nothing happens.
  *
- * \par Method of function operation:
- * Sets up the database connection and queries the number of messages based on address from the message table.
+ * @param[in] handle                 The message handle
+ * @param[in] addr_info              A pointer to an address list information structure
+ * @param[in] msg_thread_count_list  A pointer to an thread count information structure
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * - If addr_info is NULL, nothing happens.
- *
- * \param input - handle is Message handle.
- * \param input - addr_info is a pointer to an MSG_ADDRESS_INFO_LIST_S structure.
- * \param input - msg_thread_count_list is a pointer to an MSG_THREAD_COUNT_INFO_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_COUNT_INFO_S countInfo;
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_count_msg_by_type(msgHandle, MSG_TYPE_SMS, &countInfo);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_count_msg_by_contact(msg_handle_t handle, const msg_struct_t addr_info, msg_struct_t msg_thread_count_list);
 
 
 /**
-
- * \par Description:
- * Gets the detail information of a message from the database.
- *
- * \par Purpose:
- * This API is used to get the number of messages from a specific address.
+ * @brief Gets the detail information of a message from the database.
+ * @details This API is used to get the detail information of message by message ID.
  *
- * \par Typical use case:
- * Get the count of messages from the specified address
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Method of function operation:
- * Sets up the database connection and queries the number of messages based on address from the message table.
+ * @remarks Applications need to call msg_release_struct() to free the memory.
+ * @remarks However, if this function fails, the memory for the message is NOT allocated in this function.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in]  handle    The Message handle
+ * @param[in]  msg_id    The ID of the Message to be returned
+ * @param[out] msg       A pointer to a #msg_struct_t message structure
+ * @param[in]  send_opt  A pointer to a #msg_struct_t sending option structure
  *
- * \par Important notes:
- * - If addr_info is NULL, nothing happens.
- * - Applications need to call msg_release_message to free the memory.
- * - However, if this function is failed, the memory for the message is NOT allocated in this function.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
-handle is Message handle.
- * \param input - handle is Message handle.
- * \param input - msg_id is the ID of the Message to be returned.
- * \param output - msg is a pointer to an msg_message_t structure.
- * \param input - send_opt is a pointer to an MSG_SENDINGOPT_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * - None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- *
- * ...
- * msg_message_t msg = msg_new_message();
- * MSG_SENDINGOPT_S sendOpt = {0, };
- * ...
- * err = msg_get_message(msgHandle, 0, msg, &sendOpt);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_get_message(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_t msg, msg_struct_t send_opt);
 
-int msg_get_conversation(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_t conv);
-int msg_get_vobject_data(msg_handle_t handle, msg_message_id_t msg_id, void** encoded_data);
 
 /**
-
- * \par Description:
- * Returns the common information list of messages with selected folder id.
- *
- * \par Purpose:
- * This API is used to get the common information list of messages with selected folder id from database.
- *
- * \par Typical use case:
- * Get the common information from the specified folder from database.
+ * @brief Gets the detail information of a message on conversation list.
+ * @details This API is used to get the conversation informations of message by message ID.
  *
- * \par Method of function operation:
- * Sets up the database connection and queries the common information based on selected folder id from the message and folder tables.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in]  handle  The Message handle
+ * @param[in]  msg_id  The ID of the Message to be returned
+ * @param[out] conv    A pointer to a #msg_struct_t of message structure
  *
- * \par Important notes:
- * - The memory for a message will be allocated in this function.
- * - Applications need to call msg_release_folder_view_list to free the memory.
- * - However, if this function is failed, the memory for the message is NOT allocated in this function.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \param input - handle is Message handle.
- * \param input - folder_id is the ID of the folder to be returned.
- * \param input - sort_rule indicates a sort type and sort order for querying messages.
- * \param output - msg_folder_view_list is a pointer to an MSG_FOLDER_VIEW_LIST_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * - None
- *
- * \par Known issues/bugs:
- * None
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_get_conversation(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_t conv);
+
+
+/**
+ * @brief Gets the v-object data of message.
+ * @details This API is used to get the v-object data of message by message ID.
  *
- * \par Sample code:
- * \code
- * ...
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * msg_handle_t msgHandle = NULL;
+ * @param[in]  handle        The Message handle
+ * @param[in]  msg_id        The ID of the Message to be returned
+ * @param[out] encoded_data  A pointer to a encoded v-object data of message
  *
- * ...
- * MSG_FOLDER_VIEW_LIST_S folderViewList;
- * ...
- * err = msg_get_folder_view_list(hMsgHandle, 0, NULL, &folderViewList);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_get_folder_view_list(msg_handle_t handle, msg_folder_id_t folder_id, const msg_struct_t sort_rule, msg_struct_list_s *msg_folder_view_list);
 
+int msg_get_vobject_data(msg_handle_t handle, msg_message_id_t msg_id, void** encoded_data);
 
-/**
 
- * \par Description:
- * Returns the information of all peers to whom messages have been sent or recieved.
- *
- * \par Purpose:
- * This API is used to get the information of all peers to whom messages have been sent or recieved.
- *
- * \par Typical use case:
- * Get the common information from the specified folder from database.
- *
- * \par Method of function operation:
- * Frees the memory occupied by MSG_FOLDER_VIEW_LIST_S object and its members.
+/**
+ * @brief Gets the information of all peers to whom messages have been sent or received.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Important notes:
- * - The memory for a list will be allocated in this function.
- * - Applications need to call msg_release_thread_view_list to free the memory.
- * - However, if this function is failed, the memory for a list is NOT allocated in this function.
+ * @remarks The memory for a list will be allocated in this function.
+ * @remarks Applications need to call msg_release_thread_view_list() to free the memory.
+ * @remarks However, if this function fails, the memory for a list is NOT allocated in this function.
  *
- * \param input - handle is Message handle.
- * \param input - sort_rule indicates a sort type and sort order for querying messages.
- * \param output - msg_thread_view_list is a pointer to an msg_struct_list_s structure.
+ * @param[in]  handle                The Message handle
+ * @param[in]  sourt_rule            This indicates a sort type and sort order for querying messages
+ * @param[out] msg_thread_view_list  A pointer to an #msg_struct_list_s structure
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t sort_rule, msg_struct_list_s *msg_thread_view_list);
+
+
+/**
+ * @briefs Gets the common information list of messages with the selected thread ID.
  *
- * \par Related functions:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Known issues/bugs:
- * None
+ * @remarks The memory for a list will be allocated in this function.
+ * @remarks Applications need to call msg_release_conversation_view_list() to free the memory.
+ * @remarks However, if this function is failed, the memory for a list is NOT allocated in this function.
  *
- * \par Sample code:
- * \code
- * ...
+ * @param[in]  hMsgHandle          The Message handle
+ * @param[in]  thread_id           The ID of the thread to be returned
+ * @param[out] msg_conv_view_list  A pointer to a structure of conversational message list
  *
- * msg_handle_t msgHandle = NULL;
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * ...
- * msg_struct_list_s threadViewList;
- * ...
- * err = msg_get_thread_view_list(hMsgHandle, NULL, &threadViewList);
- * ...
- * msg_release_thread_view_list(&threadViewList);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t sort_rule, msg_struct_list_s *msg_thread_view_list);
-
-
-/**
 
- * \par Description:
- * Returns the common information list of messages with selected thread_id.
- *
- * \par Purpose:
- * This API is used to get the common information list of messages with selected thread_id.
- *
- * \par Typical use case:
- * Gets the common information list of messages with the selected thread id from the database.
- *
- * \par Method of function operation:
- * Connects to the database and queries the common infomation of  list messages with the provided thread id.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - The memory for a list will be allocated in this function.
- * - Applications need to call msg_release_conversation_view_list to free the memory.
- * - However, if this function is failed, the memory for a list is NOT allocated in this function.
- *
- * \param input - hMsgHandle is Message handle.
- * \param input - thread_id is the ID of the thread to be returned.
- * \param output - msg_conv_view_list is a pointer to an MSG_CONV_VIEW_LIST_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * - None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
- * ...
- * MSG_CONV_VIEW_LIST_S convViewList;
- * ...
- * err = msg_get_conversation_view_list(hMsgHandle, ThreadId, &convViewList);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * msg_release_conversation_view_list(&convViewList);
- * ...
- * \endcode
- */
-/*================================================================================================*/
 int msg_get_conversation_view_list(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_list_s *msg_conv_view_list);
 
 
 /**
-
- * \par Description:
- * Deletes all the Messages Sent/Received from the selected list.
- *
- * \par Purpose:
- * This API is used to delete all the Messages Sent/Received from the selected list.
+ * @brief Deletes all the Messages Sent/Received from the selected list.
  *
- * \par Typical use case:
- * Deletes all messages sent/received from the selected list.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Method of function operation:
- * Sets up the database connection and deletes all messages sent/received from a selected list.
+ * @param[in] handle                 The Message handle
+ * @param[in] thread_id              The ID of the thread to be deleted
+ * @param[in] include_protected_msg  Set @c true to delete protected messages,
+ *                                   otherwise @c false to not delete protected messages
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * - If addr_info is NULL, nothing happens.
- *
- * \param input - handle is Message handle.
- * \param input - thread_id is the ID of the thread to be deleted.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * MSG_SYNCML_MESSAGE_S syncMLMsg;
- * MSG_SENDINGOPT_S sendingOpt = {0};
- *
- * ...
- *
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- *
- * err = msg_delete_thread_message_list(hMsgHandle, 0);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_delete_thread_message_list(msg_handle_t handle, msg_thread_id_t thread_id, bool include_protected_msg);
 
 
 /**
-
- * \par Description:
- * Adds a new folder.
- *
- * \par Purpose:
- * This API is used to add a new folder.
- *
- * \par Typical use case:
- * Adds a new folder with the specified folder info
+ * @brief Adds a new folder.
  *
- * \par Method of function operation:
- * Sets up the database connection and add a new folder to the folder table.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in] handle      The Message handle
+ * @param[in] folder_info A pointer to an #MSG_FOLDER_INFO_S structure
  *
- * \par Important notes:
- * - None.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \param - handle is Message handle.
- * \param - folder_info is a pointer to an MSG_FOLDER_INFO_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- *  Make Folder
- * MSG_FOLDER_INFO_S folderInfo;
- * ...
- * err = msg_open_msg_handle(&msgHandle);
- *
- * folderInfo.folderId = 1;
- * folderInfo.folderType = MSG_FOLDER_TYPE_USER_DEF;
- * ...
- *
- * err = msg_add_folder(hMsgHandle, &folderInfo);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_add_folder(msg_handle_t handle, const msg_struct_t folder_info);
 
 
 /**
-
- * \par Description:
- * Updates the folder info.
- *
- * \par Purpose:
- * This API is used to add a new folder.
- *
- * \par Typical use case:
- * Adds a new folder with the specified folder info
- *
- * \par Method of function operation:
- * Sets up the database connection and add a new folder to the folder table.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None.
+ * @brief Updates the folder info.
  *
- * \param - handle is Message handle.
- * \param - folder_info is a pointer to an MSG_FOLDER_INFO_S structure.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @param[in] handle       The Message handle
+ * @param[in] folder_info  A pointer to an #MSG_FOLDER_INFO_S structure
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- *  Make Folder
- * MSG_FOLDER_INFO_S folderInfo;
- * ...
- * err = msg_open_msg_handle(&msgHandle);
- *
- * folderInfo.folderId = 2;
- * folderInfo.folderType = MSG_FOLDER_TYPE_USER_DEF;
- * ...
- * err = msg_update_folder(msgHandle, &folderInfo);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_update_folder(msg_handle_t handle, const msg_struct_t folder_info);
 
 
 /**
-
- * \par Description:
- * Deletes an exisiting folder.
- *
- * \par Purpose:
- * This API is used to delete an existing folder.
- *
- * \par Typical use case:
- * Deletes an existing folder.
- *
- * \par Method of function operation:
- * Sets up the database connection and deletes an existing folder to the folder table.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None.
- *
- * \param input - handle is Message handle.
- * \param input - folder_id is the ID of the folder to be deleted.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
+ * @brief Deletes an existing folder.
  *
- * \par Known issues/bugs:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Sample code:
- * \code
- * ...
+ * @param[in] handle    The Message handle
+ * @param[in] folder_id The ID of the folder to be deleted
  *
- * msg_handle_t msgHandle = NULL;
- * err = msg_open_msg_handle(&msgHandle);
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * ...
- * err = msg_delete_folder(hMsgHandle, MSG_INBOX_ID);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_delete_folder(msg_handle_t handle, msg_folder_id_t folder_id);
 
 
 /**
-
- * \par Description:
- * Returns the information list of folders.
- *
- * \par Purpose:
- * This API is used to get the information list of folders.
- *
- * \par Typical use case:
- * Gets the folder list information.
- *
- * \par Method of function operation:
- * Sets up the database connection and queries for the folder list information.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None.
+ * @brief Gets the information list of folders.
  *
- * \param input - handle is Message handle.
- * \param output - folder_list is a pointer to an msg_struct_list_s structure.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @param[in]  handle       The Message handle
+ * @param[out] folder_list  A pointer to a #msg_struct_list_s structure
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- *  msg_struct_list_s folderList;
-
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- * err = msg_get_folder_list(msgHandle, &folderList);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * msg_release_folder_list(&folderList);
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_get_folder_list(msg_handle_t handle, msg_struct_list_s *folder_list);
 
 
 /**
-
- * \par Description:
- * Creates the specified number of messages in database.
- *
- * \par Purpose:
- * This API is used to generate specified number of messages in the database
- *
- * \par Typical use case:
- * Generate large number of messages in the database.
- *
- * \par Method of function operation:
- * Creates the specified number of messages in database for specified message type in the specified folder
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input - handle is Message handle.
- * \param input - msg_type is one of enum _MSG_MESSAGE_TYPE_E.
- * \param input - folder_id is the folder for the test messages.
- * \param input - num_msg is the number of messages.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE Parameter is invalid.
- * - MSG_ERR_INVALID_FOLDER_ID Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- *  msg_struct_list_s folderList;
-
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- * err = msg_generate_message(msgHandle, MSG_TYPE_SMS, MSG_INBOX_ID, 100);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @brief Creates the specified number of messages in database.
+ * @details This API is used to generate specified number of messages in the database
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @param[in] handle     The Message handle
+ * @param[in] msg_type   The message type \n
+ *                       One of enum _MSG_MESSAGE_TYPE_E.
+ * @param[in] folder_id  The folder for the test messages
+ * @param[in] num_msg    The number of messages
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_MSGHANDLE Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_generate_message(msg_handle_t handle, msg_message_type_t msg_type, msg_folder_id_t folder_id, unsigned int num_msg);
-int msg_generate_sms(msg_handle_t handle, msg_folder_id_t folder_id, unsigned int num_msg) DEPRECATED;
 
 
 /**
-
- * \par Description:
- * Returns the Message Data to be used by the Quick Panel.
- *
- * \par Purpose:
- * This API is used to get the Message Datato be used by the Quick Panel.
- *
- * \par Typical use case:
- * Quick panel needs the message information to show new message notification.
- *
- * \par Method of function operation:
- * Connects to database and queries for information needed by the quick panel.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input - handle is Message handle.
- * \param input - type is the type of message that Quick Panel need.
- * \param output - msg is a pointer to an msg_message_t structure.
+ * @brief Returns the Message Data to be used by the Quick Panel.
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE Parameter is invalid.
- * - MSG_ERR_INVALID_FOLDER_ID Storage is error.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @param[in]  handle  The Message handle
+ * @param[in]  type    The type of message that Quick Panel needs
+ * @param[out] msg     A pointer to a #msg_struct_t structure
  *
- * \par Related functions:
- * None
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * msg_message_t msgInfo;
-
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- * err = msg_get_quick_panel_data(msgHandle, MSG_QUICKPANEL_SMS, msgInfo);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS                   Success in operation
+ * @retval MSG_ERR_DB_STEP               There is no Quick Panel message
+ * @retval MSG_ERR_INVALID_PARAMETER(-9) Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR         Storage  error
+ * @retval MSG_ERR_PERMISSION_DENIED     The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_get_quick_panel_data(msg_handle_t handle, msg_quickpanel_type_t type, msg_struct_t msg);
 
 
 /**
-
- * \par Description:
- * Resets the Messaging database.
- *
- * \par Purpose:
- * This API is used to reset the messaging database.
+ * @brief Resets the Messaging database.
  *
- * \par Typical use case:
- * Completely delete the messaging database.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Method of function operation:
- * Connects to database and deletes all the messaging tables.
+ * @param[in] handle The Message handle
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * - None
- *
- * \param input - handle is Message handle.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- * err = msg_reset_database(msgHandle);
- * if (err != MSG_SUCCESS)
- *{
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_reset_database(msg_handle_t handle);
 
 
 /**
-
- * \par Description:
- * Returns the total size used for message contents.
- *
- * \par Purpose:
- * This API is used to get the total size used for message contents.
- *
- * \par Typical use case:
- * To get the total space used by message contents.
- *
- * \par Method of function operation:
- * Uses linux system calls to query the space used by message contents.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
+ * @brief Gets the total size used for message contents.
  *
- * \param input - handle is Message handle.
- * \param output -     memsize is a pointer to the size.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
+ * @param[in]  handle    The Message handle
+ * @param[out] memsize   A pointer to the size
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * int memsize = 0;
- * err = msg_open_msg_handle(&msgHandle);
- *
- * ...
- * err = msg_get_mem_size(msgHandle, &memsize);
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_get_mem_size(msg_handle_t handle, unsigned int* memsize);
 
 /**
-
- * \par Description:
- * Backup messages to storage.
- *
- * \par Purpose:
- * This API is used to backup messages to storage.
- *
- * \par Typical use case:
- * Backup messages to storage.
- *
- * \par Method of function operation:
- * Reads all the messages from Messaging database and writes to storage in V-Message format
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * None
- *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - msg_message_backup_type_t  type is backup_type.
- * \param input - backup_filepath is path to backup message.
- *
- * \return Return Type int (msg_error_t) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @brief Backs up messages to storage.
  *
- * \par Related functions:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Known issues/bugs:
- * None
+ * @param[in] handle          The Message handle
+ * @param[in] type            The backup type
+ * @param[in] backup_filepath The path to backup message
  *
- * \par Sample code:
- * \code
- * ...
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err;
- * msg_message_backup_type_t type = MSG_BACKUP_TYPE_MMS;
- * const char *filepath = "/backup_mms"
- *
- * ...
- * err = msg_backup_message(&msgHandle, type, filepath);
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_backup_message(msg_handle_t handle, msg_message_backup_type_t type, const char *backup_filepath);
 
 
 /**
-
- * \par Description:
- * Restore messages from backed up messages.
- *
- * \par Purpose:
- * This API is used to restore messages from backed up messages.
- *
- * \par Typical use case:
- * Restore messages from previously backed up messages.
- *
- * \par Method of function operation:
- * Reads the previously backup up messages and restores the database.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * None
+ * @brief Restores messages from backed up messages.
  *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - backup_filepath is path of backup file for restore.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
+ * @param[in] handle          The Message handle
+ * @param[in] backup_filepath The path to backup message
  *
- * \return Return Type int (msg_error_t) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err;
- * const char *filepath = "/backup_mms"
-  * ...
- * err = msg_restore_message(&msgHandle, filepath);
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_restore_message(msg_handle_t handle, const char *backup_filepath);
 
 
 /**
-
- * \par Description:
- * Search messages or addresses which including a string that applcation want to find.
- *
- * \par Purpose:
- * This API is used to search messages or addresses from storage.
+ * @brief Searches messages or addresses for the specified string.
+ * @details This API is used to search messages or addresses from storage.
  *
- * \par Typical use case:
- * Search messages or addresses from storage.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Method of function operation:
- * search messages or addresses from storage.
+ * @param[in]  handle               The Message handle
+ * @param[in]  search_string        The string to search
+ * @param[out] msg_thread_view_list A pointer to an #msg_struct_list_s structure
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * None
- *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - search_string is the string to search.
- * \param output - msg_thread_view_list is a pointer to an msg_struct_list_s structure.
- *
- * \return Return Type int (msg_error_t) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
- * ...
- * char* search_string = "hello";
- * msg_struct_list_s threadViewList;
- * ...
- * err = msg_search_message_for_thread_view(&msgHandle, search_string, &threadViewList);
- *
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_search_message_for_thread_view(msg_handle_t handle, const char *search_string, msg_struct_list_s *msg_thread_view_list);
 
 
 /**
-
- * \par Description:
- * Search messages or addresses which including a string that applcation want to find.
- *
- * \par Purpose:
- * This API is used to search messages or addresses from storage.
+ * @brief Gets reject message list by phone number.
+ * @details This API is used to get reject message list from storage.
  *
- * \par Typical use case:
- * Search messages or addresses from storage.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Method of function operation:
- * search messages or addresses from storage.
+ * @param[in]  handle               The Message handle
+ * @param[in]  phone_num            The string of phone number to find
+ * @param[out] msg_reject_msg_list  A pointer to a #msg_struct_list_s structure
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * None
- *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - search_string is the string to search.
- * \param input - offset is the offset of the search result.
- * \param input - limit is the limit of the search result.
- * \param output - msg_list is a pointer to an msg_struct_list_s structure.
- *
- * \return Return Type int (msg_error_t) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_get_reject_msg_list(msg_handle_t handle, const char* phone_num, msg_struct_list_s *msg_reject_msg_list);
+
+
+/**
+ * @brief Registers a callback function about the change of storage status to Message handle.
+ * @details This API is used to register a callback function about the change of storage status "msg_storage_change_cb" to Message handle.
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Related functions:
- * None
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Known issues/bugs:
- * None
+ * @param[in] handle      The Message handle
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  A pointer to user data
  *
- * \par Sample code:
- * \code
- * ...
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
- * ...
- * msg_struct_list_s msg_list;
- * int offset = 0;
- * int limit = 10;
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_MSGHANDLE_NOT_CONNECTED Message handle is not connected
+ * @retval MSG_ERR_MEMORY_ERROR         Memory is error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_reg_storage_change_callback(msg_handle_t handle, msg_storage_change_cb cb, void *user_param);
+
+
+/**
+ * @brief Gets the report status information of message.
  *
- * MSG_SEARCH_CONDITION_S searchCon;
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * searchCon.msgType = MSG_TYPE_SMS;
- * searchCon.folderId = MSG_INBOX_ID;
- * searchCon.pSearchVal = "keyString";
- * searchCon.pAddressVal = "01000000000";
+ * @param[in]  handle        The Message handle
+ * @param[in]  msg_id        The ID of the message
+ * @param[out] report_status A pointer to a #msg_struct_list_s structure
  *
- * ...
- * err = msg_search_message(hMsgHandle, &searchCon, offset, limit, &msgList);
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_search_message(msg_handle_t handle, const msg_struct_t msg_search_conditions, int offset, int limit, msg_struct_list_s *msg_list);
 
-/**
+int msg_get_report_status(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_list_s *report_list);
 
- * \par Description:
- * Get reject message list that application wants to find by phone number.
- *
- * \par Purpose:
- * This API is used to get reject message list from storage.
- *
- * \par Typical use case:
- * Get reject message list from storage.
+
+/**
+ * @brief Gets the address list for specific thread ID.
  *
- * \par Method of function operation:
- * Get reject message list from storage.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in]  handle           The Message handle
+ * @param[in]  msg_id           The ID of the message
+ * @param[out] msg_address_list A pointer to a #msg_struct_list_s structure
  *
- * \par Important notes:
- * None
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \param input - msg_handle_t  handle is Message handle.
- * \param input - phone_num is the string of phone number to find.
- * \param output - msg_reject_msg_list is a pointer to an msg_struct_list_s structure.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
 
- * \return Return Type int (msg_error_t) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_PARAMETER Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR             Storage is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
+int msg_get_address_list(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_list_s *msg_address_list);
+
+
+/**
+ * @brief Gets the thread ID by address.
  *
- * \par Known issues/bugs:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sample code:
- * \code
- * ...
+ * @param[in]  handle           The Message handle
+ * @param[in]  msg_address_list A pointer to a #msg_struct_list_s structure
+ * @param[out] thread_id        The thread ID of the message
  *
- * msg_handle_t msgHandle = NULL;
- * msg_error_t err = MSG_SUCCESS;
- * ...
- * char* phone_num = "01030016057";
- * msg_struct_list_s rejectMsgList;
- * ...
- * err = msg_get_reject_msg_list(hMsgHandle, phone_num, &rejectMsgList);
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_get_reject_msg_list(msg_handle_t handle, const char* phone_num, msg_struct_list_s *msg_reject_msg_list);
 
+int msg_get_thread_id_by_address(msg_handle_t handle, msg_struct_list_s *msg_address_list, msg_thread_id_t *thread_id);
 
 /**
-
- * \par Description:
- * Registers a callback function about the change of storage status to Message handle.
- *
- * \par Purpose:
- * This API is used to register a callback function about the change of storage status "msg_storage_change_cb" to Message handle.
- *
- * \par Typical use case:
- * Register a callback function about the change of storage status.
+ * @brief Gets the thread ID by address.
  *
- * \par Method of function operation:
- * Adds the msg_storage_change_cb API to a callback function list.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in]  handle            The Message handle
+ * @param[in]  msg_address_list  A pointer to a #msg_list_handle structure
+ * @param[out] thread_id         The thread ID of the message
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - user_param is a pointer to user data.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_get_thread_id_by_address2(msg_handle_t handle, msg_list_handle_t msg_address_list, msg_thread_id_t *thread_id);
+
+
+
+/**
+ * @brief Gets the thread information.
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                                       Success in operation.
- * - MSG_ERR_MSGHANDLE_NOT_CONNECTED   Message handle is not connected.
- * - MSG_ERR_MEMORY_ERROR                              Memory is error.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @param[in]  handle      The Message handle
+ * @param[in]  thread_id   The ID of the thread
+ * @param[out] msg_thread  A pointer to a #msg_struct_t structure
  *
- * \par Related functions:
- * None
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Known issues/bugs:
- * None
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_get_thread(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_t msg_thread);
+
+
+/**
+ * @brief Gets the information list of messages.
  *
- * \par Sample code:
- * \code
- * ...
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * int err = MSG_SUCCESS;
+ * @param[in]  handle               The Message handle
+ * @param[in]  msg_list_conditions  A pointer to a #msg_struct_t structure for getting conditions
+ * @param[out] msg_list             A pointer to a #msg_struct_list_s structure
  *
- * err = msg_reg_storage_change_callback(msgHandle, &storageCB, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * void storageCB(msg_handle_t handle, msg_thread_id_t threadId, msg_message_id_t msgId, void *user_param)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_reg_storage_change_callback(msg_handle_t handle, msg_storage_change_cb cb, void *user_param);
 
+int msg_get_message_list2(msg_handle_t handle, const msg_struct_t msg_list_conditions, msg_struct_list_s *msg_list);
 
-/**
 
- * \par Description:
- * Gets the report status information of message.
- *
- * \par Purpose:
- * This API is used to get the report status information of specified message.
+/**
+ * @brief Adds a new push event.
  *
- * \par Typical use case:
- * Gets the report status information of specified message from the database.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Method of function operation:
- * Sets up the database connection and Gets the report status information of specified message from the report table.
+ * @param[in] handle     The Message handle
+ * @param[in] push_event A pointer to a #msg_struct_t structure for push event
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Important notes:
- * - None
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_add_push_event(msg_handle_t handle, const msg_struct_t push_event);
+
+
+/**
+ * @brief Deletes a push event.
  *
- * \param input - handle is Message handle.
- * \param input - msg_id is the ID of the message.
- * \param output - report_status is a pointer to a MSG_REPORT_STATUS_INFO_S structure.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS       - Success in operation.
- * - MSG_ERR_INVALID_PARAMETER - Parameter is invalid.
- * - MSG_ERR_STORAGE_ERROR - Storage is error.
+ * @param[in] handle     The Message handle
+ * @param[in] push_event A pointer to a #msg_struct_t structure for push event
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * \par Related functions:
- * None
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_delete_push_event(msg_handle_t handle, const msg_struct_t push_event);
+
+
+/**
+ * @brief Updates a push event.
  *
- * \par Known issues/bugs:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Sample code:
- * \code
- * ...
+ * @param[in] handle    The Message handle
+ * @param[in] src_event A pointer to a #msg_struct_t structure for source push event
+ * @param[in] dst_event A pointer to a #msg_struct_t structure for destination push event
  *
- * msg_handle_t msgHandle = NULL;
- * MSG_REPORT_STATUS_INFO_S reportStatus;
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * ...
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_update_push_event(msg_handle_t handle, const msg_struct_t src_event, const msg_struct_t dst_event);
+
+
+/**
+ * @brief Deletes messages by Message ID list from the database.
  *
- * err = msg_open_msg_handle(&msgHandle);
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * ...
+ * @param[in] handle      sThe Message handle
+ * @param[in] msg_id_list The message ID list to be deleted
  *
- * err = msg_get_report_status(msgHandle, msgID, &reportStatus)
-* if( err != MSG_SUCCESS )
- * {
- *     printf("err [%d]", err);
- *     return err;
- * }
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
  *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_get_report_status(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_list_s *report_list);
-
-int msg_get_address_list(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_list_s *msg_address_list);
-
-
-int msg_get_thread_id_by_address(msg_handle_t handle, msg_struct_list_s *msg_address_list, msg_thread_id_t *thread_id);
-
-
-int msg_get_thread(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_t msg_thread);
-
 
-int msg_get_message_list(msg_handle_t handle, msg_folder_id_t folder_id, msg_thread_id_t thread_id, msg_message_type_t msg_type, msg_storage_id_t storage_id, msg_struct_list_s *msg_list);
-
-
-int msg_add_push_event(msg_handle_t handle, const msg_struct_t push_event);
-
-int msg_delete_push_event(msg_handle_t handle, const msg_struct_t push_event);
+int msg_delete_msgs_by_list(msg_handle_t handle, msg_id_list_s *msg_id_list);
 
-int msg_update_push_event(msg_handle_t handle, const msg_struct_t src_event, const msg_struct_t dst_event);
 
-int msg_delete_msgs_by_list(msg_handle_t handle, msg_id_list_s *msg_id_list);
+/**
+ * @brief Marks a conversation given by thread ID as read.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
+ *
+ * @param[in] handle    The Message handle
+ * @param[in] thread_id The thread ID to be updated
+ *
+ * @return  @c 0 on success,
+ *        otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid
+ * @retval MSG_ERR_STORAGE_ERROR     Storage error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+int msg_set_conversation_to_read(msg_handle_t handle,  msg_thread_id_t thread_id);
 /**
  *     @}
  */
index 2fc922d..792d6ef 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_STORAGE_TYPES_H_
 ==================================================================================================*/
 
 /**
- *     @brief  Represents message id list.
+ * @internal
+ * @addtogroup MSG_SERVICE_FRAMEWORK_STORAGE_MODULE
+ * @{
+ */
+
+
+/**
+ *     @brief  The structure type that represents message ID list.
  */
 typedef struct
 {
-       int                                     nCount;                         /**< The count of message id informatioin */
-       msg_message_id_t        *msgIdList;                     /**< The pointer to message id informatioin */
+       int                                     nCount;                         /**< The count of message ID informatioin */
+       msg_message_id_t        *msgIdList;                     /**< The pointer to message ID informatioin */
 }msg_id_list_s;
 
 
@@ -42,46 +49,50 @@ typedef struct
 ==================================================================================================*/
 
 /**
- *     @brief  Represents a folder type. \n
- *     The values for this type SHOULD be in _MSG_FOLDER_TYPE_E.
+ *     @brief  The structure type that represents a folder type. \n
+ *     The values for this type SHOULD be in @ref _MSG_FOLDER_TYPE_E.
  */
 typedef unsigned char msg_folder_type_t;
 
 
 /**
- *     @brief  Represents a sort type. \n
- *     The values for this type SHOULD be in \ref _MSG_SORT_TYPE_E.
+ *     @brief  The structure type that represents a sort type. \n
+ *     The values for this type SHOULD be in @ref _MSG_SORT_TYPE_E.
  */
 typedef unsigned char msg_sort_type_t;
 
 
 /**
- *     @brief  Represents a Saved SIM message ID.
+ *     @brief  The structure type that represents a saved SIM message ID.
  */
 typedef signed short msg_sim_id_t;
 
+/**
+ *     @brief  The structure type that represents a Saved SIM slot ID.
+ */
+typedef int msg_sim_slot_id_t;
+
 
 /**
- *     @brief  Represents a message type for quick panel. \n
- *     The values for this type SHOULD be in \ref _MSG_QUICKPANEL_TYPE_E.
+ *     @brief  The structure type that represents a message type for quick panel. \n
+ *     The values for this type SHOULD be in @ref _MSG_QUICKPANEL_TYPE_E.
  */
 typedef unsigned char msg_quickpanel_type_t;
 
 
 /**
- *     @brief  Represents a storage change CB type. \n
- *     The values for this type SHOULD be in \ref _MSG_STORAGE_CHANGE_TYPE_E.
+ *     @brief  The structure type that represents a storage change CB type. \n
+ *     The values for this type SHOULD be in @ref _MSG_STORAGE_CHANGE_TYPE_E.
  */
 typedef unsigned char msg_storage_change_type_t;
 
 
-/** @brief     Prototype of the function that will be called when the database of message framework is changed.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_storage_change_callback.
- *     The callback function runs in the application process, not in the framework process.
- *     @param[in]      handle is Message handle.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/** @brief     Called when the database of message framework is changed.
+ *          Applications SHOULD implement this callback function and register it into Message handle.
+ *             For how to register this callback function, please refer to msg_reg_storage_change_callback().
+ *             The callback function runs in the application process, not in the framework process.
+ * @param[in]  handle      The Message handle.
+ * @param[in]  user_param  A pointer to user data
  */
 typedef void (*msg_storage_change_cb)(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_id_list_s *pMsgIdList, void *user_param);
 
@@ -91,121 +102,129 @@ typedef void (*msg_storage_change_cb)(msg_handle_t handle, msg_storage_change_ty
 ==================================================================================================*/
 
 /**
- *     @brief  Represents the values of a storage type. \n
- *     This enum is used as the value of msg_storage_id_t.
+ *     @brief Enumeration for the values of a storage type. \n
+ *            This enum is used as the value of msg_storage_id_t.
  */
 enum _MSG_STORAGE_ID_E
 {
-       MSG_STORAGE_UNKNOWN = 0,                /**< Storage Id is unknown. */
-       MSG_STORAGE_PHONE,                      /**< Storage Id is Phone. */
-       MSG_STORAGE_SIM,                                /**< Storage Id is SIM card. */
+       MSG_STORAGE_UNKNOWN = 0,                /**< Storage ID is unknown. */
+       MSG_STORAGE_PHONE,                          /**< Storage ID is Phone. */
+       MSG_STORAGE_SIM,                                /**< Storage ID is SIM card in slot 1. */
+       MSG_STORAGE_SIM2,                               /**< Storage ID is SIM card in slot 2. */
 };
 
 
 /**
- *     @brief  Represents the values of a storage type. \n
- *     This enum is used as the value of msg_folder_id_t.
+ *     @brief  Enumeration for the values of a storage type. \n
+ *             This enum is used as the value of msg_folder_id_t.
  */
 enum _MSG_FOLDER_ID_E
 {
-       MSG_IOSBOX_ID = -1,                     /**< Indicates INBOX, OUTBOX and SENTBOX group folder id. (Only for search option.) */
-       MSG_ALLBOX_ID = 0,                              /**< Indicates INBOX, OUTBOX, SENTBOX and DRAFTBOX group folder id. (Only for search option.) */
-       MSG_INBOX_ID = 1,
-       MSG_OUTBOX_ID = 2,
-       MSG_SENTBOX_ID = 3,
-       MSG_DRAFT_ID = 4,
-       MSG_CBMSGBOX_ID = 5,
-       MSG_SPAMBOX_ID = 6,
-       MSG_SMS_TEMPLATE_ID = 7,
-       MSG_MMS_TEMPLATE_ID = 8,
-
-       // new folder should be placed here
-
-       MSG_MAX_FOLDER_ID
+       MSG_IOSBOX_ID = -1,                         /**< Indicates INBOX, OUTBOX and SENTBOX group folder ID. (Only for search option.) */
+       MSG_ALLBOX_ID = 0,                              /**< Indicates INBOX, OUTBOX, SENTBOX and DRAFTBOX group folder ID. (Only for search option.) */
+       MSG_INBOX_ID = 1,                               /**< Indicates INBOX folder ID */
+       MSG_OUTBOX_ID = 2,                              /**< Indicates OUTBOX folder ID */
+       MSG_SENTBOX_ID = 3,                             /**< Indicates SENTBOX folder ID */
+       MSG_DRAFT_ID = 4,                               /**< Indicates DRAFT folder ID */
+       MSG_CBMSGBOX_ID = 5,                    /**< Indicates CALLBACK message folder ID */
+       MSG_SPAMBOX_ID = 6,                             /**< Indicates SPAM message folder ID */
+       MSG_MAX_FOLDER_ID                               /**< Indicates MAX folder ID. Folder ID to be accessed should be smaller than this */
 };
 
 
 /**
- *     @brief  Represents the values of a folder type. \n
- *     This enum is used as the value of msg_folder_type_t.
+ *     @brief  Enumeration for the values of a folder type. \n
+ *             This enum is used as the value of msg_folder_type_t.
  */
 enum _MSG_FOLDER_TYPE_E
 {
        MSG_FOLDER_TYPE_INBOX = 1,              /**< Inbox folder */
-       MSG_FOLDER_TYPE_OUTBOX,         /**< Outbox folder */
-       MSG_FOLDER_TYPE_DRAFT,          /**< Draft folder */
+       MSG_FOLDER_TYPE_OUTBOX,             /**< Outbox folder */
+       MSG_FOLDER_TYPE_DRAFT,              /**< Draft folder */
        MSG_FOLDER_TYPE_SPAMBOX,                /**< Spambox folder */
-       MSG_FOLDER_TYPE_TEMPLATE,               /**< Template folder */
        MSG_FOLDER_TYPE_USER_DEF                /**< Folder which is created by a user */
 };
 
 
 /**
- *     @brief  Represents the values of a sort type. \n
- *     This enum is used as the value of msg_sort_type_t.
+ *     @brief  Enumeration for the values of a sort type. \n
+ *             This enum is used as the value of msg_sort_type_t.
  */
 enum _MSG_SORT_TYPE_E
 {
        MSG_SORT_BY_UNKNOWN = 0,                        /**< Unknown sort type */
-       MSG_SORT_BY_DISPLAY_FROM,               /**< Sort by display from */
-       MSG_SORT_BY_DISPLAY_TO,                 /**< Sort by display to */
+       MSG_SORT_BY_DISPLAY_FROM,                   /**< Sort by display from */
+       MSG_SORT_BY_DISPLAY_TO,                     /**< Sort by display to */
        MSG_SORT_BY_DISPLAY_TIME,                       /**< Sort by display time */
        MSG_SORT_BY_MSG_TYPE,                           /**< Sort by msg type */
        MSG_SORT_BY_READ_STATUS,                        /**< Sort by read status */
-       MSG_SORT_BY_STORAGE_TYPE,               /**< Sort by storage type */
+       MSG_SORT_BY_STORAGE_TYPE,                   /**< Sort by storage type */
        MSG_SORT_BY_THREAD_NAME,                        /**< Sort by name for thread view*/
        MSG_SORT_BY_THREAD_DATE,                        /**< Sort by date for thread view*/
-       MSG_SORT_BY_THREAD_COUNT,               /**< Sort by count for thread view*/
+       MSG_SORT_BY_THREAD_COUNT,                   /**< Sort by count for thread view*/
 };
 
 
 /**
- *     @brief  Represents the values of a message type for quick panel. \n
- *     This enum is used as the value of msg_quickpanel_type_t.
+ *     @brief  Enumeration for the values of a message type for quick panel. \n
+ *             This enum is used as the value of msg_quickpanel_type_t.
  */
 enum _MSG_QUICKPANEL_TYPE_E
 {
-       MSG_QUICKPANEL_SMS = 0,
-       MSG_QUICKPANEL_MMS,
-       MSG_QUICKPANEL_DELIVER_REP,
-       MSG_QUICKPANEL_READ_REP,
-       MSG_QUICKPANEL_VOICEMAIL,
-       MSG_QUICKPANEL_MMS_NOTI,
+       MSG_QUICKPANEL_SMS = 0,                         /**< Quickpanel SMS */
+       MSG_QUICKPANEL_MMS,                                     /**< Quickpanel MMS */
+       MSG_QUICKPANEL_DELIVER_REP,                     /**< Quickpanel delivery report */
+       MSG_QUICKPANEL_READ_REP,                        /**< Quickpanel message read report */
+       MSG_QUICKPANEL_VOICEMAIL,                       /**< Quickpanel voicemail */
+       MSG_QUICKPANEL_MMS_NOTI,                        /**< Quickpanel MMS notification */
 };
 
+
 /**
- *     @}
+ *     @brief  Enumeration for the values of a count limit for each mailbox.
  */
 enum _MSG_COUNT_LIMIT_MAILBOX_TYPE_E
 {
-       MSG_COUNT_LIMIT_INBOX_TYPE,
-       MSG_COUNT_LIMIT_OUTBOX_TYPE,
-       MSG_COUNT_LIMIT_SENTBOX_TYPE,
-       MSG_COUNT_LIMIT_DRAFTBOX_TYPE,
-       MSG_COUNT_LIMIT_CBMSGBOX_TYPE,
-       MSG_COUNT_LIMIT_MAILBOX_TYPE_MAX,
+       MSG_COUNT_LIMIT_INBOX_TYPE,                             /**< Message count limit of inbox folder*/
+       MSG_COUNT_LIMIT_OUTBOX_TYPE,                    /**< Message count limit of outbox folder*/
+       MSG_COUNT_LIMIT_SENTBOX_TYPE,                   /**< Message count limit of sentbox folder*/
+       MSG_COUNT_LIMIT_DRAFTBOX_TYPE,                  /**< Message count limit of draftbox folder*/
+       MSG_COUNT_LIMIT_CBMSGBOX_TYPE,                  /**< Message count limit of call-back-message-box folder */
+       MSG_COUNT_LIMIT_MAILBOX_TYPE_MAX,               /**< Indicates the maximum number of types of folder message count limits */
 };
 
+
+/**
+ *     @brief  Enumeration for the values of a count limit for each message type.
+ */
 enum _MSG_COUNT_LIMIT_MSG_TYPE_E
 {
-       MSG_COUNT_LIMIT_SMS_TYPE,
-       MSG_COUNT_LIMIT_MMS_TYPE,
-       MSG_COUNT_LIMIT_CB_TYPE,
-       MSG_COUNT_LIMIT_WAPPUSH_TYPE,
-       MSG_COUNT_LIMIT_PROVISION_TYPE,
-       MSG_COUNT_LIMIT_MSG_TYPE_MAX,
+       MSG_COUNT_LIMIT_SMS_TYPE,                               /**< Message count limit for SMS */
+       MSG_COUNT_LIMIT_MMS_TYPE,                               /**< Message count limit for MMS */
+       MSG_COUNT_LIMIT_CB_TYPE,                                /**< Message count limit for callback messages */
+       MSG_COUNT_LIMIT_WAPPUSH_TYPE,                   /**< Message count limit for wappush messages */
+       MSG_COUNT_LIMIT_PROVISION_TYPE,                 /**< Message count limit for provision messages */
+       MSG_COUNT_LIMIT_MSG_TYPE_MAX,                   /**< Indicates maximum number of types of message count limits */
 };
 
+
+/**
+ *     @brief  Enumeration for the values of a storage change type. \n
+ *             This enum is used with storage change callback functions.
+ */
 enum _MSG_STORAGE_CHANGE_TYPE_E
 {
        // msg data
-       MSG_STORAGE_CHANGE_INSERT = 1,
-       MSG_STORAGE_CHANGE_UPDATE,
-       MSG_STORAGE_CHANGE_DELETE,
+       MSG_STORAGE_CHANGE_INSERT = 1,                  /**< Indicates storage change by an INSERT operation*/
+       MSG_STORAGE_CHANGE_UPDATE,                              /**< Indicates storage change by an UPDATE operation*/
+       MSG_STORAGE_CHANGE_DELETE,                              /**< Indicates storage change by a DELETE operation*/
 
        // thread data
-       MSG_STORAGE_CHANGE_CONTACT,
+       MSG_STORAGE_CHANGE_CONTACT,                             /**< Indicates storage change by a CHANGE CONTACT operation*/
 };
 
+/**
+ * @}
+ */
 
 #endif /* MSG_STORAGE_TYPES_H_ */
index 5861c8f..623457a 100755 (executable)
@@ -1,35 +1,22 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
-/**
- *     @file           MapiTransport.h
- *     @brief          Defines transport API of messaging framework
- *     @version        1.0
- */
-
 #ifndef MAPI_TRANSPORT_H
 #define MAPI_TRANSPORT_H
 
-/**
- *     @section                Introduction
- *     - Introduction : Overview on Messaging Transport API
- *     @section                Program
- *     - Program : Messaging Transport API Reference
- */
-
 /*==================================================================================================
                                          INCLUDE FILES
 ==================================================================================================*/
@@ -42,937 +29,503 @@ extern "C"
 #endif
 
 /**
- *     @ingroup                MESSAGING_FRAMEWORK
- *     @defgroup       MESSAGING_TRANSPORT_API Messaging Transport API
- *     @{
- */
-
-/*==================================================================================================
-                                     FUNCTION PROTOTYPES
-==================================================================================================*/
-
-/**
-
- * \par Description:
- * Submits a request to the Messaging Framework.
- *
- * \par Purpose:
- * This API is used to submit a request to the Messaging Framework.
- *
- * \par Typical use case:
- * Submit a request to Messaging Service such as Send Message, Forward etc.
+ * @internal
+ * @ingroup MSG_SERVICE_FRAMEWORK
+ * @defgroup MSG_SERVICE_FRAMEWORK_TRANSPORT_MODULE Transport API
+ * @brief The Transport API provides functions to send SMS/MMS and register incoming/sending/syncML/report callback.
  *
- * \par Method of function operation:
- * Sets up the database connection and inserts the message to message table.
+ * @internal
+ * @addtogroup MSG_SERVICE_FRAMEWORK_TRANSPORT_MODULE
+ * @{
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @section MSG_SERVICE_FRAMEWORK_TRANSPORT_MODULE_HEADER Required Header
+ *   \#include <msg_transport.h>
  *
- * \par Important notes:
- * - The result information will be sent back by using the callback function, msg_sent_status_cb.
- * - Applications MUST fill in the valid message type.
- * -  reqId will be filled in the framework.
+ * @section MSG_SERVICE_FRAMEWORK_TRANSPORT_MODULE_OVERVIEW Overview
  *
- * \param input  - handle is Message handle.
- * \param input  - req is a pointer to an MSG_REQUEST_S structure.
+ * The Transport API provides the following functionalities:
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE Message handle is invalid.
- * - MSG_ERR_NULL_POINTER                      Pointer is NULL.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * - Sending SMS/MMS messages
+ * - Register incoming message callback
+ * - Register sent status callback
+ * - Register push message application
+ * - Register syncML message callback
+ * - Managing the registration
  *
- * \par Related functions:
- * None
+ * @section MSG_SERVICE_FRAMEWORK_TRANSPORT_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ *  - http://tizen.org/feature/network.telephony\n
+ *  - http://tizen.org/feature/network.telephony.mms\n
  *
- * \par Known issues/bugs:
- * None
+ * It is recommended to design feature related codes in your application for reliability.\n
  *
- * \par Sample code:
- * \code
- * ...
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
  *
- * int err = MSG_SUCCESS;
- * MSG_REQUEST_S req;
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
  *
- * req.msg = msg;
- * req.sendOpt = sendOpt;
-
- * err = msg_submit_req(msgHandle, &req);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
+ * More details on featuring your application can be found from <a href="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
  *
- * ...
- * \endcode
  */
-/*================================================================================================*/
-int msg_submit_req(msg_handle_t handle, msg_struct_t req);
 
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
 
 /**
-
- * \par Description:
- * Registers sent status callback function to Message handle.
- *
- * \par Purpose:
- * This API is used to register sent status callback function "msg_sent_status_cb" to Message handle.
+ * @brief Submits a request to the Messaging Framework.
  *
- * \par Typical use case:
- * Register for sent status callback.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Method of function operation:
- * Adds the msg_sent_status_cb API to sent status callback list.
+ * @remarks The result information will be sent back by using the callback function, msg_sent_status_cb().
+ * @remarks Applications MUST fill in the valid message type.
+ * @remarks reqId will be filled in the framework.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in] handle  The message handle
+ * @param[in] req     The pointer to an #MSG_REQUEST_S structure
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - user_param is a pointer to user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE Message handle is invalid.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_TRANSPORT_ERROR   Transport error
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_submit_req(msg_handle_t handle, msg_struct_t req);
+
+
+/**
+ * @brief Registers sent status callback function to Message handle.
+ * @details This API is used to register sent status callback function msg_sent_status_cb() to Message handle.
  *
- * \par Related functions:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Known issues/bugs:
- * None
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Sample code:
- * \code
- * ...
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  A pointer to user data
  *
- * int err = MSG_SUCCESS;
- * MSG_REQUEST_S req;
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * req.msg = msg;
- * req.sendOpt = sendOpt;
-
- * err = msg_reg_sent_status_callback(msgHandle, &sentStatusCB, (void*)"sent status callback");
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
-
- * void sentStatusCB(msg_handle_t Handle, MSG_SENT_STATUS_S *pStatus, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_reg_sent_status_callback(msg_handle_t handle, msg_sent_status_cb cb, void *user_param);
 
 
 /**
-
- * \par Description:
- * Registers incoming SMS callback to Message handle.
+ * @brief Registers incoming SMS callback to Message handle.
+ * @details This API is used to Registers incoming SMS callback function msg_sms_incoming_cb() to Message handle.
  *
- * \par Purpose:
- * This API is used to Registers incoming SMS callback function "msg_sms_incoming_cb" to Message handle.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Typical use case:
- * Register incoming SMS message callback.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Method of function operation:
- * Adds the msg_sms_incoming_cb API to incoming SMS callback list.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] port        The port used for listening \n
+ *                        If port is not used, set to @c 0.
+ * @param[in] user_param  A pointer to user data
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
- *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - port is used for listening. If port is not used, please assign 0 to it.
- * \param input - user_param is a pointer to user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE Message handle is invalid.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- * MSG_REQUEST_S req;
- *
- * req.msg = msg;
- * req.sendOpt = sendOpt;
-
- * err = msg_reg_sms_message_callback(msgHandle, &incomingSmsCB, 0, (void*)"sms message callback");
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
- *
- * void incomingSmsCB(msg_handle_t Handle, msg_message_t msg, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_reg_sms_message_callback(msg_handle_t handle, msg_sms_incoming_cb cb, unsigned short port, void *user_param);
 
 
 /**
-
- * \par Description:
- * Registers incoming MMS callback to Message handle.
+ * @brief Registers incoming MMS conf callback to Message handle.
+ * @details This API is used to Registers incoming MMS conf callback function msg_mms_conf_msg_incoming_cb() to Message handle.
  *
- * \par Purpose:
- * This API is used to Registers incoming MMS callback function "msg_mms_conf_msg_incoming_cb" to Message handle.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Typical use case:
- * Register incoming SMS message callback.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Method of function operation:
- * Adds the msg_mms_conf_msg_incoming_cb API to incoming MMS callback list.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] app_id      The app ID used for listening \n
+ *                        If appId is not used, set to @c NULL.
+ * @param[in] user_param  A pointer to user data
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
- *
- * \param input - handle is Message handle.
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - app_id is used for listening. If appId is not used, please assign NULL to it.
- * \param input - user_param is a pointer to user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE Message handle is invalid.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- * MSG_REQUEST_S req;
- *
- * req.msg = msg;
- * req.sendOpt = sendOpt;
-
- * err = msg_reg_mms_conf_message_callback(msgHandle, &incomingMmsConfCB, NULL, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
- *
- * void incomingMmsConfCB(msg_handle_t Handle, msg_message_t msg, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_reg_mms_conf_message_callback(msg_handle_t handle, msg_mms_conf_msg_incoming_cb cb, const char *app_id, void *user_param);
 
 
 /**
-
- * \par Description:
- * Registers incoming SyncML Message callback to Message handle.
+ * @brief Registers incoming SyncML Message callback to Message handle.
+ * @details This API is used to register incoming SyncML Message callback function msg_syncml_msg_incoming_cb() to Message handle.
  *
- * \par Purpose:
- * This API is used to Registers incoming SyncML Message callback function "msg_syncml_msg_incoming_cb" to Message handle.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Typical use case:
- * Register incoming SMS message callback.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Method of function operation:
- * Adds the msg_syncml_msg_incoming_cb API to incoming SyncML callback list.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  A pointer to user data
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
- *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - user_param is a pointer to user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                                       Success in operation.
- * - MSG_ERR_MSGHANDLE_NOT_CONNECTED   Message handle is not connected.
- * - MSG_ERR_MEMORY_ERROR                              Memory is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- *
- * err = err = msg_reg_syncml_message_callback(msgHandle, &syncMLCB, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
- *
- * void syncMLCB(msg_handle_t hMsgHandle, msg_syncml_message_type_t msgType, const char* pPushHeader, int PushHeaderLen, const char* pPushBody, int PushBodyLen, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_reg_syncml_message_callback(msg_handle_t handle,  msg_syncml_msg_incoming_cb cb, void *user_param);
 
 
 /**
-
- * \par Description:
- * Registers incoming LBS Message callback to Message handle.
- *
- * \par Purpose:
- * This API is used to Registers incoming LBS Message callback function "msg_lbs_msg_incoming_cb" to Message handle.
+ * @brief Registers incoming LBS Message callback to Message handle.
+ * @details This API is used to register incoming LBS Message callback function msg_lbs_msg_incoming_cb() to Message handle.
  *
- * \par Typical use case:
- * Register incoming SMS message callback.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Method of function operation:
- * Adds the msg_lbs_msg_incoming_cb API to incoming LBS Message callback list.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  A pointer to user data
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - user_param is a pointer to user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                                       Success in operation.
- * - MSG_ERR_MSGHANDLE_NOT_CONNECTED   Message handle is not connected.
- * - MSG_ERR_MEMORY_ERROR                              Memory is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- *
- * err = msg_reg_lbs_message_callback(msgHandle, &lbsCB, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
- *
- * void lbsCB(msg_handle_t hMsgHandle, const char* pPushHeader, const char* pPushBody, int pushBodyLen, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_reg_lbs_message_callback(msg_handle_t handle, msg_lbs_msg_incoming_cb cb, void *user_param);
 
 
 /**
-
- * \par Description:
- * Registers incoming LBS Message callback to Message handle.
- *
- * \par Purpose:
- * This API is used to Registers incoming LBS Message callback function "msg_lbs_msg_incoming_cb" to Message handle.
- *
- * \par Typical use case:
- * Register incoming SMS message callback.
+ * @brief Registers SyncML operation callback to Message handle.
+ * @details This API is used to register SyncML operation callback function msg_syncml_msg_operation_cb() to Message handle.
  *
- * \par Method of function operation:
- * Adds the msg_lbs_msg_incoming_cb API to incoming LBS Message callback list.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  A pointer to user data
  *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - user_param is a pointer to user data.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                                       Success in operation.
- * - MSG_ERR_MSGHANDLE_NOT_CONNECTED   Message handle is not connected.
- * - MSG_ERR_MEMORY_ERROR                              Memory is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_reg_syncml_message_operation_callback(msg_handle_t handle,  msg_syncml_msg_operation_cb cb, void *user_param);
+
+
+/**
+ * @brief Registers incoming push Message callback to Message handle.
+ * @details This API is used to register incoming push Message callback function msg_push_msg_incoming_cb() to Message handle.
  *
- * \par Known issues/bugs:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sample code:
- * \code
- * ...
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * int err = MSG_SUCCESS;
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] app_id      The app ID for listening \n
+ *                        If appId is not used, set to @c NULL.
+ * @param[in] user_param  A pointer to user data
  *
- * err = msg_reg_lbs_message_callback(msgHandle, &lbsCB, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * void lbsCB(msg_handle_t hMsgHandle, const char* pPushHeader, const char* pPushBody, int pushBodyLen, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
-int msg_reg_syncml_message_operation_callback(msg_handle_t handle,  msg_syncml_msg_operation_cb cb, void *user_param);
-
 
 int msg_reg_push_message_callback(msg_handle_t handle,  msg_push_msg_incoming_cb cb, const char *app_id, void *user_param);
 
-int msg_reg_cb_message_callback(msg_handle_t handle, msg_cb_incoming_cb  cb, bool bsave, void *user_param);
 
 /**
-
- * \par Description:
- * Registers incoming LBS Message callback to Message handle.
+ * @brief Registers incoming CB Message callback to Message handle.
+ * @details This API is used to register incoming CB Message callback function msg_cb_incoming_cb() to Message handle.
  *
- * \par Purpose:
- * This API is used to Registers incoming LBS Message callback function "msg_lbs_msg_incoming_cb" to Message handle.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Typical use case:
- * Register incoming SMS message callback.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Method of function operation:
- * Adds the msg_lbs_msg_incoming_cb API to incoming LBS Message callback list.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] bsave       A bool flag to indicate whether CB message is to be saved or not \n
+ *                        CB message will be saved if this flag is true
+ * @param[in] user_param  A pointer to user data
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Important notes:
- *     This function MUST be called after Message handle is opened.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_reg_cb_message_callback(msg_handle_t handle, msg_cb_incoming_cb  cb, bool bsave, void *user_param);
+
+
+
+/**
+ * @brief Registers incoming Report Message callback to Message handle.
+ * @details This API is used to register incoming Report Message callback function msg_report_msg_incoming_cb() to Message handle.
  *
- * \param input - handle is Message handle.
- * \param input - cb is a function to be called.
- * \param input - user_param is a pointer to user data.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                                       Success in operation.
- * - MSG_ERR_MSGHANDLE_NOT_CONNECTED   Message handle is not connected.
- * - MSG_ERR_MEMORY_ERROR                              Memory is error.
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
+ * @param[in] handle      The message handle
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  A pointer to user data
  *
- * \par Related functions:
- * None
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ *
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_CALLBACK_ERROR    Callback registration error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
+ */
+
+int msg_reg_report_message_callback(msg_handle_t handle, msg_report_msg_incoming_cb cb, void *user_param);
+
+
+/**
+ * @brief Operates SyncML message.
+ * @details This API is used to run SyncML operation.
  *
- * \par Known issues/bugs:
- * None
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.read
  *
- * \par Sample code:
- * \code
- * ...
+ * @remarks This function MUST be called after Message handle is opened.
  *
- * int err = MSG_SUCCESS;
+ * @param[in] handle  The message handle
+ * @param[in] msgId   The message ID to run SycnML operation
  *
- * err = msg_reg_lbs_message_callback(msgHandle, &lbsCB, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- * return;
- * }
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * void lbsCB(msg_handle_t hMsgHandle, const char* pPushHeader, const char* pPushBody, int pushBodyLen, void *pUserParam)
- * {
- *     ...
- * }
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_TRANSPORT_ERROR   Transport error
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_syncml_message_operation(msg_handle_t handle,  msg_message_id_t msgId);
 
 
 /**
-
- * \par Description:
- * Sends SMS. It is a synchronous API which has been blocked until sent status arrives.
- *
- * \par Purpose:
- * This API is used to sends SMS.
+ * @brief Sends SMS.
+ * @details This API is used to send SMS. It is a synchronous API which has been blocked until sent status arrives.
  *
- * \par Typical use case:
- * Sends a SMS Message
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Method of function operation:
- * It is a synchronous API which has been blocked until sent status arrives.
+ * @param[in] phone_num   The list of phone numbers \n
+ *                        It is separated by ",".
+ * @param[in] sms_text    The SMS text
+ * @param[in] cb          The function to be called
+ * @param[in] user_param  The user data
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Important notes:
- * - None
- *
- * \param input  - phone_num is the list of phone numbers. It is separated by ",".
- * \param input  - sms_text is a SMS text.
- * \param input  - cb is a function to be called.
- * \param input  - user_param is for user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                               Success in operation.
- * - MSG_ERR_NULL_POINTER              Invalid parameter.
- * - MSG_ERR_MEMORY_ERROR      Memory is error.
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  *
  * \par Prospective clients:
  * External/Native Apps using Messaging Services.
  *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- *
- * err = msg_sms_send("01000000000,01000000000", "1234567890", sentStatusCB, NULL);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
  */
-/*================================================================================================*/
+
 int msg_sms_send(const char *phone_num, const char *sms_text, msg_simple_sent_status_cb cb, void *user_param);
 
 
 /**
-
- * \par Description:
- * Submits request to send SMS message.
- *
- * \par Purpose:
- * This API is used to submit request to send SMS message.
+ * @brief Submits request to send SMS message.
+ * @details This API is used to submit request to send SMS message.
  *
- * \par Typical use case:
- * Submits request to send SMS message.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Method of function operation:
- * Submits a request to send SMS.
+ * @param[in] handle The message handle
+ * @param[in] req    A pointer to #msg_struct_t structure for SMS request information
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Important notes:
- * - None
- *
- * \param input  - phone_num is the list of phone numbers. It is separated by ",".
- * \param input  - sms_text is a SMS text.
- * \param input  - cb is a function to be called.
- * \param input  - user_param is for user data.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                               Success in operation.
- * - MSG_ERR_NULL_POINTER              Invalid parameter.
- * - MSG_ERR_MEMORY_ERROR      Memory is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- * MSG_REQUEST_S req;
- *
- * req.msg = msg;
- * req.sendOpt = sendOpt;
- *
- * err = msg_sms_send_message(msgHandle, &req);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_NULL_POINTER      Null parameter
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_sms_send_message(msg_handle_t handle, msg_struct_t req);
 
 
 /**
-
- * \par Description:
- * Submits request to send MMS message.
+ * @brief Submits request to send MMS message.
+ * @details This API is used to submit request to send MMS message.
  *
- * \par Purpose:
- * This API is used to submit request to send MMS message.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Typical use case:
- * Submits request to send MMS message.
+ * @param[in] handle The message handle
+ * @param[in] req    A pointer to #msg_struct_t structure for MMS request information
  *
- * \par Method of function operation:
- * Submits a request to send MMS.
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input  - handle is Message handle.
- * \param input  - req is a pointer to an MSG_REQUEST_S structure.
- *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                               Success in operation.
- * - MSG_ERR_NULL_POINTER              Invalid parameter.
- * - MSG_ERR_MEMORY_ERROR      Memory is error.
- *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
- *
- * \par Sample code:
- * \code
- * ...
- *
- * int err = MSG_SUCCESS;
- * MSG_REQUEST_S req;
- *
- * req.msg = msg;
- * req.sendOpt = sendOpt;
- *
- * err = msg_mms_send_message(msgHandle, &req);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_mms_send_message(msg_handle_t handle, msg_struct_t req);
 
 
 /**
-
- * \par Description:
- * Submits request to send MMS read report request.
- *
- * \par Purpose:
- * This API is used to submit request to send MMS read report request.
- *
- * \par Typical use case:
- * Submits request to send MMS read report request.
- *
- * \par Method of function operation:
- * Submits a request to send MMS read report request.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input  - handle is Message handle.
- * \param input  - msg_id is a message id, which is a positive integer.
- * \param input  - mms_read_status is status whether message was read or not.
+ * @brief Submits request to send MMS read report request.
+ * @details This API is used to submit request to send MMS read report request.
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                               Success in operation.
- * - MSG_ERR_NULL_POINTER              Invalid parameter.
- * - MSG_ERR_MEMORY_ERROR      Memory is error.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
+ * @param[in] handle          The message handle
+ * @param[in] msg_id          The message ID \n
+ *                            This is a positive integer.
+ * @param[in] mms_read_status This is status whether message was read or not
  *
- * \par Sample code:
- * \code
- * ...
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * int err = MSG_SUCCESS;
- *
- * err = err = msg_mms_send_read_report(NULL, 0, MSG_READ_REPORT_IS_READ);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_mms_send_read_report(msg_handle_t handle, msg_message_id_t msgId, msg_read_report_status_t mms_read_status);
 
 
 /**
-
- * \par Description:
- * Submits request to send forward MMS request.
- *
- * \par Purpose:
- * This API is used to submit request to send forward MMS request.
- *
- * \par Typical use case:
- * Submits request to send forward MMS request.
- *
- * \par Method of function operation:
- * Submits a request to send forward MMS request.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input  - handle is Message handle.
-  * \param input  - req is a pointer to an MSG_REQUEST_S structure.
+ * @brief Submits request to send forward MMS request.
+ * @details This API is used to submit request to send forward MMS request.
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE         Message handle is invalid.
- * - MSG_ERR_NULL_POINTER                              Pointer is NULL.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
+ * @param[in] handle The message handle
+ * @param[in] req    A pointer to #msg_struct_t structure for MMS
  *
- * \par Sample code:
- * \code
- * ...
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * int err = MSG_SUCCESS;
- *
- * err = err = msg_mms_send_read_report(NULL, 0, MSG_READ_REPORT_IS_READ);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_mms_forward_message(msg_handle_t handle, msg_struct_t req);
 
 
 /**
-
- * \par Description:
- * Submits request to retrieve MMS request.
- *
- * \par Purpose:
- * This API is used to submit request to retrieve MMS request.
- *
- * \par Typical use case:
- * Submits request to retrieve MMS request.
- *
- * \par Method of function operation:
- * Submits a request to send forward MMS request.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input  - handle is Message handle.
-  * \param input  - req is a pointer to an MSG_REQUEST_S structure.
+ * @brief Submits request to retrieve MMS request.
+ * @details This API is used to submit request to retrieve MMS request.
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE         Message handle is invalid.
- * - MSG_ERR_NULL_POINTER                              Pointer is NULL.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
+ * @param[in] handle  The message handle
+ * @param[in] req     A pointer to #msg_struct_t structure for MMS
  *
- * \par Sample code:
- * \code
- * ...
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * int err = MSG_SUCCESS;
- *
- * err = msg_mms_retrieve_message(handle, &req);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_mms_retrieve_message(msg_handle_t handle, msg_struct_t req);
 
 
-/* reject_msg_support */
 /**
-
- * \par Description:
- * Submits request to reject MMS message.
- *
- * \par Purpose:
- * This API is used to submit request to reject MMS message.
- *
- * \par Typical use case:
- * Submits request to reject MMS message.
- *
- * \par Method of function operation:
- * Submits a request to send forward reject MMS message.
- *
- * \par Sync (or) Async:
- * This is a Synchronous API.
- *
- * \par Important notes:
- * - None
- *
- * \param input  - handle is Message handle.
-  * \param input  - req is a pointer to an MSG_REQUEST_S structure.
+ * @brief Submits request to reject MMS message.
+ * @details This API is used to submit request to reject MMS message.
  *
- * \return Return Type (int(msg_error_t)) \n
- * - MSG_SUCCESS                                       Success in operation.
- * - MSG_ERR_INVALID_MSGHANDLE         Message handle is invalid.
- * - MSG_ERR_NULL_POINTER                              Pointer is NULL.
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/message.write
  *
- * \par Prospective clients:
- * External/Native Apps using Messaging Services.
- *
- * \par Related functions:
- * None
- *
- * \par Known issues/bugs:
- * None
+ * @param[in] handle  The message handle
+ * @param[in] req     A pointer to #msg_struct_t structure for MMS
  *
- * \par Sample code:
- * \code
- * ...
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
  *
- * int err = MSG_SUCCESS;
- *
- * err = msg_mms_reject_message(handle, &req);
- * if (err != MSG_SUCCESS)
- * {
- * ...
- * }
- *
- * ...
- * \endcode
+ * @retval MSG_SUCCESS               Success in operation
+ * @retval MSG_ERR_INVALID_PARAMETER Input parameter is invalid
+ * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method
  */
-/*================================================================================================*/
+
 int msg_mms_reject_message(msg_handle_t handle, msg_struct_t req);
 
 /**
index 6fd5759..d27811f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_TRANSPORT_TYPES_H_
 #include "msg_types.h"
 #include "msg_storage_types.h"
 
+/**
+ * @internal
+ * @addtogroup MSG_SERVICE_FRAMEWORK_TRANSPORT_MODULE
+ * @{
+ */
+
 
 /*==================================================================================================
                                     DEFINES
 ==================================================================================================*/
 
-/**    @brief  Prototype of the function that will be called when the status of the message which is already sent is changed.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_sent_status_callback.
- *     If the application sends a message, this callback function will be called to report its sending status.
- *     The application can get the request ID from sent_status to know which request is bound.
- *     The callback function runs in the application process, not in the framework process.
- *     The memory of sent_status is managed by MAPI, when the callback function is finished.
- *     @param[in]      handle is Message handle.
- *     @param[in]      sent_status is a pointer to an MSG_SENT_STATUS_S structure.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/**    @brief  Called when the status of the message which is already sent is changed.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_sent_status_callback().
+ *              If the application sends a message, this callback function will be called to report its sending status.
+ *              The application can get the request ID from sent_status to know which request is bound.
+ *              The callback function runs in the application process, not in the framework process.
+ *              The memory of @a sent_status is managed by MAPI, when the callback function is finished.
+ *
+ * @param[in]  handle       The Message handle
+ * @param[in]  sent_status  A pointer to #msg_struct_t structure for sent status
+ * @param[in]  user_param   The user data
  */
 typedef void (*msg_sent_status_cb)(msg_handle_t handle, msg_struct_t sent_status, void *user_param);
 
 
-/**    @brief  Prototype of the function that will be called when the status of the message which is already sent is changed.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_sent_status_callback.
- *     If the application sends a message, this callback function will be called to report its sending status.
- *     The application can get the request ID from sent_status to know which request is bound.
- *     The callback function runs in the application process, not in the framework process.
- *     The memory of sent_status is managed by MAPI, when the callback function is finished.
- *     @param[in]      sent_status is a pointer to an MSG_SENT_STATUS_S structure.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/**    @brief  Called when the status of the message which is already sent is changed.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_sent_status_callback().
+ *              If the application sends a message, this callback function will be called to report its sending status.
+ *              The application can get the request ID from sent_status to know which request is bound.
+ *              The callback function runs in the application process, not in the framework process.
+ *              The memory of @a sent_status is managed by MAPI, when the callback function is finished.
+ *
+ * @param[in]  sent_status  A pointer to #msg_struct_t structure for sent status
+ * @param[in]  user_param   The pointer to user data
  */
 typedef void (*msg_simple_sent_status_cb)(msg_struct_t sent_status, void *user_param);
 
 
-/** @brief     Prototype of the function that will be called when a new message is received.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_sms_message_callback.
- *     This callback function will be called when a new message is received and the message satisfies the filter list.
- *     The callback function runs in the application process, not in the framework process.
- *     The memory for msg is managed by MAPI, when the callback function is finished.
- *     @param[in]      handle is Message handle.
- *     @param[in]      msg is a pointer to an msg_message_t structure.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/** @brief     Called when a new message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_sms_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *              The memory for msg is managed by MAPI, when the callback function is finished.
+ *
+ * @param[in]  handle       The Message handle
+ * @param[in]  msg          A pointer to #msg_struct_t structure for message details
+ * @param[in]  user_param   The user data
  */
 typedef void (*msg_sms_incoming_cb)(msg_handle_t handle, msg_struct_t msg, void *user_param);
 
 
-/** @brief     Prototype of the function that will be called when a new MMS message is received.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_mms_conf_message_callback.
- *     This callback function will be called when a new MMS message is received and the message satisfies the filter list.
- *     The callback function runs in the application process, not in the framework process.
- *     The memory for msg is managed by MAPI, when the callback function is finished.
- *     @param[in]      handle is Message handle.
- *     @param[in]      msg is a pointer to an msg_message_t structure.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/** @brief     Called when a new MMS message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_mms_conf_message_callback().
+ *              This callback function will be called when a new MMS message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *              The memory for @a msg is managed by MAPI, when the callback function is finished.
+ *
+ * @param[in]  handle      The Message handle
+ * @param[in]  msg         A pointer to #msg_struct_t structure for message details
+ * @param[in]  user_param  The user data
  */
 typedef void (*msg_mms_conf_msg_incoming_cb)(msg_handle_t handle, msg_struct_t msg, void *user_param);
 
 
-/** @brief     Prototype of the function that will be called when a new SyncML message is received.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_syncml_message_callback.
- *     This callback function will be called when a new message is received and the message satisfies the filter list.
- *     The callback function runs in the application process, not in the framework process.
- *     @param[in]      handle is Message handle.
- *     @param[in]      msg_type is msg_syncml_message_type_t structure.
- *     @param[in]      push_body is WAP Push body data.
- *     @param[in]      push_body_len is the length of WAP Push body data.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/** @brief     Called when a new SyncML message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_syncml_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *
+ * @param[in]  handle         The Message handle
+ * @param[in]  msg_type       The #msg_syncml_message_type_t structure
+ * @param[in]  push_body      The WAP Push body data
+ * @param[in]  push_body_len  The length of WAP Push body data
+ * @param[in]  sim_index      The index of the sim on which message is received.
+ * @param[in]  user_param     The user data
  */
-typedef void (*msg_syncml_msg_incoming_cb)(msg_handle_t handle, msg_syncml_message_type_t msg_type, const char *push_body, int push_body_len, const char* wsp_header, int wsp_header_len, void *user_param);
-
-
-/** @brief     Prototype of the function that will be called when a new LBS message is received.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_lbs_message_callback.
- *     This callback function will be called when a new message is received and the message satisfies the filter list.
- *     The callback function runs in the application process, not in the framework process.
- *     @param[in]      hMsgHandle is Message handle.
- *     @param[in]      push_header is push message header data.
- *     @param[in]      push_body is push message body data.
- *     @param[in]      push_body_len is push message body length.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+typedef void (*msg_syncml_msg_incoming_cb)(msg_handle_t handle, msg_syncml_message_type_t msg_type, const char *push_body, int push_body_len, const char* wsp_header, int wsp_header_len, int sim_index, void *user_param);
+
+
+/** @brief     Called when a new LBS message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_lbs_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *
+ * @param[in]  hMsgHandle     The Message handle
+ * @param[in]  push_header    The push message header data
+ * @param[in]  push_body      The push message body data
+ * @param[in]  push_body_len  The push message body length
+ * @param[in]  user_param     The user data
  */
 typedef void (*msg_lbs_msg_incoming_cb)(msg_handle_t handle, const char *push_header, const char *push_body, int push_body_len, void *user_param);
 
 
-/** @brief     Prototype of the function that will be called when a new SyncML message is received.
- *     Applications SHOULD implement this callback function and register it into Message handle.
- *     For how to register this callback function, please refer to msg_reg_syncml_message_callback.
- *     This callback function will be called when a new message is received and the message satisfies the filter list.
- *     The callback function runs in the application process, not in the framework process.
- *     @param[in]      handle is Message handle.
- *     @param[in]      user_param is a pointer to user data.
- *     @return void
+/** @brief     Called when a new SyncML message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_syncml_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *
+ * @param[in]  handle      The Message handle
+ * @param[in]  msgId       The message ID
+ * @param[in]  extId       The external ID
+ * @param[in]  user_param  The user data
  */
 typedef void (*msg_syncml_msg_operation_cb)(msg_handle_t handle, int msgId, int extId, void *user_param);
 
 
+/** @brief     Called when a new push message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_push_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *
+ * @param[in]  handle         The Message handle
+ * @param[in]  push_header    The push message header data
+ * @param[in]  push_body      The push message body data
+ * @param[in]  push_body_len  The push message body length
+ * @param[in]  user_param     The user data
+ */
 typedef void (*msg_push_msg_incoming_cb)(msg_handle_t handle, const char *push_header, const char *push_body, int push_body_len, void *user_param);
 
 
+/** @brief     Called when a new CB message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_cb_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *
+ * @param[in]  handle      The Message handle
+ * @param[in]  msg         A pointer to #msg_struct_t structure for message details
+ * @param[in]  user_param  The user data
+ */
 typedef void (*msg_cb_incoming_cb)(msg_handle_t handle, msg_struct_t msg, void *user_param);
 
+
+/** @brief     Called when a report message is received.
+ *              Applications SHOULD implement this callback function and register it into Message handle.
+ *              For how to register this callback function, please refer to msg_reg_report_message_callback().
+ *              This callback function will be called when a new message is received and the message satisfies the filter list.
+ *              The callback function runs in the application process, not in the framework process.
+ *
+ * @param[in]  handle         The Message handle
+ * @param[in]  reportMsgType  The message type of incoming report message
+ * @param[in]  MsgId          The message ID of reported message
+ * @param[in]  addr_len       The incoming report message's address length
+ * @param[in]  addr_val       The incoming report message's address value
+ * @param[in]  user_param     The user data
+ */
+typedef void (*msg_report_msg_incoming_cb)(msg_handle_t handle, msg_report_type_t reportMsgType, msg_message_id_t MsgId, int addr_len, const char *addr_val, void *user_param);
+
+/**
+ * @}
+ */
+
 #endif /* MSG_TRANSPORT_TYPES_H_ */
index e29fe95..4e11333 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_TYPES_H_
 #define EXPORT_API __attribute__ ((visibility("default")))
 #endif
 
-#define MAX_TO_ADDRESS_CNT             10
-#define MAX_PHONE_NUMBER_LEN   20
+/**
+ * @internal
+ * @addtogroup MSG_SERVICE_FRAMEWORK
+ * @{
+ */
+
+/**
+ * @brief      Definition for maximum address count
+ */
+#define MAX_TO_ADDRESS_CNT 10
+
+/**
+ * @brief      Definition for maximum phone number length
+ */
+#define MAX_PHONE_NUMBER_LEN 20
+
+/**
+ * @brief      Definition for maximum XDN alpha ID length
+ */
+#define MAX_SIM_XDN_ALPHA_ID_LEN 30
+/**
+ * @brief      Definition for maximum address value length
+ */
 #define MAX_ADDRESS_VAL_LEN    254
-#define MAX_SIGN_VAL_LEN               128
-#define MAX_SUBJECT_LEN                        120
-#define MAX_DISPLAY_NAME_LEN   195
-#define MAX_IMAGE_PATH_LEN             1024
-#define MAX_MSG_DATA_LEN               320
-#define MAX_MSG_TEXT_LEN               1530
-#define MAX_FILTER_VALUE_LEN   40
-#define MAX_COMMAND_LEN                1024
-#define MAX_FOLDER_NAME_SIZE           20
-
-#define MAX_WAPPUSH_ID_LEN                             100
-#define MAX_WAPPUSH_CONTENT_TYPE_LEN   100
-#define MAX_WAPPUSH_HREF_LEN                   300
-#define MAX_WAPPUSH_CONTENTS_LEN               2048
 
+/**
+ * @brief      Definition for maximum subject length
+ */
+#define MAX_SUBJECT_LEN 120
+
+/**
+ * @brief      Definition for maximum display length length
+ */
+#define MAX_DISPLAY_NAME_LEN 195
+
+/**
+ * @brief      Definition for maximum image path length
+ */
+#define MAX_IMAGE_PATH_LEN 1024
+
+/**
+ * @brief      Definition for maximum message data length
+ */
+#define MAX_MSG_DATA_LEN 320
+
+/**
+ * @brief      Definition for maximum message text length
+ */
+#define MAX_MSG_TEXT_LEN 1530
+
+/**
+ * @brief      Definition for maximum filter value length
+ */
+#define MAX_FILTER_VALUE_LEN 128
+
+/**
+ * @brief      Definition for maximum command length
+ */
+#define MAX_COMMAND_LEN 1024
+
+/**
+ * @brief      Definition for maximum folder name size
+ */
+#define MAX_FOLDER_NAME_SIZE 20
+
+/**
+ * @brief      Definition for maximum ID length of push message
+ */
+#define MAX_WAPPUSH_ID_LEN 100
+
+/**
+ * @brief      Definition for maximum content type length of push message
+ */
+#define MAX_WAPPUSH_CONTENT_TYPE_LEN 100
+
+/**
+ * @brief      Definition for maximum href length of push message
+ */
+#define MAX_WAPPUSH_HREF_LEN 300
+
+/**
+ * @brief      Definition for maximum contents length of push message
+ */
+#define MAX_WAPPUSH_CONTENTS_LEN 2048
+
+/**
+ * @brief      Definition for maximum invalid object count of push message(CO)
+ */
 #define MAX_PUSH_CACHEOP_INVALID_OBJECT_MAX    5
-#define MAX_PUSH_CACHEOP_INVALID_SERVICE_MAX   5
-#define MAX_PUSH_CACHEOP_MAX_URL_LEN                   200
 
-#define MAX_COMMON_INFO_SIZE   20
+/**
+ * @brief      Definition for maximum invalid service count of push message(CO)
+ */
+#define MAX_PUSH_CACHEOP_INVALID_SERVICE_MAX 5
+
+/**
+ * @brief      Definition for maximum URL length of push message(CO)
+ */
+#define MAX_PUSH_CACHEOP_MAX_URL_LEN 200
 
-#define MAX_SEGMENT_NUM                        15
+/**
+ * @brief      Definition for maximum segment count
+ */
+#define MAX_SEGMENT_NUM 15
 
 /**
- *     @brief  Defines the maximum file path length
+ * @brief      Definition for maximum file path length
  */
-#define        MSG_FILEPATH_LEN_MAX    1024
+#define        MSG_FILEPATH_LEN_MAX 1024
 
 // setting
-#define SMSC_NAME_MAX                  127             /* Max SMSC Name Length */
-#define SMSC_ADDR_MAX                  20              /* Max SMSC Adress Length  */
-#define SMSC_LIST_MAX                  5               /* Max List Count of SMSC */
-#define CB_CHANNEL_NAME_MAX    32              /* cb channel name max size */
-#define CB_CHANNEL_MAX                 30              /* cb channel max count */
-#define CB_LANG_TYPE_MAX               10
+/**
+ * @brief      Definition for maximum SMSC name length
+ */
+#define SMSC_NAME_MAX 127
 
 /**
- *     @brief  Defines the maximum file name length
+ * @brief      Definition for maximum SMSC address length
  */
-#define        MSG_FILENAME_LEN_MAX    1024
+#define SMSC_ADDR_MAX 21
 
 /**
- *     @brief  Defines the maximum message id length
+ * @brief      Definition for maximum SMSC list count
  */
-#define        MSG_MSG_ID_LEN                  100
+#define SMSC_LIST_MAX 5
 
 /**
- *     @brief  Defines the maximum in transition id length
+ * @brief      Definition for maximum CB channel name length
  */
-#define MAX_SMIL_TRANSIN_ID            100
+#define CB_CHANNEL_NAME_MAX 32
 
 /**
- *     @brief  Defines the maximum out transition id length
+ * @brief      Definition for maximum CB channel count
  */
-#define MAX_SMIL_TRANSOUT_ID   100
+#define CB_CHANNEL_MAX 30
 
 /**
- *     @brief  Defines the maximum region id length
+ * @brief      Definition for maximum CB language type count
  */
-#define        MAX_SMIL_REGION_ID              151
+#define CB_LANG_TYPE_MAX 10
 
 /**
- *     @brief  Defines the maximum transition id length
+ * @brief      Definition for maximum file name length
  */
-#define MAX_SMIL_TRANSITION_ID         151
+#define        MSG_FILENAME_LEN_MAX 1024
 
 /**
- *     @brief  Defines the maximum meta id length
+ * @brief      Definition for maximum message id length
  */
-#define MAX_SMIL_META_ID               151
+#define        MSG_MSG_ID_LEN 1024
 
 /**
- *     @brief  Defines the maximum meta name length
+ * @brief      Definition for maximum in transition id length
  */
-#define MAX_SMIL_META_NAME             100
+#define MAX_SMIL_TRANSIN_ID 100
 
 /**
- *     @brief  Defines the maximum meta content length
+ * @brief      Definition for maximum out transition id length
  */
-#define MAX_SMIL_META_CONTENT          255
+#define MAX_SMIL_TRANSOUT_ID 100
 
 /**
- *     @brief  Defines the maximum fit size
+ * @brief      Definition for maximum region id length
  */
-#define        MAX_SMIL_FIT_SIZE               31
+#define        MAX_SMIL_REGION_ID 151
 
 /**
- *     @brief  Defines the maximum pages in a MMS
+ * @brief      Definition for maximum transition id length
  */
-#define        MMS_PAGE_MAX                    20
+#define MAX_SMIL_TRANSITION_ID 151
 
 /**
- *     @brief  Defines the maximum media in a MMS
+ * @brief      Definition for maximum meta id length
  */
-#define        MMS_MEDIA_MAX                   60
+#define MAX_SMIL_META_ID 151
 
 /**
- *     @brief  Defines the maximum alternate text length
+ * @brief      Definition for maximum meta name length
  */
-#define        MAX_SMIL_ALT_LEN                255
+#define MAX_SMIL_META_NAME 100
 
+/**
+ * @brief      Definition for maximum meta content length
+ */
+#define MAX_SMIL_META_CONTENT 255
+
+/**
+ * @brief      Definition for maximum fit size
+ */
+#define        MAX_SMIL_FIT_SIZE 31
+
+/**
+ * @brief      Definition for maximum pages in a MMS
+ */
+#define        MMS_PAGE_MAX 20
+
+/**
+ * @brief      Definition for maximum media in a MMS
+ */
+#define        MMS_MEDIA_MAX 60
 
-//font size
 /**
- *     @brief  Defines the small font size
+ * @brief      Definition for maximum alternate text length
  */
-#define        MMS_SMIL_FONT_SIZE_SMALL                24
+#define        MAX_SMIL_ALT_LEN 255
 
+
+//font size
 /**
- *     @brief  Defines the normal font size
+ * @brief      Definition for small font size
  */
-#define        MMS_SMIL_FONT_SIZE_NORMAL               30
+#define        MMS_SMIL_FONT_SIZE_SMALL 24
 
 /**
- *     @brief  Defines the large font size
+ * @brief      Definition for normal font size
  */
-#define        MMS_SMIL_FONT_SIZE_LARGE                36
+#define        MMS_SMIL_FONT_SIZE_NORMAL 30
 
-#define MAX_SMIL_ANIMATE_ATTRIBUTE_NAME 100
-#define MAX_SMIL_ANIMATE_ATTRIBUTE_TYPE 100
-#define MAX_SMIL_ANIMATE_TARGET_ELEMENT 100
-#define MAX_SMIL_ANIMATE_CALC_MODE 100
+/**
+ * @brief      Definition for large font size
+ */
+#define        MMS_SMIL_FONT_SIZE_LARGE 36
 
+/**
+ * @brief      Definition for maximum length of java app ID
+ */
 #define MAX_MMS_JAVA_APPID_LEN 32
 
-#define CONV_THUMB_WIDTH       250
-#define CONV_THUMB_HEIGHT 170
+/**
+ * @brief      Definition for maximum length of MMS transaction ID
+ */
+#define MMS_TR_ID_LEN 40
 
-#define MMS_TR_ID_LEN          40
-#define MMS_MSG_ID_LEN         40
-#define MMS_LOCATION_LEN       100
+/**
+ * @brief      Definition for maximum length of MMS message ID
+ */
+#define MMS_MSG_ID_LEN 40
+
+/**
+ * @brief      Definition for maximum length of MMS contents location
+ */
+#define MMS_LOCATION_LEN 100
 
-#define MAX_MMS_TEXT_LEN               2000
 /*==================================================================================================
                                          TYPES
 ==================================================================================================*/
 
-typedef struct opq_msg_svc_s *                 msg_handle_t;
-typedef struct opq_struct_s *                          msg_struct_t;
+/**
+ * @brief      The structure type representing an opaque pointer to message handle.
+ */
+typedef struct opq_msg_svc_s *msg_handle_t;
 
+/**
+ * @brief      The structure type representing an opaque pointer to message structure type.
+ */
+typedef struct opq_struct_s *msg_struct_t;
 
+/**
+ * @brief      The structure type representing a pointer to message list handle.
+ */
 typedef struct msg_list_handle *msg_list_handle_t;
 
-
+/**
+ * @brief      The structure type representing a message structure list.
+ */
 typedef struct {
-       int                                     nCount;                         /**< Indicates the count of msg_struct_t. */
-       msg_struct_t            *msg_struct_info;       /**< Indicates the msg_struct_t information list. */
+    int             nCount;            /**< The count of #msg_struct_t */
+    msg_struct_t    *msg_struct_info;  /**< The #msg_struct_t information list */
 }msg_struct_list_s;
 
 
 /**
- *     @brief  Represents a messsage ID.
+ * @brief  The message ID.
  */
 typedef unsigned int msg_message_id_t;
 
 
 /**
- *     @brief  Represents a storage type.
-       See enum _MSG_STORAGE_ID_E
+ * @brief  The storage type.
+ *         See enum _MSG_STORAGE_ID_E.
  */
 typedef unsigned char msg_storage_id_t;
 
 
 /**
- *     @brief  Represents a folder ID.
-       See enum _MSG_FOLDER_ID_E
+ * @brief  The folder ID.
+ *         See enum _MSG_FOLDER_ID_E.
  */
 typedef char msg_folder_id_t;
 
 
 /**
- *     @brief  Represents a request ID, which is unique for each request.
+ * @brief The request ID, which is unique for each request.
  */
 typedef unsigned int msg_request_id_t;
 
 
 /**
- *     @brief  Represents a message priority. \n
- *     The values for this type SHOULD be in _MSG_PRIORITY_TYPE_E.
+ * @brief  The message priority. \n
+ *         The values for this type SHOULD be in _MSG_PRIORITY_TYPE_E.
  */
 typedef unsigned char msg_priority_type_t;
 
 
 /**
- *     @brief  Represents the network status of a message. \n
- *     The values for this type SHOULD be in _MSG_NETWORK_STATUS_E.
+ * @brief  The network status of a message. \n
+ *         The values for this type SHOULD be in _MSG_NETWORK_STATUS_E.
  */
 typedef unsigned char msg_network_status_t;
 
 
 /**
- *     @brief  Represents an address type. \n
- *     The values for this type SHOULD be in _MSG_ADDRESS_TYPE_E.
+ * @brief  The address type. \n
+ *         The values for this type SHOULD be in _MSG_ADDRESS_TYPE_E.
  */
 typedef unsigned char msg_address_type_t;
 
 
 /**
- *     @brief  Represents an recipient type. \n
- *     The values for this type SHOULD be in _MSG_RECIPIENT_TYPE_E.
+ * @brief  The recipient type. \n
+ *         The values for this type SHOULD be in _MSG_RECIPIENT_TYPE_E.
  */
 typedef unsigned char msg_recipient_type_t;
 
 
 /**
- *     @brief  Represents the type of a message direction. \n
- *     The values for this type SHOULD be in _MSG_DIRECTION_TYPE_E.
+ * @brief  The type of a message direction. \n
+ *         The values for this type SHOULD be in _MSG_DIRECTION_TYPE_E.
  */
 typedef unsigned char msg_direction_type_t;
 
 
 /**
- *     @brief  Represents an encoding type. \n
- *     The values for this type SHOULD be in _MSG_ENCODE_TYPE_E.
+ * @brief  The encoding type. \n
+ *         The values for this type SHOULD be in _MSG_ENCODE_TYPE_E.
  */
 typedef unsigned char msg_encode_type_t;
 
 
 /**
- *     @brief  Represents an error code. \n
- *     The values for this type SHOULD be in _MSG_ERROR_E
+ * @brief  The error code. \n
+ *         The values for this type SHOULD be in _MSG_ERROR_E.
  */
 typedef int msg_error_t;
 
 
 /**
-\brief Represents WAP Push App Code.
+* @brief The WAP Push App Code.
 */
 typedef unsigned char msg_push_action_t;
 
 
 /**
-\brief Represents SyncML Message Type.
+* @brief The SyncML Message Type.
 */
 typedef unsigned short msg_syncml_message_type_t;
 
 
 /**
- *     @brief  Represents a Contact ID.
+ * @brief The Contact ID.
  */
 typedef unsigned int msg_contact_id_t;
 
 
 /**
-  *  @brief    Represents a Report Type.
- *     The values for this type SHOULD be in _MSG_REPORT_TYPE_E
 */
+ * @brief  The Report Type. \n
+ *         The values for this type SHOULD be in _MSG_REPORT_TYPE_E.
+ */
 typedef int msg_report_type_t;
 
 
 /**
-  *  @brief    Represents a Delivery Report Status.
- *     The values for this type SHOULD be in _MSG_DELIVERY_REPORT_STATUS_E
 */
+ * @brief  The Delivery Report Status. \n
+ *         The values for this type SHOULD be in _MSG_DELIVERY_REPORT_STATUS_E.
+ */
 typedef int msg_delivery_report_status_t;
 
 
 /**
- *     @brief  Represents a Read Report Status.
- *     The values for this type SHOULD be in _MSG_READ_REPORT_STATUS_E
+ * @brief  The Read Report Status.\n
+ *         The values for this type SHOULD be in _MSG_READ_REPORT_STATUS_E
  */
 typedef int msg_read_report_status_t;
 
 
 /**
- *     @brief  Represents a Message Type.
- *     The values for this type SHOULD be in _MSG_MESSAGE_TYPE_E
+ * @brief  The Message Type. \n
+ *         The values for this type SHOULD be in _MSG_MESSAGE_TYPE_E.
 */
 typedef unsigned short msg_message_type_t;
 
 /**
- *     @brief  Represents a Message Backup Type.
- *     The values for this type SHOULD be in _MSG_MESSAGE_BACKUP_TYPE_E
+ * @brief  The Message Backup Type. \n
+ *         The values for this type SHOULD be in _MSG_MESSAGE_BACKUP_TYPE_E.
 */
 typedef unsigned int msg_message_backup_type_t;
 
 /**
- *     @brief  Represents a thread ID. \n
+ * @brief  The thread ID.
  */
 typedef unsigned int msg_thread_id_t;
 
 // filter
 /**
- *     @brief  Represents a filter ID.
+ * @brief  The filter ID.
  */
 typedef unsigned char msg_filter_id_t;
 
 
 /**
- *     @brief  Represents a filter Type. \n
- *     The filter Type represents a unique filter type. \n
- *     The values for this type SHOULD be in _MSG_FILTER_TYPE_E.
+ * @brief  The filter Type. \n
+ *         The filter type represents a unique filter type. \n
+ *         The values for this type SHOULD be in _MSG_FILTER_TYPE_E.
  */
 typedef unsigned char msg_filter_type_t;
 
@@ -331,441 +449,727 @@ typedef unsigned char msg_filter_type_t;
                                          ENUMS
 ==================================================================================================*/
 
+/**
+ * @brief  Enumeration for the values of a structure type for #msg_sturuct_t. \n
+ */
 enum _MSG_STRUCT_E {
-       MSG_STRUCT_FILTER = 0X0000,                                                             /**< Indicates the MSG_STRUCT_FILTER */
-
-       MSG_STRUCT_MESSAGE_INFO = 0x0200,                               /**< Indicates the MSG_STRUCT_MESSAGE_INFO */
-       MSG_STRUCT_THREAD_INFO = 0x0300,
-       MSG_STRUCT_CONV_INFO = 0x0400,
-       MSG_STRUCT_MMS = 0x0500,                                                                /**< Indicates the MSG_STRUCT_MMS */
-       MSG_STRUCT_MMS_PAGE = 0x0600,                                           /**< Indicates the MSG_STRUCT_MMS_PAGE */
-       MSG_STRUCT_MMS_MEDIA = 0x0700,                                  /**< Indicates the MSG_STRUCT_MMS_MEDIA */
-       MSG_STRUCT_MMS_ATTACH = 0x0800,                                 /**< Indicates the MSG_STRUCT_MMS_ATTACH */
-       MSG_STRUCT_MMS_REGION = 0x0900,                                 /**< Indicates the MSG_STRUCT_MMS_REGION */
-       MSG_STRUCT_MMS_TRANSITION = 0x0a00,                     /**< Indicates the MSG_STRUCT_MMS_TRANSITION */
-       MSG_STRUCT_MMS_META = 0x0b00,                                           /**< Indicates the MSG_STRUCT_MMS_META */
-       MSG_STRUCT_MMS_SMIL_TEXT = 0x0c00,                      /**< Indicates the MSG_STRUCT_MMS_SMIL_TEXT */
-       MSG_STRUCT_MMS_SMIL_AVI = 0x0d00,                               /**< Indicates the MSG_STRUCT_MMS_SMIL_AVI */
-
-       MSG_STRUCT_SETTING_SMSC_OPT = 0x2000,
-       MSG_STRUCT_SETTING_SMSC_INFO = 0x2100,                                          /**< Indicates the MSG_STRUCT_SETTING_SMSC_INFO */
-       MSG_STRUCT_SETTING_CB_OPT = 0x2200,                                                     /**< Indicates the MSG_STRUCT_SETTING_CB_OPT */
-       MSG_STRUCT_SETTING_CB_CHANNEL_INFO = 0x2300,                    /**< Indicates the MSG_STRUCT_CB_CHANNEL_INFO */
-       MSG_STRUCT_SETTING_SMS_SEND_OPT = 0x2400,                               /**< Indicates the MSG_STRUCT_SETTING_SMS_SEND_OPT */
-       MSG_STRUCT_SETTING_MMS_SEND_OPT = 0x2500,                               /**< Indicates the MSG_STRUCT_SETTING_MMS_SEND_OPT */
-       MSG_STRUCT_SETTING_MMS_RECV_OPT = 0x2600,                               /**< Indicates the MSG_STRUCT_SETTING_MMS_RECV_OPT */
-       MSG_STRUCT_SETTING_PUSH_MSG_OPT = 0x2700,                               /**< Indicates the MSG_STRUCT_SETTING_PUSH_MSG_OPT */
-       MSG_STRUCT_SETTING_VOICE_MSG_OPT = 0x2800,                              /**< Indicates the MSG_STRUCT_SETTING_VOICE_MSG_OPT */
-       MSG_STRUCT_SETTING_GENERAL_OPT = 0x2900,                                /**< Indicates the MSG_STRUCT_SETTING_GENERAL_OPT */
-       MSG_STRUCT_SETTING_MSGSIZE_OPT = 0x2c00,                                        /**< Indicates the MSG_STRUCT_SETTING_MSGSIZE_OPT */
-
-
-       MSG_STRUCT_SYNCML_INFO = 0x3100,                                        /**< Indicates the MSG_STRUCT_SYNCML_INFO */
-       MSG_STRUCT_COUNT_INFO = 0x3200,                                 /**< Indicates the MSG_STRUCT_COUNT_INFO */
-       MSG_STRUCT_THREAD_COUNT_INFO = 0x3300,          /**< Indicates the MSG_STRUCT_THREAD_COUNT_INFO */
-       MSG_STRUCT_THREAD_LIST_INDEX = 0x3400,          /**< Indicates the MSG_STRUCT_THREAD_LIST_INDEX */
-       MSG_STRUCT_SORT_RULE = 0x3500,                                          /**< Indicates the MSG_STRUCT_SORT_RULE */
-       MSG_STRUCT_FOLDER_INFO = 0x3600,                                        /**< Indicates the MSG_STRUCT_FOLDER_INFO */
-       MSG_STRUCT_SEARCH_CONDITION = 0x3700,           /**< Indicates the MSG_STRUCT_SEARCH_CONDITION */
-       MSG_STRUCT_REPORT_STATUS_INFO = 0x3800, /**< Indicates the MSG_STRUCT_REPORT_STATUS_INFO */
-
-       MSG_STRUCT_ADDRESS_INFO = 0x4000,                               /**< Indicates the MSG_STRUCT_ADDRESS_INFO */
-       MSG_STRUCT_SENDOPT = 0x4100,                                                    /**< Indicates the MSG_STRUCT_SENDOPT */
-       MSG_STRUCT_MMS_SENDOPT = 0x4200,                                /**< Indicates the MSG_STRUCT_MMS_SENDOPT */
-       MSG_STRUCT_SMS_SENDOPT = 0x4300,                                /**< Indicates the MSG_STRUCT_SMS_SENDOPT */
-       MSG_STRUCT_REJECT_MSG_INFO = 0x4400,                    /**< Indicates the MSG_STRUCT_REJECT_MSG_INFO */
-       MSG_STRUCT_REQUEST_INFO = 0x4500,                               /**< Indicates the MSG_STRUCT_REQUEST_INFO */
-       MSG_STRUCT_SENT_STATUS_INFO = 0x4600,                           /**< Indicates the MSG_STRUCT_SENT_STATUS_INFO */
-       MSG_STRUCT_PUSH_CONFIG_INFO = 0x4700,                           /**< Indicates the MSG_STRUCT_PUSH_CONFIG_INFO */
-       MSG_STRUCT_CB_MSG = 0x4800,                                             /**< Indicates the MSG_STRUCT_CB_MSG */
-};
-
+       MSG_STRUCT_FILTER = 0X0000,                             /**< Indicates the MSG_STRUCT_FILTER */
+
+       MSG_STRUCT_MESSAGE_INFO = 0x0200,                       /**< Indicates the MSG_STRUCT_MESSAGE_INFO */
+       MSG_STRUCT_THREAD_INFO = 0x0300,                        /**< Indicates the MSG_STRUCT_THREAD_INFO*/
+       MSG_STRUCT_CONV_INFO = 0x0400,                          /**< Indicates the MSG_STRUCT_CONV_INFO*/
+       MSG_STRUCT_MMS = 0x0500,                                /**< Indicates the MSG_STRUCT_MMS */
+       MSG_STRUCT_MMS_PAGE = 0x0600,                           /**< Indicates the MSG_STRUCT_MMS_PAGE */
+       MSG_STRUCT_MMS_MEDIA = 0x0700,                          /**< Indicates the MSG_STRUCT_MMS_MEDIA */
+       MSG_STRUCT_MMS_ATTACH = 0x0800,                         /**< Indicates the MSG_STRUCT_MMS_ATTACH */
+       MSG_STRUCT_MMS_REGION = 0x0900,                         /**< Indicates the MSG_STRUCT_MMS_REGION */
+       MSG_STRUCT_MMS_TRANSITION = 0x0a00,                     /**< Indicates the MSG_STRUCT_MMS_TRANSITION */
+       MSG_STRUCT_MMS_META = 0x0b00,                           /**< Indicates the MSG_STRUCT_MMS_META */
+       MSG_STRUCT_MMS_SMIL_TEXT = 0x0c00,                      /**< Indicates the MSG_STRUCT_MMS_SMIL_TEXT */
+       MSG_STRUCT_MMS_SMIL_AVI = 0x0d00,                       /**< Indicates the MSG_STRUCT_MMS_SMIL_AVI */
+
+       MSG_STRUCT_SETTING_SMSC_OPT = 0x2000,                   /**< Indicates the MSG_STRUCT_SETTING_SMSC_OPT */
+       MSG_STRUCT_SETTING_SMSC_INFO = 0x2100,                  /**< Indicates the MSG_STRUCT_SETTING_SMSC_INFO */
+       MSG_STRUCT_SETTING_CB_OPT = 0x2200,                     /**< Indicates the MSG_STRUCT_SETTING_CB_OPT */
+       MSG_STRUCT_SETTING_CB_CHANNEL_INFO = 0x2300,            /**< Indicates the MSG_STRUCT_CB_CHANNEL_INFO */
+       MSG_STRUCT_SETTING_SMS_SEND_OPT = 0x2400,               /**< Indicates the MSG_STRUCT_SETTING_SMS_SEND_OPT */
+       MSG_STRUCT_SETTING_MMS_SEND_OPT = 0x2500,               /**< Indicates the MSG_STRUCT_SETTING_MMS_SEND_OPT */
+       MSG_STRUCT_SETTING_MMS_RECV_OPT = 0x2600,               /**< Indicates the MSG_STRUCT_SETTING_MMS_RECV_OPT */
+       MSG_STRUCT_SETTING_PUSH_MSG_OPT = 0x2700,               /**< Indicates the MSG_STRUCT_SETTING_PUSH_MSG_OPT */
+       MSG_STRUCT_SETTING_VOICE_MSG_OPT = 0x2800,              /**< Indicates the MSG_STRUCT_SETTING_VOICE_MSG_OPT */
+       MSG_STRUCT_SETTING_GENERAL_OPT = 0x2900,                /**< Indicates the MSG_STRUCT_SETTING_GENERAL_OPT */
+
+       MSG_STRUCT_SETTING_MSGSIZE_OPT = 0x2c00,                /**< Indicates the MSG_STRUCT_SETTING_MSGSIZE_OPT */
+
+
+       MSG_STRUCT_SYNCML_INFO = 0x3100,                        /**< Indicates the MSG_STRUCT_SYNCML_INFO */
+       MSG_STRUCT_COUNT_INFO = 0x3200,                         /**< Indicates the MSG_STRUCT_COUNT_INFO */
+       MSG_STRUCT_THREAD_COUNT_INFO = 0x3300,                  /**< Indicates the MSG_STRUCT_THREAD_COUNT_INFO */
+       MSG_STRUCT_THREAD_LIST_INDEX = 0x3400,                  /**< Indicates the MSG_STRUCT_THREAD_LIST_INDEX */
+       MSG_STRUCT_SORT_RULE = 0x3500,                          /**< Indicates the MSG_STRUCT_SORT_RULE */
+       MSG_STRUCT_FOLDER_INFO = 0x3600,                        /**< Indicates the MSG_STRUCT_FOLDER_INFO */
+       MSG_STRUCT_SEARCH_CONDITION = 0x3700,                   /**< Indicates the MSG_STRUCT_SEARCH_CONDITION */
+       MSG_STRUCT_REPORT_STATUS_INFO = 0x3800,                 /**< Indicates the MSG_STRUCT_REPORT_STATUS_INFO */
+       MSG_STRUCT_MSG_LIST_CONDITION = 0x3900,                 /**< Indicates the MSG_LIST_CONDITION  */
+
+       MSG_STRUCT_ADDRESS_INFO = 0x4000,                       /**< Indicates the MSG_STRUCT_ADDRESS_INFO */
+       MSG_STRUCT_SENDOPT = 0x4100,                            /**< Indicates the MSG_STRUCT_SENDOPT */
+       MSG_STRUCT_MMS_SENDOPT = 0x4200,                        /**< Indicates the MSG_STRUCT_MMS_SENDOPT */
+       MSG_STRUCT_SMS_SENDOPT = 0x4300,                        /**< Indicates the MSG_STRUCT_SMS_SENDOPT */
+       MSG_STRUCT_REJECT_MSG_INFO = 0x4400,                    /**< Indicates the MSG_STRUCT_REJECT_MSG_INFO */
+       MSG_STRUCT_REQUEST_INFO = 0x4500,                       /**< Indicates the MSG_STRUCT_REQUEST_INFO */
+       MSG_STRUCT_SENT_STATUS_INFO = 0x4600,                   /**< Indicates the MSG_STRUCT_SENT_STATUS_INFO */
+       MSG_STRUCT_PUSH_CONFIG_INFO = 0x4700,                   /**< Indicates the MSG_STRUCT_PUSH_CONFIG_INFO */
+       MSG_STRUCT_CB_MSG = 0x4800,                             /**< Indicates the MSG_STRUCT_CB_MSG */
+
+       MSG_STRUCT_TRANSLATION_INFO = 0x4900,                   /**< Indicates the MSG_STRUCT_TRANSLATION_SETTING */
+
+       MSG_STRUCT_MULTIPART_INFO = 0x4a00,                     /**< Indicates the MSG_STRUCT_MULTIPART_INFO */
+};
+
+/**
+ * @brief  Enumeration for the values of message detail information. \n
+ *         This enum is used as member of #msg_struct_t for MSG_STRUCT_MESSAGE_INFO.
+ */
 enum _MSG_MESSAGE_INFO_E_ {
-       MSG_MESSAGE_ID_INT = MSG_STRUCT_MESSAGE_INFO+1,         /**< Indicates the message ID of this message. */
-       MSG_MESSAGE_THREAD_ID_INT,                              /**< Indicates the thread ID. */
-       MSG_MESSAGE_FOLDER_ID_INT,                              /**< Indicates the folder ID. see enum _MSG_FOLDER_TYPE_E */
-       MSG_MESSAGE_TYPE_INT,                           /**< Indicates the message type. See enum _MSG_MESSAGE_TYPE_E */
-       MSG_MESSAGE_CLASS_TYPE_INT,                             /**< Message class type. See enum _MSG_CLASS_TYPE_E */
-       MSG_MESSAGE_STORAGE_ID_INT,                             /**< Indicates where the message is saved. see enum _MSG_STORAGE_ID_E*/
-       MSG_MESSAGE_ADDR_LIST_STRUCT,                           /**< Indicates the address information list. */
-       MSG_MESSAGE_REPLY_ADDR_STR,                             /**< Indicates the reply address. */
-       MSG_MESSAGE_SUBJECT_STR,                                /**< Indicates the message subject. */
-       MSG_MESSAGE_DISPLAY_TIME_INT,                           /**< Indicates the display time related to the specific operation. */
-       MSG_MESSAGE_NETWORK_STATUS_INT,                         /**< Indicates the network status of the message. See enum _MSG_NETWORK_STATUS_E */
-       MSG_MESSAGE_ENCODE_TYPE_INT,                            /**< Indicates the string encoding type. See enum _MSG_ENCODE_TYPE_E */
-       MSG_MESSAGE_READ_BOOL,                                  /**< Indicates whether the message is read or not. */
-       MSG_MESSAGE_PROTECTED_BOOL,                             /**< Indicates whether the message is protected or not. */
-       MSG_MESSAGE_BACKUP_BOOL,                                /**< Indicates whether the message was restored from PC. */
-       MSG_MESSAGE_PRIORITY_INT,                               /**< Indicates the priority of the message. See enum _MSG_PRIORITY_TYPE_E */
-       MSG_MESSAGE_DIRECTION_INT,                              /**< Indicates whether the message is MO or MT, affecting address. See enum _MSG_DIRECTION_TYPE_E */
-       MSG_MESSAGE_PORT_VALID_BOOL,                            /**< Indicates whether port information is used or not. */
-       MSG_MESSAGE_DEST_PORT_INT,                              /**< Recipient port number, not greater than 16 bit */
-       MSG_MESSAGE_SRC_PORT_INT,                               /**< Sender port number, not greater than 16 bit */
-       MSG_MESSAGE_ATTACH_COUNT_INT,                           /**< Indicates the count of attached files in mms. */
-       MSG_MESSAGE_THUMBNAIL_PATH_STR,                         /**< Indicates the thumbnail path of message. */
-       MSG_MESSAGE_DATA_SIZE_INT,                              /**< Indicates the data size. The unit is byte. */
-       MSG_MESSAGE_SMS_DATA_STR,                               /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
-       MSG_MESSAGE_MMS_TEXT_STR,
-};
-
+       MSG_MESSAGE_ID_INT = MSG_STRUCT_MESSAGE_INFO+1,     /**< Indicates the message ID of this message. */
+       MSG_MESSAGE_THREAD_ID_INT,                          /**< Indicates the thread ID. */
+       MSG_MESSAGE_FOLDER_ID_INT,                          /**< Indicates the folder ID. See enum _MSG_FOLDER_ID_E */
+       MSG_MESSAGE_TYPE_INT,                               /**< Indicates the message type. See enum _MSG_MESSAGE_TYPE_E */
+       MSG_MESSAGE_CLASS_TYPE_INT,                         /**< Indicates the message class type. See enum _MSG_CLASS_TYPE_E */
+       MSG_MESSAGE_STORAGE_ID_INT,                         /**< Indicates where the message is saved. See enum _MSG_STORAGE_ID_E*/
+       MSG_MESSAGE_ADDR_LIST_STRUCT,                       /**< Indicates the address information list. **DEPRECATED** */
+       MSG_MESSAGE_REPLY_ADDR_STR,                         /**< Indicates the reply address. */
+       MSG_MESSAGE_SUBJECT_STR,                            /**< Indicates the message subject. */
+       MSG_MESSAGE_DISPLAY_TIME_INT,                       /**< Indicates the display time related to the specific operation. */
+       MSG_MESSAGE_NETWORK_STATUS_INT,                     /**< Indicates the network status of the message. See enum _MSG_NETWORK_STATUS_E */
+       MSG_MESSAGE_ENCODE_TYPE_INT,                        /**< Indicates the string encoding type. See enum _MSG_ENCODE_TYPE_E */
+       MSG_MESSAGE_READ_BOOL,                              /**< Indicates whether the message is read or not. */
+       MSG_MESSAGE_PROTECTED_BOOL,                         /**< Indicates whether the message is protected or not. */
+       MSG_MESSAGE_BACKUP_BOOL,                            /**< Indicates whether the message was restored from PC. */
+       MSG_MESSAGE_PRIORITY_INT,                           /**< Indicates the priority of the message. See enum _MSG_PRIORITY_TYPE_E */
+       MSG_MESSAGE_DIRECTION_INT,                          /**< Indicates whether the message is MO or MT, affecting address. See enum _MSG_DIRECTION_TYPE_E */
+       MSG_MESSAGE_PORT_VALID_BOOL,                        /**< Indicates whether port information is used or not. */
+       MSG_MESSAGE_DEST_PORT_INT,                          /**< Indicates the recipient port number, not greater than 16 bit */
+       MSG_MESSAGE_SRC_PORT_INT,                           /**< Indicates the sender port number, not greater than 16 bit */
+       MSG_MESSAGE_ATTACH_COUNT_INT,                       /**< Indicates the count of attached files in MMS. */
+       MSG_MESSAGE_THUMBNAIL_PATH_STR,                     /**< Indicates the thumbnail path of message. */
+       MSG_MESSAGE_DATA_SIZE_INT,                          /**< Indicates the data size. The unit is byte. */
+       MSG_MESSAGE_SMS_DATA_STR,                           /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
+       MSG_MESSAGE_MMS_TEXT_STR,                           /**< Indicates the text part of MMS message payload. default character encoding is UTF-8  */
+       MSG_MESSAGE_ADDR_LIST_HND,                          /**< Indicates the address information list. */
+       MSG_MESSAGE_REPLACE_BOOL,                           /**< Indicates whether the message is replace or not */
+       MSG_MESSAGE_SIM_INDEX_INT,                          /**< Indicates the sim index */
+       MSG_MESSAGE_INFO_MAX,                               /**< Placeholder for max value of this enum*/
+};
+
+/**
+ *  @brief  Enumeration for the values of message filter information. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_FILTER.
+ */
 enum MSG_FILTER_INFO_E {
-       MSG_FILTER_ID_INT = MSG_STRUCT_FILTER+1,                /**< Indicates the filter ID. */
-       MSG_FILTER_TYPE_INT,                                    /**< Indicates the filter type. See enum _MSG_FILTER_TYPE_E */
-       MSG_FILTER_VALUE_STR,                                   /**< The value of the filter. */
-       MSG_FILTER_ACTIVE_BOOL,                                 /**< Indicates the activation of the filter. */
+       MSG_FILTER_ID_INT = MSG_STRUCT_FILTER+1,        /**< Indicates the filter ID. */
+       MSG_FILTER_TYPE_INT,                            /**< Indicates the filter type. See enum _MSG_FILTER_TYPE_E */
+       MSG_FILTER_VALUE_STR,                           /**< Indicates the value of the filter. */
+       MSG_FILTER_ACTIVE_BOOL,                         /**< Indicates the activation of the filter. */
 };
 
+/**
+ *  @brief  Enumeration for the values of thread information. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_THREAD_INFO.
+ */
 enum MSG_STRUCT_THREAD_INFO_E {
-       MSG_THREAD_ID_INT = MSG_STRUCT_THREAD_INFO+1,           /**< Indicates the message thread ID. */
-       MSG_THREAD_NAME_STR,                                    /**< Indicates the message thread name */
-       MSG_THREAD_MSG_TYPE_INT,                                /**< Indicates the message type. See enum _MSG_MESSAGE_TYPE_E  */
-       MSG_THREAD_MSG_DATA_STR,                                /**< The latest message text. */
-       MSG_THREAD_MSG_TIME_INT,                                /**< The latest message time */
-       MSG_THREAD_DIRECTION_INT,                               /**< The latest message direction See enum _MSG_DIRECTION_TYPE_E */
-       MSG_THREAD_UNREAD_COUNT_INT,                            /**< Indicates unread count of thread */
-       MSG_THREAD_SMS_COUNT_INT,                               /**< Indicates sms message count of thread */
-       MSG_THREAD_MMS_COUNT_INT,                               /**< Indicates mms message count of thread */
-       MSG_THREAD_PROTECTED_BOOL               /**< Indicates whether thread includes protected messages. */
-};
-
+       MSG_THREAD_ID_INT = MSG_STRUCT_THREAD_INFO+1,       /**< Indicates the message thread ID. */
+       MSG_THREAD_NAME_STR,                                /**< Indicates the message thread name */
+       MSG_THREAD_MSG_TYPE_INT,                            /**< Indicates the message type. See enum _MSG_MESSAGE_TYPE_E  */
+       MSG_THREAD_MSG_DATA_STR,                            /**< The latest message text. */
+       MSG_THREAD_MSG_TIME_INT,                            /**< The latest message time */
+       MSG_THREAD_DIRECTION_INT,                           /**< The latest message direction See enum _MSG_DIRECTION_TYPE_E */
+       MSG_THREAD_UNREAD_COUNT_INT,                        /**< Indicates unread count of thread */
+       MSG_THREAD_SMS_COUNT_INT,                           /**< Indicates SMS message count of thread */
+       MSG_THREAD_MMS_COUNT_INT,                           /**< Indicates MMS message count of thread */
+       MSG_THREAD_PROTECTED_BOOL,                          /**< Indicates whether thread includes protected message. */
+       MSG_THREAD_DRAFT_BOOL,                              /**< Indicates whether thread includes draft message. */
+       MSG_THREAD_SEND_FAILED_BOOL,                        /**< Indicates whether thread includes  send failed message. */
+       MSG_THREAD_SENDING_BOOL,                            /**< Indicates whether thread includes  sending message. */
+       MSG_THREAD_TRANSLATION_BOOL,                        /**< Indicates whether s-translation is used or not. */
+       MSG_THREAD_TRANSLATION_SENDER_LANG_INT,             /**< Indicates sender language. */
+       MSG_THREAD_TRANSLATION_RECEIVER_LANG_INT,           /**< Indicates receiver language. */
+       MSG_THREAD_TRANSLATION_RECEIVE_ONLY_BOOL,           /**< Indicates whether only the receiving message applies the s-translation. */
+       MSG_THREAD_TRANSLATION_INCLUDE_ORGMSG_BOOL,         /**< Indicates whether the original message is included. */
+       MSG_THREAD_LAST_MSG_ID_INT,                         /**< Indicates the last message ID of this thread. */
+       MSG_THREAD_MSG_TAG_TYPE_INT                         /**< Indicates the conversation tag type. */
+};
+
+/**
+ *  @brief  Enumeration for the values of translation information. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_TRANSLATION_INFO.
+ */
+enum MSG_STRUCT_TRANSLATION_INFO_E {
+       MSG_TRANSLATION_BOOL = MSG_STRUCT_TRANSLATION_INFO + 1,     /**< Indicates whether s-translation is used or not. */
+       MSG_TRANSLATION_SENDER_LANG_INT,                            /**< Indicates sender language. */
+       MSG_TRANSLATION_RECEIVER_LANG_INT,                          /**< Indicates receiver language. */
+       MSG_TRANSLATION_RECEIVE_ONLY_BOOL,                          /**< Indicates whether only the receiving message applies the s-translation. */
+       MSG_TRANSLATION_INCLUDE_ORGMSG_BOOL,                        /**< Indicates whether the original message is included. */
+};
+
+/**
+ *  @brief  Enumeration for the values of conversation information. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_CONV_INFO.
+ */
 enum MSG_STRUCT_CONV_INFO_E {
-       MSG_CONV_MSG_ID_INT = MSG_STRUCT_CONV_INFO+1,           /**< Indicates the message ID of this message. */
-       MSG_CONV_MSG_THREAD_ID_INT,                             /**< Indicates the thread ID. */
-       MSG_CONV_MSG_TYPE_INT,                                                                                                  /**< Indicates the message type. See enum _MSG_MESSAGE_TYPE_E */
-       MSG_CONV_MSG_FOLDER_ID_INT,                             /**< Indicates the folder ID. see enum _MSG_FOLDER_TYPE_E */
-       MSG_CONV_MSG_STORAGE_ID_INT,                                                                            /**< Indicates where the message is saved. see enum _MSG_STORAGE_ID_E*/
-       MSG_CONV_MSG_SUBJECT_STR,                                                                                       /**< Indicates the message subject. */
-       MSG_CONV_MSG_DISPLAY_TIME_INT,                                                                  /**< Indicates the display time related to the specific operation. */
-       MSG_CONV_MSG_SCHEDULED_TIME_INT,                                                                /**< Indicates the time to send scheduled message. */
-       MSG_CONV_MSG_NETWORK_STATUS_INT,                                                        /**< Indicates the network status of the message. See enum _MSG_NETWORK_STATUS_E */
-       MSG_CONV_MSG_READ_BOOL,                                                                                         /**< Indicates whether the message is read or not. */
-       MSG_CONV_MSG_PROTECTED_BOOL,                                                                    /**< Indicates whether the message is protected or not. */
-       MSG_CONV_MSG_DIRECTION_INT,                                                                                     /**< Indicates whether the message is MO or MT, affecting address. See enum _MSG_DIRECTION_TYPE_E */
-       MSG_CONV_MSG_PAGE_COUNT_INT,                                                                    /**< Indicates the count of pages in mms. */
-       MSG_CONV_MSG_ATTACH_COUNT_INT,                                                                  /**< Indicates the count of attached files in mms. */
-       MSG_CONV_MSG_ATTACH_NAME_STR,                                                           /**< Indicates the attached file name of message. */
-       MSG_CONV_MSG_AUDIO_NAME_STR,                                                                    /**< Indicates the audio file name of message. */
-       MSG_CONV_MSG_IMAGE_THUMB_PATH_STR,                                              /**< Indicates the image thumbnail path of message. */
-       MSG_CONV_MSG_VIDEO_THUMB_PATH_STR,                                              /**< Indicates the video thumbnail path of message. */
-       MSG_CONV_MSG_TEXT_SIZE_INT,                                                                                     /**< Indicates the data size. The unit is byte. */
-       MSG_CONV_MSG_TEXT_STR                                                                                                   /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
-};
-
+       MSG_CONV_MSG_ID_INT = MSG_STRUCT_CONV_INFO+1,       /**< Indicates the message ID of this message. */
+       MSG_CONV_MSG_THREAD_ID_INT,                         /**< Indicates the thread ID. */
+       MSG_CONV_MSG_TYPE_INT,                              /**< Indicates the message type. See enum _MSG_MESSAGE_TYPE_E */
+       MSG_CONV_MSG_FOLDER_ID_INT,                         /**< Indicates the folder ID. See enum _MSG_FOLDER_TYPE_E */
+       MSG_CONV_MSG_STORAGE_ID_INT,                        /**< Indicates where the message is saved. See enum _MSG_STORAGE_ID_E*/
+       MSG_CONV_MSG_SUBJECT_STR,                           /**< Indicates the message subject. */
+       MSG_CONV_MSG_DISPLAY_TIME_INT,                      /**< Indicates the display time related to the specific operation. */
+       MSG_CONV_MSG_SCHEDULED_TIME_INT,                    /**< Indicates the time to send scheduled message. */
+       MSG_CONV_MSG_NETWORK_STATUS_INT,                    /**< Indicates the network status of the message. See enum _MSG_NETWORK_STATUS_E */
+       MSG_CONV_MSG_READ_BOOL,                             /**< Indicates whether the message is read or not. */
+       MSG_CONV_MSG_PROTECTED_BOOL,                        /**< Indicates whether the message is protected or not. */
+       MSG_CONV_MSG_DIRECTION_INT,                         /**< Indicates whether the message is MO or MT, affecting address. See enum _MSG_DIRECTION_TYPE_E */
+       MSG_CONV_MSG_PAGE_COUNT_INT,                        /**< Indicates the count of pages in MMS. */
+       MSG_CONV_MSG_ATTACH_COUNT_INT,                      /**< Indicates the count of attached files in MMS. */
+       MSG_CONV_MSG_ATTACH_NAME_STR,                       /**< Indicates the attached file name of message. */
+       MSG_CONV_MSG_AUDIO_NAME_STR,                        /**< Indicates the audio file name of message. */
+       MSG_CONV_MSG_IMAGE_THUMB_PATH_STR,                  /**< Indicates the image thumbnail path of message. */
+       MSG_CONV_MSG_VIDEO_THUMB_PATH_STR,                  /**< Indicates the video thumbnail path of message. */
+       MSG_CONV_MSG_TEXT_SIZE_INT,                         /**< Indicates the data size. The unit is byte. */
+       MSG_CONV_MSG_TEXT_STR,                              /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
+       MSG_CONV_MSG_TCS_BC_LEVEL_INT,                      /**< Indicates the Behavior Level of malware. @c -1 is None*/
+       MSG_CONV_MSG_1ST_MEDIA_PATH_STR,                    /**< Indicates the First Media path of MMS */
+       MSG_CONV_MSG_MULTIPART_HND,
+       MSG_CONV_MSG_SIM_INDEX_INT,                         /**< Indicates the sim index */
+
+};
+
+/**
+ *  @brief  Enumeration for the values of setting for SMSC options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_SMSC_OPT.
+ */
 enum _MSG_STRUCT_SETTING_SMSC_OPT_E {
-       MSG_SMSC_SELECTED_ID_INT = MSG_STRUCT_SETTING_SMSC_OPT+1,
-       MSG_SMSC_LIST_STRUCT
+       MSG_SMSC_SELECTED_ID_INT = MSG_STRUCT_SETTING_SMSC_OPT+1,       /**< Indicates Selected SMSC index option */
+       MSG_SMSC_LIST_STRUCT,                                           /**< Indicates SMSC data information list option*/
+       MSG_SMSC_LIST_INDEX_INT,                                        /**< Indicates SMSC index option for Updating information */
+       MSG_SMSC_LIST_SIM_INDEX_INT                                     /**< Indicates the sim index */
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for SMSC informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_SMSC_INFO.
+ */
 enum _MSG_STRUCT_SETTING_SMSC_INFO_E {
-       MSG_SMSC_ADDR_TON_INT = MSG_STRUCT_SETTING_SMSC_INFO+1,         /**< Type of number. See enum _MSG_SMS_TON_E */
-       MSG_SMSC_ADDR_NPI_INT,                                  /**< Numbering plan ID. See enum _MSG_SMS_NPI_E */
-       MSG_SMSC_ADDR_STR,                                      /**< SMSC address */
-       MSG_SMSC_NAME_STR,                                      /**< SMSC name */
-       MSG_SMSC_PID_INT,                                       /**< Protocol idendifier See enum _MSG_SMS_PID_E */
-       MSG_SMSC_VAL_PERIOD_INT                                 /**< Validity period value. See enum _MSG_VAL_PERIOD_E*/
+       MSG_SMSC_ADDR_TON_INT = MSG_STRUCT_SETTING_SMSC_INFO+1,     /**< Type of number. See enum _MSG_SMS_TON_E */
+       MSG_SMSC_ADDR_NPI_INT,                                      /**< Numbering plan ID. See enum _MSG_SMS_NPI_E */
+       MSG_SMSC_ADDR_STR,                                          /**< SMSC address */
+       MSG_SMSC_NAME_STR,                                          /**< SMSC name */
+       MSG_SMSC_PID_INT,                                           /**< Protocol idendifier See enum _MSG_SMS_PID_E */
+       MSG_SMSC_VAL_PERIOD_INT                                     /**< Validity period value. See enum _MSG_VAL_PERIOD_E*/
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for CB channel options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_CB_OPT.
+ */
 enum _MSG_STRUCT_CB_OPT_E {
-       MSG_CB_RECEIVE_BOOL = MSG_STRUCT_SETTING_CB_OPT+1,              /**< Indicates whether the CB message is received or not. */
-       MSG_CB_MAX_SIM_COUNT_INT,                               /**< Indicates the number of channels which can be stored in SIM. */
-       MSG_CB_CHANNEL_LIST_STRUCT,                             /**< Indicates the cell broadcasting channel information. */
-       MSG_CB_LANGUAGE_TYPE_ALL_BOOL,
-       MSG_CB_LANGUAGE_TYPE_ENG_BOOL,                  /**< CB message English  */
-       MSG_CB_LANGUAGE_TYPE_GER_BOOL,                  /**< CB message Germany */
-       MSG_CB_LANGUAGE_TYPE_FRE_BOOL,                  /**< CB message France */
-       MSG_CB_LANGUAGE_TYPE_ITA_BOOL,                  /**< CB message Italy */
-       MSG_CB_LANGUAGE_TYPE_NED_BOOL,                  /**< CB message Netherland */
-       MSG_CB_LANGUAGE_TYPE_SPA_BOOL,                  /**< CB message Spain */
-       MSG_CB_LANGUAGE_TYPE_POR_BOOL,                  /**< CB message Portugal */
-       MSG_CB_LANGUAGE_TYPE_SWE_BOOL,                  /**< CB message Sweden */
-       MSG_CB_LANGUAGE_TYPE_TUR_BOOL,                  /**< CB message Turkey */
-};
-
+       MSG_CB_RECEIVE_BOOL = MSG_STRUCT_SETTING_CB_OPT+1,      /**< Indicates whether the CB message is received or not. */
+       MSG_CB_MAX_SIM_COUNT_INT,                               /**< Indicates the number of channels which can be stored in SIM. */
+       MSG_CB_CHANNEL_LIST_STRUCT,                             /**< Indicates the cell broadcasting channel information. */
+       MSG_CB_LANGUAGE_TYPE_ALL_BOOL,                          /**< CB message all languages */
+       MSG_CB_LANGUAGE_TYPE_ENG_BOOL,                          /**< CB message English  */
+       MSG_CB_LANGUAGE_TYPE_GER_BOOL,                          /**< CB message Germany */
+       MSG_CB_LANGUAGE_TYPE_FRE_BOOL,                          /**< CB message France */
+       MSG_CB_LANGUAGE_TYPE_ITA_BOOL,                          /**< CB message Italy */
+       MSG_CB_LANGUAGE_TYPE_NED_BOOL,                          /**< CB message Netherland */
+       MSG_CB_LANGUAGE_TYPE_SPA_BOOL,                          /**< CB message Spain */
+       MSG_CB_LANGUAGE_TYPE_POR_BOOL,                          /**< CB message Portugal */
+       MSG_CB_LANGUAGE_TYPE_SWE_BOOL,                          /**< CB message Sweden */
+       MSG_CB_LANGUAGE_TYPE_TUR_BOOL,                          /**< CB message Turkey */
+       MSG_CB_SIM_INDEX_INT,                                   /**< Indicates the sim index */
+};
+
+/**
+ *  @brief  Enumeration for the values of setting for CB channel informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_CB_CHANNEL_INFO.
+ */
 enum _MSG_STRUCT_CB_CHANNEL_INFO_E {
-       MSG_CB_CHANNEL_ACTIVATE_BOOL = MSG_STRUCT_SETTING_CB_CHANNEL_INFO+1,    /**< Indicates whether the CB channel is activate or passive. */
-       MSG_CB_CHANNEL_ID_FROM_INT,                                             /**< Indicates the ID of a CB channel. */
-       MSG_CB_CHANNEL_ID_TO_INT,                                               /**< Indicates the ID of a CB channel. */
-       MSG_CB_CHANNEL_NAME_STR                                         /**< Indicates the name of a CB channel. */
+       MSG_CB_CHANNEL_ACTIVATE_BOOL = MSG_STRUCT_SETTING_CB_CHANNEL_INFO+1,    /**< Indicates whether the CB channel is activate or passive. */
+       MSG_CB_CHANNEL_ID_FROM_INT,                                             /**< Indicates the From ID of a CB channel. */
+       MSG_CB_CHANNEL_ID_TO_INT,                                               /**< Indicates the To ID of a CB channel. */
+       MSG_CB_CHANNEL_NAME_STR                                                 /**< Indicates the name of a CB channel. */
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for SMS sending options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_SMS_SEND_OPT.
+ */
 enum _MSG_STRUCT_SMS_SEND_OPT_E {
-       MSG_SMS_SENDOPT_ENCODE_TYPE_INT = MSG_STRUCT_SETTING_SMS_SEND_OPT+1,    /**< Indicates the string encoding type.  See enum _MSG_ENCODE_TYPE_E*/
-       MSG_SMS_SENDOPT_NETWORK_MODE_INT,                               /**< Indicates the network mode (CS/PS) to send SMS. See enum _MSG_SMS_NETWORK_MODE_E*/
-       MSG_SMS_SENDOPT_REPLY_PATH_BOOL,                                /**< Indicates whether the SMS reply path is set or not. */
-       MSG_SMS_SENDOPT_DELIVERY_REPORT_BOOL,                           /**< Indicates whether the SMS delivery report will be sent or not. */
-       MSG_SMS_SENDOPT_SAVE_STORAGE_INT                                /**< Indicates the default storage to save SMS. See enum _MSG_SMS_SAVE_STORAGE_E */
+       MSG_SMS_SENDOPT_ENCODE_TYPE_INT = MSG_STRUCT_SETTING_SMS_SEND_OPT+1,  /**< Indicates the string encoding type.  See enum _MSG_ENCODE_TYPE_E*/
+       MSG_SMS_SENDOPT_NETWORK_MODE_INT,                                     /**< Indicates the network mode (CS/PS) to send SMS. See enum _MSG_SMS_NETWORK_MODE_E*/
+       MSG_SMS_SENDOPT_REPLY_PATH_BOOL,                                      /**< Indicates whether the SMS reply path is set or not. */
+       MSG_SMS_SENDOPT_DELIVERY_REPORT_BOOL,                                 /**< Indicates whether the SMS delivery report will be sent or not. */
+       MSG_SMS_SENDOPT_SAVE_STORAGE_INT                                      /**< Indicates the default storage to save SMS. See enum _MSG_SMS_SAVE_STORAGE_E */
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for MMS sending options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_MMS_SEND_OPT.
+ */
 enum _MSG_STRUCT_MMS_SEND_OPT_E {
-       MSG_MMS_SENDOPT_CLASS_TYPE_INT = MSG_STRUCT_SETTING_MMS_SEND_OPT+1,             /**< Indicates the class type of message.  See enum _MSG_MMS_MSG_CLASS_TYPE_E */
-       MSG_MMS_SENDOPT_PRIORITY_TYPE_INT,                                      /**< Indicates the priority of the message. See enum _MSG_PRIORITY_TYPE_E */
-       MSG_MMS_SENDOPT_EXPIRY_TIME_INT,                                        /**< Indicates the time when the message is to be removed from the MMSC. See enum _MSG_MMS_EXPIRY_TIME_E */
-       MSG_MMS_SENDOPT_DELIVERY_TIME_INT,                                      /**< Indicates the message transmission time which is set in the MMSC. See enum _MSG_MMS_DELIVERY_TIME_E */
-       MSG_MMS_SENDOPT_CUSTOM_DELIVERY_TIME_INT,                               /**< Indicates the message transmission time which is set in the MMSC. */
-       MSG_MMS_SENDOPT_SENDER_VISIBILITY_BOOL,                                 /**< Indicates whether the address is hidden or not. */
-       MSG_MMS_SENDOPT_DELIVERY_REPORT_BOOL,                                   /**< Indicates whether the delivery report will be sent or not. */
-       MSG_MMS_SENDOPT_READ_REPLY_BOOL,                                        /**< Indicates whether the read report will be sent or not. */
-       MSG_MMS_SENDOPT_KEEP_COPY_BOOL,                                         /**< Indicates whether the message copy is kept or not. */
-       MSG_MMS_SENDOPT_BODY_REPLYING_BOOL,                                     /**< Indicates whether the body is included when replying or not. */
-       MSG_MMS_SENDOPT_HIDE_RECIPIENTS_BOOL,                                   /**< Indicates whether the recipients are hidden or not. */
-       MSG_MMS_SENDOPT_REPLY_CHARGING_INT,                                     /**< Indicates the reply charging type of message. See enum _MSG_MMS_REPLY_CHARGING_TYPE_E */
-       MSG_MMS_SENDOPT_REPLY_CHARGING_DEADLINE_INT,                            /**< Indicates the deadline for replying charging. is set in the MMSC. */
-       MSG_MMS_SENDOPT_REPLY_CHARGING_SIZE_INT,                                /**< Indicates the reply charging size. */
-       MSG_MMS_SENDOPT_CREATION_MODE_INT                                       /**< Indicates the creation mode of MMS. See enum _MSG_MMS_CREATION_MODE_E */
-};
-
+       MSG_MMS_SENDOPT_CLASS_TYPE_INT = MSG_STRUCT_SETTING_MMS_SEND_OPT+1,  /**< Indicates the class type of message.  See enum _MSG_MMS_MSG_CLASS_TYPE_E */
+       MSG_MMS_SENDOPT_PRIORITY_TYPE_INT,                                   /**< Indicates the priority of the message. See enum _MSG_PRIORITY_TYPE_E */
+       MSG_MMS_SENDOPT_EXPIRY_TIME_INT,                                     /**< Indicates the time when the message is to be removed from the MMSC. See enum _MSG_MMS_EXPIRY_TIME_E */
+       MSG_MMS_SENDOPT_DELIVERY_TIME_INT,                                   /**< Indicates the message transmission time which is set in the MMSC. See enum _MSG_MMS_DELIVERY_TIME_E */
+       MSG_MMS_SENDOPT_CUSTOM_DELIVERY_TIME_INT,                            /**< Indicates the message transmission time which is set in the MMSC. */
+       MSG_MMS_SENDOPT_SENDER_VISIBILITY_BOOL,                              /**< Indicates whether the address is hidden or not. */
+       MSG_MMS_SENDOPT_DELIVERY_REPORT_BOOL,                                /**< Indicates whether the delivery report will be sent or not. */
+       MSG_MMS_SENDOPT_READ_REPLY_BOOL,                                     /**< Indicates whether the read report will be sent or not. */
+       MSG_MMS_SENDOPT_KEEP_COPY_BOOL,                                      /**< Indicates whether the message copy is kept or not. */
+       MSG_MMS_SENDOPT_BODY_REPLYING_BOOL,                                  /**< Indicates whether the body is included when replying or not. */
+       MSG_MMS_SENDOPT_HIDE_RECIPIENTS_BOOL,                                /**< Indicates whether the recipients are hidden or not. */
+       MSG_MMS_SENDOPT_REPLY_CHARGING_INT,                                  /**< Indicates the reply charging type of message. See enum _MSG_MMS_REPLY_CHARGING_TYPE_E */
+       MSG_MMS_SENDOPT_REPLY_CHARGING_DEADLINE_INT,                         /**< Indicates the deadline for replying charging. is set in the MMSC. */
+       MSG_MMS_SENDOPT_REPLY_CHARGING_SIZE_INT,                             /**< Indicates the reply charging size. */
+       MSG_MMS_SENDOPT_CREATION_MODE_INT                                    /**< Indicates the creation mode of MMS. See enum _MSG_MMS_CREATION_MODE_E */
+};
+
+/**
+ *  @brief  Enumeration for the values of setting for MMS receiving options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_MMS_RECV_OPT.
+ */
 enum _MSG_STRUCT_MMS_RECV_OPT_E {
-       MSG_MMS_RECVOPT_HOME_RETRIEVE_TYPE_INT = MSG_STRUCT_SETTING_MMS_RECV_OPT+1,     /**< Indicates the retrieve type for MMS home network. See enum _MSG_MMS_HOME_RETRIEVE_TYPE_E */
-       MSG_MMS_RECVOPT_ABROAD_RETRIEVE_TYPE_INT,                               /**< Indicates the retrieve type for MMS abroad network. See enum _MSG_MMS_ABROAD_RETRIEVE_TYPE_E */
-       MSG_MMS_RECVOPT_READ_REPORT_BOOL,                                       /**< Indicates whether the read report will be sent or not. */
-       MSG_MMS_RECVOPT_DELIVERY_REPORT_BOOL,                                   /**< Indicates whether the delivery report will be sent or not. */
-       MSG_MMS_RECVOPT_REJECT_UNKNOWN_BOOL,                                    /**< Indicates whether unknown addresses are rejected or not. */
-       MSG_MMS_RECVOPT_REJECT_ADVERTISEMENT_BOOL                               /**< Indicates whether advertisement is rejected or not. */
+       MSG_MMS_RECVOPT_HOME_RETRIEVE_TYPE_INT = MSG_STRUCT_SETTING_MMS_RECV_OPT+1, /**< Indicates the retrieve type for MMS home network. See enum _MSG_MMS_HOME_RETRIEVE_TYPE_E */
+       MSG_MMS_RECVOPT_ABROAD_RETRIEVE_TYPE_INT,                                   /**< Indicates the retrieve type for MMS abroad network. See enum _MSG_MMS_ABROAD_RETRIEVE_TYPE_E */
+       MSG_MMS_RECVOPT_READ_REPORT_BOOL,                                           /**< Indicates whether the read report will be sent or not. */
+       MSG_MMS_RECVOPT_DELIVERY_REPORT_BOOL,                                       /**< Indicates whether the delivery report will be sent or not. */
+       MSG_MMS_RECVOPT_REJECT_UNKNOWN_BOOL,                                        /**< Indicates whether unknown addresses are rejected or not. */
+       MSG_MMS_RECVOPT_REJECT_ADVERTISEMENT_BOOL                                   /**< Indicates whether advertisement is rejected or not. */
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for general options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_GENERAL_OPT.
+ */
 enum _MSG_STRUCT_GENERAL_OPT_E {
-       MSG_GENERAL_KEEP_COPY_BOOL = MSG_STRUCT_SETTING_GENERAL_OPT+1,                  /**< Indicates whether the SMS message copy is kept or not. */
-       MSG_GENERAL_ALERT_TONE_INT,                                             /**< Indicates the period of playing alert tone. See enum _MSG_ALERT_TONE_E */
-       MSG_GENERAL_AUTO_ERASE_BOOL                                             /**< Indicates whether the auto-erase option is enabled or not. */
+       MSG_GENERAL_KEEP_COPY_BOOL = MSG_STRUCT_SETTING_GENERAL_OPT+1,  /**< Indicates whether the SMS message copy is kept or not. */
+       MSG_GENERAL_ALERT_TONE_INT,                                     /**< Indicates the period of playing alert tone. See enum _MSG_ALERT_TONE_E */
+       MSG_GENERAL_AUTO_ERASE_BOOL,                                    /**< Indicates whether the auto-erase option is enabled or not. */
+       MSG_GENERAL_BLOCK_UNKNOWN_NUMBER_BOOL,                          /**< Indicates whether unknown sender message is blocked or not. */
+       MSG_GENERAL_SMS_LIMIT_CNT_INT,                                  /**< Indicates the count limitation of SMS messages in one conversation */
+       MSG_GENERAL_MMS_LIMIT_CNT_INT,                                  /**< Indicates the count limitation of MMS messages in one conversation */
+       MSG_GENERAL_MSG_NOTIFICATION_BOOL,                              /**< Indicates whether notification for incoming message is shown or not. */
+       MSG_GENERAL_MSG_VIBRATION_BOOL,                                 /**< Indicates whether vibration for incoming message is run or not. */
+       MSG_GENERAL_MSG_PREVIEW_BOOL,                                   /**< Indicates whether preview for incoming message is shown or not. */
+       MSG_GENERAL_RINGTONE_TYPE_INT,                                  /**< Indicates the message ringtone type. */
+       MSG_GENERAL_RINGTONE_PATH_STR,                                  /**< Indicates the message ringtone path */
+       MSG_GENERAL_MSG_SEARCH_TAGS_INT                                 /**< Indicates the tags to be enabled for search ex) MSG_MESSAGE_TAG_PRIMARY | MSG_MESSAGE_TAG_PROMOTION.  See enum _MSG_TAG_TYPE_E  */
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for push message options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_PUSH_MSG_OPT.
+ */
 enum _MSG_STRUCT_PUSH_MSG_OPT_E {
-       MSG_PUSHMSG_RECEIVE_BOOL = MSG_STRUCT_SETTING_PUSH_MSG_OPT+1,           /**< Indicates whether the push message is received or not. */
-       MSG_PUSHMSG_SERVICE_TYPE_INT                                    /**< Indicates the service type of a push message. See enum _MSG_PUSH_SERVICE_TYPE_E */
+       MSG_PUSHMSG_RECEIVE_BOOL = MSG_STRUCT_SETTING_PUSH_MSG_OPT+1,  /**< Indicates whether the push message is received or not. */
+       MSG_PUSHMSG_SERVICE_TYPE_INT                                   /**< Indicates the service type of a push message. See enum _MSG_PUSH_SERVICE_TYPE_E */
 };
 
+/**
+ *  @brief  Enumeration for the values of setting for voice message options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_VOICE_MSG_OPT.
+ */
 enum _MSG_STRUCT_VOICE_MSG_OPT_E {
-       MSG_VOICEMSG_ADDRESS_STR = MSG_STRUCT_SETTING_VOICE_MSG_OPT+1,          /**< Indicates the address for voice message. */
+       MSG_VOICEMSG_ADDRESS_STR = MSG_STRUCT_SETTING_VOICE_MSG_OPT+1,  /**< Indicates the address for voice message. */
+       MSG_VOICEMSG_ALPHA_ID_STR,                                      /**< Indicates the alpha id for voice message address. */
+       MSG_VOICEMSG_SIM_INDEX_INT                                      /**< Indicates the SIM index for voice message. */
 };
 
+
+/**
+ *  @brief  Enumeration for the values of setting for message size option. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SETTING_MSGSIZE_OPT.
+ */
 enum _MSG_STRUCT_MSGSISE_OPT_E {
-       MSG_MESSAGE_SIZE_INT = MSG_STRUCT_SETTING_MSGSIZE_OPT+1,                /**< Indicates the message size */
+       MSG_MESSAGE_SIZE_INT = MSG_STRUCT_SETTING_MSGSIZE_OPT+1,        /**< Indicates the message size */
 };
 
-//MSG_MMS_DATA
+/**
+ *  @brief  Enumeration for the values of MMS detail informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS.
+ */
 enum MSG_MMS_INFO_E {
-       MSG_MMS_PAGE_LIST_HND = MSG_STRUCT_MMS+1,                       /**< The pointer to SMIL pages list */
-       MSG_MMS_REGION_LIST_HND,                                        /**< The pointer to SMIL regions list */
-       MSG_MMS_ATTACH_LIST_HND,                                        /**< The pointer to attachment list */
-       MSG_MMS_TRANSITION_LIST_HND,                                    /**< The pointer to SMIL transitions list */
-       MSG_MMS_META_LIST_HND,                                          /**< The pointer to SMIL meta list */
-       MSG_MMS_ROOTLAYOUT_WIDTH_INT,                                   /**< Indicates the width of the root layout */
-       MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL,                          /**< Indicates the length is in percentage(%) or not */
-       MSG_MMS_ROOTLAYOUT_HEIGHT_INT,                                  /**< Indicates the height of the root layout */
-       MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL,                         /**< Indicates the length is in percentage(%) or not */
-       MSG_MMS_ROOTLAYOUT_BGCOLOR_INT,                                 /**< Indicates the background color of the root layout */
-       MSG_MMS_ROOTLAYOUT_BGCOLOR_BOOL,                                /**< Indicates the background color is set in the root layout */
-};
-
-//MSG_MMS_PAGE
+       MSG_MMS_PAGE_LIST_HND = MSG_STRUCT_MMS+1,       /**< The pointer to SMIL pages list */
+       MSG_MMS_REGION_LIST_HND,                        /**< The pointer to SMIL regions list */
+       MSG_MMS_ATTACH_LIST_HND,                        /**< The pointer to attachment list */
+       MSG_MMS_TRANSITION_LIST_HND,                    /**< The pointer to SMIL transitions list */
+       MSG_MMS_META_LIST_HND,                          /**< The pointer to SMIL meta list */
+       MSG_MMS_ROOTLAYOUT_WIDTH_INT,                   /**< Indicates the width of the root layout */
+       MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL,          /**< Indicates the length is in percentage(%) or not */
+       MSG_MMS_ROOTLAYOUT_HEIGHT_INT,                  /**< Indicates the height of the root layout */
+       MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL,         /**< Indicates the length is in percentage(%) or not */
+       MSG_MMS_ROOTLAYOUT_BGCOLOR_INT,                 /**< Indicates the background color of the root layout */
+       MSG_MMS_ROOTLAYOUT_BGCOLOR_BOOL,                /**< Indicates the background color is set in the root layout */
+       MSG_MMS_HEADER_BCC_ADDRESS_LIST_HND,            /**< The pointer to BCC address list */
+       MSG_MMS_HEADER_CC_ADDRESS_LIST_HND,             /**< The pointer to CC address list */
+       MSG_MMS_HEADER_CONTENT_LOCATION_STR,            /**< Indicates contentLocation in MMS header */
+       MSG_MMS_HEADER_CONTENT_TYPE_STR,                /**< Indicates szContentType in MMS header. ex) application/vnd.wap.multipart.related */
+       MSG_MMS_HEADER_DATE_INT,                        /**< Indicates date in MMS header */
+       MSG_MMS_HEADER_DELIVERY_REPORT_INT,             /**< Indicates X-Mms-Delivery-Report */
+       MSG_MMS_HEADER_DELIVERY_TIME_INT,               /**< Indicates X-Mms-Delivery-Time */
+       MSG_MMS_HEADER_EXPIRY_TIME_INT,                 /**< Indicates X-Mms-Expiry-Time */
+       MSG_MMS_HEADER_FROM_STR,                        /**< Indicates FROM address in header */
+       MSG_MMS_HEADER_MESSAGE_CLASS_INT,               /**< Indicates messageClassin in header. ex) Personal | Advertisement | Informational | Auto */
+       MSG_MMS_HEADER_MESSAGE_ID_STR,                  /**< Indicates messageID in header*/
+       MSG_MMS_HEADER_MESSAGE_TYPE_INT,                /**< Indicates MmsMsgTypein header. ex) sendreq */
+       MSG_MMS_HEADER_VERSION_INT,                     /**< Indicates mmsVersion in header. ex) 1.0 1.3 etc */
+       MSG_MMS_HEADER_SIZE_INT,                        /**< Indicates X-Mms-Message-Size */
+       MSG_MMS_HEADER_PRIORITY_INT,                    /**< Indicates _MSG_PRIORITY_TYPE_E in header: Low | Normal | High */
+       MSG_MMS_HEADER_READ_REPORT_INT,                 /**< Indicates X-Mms-Read-Report */
+       MSG_MMS_HEADER_HIDE_ADDRESS_INT,                /**< Indicates X-Mms-Sender-Visibility */
+       MSG_MMS_HEADER_MMS_STATUS_INT,                  /**< Indicates X-Mms-Status */
+       MSG_MMS_HEADER_TO_ADDRESS_LIST_HND,             /**< The pointer to 'TO' address list in header*/
+       MSG_MMS_HEADER_TR_ID_STR,                       /**< Indicates thread ID in header */
+       MSG_MMS_HEADER_CONTENT_CLASS_INT,               /**< Indicates contentClass in header. ex) text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich */
+       MSG_MMS_SMIL_MULTIPART_CONTENT_TYPE_STR,        /**< Indicates multipart content type in header*/
+       MSG_MMS_SMIL_MULTIPART_NAME_STR,                /**<Indicates multipart file name in header*/
+       MSG_MMS_SMIL_MULTIPART_FILEPATH_STR,            /**< Indicates multipart file path in header*/
+       MSG_MMS_SMIL_MULTIPART_CONTENT_ID_STR,          /**< Indicates multipart content id in header*/
+       MSG_MMS_SMIL_MULTIPART_CONTENT_LOCATION_STR,    /**< Indicates multipart content Location in header*/
+       MSG_MMS_MULTIPART_LIST_HND,                     /**< The pointer to MMS multipart list */
+       MSG_MMS_INFO_MAX,                               /**< Placeholder for max value of this enum */
+};
+
+/**
+ *  @brief  Enumeration for the values of MMS multipart informations. \n
+ *          This enum is used as member of #msg_struct_t for MMS_MULTIPART_DATA_S.
+ */
+enum _MSG_STRUCT_MULTIPART_INFO_E {
+       MSG_MMS_MULTIPART_CONTENT_TYPE_STR = MSG_STRUCT_MULTIPART_INFO+1,  /**< Indicates multipart content type */
+       MSG_MMS_MULTIPART_NAME_STR,                                        /**< Indicates multipart file name */
+       MSG_MMS_MULTIPART_FILEPATH_STR,                                    /**< Indicates multipart file path */
+       MSG_MMS_MULTIPART_CONTENT_ID_STR,                                  /**< Indicates mutipart content ID */
+       MSG_MMS_MULTIPART_CONTENT_LOCATION_STR,                            /**< Indicates multipart content Location */
+       MSG_MMS_MULTIPART_TCS_LEVEL_INT,                                   /**< Indicates detection of malware type */
+       MSG_MMS_MULTIPART_MALWARE_ALLOW_INT,                               /**< Indicates malware allowed */
+       MSG_MMS_MULTIPART_THUMBNAIL_FILEPATH_STR,                          /**< Indicates the thumbnail filepath */
+};
+
+/**
+ *  @brief  Enumeration for the values of MMS page informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_PAGE.
+ */
 enum MSG_MMS_PAGE_INFO_E {
-       MSG_MMS_PAGE_MEDIA_LIST_HND = MSG_STRUCT_MMS_PAGE+1,            /**< The pointer to media list */
-       MSG_MMS_PAGE_PAGE_DURATION_INT,                                 /**< Indicates the duration of the page */
-       MSG_MMS_PAGE_BEGIN_TIME_INT,                                    /**< Indicates the begin time of the page */
-       MSG_MMS_PAGE_END_TIME_INT,                                      /**< Indicates the end time of the page */
-       MSG_MMS_PAGE_MIN_INT,                                           /**< Indicates the min attribute of the page */
-       MSG_MMS_PAGE_MAX_INT,                                           /**< Indicates the max attribute of the page */
-       MSG_MMS_PAGE_REPEAT_INT,                                        /**< Indicates the page needs to be displayed repeatedly */
+       MSG_MMS_PAGE_MEDIA_LIST_HND = MSG_STRUCT_MMS_PAGE+1,  /**< The pointer to media list */
+       MSG_MMS_PAGE_PAGE_DURATION_INT,                       /**< Indicates the duration of the page */
+       MSG_MMS_PAGE_BEGIN_TIME_INT,                          /**< Indicates the begin time of the page */
+       MSG_MMS_PAGE_END_TIME_INT,                            /**< Indicates the end time of the page */
+       MSG_MMS_PAGE_MIN_INT,                                 /**< Indicates the min attribute of the page */
+       MSG_MMS_PAGE_MAX_INT,                                 /**< Indicates the max attribute of the page */
+       MSG_MMS_PAGE_REPEAT_INT,                              /**< Indicates the page needs to be displayed repeatedly */
 };
 
+/**
+ *  @brief  Enumeration for the values of MMS media informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_MEDIA.
+ */
 enum MSG_MMS_MEDIA_INFO {
-       MSG_MMS_MEDIA_TYPE_INT = MSG_STRUCT_MMS_MEDIA+1,                /**< Indicates the SMIL media type. see enum MmsSmilMediaType */
-       MSG_MMS_MEDIA_SRC_STR,                                          /**< Indicates the media source name */
-       MSG_MMS_MEDIA_FILENAME_STR,                                     /**< Indicates the file name */
-       MSG_MMS_MEDIA_FILEPATH_STR,                                     /**< Indicates the file path */
-       MSG_MMS_MEDIA_CONTENT_ID_STR,                                   /**< Indicates the content id */
-       MSG_MMS_MEDIA_REGION_ID_STR,                                    /**< Indicates the region id */
-       MSG_MMS_MEDIA_ALTERNATIVE_STR,                                  /**< Indicates the alternative text to be displayed in failure case */
-       MSG_MMS_MEDIA_DRM_TYPE_INT,                                     /**< Indicates the drm type. see enum MsgDrmType */
-       MSG_MMS_MEDIA_DRM_FULLPATH_STR,                                 /**< Indicates the fullpath of the DRM */
-       MSG_MMS_MEDIA_SMIL_TEXT_HND,                                    /**< Indicates the text attributes */
-       MSG_MMS_MEDIA_SMIL_AVI_HND,                                     /**< Indicates the video attributes */
-};
-
-//MSG_MMS_ATTACH
+       MSG_MMS_MEDIA_TYPE_INT = MSG_STRUCT_MMS_MEDIA+1,  /**< Indicates the SMIL media type. See enum MmsSmilMediaType */
+       MSG_MMS_MEDIA_SRC_STR,                            /**< Indicates the media source name */
+       MSG_MMS_MEDIA_FILENAME_STR,                       /**< Indicates the file name */
+       MSG_MMS_MEDIA_FILEPATH_STR,                       /**< Indicates the file path */
+       MSG_MMS_MEDIA_CONTENT_ID_STR,                     /**< Indicates the content ID */
+       MSG_MMS_MEDIA_REGION_ID_STR,                      /**< Indicates the region ID */
+       MSG_MMS_MEDIA_ALTERNATIVE_STR,                    /**< Indicates the alternative text to be displayed in failure case */
+       MSG_MMS_MEDIA_DRM_TYPE_INT,                       /**< Indicates the DRM type. See enum MsgDrmType */
+       MSG_MMS_MEDIA_DRM_FULLPATH_STR,                   /**< Indicates the fullpath of the DRM */
+       MSG_MMS_MEDIA_SMIL_TEXT_HND,                      /**< Indicates the text attributes */
+       MSG_MMS_MEDIA_SMIL_AVI_HND,                       /**< Indicates the video attributes */
+       MSG_MMS_MEDIA_CONTENT_LOCATION_STR,               /**< Indicates the content location */
+       MSG_MMS_MEDIA_CONTENT_TYPE_STR,                   /**< Indicates the content type */
+       MSG_MMS_MEDIA_INFO_MAX,                           /**< Placeholder for max value of this enum*/
+};
+
+/**
+ *  @brief  Enumeration for the values of MMS attachment informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_ATTACH.
+ */
 enum MSG_MMS_ATTACH_INFO_E {
-       MSG_MMS_ATTACH_MIME_TYPE_INT = MSG_STRUCT_MMS_ATTACH+1,         /**< Indicates the file mime type. see enum MimeType */
-       MSG_MMS_ATTACH_FILENAME_STR,                                    /**< Indicates the file name */
-       MSG_MMS_ATTACH_FILEPATH_STR,                                    /**< Indicates the file path */
-       MSG_MMS_ATTACH_FILESIZE_INT,                                    /**< Indicates the size of the file */
-       MSG_MMS_ATTACH_DRM_TYPE_INT,                                    /**< Indicates the drm type. see enum MsgDrmType */
-       MSG_MMS_ATTACH_DRM_FULLPATH_STR,                                /**< Indicates the fullpath of the DRM */
+       MSG_MMS_ATTACH_MIME_TYPE_INT = MSG_STRUCT_MMS_ATTACH+1,     /**< Indicates the file mime type. See enum MimeType */
+       MSG_MMS_ATTACH_FILENAME_STR,                                /**< Indicates the file name */
+       MSG_MMS_ATTACH_FILEPATH_STR,                                /**< Indicates the file path */
+       MSG_MMS_ATTACH_FILESIZE_INT,                                /**< Indicates the size of the file */
+       MSG_MMS_ATTACH_DRM_TYPE_INT,                                /**< Indicates the DRM type. See enum MsgDrmType */
+       MSG_MMS_ATTACH_DRM_FULLPATH_STR,                            /**< Indicates the fullpath of the DRM */
+       MSG_MMS_ATTACH_CONTENT_TYPE_STR,                            /**< Indicates the content type */
+       MSG_MMS_ATTACH_INFO_MAX,                                    /**< Placeholder for max value of this enum*/
 };
 
+/**
+ *  @brief  Enumeration for the values of MMS region informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_REGION.
+ */
 enum MSG_MMS_REGION_INFO_E {
-       MSG_MMS_REGION_ID_STR = MSG_STRUCT_MMS_REGION+1,                /**< Indicates the ID of region information */
-       MSG_MMS_REGION_LENGTH_LEFT_INT,                                 /**< Indicates the left co-ordinate of the region */
-       MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL,                        /**< Indicates the length is in percentage(%) or not */
-       MSG_MMS_REGION_LENGTH_TOP_INT,                                  /**< Indicates the top co-ordinate of the region */
-       MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL,                         /**< Indicates the length is in percentage(%) or not */
-       MSG_MMS_REGION_LENGTH_WIDTH_INT,                                /**< Indicates the width of the region */
-       MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL,                       /**< Indicates the length is in percentage(%) or not */
-       MSG_MMS_REGION_LENGTH_HEIGHT_INT,                               /**< Indicates the width of the region */
-       MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL,                      /**< Indicates the length is in percentage(%) or not */
-       MSG_MMS_REGION_BGCOLOR_INT,                                     /**< Indicates the background color of the region */
-       MSG_MMS_REGION_FIT_TYPE_INT,                                    /**< Indicates the fit type. see enum REGION_FIT_TYPE_T */
-       MSG_MMS_REGION_BGCOLOR_BOOL,                            /**< Indicates the background color is set in the region */
+       MSG_MMS_REGION_ID_STR = MSG_STRUCT_MMS_REGION+1,      /**< Indicates the ID of region information */
+       MSG_MMS_REGION_LENGTH_LEFT_INT,                       /**< Indicates the left co-ordinate of the region */
+       MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL,              /**< Indicates the length is in percentage(%) or not */
+       MSG_MMS_REGION_LENGTH_TOP_INT,                        /**< Indicates the top co-ordinate of the region */
+       MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL,               /**< Indicates the length is in percentage(%) or not */
+       MSG_MMS_REGION_LENGTH_WIDTH_INT,                      /**< Indicates the width of the region */
+       MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL,             /**< Indicates the length is in percentage(%) or not */
+       MSG_MMS_REGION_LENGTH_HEIGHT_INT,                     /**< Indicates the width of the region */
+       MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL,            /**< Indicates the length is in percentage(%) or not */
+       MSG_MMS_REGION_BGCOLOR_INT,                           /**< Indicates the background color of the region */
+       MSG_MMS_REGION_FIT_TYPE_INT,                          /**< Indicates the fit type. See enum REGION_FIT_TYPE_T */
+       MSG_MMS_REGION_BGCOLOR_BOOL,                          /**< Indicates the background color is set in the region */
 };
 
+/**
+ *  @brief  Enumeration for the values of MMS meta data informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_META.
+ */
 enum MSG_MMS_META_INFO_E {
-       MSG_MMS_META_ID_STR = MSG_STRUCT_MMS_META+1,                    /**< Indicates the ID of meta information */
-       MSG_MMS_META_NAME_STR,                                          /**< Indicates the Name */
-       MSG_MMS_META_CONTENT_STR,                                       /**< Indicates the content */
+       MSG_MMS_META_ID_STR = MSG_STRUCT_MMS_META+1,  /**< Indicates the ID of meta information */
+       MSG_MMS_META_NAME_STR,                        /**< Indicates the Name */
+       MSG_MMS_META_CONTENT_STR,                     /**< Indicates the content */
 };
 
-enum MSG_MMS_TRANSION_INFO_E {
-       MSG_MMS_TRANSITION_ID_STR = MSG_STRUCT_MMS_TRANSITION+1,        /**< Indicates the ID of transition information */
-       MSG_MMS_TRANSITION_TYPE_INT,                                    /**< Indicates the transition type. see enum MmsSmilTransType */
-       MSG_MMS_TRANSITION_SUBTYPE_INT,                                 /**< Indicates the transition sub type. see enum MmsSmilTransSubType */
-       MSG_MMS_TRANSITION_DURATION_INT,                                /**< Indicates the transition duration */
+/**
+ *  @brief  Enumeration for the values of MMS transition informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_TRANSITION.
+ */
+enum MSG_MMS_TRANSITION_INFO_E {
+       MSG_MMS_TRANSITION_ID_STR = MSG_STRUCT_MMS_TRANSITION+1,    /**< Indicates the ID of transition information */
+       MSG_MMS_TRANSITION_TYPE_INT,                                /**< Indicates the transition type. See enum MmsSmilTransType */
+       MSG_MMS_TRANSITION_SUBTYPE_INT,                             /**< Indicates the transition sub type. See enum MmsSmilTransSubType */
+       MSG_MMS_TRANSITION_DURATION_INT,                            /**< Indicates the transition duration */
 };
 
+/**
+ *  @brief  Enumeration for the values of MMS SMIL text informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_SMIL_TEXT.
+ */
 enum MSG_MMS_SMIL_TEXT_INFO_E {
-       MSG_MMS_SMIL_TEXT_TRANSITION_IN_ID_STR = MSG_STRUCT_MMS_SMIL_TEXT+1,    /**< Indicates the In SMIL transition id */
-       MSG_MMS_SMIL_TEXT_TRANSITION_OUT_ID_STR,                                /**< Indicates the Out SMIL transition id */
-       MSG_MMS_SMIL_TEXT_REPEAT_INT,                                           /**< Indicates the text needs to be displayed repeatedly */
-       MSG_MMS_SMIL_TEXT_BEGIN_INT,                                            /**< Indicates the begin time */
-       MSG_MMS_SMIL_TEXT_END_INT,                                              /**< Indicates the end time */
-       MSG_MMS_SMIL_TEXT_DURTIME_INT,                                          /**< Indicates the duration */
-       MSG_MMS_SMIL_TEXT_BGCOLOR_INT,                                          /**< Indicates the background color of the text */
-       MSG_MMS_SMIL_TEXT_BOLD_BOOL,                                            /**< Indicates whether the text is bold */
-       MSG_MMS_SMIL_TEXT_UNDERLINE_BOOL,                                       /**< Indicates whether the text is underlined */
-       MSG_MMS_SMIL_TEXT_ITALIC_BOOL,                                          /**< Indicates whether the text is Italic */
-       MSG_MMS_SMIL_TEXT_REVERSE_BOOL,                                         /**< Indicates whether the text is reversed */
-       MSG_MMS_SMIL_TEXT_DIRECTION_TYPE_INT,                                   /**< Indicates the text direction type. see enum MmsTextDirection */
-       MSG_MMS_SMIL_TEXT_SIZE_INT,                                             /**< Indicates the font size */
-       MSG_MMS_SMIL_TEXT_COLOR_INT,                                            /**< Indicates the font color */
-};
-
+       MSG_MMS_SMIL_TEXT_TRANSITION_IN_ID_STR = MSG_STRUCT_MMS_SMIL_TEXT+1,  /**< Indicates the In SMIL transition ID */
+       MSG_MMS_SMIL_TEXT_TRANSITION_OUT_ID_STR,                              /**< Indicates the Out SMIL transition ID */
+       MSG_MMS_SMIL_TEXT_REPEAT_INT,                                         /**< Indicates the text needs to be displayed repeatedly */
+       MSG_MMS_SMIL_TEXT_BEGIN_INT,                                          /**< Indicates the begin time */
+       MSG_MMS_SMIL_TEXT_END_INT,                                            /**< Indicates the end time */
+       MSG_MMS_SMIL_TEXT_DURTIME_INT,                                        /**< Indicates the duration */
+       MSG_MMS_SMIL_TEXT_BGCOLOR_INT,                                        /**< Indicates the background color of the text */
+       MSG_MMS_SMIL_TEXT_BOLD_BOOL,                                          /**< Indicates whether the text is bold */
+       MSG_MMS_SMIL_TEXT_UNDERLINE_BOOL,                                     /**< Indicates whether the text is underlined */
+       MSG_MMS_SMIL_TEXT_ITALIC_BOOL,                                        /**< Indicates whether the text is Italic */
+       MSG_MMS_SMIL_TEXT_REVERSE_BOOL,                                       /**< Indicates whether the text is reversed */
+       MSG_MMS_SMIL_TEXT_DIRECTION_TYPE_INT,                                 /**< Indicates the text direction type. see enum MmsTextDirection */
+       MSG_MMS_SMIL_TEXT_SIZE_INT,                                           /**< Indicates the font size */
+       MSG_MMS_SMIL_TEXT_COLOR_INT,                                          /**< Indicates the font color */
+};
+
+/**
+ *  @brief  Enumeration for the values of MMS SMIL avi informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_SMIL_AVI.
+ */
 enum MSG_MMS_SMIL_AVI_INFO_E {
-       MSG_MMS_SMIL_AVI_TRANSITION_IN_ID_STR = MSG_STRUCT_MMS_SMIL_AVI+1,      /**< Indicates the In SMIL transition id */
-       MSG_MMS_SMIL_AVI_TRANSITION_OUT_ID_STR,                                 /**< Indicates the Out SMIL transition id */
-       MSG_MMS_SMIL_AVI_REPEAT_INT,                                            /**< Indicates the video needs to be displayed repeatedly */
-       MSG_MMS_SMIL_AVI_BEGIN_INT,                                             /**< Indicates the begin time */
-       MSG_MMS_SMIL_AVI_END_INT,                                               /**< Indicates the end time */
-       MSG_MMS_SMIL_AVI_DURTIME_INT,                                           /**< Indicates the duration */
-       MSG_MMS_SMIL_AVI_BGCOLOR_INT,                                           /**< Indicates the background color of the text */
+       MSG_MMS_SMIL_AVI_TRANSITION_IN_ID_STR = MSG_STRUCT_MMS_SMIL_AVI+1,  /**< Indicates the In SMIL transition ID */
+       MSG_MMS_SMIL_AVI_TRANSITION_OUT_ID_STR,                             /**< Indicates the Out SMIL transition ID */
+       MSG_MMS_SMIL_AVI_REPEAT_INT,                                        /**< Indicates the video needs to be displayed repeatedly */
+       MSG_MMS_SMIL_AVI_BEGIN_INT,                                         /**< Indicates the begin time */
+       MSG_MMS_SMIL_AVI_END_INT,                                           /**< Indicates the end time */
+       MSG_MMS_SMIL_AVI_DURTIME_INT,                                       /**< Indicates the duration */
+       MSG_MMS_SMIL_AVI_BGCOLOR_INT,                                       /**< Indicates the background color of the text */
 };
 
+/**
+ *  @brief  Enumeration for the values of message sending options. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SENDOPT.
+ */
 enum MSG_SEND_OPT_E {
-       MSG_SEND_OPT_SETTING_BOOL = MSG_STRUCT_SENDOPT+1,                       /**< Indicates whether the sending option is set ot not for a message */
-       MSG_SEND_OPT_DELIVER_REQ_BOOL,                                          /**< Indicates whether the delivey custom time is used or not */
-       MSG_SEND_OPT_KEEPCOPY_BOOL,                                             /**< Indicates whether the message copy is kept or not */
-       MSG_SEND_OPT_MMS_OPT_HND,                                               /**< The handle of MMS sending option for a message */
-       MSG_SEND_OPT_SMS_OPT_HND,                                               /**< The handle of SMS sending option for a message */
+       MSG_SEND_OPT_SETTING_BOOL = MSG_STRUCT_SENDOPT+1,  /**< Indicates whether the sending option is set or not for a message */
+       MSG_SEND_OPT_DELIVER_REQ_BOOL,                     /**< Indicates whether the delivery custom time is used or not */
+       MSG_SEND_OPT_KEEPCOPY_BOOL,                        /**< Indicates whether the message copy is kept or not */
+       MSG_SEND_OPT_MMS_OPT_HND,                          /**< The handle of MMS sending option for a message */
+       MSG_SEND_OPT_SMS_OPT_HND,                          /**< The handle of SMS sending option for a message */
 };
 
+/**
+ *  @brief  Enumeration for the values of SyncML informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SYNCML_INFO.
+ */
 enum MSG_SYNCML_INFO_E {
-       MSG_SYNCML_INFO_EXTID_INT = MSG_STRUCT_SYNCML_INFO+1,                   /**< Indicates the ext ID */
-       MSG_SYNCML_INFO_PINCODE_INT,                                            /**< Indicates the PIN code */
-       MSG_SYNCML_INFO_MESSAGE_HND,                                            /**< Indicate the handle of a message */
+       MSG_SYNCML_INFO_EXTID_INT = MSG_STRUCT_SYNCML_INFO+1,  /**< Indicates the ext ID */
+       MSG_SYNCML_INFO_PINCODE_INT,                           /**< Indicates the PIN code */
+       MSG_SYNCML_INFO_MESSAGE_HND,                           /**< Indicate the handle of a message */
 };
 
+/**
+ *  @brief  Enumeration for the values of message count status. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_COUNT_INFO.
+ */
 enum MSG_COUNT_INFO_E {
-       MSG_COUNT_INFO_READ_INT = MSG_STRUCT_COUNT_INFO+1,                      /**< The count of read messages */
-       MSG_COUNT_INFO_UNREAD_INT,                                              /**< The count of unread messages */
-       MSG_COUNT_INFO_SMS_INT,                                                 /**< The count of sms type messages */
-       MSG_COUNT_INFO_MMS_INT,                                                 /**< The count of mms type messages */
+       MSG_COUNT_INFO_READ_INT = MSG_STRUCT_COUNT_INFO+1,  /**< The count of read messages */
+       MSG_COUNT_INFO_UNREAD_INT,                          /**< The count of unread messages */
+       MSG_COUNT_INFO_SMS_INT,                             /**< The count of SMS type messages */
+       MSG_COUNT_INFO_MMS_INT,                             /**< The count of MMS type messages */
 };
 
+/**
+ *  @brief  Enumeration for the values of message count in a thread. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_THREAD_COUNT_INFO.
+ */
 enum MSG_THREAD_COUNT_INFO_E {
-       MSG_THREAD_COUNT_TOTAL_INT = MSG_STRUCT_THREAD_COUNT_INFO+1,            /**< Indicates the total number of messages from the Peer. */
-       MSG_THREAD_COUNT_UNREAD_INT,                                            /**< Indicates the unread messages from the Peer. */
-       MSG_THREAD_COUNT_SMS_INT,                                               /**< Indicates the SMS messages from the Peer. */
-       MSG_THREAD_COUNT_MMS_INT,                                               /**< Indicates the MMS messages from the Peer. */
+       MSG_THREAD_COUNT_TOTAL_INT = MSG_STRUCT_THREAD_COUNT_INFO+1,  /**< Indicates the total number of messages from the Peer. */
+       MSG_THREAD_COUNT_UNREAD_INT,                                  /**< Indicates the unread messages from the peer. */
+       MSG_THREAD_COUNT_SMS_INT,                                     /**< Indicates the SMS messages from the peer. */
+       MSG_THREAD_COUNT_MMS_INT,                                     /**< Indicates the MMS messages from the peer. */
 };
 
+/**
+ *  @brief  Enumeration for the values of thread informations for address. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_THREAD_LIST_INDEX.
+ */
 enum MSG_THREAD_LIST_INDEX_E {
-       MSG_THREAD_LIST_INDEX_CONTACTID_INT = MSG_STRUCT_THREAD_LIST_INDEX+1,   /**< The contact id of message common informatioin */
-       MSG_THREAD_LIST_INDEX_ADDR_INFO_HND,                                    /**< The pointer to message common informatioin */
+       MSG_THREAD_LIST_INDEX_CONTACTID_INT = MSG_STRUCT_THREAD_LIST_INDEX+1,   /**< The contact ID of message common informatioin */
+       MSG_THREAD_LIST_INDEX_ADDR_INFO_HND,                                    /**< The pointer to message common informatioin */
 };
 
+/**
+ *  @brief  Enumeration for the values of sort rule for getting message list. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SORT_RULE.
+ */
 enum MSG_SORT_RULE_E {
-       MSG_SORT_RULE_SORT_TYPE_INT = MSG_STRUCT_SORT_RULE+1,           /**< Indicates the sort type. See enum _MSG_SORT_TYPE_E */
-       MSG_SORT_RULE_ACSCEND_BOOL,                                     /**< Indicates the sort order which is ascending or descending */
+       MSG_SORT_RULE_SORT_TYPE_INT = MSG_STRUCT_SORT_RULE+1,  /**< Indicates the sort type. See enum _MSG_SORT_TYPE_E */
+       MSG_SORT_RULE_ACSCEND_BOOL,                            /**< Indicates the sort order which is ascending or descending */
 };
 
+/**
+ *  @brief  Enumeration for the values of message folder information. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_FOLDER_INFO.
+ */
 enum MSG_FOLDER_INFO_E {
-       MSG_FOLDER_INFO_ID_INT = MSG_STRUCT_FOLDER_INFO+1,              /**< Indicates the unique folder ID. */
-       MSG_FOLDER_INFO_NAME_STR,                                       /**< Indicates the name of the folder. */
-       MSG_FOLDER_INFO_TYPE_INT,                                       /**< Indicates the folder type. */
+       MSG_FOLDER_INFO_ID_INT = MSG_STRUCT_FOLDER_INFO+1,  /**< Indicates the unique folder ID. */
+       MSG_FOLDER_INFO_NAME_STR,                           /**< Indicates the name of the folder. */
+       MSG_FOLDER_INFO_TYPE_INT,                           /**< Indicates the folder type. */
 };
 
+/**
+ *  @brief  Enumeration for the values of conditions for searching message. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SEARCH_CONDITION.
+ */
 enum MSG_SEARCH_CONDITION_E {
-       MSG_SEARCH_CONDITION_FOLDERID_INT = MSG_STRUCT_SEARCH_CONDITION+1,              /**< Indicates the folder ID for searching messages. See enum _MSG_FOLDER_ID_E */
-       MSG_SEARCH_CONDITION_MSGTYPE_INT,                                               /**< Indicates the message type for searching messages. See enum _MSG_MESSAGE_TYPE_E */
-       MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR,                                         /**< The address value for searching messages. */
-       MSG_SEARCH_CONDITION_SEARCH_VALUE_STR,                                          /**< The string to search */
-       MSG_SEARCH_CONDITION_RESERVED_INT,
+       MSG_SEARCH_CONDITION_FOLDERID_INT = MSG_STRUCT_SEARCH_CONDITION+1,  /**< The folder ID for searching messages. See enum _MSG_FOLDER_ID_E */
+       MSG_SEARCH_CONDITION_MSGTYPE_INT,                                   /**< The message type for searching messages. See enum _MSG_MESSAGE_TYPE_E */
+       MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR,                             /**< The address value for searching messages. */
+       MSG_SEARCH_CONDITION_SEARCH_VALUE_STR,                              /**< The string to search */
+       MSG_SEARCH_CONDITION_RESERVED_INT,                                  /**< The search condition reserved*/
 };
 
+/**
+ *  @brief  Enumeration for the values of report message status. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_REPORT_STATUS_INFO.
+ */
 enum MSG_REPORT_E {
-       MSG_REPORT_ADDRESS_STR = MSG_STRUCT_REPORT_STATUS_INFO+1,       /**< Indicates Report address */
-       MSG_REPORT_TYPE_INT,                                                    /**< Indicates Report type. See the msg_report_type_t type*/
-       MSG_REPORT_STATUS_INT,                                          /**< Indicates Report status. See the msg_delivery_report_status_t or msg_read_report_status_t type*/
-       MSG_REPORT_TIME_INT,                                                    /**< Indicates Report time */
+       MSG_REPORT_ADDRESS_STR = MSG_STRUCT_REPORT_STATUS_INFO+1,  /**< Indicates Report address */
+       MSG_REPORT_TYPE_INT,                                       /**< Indicates Report type. See the msg_report_type_t type*/
+       MSG_REPORT_STATUS_INT,                                     /**< Indicates Report status. See the msg_delivery_report_status_t or msg_read_report_status_t type*/
+       MSG_REPORT_TIME_INT,                                       /**< Indicates Report time */
 };
 
+/**
+ *  @brief  Enumeration for the values of conditions for getting message list. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MSG_LIST_CONDITION.
+ */
+enum MSG_LIST_CONDITION_E {
+       MSG_LIST_CONDITION_FOLDER_ID_INT = MSG_STRUCT_MSG_LIST_CONDITION+1,  /**< Indicates the folder ID for searching messages. See enum _MSG_FOLDER_ID_E */
+       MSG_LIST_CONDITION_THREAD_ID_INT,                                    /**< Indicates the thread ID for searching messages. */
+       MSG_LIST_CONDITION_STORAGE_ID_INT,                                   /**< Indicates the storage ID for searching messages. See enum _MSG_STORAGE_ID_E */
+       MSG_LIST_CONDITION_MSGTYPE_INT,                                      /**< Indicates the message type for searching messages. See enum _MSG_MESSAGE_TYPE_E */
+       MSG_LIST_CONDITION_PROTECTED_BOOL,                                   /**< Indicates the protected flag for searching messages*/
+       MSG_LIST_CONDITION_SCHEDULED_BOOL,                                   /**< Indicates the scheduled flag for searching messages*/
+       MSG_LIST_CONDITION_ADDRESS_VALUE_STR,                                /**< The address value for searching messages. */
+       MSG_LIST_CONDITION_TEXT_VALUE_STR,                                   /**< The string to search */
+       MSG_LIST_CONDITION_AND_OPERATER_BOOL,                                /**< Indicates presence of 'AND' operator for searching messages*/
+       MSG_LIST_CONDITION_FROM_TIME_INT,                                    /**< Indicates the 'FROM TIME' for searching messages*/
+       MSG_LIST_CONDITION_TO_TIME_INT,                                      /**< Indicates the 'TO TIME' for searching messages*/
+       MSG_LIST_CONDITION_OFFSET_INT,                                       /**< Indicates Search Result offset*/
+       MSG_LIST_CONDITION_LIMIT_INT,                                        /**< Indicates Search Result limit*/
+       MSG_LIST_CONDITION_SORT_RULE_HND,                                    /**< The pointer to sort rule to apply*/
+       MSG_LIST_CONDITION_SIM_INDEX_INT,
+};
+
+/**
+ *  @brief  Enumeration for the values of address informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_ADDRESS_INFO.
+ */
 enum MSG_ADDRESS_INFO_E {
-       MSG_ADDRESS_INFO_ADDRESS_TYPE_INT = MSG_STRUCT_ADDRESS_INFO+1,                  /**< The type of an address in case of an Email or a mobile phone. See enum _MSG_ADDRESS_TYPE_E */
-       MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,                                            /**< The type of recipient address in case of To, Cc, and Bcc. See enum _MSG_RECIPIENT_TYPE_E */
-       MSG_ADDRESS_INFO_CONTACT_ID_INT,                                                /**< The contact ID of address */
-       MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,                                             /**< The actual value of an address */
-       MSG_ADDRESS_INFO_DISPLAYNAME_STR,                                               /**< The display name of an address */
+       MSG_ADDRESS_INFO_ADDRESS_TYPE_INT = MSG_STRUCT_ADDRESS_INFO+1,  /**< The type of an address in case of an Email or a mobile phone. See enum _MSG_ADDRESS_TYPE_E */
+       MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,                            /**< The type of recipient address in case of To, Cc, and Bcc. See enum _MSG_RECIPIENT_TYPE_E */
+       MSG_ADDRESS_INFO_CONTACT_ID_INT,                                /**< The contact ID of address **DEPRECATED** */
+       MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,                             /**< The actual value of an address */
+       MSG_ADDRESS_INFO_DISPLAYNAME_STR,                               /**< The display name of an address **DEPRECATED** */
 };
 
+/**
+ *  @brief  Enumeration for the values of MMS sending options for sent message. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_MMS_SENDOPT.
+ */
 enum MSG_MMS_SENDOPT_E {
-       MSG_MMS_SENDOPTION_READ_REQUEST_BOOL = MSG_STRUCT_MMS_SENDOPT+1,                /**< Indicates whether it requests read report or not */
-       MSG_MMS_SENDOPTION_EXPIRY_TIME_INT,                                             /**< Indicates MMS expiry time */
-       MSG_MMS_SENDOPTION_DELIVERY_CUSTOMTIME_BOOL,                                    /**< Indicates whether is use MMS delivery custom time */
-       MSG_MMS_SENDOPTION_DELIVERY_TIME_INT,                                           /**< Indicates MMS delivery time */
-       MSG_MMS_SENDOPTION_PRIORITY_INT,                                                /**< Indicates MMS priority. See enum _MSG_PRIORITY_TYPE_E */
+       MSG_MMS_SENDOPTION_READ_REQUEST_BOOL = MSG_STRUCT_MMS_SENDOPT+1,  /**< Indicates whether it requests read report or not */
+       MSG_MMS_SENDOPTION_EXPIRY_TIME_INT,                               /**< Indicates MMS expiry time */
+       MSG_MMS_SENDOPTION_DELIVERY_CUSTOMTIME_BOOL,                      /**< Indicates whether is use MMS delivery custom time */
+       MSG_MMS_SENDOPTION_DELIVERY_TIME_INT,                             /**< Indicates MMS delivery time */
+       MSG_MMS_SENDOPTION_PRIORITY_INT,                                  /**< Indicates MMS priority. See enum _MSG_PRIORITY_TYPE_E */
 };
 
+/**
+ *  @brief  Enumeration for the values of SMS sending options for sent message. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SMS_SENDOPT.
+ */
 enum MSG_SMS_SENDOPT_E {
-       MSG_SMS_SENDOPT_REPLYPATH_BOOL = MSG_STRUCT_SMS_SENDOPT+1,              /**< Indicates whether reply path is set */
+       MSG_SMS_SENDOPT_REPLYPATH_BOOL = MSG_STRUCT_SMS_SENDOPT+1,  /**< Indicates whether reply path is set */
 };
 
+/**
+ *  @brief  Enumeration for the values of reject message informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_REJECT_MSG_INFO.
+ */
 enum MSG_REJECT_MESSAGE_E {
-       MSG_REJECT_MESSAGE_MSGID_INT = MSG_STRUCT_REJECT_MSG_INFO+1,            /**< Indicates the font type none */
-       MSG_REJECT_MESSAGE_MSGTEXT_STR,                                         /**< Indicates the font type none */
-       MSG_REJECT_MESSAGE_DISPLAY_TIME_INT,                                    /**< Indicates the font type none */
+       MSG_REJECT_MESSAGE_MSGID_INT = MSG_STRUCT_REJECT_MSG_INFO+1,   /**< Indicates the ID of rejected message */
+       MSG_REJECT_MESSAGE_MSGTEXT_STR,                                /**< Indicates the text of rejected message */
+       MSG_REJECT_MESSAGE_DISPLAY_TIME_INT,                           /**< Indicates the display time of rejected message */
 };
 
+/**
+ *  @brief  Enumeration for the values of requested message informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_REQUEST_INFO.
+ */
 enum MSG_REQUEST_INFO_E {
-       MSG_REQUEST_REQUESTID_INT = MSG_STRUCT_REQUEST_INFO+1,  /**< Indicates the request ID, which is unique. When applications submit a request to the framework, this value will be set by the framework. */
-       MSG_REQUEST_MESSAGE_HND,                                /**< Indicates the message structure to be sent by applications. */
-       MSG_REQUEST_SENDOPT_HND,
+       MSG_REQUEST_REQUESTID_INT = MSG_STRUCT_REQUEST_INFO+1,  /**< Indicates the request ID, which is unique. When applications submit a request to the framework, this value will be set by the framework. */
+       MSG_REQUEST_MESSAGE_HND,                                /**< Indicates the message structure to be sent by applications. */
+       MSG_REQUEST_SENDOPT_HND,                                /**< Indicates the send options to be sent by applications*/
 };
 
+/**
+ *  @brief  Enumeration for the values of sent status informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_SENT_STATUS_INFO.
+ */
 enum MSG_SENT_STATUS_INFO_E {
-       MSG_SENT_STATUS_REQUESTID_INT = MSG_STRUCT_SENT_STATUS_INFO+1,  /**< Indicates the corresponding request Id. */
-       MSG_SENT_STATUS_NETWORK_STATUS_INT,                             /**< Indicates the status of the corresponding request. Refer to enum _MSG_NETWORK_STATUS_E*/
+       MSG_SENT_STATUS_REQUESTID_INT = MSG_STRUCT_SENT_STATUS_INFO+1,  /**< Indicates the corresponding request ID. */
+       MSG_SENT_STATUS_NETWORK_STATUS_INT,                             /**< Indicates the status of the corresponding request. See enum _MSG_NETWORK_STATUS_E*/
 };
 
+/**
+ *  @brief  Enumeration for the values of push configurations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_PUSH_CONFIG_INFO.
+ */
 enum MSG_PUSH_CONFIG_INFO_E {
-       MSG_PUSH_CONFIG_CONTENT_TYPE_STR = MSG_STRUCT_PUSH_CONFIG_INFO+1,
-       MSG_PUSH_CONFIG_APPLICATON_ID_STR,
-       MSG_PUSH_CONFIG_PACKAGE_NAME_STR,
-       MSG_PUSH_CONFIG_LAUNCH_BOOL,
+       MSG_PUSH_CONFIG_CONTENT_TYPE_STR = MSG_STRUCT_PUSH_CONFIG_INFO+1,  /**< Indicates the content type*/
+       MSG_PUSH_CONFIG_APPLICATON_ID_STR,                                 /**< Indicates the application ID*/
+       MSG_PUSH_CONFIG_PACKAGE_NAME_STR,                                  /**< Indicates the package name*/
+       MSG_PUSH_CONFIG_LAUNCH_BOOL,                                       /**< Indicates launch*/
 };
 
+/**
+ *  @brief  Enumeration for the values of CB message informations. \n
+ *          This enum is used as member of #msg_struct_t for MSG_STRUCT_CB_MSG.
+ */
 enum MSG_CB_MSG_E {
-       MSG_CB_MSG_TYPE_INT     = MSG_STRUCT_CB_MSG+1,          /**<  MSG_TYPE_SMS_CB/ETWS_PRIMARY/ETWS_SECONDARY (see _MSG_MESSAGE_TYPE_E) */
-       MSG_CB_MSG_RECV_TIME_INT,
-       MSG_CB_MSG_SERIAL_NUM_INT,                                              /**< serial number of CB/ETWS Primary Noti. : 2 bytes binary data */
-       MSG_CB_MSG_MSG_ID_INT,                                                  /**< message identifier of CB/ETWS Primary Noti. */
-       MSG_CB_MSG_DCS_INT,                                                             /**< Data coding scheme of CB MSG. */
-       MSG_CB_MSG_CB_TEXT_LEN_INT,                                             /**< length of CB text (except NULL) */
-       MSG_CB_MSG_CB_TEXT_STR,                                                 /**< CB text */
-       MSG_CB_MSG_ETWS_WARNING_TYPE_INT,                               /**< warning type of ETWS Primary Noti. : 2 bytes binary data */
-       MSG_CB_MSG_ETWS_WARNING_SECU_INFO_STR,                  /**< warning security information of ETWS Primary Noti. : 50 bytes binary data */
-       MSG_CB_MSG_LANGUAGE_TYPE_STR,                                   /**< Language type of CB message data */
+       MSG_CB_MSG_TYPE_INT     = MSG_STRUCT_CB_MSG+1,      /**<  MSG_TYPE_SMS_CB/ETWS_PRIMARY/ETWS_SECONDARY (see _MSG_MESSAGE_TYPE_E) */
+       MSG_CB_MSG_RECV_TIME_INT,                       /**< Received time*/
+       MSG_CB_MSG_SERIAL_NUM_INT,                      /**< Serial number of CB/ETWS Primary Noti. : 2 bytes binary data */
+       MSG_CB_MSG_MSG_ID_INT,                          /**< Message identifier of CB/ETWS Primary Noti. */
+       MSG_CB_MSG_DCS_INT,                             /**< Data coding scheme of CB MSG. */
+       MSG_CB_MSG_CB_TEXT_LEN_INT,                     /**< Length of CB text (except NULL) */
+       MSG_CB_MSG_CB_TEXT_STR,                         /**< CB text */
+       MSG_CB_MSG_ETWS_WARNING_TYPE_INT,               /**< Warning type of ETWS Primary Noti. : 2 bytes binary data */
+       MSG_CB_MSG_ETWS_WARNING_SECU_INFO_STR,          /**< Warning security information of ETWS Primary Noti. : 50 bytes binary data */
+       MSG_CB_MSG_LANGUAGE_TYPE_STR,                   /**< Language type of CB message data */
 };
 
 /**
- *     @brief  Represents the values of a message class type. \n
- *     This enum is used as the value of MSG_CLASS_TYPE_T.
+ *  @brief  Enumeration for the values of a message class type. \n
+ *             This enum is used as the value of MSG_CLASS_TYPE_T.
  */
 enum _MSG_CLASS_TYPE_E
 {
@@ -773,137 +1177,150 @@ enum _MSG_CLASS_TYPE_E
        MSG_CLASS_1,                    /**< Stored in the mobile equipment or SIM (depending on memory availability) */
        MSG_CLASS_2,                    /**< Stored in SIM */
        MSG_CLASS_3,                    /**< Transferred to the terminal equipment (such as PDA or PC) which is connected to the mobile equipment */
-       MSG_CLASS_NONE,
+       MSG_CLASS_NONE,                 /**< Message class none*/
 };
 
 /**
- *     @brief  Represents the type of Message. More members maybe added if needed \n
- *     This enum is used as the value of msg_message_type_t.
+ *  @brief  Enumeration for the type of Message. \n
+ *          More members maybe added if needed. \n
+ *             This enum is used as the value of msg_message_type_t.
  */
 enum _MSG_MESSAGE_TYPE_E
 {
-       MSG_TYPE_INVALID = 0,                   /** < Invalid Type Message */
+       MSG_TYPE_INVALID = 0,               /** < Invalid Type Message */
+
+       MSG_TYPE_SMS,                       /** < Normal SMS Message */
+       MSG_TYPE_SMS_CB,                    /** < Cell Broadcasting SMS Message */
+       MSG_TYPE_SMS_JAVACB,                /** < JAVA Cell Broadcasting SMS Message */
+       MSG_TYPE_SMS_WAPPUSH,               /** < WAP Push SMS Message */
+       MSG_TYPE_SMS_MWI,                   /** < MWI SMS Message */
+       MSG_TYPE_SMS_SYNCML,                /** < SyncML CP SMS Message */
+       MSG_TYPE_SMS_REJECT,                /** < Reject Message */
 
-       MSG_TYPE_SMS,                                   /** < Normal SMS Message */
-       MSG_TYPE_SMS_CB,                                /** < Cell Broadcasting SMS Message */
-       MSG_TYPE_SMS_JAVACB,                    /** < JAVA Cell Broadcasting SMS Message */
-       MSG_TYPE_SMS_WAPPUSH,           /** < WAP Push SMS Message */
-       MSG_TYPE_SMS_MWI,                               /** < MWI SMS Message */
-       MSG_TYPE_SMS_SYNCML,                    /** < SyncML CP SMS Message */
-       MSG_TYPE_SMS_REJECT,                    /** < Reject Message */
+       MSG_TYPE_MMS,                       /** < Normal MMS Message */
+       MSG_TYPE_MMS_JAVA,                  /** < JAVA MMS Message */
+       MSG_TYPE_MMS_NOTI,                  /** < MMS Notification Message */
 
-       MSG_TYPE_MMS,                                   /** < Normal MMS Message */
-       MSG_TYPE_MMS_JAVA,                      /** < JAVA MMS Message */
-       MSG_TYPE_MMS_NOTI,                      /** < MMS Notification Message */
+       MSG_TYPE_SMS_ETWS_PRIMARY,          /** < CB - ETWS Primary Notification */
+       MSG_TYPE_SMS_ETWS_SECONDARY,        /** < CB - ETWS Secondary Notification */
 
-       MSG_TYPE_SMS_ETWS_PRIMARY,              /** < CB - ETWS Primary Notification */
-       MSG_TYPE_SMS_ETWS_SECONDARY,    /** < CB - ETWS Secondary Notification */
+       MSG_TYPE_SMS_CMAS_PRESIDENTIAL,     /** < CB - CMAS Presidential Alerts */
+       MSG_TYPE_SMS_CMAS_EXTREME,          /** < CB - CMAS Extreme Alerts */
+       MSG_TYPE_SMS_CMAS_SEVERE,           /** < CB - CMAS Severe Alerts */
+       MSG_TYPE_SMS_CMAS_AMBER,            /** < CB - CMAS AMBER Alerts (Child Abduction Emergency) */
+       MSG_TYPE_SMS_CMAS_TEST,             /** < CB - CMAS Test */
+       MSG_TYPE_SMS_CMAS_OPERATOR_DEFINED, /** < CB - CMAS Operator defined */
+       MSG_MESSAGE_TYPE_MAX,                       /**< Placeholder for max value of this enum */
 };
 
 /**
- *     @brief  Represents the backup type of Message. More members maybe added if needed \n
- *     This enum is used as the value of msg_message_backup_type_t.
+ *  @brief  Enumeration for the backup type of Message. More members maybe added if needed \n
+ *             This enum is used as the value of msg_message_backup_type_t.
  */
 enum _MSG_MESSAGE_BACKUP_TYPE_E
 {
-       MSG_BACKUP_TYPE_ALL = 0,
-       MSG_BACKUP_TYPE_SMS,
-       MSG_BACKUP_TYPE_MMS,
+       MSG_BACKUP_TYPE_ALL = 0,                /**< Backup all*/
+       MSG_BACKUP_TYPE_SMS,                    /**< Backup SMS*/
+       MSG_BACKUP_TYPE_MMS,                    /**< Backup MMS*/
 };
 
 /**
- *     @brief  Represents the values of an error code. \n
- *     Success code is zero, but all error codes SHOULD be negative and smaller than MSG_ERROR_BEGIN. \n
- *     This enum is used as the value of msg_error_t.
+ *  @brief  Enumeration for the values of an error code. \n
+ *             Success code is zero, but all error codes SHOULD be negative and smaller than MSG_ERROR_BEGIN. \n
+ *             This enum is used as the value of msg_error_t.
  */
 enum _MSG_ERROR_E
 {
-       MSG_SUCCESS = 0,                                /**< Successful */
-
-       MSG_ERR_NULL_MSGHANDLE = -1,    /**< Message handle is NULL */
-       MSG_ERR_NULL_POINTER = -2,              /**< Pointer is NULL */
-       MSG_ERR_NULL_MESSAGE = -3,              /**< Message is NULL */
-       MSG_ERR_INVALID_STORAGE_ID = -4,        /**< Storage ID is invalid */
-       MSG_ERR_INVALID_MSG_TYPE = -5,          /**< Message type is invalid */
-
-       MSG_ERR_INVALID_STORAGE_REG= -6,        /**< Storage registry is invalid */
-       MSG_ERR_INVALID_MESSAGE_ID = -7,        /**< Message ID is invalid */
-       MSG_ERR_INVALID_MSGHANDLE = -8, /**< Message handle is invalid */
-       MSG_ERR_INVALID_PARAMETER = -9, /**< Parameter is invalid */
-       MSG_ERR_INVALID_MESSAGE = -10,                  /**< Message is invalid */
-
-       MSG_ERR_INVALID_PLUGIN_HANDLE = -11,    /**< Plugin handle is invalid */
-       MSG_ERR_MEMORY_ERROR = -12,                     /**< Memory is error */
-       MSG_ERR_COMMUNICATION_ERROR = -13,      /**< Communication between client and server is error */
-       MSG_ERR_SIM_STORAGE_FULL = -14,         /**< SIM Storage is full */
-       MSG_ERR_TRANSPORT_ERROR = -15,                  /**< Transport event error */
-
-       MSG_ERR_CALLBACK_ERROR = -16,                   /**< Callback event error */
-       MSG_ERR_STORAGE_ERROR = -17,                    /**< Storage event error */
-       MSG_ERR_FILTER_ERROR = -18,                             /**< Filter event error */
-       MSG_ERR_MMS_ERROR = -19,                                /**< MMS event error */
-       MSG_ERR_MMPLAYER_CREATE = -20,                  /**< Multimedia Error*/
-
-       MSG_ERR_MMPLAYER_SET_ATTRS = -21,               /**< Multimedia Error*/
-       MSG_ERR_MMPLAYER_REALIZE = -22,         /**< Multimedia Error*/
-       MSG_ERR_MMPLAYER_PLAY = -23,                    /**< Multimedia Error*/
-       MSG_ERR_MMPLAYER_STOP = -24,                    /**< Multimedia Error*/
-       MSG_ERR_MMPLAYER_DESTROY = -25,         /**< Multimedia Error*/
-
-       MSG_ERR_UNKNOWN = -26,                                  /**< Unknown errors */
+       MSG_SUCCESS = 0,                        /**< Successful */
+
+       MSG_ERR_NULL_MSGHANDLE = -1,            /**< Message handle is NULL */
+       MSG_ERR_NULL_POINTER = -2,              /**< Pointer is NULL */
+       MSG_ERR_NULL_MESSAGE = -3,              /**< Message is NULL */
+       MSG_ERR_INVALID_STORAGE_ID = -4,        /**< Storage ID is invalid */
+       MSG_ERR_INVALID_MSG_TYPE = -5,          /**< Message type is invalid */
+
+       MSG_ERR_INVALID_STORAGE_REG= -6,        /**< Storage registry is invalid */
+       MSG_ERR_INVALID_MESSAGE_ID = -7,        /**< Message ID is invalid */
+       MSG_ERR_INVALID_MSGHANDLE = -8,         /**< Message handle is invalid */
+       MSG_ERR_INVALID_PARAMETER = -9,         /**< Parameter is invalid */
+       MSG_ERR_INVALID_MESSAGE = -10,          /**< Message is invalid */
+
+       MSG_ERR_INVALID_PLUGIN_HANDLE = -11,    /**< Plugin handle is invalid */
+       MSG_ERR_MEMORY_ERROR = -12,             /**< Memory is error */
+       MSG_ERR_COMMUNICATION_ERROR = -13,      /**< Communication between client and server is error */
+       MSG_ERR_SIM_STORAGE_FULL = -14,         /**< SIM Storage is full */
+       MSG_ERR_TRANSPORT_ERROR = -15,          /**< Transport event error */
+
+       MSG_ERR_CALLBACK_ERROR = -16,           /**< Callback event error */
+       MSG_ERR_STORAGE_ERROR = -17,            /**< Storage event error */
+       MSG_ERR_FILTER_ERROR = -18,             /**< Filter event error */
+       MSG_ERR_MMS_ERROR = -19,                /**< MMS event error */
+       MSG_ERR_MMPLAYER_CREATE = -20,          /**< Multimedia Error*/
+
+       MSG_ERR_MMPLAYER_SET_ATTRS = -21,       /**< Multimedia Error*/
+       MSG_ERR_MMPLAYER_REALIZE = -22,         /**< Multimedia Error*/
+       MSG_ERR_MMPLAYER_PLAY = -23,            /**< Multimedia Error*/
+       MSG_ERR_MMPLAYER_STOP = -24,            /**< Multimedia Error*/
+       MSG_ERR_MMPLAYER_DESTROY = -25,         /**< Multimedia Error*/
+
+       MSG_ERR_UNKNOWN = -26,                  /**< Unknown errors */
 
        /* Start Database Errors */
-       MSG_ERR_DB_CONNECT = -27,
-       MSG_ERR_DB_DISCONNECT = -28,
-       MSG_ERR_DB_EXEC = -29,
-       MSG_ERR_DB_GETTABLE = -30,
-
-       MSG_ERR_DB_PREPARE = -31,
-       MSG_ERR_DB_STEP = -32,
-       MSG_ERR_DB_NORECORD= -33,
-       MSG_ERR_DB_STORAGE_INIT = -34,
-       MSG_ERR_DB_MAKE_DIR = -35,
-
-       MSG_ERR_DB_ROW = -36,
-       MSG_ERR_DB_DONE = -37,
-       MSG_ERR_DB_GENERIC= -38,
-       MSG_ERR_DB_END = -39,
+       MSG_ERR_DB_CONNECT = -27,               /**< DB connect error*/
+       MSG_ERR_DB_DISCONNECT = -28,            /**< DB disconnect error*/
+       MSG_ERR_DB_EXEC = -29,                  /**< DB command execute error*/
+       MSG_ERR_DB_GETTABLE = -30,              /**< DB get-table error*/
+
+       MSG_ERR_DB_PREPARE = -31,               /**< DB prepare query error*/
+       MSG_ERR_DB_STEP = -32,                  /**< DB step query error*/
+       MSG_ERR_DB_NORECORD= -33,               /**< DB no-record error*/
+       MSG_ERR_DB_STORAGE_INIT = -34,          /**< DB storage init error*/
+       MSG_ERR_DB_MAKE_DIR = -35,              /**< mkdir error*/
+
+       MSG_ERR_DB_ROW = -36,                   /**< DB step() has another row ready */
+       MSG_ERR_DB_DONE = -37,                  /**< DB step() has finished executing */
+       MSG_ERR_DB_GENERIC= -38,                /**< Generic DB error*/
+       MSG_ERR_DB_END = -39,                   /**< DB end error*/
        /* End Database Errors */
 
        /* Start Setting Errors */
-       MSG_ERR_SET_SETTING = -40,
-       MSG_ERR_SET_SIM_SET = -41,
-       MSG_ERR_SET_READ_ERROR = -42,
-       MSG_ERR_SET_WRITE_ERROR = -43,
-       MSG_ERR_SET_DELETE_ERROR = -44,
+       MSG_ERR_SET_SETTING = -40,              /**< Error setting config data*/
+       MSG_ERR_SET_SIM_SET = -41,              /**< Error setting config data in SIM*/
+       MSG_ERR_SET_READ_ERROR = -42,           /**< Error reading config settings*/
+       MSG_ERR_SET_WRITE_ERROR = -43,          /**< Error in writing config settings*/
+       MSG_ERR_SET_DELETE_ERROR = -44,         /**< Error in deleting config settings*/
        /* End Setting Errors */
 
        /* Start Plugin Errors */
-       MSG_ERR_PLUGIN_TAPIINIT = -45,
-       MSG_ERR_PLUGIN_REGEVENT = -46,
-       MSG_ERR_PLUGIN_TRANSPORT = -47,
-       MSG_ERR_PLUGIN_STORAGE = -48,
-       MSG_ERR_PLUGIN_SETTING = -49,
-
-       MSG_ERR_PLUGIN_WAPDECODE = -50,
-       MSG_ERR_PLUGIN_TAPI_FAILED = -51,
-       MSG_ERR_PLUGIN_SIM_MSG_FULL = -52,
+       MSG_ERR_PLUGIN_TAPIINIT = -45,          /**< Telephony init error*/
+       MSG_ERR_PLUGIN_REGEVENT = -46,          /**< Register even error*/
+       MSG_ERR_PLUGIN_TRANSPORT = -47,         /**< Transport (send/receive) error*/
+       MSG_ERR_PLUGIN_STORAGE = -48,           /**< Storage error*/
+       MSG_ERR_PLUGIN_SETTING = -49,           /**< Error setting config data*/
+
+       MSG_ERR_PLUGIN_WAPDECODE = -50,         /**< WAP decode error*/
+       MSG_ERR_PLUGIN_TAPI_FAILED = -51,       /**< TAPI failure*/
+       MSG_ERR_PLUGIN_SIM_MSG_FULL = -52,      /**< SIM message full error*/
        /* End Plugin Errors */
 
-       MSG_ERR_MESSAGE_COUNT_FULL = -53,
-       MSG_ERR_READREPORT_NOT_REQUESTED = -54,
-       MSG_ERR_READREPORT_ALEADY_SENT = -55,
+       MSG_ERR_MESSAGE_COUNT_FULL = -53,       /**< Message count full*/
+       MSG_ERR_READREPORT_NOT_REQUESTED = -54, /**< Read report  not requested*/
+       MSG_ERR_READREPORT_ALEADY_SENT = -55,   /**< Read report already sent*/
+
+       MSG_ERR_FILTER_DUPLICATED = -56,        /**< Filter duplicate error */
+       MSG_ERR_PERMISSION_DENIED = -57,        /**< Permission denied*/
+       MSG_ERR_NO_SIM = -58,                   /**< No SIM*/
+
+       MSG_ERR_SERVER_NOT_READY = -59,         /**< Message server not ready*/
 
-       MSG_ERR_FILTER_DUPLICATED = -56,                                /**< Filter duplicate error */
-       MSG_ERR_SECURITY_ERROR = -57,
-       MSG_ERR_NO_SIM = -58,
-       MSG_ERR_SERVER_NOT_READY= -59,
+       MSG_ERR_STORE_RESTRICT = -60,           /**< Storage restricted error*/
+       MSG_ERR_DB_BUSY = -61,                  /**< DB file locked*/
 };
 
 
 /**
- *     @brief  Represents the values of a message priority. \n
- *     This enum is used as the value of msg_priority_type_t.
+ *  @brief  Enumeration for the values of a message priority. \n
+ *             This enum is used as the value of msg_priority_type_t.
  */
 enum _MSG_PRIORITY_TYPE_E
 {
@@ -914,29 +1331,50 @@ enum _MSG_PRIORITY_TYPE_E
 
 
 /**
- *     @brief  Represents the values of a network status. \n
- *     This enum is used as the value of msg_network_status_t.
+ *  @brief  Enumeration for the values of a message priority. \n
+ *             This enum is used as the value of msg_priority_type_t.
  */
-enum _MSG_NETWORK_STATUS_E
+enum _MSG_TAG_TYPE_E
 {
-       MSG_NETWORK_NOT_SEND = 0,               /**< Message is not sending */
-       MSG_NETWORK_SENDING,                            /**< Message is sending */
-       MSG_NETWORK_SEND_SUCCESS,               /**< Message is sent successfully */
-       MSG_NETWORK_SEND_FAIL,                  /**< Message is failed to send */
-       MSG_NETWORK_DELIVER_SUCCESS,    /**< Message is delivered */
-       MSG_NETWORK_DELIVER_FAIL,               /**< Message is failed to deliver */
-       MSG_NETWORK_RECEIVED,                   /**< Message is received */
-       MSG_NETWORK_REQ_CANCELLED,              /**< Request is cancelled */
-       MSG_NETWORK_RETRIEVING,                         /**< Message is retrieving */
-       MSG_NETWORK_RETRIEVE_SUCCESS,           /**< Message is retrieved successfully */
-       MSG_NETWORK_RETRIEVE_FAIL,                      /**< Message is failed to retrieve */
-       MSG_NETWORK_SEND_TIMEOUT,                       /**< Message is failed to send by timeout */
+       MSG_MESSAGE_TAG_NONE = 0x00,            /**< None Tag */
+       MSG_MESSAGE_TAG_PRIMARY = 0x01,         /**< Priority Tag*/
+       MSG_MESSAGE_TAG_PROMOTION = 0x02,               /**< Promotion Tag */
+       MSG_MESSAGE_TAG_FINANCE = 0x04,                 /**< Finance Tag*/
+       MSG_MESSAGE_TAG_DELIVERY = 0x08,                /**< Delivery Tag */
+       MSG_MESSAGE_TAG_EVENT =0x10,                /**< Event Tag */
 };
 
-
 /**
- *     @brief  Represents the values of an address type. \n
- *     This enum is used as the value of msg_address_type_t.
+ *  @brief  Enumeration for the values of a network status. \n
+ *             This enum is used as the value of msg_network_status_t.
+ */
+enum _MSG_NETWORK_STATUS_E
+{
+       MSG_NETWORK_NOT_SEND = 0,                            /**< Message is not sending */
+       MSG_NETWORK_SENDING,                                 /**< Sending message */
+       MSG_NETWORK_SEND_SUCCESS,                            /**< Message is sent successfully */
+       MSG_NETWORK_SEND_FAIL,                               /**< Failed to send message */
+       MSG_NETWORK_DELIVER_SUCCESS,                         /**< Message is delivered */
+       MSG_NETWORK_DELIVER_FAIL,                            /**< Failed to deliver message */
+       MSG_NETWORK_RECEIVED,                                /**< Message is received */
+       MSG_NETWORK_REQ_CANCELLED,                           /**< Request is cancelled */
+       MSG_NETWORK_RETRIEVING,                              /**< Retrieving message */
+       MSG_NETWORK_RETRIEVE_SUCCESS,                        /**< Message is retrieved successfully */
+       MSG_NETWORK_RETRIEVE_FAIL,                           /**< Failed to retrieve */
+       MSG_NETWORK_SEND_TIMEOUT,                            /**< Send timed-out*/ // WILL BE REMOVED
+       MSG_NETWORK_SEND_FAIL_MANDATORY_INFO_MISSING,        /**< Send failed due to mandatory info missing*/ // WILL BE REMOVED
+       MSG_NETWORK_SEND_FAIL_TEMPORARY,                     /**<Send failed temporarily*/ // WILL BE REMOVED
+       MSG_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD,        /**< Send failed by MO control- ALLOWED WITH MOD*/ // WILL BE REMOVED
+       MSG_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED,     /**< Send failed by MO control*/ // WILL BE REMOVED
+       MSG_NETWORK_DELIVER_PENDING,                         /**< Delivery pending*/
+       MSG_NETWORK_DELIVER_EXPIRED,                         /**< Delivery expired*/
+       MSG_NETWORK_SEND_PENDING,                            /**< Send is pending*/
+};
+
+
+/**
+ *  @brief  Enumeration for the values of an address type. \n
+ *             This enum is used as the value of msg_address_type_t.
 */
 enum _MSG_ADDRESS_TYPE_E
 {
@@ -947,21 +1385,21 @@ enum _MSG_ADDRESS_TYPE_E
 
 
 /**
- *     @brief  Represents the values of a recipient type. \n
- *     This enum is used as the value of msg_recipient_type_t.
+ *  @brief  Enumeration for the values of a recipient type. \n
+ *             This enum is used as the value of msg_recipient_type_t.
 */
 enum _MSG_RECIPIENT_TYPE_E
 {
-       MSG_RECIPIENTS_TYPE_UNKNOWN = 0,        /**< The recipient type is unknown. */
-       MSG_RECIPIENTS_TYPE_TO,                 /**< The recipient type is for "To". */
-       MSG_RECIPIENTS_TYPE_CC,                 /**< The recipient type is for "Cc". */
-       MSG_RECIPIENTS_TYPE_BCC,                        /**< The recipient type is for "Bcc". */
+       MSG_RECIPIENTS_TYPE_UNKNOWN = 0,    /**< The recipient type is unknown. */
+       MSG_RECIPIENTS_TYPE_TO,             /**< The recipient type is for "To". */
+       MSG_RECIPIENTS_TYPE_CC,             /**< The recipient type is for "Cc". */
+       MSG_RECIPIENTS_TYPE_BCC,            /**< The recipient type is for "Bcc". */
 };
 
 
 /**
- *     @brief  Represents the values of a direction type. \n
- *     This enum is used as the value of msg_direction_type_t.
+ *  @brief  Enumeration for the values of a direction type. \n
+ *             This enum is used as the value of msg_direction_type_t.
  */
 enum _MSG_DIRECTION_TYPE_E
 {
@@ -971,43 +1409,43 @@ enum _MSG_DIRECTION_TYPE_E
 
 
 /**
- *     @brief  Represents the values of a string encoding type. \n
- *     This enum is used as the value of msg_encode_type_t.
+ *  @brief  Enumeration for the values of a string encoding type. \n
+ *             This enum is used as the value of msg_encode_type_t.
  */
 enum _MSG_ENCODE_TYPE_E
 {
-       MSG_ENCODE_GSM7BIT = 0, /**< The string encoding type is GSM7BIT */
-       MSG_ENCODE_8BIT,                /**< The string encoding type is 8 BIT */
-       MSG_ENCODE_UCS2,                /**< The string encoding type is UCS2 */
-       MSG_ENCODE_AUTO,                /**< The string encoding type is AUTO */
+       MSG_ENCODE_GSM7BIT = 0,      /**< The string encoding type is GSM7BIT */
+       MSG_ENCODE_8BIT,             /**< The string encoding type is 8 BIT */
+       MSG_ENCODE_UCS2,             /**< The string encoding type is UCS2 */
+       MSG_ENCODE_AUTO,             /**< The string encoding type is AUTO */
 
        MSG_ENCODE_GSM7BIT_ABNORMAL, /**< The string encoding type is GSM7BIT, but abnormal character included */
 };
 
 
 /**
- *     @brief  Represents the action type of Push Message. \n
- *     This enum is used as the value of msg_push_action_t.
+ *  @brief  Enumeration for the action type of Push Message. \n
+ *             This enum is used as the value of msg_push_action_t.
  */
 enum _MSG_PUSH_ACTION_E
 {
        // SI Action
-       MSG_PUSH_SI_ACTION_SIGNAL_NONE = 0x00,
-       MSG_PUSH_SI_ACTION_SIGNAL_LOW,
-       MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM,
-       MSG_PUSH_SI_ACTION_SIGNAL_HIGH,
-       MSG_PUSH_SI_ACTION_DELETE,
+       MSG_PUSH_SI_ACTION_SIGNAL_NONE = 0x00,          /**<  No signal for push message action */
+       MSG_PUSH_SI_ACTION_SIGNAL_LOW,                          /**< Low signal for push message action */
+       MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM,                       /**< Medium signal for push message action */
+       MSG_PUSH_SI_ACTION_SIGNAL_HIGH,                         /**< High signal for push message action */
+       MSG_PUSH_SI_ACTION_DELETE,                                      /**< Delete push message */
 
        // SL Action
-       MSG_PUSH_SL_ACTION_EXECUTE_LOW,
-       MSG_PUSH_SL_ACTION_EXECUTE_HIGH,
-       MSG_PUSH_SL_ACTION_CACHE,
+       MSG_PUSH_SL_ACTION_EXECUTE_LOW,                         /**< Action: execute-low*/
+       MSG_PUSH_SL_ACTION_EXECUTE_HIGH,                        /**< Action: execute-high*/
+       MSG_PUSH_SL_ACTION_CACHE,                                       /**< Action: cache*/
 };
 
 
 /**
- *     @brief  Represents the type of SyncML Message. \n
- *     This enum is used as the value of msg_syncml_message_type_t.
+ *  @brief  Enumeration for the type of SyncML Message. \n
+ *             This enum is used as the value of msg_syncml_message_type_t.
  */
  enum _MSG_SYNCML_MESSAGE_TYPE_E
  {
@@ -1026,18 +1464,18 @@ enum _MSG_PUSH_ACTION_E
 
 
 /**
- *     @brief  Represents the values of a Delivery Report Status. \n
- *     This enum is used as the value of msg_delivery_report_status_t.
+ *  @brief  Enumeration for the values of a Delivery Report Status. \n
+ *             This enum is used as the value of msg_delivery_report_status_t.
 */
  enum _MSG_DELIVERY_REPORT_STATUS_E
  {
         MSG_DELIVERY_REPORT_NONE                               =       -1,     /**< Indicates the status unavailable */
         MSG_DELIVERY_REPORT_EXPIRED                    =       0,      /**< Indicates the expired status of message */
-        MSG_DELIVERY_REPORT_SUCCESS                            =       1,      /**< Indicates the success status of message */
+        MSG_DELIVERY_REPORT_SUCCESS                    =       1,      /**< Indicates the success status of message */
         MSG_DELIVERY_REPORT_REJECTED                   =       2,      /**< Indicates the rejected status of message */
         MSG_DELIVERY_REPORT_DEFERRED                   =       3,      /**< Indicates the deferred status of message */
-        MSG_DELIVERY_REPORT_UNRECOGNISED               =       4,      /**< Indicates the unrecongnised status of message */
-        MSG_DELIVERY_REPORT_INDETERMINATE              =       5,      /**< Indicates the unrecongnised status of message */
+        MSG_DELIVERY_REPORT_UNRECOGNISED               =       4,      /**< Indicates the unrecognized status of message */
+        MSG_DELIVERY_REPORT_INDETERMINATE              =       5,      /**< Indicates the intermediate status of message */
         MSG_DELIVERY_REPORT_FORWARDED                  =       6,      /**< Indicates the forwarded status of message */
         MSG_DELIVERY_REPORT_UNREACHABLE                =       7,      /**< Indicates the unreachable status of message */
         MSG_DELIVERY_REPORT_ERROR                              =       8,      /**< Indicates the error status of message */
@@ -1045,271 +1483,274 @@ enum _MSG_PUSH_ACTION_E
 
 
 /**
- *     @brief  Represents the values of a Read Report Status. \n
- *     This enum is used as the value of msg_read_report_status_t.
+ *  @brief  Enumeration for the values of a Read Report Status. \n
+ *             This enum is used as the value of msg_read_report_status_t.
 */
 enum _MSG_READ_REPORT_STATUS_E
  {
         MSG_READ_REPORT_NONE                   =       -1,       /**< Indicates the status unavailable */
         MSG_READ_REPORT_IS_READ                =       0,        /**< Indicates the message is read */
-        MSG_READ_REPORT_IS_DELETED     =       1         /**< Indicates the message is deleted */
+        MSG_READ_REPORT_IS_DELETED     =       1,        /**< Indicates the message is deleted */
+        MSG_READ_REPORT_REJECT_BY_USER =       2,        /**< Indicates read report reject by user*/
  };
 
 /**
- *     @brief  Represents the values of a Report Type. \n
- *     This enum is used as the value of msg_read_report_status_t.
+ *  @brief  Enumeration for the values of a Report Type. \n
+ *             This enum is used as the value of msg_read_report_status_t.
 */
 enum _MSG_REPORT_TYPE_E
  {
-        MSG_REPORT_TYPE_DELIVERY       =       0,        /**< Indicates the type is delivery report*/
-        MSG_REPORT_TYPE_READ   =       1,        /**< Indicates the type is read report */
-
+        MSG_REPORT_TYPE_DELIVERY       =       0,      /**< Indicates the type is delivery report*/
+        MSG_REPORT_TYPE_READ   =       1,          /**< Indicates the type is read report*/
+        MSG_REPORT_TYPE_READ_REPORT_SENT = 2,  /**< Indicates the type is read report sent*/
  };
 
 // filter
 /**
- *     @brief  Represents the values of a filter type. \n
- *     This enum is used as the value of msg_filter_type_t.
+ *  @brief  Enumeration for the values of a filter type. \n
+ *             This enum is used as the value of msg_filter_type_t.
  */
 enum _MSG_FILTER_TYPE_E
 {
-       MSG_FILTER_BY_WORD = 0,                 /**< Filtered by sub string in the text */
-       MSG_FILTER_BY_ADDRESS_SAME,                     /**< Filtered by address exactly same as */
-       MSG_FILTER_BY_ADDRESS_START,                    /**< Filtered by address start with */
-       MSG_FILTER_BY_ADDRESS_INCLUDE,                  /**< Filtered by address include */
+       MSG_FILTER_BY_WORD = 0,             /**< Filtered by sub string in the text */
+       MSG_FILTER_BY_ADDRESS_SAME,         /**< Filtered by address exactly same as */
+       MSG_FILTER_BY_ADDRESS_START,        /**< Filtered by address start with */
+       MSG_FILTER_BY_ADDRESS_INCLUDE,      /**< Filtered by address include */
+       MSG_FILTER_BY_ADDRESS_END,          /**< Filtered by address end with */
 };
 
 
 // mms
 
 /**
- *     @brief  Represents the values of a mime type.
+ *  @brief  Enumeration for the values of a MIME type.
  */
 typedef enum   _MimeType
 {
        // 0
-       MIME_ASTERISK                                                                                   = 0x0000, /**< Indicates the valid default mime type  */
+       MIME_ASTERISK                                       = 0x0000, /**< Indicates the valid default MIME type  */
 
        // 1
-       MIME_APPLICATION_XML                                                                    = 0x1000, /**< Indicates the application xml type */
-       MIME_APPLICATION_WML_XML                                                        = 0x1001,       /**< Indicates the application wml xml type  */
-       MIME_APPLICATION_XHTML_XML                                                      = 0x1002,       /**< Indicates the application xhtml xml type  */
-       MIME_APPLICATION_JAVA_VM                                                                = 0x1003, /**< Indicates the application java vm type */
-       MIME_APPLICATION_SMIL                                                           = 0x1004, /**< Indicates the application smil  type */
-       MIME_APPLICATION_JAVA_ARCHIVE                                           = 0x1005, /**< Indicates the application java archive type */
-       MIME_APPLICATION_JAVA                                                           = 0x1006, /**< Indicates the application java  type */
-       MIME_APPLICATION_OCTET_STREAM                                           = 0x1007, /**< Indicates the application octect stream type */
-       MIME_APPLICATION_STUDIOM                                                        = 0x1008, /**< Indicates the application studiom type */
-       MIME_APPLICATION_FUNMEDIA                                                       = 0x1009, /**< Indicates the application fun media type */
-       MIME_APPLICATION_MSWORD                                                         = 0x100a,       /**< Indicates the application ms word type */
-       MIME_APPLICATION_PDF                                                                    = 0x100b, /**< Indicates the application pdf type */
-       MIME_APPLICATION_SDP                                                                    = 0x100c,  /**< Indicates the application sdp type */
-       MIME_APPLICATION_RAM                                                                    = 0x100d, /**< Indicates the application ram type */
-       MIME_APPLICATION_ASTERIC                                                                = 0x100e, /**< Indicates the application as main type and generic sub type */
+       MIME_APPLICATION_XML                                = 0x1000, /**< Indicates the application XML type */
+       MIME_APPLICATION_WML_XML                            = 0x1001, /**< Indicates the application WML XML type  */
+       MIME_APPLICATION_XHTML_XML                          = 0x1002, /**< Indicates the application XHTML XML type  */
+       MIME_APPLICATION_JAVA_VM                            = 0x1003, /**< Indicates the application Java VM type */
+       MIME_APPLICATION_SMIL                               = 0x1004, /**< Indicates the application SMIL  type */
+       MIME_APPLICATION_JAVA_ARCHIVE                       = 0x1005, /**< Indicates the application Java archive type */
+       MIME_APPLICATION_JAVA                               = 0x1006, /**< Indicates the application Java  type */
+       MIME_APPLICATION_OCTET_STREAM                       = 0x1007, /**< Indicates the application octect stream type */
+       MIME_APPLICATION_STUDIOM                            = 0x1008, /**< Indicates the application studiom type */
+       MIME_APPLICATION_FUNMEDIA                           = 0x1009, /**< Indicates the application fun media type */
+       MIME_APPLICATION_MSWORD                             = 0x100a, /**< Indicates the application MS Word type */
+       MIME_APPLICATION_PDF                                = 0x100b, /**< Indicates the application PDF type */
+       MIME_APPLICATION_SDP                                = 0x100c, /**< Indicates the application SDP type */
+       MIME_APPLICATION_RAM                                = 0x100d, /**< Indicates the application RAM type */
+       MIME_APPLICATION_ASTERIC                            = 0x100e, /**< Indicates the application as main type and generic sub type */
 
        // 16
-       MIME_APPLICATION_VND_WAP_XHTMLXML                                       = 0x1100, /**< Indicates the application wap xhtml xml type */
-       MIME_APPLICATION_VND_WAP_WMLC                                           = 0x1101,  /**< Indicates the application wap wmlc type */
-       MIME_APPLICATION_VND_WAP_WMLSCRIPTC                             = 0x1102,  /**< Indicates the application wap wmlscrpitc type */
-       MIME_APPLICATION_VND_WAP_WTA_EVENTC                             = 0x1103, /**< Indicates the application wap  wta event type */
-       MIME_APPLICATION_VND_WAP_UAPROF                                 = 0x1104, /**< Indicates the application wap uaprof type */
-       MIME_APPLICATION_VND_WAP_SIC                                            = 0x1105,  /**< Indicates the application wap sic type */
-       MIME_APPLICATION_VND_WAP_SLC                                            = 0x1106, /**< Indicates the application wap slc type */
-       MIME_APPLICATION_VND_WAP_COC                                            = 0x1107, /**< Indicates the application wap coc type */
-       MIME_APPLICATION_VND_WAP_SIA                                            = 0x1108, /**< Indicates the application wap sia type */
-       MIME_APPLICATION_VND_WAP_CONNECTIVITY_WBXML             = 0x1109,  /**< Indicates the application wap connectivity wbxml type */
-       MIME_APPLICATION_VND_WAP_MULTIPART_FORM_DATA    = 0x110a, /**< Indicates the application wap multipart data type */
-       MIME_APPLICATION_VND_WAP_MULTIPART_BYTERANGES   = 0x110b, /**< Indicates the application wap multipart byte type */
-       MIME_APPLICATION_VND_WAP_MULTIPART_MIXED                        = 0x110c,  /**< Indicates the application wap multipart mixed type */
-       MIME_APPLICATION_VND_WAP_MULTIPART_RELATED              = 0x110d,  /**< Indicates the application wap multipart related type */
-       MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE  = 0x110e,  /**< Indicates the application wap  multipart alternative type */
-       MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC              = 0x110f, /**< Indicates the application wap mulitpart as main type and generic sub type */
-       MIME_APPLICATION_VND_WAP_WBXML                                  = 0x1110, /**< Indicates the application wap wbxml type */
-       MIME_APPLICATION_VND_OMA_DD_XML                                 = 0x1111, /**< Indicates the application oma dd xml type */
-       MIME_APPLICATION_VND_OMA_DRM_MESSAGE                            = 0x1112,  /**< Indicates the application oma drm message type */
-       MIME_APPLICATION_VND_OMA_DRM_CONTENT                            = 0x1113, /**< Indicates the application oma drm content type */
-       MIME_APPLICATION_VND_OMA_DRM_RIGHTS_XML                 = 0x1114, /**< Indicates the application oma drm rights xml type */
-       MIME_APPLICATION_VND_OMA_DRM_RIGHTS_WBXML               = 0x1115,  /**< Indicates the application oma drm rights wbxml type */
-       MIME_APPLICATION_VND_OMA_DRM_RO_XML                             = 0x1116, /**< Indicates the application oma drm ro xml type */
-       MIME_APPLICATION_VND_OMA_DRM_DCF                                        = 0x1117, /**< Indicates the application oma drm dcf type */
-       MIME_APPLICATION_VND_OMA_ROAPPDU_XML                            = 0x1118,  /**< Indicates the application oma roap pdu xml type */
-       MIME_APPLICATION_VND_OMA_ROAPTRIGGER_XML                        = 0x1119,       /**< Indicates the application oma roap trigger xml  type */
-       MIME_APPLICATION_VND_SMAF                                                       = 0x111a,  /**< Indicates the application smaf type */
-       MIME_APPLICATION_VND_RN_REALMEDIA                                       = 0x111b,  /**< Indicates the application rn real media type */
-       MIME_APPLICATION_VND_SUN_J2ME_JAVA_ARCHIVE              = 0x111c,  /**< Indicates the application j2me java archive type */
-       MIME_APPLICATION_VND_SAMSUNG_THEME                              = 0x111d,  /**< Indicates the application samsung theme type */
-       MIME_APPLICATION_VND_EXCEL                                                      = 0x111e,  /**< Indicates the application excel type */
-       MIME_APPLICATION_VND_POWERPOINT                                 = 0x111f,  /**< Indicates the application power point type */
-       MIME_APPLICATION_VND_MSWORD                                             = 0x1120,        /**< Indicates the application ms word type */
+       MIME_APPLICATION_VND_WAP_XHTMLXML                   = 0x1100, /**< Indicates the application wap xhtml xml type */
+       MIME_APPLICATION_VND_WAP_WMLC                       = 0x1101, /**< Indicates the application wap wmlc type */
+       MIME_APPLICATION_VND_WAP_WMLSCRIPTC                 = 0x1102, /**< Indicates the application wap wmlscrpitc type */
+       MIME_APPLICATION_VND_WAP_WTA_EVENTC                 = 0x1103, /**< Indicates the application wap  wta event type */
+       MIME_APPLICATION_VND_WAP_UAPROF                     = 0x1104, /**< Indicates the application wap uaprof type */
+       MIME_APPLICATION_VND_WAP_SIC                        = 0x1105, /**< Indicates the application wap sic type */
+       MIME_APPLICATION_VND_WAP_SLC                        = 0x1106, /**< Indicates the application wap slc type */
+       MIME_APPLICATION_VND_WAP_COC                        = 0x1107, /**< Indicates the application wap coc type */
+       MIME_APPLICATION_VND_WAP_SIA                        = 0x1108, /**< Indicates the application wap sia type */
+       MIME_APPLICATION_VND_WAP_CONNECTIVITY_WBXML         = 0x1109, /**< Indicates the application wap connectivity wbxml type */
+       MIME_APPLICATION_VND_WAP_MULTIPART_FORM_DATA        = 0x110a, /**< Indicates the application wap multipart data type */
+       MIME_APPLICATION_VND_WAP_MULTIPART_BYTERANGES       = 0x110b, /**< Indicates the application wap multipart byte type */
+       MIME_APPLICATION_VND_WAP_MULTIPART_MIXED            = 0x110c, /**< Indicates the application wap multipart mixed type */
+       MIME_APPLICATION_VND_WAP_MULTIPART_RELATED          = 0x110d, /**< Indicates the application wap multipart related type */
+       MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE      = 0x110e, /**< Indicates the application wap  multipart alternative type */
+       MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC          = 0x110f, /**< Indicates the application wap mulitpart as main type and generic sub type */
+       MIME_APPLICATION_VND_WAP_WBXML                      = 0x1110, /**< Indicates the application wap wbxml type */
+       MIME_APPLICATION_VND_OMA_DD_XML                     = 0x1111, /**< Indicates the application oma dd xml type */
+       MIME_APPLICATION_VND_OMA_DRM_MESSAGE                = 0x1112, /**< Indicates the application oma drm message type */
+       MIME_APPLICATION_VND_OMA_DRM_CONTENT                = 0x1113, /**< Indicates the application oma drm content type */
+       MIME_APPLICATION_VND_OMA_DRM_RIGHTS_XML             = 0x1114, /**< Indicates the application oma drm rights xml type */
+       MIME_APPLICATION_VND_OMA_DRM_RIGHTS_WBXML           = 0x1115, /**< Indicates the application oma drm rights wbxml type */
+       MIME_APPLICATION_VND_OMA_DRM_RO_XML                 = 0x1116, /**< Indicates the application oma drm ro xml type */
+       MIME_APPLICATION_VND_OMA_DRM_DCF                    = 0x1117, /**< Indicates the application oma drm dcf type */
+       MIME_APPLICATION_VND_OMA_ROAPPDU_XML                = 0x1118, /**< Indicates the application oma roap pdu xml type */
+       MIME_APPLICATION_VND_OMA_ROAPTRIGGER_XML            = 0x1119, /**< Indicates the application oma roap trigger xml  type */
+       MIME_APPLICATION_VND_SMAF                           = 0x111a, /**< Indicates the application smaf type */
+       MIME_APPLICATION_VND_RN_REALMEDIA                   = 0x111b, /**< Indicates the application rn real media type */
+       MIME_APPLICATION_VND_SUN_J2ME_JAVA_ARCHIVE          = 0x111c, /**< Indicates the application J2ME Java archive type */
+       MIME_APPLICATION_VND_SAMSUNG_THEME                  = 0x111d, /**< Indicates the application Samsung theme type */
+       MIME_APPLICATION_VND_EXCEL                          = 0x111e, /**< Indicates the application Excel type */
+       MIME_APPLICATION_VND_POWERPOINT                     = 0x111f, /**< Indicates the application Power point type */
+       MIME_APPLICATION_VND_MSWORD                         = 0x1120, /**< Indicates the application MS Word type */
 
        // 49
-       MIME_APPLICATION_X_HDMLC                                                        = 0x1200, /**< Indicates the application x hdmlc type */
-       MIME_APPLICATION_X_X968_USERCERT                                        = 0x1201, /**< Indicates the application x x968 user certified type */
-       MIME_APPLICATION_X_WWW_FORM_URLENCODED                  = 0x1202, /**< Indicates the application x www form url encoded type */
-       MIME_APPLICATION_X_SMAF                                                         = 0x1203, /**< Indicates the application x smaf type */
-       MIME_APPLICATION_X_FLASH                                                                = 0x1204, /**< Indicates the application x flash type */
-       MIME_APPLICATION_X_EXCEL                                                                = 0x1205, /**< Indicates the application x excel type */
-       MIME_APPLICATION_X_POWERPOINT                                           = 0x1206, /**< Indicates the application x power point type */
+       MIME_APPLICATION_X_HDMLC                            = 0x1200, /**< Indicates the application x hdmlc type */
+       MIME_APPLICATION_X_X968_USERCERT                    = 0x1201, /**< Indicates the application x x968 user certified type */
+       MIME_APPLICATION_X_WWW_FORM_URLENCODED              = 0x1202, /**< Indicates the application x www form url encoded type */
+       MIME_APPLICATION_X_SMAF                             = 0x1203, /**< Indicates the application x smaf type */
+       MIME_APPLICATION_X_FLASH                            = 0x1204, /**< Indicates the application x flash type */
+       MIME_APPLICATION_X_EXCEL                            = 0x1205, /**< Indicates the application x excel type */
+       MIME_APPLICATION_X_POWERPOINT                       = 0x1206, /**< Indicates the application x power point type */
 
        // 56
-       MIME_AUDIO_BASIC                                                                                = 0x2000, /**< Indicates the audio basic type  */
-       MIME_AUDIO_MPEG                                                                         = 0x2001, /**< Indicates the audio mpeg type  */
-       MIME_AUDIO_MP3                                                                          = 0x2002, /**< Indicates the audio mp3 type  */
-       MIME_AUDIO_MPG3                                                                         = 0x2003,  /**< Indicates the audio mpg3 type  */
-       MIME_AUDIO_MPEG3                                                                                = 0x2004, /**< Indicates the audio mpeg3 type  */
-       MIME_AUDIO_MPG                                                                          = 0x2005, /**< Indicates the audio mpg type  */
-       MIME_AUDIO_AAC                                                                          = 0x2006, /**< Indicates the audio aac type  */
-       MIME_AUDIO_G72                                                                          = 0x2007, /**< Indicates the audio g72 type  */
-       MIME_AUDIO_AMR                                                                          = 0x2008, /**< Indicates the audio amr type  */
-       MIME_AUDIO_AMR_WB                                                                       = 0x2009, /**< Indicates the audio amr wb type  */
-       MIME_AUDIO_MMF                                                                          = 0x200a, /**< Indicates the audio mmf type  */
-       MIME_AUDIO_SMAF                                                                         = 0x200b, /**< Indicates the audio smaf type  */
-       MIME_AUDIO_IMELODY                                                                      = 0x200c, /**< Indicates the audio imelody type  */
-       MIME_AUDIO_IMELODY2                                                                     = 0x200d, /**< Indicates the audio imelody2 type  */
-       MIME_AUDIO_MELODY                                                                       = 0x200e, /**< Indicates the audio melody type  */
-       MIME_AUDIO_MID                                                                          = 0x200f, /**< Indicates the audio mid type  */
-       MIME_AUDIO_MIDI                                                                         = 0x2010, /**< Indicates the audio midi type  */
-       MIME_AUDIO_SP_MIDI                                                                      = 0x2011, /**< Indicates the audio sp midi type  */
-       MIME_AUDIO_WAVE                                                                         = 0x2012, /**< Indicates the audio wave type  */
-       MIME_AUDIO_WAV                                                                          = 0x2013, /**< Indicates the audio wav type  */
-       MIME_AUDIO_3GPP                                                                         = 0x2014, /**< Indicates the audio 3gpp type  */
-       MIME_AUDIO_MP4                                                                          = 0x2015, /**< Indicates the audio mp4 type  */
-       MIME_AUDIO_MP4A_LATM                                                            = 0x2016, /**< Indicates the audio mp4 latm type  */
-       MIME_AUDIO_M4A                                                                          = 0x2017, /**< Indicates the audio m4a type  */
-       MIME_AUDIO_MPEG4                                                                                = 0x2018, /**< Indicates the audio mpeg4 type  */
-       MIME_AUDIO_WMA                                                                          = 0x2019, /**< Indicates the audio wma type  */
-       MIME_AUDIO_XMF                                                                          = 0x201a, /**< Indicates the audio xmf type  */
-       MIME_AUDIO_IMY                                                                          = 0x201b, /**< Indicates the audio imy type  */
-       MIME_AUDIO_MOBILE_XMF                                                           = 0x201c, /**< Indicates the audio mobile xmf type  */
+       MIME_AUDIO_BASIC                                    = 0x2000, /**< Indicates the audio basic type  */
+       MIME_AUDIO_MPEG                                     = 0x2001, /**< Indicates the audio mpeg type  */
+       MIME_AUDIO_MP3                                      = 0x2002, /**< Indicates the audio mp3 type  */
+       MIME_AUDIO_MPG3                                     = 0x2003, /**< Indicates the audio mpg3 type  */
+       MIME_AUDIO_MPEG3                                    = 0x2004, /**< Indicates the audio mpeg3 type  */
+       MIME_AUDIO_MPG                                      = 0x2005, /**< Indicates the audio mpg type  */
+       MIME_AUDIO_AAC                                      = 0x2006, /**< Indicates the audio aac type  */
+       MIME_AUDIO_G72                                      = 0x2007, /**< Indicates the audio g72 type  */
+       MIME_AUDIO_AMR                                      = 0x2008, /**< Indicates the audio amr type  */
+       MIME_AUDIO_AMR_WB                                   = 0x2009, /**< Indicates the audio amr wb type  */
+       MIME_AUDIO_MMF                                      = 0x200a, /**< Indicates the audio mmf type  */
+       MIME_AUDIO_SMAF                                     = 0x200b, /**< Indicates the audio smaf type  */
+       MIME_AUDIO_IMELODY                                  = 0x200c, /**< Indicates the audio imelody type  */
+       MIME_AUDIO_IMELODY2                                 = 0x200d, /**< Indicates the audio imelody2 type  */
+       MIME_AUDIO_MELODY                                   = 0x200e, /**< Indicates the audio melody type  */
+       MIME_AUDIO_MID                                      = 0x200f, /**< Indicates the audio mid type  */
+       MIME_AUDIO_MIDI                                     = 0x2010, /**< Indicates the audio midi type  */
+       MIME_AUDIO_SP_MIDI                                  = 0x2011, /**< Indicates the audio sp midi type  */
+       MIME_AUDIO_WAVE                                     = 0x2012, /**< Indicates the audio wave type  */
+       MIME_AUDIO_WAV                                      = 0x2013, /**< Indicates the audio wav type  */
+       MIME_AUDIO_3GPP                                     = 0x2014, /**< Indicates the audio 3gpp type  */
+       MIME_AUDIO_MP4                                      = 0x2015, /**< Indicates the audio mp4 type  */
+       MIME_AUDIO_MP4A_LATM                                = 0x2016, /**< Indicates the audio mp4 latm type  */
+       MIME_AUDIO_M4A                                      = 0x2017, /**< Indicates the audio m4a type  */
+       MIME_AUDIO_MPEG4                                    = 0x2018, /**< Indicates the audio mpeg4 type  */
+       MIME_AUDIO_WMA                                      = 0x2019, /**< Indicates the audio wma type  */
+       MIME_AUDIO_XMF                                      = 0x201a, /**< Indicates the audio xmf type  */
+       MIME_AUDIO_IMY                                      = 0x201b, /**< Indicates the audio imy type  */
+       MIME_AUDIO_MOBILE_XMF                               = 0x201c, /**< Indicates the audio mobile xmf type  */
 
        //85
-       MIME_AUDIO_VND_RN_REALAUDIO                                             = 0x2100, /**< Indicates the audio rn real audio type  */
+       MIME_AUDIO_VND_RN_REALAUDIO                         = 0x2100, /**< Indicates the audio rn real audio type  */
 
        // 86
-       MIME_AUDIO_X_MPEG                                                                       = 0x2200, /**< Indicates the audio x mpeg type  */
-       MIME_AUDIO_X_MP3                                                                                = 0x2201, /**< Indicates the audio x mp3 type  */
-       MIME_AUDIO_X_MPEG3                                                                      = 0x2202,    /**< Indicates the audio x mpeg3 type  */
-       MIME_AUDIO_X_MPG                                                                                = 0x2203, /**< Indicates the audio x mpg type  */
-       MIME_AUDIO_X_AMR                                                                                = 0x2204, /**< Indicates the audio x amr type  */
-       MIME_AUDIO_X_MMF                                                                                = 0x2205, /**< Indicates the audio x mmf type  */
-       MIME_AUDIO_X_SMAF                                                                       = 0x2206, /**< Indicates the audio x smaf type  */
-       MIME_AUDIO_X_IMELODY                                                                    = 0x2207, /**< Indicates the audio x imelody type  */
-       MIME_AUDIO_X_MIDI                                                                               = 0x2208, /**< Indicates the audio x midi type  */
-       MIME_AUDIO_X_MPEGAUDIO                                                          = 0x2209, /**< Indicates the audio x mpeg  type  */
-       MIME_AUDIO_X_PN_REALAUDIO                                                       = 0x220a, /**< Indicates the audio x pn real audio type  */
-       MIME_AUDIO_X_PN_MULTIRATE_REALAUDIO                             = 0x220b, /**< Indicates the audio x pn multirate real audio  type  */
-       MIME_AUDIO_X_PN_MULTIRATE_REALAUDIO_LIVE                        = 0x220c, /**< Indicates the audio x pn multirate real audio live type  */
-       MIME_AUDIO_X_WAVE                                                                       = 0x220d, /**< Indicates the audio x wave  type  */
-       MIME_AUDIO_X_WAV                                                                                = 0x220e, /**< Indicates the audio x wav  type  */
-       MIME_AUDIO_X_MS_WMA                                                                     = 0x220f, /**< Indicates the audio ms wma type  */
-       MIME_AUDIO_X_MID                                                                                = 0x2210, /**< Indicates the audio mid type  */
-       MIME_AUDIO_X_MS_ASF                                                                     = 0x2211, /**< Indicates the audio ms asf  type  */
-       MIME_AUDIO_X_XMF                                                                                = 0x2212, /**< Indicates the audio x xmf  type  */
+       MIME_AUDIO_X_MPEG                                   = 0x2200, /**< Indicates the audio x mpeg type  */
+       MIME_AUDIO_X_MP3                                    = 0x2201, /**< Indicates the audio x mp3 type  */
+       MIME_AUDIO_X_MPEG3                                  = 0x2202, /**< Indicates the audio x mpeg3 type  */
+       MIME_AUDIO_X_MPG                                    = 0x2203, /**< Indicates the audio x mpg type  */
+       MIME_AUDIO_X_AMR                                    = 0x2204, /**< Indicates the audio x amr type  */
+       MIME_AUDIO_X_MMF                                    = 0x2205, /**< Indicates the audio x mmf type  */
+       MIME_AUDIO_X_SMAF                                   = 0x2206, /**< Indicates the audio x smaf type  */
+       MIME_AUDIO_X_IMELODY                                = 0x2207, /**< Indicates the audio x imelody type  */
+       MIME_AUDIO_X_MIDI                                   = 0x2208, /**< Indicates the audio x midi type  */
+       MIME_AUDIO_X_MPEGAUDIO                              = 0x2209, /**< Indicates the audio x mpeg  type  */
+       MIME_AUDIO_X_PN_REALAUDIO                           = 0x220a, /**< Indicates the audio x pn real audio type  */
+       MIME_AUDIO_X_PN_MULTIRATE_REALAUDIO                 = 0x220b, /**< Indicates the audio x pn multirate real audio  type  */
+       MIME_AUDIO_X_PN_MULTIRATE_REALAUDIO_LIVE            = 0x220c, /**< Indicates the audio x pn multirate real audio live type  */
+       MIME_AUDIO_X_WAVE                                   = 0x220d, /**< Indicates the audio x wave  type  */
+       MIME_AUDIO_X_WAV                                    = 0x220e, /**< Indicates the audio x wav  type  */
+       MIME_AUDIO_X_MS_WMA                                 = 0x220f, /**< Indicates the audio ms wma type  */
+       MIME_AUDIO_X_MID                                    = 0x2210, /**< Indicates the audio mid type  */
+       MIME_AUDIO_X_MS_ASF                                 = 0x2211, /**< Indicates the audio ms asf  type  */
+       MIME_AUDIO_X_XMF                                    = 0x2212, /**< Indicates the audio x xmf  type  */
 
        // 105
-       MIME_IMAGE_GIF                                                                          = 0x3000, /**< Indicates the image gif type  */
-       MIME_IMAGE_JPEG                                                                         = 0x3001, /**< Indicates the image jpeg type  */
-       MIME_IMAGE_JPG                                                                          = 0x3002, /**< Indicates the image jpg type  */
-       MIME_IMAGE_TIFF                                                                         = 0x3003, /**< Indicates the image tiff type  */
-       MIME_IMAGE_TIF                                                                          = 0x3004, /**< Indicates the image tif type  */
-       MIME_IMAGE_PNG                                                                          = 0x3005, /**< Indicates the image png type  */
-       MIME_IMAGE_WBMP                                                                         = 0x3006, /**< Indicates the image wbmp type  */
-       MIME_IMAGE_PJPEG                                                                                = 0x3007, /**< Indicates the image pjpeg type  */
-       MIME_IMAGE_BMP                                                                          = 0x3008, /**< Indicates the image bmp type  */
-       MIME_IMAGE_SVG                                                                          = 0x3009, /**< Indicates the image svg type  */
-       MIME_IMAGE_SVG1                                                                         = 0x300a, /**< Indicates the image svg1 type  */
+       MIME_IMAGE_GIF                                      = 0x3000, /**< Indicates the image gif type  */
+       MIME_IMAGE_JPEG                                     = 0x3001, /**< Indicates the image jpeg type  */
+       MIME_IMAGE_JPG                                      = 0x3002, /**< Indicates the image jpg type  */
+       MIME_IMAGE_TIFF                                     = 0x3003, /**< Indicates the image tiff type  */
+       MIME_IMAGE_TIF                                      = 0x3004, /**< Indicates the image tif type  */
+       MIME_IMAGE_PNG                                      = 0x3005, /**< Indicates the image png type  */
+       MIME_IMAGE_WBMP                                     = 0x3006, /**< Indicates the image wbmp type  */
+       MIME_IMAGE_PJPEG                                    = 0x3007, /**< Indicates the image pjpeg type  */
+       MIME_IMAGE_BMP                                      = 0x3008, /**< Indicates the image bmp type  */
+       MIME_IMAGE_SVG                                      = 0x3009, /**< Indicates the image svg type  */
+       MIME_IMAGE_SVG1                                     = 0x300a, /**< Indicates the image svg1 type  */
 
        // 116
-       MIME_IMAGE_VND_WAP_WBMP                                                 = 0x3100,  /**< Indicates the image vnd wap wbmp type  */
-       MIME_IMAGE_VND_TMO_GIF                                                          = 0x3101,  /**< Indicates the image vnd tmo gif type  */
-       MIME_IMAGE_VND_TMO_JPG                                                          = 0x3102,  /**< Indicates the image vnd tmo jpg type  */
+       MIME_IMAGE_VND_WAP_WBMP                             = 0x3100, /**< Indicates the image vnd wap wbmp type  */
+       MIME_IMAGE_VND_TMO_GIF                              = 0x3101, /**< Indicates the image vnd tmo gif type  */
+       MIME_IMAGE_VND_TMO_JPG                              = 0x3102, /**< Indicates the image vnd tmo jpg type  */
 
        // 119
-       MIME_IMAGE_X_BMP                                                                                = 0x3200, /**< Indicates the image x bmp type  */
+       MIME_IMAGE_X_BMP                                    = 0x3200, /**< Indicates the image x bmp type  */
 
        // 120
-       MIME_MESSAGE_RFC822                                                                     = 0x4000,  /**< Indicates the message rfc822 type  */
+       MIME_MESSAGE_RFC822                                 = 0x4000, /**< Indicates the message rfc822 type  */
 
        // 121
-       MIME_MULTIPART_MIXED                                                                    = 0x5000,  /**< Indicates the multipart mixed type  */
-       MIME_MULTIPART_RELATED                                                          = 0x5001, /**< Indicates the multipart related type  */
-       MIME_MULTIPART_ALTERNATIVE                                                      = 0x5002, /**< Indicates the multipart alternative type  */
-       MIME_MULTIPART_FORM_DATA                                                        = 0x5003, /**< Indicates the multipart form data type  */
-       MIME_MULTIPART_BYTERANGE                                                        = 0x5004, /**< Indicates the multipart byte range type  */
-       MIME_MULTIPART_REPORT                                                           = 0x5005, /**< Indicates the multipart report type  */
-       MIME_MULTIPART_VOICE_MESSAGE                                            = 0x5006, /**< Indicates the multipart voice message type  */
+       MIME_MULTIPART_MIXED                                = 0x5000, /**< Indicates the multipart mixed type  */
+       MIME_MULTIPART_RELATED                              = 0x5001, /**< Indicates the multipart related type  */
+       MIME_MULTIPART_ALTERNATIVE                          = 0x5002, /**< Indicates the multipart alternative type  */
+       MIME_MULTIPART_FORM_DATA                            = 0x5003, /**< Indicates the multipart form data type  */
+       MIME_MULTIPART_BYTERANGE                            = 0x5004, /**< Indicates the multipart byte range type  */
+       MIME_MULTIPART_REPORT                               = 0x5005, /**< Indicates the multipart report type  */
+       MIME_MULTIPART_VOICE_MESSAGE                        = 0x5006, /**< Indicates the multipart voice message type  */
 
        // 128
-       MIME_TEXT_TXT                                                                                   = 0x6000, /**< Indicates the text txt type  */
-       MIME_TEXT_HTML                                                                          = 0x6001, /**< Indicates the text html type  */
-       MIME_TEXT_PLAIN                                                                         = 0x6002,  /**< Indicates the text plain type  */
-       MIME_TEXT_CSS                                                                                   = 0x6003,  /**< Indicates the text css type  */
-       MIME_TEXT_XML                                                                                   = 0x6004,  /**< Indicates the text xml type  */
-       MIME_TEXT_IMELODY                                                                               = 0x6005,  /**< Indicates the text imelody type  */
+       MIME_TEXT_TXT                                       = 0x6000, /**< Indicates the text txt type  */
+       MIME_TEXT_HTML                                      = 0x6001, /**< Indicates the text html type  */
+       MIME_TEXT_PLAIN                                     = 0x6002, /**< Indicates the text plain type  */
+       MIME_TEXT_CSS                                       = 0x6003, /**< Indicates the text css type  */
+       MIME_TEXT_XML                                       = 0x6004, /**< Indicates the text xml type  */
+       MIME_TEXT_IMELODY                                   = 0x6005, /**< Indicates the text imelody type  */
+       MIME_TEXT_CALENDAR                                  = 0x6006, /**< Indicates the text calendar type */
 
        // 134
-       MIME_TEXT_VND_WAP_WMLSCRIPT                                             = 0x6100, /**< Indicates the text wap wmlscript  type  */
-       MIME_TEXT_VND_WAP_WML                                                           = 0x6101, /**< Indicates the text wap wml  type  */
-       MIME_TEXT_VND_WAP_WTA_EVENT                                             = 0x6102, /**< Indicates the text wap wta event  type  */
-       MIME_TEXT_VND_WAP_CONNECTIVITY_XML                              = 0x6103, /**< Indicates the text wap connectivity xml  type  */
-       MIME_TEXT_VND_WAP_SI                                                                    = 0x6104,  /**< Indicates the text wap si  type  */
-       MIME_TEXT_VND_WAP_SL                                                            = 0x6105, /**< Indicates the text wap sl  type  */
-       MIME_TEXT_VND_WAP_CO                                                            = 0x6106, /**< Indicates the text wap co  type  */
-       MIME_TEXT_VND_SUN_J2ME_APP_DESCRIPTOR                           = 0x6107, /**< Indicates the text sun j2me type  */
+       MIME_TEXT_VND_WAP_WMLSCRIPT                         = 0x6100, /**< Indicates the text wap wmlscript  type  */
+       MIME_TEXT_VND_WAP_WML                               = 0x6101, /**< Indicates the text wap wml  type  */
+       MIME_TEXT_VND_WAP_WTA_EVENT                         = 0x6102, /**< Indicates the text wap wta event  type  */
+       MIME_TEXT_VND_WAP_CONNECTIVITY_XML                  = 0x6103, /**< Indicates the text wap connectivity xml  type  */
+       MIME_TEXT_VND_WAP_SI                                = 0x6104, /**< Indicates the text wap si  type  */
+       MIME_TEXT_VND_WAP_SL                                = 0x6105, /**< Indicates the text wap sl  type  */
+       MIME_TEXT_VND_WAP_CO                                = 0x6106, /**< Indicates the text wap co  type  */
+       MIME_TEXT_VND_SUN_J2ME_APP_DESCRIPTOR               = 0x6107, /**< Indicates the text sun j2me type  */
 
        // 142
-       MIME_TEXT_X_HDML                                                                                = 0x6200, /**< Indicates the x html  type  */
-       MIME_TEXT_X_VCALENDAR                                                           = 0x6201,  /**< Indicates the x calendar  type  */
-       MIME_TEXT_X_VCARD                                                                       = 0x6202, /**< Indicates the x vcard  type  */
-       MIME_TEXT_X_IMELODY                                                                     = 0x6203, /**< Indicates the x imelody  type  */
-       MIME_TEXT_X_IMELODY2                                                                    = 0x6204, /**< Indicates the x imelody2  type  */
-       MIME_TEXT_X_VNOTE                                                                       = 0x6205,  /**< Indicates the x vnote  type  */
-
-       // 148
-       MIME_VIDEO_MPEG4                                                                                = 0x7000, /**< Indicates the mpeg4  type  */
-       MIME_VIDEO_MP4                                                                          = 0x7001, /**< Indicates the mp4  type  */
-       MIME_VIDEO_H263                                                                         = 0x7002, /**< Indicates the h263  type  */
-       MIME_VIDEO_3GPP                                                                         = 0x7003, /**< Indicates the 3gpp  type  */
-       MIME_VIDEO_3GP                                                                          = 0x7004, /**< Indicates the 3gp  type  */
-       MIME_VIDEO_AVI                                                                          = 0x7005, /**< Indicates the avi  type  */
-       MIME_VIDEO_SDP                                                                          = 0x7006, /**< Indicates the sdp  type  */
-       MIME_VIDEO_MP4_ES                                                                       = 0x7007, /**< Indicates the mp4 es  type  */
-       MIME_VIDEO_MPEG                                                                         = 0x7008, /**< Indicates the mpeg  type  */
-
-       // 157
-       MIME_VIDEO_VND_RN_REALVIDEO                                                     = 0x7100, /**< Indicates the pn real video type  */
-       MIME_VIDEO_VND_RN_REALMEDIA                                                     = 0x7101, /**< Indicates the pn multi rate real media type  */
-
-       // 159
-       MIME_VIDEO_X_MP4                                                                                = 0x7200, /**< Indicates the video x mp4 type  */
-       MIME_VIDEO_X_PV_MP4                                                                     = 0x7201, /**< Indicates the video x pv mp4 type  */
-       MIME_VIDEO_X_PN_REALVIDEO                                                       = 0x7202, /**< Indicates the x pn real video type  */
-       MIME_VIDEO_X_PN_MULTIRATE_REALVIDEO                             = 0x7203, /**< Indicates the x pn multi rate real video type  */
-       MIME_VIDEO_X_MS_WMV                                                                     = 0x7204, /**< Indicates the x ms wmv type  */
-       MIME_VIDEO_X_MS_ASF                                                                     = 0x7205, /**< Indicates the x ms asf type  */
-       MIME_VIDEO_X_PV_PVX                                                                     = 0x7206, /**< Indicates the x pv pvx type  */
-
-       MIME_TYPE_VALUE_MAX                                                                     = 0x7207,               /**< Indicates the maximum mime type  */
-       MIME_UNKNOWN                                                                                    = 0xffff        /**< Indicates the unknown mime type  */
+       MIME_TEXT_X_HDML                                    = 0x6200, /**< Indicates the x html  type  */
+       MIME_TEXT_X_VCALENDAR                               = 0x6201, /**< Indicates the x calendar  type  */
+       MIME_TEXT_X_VCARD                                   = 0x6202, /**< Indicates the x vcard  type  */
+       MIME_TEXT_X_IMELODY                                 = 0x6203, /**< Indicates the x imelody  type  */
+       MIME_TEXT_X_IMELODY2                                = 0x6204, /**< Indicates the x imelody2  type  */
+       MIME_TEXT_X_VNOTE                                   = 0x6205, /**< Indicates the x vnote  type  */
+       MIME_TEXT_X_VTODO                                   = 0x6206, /**< Indicates the x todo  type  */
+
+       // 149
+       MIME_VIDEO_MPEG4                                    = 0x7000, /**< Indicates the mpeg4  type  */
+       MIME_VIDEO_MP4                                      = 0x7001, /**< Indicates the mp4  type  */
+       MIME_VIDEO_H263                                     = 0x7002, /**< Indicates the h263  type  */
+       MIME_VIDEO_3GPP                                     = 0x7003, /**< Indicates the 3gpp  type  */
+       MIME_VIDEO_3GP                                      = 0x7004, /**< Indicates the 3gp  type  */
+       MIME_VIDEO_AVI                                      = 0x7005, /**< Indicates the avi  type  */
+       MIME_VIDEO_SDP                                      = 0x7006, /**< Indicates the sdp  type  */
+       MIME_VIDEO_MP4_ES                                   = 0x7007, /**< Indicates the mp4 es  type  */
+       MIME_VIDEO_MPEG                                     = 0x7008, /**< Indicates the mpeg  type  */
+       MIME_VIDEO_MOV                                      = 0x7009, /**< Indicates the mov  type  */
+
+       // 158
+       MIME_VIDEO_VND_RN_REALVIDEO                         = 0x7100, /**< Indicates the pn real video type  */
+       MIME_VIDEO_VND_RN_REALMEDIA                         = 0x7101, /**< Indicates the pn multi rate real media type  */
+
+       // 160
+       MIME_VIDEO_X_MP4                                    = 0x7200, /**< Indicates the video x mp4 type  */
+       MIME_VIDEO_X_PV_MP4                                 = 0x7201, /**< Indicates the video x pv mp4 type  */
+       MIME_VIDEO_X_PN_REALVIDEO                           = 0x7202, /**< Indicates the x pn real video type  */
+       MIME_VIDEO_X_PN_MULTIRATE_REALVIDEO                 = 0x7203, /**< Indicates the x pn multi rate real video type  */
+       MIME_VIDEO_X_MS_WMV                                 = 0x7204, /**< Indicates the x ms wmv type  */
+       MIME_VIDEO_X_MS_ASF                                 = 0x7205, /**< Indicates the x ms asf type  */
+       MIME_VIDEO_X_PV_PVX                                 = 0x7206, /**< Indicates the x pv pvx type  */
+
+       MIME_TYPE_VALUE_MAX                                 = 0x7207, /**< Indicates the maximum MIME type  */
+       MIME_UNKNOWN                                        = 0xffff  /**< Indicates the unknown MIME type  */
 
 } MimeType;
 
 /**
- *     @brief  Represents the values of a DRM type.
+ *  @brief  Enumeration for the values of a DRM type.
  */
-//#ifdef __SUPPORT_DRM__
 typedef enum
 {
-       MSG_DRM_TYPE_NONE       = 0, /**< Indicates the drm type none */
+       MSG_DRM_TYPE_NONE       = 0, /**< Indicates the DRM type none */
        MSG_DRM_TYPE_FL         = 1, /**< Indicates the forward lock */         /* 2004-07-09: forwardLock type */
        MSG_DRM_TYPE_CD         = 2, /**< Indicates the combined delivery */    /* 2004-07-09: combined delivery type */
        MSG_DRM_TYPE_SD         = 3, /**< Indicates the separate delivery */    /* 2004-07-09: seperate delivery type */
-       MSG_DRM_TYPE_SSD        = 4     /**< Indicates the special separate delivery */ // 2005-02-28: add Special Sperate Delivery
+       MSG_DRM_TYPE_SSD        = 4      /**< Indicates the special separate delivery */        // 2005-02-28: add Special Sperate Delivery
 }MsgDrmType;
-//#endif
 
 /**
- *     @brief  Represents the values of a SMIL region type.
+ *  @brief  Enumeration for the values of a SMIL region type.
  */
 typedef enum _REGION_FIT_TYPE_T
 {
@@ -1319,344 +1760,425 @@ typedef enum _REGION_FIT_TYPE_T
 
 
 /**
- *     @brief  Represents the values of a SMIL media type.
+ *  @brief  Enumeration for the values of a SMIL media type.
  */
 typedef enum
 {
-       MMS_SMIL_MEDIA_INVALID = 0, /**< Indicates the invalid media type */
-       MMS_SMIL_MEDIA_IMG,                     /**< Indicates the image media */
-       MMS_SMIL_MEDIA_AUDIO,           /**< Indicates the audio media */
-       MMS_SMIL_MEDIA_VIDEO,           /**< Indicates the video media */
-       MMS_SMIL_MEDIA_TEXT,            /**< Indicates the text media */
-       MMS_SMIL_MEDIA_ANIMATE,         /**< Indicates the animation media */
-       MMS_SMIL_MEDIA_IMG_OR_VIDEO     , /**< Indicates the image or video media */
-       MMS_SMIL_MEDIA_MAX = 0xffffffff,        /**< Indicates the maximum media type */
+       MMS_SMIL_MEDIA_INVALID = 0,       /**< Indicates the invalid media type */
+       MMS_SMIL_MEDIA_IMG,               /**< Indicates the image media */
+       MMS_SMIL_MEDIA_AUDIO,             /**< Indicates the audio media */
+       MMS_SMIL_MEDIA_VIDEO,             /**< Indicates the video media */
+       MMS_SMIL_MEDIA_TEXT,              /**< Indicates the text media */
+       MMS_SMIL_MEDIA_ANIMATE,           /**< Indicates the animation media */
+       MMS_SMIL_MEDIA_IMG_OR_VIDEO     ,     /**< Indicates the image or video media */
+       MMS_SMIL_MEDIA_MAX = 0xffffffff,  /**< Indicates the maximum media type */
 }MmsSmilMediaType;
 
 /**
- *     @brief  Represents the values of a SMIL transition type.
+ *  @brief  Enumeration for the values of a SMIL transition type.
  */
 typedef enum
 {
-       MMS_SMIL_TRANS_NONE = 0,                /**< Indicates the transition type none */                      /* default */
-       MMS_SMIL_TRANS_SLIDEWIPE = 1,   /**< Indicates the slide wipe transition */
-       MMS_SMIL_TRANS_BARWIPE = 2,             /**< Indicates the bar wipe transition */
+       MMS_SMIL_TRANS_NONE = 0,         /**< Indicates the transition type none */                     /* default */
+       MMS_SMIL_TRANS_SLIDEWIPE = 1,    /**< Indicates the slide wipe transition */
+       MMS_SMIL_TRANS_BARWIPE = 2,      /**< Indicates the bar wipe transition */
        MMS_SMIL_TRANS_BARNDOORWIPE = 3, /**< Indicates the bar and door wipe transition */
-       MMS_SMIL_TRANS_FADE = 4,                /**< Indicates the fade transition */
-       MMS_SMIL_TRANS_RANDOMBLOCK = 5, /**< Indicates the random block transition */
-       MMS_SMIL_TRANS_ZOOMIN = 6,              /**< Indicates the zoom in transition */
-       MMS_SMIL_TRANS_IRISWIPE = 7,    /**< Indicates the iris wipe transition */
-       MMS_SMIL_TRANS_BOXWIPE = 8,             /**< Indicates the box wipe transition */
-       MMS_SMIL_TRANS_FOURBOXWIPE = 9, /**< Indicates the four box wipe transition */
-       MMS_SMIL_TRANS_PUSHWIPE  =10,   /**< Indicates the push wipe transition */
+       MMS_SMIL_TRANS_FADE = 4,         /**< Indicates the fade transition */
+       MMS_SMIL_TRANS_RANDOMBLOCK = 5,  /**< Indicates the random block transition */
+       MMS_SMIL_TRANS_ZOOMIN = 6,       /**< Indicates the zoom in transition */
+       MMS_SMIL_TRANS_IRISWIPE = 7,     /**< Indicates the iris wipe transition */
+       MMS_SMIL_TRANS_BOXWIPE = 8,      /**< Indicates the box wipe transition */
+       MMS_SMIL_TRANS_FOURBOXWIPE = 9,  /**< Indicates the four box wipe transition */
+       MMS_SMIL_TRANS_PUSHWIPE  =10,    /**< Indicates the push wipe transition */
        MMS_SMIL_TRANS_ELLIPSEWIPE  = 11 /**< Indicates the ellipse wipe transition */
 }MmsSmilTransType;
 
 /**
- *     @brief  Represents the values of a SMIL transition sub type.
+ *  @brief  Enumeration for the values of a SMIL transition sub type.
  */
 typedef enum
 {
-       MMS_SMIL_TRANS_SUB_NONE = 0,    /**< Indicates the transition sub type none */
-       MMS_SMIL_TRANS_SUB_FROM_LEFT = 1,       /**< Indicates the from left transition */      /* slideWipe's default */
-       MMS_SMIL_TRANS_SUB_FROM_TOP = 2,        /**< Indicates the from top transition */
-       MMS_SMIL_TRANS_SUB_FROM_BOTTOM = 3,     /**< Indicates the from bottom transition */
+       MMS_SMIL_TRANS_SUB_NONE = 0,          /**< Indicates the transition sub type none */
+       MMS_SMIL_TRANS_SUB_FROM_LEFT = 1,     /**< Indicates the from left transition */        /* slideWipe's default */
+       MMS_SMIL_TRANS_SUB_FROM_TOP = 2,      /**< Indicates the from top transition */
+       MMS_SMIL_TRANS_SUB_FROM_BOTTOM = 3,   /**< Indicates the from bottom transition */
        MMS_SMIL_TRANS_SUB_TOP_TO_BOTTOM = 4, /**< Indicates the from top to bottom transition */                       /* barWipe's default */
        MMS_SMIL_TRANS_SUB_BOTTOM_TO_TOP = 5, /**< Indicates the from bottom to top transition */
-       MMS_SMIL_TRANS_SUB_HORIZONTAL = 6,      /**< Indicates the horizontal transition */             /* barDoorWipe's default */
-    MMS_SMIL_TRANS_SUB_FROM_RIGHT = 7, /**< Indicates the from right transition */
-    MMS_SMIL_TRANS_SUB_VERTICAL = 8 /**< Indicates the vertical transition */
+       MMS_SMIL_TRANS_SUB_HORIZONTAL = 6,    /**< Indicates the horizontal transition */               /* barDoorWipe's default */
+    MMS_SMIL_TRANS_SUB_FROM_RIGHT = 7,    /**< Indicates the from right transition */
+    MMS_SMIL_TRANS_SUB_VERTICAL = 8       /**< Indicates the vertical transition */
 }MmsSmilTransSubType;
 
 /**
- *     @brief  Represents the values of a text font type.
+ *  @brief  Enumeration for the values of a text font type.
  */
 typedef enum
 {
-       MMS_SMIL_FONT_TYPE_NONE = 0, /**< Indicates the font type none */
-       MMS_SMIL_FONT_TYPE_NORMAL = 1, /**< Indicates the font type normal */
-       MMS_SMIL_FONT_TYPE_ITALIC = 2, /**< Indicates the font type italic */
-       MMS_SMIL_FONT_TYPE_BOLD = 3, /**< Indicates the font type bold */
+       MMS_SMIL_FONT_TYPE_NONE = 0,     /**< Indicates the font type none */
+       MMS_SMIL_FONT_TYPE_NORMAL = 1,   /**< Indicates the font type normal */
+       MMS_SMIL_FONT_TYPE_ITALIC = 2,   /**< Indicates the font type italic */
+       MMS_SMIL_FONT_TYPE_BOLD = 3,     /**< Indicates the font type bold */
        MMS_SMIL_FONT_TYPE_UNDERLINE = 4 /**< Indicates the font type underline */
 }MmsSmilFontType;
 
 /**
- *     @brief  Represents the values of a MMS text direction.
+ *  @brief  Enumeration for the values of a MMS text direction.
  */
 typedef enum   _MmsTextDir{
        MMS_TEXT_DIRECTION_INVALID = -1, /**< Indicates the invalid direction */
-       MMS_TEXT_DIRECTION_RIGHT = 0,   /**< Indicates the right direction */
-       MMS_TEXT_DIRECTION_DOWN,                /**< Indicates the down direction */            // supported to GC
+       MMS_TEXT_DIRECTION_RIGHT = 0,    /**< Indicates the right direction */
+       MMS_TEXT_DIRECTION_DOWN,         /**< Indicates the down direction */           // supported to GC
 } MmsTextDirection;
 
 /**
- *     @brief  Represents the values of MMS Read Report Sent Status.
+ *  @brief  Enumeration for the values of MMS Read Report Sent Status.
  */
 typedef enum
 {
-       MMS_RECEIVE_READ_REPORT_NO_SEND,        // didn't send yet
-       MMS_RECEIVE_READ_REPORT_MUST_SEND,      // didn't send yet but will send
-       MMS_RECEIVE_READ_REPORT_SENT,           // sent
-       MMS_RECEIVE_READ_REPORT_NO_SENT,        // required but, didn't send by user's choice
+       MMS_RECEIVE_READ_REPORT_NO_SEND,    /**< Not sent yet */
+       MMS_RECEIVE_READ_REPORT_MUST_SEND,  /**< Not sent yet, but will be sent */
+       MMS_RECEIVE_READ_REPORT_SENT,       /**< Sent */
+       MMS_RECEIVE_READ_REPORT_NO_SENT,    /**< Must be sent, but did not send by user's choice */
 } MmsRecvReadReportSendStatus ;
 
 
 // setting
 
 /**
- *     @brief  Represents the values of an option type. \n
- *     This enum is used as the value of MSG_OPTION_TYPE_T.
+ *  @brief  Enumeration for the values of an option type. \n
+ *             This enum is used as the value of MSG_OPTION_TYPE_T.
  */
 enum _MSG_OPTION_TYPE_E
 {
-       MSG_GENERAL_OPT,                        /**< General option */
-       MSG_SMS_SENDOPT,                        /**< SMS send option */
-       MSG_SMSC_LIST,                          /**< SMSC list option */
-       MSG_MMS_SENDOPT,                        /**< MMS send option */
-       MSG_MMS_RECVOPT,                        /**< MMS receive option */
-       MSG_MMS_CLASSOPT,                       /**< MMS class option such as personal, advertisement, and informational */
-       MSG_MMS_STYLEOPT,                       /**< MMS style option */
-       MSG_PUSHMSG_OPT,                        /**< Push message option */
-       MSG_CBMSG_OPT,                  /**< Cell broadcasting message option */
-       MSG_VOICEMAIL_OPT,                      /**< Voice mail option */
-       MSG_MSGSIZE_OPT,                        /**< Message size option */
+       MSG_GENERAL_OPT,            /**< General option */
+       MSG_SMS_SENDOPT,            /**< SMS send option */
+       MSG_SMSC_LIST,              /**< SMSC list option */
+       MSG_MMS_SENDOPT,            /**< MMS send option */
+       MSG_MMS_RECVOPT,            /**< MMS receive option */
+       MSG_MMS_CLASSOPT,           /**< MMS class option such as personal, advertisement, and informational */
+       MSG_MMS_STYLEOPT,           /**< MMS style option */
+       MSG_PUSHMSG_OPT,            /**< Push message option */
+       MSG_CBMSG_OPT,              /**< Cell broadcasting message option */
+       MSG_VOICEMAIL_OPT,          /**< Voice mail option */
+       MSG_MSGSIZE_OPT,            /**< Message size option */
+       MSG_OPTION_TYPE_MAX,        /**< Placeholder for max value of this enum*/
 };
 
 
 /**
- *     @brief  Represents the values of an SMS network mode. \n
- *     This enum is used as the value of MSG_SMS_NETWORK_MODE_T.
+ *  @brief  Enumeration for the values of an SMS network mode. \n
+ *             This enum is used as the value of MSG_SMS_NETWORK_MODE_T.
  */
 enum _MSG_SMS_NETWORK_MODE_E
 {
-       MSG_SMS_NETWORK_PS_ONLY = 0x01,         /**< Packet switched */
-       MSG_SMS_NETWORK_CS_ONLY = 0x02,         /**< Circuit switched */
-       MSG_SMS_NETWORK_PS_FIRST = 0x03,                /**< Packet switching preferred */
+       MSG_SMS_NETWORK_PS_ONLY = 0x01,     /**< Packet switched */
+       MSG_SMS_NETWORK_CS_ONLY = 0x02,     /**< Circuit switched */
+       MSG_SMS_NETWORK_PS_FIRST = 0x03,    /**< Packet switching preferred */
 };
 
 
 /**
- *     @brief  Represents the value of period of playing alert tone. \n
- *     The values for this type SHOULD be in MSG_ALERT_TONE_T.
+ *  @brief  Enumeration for the value of period of playing alert tone. \n
+ *             The values for this type SHOULD be in MSG_ALERT_TONE_T.
  */
 enum _MSG_ALERT_TONE_E
 {
-       MSG_ALERT_TONE_ONCE,
-       MSG_ALERT_TONE_2MINS,
-       MSG_ALERT_TONE_5MINS,
-       MSG_ALERT_TONE_10MINS,
+       MSG_ALERT_TONE_ONCE,        /**< Play alert tone once*/
+       MSG_ALERT_TONE_2MINS,       /**< Repeat alarm in 2 mins*/
+       MSG_ALERT_TONE_5MINS,       /**< Repeat alarm in 5 mins*/
+       MSG_ALERT_TONE_10MINS,      /**< Repeat alarm in 10 mins*/
 };
 
 
 /**
- *     @brief  Represents the value of a default storage to save SMS. \n
- *     The values for this type SHOULD be in MSG_SMS_SAVE_STORAGE_T.
+ *  @brief  Enumeration for the value of a default storage to save SMS. \n
+ *             The values for this type SHOULD be in MSG_SMS_SAVE_STORAGE_T.
  */
 enum _MSG_SMS_SAVE_STORAGE_E
 {
-       MSG_SMS_SAVE_STORAGE_SIM,
-       MSG_SMS_SAVE_STORAGE_PHONE,
+       MSG_SMS_SAVE_STORAGE_SIM,           /**< Save SMS to SIM*/
+       MSG_SMS_SAVE_STORAGE_PHONE,         /**< Save SMS to phone*/
 };
 
 
 /**
- *     @brief  Represents the values of the type of number for SMS center address. \n
- *     This enum is used as the value of MSG_SMS_TON_T.
+ *  @brief  Enumeration for the values of the type of number for SMS center address. \n
+ *             This enum is used as the value of MSG_SMS_TON_T.
  */
 enum _MSG_SMS_TON_E
 {
-       MSG_TON_UNKNOWN = 0,                    /**< Unknown */
-       MSG_TON_INTERNATIONAL,          /**< International */
-       MSG_TON_NATIONAL,                               /**< National */
-       MSG_TON_NETWORK,                                /**< Network */
-       MSG_TON_SUBSCRIBER,                     /**< Subscriber */
-       MSG_TON_ALPHANUMERIC,           /**< Alpha numeric */
-       MSG_TON_ABBREVIATED,                    /**< Abbreviated */
-       MSG_TON_RESERVE,                                /**< Reserve */
+       MSG_TON_UNKNOWN = 0,            /**< Unknown */
+       MSG_TON_INTERNATIONAL,          /**< International */
+       MSG_TON_NATIONAL,               /**< National */
+       MSG_TON_NETWORK,                /**< Network */
+       MSG_TON_SUBSCRIBER,             /**< Subscriber */
+       MSG_TON_ALPHANUMERIC,           /**< Alpha numeric */
+       MSG_TON_ABBREVIATED,            /**< Abbreviated */
+       MSG_TON_RESERVE,                /**< Reserve */
 };
 
 
 /**
- *     @brief  Represents the values of the numbering plan ID for SMS center address. \n
- *     This enum is used as the value of MSG_SMS_NPI_T.
+ *  @brief  Enumeration for the values of the numbering plan ID for SMS center address. \n
+ *             This enum is used as the value of MSG_SMS_NPI_T.
  */
 enum _MSG_SMS_NPI_E
 {
-       MSG_NPI_UNKNOWN = 0,                    /**< Unknown */
-       MSG_NPI_ISDN = 1,                               /**< ISDN */
-       MSG_NPI_DATA = 3,                               /**< Data */
-       MSG_NPI_TELEX = 4,                              /**< Telex */
-       MSG_NPI_SMSC = 5,                               /**< SMSC */
-       MSG_NPI_NATIONAL = 8,                   /**< National */
-       MSG_NPI_PRIVATE = 9,                    /**< Private */
-       MSG_NPI_IDENTIFICATION_ERMES = 10,              /**< Identification ermes */
-       MSG_NPI_IDENTIFICATION_RESERVED = 0xF           /**< Identification reserved */
+       MSG_NPI_UNKNOWN = 0,                        /**< Unknown */
+       MSG_NPI_ISDN = 1,                           /**< ISDN */
+       MSG_NPI_DATA = 3,                           /**< Data */
+       MSG_NPI_TELEX = 4,                          /**< Telex */
+       MSG_NPI_SMSC = 5,                           /**< SMSC */
+       MSG_NPI_NATIONAL = 8,                       /**< National */
+       MSG_NPI_PRIVATE = 9,                        /**< Private */
+       MSG_NPI_IDENTIFICATION_ERMES = 10,          /**< Identification ermes */
+       MSG_NPI_IDENTIFICATION_RESERVED = 0xF       /**< Identification reserved */
 };
 
 
 /**
- *     @brief  Represents the values of the protocol ID for SMS center address. \n
- *     This enum is used as the value of MSG_SMS_PID_T.
+ *  @brief  Enumeration for the values of the protocol ID for SMS center address. \n
+ *             This enum is used as the value of MSG_SMS_PID_T.
  */
 enum  _MSG_SMS_PID_E
 {
-       MSG_PID_NONE,           /**< None */
-       MSG_PID_TEXT,           /**< Text */
-       MSG_PID_VOICE,          /**< Voice */
-       MSG_PID_FAX,            /**< Fax */
-       MSG_PID_X400,           /**< X400 */
-       MSG_PID_ERMES,          /**< Ermes */
-       MSG_PID_EMAIL,          /**< Email */
-       MSG_PID_MAX             /**< Default */
+       MSG_PID_NONE,       /**< None */
+       MSG_PID_TEXT,       /**< Text */
+       MSG_PID_VOICE,      /**< Voice */
+       MSG_PID_FAX,        /**< Fax */
+       MSG_PID_X400,       /**< X400 */
+       MSG_PID_ERMES,      /**< Ermes */
+       MSG_PID_EMAIL,      /**< Email */
+       MSG_PID_MAX         /**< Default */
 };
 
 
 /**
- *     @brief  Represents the values of the Validity Period for SMS center. \n
- *     This enum is used as the value of MSG_VAL_PERIOD_T.
+ *  @brief  Enumeration for the values of the Validity Period for SMS center. \n
+ *             This enum is used as the value of MSG_VAL_PERIOD_T.
+ *
+ *     0 to 143 : (TP-VP + 1) x 5 minutes (i.e. 5 minutes intervals up to 12 hours)
+ *     144 to 167 : 12 hours + ((TP-VP -143) x 30 minutes)
+ *     168 to 196 : (TP-VP - 166) x 1 day
+ *     197 to 255 : (TP-VP - 192) x 1 week
+ *
  */
 enum  _MSG_VAL_PERIOD_E
 {
-       MSG_VAL_1DAY = 167,
-       MSG_VAL_2DAYS = 168,
-       MSG_VAL_1WEEK = 173,
-       MSG_VAL_2WEEKS = 180,
-       MSG_VAL_MAXIMUM = 255,
+       MSG_VAL_ZERO = 0,               /**< Validity period is zero */
+       MSG_VAL_1DAY = 167,             /**< Validity period is 1 day */
+       MSG_VAL_2DAYS = 168,            /**< Validity period is 2 days */
+       MSG_VAL_3DAYS = 169,            /**< Validity period is 3 days */
+       MSG_VAL_4DAYS = 170,            /**< Validity period is 4 days */
+       MSG_VAL_5DAYS = 171,            /**< Validity period is 5 days */
+       MSG_VAL_6DAYS = 172,            /**< Validity period is 6 days */
+       MSG_VAL_1WEEK = 173,            /**< Validity period is 1 week */
+       MSG_VAL_2WEEKS = 180,           /**< Validity period is 2 weeks */
+       MSG_VAL_3WEEKS = 187,           /**< Validity period is 3 weeks */
+       MSG_VAL_MAXIMUM = 255,          /**< Validity period is maximum */
 };
 
 
+/**
+ *  @brief  Enumeration for the values of the MMS expiry time. \n
+ *             This enum is used as the value of MSG_MMS_EXPIRY_TIME_T.
+ */
 enum  _MSG_MMS_EXPIRY_TIME_E
 {
-       MSG_EXPIRY_TIME_MAXIMUM = 0,
-       MSG_EXPIRY_TIME_1DAY = 86400,
-       MSG_EXPIRY_TIME_2DAYS = 2*86400,
-       MSG_EXPIRY_TIME_1WEEK = 604800,
-       MSG_EXPIRY_TIME_2WEEKS = 2*604800,
+       MSG_EXPIRY_TIME_MAXIMUM = 0,            /**< Expiry time is zero */
+       MSG_EXPIRY_TIME_1DAY = 86400,           /**< Expiry time is 1 day */
+       MSG_EXPIRY_TIME_2DAYS = 2*86400,        /**< Expiry time is 2 days */
+       MSG_EXPIRY_TIME_1WEEK = 604800,         /**< Expiry time is 1 week */
+       MSG_EXPIRY_TIME_2WEEKS = 2*604800,      /**< Expiry time is 2 weeks */
 };
 
 
+/**
+ *  @brief  Enumeration for the values of the MMS delivery time. \n
+ *             This enum is used as the value of MSG_MMS_DELIVERY_TIME_T.
+ */
 enum  _MSG_MMS_DELIVERY_TIME_E
 {
-       MSG_DELIVERY_TIME_IMMEDIATLY = 0,
-       MSG_DELIVERY_TIME_1HOUR = 3600,
-       MSG_DELIVERY_TIME_1DAY = 86400,
-       MSG_DELIVERY_TIME_1WEEK = 604800,
-       MSG_DELIVERY_TIME_CUSTOM
+       MSG_DELIVERY_TIME_IMMEDIATLY = 0,           /**< Immediate MMS delivery */
+       MSG_DELIVERY_TIME_1HOUR = 3600,             /**< MMS delivery in 1 hour */
+       MSG_DELIVERY_TIME_1DAY = 86400,             /**< MMS delivery in 1 day */
+       MSG_DELIVERY_TIME_1WEEK = 604800,           /**< MMS delivery in 1 week */
+       MSG_DELIVERY_TIME_CUSTOM                    /**< MMS delivery in custom time */
 };
 
 
+/**
+ *  @brief  Enumeration for the values of the MMS class type. \n
+ *             This enum is used as the value of MSG_MMS_MSG_CLASS_TYPE_T.
+ */
 enum _MSG_MMS_MSG_CLASS_TYPE_E
 {
-       MSG_CLASS_PERSONAL,                     /**<Personal message class*/
-       MSG_CLASS_ADVERTISEMENT,                /**<Advertisement message class*/
-       MSG_CLASS_INFORMATIONAL,                /**<Informational message class */
-       MSG_CLASS_AUTO,                         /**<Automatic */
-       MSG_CLASS_MAX                                   /**< */
+       MSG_CLASS_PERSONAL,             /**<Personal message class*/
+       MSG_CLASS_ADVERTISEMENT,        /**<Advertisement message class*/
+       MSG_CLASS_INFORMATIONAL,        /**<Informational message class */
+       MSG_CLASS_AUTO,                 /**<Automatic */
+       MSG_CLASS_MAX                   /**< Place-holder to indicate max number of MMS class types*/
 };
 
 
+/**
+ *  @brief  Enumeration for the values of the MMS reply charging type. \n
+ *             This enum is used as the value of MSG_MMS_REPLY_CHARGING_TYPE_T.
+ */
 enum _MSG_MMS_REPLY_CHARGING_TYPE_E
 {
-       MSG_REPLY_CHARGING_NONE,                                        /**<Reply-Charging none */
-       MSG_REPLY_CHARGING_REQUESTED,                           /**<Reply-Charging requested */
-       MSG_REPLY_CHARGING_REQUESTED_TEXT_ONLY, /**<Reply-Charging requested text-only */
-       MSG_REPLY_CHARGING_ACCEPTED,                            /**<Reply-Charging accepted */
-       MSG_REPLY_CHARGING_ACCEPTED_TEXT_ONLY,  /**<Reply-Charging accepted text-only */
-       MSG_REPLY_CHARGING_MAX
+       MSG_REPLY_CHARGING_NONE,                    /**<Reply-Charging none */
+       MSG_REPLY_CHARGING_REQUESTED,               /**<Reply-Charging requested */
+       MSG_REPLY_CHARGING_REQUESTED_TEXT_ONLY,     /**<Reply-Charging requested text-only */
+       MSG_REPLY_CHARGING_ACCEPTED,                /**<Reply-Charging accepted */
+       MSG_REPLY_CHARGING_ACCEPTED_TEXT_ONLY,      /**<Reply-Charging accepted text-only */
+       MSG_REPLY_CHARGING_MAX                      /**< Place-holder to indicate max number of MMS reply charging types*/
 };
 
 
+/**
+ *  @brief  Enumeration for the values of the MMS creation mode. \n
+ *             This enum is used as the value of MSG_MMS_CREATION_MODE_T.
+ */
 enum _MSG_MMS_CREATION_MODE_E
 {
-       MSG_CREATION_MODE_RESTRICTED,
-       MSG_CREATION_MODE_WARNING,
-       MSG_CREATION_MODE_FREE
+       MSG_CREATION_MODE_RESTRICTED,           /**< MMS created in restricted mode */
+       MSG_CREATION_MODE_WARNING,              /**< MMS created in warning mode */
+       MSG_CREATION_MODE_FREE                  /**< MMS created in free mode */
 };
 
 
 /**
- *     @brief  Represents the values of the retrieve type for MMS home network. \n
- *     This enum is used as the value of MSG_MMS_HOME_RETRIEVE_TYPE_T.
+ *  @brief  Enumeration for the values of the retrieve type for MMS home network. \n
+ *             This enum is used as the value of MSG_MMS_HOME_RETRIEVE_TYPE_T.
  */
 enum _MSG_MMS_HOME_RETRIEVE_TYPE_E
 {
-       MSG_HOME_AUTO_DOWNLOAD,         /**< Home auto download */
-       MSG_HOME_MANUAL,                                        /**< Home manual */
-       MSG_HOME_RESTRICTED,                            /**< Home restricted */
-       MSG_HOME_REJECT,                                        /**< Home reject */
-       MSG_HOME_MAX                                            /**< Default */
+       MSG_HOME_AUTO_DOWNLOAD,             /**< Home auto download */
+       MSG_HOME_MANUAL,                    /**< Home manual */
+       MSG_HOME_RESTRICTED,                /**< Home restricted */
+       MSG_HOME_REJECT,                    /**< Home reject */
+       MSG_HOME_MAX                        /**< Default */
 };
 
 
 /**
- *     @brief  Represents the values of the retrieve type for MMS abroad network. \n
- *     This enum is used as the value of MSG_MMS_ABROAD_RETRIEVE_TYPE_T.
+ *  @brief  Enumeration for the values of the retrieve type for MMS abroad network. \n
+ *             This enum is used as the value of MSG_MMS_ABROAD_RETRIEVE_TYPE_T.
  */
 enum _MSG_MMS_ABROAD_RETRIEVE_TYPE_E
 {
-       MSG_ABROAD_AUTO_DOWNLOAD,       /**< Abroad auto download */
-       MSG_ABROAD_MANUAL,                      /**< Abroad manual */
-       MSG_ABROAD_RESTRICTED,          /**< Abroad restricted */
-       MSG_ABROAD_REJECT,                      /**< Abroad reject */
-       MSG_ABROAD_MAX                          /**< Default */
+       MSG_ABROAD_AUTO_DOWNLOAD,   /**< Abroad auto download */
+       MSG_ABROAD_MANUAL,          /**< Abroad manual */
+       MSG_ABROAD_RESTRICTED,      /**< Abroad restricted */
+       MSG_ABROAD_REJECT,          /**< Abroad reject */
+       MSG_ABROAD_MAX              /**< Default */
 };
 
 
 /**
- *     @brief  Represents the values of the frequency of sending MMS read report. \n
- *     This enum is used as the value of MSG_MMS_SEND_READ_REPORT_T.
+ *  @brief  Enumeration for the values of the frequency of sending MMS read report. \n
+ *             This enum is used as the value of MSG_MMS_SEND_READ_REPORT_T.
  */
 enum _MSG_MMS_SEND_READ_REPORT_E
 {
-       MSG_SEND_READ_REPORT_ALWAYS,    /**< Read report always */
-       MSG_SEND_READ_REPORT_NEVER,             /**< Read report never */
-       MSG_SEND_READ_REPORT_REQUEST,   /**< Read report request */
-       MSG_SEND_READ_REPORT_MAX                /**< Default */
+       MSG_SEND_READ_REPORT_ALWAYS,    /**< Read report always */
+       MSG_SEND_READ_REPORT_NEVER,     /**< Read report never */
+       MSG_SEND_READ_REPORT_REQUEST,   /**< Read report request */
+       MSG_SEND_READ_REPORT_MAX        /**< Default */
 };
 
 
 /**
- *     @brief  Represents the values of the service type for a push message. \n
- *     This enum is used as the value of MSG_PUSH_SERVICE_TYPE_T.
+ *  @brief  Enumeration for the values of the service type for a push message. \n
+ *             This enum is used as the value of MSG_PUSH_SERVICE_TYPE_T.
  */
 enum _MSG_PUSH_SERVICE_TYPE_E
 {
-       MSG_PUSH_SERVICE_ALWAYS,        /**< Push message service always */
-       MSG_PUSH_SERVICE_PROMPT,                /**< Push message service prompt */
-       MSG_PUSH_SERVICE_NEVER,         /**< Push message service never */
+       MSG_PUSH_SERVICE_ALWAYS,    /**< Push message service always */
+       MSG_PUSH_SERVICE_PROMPT,    /**< Push message service prompt */
+       MSG_PUSH_SERVICE_NEVER,     /**< Push message service never */
 };
 
 
 /**
- *     @brief  Represents the values of the language type for a cell broadcasting message. \n
- *     This enum is used as the value of MSG_CB_LANGUAGE_TYPE_T.
+ *  @brief  Enumeration for the values of the language type for a cell broadcasting message. \n
+ *             This enum is used as the value of MSG_CB_LANGUAGE_TYPE_T.
  */
 enum _MSG_CB_LANGUAGE_TYPE_E
 {
-       MSG_CBLANG_TYPE_ALL,                    /**< CB check all */
-       MSG_CBLANG_TYPE_ENG,                    /**< CB message English  */
-       MSG_CBLANG_TYPE_GER,                    /**< CB message Germany */
-       MSG_CBLANG_TYPE_FRE,                    /**< CB message France */
-       MSG_CBLANG_TYPE_ITA,                    /**< CB message Italy */
-       MSG_CBLANG_TYPE_NED,                    /**< CB message Netherland */
-       MSG_CBLANG_TYPE_SPA,                    /**< CB message Spain */
-       MSG_CBLANG_TYPE_POR,                    /**< CB message Portugal */
-       MSG_CBLANG_TYPE_SWE,                    /**< CB message Sweden */
-       MSG_CBLANG_TYPE_TUR,                    /**< CB message Turkey */
-       MSG_CBLANG_TYPE_MAX                     /**< Default */
+       MSG_CBLANG_TYPE_ALL,            /**< CB check all */
+       MSG_CBLANG_TYPE_ENG,            /**< CB message English  */
+       MSG_CBLANG_TYPE_GER,            /**< CB message Germany */
+       MSG_CBLANG_TYPE_FRE,            /**< CB message France */
+       MSG_CBLANG_TYPE_ITA,            /**< CB message Italy */
+       MSG_CBLANG_TYPE_NED,            /**< CB message Netherland */
+       MSG_CBLANG_TYPE_SPA,            /**< CB message Spain */
+       MSG_CBLANG_TYPE_POR,            /**< CB message Portugal */
+       MSG_CBLANG_TYPE_SWE,            /**< CB message Sweden */
+       MSG_CBLANG_TYPE_TUR,            /**< CB message Turkey */
+       MSG_CBLANG_TYPE_MAX             /**< Default */
 };
 
-
 /**
- *     @brief  Represents the values of SIM status. \n
- *     This enum is used as the value of MSG_SIM_STATUS_T.
+ *  @brief  Enumeration for the values of SIM status. \n
+ *             This enum is used as the value of MSG_SIM_STATUS_T.
  */
 enum _MSG_SIM_STATUS_E
 {
-       MSG_SIM_STATUS_NORMAL = 0,
-       MSG_SIM_STATUS_CHANGED,
-       MSG_SIM_STATUS_NOT_FOUND,
+       MSG_SIM_STATUS_NORMAL = 0,          /**< SIM normal */
+       MSG_SIM_STATUS_CHANGED,             /**< SIM changed */
+       MSG_SIM_STATUS_NOT_FOUND,           /**< SIM not found */
 };
 
+/**
+ *  @brief  Enumeration for the values of language type. \n
+ */
+typedef enum
+{
+       MSG_TRANSLATION_ENGLISH,            /**< Message translation language English */
+       MSG_TRANSLATION_KOREAN,             /**< Message translation language Korean */
+       MSG_TRANSLATION_JAPANESE,           /**< Message translation language Japanese */
+       MSG_TRANSLATION_CHINESE,            /**< Message translation language Chinese */
+       MSG_TRANSLATION_FRENCH,             /**< Message translation language French */
+       MSG_TRANSLATION_GERMAN,             /**< Message translation language German */
+       MSG_TRANSLATION_ITALIAN,            /**< Message translation language Italian */
+       MSG_TRANSLATION_SPANISH,            /**< Message translation language Spanish */
+       MSG_TRANSLATION_PORTUGUESE,         /**< Message translation language Portuguese */
+       MSG_TRANSLATION_RUSIAN,             /**< Message translation language Russian */
+       MSG_TRANSLATION_BULGARIAN,          /**< Message translation language Bulgarian */
+       MSG_TRANSLATION_POLISH,             /**< Message translation language Polish */
+       MSG_TRANSLATION_ROMANIAN,           /**< Message translation language Romanian */
+       MSG_TRANSLATION_SERBIAN,            /**< Message translation language Serbian */
+       MSG_TRANSLATION_TURKISH,            /**< Message translation language Turkish */
+       MSG_TRANSLATION_UKRAINIAN,          /**< Message translation language Ukrainian */
+       MSG_TRANSLATION_CZECH,              /**< Message translation language Czech */
+}MsgTranslationLang;
+
+
+/**
+ *  @brief  Enumeration for the values of a message ringtone type. \n
+ *             This enum is used as the value of MSG_RINGTONE_TYPE_T.
+ */
+enum _MSG_RINGTONE_TYPE_E
+{
+       MSG_RINGTONE_TYPE_DEFAULT = 0,  /**< Default ringtone type */
+       MSG_RINGTONE_TYPE_USER,         /**< User defined ringtone type */
+       MSG_RINGTONE_TYPE_SILENT        /**< Silent type */
+};
+
+/**
+ *  @brief  Enumeration for the values of a SIM index(SIM slot number). \n
+ *             This enum is used as the value of msg_sim_slot_id_t.
+ */
+enum _MSG_SIM_SLOT_ID_E
+{
+       MSG_SIM_SLOT_ID_1 = 1,  /**SIM Slot #1 */
+       MSG_SIM_SLOT_ID_2,      /**SIM Slot #2 */
+};
+
+/**
+ * @}
+ */
 
 #endif /* MSG_TYPES_H_ */
diff --git a/include/msg_helper/MsgHelper.h b/include/msg_helper/MsgHelper.h
deleted file mode 100755 (executable)
index 2da12e4..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef MSG_HELPER_H
-#define MSG_HELPER_H
-
-
-#include "MsgTypes.h"
-
-/*==================================================================================================
-                                       DEFINES
-==================================================================================================*/
-
-#define MSG_NORMAL_SOUND_START "NORMAL_SOUND_START"
-#define MSG_EMERGENCY_SOUND_START      "EMERGENCY_SOUND_START"
-#define MSG_SOUND_STOP         "SOUND_STOP"
-
-#define MAX_SOUND_FILE_LEN 1024
-
-#define DEFAULT_FILE           "/usr/share/media/Sherbet.wav"
-//#define ALERT_ON_CALL_TONE   "/opt/etc/msg-service/alert_on_call.mp3"
-
-#define HAPTIC_TEST_ITERATION 1
-#define MSG_VIBRATION_INTERVAL 3000
-
-typedef void (*msg_sensor_cb)();
-
-/*==================================================================================================
-                                       FUNCTION PROTOTYPES
-==================================================================================================*/
-
-// SoundPlayer
-msg_error_t MsgSoundPlayUninit();
-void MsgSoundPlayStart(bool isEmergency);
-void MsgSoundPlayStop();
-int MsgSoundPlayMelody(char *pMsgToneFilePath, bool bIncreasing);
-void MsgSoundPlayVibration(bool isOnCall);
-void MsgSoundPlayDtmf();
-
-//Sensor FW wrapper.
-msg_error_t MsgSensorConnect();
-void MsgSensorDisconnect();
-msg_error_t MsgRegSensorCB(msg_sensor_cb cb);
-
-#endif // MSG_HELPER_H
index 02858ab..082f9b2 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_HANDLE_H
@@ -58,6 +58,7 @@ class MsgHandle
                msg_error_t regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam);
                msg_error_t regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam);
                msg_error_t regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam);
+               msg_error_t regReportMessageCallback(msg_report_msg_incoming_cb onReportMsgCB, void *pUserParam);
 
                msg_error_t operateSyncMLMessage(msg_message_id_t msgId);
 
@@ -66,6 +67,7 @@ class MsgHandle
                msg_error_t addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg);
                msg_error_t updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt);
                msg_error_t updateReadStatus(msg_message_id_t MsgId, bool bRead);
+               msg_error_t setConversationToRead(msg_thread_id_t ThreadId);
                msg_error_t updateProtectedStatus(msg_message_id_t MsgId, bool bProtected);
                msg_error_t deleteMessage(msg_message_id_t MsgId);
                msg_error_t deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB);
@@ -127,13 +129,15 @@ class MsgHandle
                msg_error_t getVobject(msg_message_id_t MsgId, void** encodedData);
                // ETC
                msg_error_t searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList);
-               msg_error_t searchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList);
+               msg_error_t searchByTag(const int tagType, msg_struct_list_s *pThreadViewList);
+
                msg_error_t getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList);
                msg_error_t regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam);
                msg_error_t getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list);
                msg_error_t getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId);
+               msg_error_t getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId);
                msg_error_t getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo);
-               msg_error_t getMessageList(msg_folder_id_t folderId, msg_thread_id_t threadId, msg_message_type_t msgType, msg_storage_id_t storageId, msg_struct_list_s *pMsgList);
+               msg_error_t getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList);
 
                // Push Event
                msg_error_t addPushEvent(MSG_PUSH_EVENT_INFO_S *push_event);
index 0cf47fd..7b4fc39 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_PROXY_LISTENER_H__
@@ -26,7 +26,7 @@
 #include "MsgMutex.h"
 #include "MsgHandle.h"
 
-#include <map>
+#include <set>
 #include <list>
 #include <glib.h>
 
@@ -102,6 +102,14 @@ typedef struct
 } MSG_STORAGE_CHANGE_CB_ITEM_S;
 
 
+typedef struct
+{
+       MsgHandle* hAddr;
+       msg_report_msg_incoming_cb pfReportMsgIncomingCB;
+       void* userParam;
+} MSG_REPORT_INCOMING_CB_ITEM_S;
+
+
 typedef std::list<MSG_SENT_STATUS_CB_ITEM_S> MsgSentStatusCBList;
 typedef std::list<MSG_INCOMING_CB_ITEM_S> MsgNewMessageCBList;
 typedef std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S> MsgNewMMSConfMessageCBList;
@@ -111,7 +119,8 @@ typedef std::list<MSG_SYNCML_INCOMING_CB_ITEM_S> MsgNewSyncMLMessageCBList;
 typedef std::list<MSG_LBS_INCOMING_CB_ITEM_S> MsgNewLBSMessageCBList;
 typedef std::list<MSG_SYNCML_OPERATION_CB_ITEM_S> MsgOperationSyncMLMessageCBList;
 typedef std::list<MSG_STORAGE_CHANGE_CB_ITEM_S> MsgStorageChangeCBList;
-
+typedef std::list<MSG_REPORT_INCOMING_CB_ITEM_S> MsgReportMessageCBList;
+typedef std::set<MsgHandle*> handle_set;
 
 /*==================================================================================================
                                      CLASS DEFINITIONS
@@ -121,7 +130,7 @@ class MsgProxyListener
 public:
        static MsgProxyListener* instance();
 
-       void start();
+       void start(MsgHandle* pMsgHandle);
        void stop();
 
        bool regSentStatusEventCB(MsgHandle* pMsgHandle, msg_sent_status_cb pfSentStatus, void *pUserParam);
@@ -133,6 +142,7 @@ public:
        bool regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam);
        bool regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam);
        bool regStorageChangeEventCB(MsgHandle* pMsgHandle, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam);
+       bool regReportMsgIncomingCB(MsgHandle* pMsgHandle, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam);
 
        void clearListOfClosedHandle(MsgHandle* pMsgHandle);
 
@@ -140,6 +150,7 @@ public:
 
        int getRemoteFd();
        int readFromSocket(char** buf, unsigned int* len);
+       void resetProxyListener();
 #ifdef CHECK_SENT_STATUS_CALLBACK
        int getSentStatusCbCnt();
 #endif
@@ -152,6 +163,8 @@ private:
 
        unsigned int running;
 
+       handle_set      openHandleSet;
+
        MsgIpcClientSocket cliSock;
 
        Mutex mx;
@@ -166,6 +179,7 @@ private:
        MsgNewLBSMessageCBList newLBSMessageCBList;
        MsgOperationSyncMLMessageCBList operationSyncMLMessageCBList;
        MsgStorageChangeCBList storageChangeCBList;
+       MsgReportMessageCBList reportMessageCBList;
 
        GIOChannel *channel;
        guint eventSourceId;
index 4f1bf66..e12e1fb 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_CONTACT_H
@@ -35,7 +35,9 @@ msg_error_t MsgCloseContactSvc();
 msg_error_t MsgInitContactSvc(MsgContactChangeCB cb);
 
 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo);
+msg_error_t MsgGetContactSearchList(const char *pSearchVal, MSG_ADDRESS_INFO_S **pAddrInfo, int *count);
 
+void MsgSyncAddressbook();
 void MsgSyncContact();
 
 bool MsgInsertContact(MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber);
@@ -43,6 +45,7 @@ bool MsgUpdateContact(int index, int type);
 bool MsgDeleteContact(int index);
 
 int MsgGetContactNameOrder();
+msg_error_t MsgGetContactStyleDisplayName(const char *first, const char *last, const char *middle, const char *prefix, const char *suffix, int contactNameOrder, char *displayName, unsigned int size);
 
 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo);
 void MsgDeletePhoneLog(msg_message_id_t msgId);
@@ -50,6 +53,10 @@ void MsgDeletePhoneLog(msg_message_id_t msgId);
 int MsgContactSVCBeginTrans();
 int MsgContactSVCEndTrans(bool bSuccess);
 
+bool checkBlockingMode(char *address, bool *pisFavorites);
 
+int MsgContactGetMinMatchDigit();
+void MsgConvertNumber(const char* pSrcNum, char* pDestNum, int destSize);
+bool MsgIsNumber(const char* pSrc);
 #endif //MSG_CONTACT_H
 
index 98d44e7..8cb07d5 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_DEBUG_H__
 #include <string.h>
 #include <sys/time.h>
 #include <time.h>
+#include <dlog.h>
 
-#include "MsgTypes.h"
 #include "MsgCmdTypes.h"
-#include "MsgFilterTypes.h"
-
-extern "C"{
-       #include <dlog.h>
-};
-
 
 /*==================================================================================================
                                     DEFINES
@@ -45,107 +39,66 @@ extern "C"{
 #define MSG_MMS_VALID_TAG "VLD_MMS"
 
 #define DLOG_ENABLE
-//#define LOG_ENABLE
-
-
-/*==================================================================================================
-                                     FUNCTION PROTOTYPES
-==================================================================================================*/
-int get_tid();
-
 
 #if defined(DLOG_ENABLE)
 
-#define MSG_FATAL(fmt, ...) \
-       do \
+/*log macros*/
+#define MSG_BEGIN()\
+       do\
        {\
-               SLOGD(" ERROR << " fmt " >>\n\n", ##__VA_ARGS__);\
-       } while (0)
+               SLOGD(" BEGIN >>>> \n");\
+       } while(0)
 
-#define MSG_DEBUG(fmt, ...)\
+#define MSG_END()\
        do\
        {\
-               SLOGD(fmt"\n\n", ##__VA_ARGS__);\
-       } while (0)
+               SLOGD(" END   <<<<  \n");\
+       } while(0)
 
-#define MSG_BEGIN() \
+#define MSG_DEBUG(fmt, ...)\
        do\
-    {\
-               SLOGD(" BEGIN >>>> \n\n");\
-    } while( 0 )
+       {\
+               SLOGD(fmt"\n", ##__VA_ARGS__);\
+       } while(0)
 
-#define MSG_END() \
+#define MSG_INFO(fmt, ...)\
        do\
-    {\
-               SLOGD(" END   <<<<  \n\n");\
-    } while( 0 )
+       {\
+               SLOGI("* Info * " fmt "\n", ##__VA_ARGS__);\
+       } while(0)
 
-#define MSG_INFO(fmt, args...)\
+#define MSG_WARN(fmt, ...)\
        do\
        {\
-               SLOGI("* Info * " fmt "\n\n", ##args);\
-       } while( 0 )
-
-#define MSG_WARN(fmt, args...)\
-       do {\
-               SLOGW("* Warning * " fmt "\n\n", ##args)\
-       } while( 0 )
-
-#define MSG_ERR(fmt, args...)\
-       do {\
-               SLOGE("* Error * " fmt "\n\n", ##args);\
-       } while( 0 )
-
+               SLOGW("* Warning * " fmt "\n", ##__VA_ARGS__);\
+       } while(0)
 
-#define MSG_ERR_RET_VM(expr, val, fmt, arg...)\
-       do {\
-               if (expr) {\
-                       MSG_ERR(fmt, ##arg);\
-                       return (val);\
-               }\
-       } while (0)
-
-#define MSG_ERR_RET_M(expr, fmt, arg...)\
-       do {\
-               if (expr) {\
-                       MSG_ERR(fmt, ##arg);\
-                       return;\
-               }\
-       } while (0)
+#define MSG_ERR(fmt, ...)\
+       do\
+       {\
+               SLOGE("* Error * " fmt "\n", ##__VA_ARGS__);\
+       } while(0)
 
-#define MSG_WARN_M(expr, fmt, arg...)\
-       do {\
-               if (expr) {\
-                       MSG_WARN(fmt, ##arg);\
-               }\
-       } while (0)
+#define MSG_FATAL(fmt, ...)\
+       do\
+       {\
+               SLOGE(" ERROR << " fmt " >>\n", ##__VA_ARGS__);\
+       } while(0)
 
-#define MSG_PROFILE_BEGIN(pfid) \
-       unsigned int __prf_l1_##pfid = __LINE__;    \
-       struct timeval __prf_1_##pfid;              \
-       struct timeval __prf_2_##pfid;              \
-       do {                                        \
-               gettimeofday(&__prf_1_##pfid, 0);       \
+/*secure log macros*/
+#define MSG_SEC_DEBUG(fmt, ...)\
+       do\
+       {\
+               SECURE_SLOGD(fmt"\n", ##__VA_ARGS__);\
        } while (0)
 
-#define MSG_PROFILE_END(pfid) \
-       unsigned int __prf_l2_##pfid = __LINE__;\
-       do { \
-               gettimeofday(&__prf_2_##pfid, 0);\
-               long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
-               long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
-               if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
-               SLOG(LOG_DEBUG, USER_TAG, "**PROFILE** [MSGFW: %s: %s() %u ~ %u] " #pfid                            \
-               " -> Elapsed Time: %u.%06u seconds\n",                    \
-               rindex(__FILE__, '/')+1,                \
-               __FUNCTION__, \
-               __prf_l1_##pfid,                                         \
-               __prf_l2_##pfid,                                         \
-               (unsigned int)(__ds),                                    \
-               (unsigned int)(__dm));                                   \
+#define MSG_SEC_INFO(fmt, ...)\
+       do\
+       {\
+               SECURE_SLOGI("* Info * " fmt"\n", ##__VA_ARGS__);\
        } while (0)
 
-
+/*valid data log macros*/
 #define MSG_SMS_VLD_INFO(fmt, ...)\
        do\
        {\
@@ -176,8 +129,62 @@ int get_tid();
                SLOG(LOG_DEBUG, MSG_MMS_VALID_TAG, "[MMS FILE]%s, "fmt"\n", __TIMESTAMP__, ##__VA_ARGS__);\
        } while (0)
 
+/*err & warn return message log macros*/
+#define MSG_ERR_RET_VM(expr, val, fmt, ...)\
+       do\
+       {\
+               if (expr) {\
+                       MSG_ERR(fmt, ##__VA_ARGS__);\
+                       return (val);\
+               }\
+       } while(0)
+
+#define MSG_ERR_RET_M(expr, fmt, ...)\
+       do\
+       {\
+               if (expr) {\
+                       MSG_ERR(fmt, ##__VA_ARGS__);\
+                       return;\
+               }\
+       } while(0)
+
+#define MSG_WARN_M(expr, fmt, ...)\
+       do\
+       {\
+               if (expr) {\
+                       MSG_WARN(fmt, ##__VA_ARGS__);\
+               }\
+       } while(0)
+
+/*profile log macros*/
+#define MSG_PROFILE_BEGIN(pfid) \
+       unsigned int __prf_l1_##pfid = __LINE__;\
+       struct timeval __prf_1_##pfid;\
+       struct timeval __prf_2_##pfid;\
+       do {\
+               gettimeofday(&__prf_1_##pfid, 0);\
+       } while (0)
+
+#define MSG_PROFILE_END(pfid) \
+       unsigned int __prf_l2_##pfid = __LINE__;\
+       do { \
+               gettimeofday(&__prf_2_##pfid, 0);\
+               long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
+               long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
+               if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
+               SLOGD("**PROFILE** [MSGFW: %s: %s() %u ~ %u] " #pfid " -> Elapsed Time: %u.%06u seconds\n",\
+               rindex(__FILE__, '/')+1,\
+               __FUNCTION__, \
+               __prf_l1_##pfid,\
+               __prf_l2_##pfid,\
+               (unsigned int)(__ds),\
+               (unsigned int)(__dm));\
+       } while (0)
+
 #elif defined(LOG_ENABLE)
 
+int get_tid();
+
 #define MSG_FATAL(fmt, ...) \
        do \
        {\
@@ -262,6 +269,19 @@ int get_tid();
 
 #endif
 
+
+#define MSG_FREE(x) \
+       ({\
+               if (x != NULL){\
+               free(x);\
+               x = NULL;}\
+       })
+
+
+/*==================================================================================================
+                                                                        FUNCTION PROTOTYPES
+==================================================================================================*/
+
 const char * MsgDbgCmdStr(MSG_CMD_TYPE_T cmdType);
 const char * MsgDbgEvtStr(MSG_EVENT_TYPE_T evtType);
 
index 7ff4d7d..b1a8779 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_DRM_WRAPPER_H_
@@ -41,6 +41,7 @@ bool MsgDrmGetMimeTypeEx(const char *szFileName, char *szMimeType, int nMimeType
 bool MsgDrmGetContentID(const char *szFileName, char *szContentID, int nContentIDLen);
 bool MsgDrmGetDrmType(const char *szFileName, MSG_DRM_TYPE *eDRMType);
 bool MsgDrmConvertDmtoDcfType(char *inputFile, char *outputFile);
+bool MsgDrmCheckRingtone(const char *ringtonePath);
 
 #ifdef __cplusplus
 }
index 23ef2c7..5d4c73f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_EXCEPTION_H
index c8b8b90..0c9793a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_GCONF_WRAPPER_H
@@ -54,11 +54,10 @@ char*                       MsgSettingGetString(const char *pKey);
 int                            MsgSettingGetInt(const char *pKey);
 int                            MsgSettingGetBool(const char *pKey, bool *pVal);
 
-void   MsgChangePmState();
 msg_error_t    MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt);
 msg_error_t    MsgSettingSetIndicator(int SmsCnt, int MmsCnt);
 
-bool   MsgSettingGetAutoReject();
+int    MsgSettingGetAutoReject();
 bool   MsgSettingGetUnknownAutoReject();
 
 void   MsgSettingRegVconfCB();
@@ -67,4 +66,7 @@ void  MsgSettingRemoveVconfCB();
 void MsgSettingRegVconfCBCommon(const char *pKey, _vconf_change_cb pCb);
 void MsgSettingRemoveVconfCBCommon(const char *pKey, _vconf_change_cb pCb);
 
+#ifdef MSG_PENDING_PUSH_MESSAGE
+msg_error_t MsgSendPendingPushMsg(void);
+#endif
 #endif // MSG_GCONF_WRAPPER_H
index 2cafe03..8795d48 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __IPCSocket_H__
@@ -73,6 +73,7 @@ public:
 private:
        int readn(char *buf, unsigned int len );
        int writen (const char *buf, unsigned int len);
+       bool wait_for_reply();
 
        int sockfd, remotefd, maxfd;
        fd_set fds;
diff --git a/include/utils/MsgJsonParser.h b/include/utils/MsgJsonParser.h
new file mode 100755 (executable)
index 0000000..9cebec0
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef __MSG_JSON_PARSER_H__
+#define __MSG_JSON_PARSER_H__
+
+#include <stdio.h>
+#include "MsgDebug.h"
+
+#define MSG_JSON_OBJ_SET_STR(json_obj, key, val)\
+       if(json_obj && key && val){\
+               json_object_set_string_member(json_obj, key, val);\
+       } else {\
+               MSG_DEBUG("Error : json_obj = %p, key = %s, val = %s", json_obj, key, val);\
+       }
+
+#define MSG_JSON_OBJ_SET_INT(json_obj, key, val)\
+       if(json_obj && key){\
+               json_object_set_int_member(json_obj, key, val);\
+       } else {\
+               MSG_DEBUG("Error : json_obj = %p, key = %s, val = %d", json_obj, key, val);\
+       }
+
+#define MSG_JSON_OBJ_SET_OBJ(json_obj, key, val)\
+       if(json_obj && key){\
+               json_object_set_object_member(json_obj, key, val);\
+       } else {\
+               MSG_DEBUG("Error : json_obj = %p, key = %s, val = %p", json_obj, key, val);\
+       }
+
+#define MSG_JSON_OBJ_SET_ARRAY(json_obj, key, json_array)\
+       if(json_obj && key && json_array){\
+               json_object_set_array_member(json_obj, key, json_array);\
+       } else {\
+               MSG_DEBUG("Error : json_obj = %p, key = %s, json_array = %p", json_obj, key, json_array);\
+       }
+
+#define MSG_JSON_ARRAY_ADD_OBJECT(json_array, json_obj)\
+       if(json_array && json_obj){\
+               json_array_add_object_element(json_array, json_obj);\
+       } else {\
+               MSG_DEBUG("Error : json_array = %p, json_obj = %p", json_array, json_obj);\
+       }
+
+#define MSG_PRINT_PARSER_OBJECT(index, obj) {\
+       switch(obj.type) {\
+       case MSG_JSON_PARSER_NULL:\
+               MSG_DEBUG("parse obj : idx = %d, key =[%s], type = [%d], value = [%p], value num = [%f]", index, obj.key, obj.type, obj.value, obj.number_value);\
+               break;\
+       case MSG_JSON_PARSER_INT:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s], value = [%d]", index, obj.key, "MSG_JSON_PARSER_INT", (int)obj.number_value);\
+               break;\
+       case MSG_JSON_PARSER_UINT:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s], value = [%u]", index, obj.key, "MSG_JSON_PARSER_UINT", (unsigned int)obj.number_value);\
+               break;\
+       case MSG_JSON_PARSER_REAL:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s], value = [%f]", index, obj.key, "MSG_JSON_PARSER_REAL", obj.number_value);\
+               break;\
+       case MSG_JSON_PARSER_STRING:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s], value = [%s]", index, obj.key, "MSG_JSON_PARSER_STRING", (char *)obj.value);\
+               break;\
+       case MSG_JSON_PARSER_BOOLEAN:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s], value = [%s]", index, obj.key, "MSG_JSON_PARSER_BOOLEAN", obj.number_value == 0 ? "TRUE" : "FALSE");\
+               break;\
+       case MSG_JSON_PARSER_ARRAY:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s]", index, obj.key, "MSG_JSON_PARSER_ARRAY");\
+               break;\
+       case MSG_JSON_PARSER_OBJECT:\
+               MSG_DEBUG("parse obj : idx = [%d], key = [%s], type = [%s]", index, obj.key, "MSG_JSON_PARSER_OBJECT");\
+               break;\
+       default:\
+               MSG_DEBUG("parse obj : idx = %d, key =[%s], type = [%d], value = [%p], value num = [%f]", index, obj.key, obj.type, obj.value, obj.number_value);\
+               break;\
+       }\
+}
+/**
+*@enum msg_json_parser_value_type
+* This enumerates json-node types.
+*/
+typedef enum {
+        MSG_JSON_PARSER_NULL = 0,      /** 0 <null value */
+        MSG_JSON_PARSER_INT,           /** 1 < signed integer value */
+        MSG_JSON_PARSER_UINT,          /** 2 < unsigned integer value */
+        MSG_JSON_PARSER_REAL,          /** 3 < double value */
+        MSG_JSON_PARSER_STRING,        /** 4 < UTF-8 string value */
+        MSG_JSON_PARSER_BOOLEAN,       /** 5 < bool value */
+        MSG_JSON_PARSER_ARRAY,         /** 6 < array value (ordered list) */
+        MSG_JSON_PARSER_OBJECT,        /** 7 < object value */
+} msg_json_parser_value_type;
+
+typedef void *msg_json_parser_handle;
+
+typedef struct msg_json_parser_object_t {
+        msg_json_parser_value_type type;
+        char *key;
+        void *value;    /** Value of the node. VALID
+                                        only if type is
+                                        MSG_JSON_PARSER_NULL,
+                                        MSG_JSON_PARSER_STRING,
+                                        MSG_JSON_PARSER_ARRAY,
+                                        MSG_JSON_PARSER_OBJECT */
+        double number_value; /** Value of the node. VALID
+                                        only if type is
+                                        MSG_JSON_PARSER_UINT,
+                                        MSG_JSON_PARSER_INT,
+                                        MSG_JSON_PARSER_REAL,
+                                        MSG_JSON_PARSER_BOOLEAN */
+} msg_json_parser_object;
+
+msg_json_parser_handle msg_json_parser_handle_create(void);
+void msg_json_parser_handle_destory(msg_json_parser_handle *handle);
+int msg_json_parser_get_value(msg_json_parser_object *json_obj);
+int msg_json_parser_object_get_value(msg_json_parser_object *json_obj);
+int msg_json_parser_get_next_child(const msg_json_parser_object *parent, msg_json_parser_object *child, int index);
+void msg_json_parser_parse_buffer(msg_json_parser_handle handle, const char* value, int value_len, msg_json_parser_object *json_obj);
+int msg_json_parser_get_child_by_name(const msg_json_parser_object *parent, msg_json_parser_object *child, const char *name);
+
+#endif /*__MSG_JSON_PARSER_H__*/
+
index c866243..7fa9522 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_MEMORY_H__
index 1180e2d..e08e2bd 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_MMS_MESSAGE_H
@@ -44,10 +44,51 @@ int _MsgMmsGetMetaCount(MMS_MESSAGE_DATA_S *pMsgData);
 
 void MsgMmsReleaseMmsLists(MMS_MESSAGE_DATA_S *pMsgData);
 
-char *_MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, size_t *pSize);
+char *_MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, unsigned int *pSize);
 bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pData);
 
 bool _MsgMmsSetRootLayout(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_ROOTLAYOUT *pRootlayout);
 
+void _MsgMmsPrint(MMS_MESSAGE_DATA_S *pMsgData);
+void _MsgMmsAttachPrint(MMS_ATTACH_S *attach);
+void _MsgMmsMediaPrint(MMS_MEDIA_S *media);
+void _MsgMmsPagePrint(MMS_PAGE_S *page);
+
+MMS_HEADER_DATA_S *MsgMmsCreateHeader();
+void MsgMmsInitHeader(MMS_HEADER_DATA_S *pMmsHeaderData);
+void MsgMmsReleaseHeader(MMS_HEADER_DATA_S **ppMmHeadersData);
+
+MMS_MULTIPART_DATA_S *MsgMmsCreateMultipart();
+void MsgMmsInitMultipart(MMS_MULTIPART_DATA_S *pMmsMultipart);
+void MsgMmsReleaseMultipart(MMS_MULTIPART_DATA_S **ppMmsMultipart);
+
+MMS_DATA_S *MsgMmsCreate();
+
+void MsgMmsRelease(MMS_DATA_S **ppMmsData);
+
+int MsgMmsReleaseMultipartList(MMSList **ppMultipartList);
+
+int MsgMmsGetSmilMultipart(MMSList *pMultipartList, MMS_MULTIPART_DATA_S **smil_multipart);//TODO : delete
+
+int MsgMmsConvertMmsDataToMmsMessageData(MMS_DATA_S *pSrc, MMS_MESSAGE_DATA_S *pDst);
+
+int MsgMmsConvertMmsMessageDataToMmsData(MMS_MESSAGE_DATA_S *pSrc, MMS_DATA_S *pDst);
+
+MMS_ADDRESS_DATA_S *MsgMmsCreateAddress(int addressType, const char *addressVal);
+void MsgMmsReleaseAddress(MMS_ADDRESS_DATA_S **ppMmsAddressData);
+int MsgMmsReleaseAddressList(MMSList **ppAddressList);
+
+int MsgMmsSetMultipartData(MMS_MULTIPART_DATA_S *pMultipart);
+int MsgMmsSetMultipartFilePath(const char *dirPath, MMS_MULTIPART_DATA_S *pMultipart);
+
+int MsgMmsSetMultipartListData(MMS_DATA_S *pMmsData);
+int MsgMmsSetMultipartListFilePath(const char *dirPath, MMS_DATA_S *pMmsData);
+
+int printMultipart(MMS_MULTIPART_DATA_S *multipart);
+int printMultipartList(MMSList *pMultipartList);//for debug
+
+void _MsgMmsMultipartPrint(MMS_MULTIPART_DATA_S *multipart);
+
+bool  _MsgMmsRemoveEmptyObject(MMS_MESSAGE_DATA_S *pMmsMsg);
 
 #endif // MSG_MMS_MESSAGE_H
index 68ab7d9..c3b1cc6 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef __MSG_MUTEX_H__
@@ -33,8 +33,23 @@ void WaitMsgReady(int sec);
 class Mutex
 {
 public:
-       Mutex(){ pthread_mutex_init(&m, 0); }
+       Mutex(){
+               pthread_mutexattr_t mattr;
+               pthread_mutexattr_init(&mattr);
+               pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
+               pthread_mutex_init(&m, &mattr);
+               pthread_mutexattr_destroy(&mattr);
+       }
+       ~Mutex(){ pthread_mutex_destroy(&m); }
        void lock(){ pthread_mutex_lock(&m); }
+
+       int timedlock(){
+               struct timespec abs_time;
+               clock_gettime(CLOCK_REALTIME, &abs_time);
+               abs_time.tv_sec += 1;
+               return pthread_mutex_timedlock(&m, &abs_time);
+       }
+
        void unlock(){ pthread_mutex_unlock(&m); }
        pthread_mutex_t* pMutex() { return &m; }
 
diff --git a/include/utils/MsgNotificationWrapper.h b/include/utils/MsgNotificationWrapper.h
deleted file mode 100755 (executable)
index 8642c4e..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef MSG_QUICKPANEL_WRAPPER_H
-#define MSG_QUICKPANEL_WRAPPER_H
-
-/*==================================================================================================
-                                         INCLUDE FILES
-==================================================================================================*/
-#include "MsgInternalTypes.h"
-#include "MsgSqliteWrapper.h"
-
-
-/*==================================================================================================
-                                         DEFINES
-==================================================================================================*/
-#define MSG_APP_PACKAGE_NAME   "message"
-#define MSG_SYS_PACKAGE_NAME   "sys_string"
-#define NORMAL_MSG_ICON_PATH           "/opt/usr/apps/8r4r5ddzzn/shared/res/screen-density-xhigh/mainmenu.png"
-
-#define MSG_APP_LOCALEDIR                      "/usr/apps/org.tizen.message/res/locale"
-
-#define SENDING_MULTIMEDIA_MESSAGE_FAILED      "Sending multimedia message failed"
-#define MULTIMEDIA_MESSAGE_SENT                                        "Multimedia message sent"
-#define RETRIEVING_MESSAGE_FAILED                                      "Retrieving message failed"
-#define MESSAGE_RETRIEVED                                                              "Message retrieved"
-#define SMS_MESSAGE_SENT                                                               "Message sent"
-#define SMS_MESSAGE_SENDING_FAIL                                       "Sending message failed"
-
-#define MESSAGE                                                "Message"
-#define NEW_MESSAGE                            "New message"
-#define NEW_MESSAGES                   "New messages"
-
-#define MSG_SYS_LOCALEDIR      "/usr/share/locale"
-
-#define NOTIFICATION_PRIV_ID DEFAULT_SETTING_PATH"/notification_priv_id"
-#define VOICE_NOTI_ID_1 DEFAULT_SETTING_PATH"/voice_noti_id1"
-#define CB_NOTI_PRIV_ID DEFAULT_SETTING_PATH"/cb_noti_priv_id"
-
-/*==================================================================================================
-                                     FUNCTION PROTOTYPES
-==================================================================================================*/
-msg_error_t MsgInsertNoti(MSG_MESSAGE_INFO_S* pMsg);
-
-msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg);
-
-msg_error_t MsgRefreshNoti(bool bWithTicker);
-msg_error_t MsgRefreshCBNoti(bool bWithTicker);
-msg_error_t MsgCleanAndResetNoti();
-
-msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg);
-msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt);
-
-msg_error_t MsgClearVoiceNoti(MSG_SUB_TYPE_T subType);
-
-#endif // MSG_QUICKPANEL_WRAPPER_H
diff --git a/include/utils/MsgSerialize.h b/include/utils/MsgSerialize.h
new file mode 100755 (executable)
index 0000000..9a8dc5f
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MSG_MMS_SERIALIZE_H
+#define MSG_MMS_SERIALIZE_H
+
+#include "MsgMmsTypes.h"
+
+int MsgSerializeMmsJsonData(const MMS_DATA_S *pMsgData, char **pValue);
+int MsgDeserializeMmsJsonData(char* value, int value_len, MMS_DATA_S **ppMmsData);
+
+int MsgSerializeMms(const MMS_DATA_S *pMsgData, char **pValue);
+int MsgDeserializeMmsData(char* value, int value_len, MMS_DATA_S **ppMmsData);
+
+#endif //MSG_MMS_SERIALIZE_H
+
diff --git a/include/utils/MsgSoundPlayer.h b/include/utils/MsgSoundPlayer.h
deleted file mode 100755 (executable)
index 90ca757..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef MSG_SOUND_PLAYER_H
-#define MSG_SOUND_PLAYER_H
-
-
-/*==================================================================================================
-                                    DEFINES
-==================================================================================================*/
-
-
-/*==================================================================================================
-                                    INCLUDE FILES
-==================================================================================================*/
-
-
-
-/*==================================================================================================
-                                     FUNCTION PROTOTYPES
-==================================================================================================*/
-void MsgSoundPlayStart(bool isEmergency);
-void MsgSoundPlayStop();
-
-bool MsgSoundSetRepeatAlarm();
-bool MsgSoundCreateRepeatAlarm(int RepeatTime);
-int MsgSoundRepeatAlarmCB(int TimerId, void *pUserParam);
-int MsgSoundGetUnreadMsgCnt();
-void MsgSoundInitRepeatAlarm();
-
-#endif // MSG_SOUND_PLAYER_H
-
index 8f35985..8840f6a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_SQLITE_WRAPPER_H
@@ -21,7 +21,7 @@
                                     INCLUDE FILES
 ==================================================================================================*/
 #include "MsgTypes.h"
-
+#include <db-util.h>
 
 /*==================================================================================================
                                     DEFINES
 #define MSGFW_CB_MSG_TABLE_NAME                                "MSG_CBMSG_TABLE"
 #define MMS_PLUGIN_MESSAGE_TABLE_NAME          "MSG_MMS_MESSAGE_TABLE"
 #define MSGFW_SYNCML_MSG_TABLE_NAME            "MSG_SYNCML_TABLE"
+
+#if 0
+#define MSGFW_RECEIVED_CB_MSG_TABLE_NAME       "MSG_CB_MESSAGE_TABLE"
+#endif
+
+#define MSGFW_CB_CHANNEL_INFO_TABLE_NAME       "MSG_CB_CHANNEL_INFO_TABLE"
+
 #define MSGFW_SMS_SENDOPT_TABLE_NAME           "MSG_SMS_SENDOPT_TABLE"
-#define MSGFW_REPORT_TABLE_NAME                                "MSG_REPORT_TABLE"
-#define MSGFW_PUSH_CONFIG_TABLE_NAME                   "MSG_PUSHCFG_TABLE"
-#define MSGFW_MMS_PREVIEW_TABLE_NAME                   "MSG_MMS_PREVIEW_INFO_TABLE"
+#define MSGFW_SMS_REPORT_TABLE_NAME            "MSG_SMS_REPORT_TABLE"
+#define MSGFW_REPORT_TABLE_NAME                                        "MSG_REPORT_TABLE"
+#define MSGFW_PUSH_CONFIG_TABLE_NAME           "MSG_PUSHCFG_TABLE"
+#define MSGFW_MMS_PREVIEW_TABLE_NAME           "MSG_MMS_PREVIEW_INFO_TABLE"
+#define MSGFW_MMS_MULTIPART_TABLE_NAME         "MSG_MULTIPART_TABLE"
 
 #define MSGFW_TMP_MSGID_TABLE_NAME                     "MSG_TMP_MSGID_TABLE"
 
+#define MSGFW_ADDRESS_TEMP_TABLE_NAME          "MSG_ADDRESS_TEMP_TABLE"
+
 #define MAX_QUERY_LEN                                  3072
 #define MAX_FOLDER_NAME_LEN            20
 #define MAX_ACCOUNT_NAME_LEN   51
 
 #define MSGFW_DB_ESCAPE_CHAR           '\\'
 
+#define SHM_FILE_FOR_DB_LOCK                "/.msg_shm_db_lock"
+
 /*==================================================================================================
                                      FUNCTION PROTOTYPES
 ==================================================================================================*/
 void   MsgReleaseMemoryDB();
 msg_error_t MsgConvertStrWithEscape(const char *input, char **output);
 
+
 /*==================================================================================================
                                      CLASS DEFINITIONS
 ==================================================================================================*/
@@ -74,9 +88,11 @@ public:
        msg_error_t getTable(const char *pQuery, int *pRowCnt);
        void freeTable();
        msg_error_t bindText(const char *pBindStr, int index);
+       msg_error_t bindInt(const int pBindint, int index);
        msg_error_t bindBlob(const void * pBindBlob, int size, int index);
        msg_error_t prepareQuery(const char *pQuery);
        msg_error_t stepQuery();
+       void resetQuery();
        void finalizeQuery();
        int columnInt(int ColumnIndex);
        const unsigned char* columnText(int ColumnIndex);
@@ -85,14 +101,23 @@ public:
        msg_error_t endTrans(bool Success);
        int getColumnToInt(int RowIndex);
        char getColumnToChar(int RowIndex);
+       char* getColumnToString(int RowIndex);
        void getColumnToString(int RowIndex, int Length, char *pString);
        msg_error_t getRowId(const char *pTableName, unsigned int *pRowId);
+       void getMmapMutex(const char *shm_file_name);
+       void shm_mutex_timedlock (int sec);
+       void shm_mutex_unlock();
 
 private:
-
        char **result;
-
+       sqlite3 *handle;
+       sqlite3_stmt *stmt;
+       pthread_mutex_t *mmapMx;
+       int shm_fd;
 };
 
+
+MsgDbHandler *getDbHandle();
+void removeDbHandle();
 #endif // MSG_SQLITE_WRAPPER_H
 
index 2098a68..7e00298 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_TEXT_CONVERT_H
@@ -35,7 +35,7 @@
 
 #define MAX_DUMP_COLUMN        16
 
-typedef unsigned short WCHAR;
+typedef unsigned long WCHAR;
 
 typedef unsigned char MSG_CHAR_TYPE_T;
 
@@ -254,31 +254,38 @@ static const WCHAR g_PortuLockingToUCS2[] =
 class MsgTextConvert
 {
 public:
-       MsgTextConvert();
-       ~MsgTextConvert();
+       static MsgTextConvert* instance();
 
        int convertUTF8ToGSM7bit(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT bool *bIncludeAbnormalChar);
        int convertUTF8ToUCS2(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen);
-       int convertUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, OUT msg_encode_type_t *pCharType);
+       int convertUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT msg_encode_type_t *pCharType);
 
        int convertGSM7bitToUTF8(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, IN MSG_LANG_INFO_S *pLangInfo);
        int convertUCS2ToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN  int srcTextLen);
        int convertEUCKRToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN  int srcTextLen);
+       int convertSHIFTJISToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN  int srcTextLen);
 
 private:
+       MsgTextConvert();
+       ~MsgTextConvert();
+
        int convertUCS2ToGSM7bit(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT bool *bIncludeAbnormalChar);
-       int convertUCS2ToGSM7bitAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT bool *pUnknown);
 
        int convertGSM7bitToUCS2(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, IN MSG_LANG_INFO_S *pLangInfo);
 
        void convertDumpTextToHex(const unsigned char *pText, int length);
 
+       static MsgTextConvert* pInstance;
+
        std::map<unsigned short, unsigned char> extCharList;
        std::map<unsigned short, unsigned char> ucs2toGSM7DefList;
        std::map<unsigned short, unsigned char> ucs2toGSM7ExtList;
        std::map<unsigned short, unsigned char> ucs2toTurkishList;
        std::map<unsigned short, unsigned char> ucs2toSpanishList;
        std::map<unsigned short, unsigned char> ucs2toPortuList;
+
+       std::map<unsigned short, unsigned char> replaceCharList;
+
 };
 
 #endif //MSG_TEXT_CONVERT_H
index e1373f5..8600b2a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_UTIL_FILE_H
@@ -55,6 +55,11 @@ unsigned int MsgDu(const char *pDirPath);
 bool MsgAppendFile(const char *pFilePath, const char *pData, int DataSize);
 void MsgMmsInitDir();
 bool MsgAccessFile(const char *filepath, int mode);
+bool MsgChmod(const char *filepath, int mode);
+bool MsgChown(const char *filepath, int uid, int gid);
+bool MsgCreateFile(const char *pFilePath,char *pData, int DataSize);
+char *MsgGetDirName(char *file_path);
+char *MsgGetFileName(char *file_path);
 
 #endif // MSG_UTIL_FILE_H
 
index be93986..c0c0f41 100755 (executable)
@@ -1,22 +1,22 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_UTIL_FUNCTION_H
 #define MSG_UTIL_FUNCTION_H
-
+#define        MSG_UTIL_CH_EMAIL_AT    '@'
 
 /*==================================================================================================
                                          INCLUDE FILES
@@ -40,7 +40,7 @@ int MsgEncodeRecipientList(MSG_RECIPIENTS_LIST_S *pRecipientList, char **ppDest)
 
 int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest);
 
-int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest);
+int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest);
 
 int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo,  MSG_SENDINGOPT_INFO_S* pSendOptInfo, char **ppDest);
 
@@ -68,6 +68,8 @@ int MsgEncodeSyncMLOperationData(int msgId, int extId, char **ppDest);
 
 int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList, char **ppDest);
 
+int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest);
+
 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest);
 
 int MsgEncodeThreadId(msg_thread_id_t *pThreadId, char **ppDest);
@@ -80,6 +82,8 @@ void MsgDecodeMsgId(char *pSrc, msg_message_id_t *pMsgId);
 
 void MsgDecodeCountInfo(char *pSrc, MSG_COUNT_INFO_S *pCountInfo);
 
+void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo);
+
 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo,  MSG_SENDINGOPT_INFO_S* pSendOptInfo);
 
 void MsgDecodeFolderViewList(char *pSrc, msg_struct_list_s *pFolderViewList);
@@ -111,8 +115,16 @@ void MsgDecodeThreadInfo(char *pSrc, MSG_THREAD_VIEW_S *pThreadInfo);
 int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg_error_t MsgError, void **ppEvent);
 
 
+// Utin functions
 int msg_verify_number(const char *raw, char *trimmed);
 
 int msg_verify_email(const char *raw);
 
+char* msg_clean_country_code(char *src);
+
+char* msg_normalize_number(char *src);
+
+msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort);
+
+bool msg_is_valid_email(char *pAddress);
 #endif // MSG_UTIL_FUNCTION_H
index de2b9d8..a189811 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_UTIL_STORAGE_H
 #include "MsgInternalTypes.h"
 #include "MsgStorageTypes.h"
 #include "MsgSqliteWrapper.h"
-
+#include "MsgSettingTypes.h"
 
 /*==================================================================================================
                                        FUNCTION PROTOTYPES
 ==================================================================================================*/
 // Common Function
+
 unsigned int MsgStoAddMessageTable(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsgInfo);
 msg_error_t MsgStoSetReadStatus(MsgDbHandler *pDbHandle, msg_message_id_t MsgId, bool bRead);
 msg_error_t MsgStoGetOldestMessage(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsgInfo, msg_message_id_t *pMsgId);
-msg_error_t MsgStoCheckMsgCntFull(MsgDbHandler *pDbHandle, const MSG_MESSAGE_TYPE_S* pMsgType, msg_folder_id_t FolderId);
+msg_error_t MsgStoCheckMsgCntFull(MsgDbHandler *pDbHandle, const MSG_MESSAGE_TYPE_S* pMsgType, msg_folder_id_t FolderId, int simIndex);
 msg_error_t MsgStoCountMsgByLimitCategory(MsgDbHandler *pDbHandle, const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount, msg_folder_id_t folderId );
+msg_error_t MsgStocheckMemoryStatus();
 int MsgStoCheckMsgCntLimit(const MSG_MESSAGE_TYPE_S* pMsgType, msg_folder_id_t FolderId);
 
 msg_error_t MsgStoAddAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pConvId);
-msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int contactNameOrder, int *nAddressCnt, MSG_ADDRESS_INFO_S *pAddress);
+msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int contactNameOrder, int *nAddressCnt, MSG_ADDRESS_INFO_S **pAddress);
 msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int contactNameOrder, msg_struct_list_s *pAddress);
 msg_error_t MsgStoGetAddressByConvId(MsgDbHandler *pDbHandle, msg_thread_id_t convId, int contactNameOrder, msg_struct_list_s *pAddrlist);
+void MsgStoUpdateAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t convId);
 msg_error_t MsgStoAddConversation(MsgDbHandler *pDbHandle, msg_thread_id_t *pConvId);
 msg_error_t MsgStoUpdateConversation(MsgDbHandler *pDbHandle, msg_thread_id_t convId);
 msg_error_t MsgStoSetConversationDisplayName(MsgDbHandler *pDbHandle, int contactId);
 msg_error_t MsgStoSetConversationDisplayName(MsgDbHandler *pDbHandle, msg_thread_id_t convId);
 msg_error_t MsgStoClearConversationTable(MsgDbHandler *pDbHandle);
+
+msg_error_t MsgStoAddCBChannelInfo(MsgDbHandler *pDbHandle, MSG_CB_CHANNEL_S *pCBChannel, msg_sim_slot_id_t simIndex);
+msg_error_t MsgStoGetCBChannelInfo(MsgDbHandler *pDbHandle, MSG_CB_CHANNEL_S *pCBChannel, msg_sim_slot_id_t simIndex);
+
 bool MsgExistAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pConvId);
+bool MsgExistAddress(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsg,  msg_thread_id_t convId, int index);
+bool MsgExistConversation(MsgDbHandler *pDbHandle, msg_thread_id_t convId);
+bool MsgExistMessage(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsg);
 
 int MsgStoGetUnreadCnt(MsgDbHandler *pDbHandle, MSG_MAIN_TYPE_T MsgType);
 msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber);
-msg_error_t MsgStoResetContactInfo(MsgDbHandler *pDbHandle, int ContactId);
-msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int ContactId, const char *pNumber);
+msg_error_t MsgStoClearContactInfoByAddrbookIdList(MsgDbHandler *pDbHandle, int* addrbookList, int addrbookCnt);
+msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int ContactId);
+msg_error_t MsgStoResetContactInfo(MsgDbHandler *pDbHandle, int contactId);
 msg_error_t MsgStoGetMmsRawFilePath(MsgDbHandler *pDbHandle, msg_message_id_t msgId, char *pFilePath);
 bool MsgStoCheckReadReportRequested(MsgDbHandler *pDbHandle, msg_message_id_t MsgId);
 bool MsgStoCheckReadReportIsSent(MsgDbHandler *pDbHandle, msg_message_id_t MsgId);
 msg_error_t MsgStoUpdateNetworkStatus(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo, msg_network_status_t status);
-char *MsgStoReplaceString(const char *org_str, const char *old_str, const char *new_str);
-void MsgConvertNumber(const char* pSrcNum, char* pDestNum);
-msg_error_t MsgStoRefreshConversationDisplayName();
+
+// Lists
+msg_error_t MsgStoGetFolderViewList(msg_folder_id_t FolderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList);
+msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList);
+msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATION_VIEW_S *pConv);
+msg_error_t MsgStoGetConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList);
+msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList);
+msg_error_t MsgStoSearchByTag(const int tagType, msg_struct_list_s *pThreadViewList);
+
+msg_error_t MsgStoGetRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList);
+msg_error_t MsgStoGetAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList);
+msg_error_t MsgStoGetMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList);
+
 #endif // MSG_UTIL_STORAGE_H
 
index 829fb06..ad9f3e3 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MSG_VMESSAGE_H
index f43dfb5..29f50af 100755 (executable)
@@ -29,14 +29,13 @@ SET(MAPI-SRCS
 
 INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/include/common
-       ${CMAKE_SOURCE_DIR}/include/framework
        ${CMAKE_SOURCE_DIR}/include/proxy
        ${CMAKE_SOURCE_DIR}/include/utils
        ${CMAKE_SOURCE_DIR}/include/mapi
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(mapi_pkgs REQUIRED glib-2.0 dlog)
+pkg_check_modules(mapi_pkgs REQUIRED glib-2.0 dlog privacy-manager-client)
 
 FOREACH(flag ${mapi_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -53,5 +52,5 @@ TARGET_LINK_LIBRARIES(${MAPI-LIB} ${mapi_pkgs_LDFLAGS} ${UTILS-LIB} ${TRANS-PROX
 SET_TARGET_PROPERTIES(${MAPI-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${MAPI-LIB} PROPERTIES VERSION ${VERSION})
 
-INSTALL(TARGETS ${MAPI-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${MAPI-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 
index 04dbc4c..0ac5917 100755 (executable)
@@ -1,20 +1,21 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
+#include <privacy_checker_client.h>
 
 #include "MsgHandle.h"
 #include "MsgDebug.h"
 ==================================================================================================*/
 EXPORT_API int msg_open_msg_handle(msg_handle_t *handle)
 {
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
                MSG_FATAL("Input Paramter is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
        MsgHandle* pHandle = new MsgHandle();
 
@@ -39,7 +48,7 @@ EXPORT_API int msg_open_msg_handle(msg_handle_t *handle)
        *handle = (msg_handle_t)pHandle;
 
        if (*handle == NULL)
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
 
        try
        {
@@ -50,8 +59,14 @@ EXPORT_API int msg_open_msg_handle(msg_handle_t *handle)
        {
                MSG_FATAL("%s", e.what());
 
+               // Destroy MsgHandle
+               delete (MsgHandle*)(*handle);
+               (*handle) = NULL;
+
                if (e.errorCode() == MsgException::SERVER_READY_ERROR)
                        return MSG_ERR_SERVER_NOT_READY;
+               else if(e.errorCode() == MsgException::SECURITY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
                else
                        return MSG_ERR_COMMUNICATION_ERROR;
        }
@@ -62,10 +77,18 @@ EXPORT_API int msg_open_msg_handle(msg_handle_t *handle)
 
 EXPORT_API int msg_close_msg_handle(msg_handle_t *handle)
 {
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || *handle == NULL)
        {
                MSG_FATAL("Input Paramter is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)(*handle);
index 9778fee..2998193 100755 (executable)
@@ -1,20 +1,21 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
+#include <privacy_checker_client.h>
 
 #include "MsgException.h"
 #include "MsgDebug.h"
@@ -28,17 +29,25 @@ EXPORT_API int msg_add_filter(msg_handle_t handle, const msg_struct_t msg_struct
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        // TODO : check NULL in msg_struct_handle
        msg_struct_s *msg_struct = (msg_struct_s *) msg_struct_handle;
 
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        if(msg_struct->type != MSG_STRUCT_FILTER)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -61,18 +70,26 @@ EXPORT_API int msg_update_filter(msg_handle_t handle, const msg_struct_t msg_str
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        // TODO : check NULL in msg_struct_handle
        msg_struct_s *msg_struct = (msg_struct_s *) msg_struct_handle;
 
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
 
        if(msg_struct->type != MSG_STRUCT_FILTER)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -95,9 +112,17 @@ EXPORT_API int msg_delete_filter(msg_handle_t handle, msg_filter_id_t filter_id)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -120,9 +145,17 @@ EXPORT_API int msg_get_filter_list(msg_handle_t handle, msg_struct_list_s *filte
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || filter_list == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -145,9 +178,17 @@ EXPORT_API int msg_set_filter_operation(msg_handle_t handle, bool set_flag)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -170,9 +211,17 @@ EXPORT_API int msg_get_filter_operation(msg_handle_t handle, bool *set_flag)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -195,9 +244,17 @@ EXPORT_API int msg_set_filter_active(msg_handle_t handle, msg_filter_id_t filter
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
index 9c43b9b..6cd600c 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <string.h>
 #include "MsgStorageTypes.h"
 #include "MsgInternalTypes.h"
 #include "MsgMmsMessage.h"
-
+#include "MsgSerialize.h"
 #include "msg.h"
 #include "msg_private.h"
 
+msg_struct_s *__msg_message_create_address_struct()
+{
+       msg_struct_s *msg_struct = new msg_struct_s;
+       bzero(msg_struct, sizeof(msg_struct_s));
+
+       msg_struct->type = MSG_STRUCT_ADDRESS_INFO;
+       msg_struct->data = new MSG_ADDRESS_INFO_S;
+       memset(msg_struct->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+       return msg_struct;
+}
+
+void __msg_message_release_address_struct(gpointer data)
+{
+       if (data == NULL)
+               return;
+
+       msg_struct_s *addr_struct = (msg_struct_s *)data;
+       MSG_ADDRESS_INFO_S *addrInfo = (MSG_ADDRESS_INFO_S *)addr_struct->data;
+
+       delete (MSG_ADDRESS_INFO_S *)addrInfo;
+
+       addr_struct->data = NULL;
+
+       delete addr_struct;
+}
+
+
 void msg_message_create_struct(msg_struct_s *msg_struct)
 {
        MSG_MESSAGE_HIDDEN_S *msg = (MSG_MESSAGE_HIDDEN_S *)new MSG_MESSAGE_HIDDEN_S;
@@ -51,6 +79,8 @@ void msg_message_create_struct(msg_struct_s *msg_struct)
        msg->pData = NULL;
        msg->pMmsData = NULL;
        msg->mmsDataSize = 0;
+       msg->simIndex = MSG_SIM_SLOT_ID_1;
+
        /* Allocate memory for address list of message */
        msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
 
@@ -60,17 +90,17 @@ void msg_message_create_struct(msg_struct_s *msg_struct)
        msg_struct_s *pTmp = NULL;
 
        for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
-               addr_list->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
+               addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
                pTmp = (msg_struct_s *)addr_list->msg_struct_info[i];
                pTmp->type = MSG_STRUCT_ADDRESS_INFO;
                pTmp->data = new MSG_ADDRESS_INFO_S;
                memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
-
-               addr_list->msg_struct_info[i] = (msg_struct_t)pTmp;
        }
 
        msg->addr_list = addr_list;
 
+       msg->addressList = NULL;
+
        msg_struct->data = (int *)msg;
 }
 
@@ -106,6 +136,12 @@ int msg_message_release(msg_struct_s **msg_struct)
                msg->addr_list = NULL;
        }
 
+       // Free GList *addressList
+       if (msg->addressList) {
+               g_list_free_full(msg->addressList, __msg_message_release_address_struct);
+               msg->addressList = NULL;
+       }
+
        delete msg;
        (*msg_struct)->data = NULL;
 
@@ -139,37 +175,67 @@ int msg_message_get_int_value(void *data, int field, int *value)
        {
         if (msg_data->mainType == MSG_SMS_TYPE)
         {
-                       if (msg_data->subType == MSG_CB_SMS)
-                               *value = MSG_TYPE_SMS_CB;
-                       else if (msg_data->subType == MSG_JAVACB_SMS)
-                               *value = MSG_TYPE_SMS_JAVACB;
-                       else if (msg_data->subType == MSG_WAP_SI_SMS || msg_data->subType == MSG_WAP_SL_SMS)
-                               *value = MSG_TYPE_SMS_WAPPUSH;
-                       else if (msg_data->subType == MSG_MWI_VOICE_SMS || msg_data->subType == MSG_MWI_FAX_SMS
-                                       || msg_data->subType == MSG_MWI_EMAIL_SMS || msg_data->subType == MSG_MWI_OTHER_SMS)
-                               *value = MSG_TYPE_SMS_MWI;
-                       else if (msg_data->subType == MSG_SYNCML_CP)
-                               *value = MSG_TYPE_SMS_SYNCML;
-                       else if (msg_data->subType == MSG_REJECT_SMS)
-                               *value = MSG_TYPE_SMS_REJECT;
-                       else if (msg_data->subType == MSG_ETWS_SMS)
-                               *value = MSG_TYPE_SMS_ETWS_PRIMARY;
-                       else
-                               *value = MSG_TYPE_SMS;
-        }
-        else if (msg_data->mainType == MSG_MMS_TYPE)
-        {
+                       switch (msg_data->subType) {
+                               case MSG_CB_SMS :
+                                       *value = MSG_TYPE_SMS_CB;
+                                       break;
+                               case MSG_JAVACB_SMS :
+                                       *value = MSG_TYPE_SMS_JAVACB;
+                                       break;
+                               case MSG_WAP_SI_SMS :
+                               case MSG_WAP_SL_SMS :
+                                       *value = MSG_TYPE_SMS_WAPPUSH;
+                                       break;
+                               case MSG_MWI_VOICE_SMS :
+                               case MSG_MWI_FAX_SMS :
+                               case MSG_MWI_EMAIL_SMS :
+                               case MSG_MWI_OTHER_SMS :
+                                       *value = MSG_TYPE_SMS_MWI;
+                                       break;
+                               case MSG_SYNCML_CP :
+                                       *value = MSG_TYPE_SMS_SYNCML;
+                                       break;
+                               case MSG_REJECT_SMS :
+                                       *value = MSG_TYPE_SMS_REJECT;
+                                       break;
+                               case MSG_ETWS_SMS :
+                                       *value = MSG_TYPE_SMS_ETWS_PRIMARY;
+                                       break;
+                               case MSG_CMAS_PRESIDENTIAL :
+                                       *value = MSG_TYPE_SMS_CMAS_PRESIDENTIAL;
+                                       break;
+                               case MSG_CMAS_EXTREME :
+                                       *value = MSG_TYPE_SMS_CMAS_EXTREME;
+                                       break;
+                               case MSG_CMAS_SEVERE :
+                                       *value = MSG_TYPE_SMS_CMAS_SEVERE;
+                                       break;
+                               case MSG_CMAS_AMBER :
+                                       *value = MSG_TYPE_SMS_CMAS_AMBER;
+                                       break;
+                               case MSG_CMAS_TEST :
+                                       *value = MSG_TYPE_SMS_CMAS_TEST;
+                                       break;
+                               case MSG_CMAS_OPERATOR_DEFINED :
+                                       *value = MSG_TYPE_SMS_CMAS_OPERATOR_DEFINED;
+                                       break;
+                               default :
+                                       *value = MSG_TYPE_SMS;
+                       }
+               }
+               else if (msg_data->mainType == MSG_MMS_TYPE)
+               {
                        if (msg_data->subType == MSG_NOTIFICATIONIND_MMS)
                                *value = MSG_TYPE_MMS_NOTI;
                        else if (msg_data->subType == MSG_SENDREQ_JAVA_MMS)
                                *value = MSG_TYPE_MMS_JAVA;
                        else
                                *value = MSG_TYPE_MMS;
-        }
-        else
-               *value = MSG_TYPE_INVALID;
+               }
+               else
+                       *value = MSG_TYPE_INVALID;
 
-       break;
+               break;
        }
        case MSG_MESSAGE_CLASS_TYPE_INT :
                *value = msg_data->classType;
@@ -204,6 +270,9 @@ int msg_message_get_int_value(void *data, int field, int *value)
        case MSG_MESSAGE_DATA_SIZE_INT :
                *value = msg_data->dataSize;
                break;
+       case MSG_MESSAGE_SIM_INDEX_INT :
+               *value = msg_data->simIndex;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -234,6 +303,14 @@ int msg_message_get_bool_value(void *data, int field, bool *value)
        case MSG_MESSAGE_PORT_VALID_BOOL :
                *value = msg_data->bPortValid;
                break;
+       case MSG_MESSAGE_REPLACE_BOOL :
+       {
+               if (msg_data->subType >= MSG_REPLACE_TYPE1_SMS && msg_data->subType <= MSG_REPLACE_TYPE7_SMS)
+                       *value = true;
+               else
+                       *value = false;
+               break;
+       }
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -314,6 +391,9 @@ int msg_message_get_list_hnd(void *data, int field, void **value)
        case MSG_MESSAGE_ADDR_LIST_STRUCT :
                *value = (void *)msg_data->addr_list;
                break;
+       case MSG_MESSAGE_ADDR_LIST_HND :
+               *value = (msg_list_handle_t)msg_data->addressList;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -403,6 +483,9 @@ int msg_message_set_int_value(void *data, int field, int value)
        case MSG_MESSAGE_DATA_SIZE_INT :
                msg_data->dataSize = value;
                break;
+       case MSG_MESSAGE_SIM_INDEX_INT :
+               msg_data->simIndex = value;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -516,6 +599,7 @@ void msg_message_copy_message(MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_HIDDEN_S *
        pDst->bPortValid = pSrc->bPortValid;
        pDst->dataSize = pSrc->dataSize;
        pDst->mmsDataSize = pSrc->mmsDataSize;
+       pDst->simIndex = pSrc->simIndex;
        memcpy(pDst->subject, pSrc->subject, sizeof(pDst->subject));
 
        if(pSrc->pMmsData && pSrc->mmsDataSize)
@@ -548,6 +632,22 @@ void msg_message_copy_message(MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_HIDDEN_S *
                memcpy(pDst->thumbPath, pSrc->thumbPath, sizeof(pDst->thumbPath));
        }
 
+       for (unsigned int i=0; i < g_list_length(pSrc->addressList); i++) {
+               msg_struct_s *addr_struct = __msg_message_create_address_struct();
+               MSG_ADDRESS_INFO_S *addrInfo = (MSG_ADDRESS_INFO_S *)addr_struct->data;
+
+               msg_struct_s *addr_info = (msg_struct_s *)g_list_nth_data(pSrc->addressList,(guint)i);
+               MSG_ADDRESS_INFO_S *address = (MSG_ADDRESS_INFO_S *)addr_info->data;
+
+               addrInfo->addressType = address->addressType;
+               addrInfo->recipientType = address->recipientType;
+               addrInfo->contactId = address->contactId;
+               strncpy(addrInfo->addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
+               strncpy(addrInfo->displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
+               addrInfo->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
+
+               pDst->addressList = g_list_append(pDst->addressList, addr_struct);
+       }
 }
 
 int msg_cb_message_get_int_value(void *data, int field, int *value)
@@ -565,12 +665,34 @@ int msg_cb_message_get_int_value(void *data, int field, int *value)
        {
                case MSG_CB_MSG_TYPE_INT :
                        {
-                               if ( cb_msg->type == MSG_ETWS_SMS )
-                                       *value = MSG_TYPE_SMS_ETWS_PRIMARY;
-                               else if ( cb_msg->type == MSG_CB_SMS )
-                                       *value = ((cb_msg->messageId & 0xFFF8) == 0x1100 ) ? MSG_TYPE_SMS_ETWS_SECONDARY : MSG_TYPE_SMS_CB;
-                               else
-                                       ret = MSG_ERR_UNKNOWN;
+                               switch (cb_msg->type) {
+                                       case MSG_ETWS_SMS :
+                                               *value = MSG_TYPE_SMS_ETWS_PRIMARY;
+                                               break;
+                                       case MSG_CB_SMS:
+                                               *value = ((cb_msg->messageId & 0xFFF8) == 0x1100 ) ? MSG_TYPE_SMS_ETWS_SECONDARY : MSG_TYPE_SMS_CB;
+                                               break;
+                                       case MSG_CMAS_PRESIDENTIAL :
+                                               *value = MSG_TYPE_SMS_CMAS_PRESIDENTIAL;
+                                               break;
+                                       case MSG_CMAS_EXTREME :
+                                               *value = MSG_TYPE_SMS_CMAS_EXTREME;
+                                               break;
+                                       case MSG_CMAS_SEVERE :
+                                               *value = MSG_TYPE_SMS_CMAS_SEVERE;
+                                               break;
+                                       case MSG_CMAS_AMBER :
+                                               *value = MSG_TYPE_SMS_CMAS_AMBER;
+                                               break;
+                                       case MSG_CMAS_TEST :
+                                               *value = MSG_TYPE_SMS_CMAS_TEST;
+                                               break;
+                                       case MSG_CMAS_OPERATOR_DEFINED :
+                                               *value = MSG_TYPE_SMS_CMAS_OPERATOR_DEFINED;
+                                               break;
+                                       default :
+                                               ret = MSG_ERR_UNKNOWN;
+                               }
                        }
                        break;
                case MSG_CB_MSG_RECV_TIME_INT :
@@ -665,15 +787,21 @@ EXPORT_API int msg_get_mms_struct(msg_struct_t msg_struct_handle, msg_struct_t m
 
        MSG_MESSAGE_HIDDEN_S *msg_data = (MSG_MESSAGE_HIDDEN_S *)msg_struct->data;
 
-       MMS_MESSAGE_DATA_S *tmp_mms_data  = (MMS_MESSAGE_DATA_S *)calloc(1, sizeof(MMS_MESSAGE_DATA_S));
+       if (msg_data->pMmsData == NULL) {
+               return MSG_ERR_INVALID_PARAMETER;
+       }
 
-       _MsgMmsDeserializeMessageData(tmp_mms_data, (char*)msg_data->pMmsData);
+       MMS_DATA_S *mms_data = NULL;
 
-       convert_from_mmsdata(tmp_mms_data, mms_struct);
+       MsgDeserializeMmsData((char*)msg_data->pMmsData, msg_data->mmsDataSize, &mms_data);
 
-       MsgMmsReleaseMmsLists(tmp_mms_data);
+       if (mms_data) {
+               convert_to_hidden_mmsdata(mms_data, mms_struct);
 
-       free(tmp_mms_data);
+               MsgMmsRelease(&mms_data);
+       } else {
+               return MSG_ERR_INVALID_PARAMETER;
+       }
 
        return ret;
 }
@@ -699,15 +827,89 @@ EXPORT_API int msg_set_mms_struct(msg_struct_t msg_struct_handle, msg_struct_t m
 
        MSG_MESSAGE_HIDDEN_S *msg_data = (MSG_MESSAGE_HIDDEN_S *)msg_struct->data;
 
-       MMS_MESSAGE_DATA_S *tmp_mms_data = (MMS_MESSAGE_DATA_S *)calloc(1,sizeof(MMS_MESSAGE_DATA_S));
+       MMS_DATA_S *mms_data = MsgMmsCreate();
+
+       convert_from_hidden_mmsdata(mms_struct, mms_data);
+
+       int mmsDataSize = MsgSerializeMms(mms_data, (char **)&msg_data->pMmsData);
 
-       convert_to_mmsdata(mms_struct, tmp_mms_data);
+       if (mmsDataSize > 0)
+               msg_data->mmsDataSize = mmsDataSize;
 
-       msg_data->pMmsData = _MsgMmsSerializeMessageData(tmp_mms_data, &(msg_data->mmsDataSize));
+       //TODO:: set subtype
 
-       MsgMmsReleaseMmsLists(tmp_mms_data);
+       MsgMmsRelease(&mms_data);
+
+       return ret;
+}
+
+
+int msg_message_list_append(msg_struct_t msg_struct_handle, int field, msg_struct_t *item)
+{
+       msg_error_t err = MSG_SUCCESS;
+       msg_struct_s *msg_struct = (msg_struct_s *)msg_struct_handle;
+       MSG_MESSAGE_HIDDEN_S *msg_data = (MSG_MESSAGE_HIDDEN_S *)msg_struct->data;
+
+       msg_struct_s *msg_struct_item = NULL;
+       switch(field) {
+       case MSG_MESSAGE_ADDR_LIST_HND:
+       {
+               msg_struct_item = __msg_message_create_address_struct();
+               msg_data->addressList = g_list_append(msg_data->addressList, msg_struct_item);
+               *item = (msg_struct_t)msg_struct_item;
+       }
+       break;
+       default :
+               err = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return err;
+}
+
+
+int msg_message_list_clear(msg_struct_t msg_struct_handle, int field)
+{
+       msg_error_t err = MSG_SUCCESS;
+       msg_struct_s *msg_struct = (msg_struct_s *)msg_struct_handle;
+       MSG_MESSAGE_HIDDEN_S *msg_data = (MSG_MESSAGE_HIDDEN_S *)msg_struct->data;
+
+       switch(field) {
+       case MSG_MESSAGE_ADDR_LIST_HND:
+       {
+               // Free GList *addressList
+               if (msg_data->addressList) {
+                       g_list_free_full(msg_data->addressList, __msg_message_release_address_struct);
+                       msg_data->addressList = NULL;
+               }
+       }
+       break;
+       default :
+               err = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return err;
+}
+
+int msg_conversation_get_list_hnd(void *data, int field, void **value)
+{
+       if (!data)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_SUCCESS;
+
+       MSG_CONVERSATION_VIEW_S *msg_data = (MSG_CONVERSATION_VIEW_S *)data;
+
+       switch (field) {
+       case MSG_CONV_MSG_MULTIPART_HND :
+               *value = (void *)msg_data->multipart_list;
+               break;
+       default :
+               ret = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
 
-       free(tmp_mms_data);
        return ret;
 }
 
index 71d9fba..43b0758 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -28,7 +28,7 @@
 #include "msg_private.h"
 
 //Internel Struct
-typedef struct _MMS_DATA_S
+typedef struct
 {
        GList                   *pagelist;
        GList                   *regionlist;
@@ -37,6 +37,9 @@ typedef struct _MMS_DATA_S
        GList                   *metalist;
        MMS_SMIL_ROOTLAYOUT     rootlayout;
        MMS_APPID_INFO_S        msgAppId;
+       MMS_HEADER_DATA_S header;
+       MMS_MULTIPART_DATA_S smil;
+       GList *multipartlist;//MMS_MULTIPART_DATA_S
 } MMS_DATA_HIDDEN_S;
 
 typedef struct
@@ -53,8 +56,12 @@ typedef struct
        char                    szDrm2FullPath[MSG_FILEPATH_LEN_MAX + 1];  /**< Indicates the fullpath of the DRM */
        msg_struct_s *pText;
        msg_struct_s *pAVI;
+       char szContentType[MSG_MSG_ID_LEN + 1];
+       char szContentLocation[MSG_MSG_ID_LEN + 1];
+
 } MMS_MEDIA_HIDDEN_S;
 
+static void __msg_mms_data_struct_init(MMS_DATA_HIDDEN_S *pMmsDataHidden);
 static void __msg_mms_release_mms(msg_struct_s *mms_struct);
 static void __msg_mms_release_page(msg_struct_s *page_struct);
 static void __msg_mms_release_media(msg_struct_s *media_struct);
@@ -62,7 +69,7 @@ static void __msg_mms_release_region(msg_struct_s *region_struct);
 static void __msg_mms_release_attach(msg_struct_s *attach_struct);
 static void __msg_mms_release_transition(msg_struct_s *transition_struct);
 static void __msg_mms_release_meta(msg_struct_s *meta_struct);
-
+static void __msg_mms_release_multipart(msg_struct_s *multipart_struct);
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
@@ -116,6 +123,7 @@ void *msg_mms_create_struct_data(int field)
        case MSG_STRUCT_MMS:
                data = (void *)new MMS_DATA_HIDDEN_S;
                bzero(data, sizeof(MMS_DATA_HIDDEN_S));
+               __msg_mms_data_struct_init((MMS_DATA_HIDDEN_S *)data);
                break;
        case MSG_STRUCT_MMS_PAGE:
                data = (void *)new MMS_PAGE_S;
@@ -156,6 +164,11 @@ void *msg_mms_create_struct_data(int field)
                data = (void *)new MmsSmilAVI;
                bzero(data, sizeof(MmsSmilAVI));
                break;
+       case MSG_STRUCT_MULTIPART_INFO:
+               data = new MMS_MULTIPART_DATA_S;
+               bzero(data, sizeof(MMS_MULTIPART_DATA_S));
+               MsgMmsInitMultipart((MMS_MULTIPART_DATA_S *)data);
+               break;
        }
 
        return data;
@@ -176,81 +189,120 @@ void msg_mms_list_item_free_func(gpointer data)
                __msg_mms_release_transition(msg_struct);
        } else if (msg_struct->type == MSG_STRUCT_MMS_META) {
                __msg_mms_release_meta(msg_struct);
+       } else if (msg_struct->type == MSG_STRUCT_MULTIPART_INFO) {
+               __msg_mms_release_multipart(msg_struct);
        }
 }
 
 void __msg_mms_release_page(msg_struct_s *page_struct)
 {
-       MMS_PAGE_S *page = (MMS_PAGE_S *)page_struct->data;
-       if (page->medialist) {
-                g_list_free_full(page->medialist, msg_mms_list_item_free_func);
-       }
+       if (page_struct) {
+               MMS_PAGE_S *page = (MMS_PAGE_S *)page_struct->data;
 
-       delete (MMS_PAGE_S *)page;
-       page_struct->data = NULL;
+               if (page) {
+                       if (page->medialist) {
+                                g_list_free_full(page->medialist, msg_mms_list_item_free_func);
+                       }
 
-       delete page_struct;
+                       delete (MMS_PAGE_S *)page;
+                       page_struct->data = NULL;
+               }
+
+               delete page_struct;
+       }
 }
 
 void __msg_mms_release_media(msg_struct_s *media_struct)
 {
-       MMS_MEDIA_HIDDEN_S *media = (MMS_MEDIA_HIDDEN_S *)media_struct->data;
+       if (media_struct) {
+               MMS_MEDIA_HIDDEN_S *media = (MMS_MEDIA_HIDDEN_S *)media_struct->data;
 
-       if (media->pText)
-               msg_mms_release_struct(&media->pText);
+               if (media) {
+                       if (media->pText)
+                               msg_mms_release_struct(&media->pText);
 
-       if (media->pAVI)
-               msg_mms_release_struct(&media->pAVI);
+                       if (media->pAVI)
+                               msg_mms_release_struct(&media->pAVI);
 
-       delete (MMS_MEDIA_HIDDEN_S *)media;
+                       delete (MMS_MEDIA_HIDDEN_S *)media;
 
-       media_struct->data = NULL;
+                       media_struct->data = NULL;
+               }
 
-       delete media_struct;
+               delete media_struct;
+       }
 }
 
 void __msg_mms_release_attach(msg_struct_s *attach_struct)
 {
-       MMS_ATTACH_S *attach = (MMS_ATTACH_S *)attach_struct->data;
+       if (attach_struct) {
+               MMS_ATTACH_S *attach = (MMS_ATTACH_S *)attach_struct->data;
 
-       delete (MMS_ATTACH_S *)attach;
+               if (attach)
+                       delete (MMS_ATTACH_S *)attach;
 
-       attach_struct->data = NULL;
+               attach_struct->data = NULL;
 
-       delete attach_struct;
+               delete attach_struct;
+       }
 }
 
 void __msg_mms_release_region(msg_struct_s *region_struct)
 {
-       MMS_SMIL_REGION *region = (MMS_SMIL_REGION *)region_struct->data;
+       if (region_struct) {
+               MMS_SMIL_REGION *region = (MMS_SMIL_REGION *)region_struct->data;
 
-       delete (MMS_SMIL_REGION *)region;
+               if (region)
+                       delete (MMS_SMIL_REGION *)region;
 
-       region_struct->data = NULL;
+               region_struct->data = NULL;
 
-       delete region_struct;
+               delete region_struct;
+       }
 }
 
 void __msg_mms_release_transition(msg_struct_s *transition_struct)
 {
-       MMS_SMIL_TRANSITION *transition = (MMS_SMIL_TRANSITION *)transition_struct->data;
+       if (transition_struct) {
+               MMS_SMIL_TRANSITION *transition = (MMS_SMIL_TRANSITION *)transition_struct->data;
 
-       delete (MMS_SMIL_TRANSITION *)transition;
+               if (transition)
+                       delete (MMS_SMIL_TRANSITION *)transition;
 
-       transition_struct->data = NULL;
+               transition_struct->data = NULL;
 
-       delete transition_struct;
+               delete transition_struct;
+       }
 }
 
 void __msg_mms_release_meta(msg_struct_s *meta_struct)
 {
-       MMS_SMIL_META *meta = (MMS_SMIL_META *)meta_struct->data;
+       if (meta_struct) {
+               MMS_SMIL_META *meta = (MMS_SMIL_META *)meta_struct->data;
 
-       delete (MMS_SMIL_META *)meta;
+               if (meta)
+                       delete (MMS_SMIL_META *)meta;
 
-       meta_struct->data = NULL;
+               meta_struct->data = NULL;
 
-       delete meta_struct;
+               delete meta_struct;
+       }
+}
+
+void __msg_mms_release_multipart(msg_struct_s *multipart_struct)
+{
+       if (multipart_struct) {
+               MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)multipart_struct->data;
+
+               if (multipart) {
+                       g_free(multipart->pMultipartData); multipart->pMultipartData = NULL;
+                       delete (MMS_MULTIPART_DATA_S *)multipart;
+               }
+
+               multipart_struct->data = NULL;
+
+               delete multipart_struct;
+       }
 }
 
 void __msg_mms_release_mms(msg_struct_s *mms_struct)
@@ -282,6 +334,11 @@ void __msg_mms_release_mms(msg_struct_s *mms_struct)
                mms->metalist = NULL;
        }
 
+       if (mms->multipartlist) {
+               g_list_free_full(mms->multipartlist, msg_mms_list_item_free_func);
+               mms->multipartlist = NULL;
+       }
+
        delete (MMS_DATA_HIDDEN_S *)mms;
 
        mms_struct->data = NULL;
@@ -325,16 +382,33 @@ int msg_mms_release_struct(msg_struct_s **msg_struct_data)
                *msg_struct_data = NULL;
                break;
        case MSG_STRUCT_MMS_SMIL_TEXT:
-               delete (MmsSmilText*)msg_struct->data;
+                if (msg_struct->data) {
+                    delete (MmsSmilText*)msg_struct->data;
+                    msg_struct->data = NULL;
+                }
                delete msg_struct;
                *msg_struct_data = NULL;
                break;
        case MSG_STRUCT_MMS_SMIL_AVI:
-               delete (MmsSmilAVI*)msg_struct->data;
+                if (msg_struct->data) {
+                   delete (MmsSmilAVI*)msg_struct->data;
+                    msg_struct->data = NULL;
+                }
+               delete msg_struct;
+               *msg_struct_data = NULL;
+               break;
+       case MSG_STRUCT_MULTIPART_INFO:
+       {
+                if (msg_struct->data) {
+                    delete (MMS_MULTIPART_DATA_S *)(msg_struct->data);
+                    msg_struct->data = NULL;
+                }
+
                delete msg_struct;
                *msg_struct_data = NULL;
                break;
        }
+       }
 
        return 0;
 }
@@ -347,12 +421,39 @@ int msg_mms_get_int_value(msg_struct_s *msg_struct, int field, int *value)
        case MSG_STRUCT_MMS:
        {
                MMS_DATA_HIDDEN_S *mms_data = (MMS_DATA_HIDDEN_S *)msg_struct->data;
-               if (field == MSG_MMS_ROOTLAYOUT_WIDTH_INT)
+               if (field == MSG_MMS_ROOTLAYOUT_WIDTH_INT) {
                        *value = mms_data->rootlayout.width.value;
-               else if (field == MSG_MMS_ROOTLAYOUT_HEIGHT_INT)
+               } else if (field == MSG_MMS_ROOTLAYOUT_HEIGHT_INT) {
                        *value = mms_data->rootlayout.height.value;
-               else if (field == MSG_MMS_ROOTLAYOUT_BGCOLOR_INT)
+               } else if (field == MSG_MMS_ROOTLAYOUT_BGCOLOR_INT) {
                        *value = mms_data->rootlayout.bgColor;
+               } else if (field == MSG_MMS_HEADER_DATE_INT) {
+                       *value = mms_data->header.date;
+               } else if (field == MSG_MMS_HEADER_DELIVERY_REPORT_INT) {
+                       *value = mms_data->header.bDeliveryReport;
+               } else if (field == MSG_MMS_HEADER_DELIVERY_TIME_INT) {
+                       *value = mms_data->header.delivery.time;
+               } else if (field == MSG_MMS_HEADER_EXPIRY_TIME_INT) {
+                       *value = mms_data->header.expiry.time;
+               } else if (field == MSG_MMS_HEADER_MESSAGE_CLASS_INT) {
+                       *value = mms_data->header.messageClass;
+               } else if (field == MSG_MMS_HEADER_MESSAGE_TYPE_INT) {
+                       *value = mms_data->header.messageType;
+               } else if (field == MSG_MMS_HEADER_VERSION_INT) {
+                       *value = mms_data->header.mmsVersion;
+               } else if (field == MSG_MMS_HEADER_SIZE_INT) {
+                       *value = mms_data->header.messageSize;
+               } else if (field == MSG_MMS_HEADER_PRIORITY_INT) {
+                       *value = mms_data->header.mmsPriority;
+               } else if (field == MSG_MMS_HEADER_READ_REPORT_INT) {
+                       *value = mms_data->header.bReadReport;
+               } else if (field == MSG_MMS_HEADER_HIDE_ADDRESS_INT) {
+                       *value = mms_data->header.bHideAddress;
+               } else if (field == MSG_MMS_HEADER_MMS_STATUS_INT) {
+                       *value = mms_data->header.mmsStatus;
+               } else if (field == MSG_MMS_HEADER_CONTENT_CLASS_INT) {
+                       *value = mms_data->header.contentClass;
+               }
                else
                        err = MSG_ERR_INVALID_PARAMETER;
        }
@@ -472,11 +573,15 @@ int msg_mms_get_int_value(msg_struct_s *msg_struct, int field, int *value)
                        err = MSG_ERR_INVALID_PARAMETER;
        }
        break;
+       case MSG_STRUCT_MULTIPART_INFO:
+               err = msg_multipart_get_int_value(msg_struct->data, field, value);
+       break;
+
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_get_str_value(msg_struct_s *msg_struct, int field, char *value, int size)
@@ -484,6 +589,35 @@ int msg_mms_get_str_value(msg_struct_s *msg_struct, int field, char *value, int
        msg_error_t err = MSG_SUCCESS;
 
        switch(msg_struct->type) {
+       case MSG_STRUCT_MMS:
+       {
+               MMS_DATA_HIDDEN_S *mms_data = (MMS_DATA_HIDDEN_S *)msg_struct->data;
+               if (field == MSG_MMS_HEADER_CONTENT_LOCATION_STR) {// mms header
+                       strncpy(value, mms_data->header.contentLocation, size);
+               } else if (field == MSG_MMS_HEADER_CONTENT_TYPE_STR) {
+                       strncpy(value, mms_data->header.szContentType, size);
+               } else if (field == MSG_MMS_HEADER_FROM_STR) {
+                       strncpy(value, mms_data->header.szFrom, size);
+               } else if (field == MSG_MMS_HEADER_MESSAGE_ID_STR) {
+                       strncpy(value, mms_data->header.messageID, size);
+               } else if (field == MSG_MMS_HEADER_TR_ID_STR) {
+                       strncpy(value, mms_data->header.trID, size);
+
+               } else if (field == MSG_MMS_SMIL_MULTIPART_CONTENT_TYPE_STR) { // smil
+                       strncpy(value, mms_data->smil.szContentType, size);
+               } else if (field == MSG_MMS_SMIL_MULTIPART_NAME_STR) {
+                       strncpy(value, mms_data->smil.szFileName, size);
+               } else if (field == MSG_MMS_SMIL_MULTIPART_FILEPATH_STR) {
+                       strncpy(value, mms_data->smil.szFilePath, size);
+               } else if (field == MSG_MMS_SMIL_MULTIPART_CONTENT_ID_STR) {
+                       strncpy(value, mms_data->smil.szContentID, size);
+               } else if (field == MSG_MMS_SMIL_MULTIPART_CONTENT_LOCATION_STR) {
+                       strncpy(value, mms_data->smil.szContentLocation, size);
+               }
+               else
+                       err = MSG_ERR_INVALID_PARAMETER;
+       }
+       break;
        case MSG_STRUCT_MMS_MEDIA:
        {
                MMS_MEDIA_HIDDEN_S *mms_media_data = (MMS_MEDIA_HIDDEN_S *)msg_struct->data;
@@ -502,6 +636,10 @@ int msg_mms_get_str_value(msg_struct_s *msg_struct, int field, char *value, int
                        strncpy(value, mms_media_data->szAlt, size);
                else if (field == MSG_MMS_MEDIA_DRM_FULLPATH_STR)
                        strncpy(value, mms_media_data->szDrm2FullPath, size);
+               else if (field == MSG_MMS_MEDIA_CONTENT_LOCATION_STR)
+                       strncpy(value, mms_media_data->szContentLocation, size);
+               else if (field == MSG_MMS_MEDIA_CONTENT_TYPE_STR)
+                       strncpy(value, mms_media_data->szContentType, size);
                else
                        err = MSG_ERR_INVALID_PARAMETER;
        }
@@ -515,6 +653,8 @@ int msg_mms_get_str_value(msg_struct_s *msg_struct, int field, char *value, int
                        strncpy(value, mms_attach_data->szFilePath, size);
                else if (field == MSG_MMS_ATTACH_DRM_FULLPATH_STR)
                        strncpy(value, mms_attach_data->szDrm2FullPath, size);
+               else if (field == MSG_MMS_ATTACH_CONTENT_TYPE_STR)
+                       strncpy(value, mms_attach_data->szContentType, size);
                else
                        err = MSG_ERR_INVALID_PARAMETER;
        }
@@ -572,11 +712,15 @@ int msg_mms_get_str_value(msg_struct_s *msg_struct, int field, char *value, int
                        err = MSG_ERR_INVALID_PARAMETER;
        }
        break;
+       case MSG_STRUCT_MULTIPART_INFO:
+               err = msg_multipart_get_str_value(msg_struct->data, field, value, size);
+       break;
+
        default :
                        err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_get_bool_value(msg_struct_s *msg_struct, int field, bool *value)
@@ -633,7 +777,7 @@ int msg_mms_get_bool_value(msg_struct_s *msg_struct, int field, bool *value)
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_get_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s **value)
@@ -656,7 +800,7 @@ int msg_mms_get_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_get_list_handle(msg_struct_s *msg_struct, int field, msg_list_handle_t *value)
@@ -677,6 +821,8 @@ int msg_mms_get_list_handle(msg_struct_s *msg_struct, int field, msg_list_handle
                        *value = (msg_list_handle_t)mms_data->transitionlist;
                else if (field == MSG_MMS_META_LIST_HND)
                        *value = (msg_list_handle_t)mms_data->metalist;
+               else if (field == MSG_MMS_MULTIPART_LIST_HND)
+                       *value = (msg_list_handle_t)mms_data->multipartlist;
                else
                        err = MSG_ERR_INVALID_PARAMETER;
        }
@@ -694,7 +840,7 @@ int msg_mms_get_list_handle(msg_struct_s *msg_struct, int field, msg_list_handle
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 /*SET*/
 int msg_mms_set_int_value(msg_struct_s *msg_struct, int field, int value)
@@ -713,6 +859,35 @@ int msg_mms_set_int_value(msg_struct_s *msg_struct, int field, int value)
                        mms_data->rootlayout.bBgColor = true;
                        mms_data->rootlayout.bgColor = value;
                }
+
+                else if (field == MSG_MMS_HEADER_DATE_INT) {
+                       mms_data->header.date = value;
+               } else if (field == MSG_MMS_HEADER_DELIVERY_REPORT_INT) {
+                       mms_data->header.bDeliveryReport = (bool)value;
+               } else if (field == MSG_MMS_HEADER_DELIVERY_TIME_INT) {
+                       mms_data->header.delivery.time = value;
+               } else if (field == MSG_MMS_HEADER_EXPIRY_TIME_INT) {
+                       mms_data->header.expiry.time = value;
+               } else if (field == MSG_MMS_HEADER_MESSAGE_CLASS_INT) {
+                       mms_data->header.messageClass = value;
+               } else if (field == MSG_MMS_HEADER_MESSAGE_TYPE_INT) {
+                       mms_data->header.messageType = value;
+               } else if (field == MSG_MMS_HEADER_VERSION_INT) {
+                       mms_data->header.mmsVersion = value;
+               } else if (field == MSG_MMS_HEADER_SIZE_INT) {
+                       mms_data->header.messageSize = value;
+               } else if (field == MSG_MMS_HEADER_PRIORITY_INT) {
+                       mms_data->header.mmsPriority = value;
+               } else if (field == MSG_MMS_HEADER_READ_REPORT_INT) {
+                       mms_data->header.bReadReport = (bool)value;
+               } else if (field == MSG_MMS_HEADER_HIDE_ADDRESS_INT) {
+                       mms_data->header.bHideAddress = value;
+               } else if (field == MSG_MMS_HEADER_MMS_STATUS_INT) {
+                       mms_data->header.mmsStatus = value;
+               } else if (field == MSG_MMS_HEADER_CONTENT_CLASS_INT) {
+                       mms_data->header.contentClass = value;
+               }
+
                else
                        err = MSG_ERR_INVALID_PARAMETER;
        }
@@ -837,7 +1012,7 @@ int msg_mms_set_int_value(msg_struct_s *msg_struct, int field, int value)
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_set_str_value(msg_struct_s *msg_struct, int field, char *value, int size)
@@ -855,7 +1030,7 @@ int msg_mms_set_str_value(msg_struct_s *msg_struct, int field, char *value, int
                } else if (field == MSG_MMS_MEDIA_FILEPATH_STR) {
                        char *filename = NULL;
                        if (value != NULL) {
-                               MSG_DEBUG("media file path = %s", value);
+                               MSG_SEC_DEBUG("media file path = %s", value);
                                strncpy(mms_media_data->szFilePath, value, MSG_FILEPATH_LEN_MAX);
                                filename = strrchr(value, '/');
                                if (filename != NULL) {
@@ -877,6 +1052,10 @@ int msg_mms_set_str_value(msg_struct_s *msg_struct, int field, char *value, int
                        strncpy(mms_media_data->szAlt, value, MAX_SMIL_ALT_LEN);
                else if (field == MSG_MMS_MEDIA_DRM_FULLPATH_STR)
                        strncpy(mms_media_data->szDrm2FullPath, value, MSG_FILEPATH_LEN_MAX);
+               else if (field == MSG_MMS_MEDIA_CONTENT_LOCATION_STR)
+                       strncpy(mms_media_data->szContentLocation, value, MSG_FILEPATH_LEN_MAX);
+               else if (field == MSG_MMS_MEDIA_CONTENT_TYPE_STR)
+                       strncpy(mms_media_data->szContentType, value, MSG_FILEPATH_LEN_MAX);
                else
                        err = MSG_ERR_INVALID_PARAMETER;
        }
@@ -884,14 +1063,14 @@ int msg_mms_set_str_value(msg_struct_s *msg_struct, int field, char *value, int
        case MSG_STRUCT_MMS_ATTACH:
        {
                MMS_ATTACH_S *mms_attach_data = (MMS_ATTACH_S *)msg_struct->data;
-               if (field == MSG_MMS_ATTACH_FILENAME_STR)
+               if (field == MSG_MMS_ATTACH_FILENAME_STR) {
                        strncpy(mms_attach_data->szFileName, value, MSG_FILENAME_LEN_MAX);
-               else if (field == MSG_MMS_ATTACH_FILEPATH_STR) {
+               else if (field == MSG_MMS_ATTACH_FILEPATH_STR) {
                        char *filename = NULL;
                        char *filepath = value;
 
                        if (filepath != NULL) {
-                               MSG_DEBUG("attach file path = %s", filepath);
+                               MSG_SEC_DEBUG("attach file path = %s", filepath);
                                mms_attach_data->mediatype = MIME_UNKNOWN;
                                mms_attach_data->fileSize = -1;
 
@@ -908,10 +1087,13 @@ int msg_mms_set_str_value(msg_struct_s *msg_struct, int field, char *value, int
                                MSG_DEBUG("attach file path is NULL");
                                err = MSG_ERR_INVALID_PARAMETER;
                        }
-               } else if (field == MSG_MMS_ATTACH_DRM_FULLPATH_STR)
+               } else if (field == MSG_MMS_ATTACH_DRM_FULLPATH_STR) {
                        strncpy(mms_attach_data->szDrm2FullPath, value, MSG_FILEPATH_LEN_MAX);
-               else
+               } else if (field == MSG_MMS_ATTACH_CONTENT_TYPE_STR) {
+                       strncpy(mms_attach_data->szContentType, value, MSG_FILEPATH_LEN_MAX);
+               } else {
                        err = MSG_ERR_INVALID_PARAMETER;
+               }
        }
        break;
        case MSG_STRUCT_MMS_REGION:
@@ -967,11 +1149,44 @@ int msg_mms_set_str_value(msg_struct_s *msg_struct, int field, char *value, int
                        err = MSG_ERR_INVALID_PARAMETER;
        }
        break;
+       case MSG_STRUCT_MMS:
+       {
+               MMS_DATA_HIDDEN_S *mms_data = (MMS_DATA_HIDDEN_S *)msg_struct->data;
+               if (field == MSG_MMS_HEADER_CONTENT_LOCATION_STR) {// mms header
+                       strncpy(mms_data->header.contentLocation, value, sizeof(mms_data->header.contentLocation) - 1 );
+               } else if (field == MSG_MMS_HEADER_CONTENT_TYPE_STR) {
+                       strncpy(mms_data->header.szContentType, value, sizeof(mms_data->header.szContentType) - 1 );
+               } else if (field == MSG_MMS_HEADER_FROM_STR) {
+                       strncpy(mms_data->header.szFrom, value, sizeof(mms_data->header.szFrom) - 1 );
+               } else if (field == MSG_MMS_HEADER_MESSAGE_ID_STR) {
+                       strncpy(mms_data->header.messageID, value, sizeof(mms_data->header.messageID) - 1 );
+               } else if (field == MSG_MMS_HEADER_TR_ID_STR) {
+                       strncpy(mms_data->header.trID, value, sizeof(mms_data->header.trID) - 1 );
+
+               } else if (field == MSG_MMS_SMIL_MULTIPART_CONTENT_TYPE_STR) { // smil
+                       strncpy(mms_data->smil.szContentType, value, sizeof(mms_data->smil.szContentType) - 1 );
+               } else if (field == MSG_MMS_SMIL_MULTIPART_NAME_STR) {
+                       strncpy(mms_data->smil.szFileName, value, sizeof(mms_data->smil.szFileName) - 1 );
+               } else if (field == MSG_MMS_SMIL_MULTIPART_FILEPATH_STR) {
+                       strncpy(mms_data->smil.szFilePath, value, sizeof(mms_data->smil.szFilePath) - 1 );
+               } else if (field == MSG_MMS_SMIL_MULTIPART_CONTENT_ID_STR) {
+                       strncpy(mms_data->smil.szContentID, value, sizeof(mms_data->smil.szContentID) - 1 );
+               } else if (field == MSG_MMS_SMIL_MULTIPART_CONTENT_LOCATION_STR) {
+                       strncpy(mms_data->smil.szContentLocation, value, sizeof(mms_data->smil.szContentLocation) - 1 );
+               }
+               else
+                       err = MSG_ERR_INVALID_PARAMETER;
+       }
+       break;
+       case MSG_STRUCT_MULTIPART_INFO:
+               err = msg_multipart_set_str_value(msg_struct->data, field, value, size);
+       break;
+
        default :
                        err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_set_bool_value(msg_struct_s *msg_struct, int field, bool value)
@@ -1024,7 +1239,7 @@ int msg_mms_set_bool_value(msg_struct_s *msg_struct, int field, bool value)
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value)
@@ -1048,7 +1263,7 @@ int msg_mms_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
 int msg_mms_set_list_handle(msg_struct_s *msg_struct, int field, msg_list_handle_t value)
@@ -1086,10 +1301,10 @@ int msg_mms_set_list_handle(msg_struct_s *msg_struct, int field, msg_list_handle
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
-       return MSG_SUCCESS;
+       return err;
 }
 
-EXPORT_API int msg_mms_add_item(msg_struct_t msg_struct_handle, int field, msg_struct_t *item)
+int msg_mms_list_append(msg_struct_t msg_struct_handle, int field, msg_struct_t *item)
 {
        msg_error_t err = MSG_SUCCESS;
        msg_struct_s *msg_struct = (msg_struct_s *)msg_struct_handle;
@@ -1102,25 +1317,29 @@ EXPORT_API int msg_mms_add_item(msg_struct_t msg_struct_handle, int field, msg_s
                MMS_DATA_HIDDEN_S *mms_data = (MMS_DATA_HIDDEN_S *)msg_struct->data;
 
                if (field == MSG_STRUCT_MMS_PAGE) {
-                       msg_struct_item = msg_mms_create_struct(field);
+                       msg_struct_item = msg_mms_create_struct(MSG_STRUCT_MMS_PAGE);
                        mms_data->pagelist = g_list_append(mms_data->pagelist, msg_struct_item);
                        *item = (msg_struct_t)msg_struct_item;
                } else if (field == MSG_STRUCT_MMS_REGION) {
-                       msg_struct_item = msg_mms_create_struct(field);
+                       msg_struct_item = msg_mms_create_struct(MSG_STRUCT_MMS_REGION);
                        mms_data->regionlist = g_list_append(mms_data->regionlist, msg_struct_item);
                        *item = (msg_struct_t)msg_struct_item;
                } else if (field == MSG_STRUCT_MMS_ATTACH) {
-                       msg_struct_item = msg_mms_create_struct(field);
+                       msg_struct_item = msg_mms_create_struct(MSG_STRUCT_MMS_ATTACH);
                        mms_data->attachlist = g_list_append(mms_data->attachlist, msg_struct_item);
                        *item = (msg_struct_t)msg_struct_item;
                } else if (field == MSG_STRUCT_MMS_TRANSITION) {
-                       msg_struct_item = msg_mms_create_struct(field);
+                       msg_struct_item = msg_mms_create_struct(MSG_STRUCT_MMS_TRANSITION);
                        mms_data->transitionlist = g_list_append(mms_data->transitionlist, msg_struct_item);
                        *item = (msg_struct_t)msg_struct_item;
                } else if (field == MSG_STRUCT_MMS_META) {
-                       msg_struct_item = msg_mms_create_struct(field);
+                       msg_struct_item = msg_mms_create_struct(MSG_STRUCT_MMS_META);
                        mms_data->metalist = g_list_append(mms_data->metalist, msg_struct_item);
                        *item = (msg_struct_t)msg_struct_item;
+               } else if (field == MSG_MMS_MULTIPART_LIST_HND) {
+                       msg_struct_item = (msg_struct_s *)msg_create_struct(MSG_STRUCT_MULTIPART_INFO);
+                       mms_data->multipartlist = g_list_append(mms_data->multipartlist, msg_struct_item);
+                       *item = (msg_struct_t)msg_struct_item;
                } else {
                        err = MSG_ERR_INVALID_PARAMETER;
                }
@@ -1160,8 +1379,9 @@ void convert_to_media_data(const msg_struct_s *pSrc, MMS_MEDIA_S *pDest)
        memcpy(dst_media->szContentID, src_media->szContentID, MSG_MSG_ID_LEN);
        memcpy(dst_media->regionId, src_media->regionId, MAX_SMIL_REGION_ID);
        memcpy(dst_media->szAlt, src_media->szAlt, MAX_SMIL_ALT_LEN);
-
        memcpy(dst_media->szDrm2FullPath, src_media->szDrm2FullPath, MSG_FILEPATH_LEN_MAX);
+       memcpy(dst_media->szContentType, src_media->szContentType, MSG_MSG_ID_LEN);
+       memcpy(dst_media->szContentLocation, src_media->szContentLocation, MSG_MSG_ID_LEN);
        dst_media->drmType = src_media->drmType;
 
        if (src_media->mediatype == MMS_SMIL_MEDIA_TEXT) {
@@ -1187,8 +1407,9 @@ void convert_from_media_data(const MMS_MEDIA_S *pSrc, msg_struct_s *pDest)
        memcpy(dst_media->szContentID, src_media->szContentID, MSG_MSG_ID_LEN);
        memcpy(dst_media->regionId, src_media->regionId, MAX_SMIL_REGION_ID);
        memcpy(dst_media->szAlt, src_media->szAlt, MAX_SMIL_ALT_LEN);
-
        memcpy(dst_media->szDrm2FullPath, src_media->szDrm2FullPath, MSG_FILEPATH_LEN_MAX);
+       memcpy(dst_media->szContentType, src_media->szContentType, MSG_MSG_ID_LEN);
+       memcpy(dst_media->szContentLocation, src_media->szContentLocation, MSG_MSG_ID_LEN);
        dst_media->drmType = src_media->drmType;
 
        if (src_media->mediatype == MMS_SMIL_MEDIA_TEXT) {
@@ -1273,6 +1494,8 @@ void convert_to_mmsdata(const msg_struct_s *pSrc, MMS_MESSAGE_DATA_S *pDest)
        memcpy(&pDest->rootlayout, &pSrcMms->rootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
 
        memcpy(&pDest->msgAppId, &pSrcMms->msgAppId, sizeof(MMS_APPID_INFO_S));
+       memcpy(&pDest->header, &pSrcMms->header, sizeof(MMS_HEADER_DATA_S));
+       memcpy(&pDest->smil, &pSrcMms->smil, sizeof(MMS_MULTIPART_DATA_S));
 }
 
 void convert_from_mmsdata(const MMS_MESSAGE_DATA_S *pSrc, msg_struct_s *pDest)
@@ -1344,4 +1567,330 @@ void convert_from_mmsdata(const MMS_MESSAGE_DATA_S *pSrc, msg_struct_s *pDest)
        memcpy(&pDestMms->rootlayout, &pSrc->rootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
 
        memcpy(&pDestMms->msgAppId, &pSrc->msgAppId, sizeof(MMS_APPID_INFO_S));
+
+       memcpy(&pDestMms->header, &pSrc->header, sizeof(MMS_HEADER_DATA_S));
+       memcpy(&pDestMms->smil, &pSrc->smil, sizeof(MMS_MULTIPART_DATA_S));
+
+}
+
+void convert_to_mmsdata2(MMS_DATA_HIDDEN_S *pSrcMms, MMS_MESSAGE_DATA_S *pDest)
+{
+       int i, j;
+       //MMS_DATA_HIDDEN_S *pSrcMms = (MMS_DATA_HIDDEN_S *)pSrc->data;
+
+       pDest->pageCnt = g_list_length(pSrcMms->pagelist);
+
+       for (i = 0; i < pDest->pageCnt; i++) {
+               MMS_PAGE_S *page = (MMS_PAGE_S *)calloc(1, sizeof(MMS_PAGE_S));
+               MMS_PAGE_S *src_page = (MMS_PAGE_S *)get_msg_struct_data((msg_struct_s *)g_list_nth_data(pSrcMms->pagelist, i));
+               page->mediaCnt = g_list_length(src_page->medialist);
+
+               for (j = 0; j < page->mediaCnt; j++)
+               {
+                       MMS_MEDIA_S *dst_media = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                       msg_struct_s *src_media_s = (msg_struct_s *)g_list_nth_data(src_page->medialist, j);
+
+                       convert_to_media_data(src_media_s, dst_media);
+
+                       page->medialist = g_list_append(page->medialist, dst_media);
+               }
+
+               page->nDur = src_page->nDur;
+               page->nBegin = src_page->nBegin;
+               page->nEnd = src_page->nEnd;
+               page->nMin = src_page->nMin;
+               page->nMax = src_page->nMax;
+               page->nRepeat = src_page->nRepeat;
+
+               pDest->pagelist = g_list_append(pDest->pagelist, page);
+       }
+
+       pDest->regionCnt = g_list_length(pSrcMms->regionlist);
+
+       for (i = 0; i < pDest->regionCnt; i++) {
+               MMS_SMIL_REGION *region = (MMS_SMIL_REGION *)calloc(1, sizeof(MMS_SMIL_REGION));
+               MMS_SMIL_REGION *src_region = (MMS_SMIL_REGION *)get_msg_struct_data((msg_struct_s *)g_list_nth_data(pSrcMms->regionlist, i));
+               memcpy(region, src_region, sizeof(MMS_SMIL_REGION));
+               pDest->regionlist = g_list_append(pDest->regionlist, region);
+       }
+
+       pDest->attachCnt = g_list_length(pSrcMms->attachlist);
+
+       for (i = 0; i < pDest->attachCnt; i++) {
+               MMS_ATTACH_S *attach = (MMS_ATTACH_S *)calloc(1, sizeof(MMS_ATTACH_S));
+               MMS_ATTACH_S *src_attach = (MMS_ATTACH_S *)get_msg_struct_data((msg_struct_s *)g_list_nth_data(pSrcMms->attachlist, i));
+               memcpy(attach, src_attach, sizeof(MMS_ATTACH_S));
+               pDest->attachlist = g_list_append(pDest->attachlist, attach);
+       }
+
+       pDest->transitionCnt = g_list_length(pSrcMms->transitionlist);
+
+       for (i = 0; i < pDest->transitionCnt; i++) {
+               MMS_SMIL_TRANSITION *transition = (MMS_SMIL_TRANSITION *)calloc(1, sizeof(MMS_SMIL_TRANSITION));
+               MMS_SMIL_TRANSITION *src_transition = (MMS_SMIL_TRANSITION *)get_msg_struct_data((msg_struct_s *)g_list_nth_data(pSrcMms->transitionlist, i));
+               memcpy(transition, src_transition, sizeof(MMS_SMIL_TRANSITION));
+               pDest->transitionlist = g_list_append(pDest->transitionlist, transition);
+       }
+
+       pDest->metaCnt = g_list_length(pSrcMms->metalist);
+
+       for (i = 0; i < pDest->metaCnt; i++) {
+               MMS_SMIL_META *meta = (MMS_SMIL_META *)calloc(1, sizeof(MMS_SMIL_META));
+               MMS_SMIL_META *src_meta = (MMS_SMIL_META *)get_msg_struct_data((msg_struct_s *)g_list_nth_data(pSrcMms->metalist, i));
+               memcpy(meta, src_meta, sizeof(MMS_SMIL_META));
+               pDest->metalist = g_list_append(pDest->metalist, meta);
+       }
+
+       memcpy(&pDest->rootlayout, &pSrcMms->rootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
+
+       memcpy(&pDest->msgAppId, &pSrcMms->msgAppId, sizeof(MMS_APPID_INFO_S));
+       memcpy(&pDest->header, &pSrcMms->header, sizeof(MMS_HEADER_DATA_S));
+       memcpy(&pDest->smil, &pSrcMms->smil, sizeof(MMS_MULTIPART_DATA_S));
+}
+
+void convert_from_mmsdata2(const MMS_MESSAGE_DATA_S *pSrc, MMS_DATA_HIDDEN_S *pDestMms)
+{
+       int i, j;
+       //MMS_DATA_HIDDEN_S *pDestMms = (MMS_DATA_HIDDEN_S *)pDest->data;
+
+       for (i = 0; i < pSrc->pageCnt; i++) {
+               msg_struct_s *page_struct = msg_mms_create_struct(MSG_STRUCT_MMS_PAGE);
+               MMS_PAGE_S *page = (MMS_PAGE_S *)page_struct->data;
+
+               MMS_PAGE_S *src_page = (MMS_PAGE_S *)g_list_nth_data(pSrc->pagelist, i);
+               page->mediaCnt = g_list_length(src_page->medialist);
+
+               for (j = 0; j < page->mediaCnt; j++)
+               {
+                       msg_struct_s *dst_media_s = msg_mms_create_struct(MSG_STRUCT_MMS_MEDIA);
+
+                       MMS_MEDIA_S *src_media = (MMS_MEDIA_S *)g_list_nth_data(src_page->medialist, j);
+
+                       convert_from_media_data(src_media, dst_media_s);
+
+                       page->medialist = g_list_append(page->medialist, dst_media_s);
+               }
+
+               page->nDur = src_page->nDur;
+               page->nBegin = src_page->nBegin;
+               page->nEnd = src_page->nEnd;
+               page->nMin = src_page->nMin;
+               page->nMax = src_page->nMax;
+               page->nRepeat = src_page->nRepeat;
+
+               pDestMms->pagelist = g_list_append(pDestMms->pagelist, page_struct);
+       }
+
+       for (i = 0; i < pSrc->regionCnt; i++) {
+               msg_struct_s *region_struct = msg_mms_create_struct(MSG_STRUCT_MMS_REGION);
+               MMS_SMIL_REGION *region = (MMS_SMIL_REGION *)region_struct->data;
+               MMS_SMIL_REGION *src_region = (MMS_SMIL_REGION *)g_list_nth_data(pSrc->regionlist, i);
+               memcpy(region, src_region, sizeof(MMS_SMIL_REGION));
+               pDestMms->regionlist = g_list_append(pDestMms->regionlist, region_struct);
+       }
+
+       for (i = 0; i < pSrc->attachCnt; i++) {
+               msg_struct_s *attach_struct = msg_mms_create_struct(MSG_STRUCT_MMS_ATTACH);
+               MMS_ATTACH_S *attach = (MMS_ATTACH_S *)attach_struct->data;
+               MMS_ATTACH_S *src_attach = (MMS_ATTACH_S *)g_list_nth_data(pSrc->attachlist, i);
+               memcpy(attach, src_attach, sizeof(MMS_ATTACH_S));
+               pDestMms->attachlist = g_list_append(pDestMms->attachlist, attach_struct);
+       }
+
+       for (i = 0; i < pSrc->transitionCnt; i++) {
+               msg_struct_s *transition_struct = msg_mms_create_struct(MSG_STRUCT_MMS_TRANSITION);
+               MMS_SMIL_TRANSITION *transition = (MMS_SMIL_TRANSITION *)transition_struct->data;
+               MMS_SMIL_TRANSITION *src_transition = (MMS_SMIL_TRANSITION *)g_list_nth_data(pSrc->transitionlist, i);
+               memcpy(transition, src_transition, sizeof(MMS_SMIL_TRANSITION));
+               pDestMms->transitionlist = g_list_append(pDestMms->transitionlist, transition_struct);
+       }
+
+       for (i = 0; i < pSrc->metaCnt; i++) {
+               msg_struct_s *meta_struct = msg_mms_create_struct(MSG_STRUCT_MMS_META);
+               MMS_SMIL_META *meta = (MMS_SMIL_META *)meta_struct->data;
+               MMS_SMIL_META *src_meta = (MMS_SMIL_META *)g_list_nth_data(pSrc->metalist, i);
+
+               memcpy(meta, src_meta, sizeof(MMS_SMIL_META));
+               pDestMms->metalist = g_list_append(pDestMms->metalist, meta_struct);
+       }
+
+       memcpy(&pDestMms->rootlayout, &pSrc->rootlayout, sizeof(MMS_SMIL_ROOTLAYOUT));
+
+       memcpy(&pDestMms->msgAppId, &pSrc->msgAppId, sizeof(MMS_APPID_INFO_S));
+
+       memcpy(&pDestMms->header, &pSrc->header, sizeof(MMS_HEADER_DATA_S));
+       memcpy(&pDestMms->smil, &pSrc->smil, sizeof(MMS_MULTIPART_DATA_S));
+
+}
+
+
+int msg_multipart_get_str_value(void *data, int field, char *value, int size)
+{
+       if (!data || !value)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_SUCCESS;
+
+       MMS_MULTIPART_DATA_S *msg_data = (MMS_MULTIPART_DATA_S *)data;
+
+       switch (field) {
+       case MSG_MMS_MULTIPART_CONTENT_TYPE_STR:
+               strncpy(value, msg_data->szContentType, size);
+               break;
+       case MSG_MMS_MULTIPART_NAME_STR:
+               strncpy(value, msg_data->szFileName, size);
+               break;
+       case MSG_MMS_MULTIPART_FILEPATH_STR:
+               strncpy(value, msg_data->szFilePath, size);
+               break;
+       case MSG_MMS_MULTIPART_THUMBNAIL_FILEPATH_STR:
+               strncpy(value, msg_data->szThumbFilePath, size);
+               break;
+       case MSG_MMS_MULTIPART_CONTENT_ID_STR:
+               strncpy(value, msg_data->szContentID, size);
+               break;
+       case MSG_MMS_MULTIPART_CONTENT_LOCATION_STR:
+               strncpy(value, msg_data->szContentLocation, size);
+               break;
+
+       default :
+               ret = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return ret;
+}
+
+int msg_multipart_get_int_value(void *data, int field, int *value)
+{
+       if (!data || !value)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_SUCCESS;
+
+       MMS_MULTIPART_DATA_S *msg_data = (MMS_MULTIPART_DATA_S *)data;
+
+       switch (field) {
+               case MSG_MMS_MULTIPART_TCS_LEVEL_INT:
+                       *value = msg_data->tcs_bc_level;
+                       break;
+               case MSG_MMS_MULTIPART_MALWARE_ALLOW_INT:
+                       *value = msg_data->malware_allow;
+                       break;
+               default :
+                       ret = MSG_ERR_INVALID_PARAMETER;
+                       break;
+       }
+
+       return ret;
+}
+
+int msg_multipart_set_str_value(void *data, int field, char *value, int size)
+{
+       if (!data || !value)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_SUCCESS;
+
+       MMS_MULTIPART_DATA_S *msg_data = (MMS_MULTIPART_DATA_S *)data;
+
+       //CID 41980: Reducing the size argument to strncpy calls to accomodate string termination '\0' in case source string is larger than size
+       switch (field) {
+       case MSG_MMS_MULTIPART_CONTENT_TYPE_STR:
+               strncpy(msg_data->szContentType, value, MSG_MSG_ID_LEN);
+               break;
+       case MSG_MMS_MULTIPART_NAME_STR:
+               strncpy(msg_data->szFileName, value, MSG_FILENAME_LEN_MAX);
+               break;
+       case MSG_MMS_MULTIPART_FILEPATH_STR:
+               strncpy(msg_data->szFilePath, value, MSG_FILEPATH_LEN_MAX);
+               break;
+       case MSG_MMS_MULTIPART_THUMBNAIL_FILEPATH_STR:
+               break;
+       case MSG_MMS_MULTIPART_CONTENT_ID_STR:
+               strncpy(msg_data->szContentID, value, MSG_MSG_ID_LEN);
+               break;
+       case MSG_MMS_MULTIPART_CONTENT_LOCATION_STR:
+               strncpy(msg_data->szContentLocation, value, MSG_MSG_ID_LEN);
+               break;
+       default :
+               ret = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return ret;
+}
+void convert_to_hidden_mmsdata(MMS_DATA_S *pSrc, msg_struct_s *pDest)
+{
+       MMS_DATA_HIDDEN_S *pDestMms = (MMS_DATA_HIDDEN_S *)pDest->data;
+
+       MMS_MESSAGE_DATA_S MmsMessageData = {0};
+
+       MsgMmsConvertMmsDataToMmsMessageData(pSrc, &MmsMessageData);
+
+       convert_from_mmsdata2(&MmsMessageData, pDestMms);
+
+       MsgMmsReleaseMmsLists(&MmsMessageData);
+
+       if (pSrc->header) {
+               memcpy(&pDestMms->header, pSrc->header, sizeof(MMS_HEADER_DATA_S));
+       }
+
+       if (pSrc->smil) {
+               memcpy(&pDestMms->smil, pSrc->smil, sizeof(MMS_MULTIPART_DATA_S));
+               pDestMms->smil.type = MIME_APPLICATION_SMIL;
+               pDestMms->smil.pMultipartData = (char *)calloc(1,  pDestMms->smil.nMultipartDataLen+1);
+               if (pDestMms->smil.pMultipartData)
+                       memcpy(pDestMms->smil.pMultipartData, pSrc->smil->pMultipartData,pDestMms->smil.nMultipartDataLen);
+       }
+
+       if (pSrc->multipartlist) {
+
+               int list_cnt = g_list_length(pSrc->multipartlist);
+
+               for (int i = 0; i < list_cnt; i++) {
+                       MMS_MULTIPART_DATA_S *src_multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pSrc->multipartlist, i);
+
+                       if (src_multipart) {
+                               msg_struct_s *multipart_struct = (msg_struct_s *)msg_create_struct(MSG_STRUCT_MULTIPART_INFO);
+
+                               MMS_MULTIPART_DATA_S *dst_multipart = (MMS_MULTIPART_DATA_S*)multipart_struct->data;
+
+                               memcpy(dst_multipart, src_multipart, sizeof(MMS_MULTIPART_DATA_S));
+
+                               pDestMms->multipartlist = g_list_append(pDestMms->multipartlist, multipart_struct);
+                       }
+               }
+       }
+
+}
+
+void convert_from_hidden_mmsdata(msg_struct_s *pSrc, MMS_DATA_S *pDest)
+{
+
+       MMS_DATA_HIDDEN_S *pSrcMms = (MMS_DATA_HIDDEN_S *)pSrc->data;
+
+       MMS_MESSAGE_DATA_S MmsMessageData = {0};
+
+       convert_to_mmsdata2(pSrcMms, &MmsMessageData);
+
+       MsgMmsConvertMmsMessageDataToMmsData(&MmsMessageData, pDest);
+
+       MsgMmsReleaseMmsLists(&MmsMessageData);
+}
+
+void __msg_mms_data_struct_init(MMS_DATA_HIDDEN_S *pMmsDataHidden)
+{
+       if (pMmsDataHidden) {
+               pMmsDataHidden->pagelist = NULL;
+               pMmsDataHidden->regionlist = NULL;
+               pMmsDataHidden->attachlist = NULL;
+               pMmsDataHidden->transitionlist = NULL;
+               pMmsDataHidden->metalist = NULL;
+
+               MsgMmsInitHeader(&pMmsDataHidden->header);
+               MsgMmsInitMultipart(&pMmsDataHidden->smil);
+               pMmsDataHidden->smil.type = MIME_APPLICATION_SMIL;
+               snprintf(pMmsDataHidden->smil.szContentType, sizeof(pMmsDataHidden->smil.szContentType), "%s", "application/smil");
+       }
 }
index 865590a..fe0123e 100755 (executable)
@@ -1,20 +1,21 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
+#include <privacy_checker_client.h>
 #include <MsgException.h>
 #include "MsgHandle.h"
 #include "MsgDebug.h"
@@ -61,6 +62,9 @@ int msg_setting_get_int_value(msg_struct_s *msg_struct, int field, int *value)
        case MSG_STRUCT_SETTING_MSGSIZE_OPT :
                *value = msg_get_msgsize_opt_int(msg_struct->data, field);
                break;
+       case MSG_STRUCT_SETTING_VOICE_MSG_OPT :
+               *value = msg_get_voice_msg_opt_int(msg_struct->data, field);
+               break;
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -192,6 +196,9 @@ int msg_setting_set_int_value(msg_struct_s *msg_struct, int field, int value)
        case MSG_STRUCT_SETTING_MSGSIZE_OPT :
                err = msg_set_msgsize_opt_int(msg_struct->data, field, value);
                break;
+       case MSG_STRUCT_SETTING_VOICE_MSG_OPT :
+               err = msg_set_voice_msg_opt_int(msg_struct->data, field, value);
+               break;
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -263,9 +270,17 @@ EXPORT_API int msg_get_smsc_opt(msg_handle_t handle, msg_struct_t msg_struct)
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -288,9 +303,17 @@ EXPORT_API int msg_set_smsc_opt(msg_handle_t handle, msg_struct_t msg_struct)
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -343,6 +366,9 @@ int msg_get_smsc_opt_int(void *smsc_opt, int field)
        case MSG_SMSC_SELECTED_ID_INT :
                ret = smsc_opt_data->selected;
                break;
+       case MSG_SMSC_LIST_SIM_INDEX_INT :
+               ret = smsc_opt_data->simIndex;
+               break;
        default :
                return MSG_ERR_INVALID_PARAMETER;
        }
@@ -364,6 +390,12 @@ int msg_set_smsc_opt_int(void *smsc_opt, int field, int value)
        case MSG_SMSC_SELECTED_ID_INT :
                smsc_opt_data->selected = value;
                break;
+       case MSG_SMSC_LIST_INDEX_INT :
+               smsc_opt_data->index = value;
+               break;
+       case MSG_SMSC_LIST_SIM_INDEX_INT :
+               smsc_opt_data->simIndex = value;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -489,9 +521,17 @@ EXPORT_API int msg_get_cb_opt(msg_handle_t handle, msg_struct_t msg_struct)
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -514,9 +554,17 @@ EXPORT_API int msg_set_cb_opt(msg_handle_t handle, msg_struct_t msg_struct)
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -548,6 +596,9 @@ int msg_get_cb_option_int(void *cb_opt, int field)
        case MSG_CB_MAX_SIM_COUNT_INT :
                ret = cb_opt_data->maxSimCnt;
                break;
+       case MSG_CB_SIM_INDEX_INT :
+               ret = cb_opt_data->simIndex;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -570,6 +621,9 @@ int msg_set_cb_option_int(void *cb_opt, int field, int value)
        case MSG_CB_MAX_SIM_COUNT_INT :
                cb_opt_data->maxSimCnt = value;
                break;
+       case MSG_CB_SIM_INDEX_INT :
+               cb_opt_data->simIndex = value;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -844,9 +898,17 @@ EXPORT_API int msg_get_sms_send_opt(msg_handle_t handle, msg_struct_t msg_struct
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -869,9 +931,17 @@ EXPORT_API int msg_set_sms_send_opt(msg_handle_t handle, msg_struct_t msg_struct
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -998,9 +1068,17 @@ EXPORT_API int msg_get_mms_send_opt(msg_handle_t handle, msg_struct_t msg_struct
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1023,9 +1101,17 @@ EXPORT_API int msg_set_mms_send_opt(msg_handle_t handle, msg_struct_t msg_struct
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1213,9 +1299,17 @@ EXPORT_API int msg_get_mms_recv_opt(msg_handle_t handle, msg_struct_t msg_struct
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1238,9 +1332,17 @@ EXPORT_API int msg_set_mms_recv_opt(msg_handle_t handle, msg_struct_t msg_struct
 
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1372,9 +1474,17 @@ EXPORT_API int msg_get_push_msg_opt(msg_handle_t handle, msg_struct_t msg_struct
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1396,9 +1506,17 @@ EXPORT_API int msg_set_push_msg_opt(msg_handle_t handle, msg_struct_t msg_struct
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1506,9 +1624,17 @@ EXPORT_API int msg_get_voice_msg_opt(msg_handle_t handle, msg_struct_t msg_struc
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1530,9 +1656,17 @@ EXPORT_API int msg_set_voice_msg_opt(msg_handle_t handle, msg_struct_t msg_struc
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1550,6 +1684,49 @@ EXPORT_API int msg_set_voice_msg_opt(msg_handle_t handle, msg_struct_t msg_struc
        return err;
 }
 
+int msg_get_voice_msg_opt_int(void *voice_msg_opt, int field)
+{
+       if (!voice_msg_opt)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_ERR_INVALID_PARAMETER;
+
+       MSG_VOICEMAIL_OPT_S *voice_opt = (MSG_VOICEMAIL_OPT_S *)voice_msg_opt;
+
+       switch (field)
+       {
+       case MSG_VOICEMSG_SIM_INDEX_INT :
+               ret = voice_opt->simIndex;
+               break;
+       default :
+               break;
+       }
+
+       return ret;
+}
+
+int msg_set_voice_msg_opt_int(void *voice_msg_opt, int field, int value)
+{
+       if (!voice_msg_opt)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_SUCCESS;
+
+       MSG_VOICEMAIL_OPT_S *voice_opt = (MSG_VOICEMAIL_OPT_S *)voice_msg_opt;
+
+       switch (field)
+       {
+       case MSG_VOICEMSG_SIM_INDEX_INT :
+               voice_opt->simIndex = value;
+               break;
+       default :
+               ret = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return ret;
+}
+
 char *msg_get_voice_msg_opt_str(void *voice_msg_opt, int field)
 {
        if (!voice_msg_opt)
@@ -1564,6 +1741,9 @@ char *msg_get_voice_msg_opt_str(void *voice_msg_opt, int field)
        case MSG_VOICEMSG_ADDRESS_STR :
                ret_str = voice_opt->mailNumber;
                break;
+       case MSG_VOICEMSG_ALPHA_ID_STR :
+               ret_str = voice_opt->alpahId;
+               break;
        default :
                break;
        }
@@ -1598,9 +1778,17 @@ EXPORT_API int msg_get_general_opt(msg_handle_t handle, msg_struct_t msg_struct)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1622,9 +1810,17 @@ EXPORT_API int msg_set_general_opt(msg_handle_t handle, msg_struct_t msg_struct)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1656,6 +1852,18 @@ int msg_get_general_opt_int(void *general_opt, int field)
        case MSG_GENERAL_ALERT_TONE_INT :
                ret = opt->alertTone;
                break;
+       case MSG_GENERAL_SMS_LIMIT_CNT_INT :
+               ret = opt->smsLimitCnt;
+               break;
+       case MSG_GENERAL_MMS_LIMIT_CNT_INT :
+               ret = opt->mmsLimitCnt;
+               break;
+       case MSG_GENERAL_RINGTONE_TYPE_INT :
+               ret = opt->ringtoneType;
+               break;
+       case MSG_GENERAL_MSG_SEARCH_TAGS_INT :
+               ret = opt->searchTags;
+               break;
        default :
                break;
        }
@@ -1677,6 +1885,18 @@ int msg_set_general_opt_int(void *general_opt, int field, int value)
        case MSG_GENERAL_ALERT_TONE_INT :
                opt->alertTone = value;
                break;
+       case MSG_GENERAL_SMS_LIMIT_CNT_INT :
+               opt->smsLimitCnt = value;
+               break;
+       case MSG_GENERAL_MMS_LIMIT_CNT_INT :
+               opt->mmsLimitCnt = value;
+               break;
+       case MSG_GENERAL_RINGTONE_TYPE_INT :
+               opt->ringtoneType = value;
+               break;
+       case MSG_GENERAL_MSG_SEARCH_TAGS_INT :
+               opt->searchTags = value;
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -1702,6 +1922,18 @@ bool msg_get_general_opt_bool(void *general_opt, int field)
        case MSG_GENERAL_AUTO_ERASE_BOOL :
                ret = opt->bAutoErase;
                break;
+       case MSG_GENERAL_BLOCK_UNKNOWN_NUMBER_BOOL :
+               ret = opt->bBlockUnknownMsg;
+               break;
+       case MSG_GENERAL_MSG_NOTIFICATION_BOOL :
+               ret = opt->bNotification;
+               break;
+       case MSG_GENERAL_MSG_VIBRATION_BOOL :
+               ret = opt->bVibration;
+               break;
+       case MSG_GENERAL_MSG_PREVIEW_BOOL :
+               ret = opt->bPreview;
+               break;
        default :
                break;
        }
@@ -1726,6 +1958,62 @@ int msg_set_general_opt_bool(void *general_opt, int field, bool value)
        case MSG_GENERAL_AUTO_ERASE_BOOL :
                opt->bAutoErase = value;
                break;
+       case MSG_GENERAL_BLOCK_UNKNOWN_NUMBER_BOOL :
+               opt->bBlockUnknownMsg = value;
+               break;
+       case MSG_GENERAL_MSG_NOTIFICATION_BOOL :
+               opt->bNotification = value;
+               break;
+       case MSG_GENERAL_MSG_VIBRATION_BOOL :
+               opt->bVibration = value;
+               break;
+       case MSG_GENERAL_MSG_PREVIEW_BOOL :
+               opt->bPreview = value;
+               break;
+       default :
+               ret = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return ret;
+}
+
+char *msg_get_general_opt_str(void *general_opt, int field)
+{
+       if (!general_opt)
+               return NULL;
+
+       char *ret_str = NULL;
+
+       MSG_GENERAL_OPT_S *opt = (MSG_GENERAL_OPT_S *)general_opt;
+
+       switch (field)
+       {
+       case MSG_GENERAL_RINGTONE_PATH_STR :
+               ret_str = opt->ringtonePath;
+               break;
+       default :
+               break;
+       }
+
+       return ret_str;
+}
+
+int msg_set_general_opt_str(void *general_opt, int field, char *val, int size)
+{
+       if (!general_opt)
+               return MSG_ERR_NULL_POINTER;
+
+       int ret = MSG_SUCCESS;
+
+       MSG_GENERAL_OPT_S *opt = (MSG_GENERAL_OPT_S *)general_opt;
+
+       switch (field)
+       {
+       case MSG_GENERAL_RINGTONE_PATH_STR :
+               bzero(opt->ringtonePath, sizeof(opt->ringtonePath));
+               snprintf(opt->ringtonePath, sizeof(opt->ringtonePath), "%s", val);
+               break;
        default :
                ret = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -1734,13 +2022,22 @@ int msg_set_general_opt_bool(void *general_opt, int field, bool value)
        return ret;
 }
 
+
 EXPORT_API int msg_get_msgsize_opt(msg_handle_t handle, msg_struct_t msg_struct)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1762,9 +2059,17 @@ EXPORT_API int msg_set_msgsize_opt(msg_handle_t handle, msg_struct_t msg_struct)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_struct == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
index 0816d0a..ae51bfc 100755 (executable)
@@ -1,20 +1,21 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
+#include <privacy_checker_client.h>
 
 #include "MsgHandle.h"
 #include "MsgDebug.h"
@@ -33,9 +34,17 @@ EXPORT_API int msg_add_message(msg_handle_t handle, msg_struct_t opq_msg, const
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || opq_msg == NULL || send_opt == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -61,9 +70,17 @@ EXPORT_API int msg_add_syncml_message(msg_handle_t handle, const msg_struct_t sy
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || syncml_msg == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -87,9 +104,17 @@ EXPORT_API int msg_update_message(msg_handle_t handle, const msg_struct_t opq_ms
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || opq_msg == NULL || send_opt == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -98,12 +123,6 @@ EXPORT_API int msg_update_message(msg_handle_t handle, const msg_struct_t opq_ms
 
        MSG_MESSAGE_HIDDEN_S *msg = (MSG_MESSAGE_HIDDEN_S *)pMsgStruct->data;
 
-       if (msg->addr_list->nCount > 1)
-       {
-               MSG_DEBUG("Multiple Address cannot be updated [%d]", msg->addr_list->nCount);
-               return -EINVAL;
-       }
-
        try
        {
                err = pHandle->updateMessage(msg, (MSG_SENDINGOPT_S *)pStruct->data);
@@ -122,9 +141,17 @@ EXPORT_API int msg_update_read_status(msg_handle_t handle, msg_message_id_t msg_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -143,13 +170,54 @@ EXPORT_API int msg_update_read_status(msg_handle_t handle, msg_message_id_t msg_
 }
 
 
+EXPORT_API int msg_set_conversation_to_read(msg_handle_t handle,  msg_thread_id_t thread_id)
+{
+       msg_error_t err =  MSG_SUCCESS;
+
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL)
+       {
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       MsgHandle* pHandle = (MsgHandle*)handle;
+
+       try
+       {
+               err = pHandle->setConversationToRead(thread_id);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_STORAGE_ERROR;
+       }
+
+       return err;
+}
+
+
 EXPORT_API int msg_update_protected_status(msg_handle_t handle, msg_message_id_t msg_id, bool is_protected)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -167,14 +235,21 @@ EXPORT_API int msg_update_protected_status(msg_handle_t handle, msg_message_id_t
        return err;
 }
 
-
 EXPORT_API int msg_delete_message(msg_handle_t handle, msg_message_id_t msg_id)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -197,9 +272,17 @@ EXPORT_API int msg_delete_all_msgs_in_folder(msg_handle_t handle, msg_folder_id_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -222,9 +305,17 @@ EXPORT_API int msg_delete_msgs_by_list(msg_handle_t handle, msg_id_list_s *msg_i
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -247,9 +338,17 @@ EXPORT_API int msg_move_msg_to_folder(msg_handle_t handle, msg_message_id_t msg_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -272,12 +371,20 @@ EXPORT_API int msg_move_msg_to_storage(msg_handle_t handle, msg_message_id_t msg
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
-       if (storage_id != MSG_STORAGE_PHONE && storage_id != MSG_STORAGE_SIM)
+       if (storage_id < MSG_STORAGE_PHONE || storage_id > MSG_STORAGE_SIM2)
        {
                MSG_FATAL("unsupported storage [%d]", storage_id);
                return MSG_ERR_INVALID_PARAMETER;
@@ -303,9 +410,17 @@ EXPORT_API int msg_count_message(msg_handle_t handle, msg_folder_id_t folder_id,
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -328,9 +443,17 @@ EXPORT_API int msg_count_msg_by_type(msg_handle_t handle, msg_message_type_t msg
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -371,9 +494,17 @@ EXPORT_API int msg_count_msg_by_contact(msg_handle_t handle, const msg_struct_t
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || addr_info == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -398,10 +529,18 @@ EXPORT_API int msg_get_message(msg_handle_t handle, msg_message_id_t msg_id, msg
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || !opq_msg)
        {
                MSG_FATAL("handle or opq_msg is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -426,10 +565,18 @@ EXPORT_API int msg_get_vobject_data(msg_handle_t handle, msg_message_id_t msg_id
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || result_data == NULL)
        {
                MSG_FATAL("handle or result_data is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -446,14 +593,23 @@ EXPORT_API int msg_get_vobject_data(msg_handle_t handle, msg_message_id_t msg_id
 
        return err;
 }
+
 EXPORT_API int msg_get_conversation(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_t conv)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || !conv)
        {
                MSG_FATAL("handle or opq_msg is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -472,51 +628,22 @@ EXPORT_API int msg_get_conversation(msg_handle_t handle, msg_message_id_t msg_id
        return err;
 }
 
-EXPORT_API int msg_get_folder_view_list(msg_handle_t handle, msg_folder_id_t folder_id, const msg_struct_t sort_rule, msg_struct_list_s *msg_folder_view_list)
+
+EXPORT_API int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t sort_rule, msg_struct_list_s *msg_thread_view_list)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
        {
-               return -EINVAL;
-       }
-
-       MsgHandle* pHandle = (MsgHandle*)handle;
-       msg_struct_s *pStruct = (msg_struct_s *)sort_rule;
-
-       try
-       {
-               if (sort_rule == NULL)
-               {
-                       MSG_SORT_RULE_S sortRule = {0};
-
-                       sortRule.sortType = MSG_SORT_BY_READ_STATUS;
-                       sortRule.bAscending = true;
-
-                       err = pHandle->getFolderViewList(folder_id, &sortRule, msg_folder_view_list);
-               }
-               else
-               {
-               err = pHandle->getFolderViewList(folder_id, (MSG_SORT_RULE_S *)pStruct->data, msg_folder_view_list);
-       }
-       }
-       catch (MsgException& e)
-       {
-               MSG_FATAL("%s", e.what());
-               return MSG_ERR_STORAGE_ERROR;
+               return MSG_ERR_PERMISSION_DENIED;
        }
 
-       return err;
-}
-
-
-EXPORT_API int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t sort_rule, msg_struct_list_s *msg_thread_view_list)
-{
-       msg_error_t err =  MSG_SUCCESS;
-
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -552,9 +679,17 @@ EXPORT_API int msg_get_conversation_view_list(msg_handle_t handle, msg_thread_id
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -577,9 +712,17 @@ EXPORT_API int msg_delete_thread_message_list(msg_handle_t handle, msg_thread_id
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -602,9 +745,17 @@ EXPORT_API int msg_add_folder(msg_handle_t handle, const msg_struct_t folder_inf
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || folder_info == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -628,9 +779,17 @@ EXPORT_API int msg_update_folder(msg_handle_t handle, const msg_struct_t folder_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || folder_info == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -654,9 +813,17 @@ EXPORT_API int msg_delete_folder(msg_handle_t handle, msg_folder_id_t folder_id)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -679,9 +846,17 @@ EXPORT_API int msg_get_folder_list(msg_handle_t handle, msg_struct_list_s *folde
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -702,16 +877,24 @@ EXPORT_API int msg_get_folder_list(msg_handle_t handle, msg_struct_list_s *folde
 
 EXPORT_API int msg_generate_message(msg_handle_t handle, msg_message_type_t msg_type, msg_folder_id_t folder_id, unsigned int num_msg)
 {
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
                MSG_DEBUG("Handle is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        if (folder_id >= MSG_MAX_FOLDER_ID)
        {
                MSG_DEBUG("folderId is invalid [%d]", folder_id);
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MSG_DEBUG("type : %d, folder : %d, num_msg : %d", msg_type, folder_id, num_msg);
@@ -852,108 +1035,22 @@ EXPORT_API int msg_generate_message(msg_handle_t handle, msg_message_type_t msg_
 }
 
 
-EXPORT_API int msg_generate_sms(msg_handle_t handle, msg_folder_id_t folder_id, unsigned int num_msg)
+EXPORT_API int msg_get_quick_panel_data(msg_handle_t handle, msg_quickpanel_type_t type, msg_struct_t opq_msg)
 {
-       MSG_DEBUG("folder %d, num_msg %d", folder_id, num_msg);
-
-       if (handle == NULL)
-       {
-               MSG_DEBUG("Handle is NULL");
-               return -EINVAL;
-       }
-
-       if (folder_id >= MSG_MAX_FOLDER_ID)
-       {
-               MSG_DEBUG("folderId is invalid");
-               return -EINVAL;
-       }
-
-       int err = 0;
-       char strMsg[20] = {0};
-       char prefix[10] ="0103001";
-       int postfix = 0;
-
-       MSG_SENDINGOPT_S sendingOpt = {0};
-       sendingOpt.bSetting = false;
-
-       srand(getpid());
-
-       msg_struct_s *msg_s = NULL;
-       msg_struct_s *addr_s = NULL;
-       MSG_MESSAGE_HIDDEN_S *msgInfo = NULL;
-       MSG_ADDRESS_INFO_S *addrInfo = NULL;
+       msg_error_t err =  MSG_SUCCESS;
 
-       for (unsigned int i = 0; i < num_msg; i++)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
        {
-               msg_s = (msg_struct_s *)msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
-               msgInfo = (MSG_MESSAGE_HIDDEN_S *)msg_s->data;
-
-               msgInfo->msgId  = 0; // It should be set 0
-               msgInfo->folderId = folder_id;
-
-               msgInfo->mainType = MSG_SMS_TYPE;
-               msgInfo->subType = 0;
-
-               msgInfo->storageId = MSG_STORAGE_PHONE;
-
-               snprintf(strMsg, sizeof(strMsg), "test %d", i);
-               msgInfo->dataSize = strlen(strMsg);
-               msgInfo->pData = strMsg;
-
-               msgInfo->addr_list->nCount = 1;
-
-               addr_s = (msg_struct_s *)msgInfo->addr_list->msg_struct_info[0];
-
-               addrInfo = (MSG_ADDRESS_INFO_S *)addr_s->data;
-
-               addrInfo->addressType = MSG_ADDRESS_TYPE_PLMN;
-               postfix = rand()%10000;
-               snprintf(addrInfo->addressVal, MAX_ADDRESS_VAL_LEN+1, "%s%04d", prefix, postfix);
-
-               addrInfo->recipientType = MSG_RECIPIENTS_TYPE_TO;
-
-               time(&(msgInfo->displayTime));
-
-               msgInfo->networkStatus = MSG_NETWORK_NOT_SEND;
-               msgInfo->bRead = false;
-               msgInfo->bProtected = false;
-               msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
-               msgInfo->direction = MSG_DIRECTION_TYPE_MO;
-
-//             err = msg_add_message(handle, (msg_message_t) &msgInfo, &sendingOpt);
-               try
-               {
-                       MsgHandle* pHandle = (MsgHandle*)handle;
-                       err = pHandle->addMessage(msgInfo, &sendingOpt);
-               }
-               catch (MsgException& e)
-               {
-                       MSG_FATAL("%s", e.what());
-                       msg_release_struct((msg_struct_t *)&msg_s);
-                       return MSG_ERR_STORAGE_ERROR;
-               }
-
-               msg_release_struct((msg_struct_t *)&msg_s);
-
-               if (err < 0)
-               {
-                       MSG_DEBUG("err [%d]", err);
-                       return err;
-               }
+               return MSG_ERR_PERMISSION_DENIED;
        }
 
-       return MSG_SUCCESS;
-}
-
-
-EXPORT_API int msg_get_quick_panel_data(msg_handle_t handle, msg_quickpanel_type_t type, msg_struct_t opq_msg)
-{
-       msg_error_t err =  MSG_SUCCESS;
-
        if (handle == NULL || !opq_msg )
        {
                MSG_FATAL("handle or opq_msg is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -977,9 +1074,17 @@ EXPORT_API int msg_reset_database(msg_handle_t handle)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1002,9 +1107,17 @@ EXPORT_API int msg_get_mem_size(msg_handle_t handle, unsigned int* memsize)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1027,9 +1140,17 @@ EXPORT_API int msg_backup_message(msg_handle_t handle, msg_message_backup_type_t
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || backup_filepath == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1052,9 +1173,17 @@ EXPORT_API int msg_restore_message(msg_handle_t handle, const char *backup_filep
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || backup_filepath == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1077,14 +1206,22 @@ EXPORT_API int msg_search_message_for_thread_view(msg_handle_t handle, const cha
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || search_string == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        if (strlen(search_string) <= 0 || strlen(search_string) > MAX_MSG_TEXT_LEN)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1102,22 +1239,28 @@ EXPORT_API int msg_search_message_for_thread_view(msg_handle_t handle, const cha
        return err;
 }
 
-
-EXPORT_API int msg_search_message(msg_handle_t handle, const msg_struct_t msg_search_conditions, int offset, int limit, msg_struct_list_s *msg_list)
+EXPORT_API int msg_get_reject_msg_list(msg_handle_t handle, const char *phone_num, msg_struct_list_s *msg_reject_msg_list)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL || msg_search_conditions == NULL)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
        {
-               return -EINVAL;
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL)
+       {
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
-       msg_struct_s *pStruct = (msg_struct_s *)msg_search_conditions;
 
        try
        {
-               err = pHandle->searchMessage((MSG_SEARCH_CONDITION_S *)pStruct->data, offset, limit, msg_list);
+               err = pHandle->getRejectMsgList(phone_num, msg_reject_msg_list);
        }
        catch (MsgException& e)
        {
@@ -1128,69 +1271,96 @@ EXPORT_API int msg_search_message(msg_handle_t handle, const msg_struct_t msg_se
        return err;
 }
 
-EXPORT_API int msg_get_reject_msg_list(msg_handle_t handle, const char *phone_num, msg_struct_list_s *msg_reject_msg_list)
+
+EXPORT_API int msg_reg_storage_change_callback(msg_handle_t handle, msg_storage_change_cb cb, void *user_param)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
 
        try
        {
-               err = pHandle->getRejectMsgList(phone_num, msg_reject_msg_list);
+               err = pHandle->regStorageChangeCallback(cb, user_param);
        }
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_STORAGE_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
 }
 
-
-EXPORT_API int msg_reg_storage_change_callback(msg_handle_t handle, msg_storage_change_cb cb, void *user_param)
+EXPORT_API int msg_get_report_status(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_list_s *report_list)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL || cb == NULL)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL || msg_id < 1 || report_list == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
 
        try
        {
-               err = pHandle->regStorageChangeCallback(cb, user_param);
+               err = pHandle->getReportStatus(msg_id, report_list);
        }
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               return MSG_ERR_STORAGE_ERROR;
        }
 
        return err;
 }
 
-EXPORT_API int msg_get_report_status(msg_handle_t handle, msg_message_id_t msg_id, msg_struct_list_s *report_list)
+EXPORT_API int msg_get_address_list(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_list_s *msg_address_list)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL || msg_id < 1 || report_list == NULL)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
 
        try
        {
-               err = pHandle->getReportStatus(msg_id, report_list);
+               err = pHandle->getAddressList(thread_id, msg_address_list);
        }
        catch (MsgException& e)
        {
@@ -1201,20 +1371,32 @@ EXPORT_API int msg_get_report_status(msg_handle_t handle, msg_message_id_t msg_i
        return err;
 }
 
-EXPORT_API int msg_get_address_list(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_list_s *msg_address_list)
+
+EXPORT_API int msg_get_thread_id_by_address(msg_handle_t handle, msg_struct_list_s *msg_address_list, msg_thread_id_t *thread_id)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
        {
-               return -EINVAL;
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL || msg_address_list == NULL || thread_id == NULL) {
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       if (msg_address_list->nCount < 1 ) {
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
 
        try
        {
-               err = pHandle->getAddressList(thread_id, msg_address_list);
+               err = pHandle->getThreadIdByAddress(msg_address_list, thread_id);
        }
        catch (MsgException& e)
        {
@@ -1226,13 +1408,21 @@ EXPORT_API int msg_get_address_list(msg_handle_t handle, msg_thread_id_t thread_
 }
 
 
-EXPORT_API int msg_get_thread_id_by_address(msg_handle_t handle, msg_struct_list_s *msg_address_list, msg_thread_id_t *thread_id)
+EXPORT_API int msg_get_thread_id_by_address2(msg_handle_t handle, msg_list_handle_t msg_address_list, msg_thread_id_t *thread_id)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       if (handle == NULL || msg_address_list->nCount < 1)
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL || msg_address_list == NULL || thread_id == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1255,9 +1445,17 @@ EXPORT_API int msg_get_thread(msg_handle_t handle, msg_thread_id_t thread_id, ms
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msg_thread == NULL ) {
                MSG_FATAL("handle or msg_thread is NULL");
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -1282,20 +1480,28 @@ EXPORT_API int msg_get_thread(msg_handle_t handle, msg_thread_id_t thread_id, ms
        return err;
 }
 
-
-EXPORT_API int msg_get_message_list(msg_handle_t handle, msg_folder_id_t folder_id, msg_thread_id_t thread_id, msg_message_type_t msg_type, msg_storage_id_t storage_id, msg_struct_list_s *msg_list)
+EXPORT_API int msg_get_message_list2(msg_handle_t handle, const msg_struct_t msg_list_conditions, msg_struct_list_s *msg_list)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL) {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
+       msg_struct_s *pStruct = (msg_struct_s *)msg_list_conditions;
 
        try
        {
-               err = pHandle->getMessageList(folder_id, thread_id, msg_type, storage_id, msg_list);
+               err = pHandle->getMessageList((MSG_LIST_CONDITION_S *)pStruct->data, msg_list);
        }
        catch (MsgException& e)
        {
@@ -1310,21 +1516,40 @@ static int msg_get_msg_type(int mainType, int subType)
 {
        if (mainType == MSG_SMS_TYPE)
        {
-               if (subType == MSG_CB_SMS)
-                       return MSG_TYPE_SMS_CB;
-               else if (subType == MSG_JAVACB_SMS)
-                       return MSG_TYPE_SMS_JAVACB;
-               else if (subType == MSG_WAP_SI_SMS || subType == MSG_WAP_SL_SMS)
-                       return MSG_TYPE_SMS_WAPPUSH;
-               else if (subType == MSG_MWI_VOICE_SMS || subType == MSG_MWI_FAX_SMS
-                               || subType == MSG_MWI_EMAIL_SMS || subType == MSG_MWI_OTHER_SMS)
-                       return MSG_TYPE_SMS_MWI;
-               else    if (subType == MSG_SYNCML_CP)
-                       return MSG_TYPE_SMS_SYNCML;
-               else    if (subType == MSG_REJECT_SMS)
-                       return MSG_TYPE_SMS_REJECT;
-               else
-                       return MSG_TYPE_SMS;
+       switch (subType) {
+                       case MSG_CB_SMS :
+                               return MSG_TYPE_SMS_CB;
+                       case MSG_JAVACB_SMS :
+                               return MSG_TYPE_SMS_JAVACB;
+                       case MSG_WAP_SI_SMS :
+                       case MSG_WAP_SL_SMS :
+                               return MSG_TYPE_SMS_WAPPUSH;
+                       case MSG_MWI_VOICE_SMS :
+                       case MSG_MWI_FAX_SMS :
+                       case MSG_MWI_EMAIL_SMS :
+                       case MSG_MWI_OTHER_SMS :
+                               return MSG_TYPE_SMS_MWI;
+                       case MSG_SYNCML_CP :
+                               return MSG_TYPE_SMS_SYNCML;
+                       case MSG_REJECT_SMS :
+                               return MSG_TYPE_SMS_REJECT;
+                       case MSG_ETWS_SMS :
+                               return MSG_TYPE_SMS_ETWS_PRIMARY;
+                       case MSG_CMAS_PRESIDENTIAL :
+                               return MSG_TYPE_SMS_CMAS_PRESIDENTIAL;
+                       case MSG_CMAS_EXTREME :
+                               return MSG_TYPE_SMS_CMAS_EXTREME;
+                       case MSG_CMAS_SEVERE :
+                               return MSG_TYPE_SMS_CMAS_SEVERE;
+                       case MSG_CMAS_AMBER :
+                               return MSG_TYPE_SMS_CMAS_AMBER;
+                       case MSG_CMAS_TEST :
+                               return MSG_TYPE_SMS_CMAS_TEST;
+                       case MSG_CMAS_OPERATOR_DEFINED :
+                               return MSG_TYPE_SMS_CMAS_OPERATOR_DEFINED;
+                       default :
+                               return MSG_TYPE_SMS;
+       }
        }
        else if (mainType == MSG_MMS_TYPE)
        {
@@ -1488,6 +1713,18 @@ int msg_thread_info_get_int(void *data, int field)
        case MSG_THREAD_MMS_COUNT_INT :
                result = pThread->mmsCnt;
                break;
+       case MSG_THREAD_TRANSLATION_SENDER_LANG_INT :
+               result = pThread->msgTranslation.senderLang;
+               break;
+       case MSG_THREAD_TRANSLATION_RECEIVER_LANG_INT :
+               result = pThread->msgTranslation.receiverLang;
+               break;
+       case MSG_THREAD_LAST_MSG_ID_INT :
+               result = pThread->lastMsgId;
+               break;
+       case MSG_THREAD_MSG_TAG_TYPE_INT:
+               result = pThread->tagType;
+               break;
        default:
                result = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -1539,6 +1776,12 @@ int msg_conv_info_get_int(void *data, int field)
        case MSG_CONV_MSG_PAGE_COUNT_INT :
                result = pConv->pageCount;
                break;
+       case MSG_CONV_MSG_TCS_BC_LEVEL_INT :
+               result = pConv->tcs_bc_level;
+               break;
+       case MSG_CONV_MSG_SIM_INDEX_INT :
+               result = pConv->simIndex;
+               break;
        default:
                result = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -1569,6 +1812,48 @@ int msg_search_condition_get_int(void *condition_info, int field)
        return result;
 }
 
+
+int msg_list_condition_get_int(void *condition_info, int field)
+{
+       int result = MSG_ERR_INVALID_PARAMETER;
+       MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S *)condition_info;
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_FOLDER_ID_INT:
+               result = pCond->folderId;
+               break;
+       case MSG_LIST_CONDITION_THREAD_ID_INT:
+                       result = pCond->threadId;
+                       break;
+       case MSG_LIST_CONDITION_STORAGE_ID_INT:
+                       result = pCond->storageId;
+                       break;
+       case MSG_LIST_CONDITION_MSGTYPE_INT:
+               result = pCond->msgType;
+               break;
+       case MSG_LIST_CONDITION_FROM_TIME_INT:
+               result = pCond->fromTime;
+               break;
+       case MSG_LIST_CONDITION_TO_TIME_INT:
+               result = pCond->toTime;
+               break;
+       case MSG_LIST_CONDITION_OFFSET_INT:
+               result = pCond->offset;
+               break;
+       case MSG_LIST_CONDITION_LIMIT_INT:
+               result = pCond->limit;
+               break;
+       case MSG_LIST_CONDITION_SIM_INDEX_INT:
+               result = pCond->simIndex;
+               break;
+       default:
+               result = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+       return result;
+}
+
+
 int msg_report_status_get_int(void *report_info, int field)
 {
        int result = MSG_ERR_INVALID_PARAMETER;
@@ -1671,6 +1956,9 @@ char *msg_conv_info_get_str(void *data, int field)
        case MSG_CONV_MSG_TEXT_STR :
                ret_str = pConv->pText;
                break;
+       case MSG_CONV_MSG_1ST_MEDIA_PATH_STR :
+               ret_str = pConv->firstMediaPath;
+               break;
        default:
                break;
        }
@@ -1691,7 +1979,26 @@ char* msg_search_condition_get_str(void *condition_info, int field, int size)
        case MSG_SEARCH_CONDITION_SEARCH_VALUE_STR:
                result = search_cond->pSearchVal;
                break;
+       default:
+               result = NULL;
+               break;
+       }
+       return result;
+}
 
+
+char* msg_list_condition_get_str(void *condition_info, int field, int size)
+{
+       char *result = NULL;
+       MSG_LIST_CONDITION_S *cond = (MSG_LIST_CONDITION_S *)condition_info;
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_ADDRESS_VALUE_STR:
+               result = cond->pAddressVal;
+               break;
+       case MSG_LIST_CONDITION_TEXT_VALUE_STR:
+               result = cond->pTextVal;
+               break;
        default:
                result = NULL;
                break;
@@ -1699,6 +2006,7 @@ char* msg_search_condition_get_str(void *condition_info, int field, int size)
        return result;
 }
 
+
 bool msg_sendopt_get_bool(void *send_opt, int field)
 {
        bool result = false;
@@ -1762,12 +2070,53 @@ bool msg_thread_info_get_bool(void *data, int field)
        case MSG_THREAD_PROTECTED_BOOL:
                result = pthreadInfo->bProtected;
                break;
+       case MSG_THREAD_DRAFT_BOOL :
+               result = pthreadInfo->bDraft;
+               break;
+       case MSG_THREAD_SEND_FAILED_BOOL :
+               result = pthreadInfo->bSendFailed;
+               break;
+       case MSG_THREAD_SENDING_BOOL :
+               result = pthreadInfo->bSending;
+               break;
+       case MSG_THREAD_TRANSLATION_BOOL :
+               result = pthreadInfo->msgTranslation.bTranslation;
+               break;
+       case MSG_THREAD_TRANSLATION_INCLUDE_ORGMSG_BOOL :
+               result = pthreadInfo->msgTranslation.bIncludeOrgMsg;
+               break;
+       case MSG_THREAD_TRANSLATION_RECEIVE_ONLY_BOOL :
+               result = pthreadInfo->msgTranslation.bOnlyReceive;
+               break;
+       default:
+               break;
+       }
+       return result;
+}
+
+
+bool msg_list_condition_get_bool(void *data, int field)
+{
+       bool result = false;
+       MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S *)data;
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_PROTECTED_BOOL:
+               result = pCond->bProtected;
+               break;
+       case MSG_LIST_CONDITION_SCHEDULED_BOOL :
+               result = pCond->bScheduled;
+               break;
+       case MSG_LIST_CONDITION_AND_OPERATER_BOOL :
+               result = pCond->bAnd;
+               break;
        default:
                break;
        }
        return result;
 }
 
+
 int msg_sendopt_get_struct_handle(msg_struct_s *msg_struct, int field, void **value)
 {
        msg_error_t err =  MSG_SUCCESS;
@@ -1822,7 +2171,7 @@ int msg_thread_index_get_struct_handle(msg_struct_s *msg_struct, int field, void
        MSG_THREAD_LIST_INDEX_INFO_S *pIndex = (MSG_THREAD_LIST_INDEX_INFO_S *)msg_struct->data;
        switch(field)
        {
-       case MSG_SYNCML_INFO_MESSAGE_HND:
+       case MSG_THREAD_LIST_INDEX_ADDR_INFO_HND:
                *value = (void *)pIndex->msgAddrInfo;
                break;
        default:
@@ -1833,6 +2182,29 @@ int msg_thread_index_get_struct_handle(msg_struct_s *msg_struct, int field, void
        return err;
 }
 
+
+int msg_list_condition_get_struct_handle(msg_struct_s *msg_struct, int field, void **value)
+{
+       msg_error_t err =  MSG_SUCCESS;
+
+       if(!msg_struct || !value)
+               return MSG_ERR_NULL_POINTER;
+
+       MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S *)msg_struct->data;
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_SORT_RULE_HND:
+               *value = (void *)pCond->sortRule;
+               break;
+       default:
+               err = MSG_ERR_UNKNOWN;
+               break;
+
+       }
+       return err;
+}
+
+
 int msg_address_info_get_int(void *addr_info, int field)
 {
        int result = MSG_ERR_INVALID_PARAMETER;
@@ -2105,32 +2477,124 @@ int msg_folder_info_set_int(void *folder_info, int field, int value)
        return err;
 }
 
-int msg_search_condition_set_int(void *condition_info, int field, int value)
+int msg_translation_set_bool(void *translation_info, int field, bool value)
 {
        msg_error_t err =  MSG_SUCCESS;
-       if(!condition_info)
+       if(!translation_info)
+               return MSG_ERR_NULL_POINTER;
+       MSG_TRANSLATION_INFO_S *pTrnaslation = (MSG_TRANSLATION_INFO_S *)translation_info;
+    switch(field)
+    {
+    case MSG_TRANSLATION_BOOL:
+       pTrnaslation->bTranslation = value;
+       break;
+    case MSG_TRANSLATION_RECEIVE_ONLY_BOOL:
+       pTrnaslation->bOnlyReceive = value;
+       break;
+    case MSG_TRANSLATION_INCLUDE_ORGMSG_BOOL:
+       pTrnaslation->bIncludeOrgMsg = value;
+       break;
+    default:
+               err = MSG_ERR_UNKNOWN;
+               break;
+    }
+       return err;
+}
+
+int msg_translation_set_int(void *translation_info, int field, int value)
+{
+       msg_error_t err =  MSG_SUCCESS;
+       if(!translation_info)
                return MSG_ERR_NULL_POINTER;
+       MSG_TRANSLATION_INFO_S *pTrnaslation = (MSG_TRANSLATION_INFO_S *)translation_info;
 
-    MSG_SEARCH_CONDITION_S *pCond = (MSG_SEARCH_CONDITION_S *)condition_info;
     switch(field)
     {
-    case MSG_SEARCH_CONDITION_FOLDERID_INT:
+    case MSG_TRANSLATION_SENDER_LANG_INT:
+       pTrnaslation->senderLang = value;
+       break;
+    case MSG_TRANSLATION_RECEIVER_LANG_INT:
+       pTrnaslation->receiverLang = value;
+       break;
+    default:
+       err = MSG_ERR_UNKNOWN;
+       break;
+    }
+       return err;
+}
+
+int msg_search_condition_set_int(void *condition_info, int field, int value)
+{
+       msg_error_t err =  MSG_SUCCESS;
+       if(!condition_info)
+               return MSG_ERR_NULL_POINTER;
+
+       MSG_SEARCH_CONDITION_S *pCond = (MSG_SEARCH_CONDITION_S *)condition_info;
+       switch(field)
+       {
+       case MSG_SEARCH_CONDITION_FOLDERID_INT:
                pCond->folderId = value;
                break;
-    case MSG_SEARCH_CONDITION_MSGTYPE_INT:
+       case MSG_SEARCH_CONDITION_MSGTYPE_INT:
                pCond->msgType = value;
                break;
-    case MSG_SEARCH_CONDITION_RESERVED_INT:
+       case MSG_SEARCH_CONDITION_RESERVED_INT:
                pCond->reserved = value;
                break;
-    default:
+       default:
                err = MSG_ERR_UNKNOWN;
                break;
-    }
+       }
+
+       return err;
+}
+
+
+int msg_list_condition_set_int(void *condition_info, int field, int value)
+{
+       msg_error_t err =  MSG_SUCCESS;
+       if(!condition_info)
+               return MSG_ERR_NULL_POINTER;
+
+       MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S *)condition_info;
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_FOLDER_ID_INT:
+               pCond->folderId = value;
+               break;
+       case MSG_LIST_CONDITION_THREAD_ID_INT:
+               pCond->threadId = value;
+               break;
+       case MSG_LIST_CONDITION_STORAGE_ID_INT:
+               pCond->storageId = value;
+               break;
+       case MSG_LIST_CONDITION_MSGTYPE_INT:
+               pCond->msgType = value;
+               break;
+       case MSG_LIST_CONDITION_FROM_TIME_INT:
+               pCond->fromTime = value;
+               break;
+       case MSG_LIST_CONDITION_TO_TIME_INT:
+               pCond->toTime = value;
+               break;
+       case MSG_LIST_CONDITION_OFFSET_INT:
+               pCond->offset = value;
+               break;
+       case MSG_LIST_CONDITION_LIMIT_INT:
+               pCond->limit = value;
+               break;
+       case MSG_LIST_CONDITION_SIM_INDEX_INT:
+               pCond->simIndex = value;
+               break;
+       default:
+               err = MSG_ERR_UNKNOWN;
+               break;
+       }
 
        return err;
 }
 
+
 int msg_report_status_set_int(void *report_info, int field, int value)
 {
        msg_error_t err =  MSG_SUCCESS;
@@ -2185,24 +2649,52 @@ int msg_search_condition_set_str(void *condition_info, int field, char *value, i
        if(!condition_info || !value)
                return MSG_ERR_NULL_POINTER;
 
-    MSG_SEARCH_CONDITION_S *search_cond = (MSG_SEARCH_CONDITION_S *)condition_info;
+       MSG_SEARCH_CONDITION_S *search_cond = (MSG_SEARCH_CONDITION_S *)condition_info;
 
-    switch(field)
-    {
-    case MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR:
-               search_cond->pAddressVal = value;
+       switch(field)
+       {
+       case MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR:
+               if(size)
+                       search_cond->pAddressVal = value;
                break;
-    case MSG_SEARCH_CONDITION_SEARCH_VALUE_STR:
-               search_cond->pSearchVal = value;
+       case MSG_SEARCH_CONDITION_SEARCH_VALUE_STR:
+               if(size)
+                       search_cond->pSearchVal = value;
+               break;
+       default:
+               err = MSG_ERR_UNKNOWN;
                break;
+       }
+       return err;
+}
 
-    default:
+
+int msg_list_condition_set_str(void *condition_info, int field, char *value, int size)
+{
+       msg_error_t err =  MSG_SUCCESS;
+       if(!condition_info || !value)
+               return MSG_ERR_NULL_POINTER;
+
+       MSG_LIST_CONDITION_S *cond = (MSG_LIST_CONDITION_S *)condition_info;
+
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_ADDRESS_VALUE_STR:
+               if(size)
+                       cond->pAddressVal = value;
+               break;
+       case MSG_LIST_CONDITION_TEXT_VALUE_STR:
+               if(size)
+                       cond->pTextVal = value;
+               break;
+       default:
                err = MSG_ERR_UNKNOWN;
                break;
-    }
+       }
        return err;
 }
 
+
 int msg_sendopt_set_bool(void *send_opt, int field, bool value)
 {
        msg_error_t err =  MSG_SUCCESS;
@@ -2234,19 +2726,46 @@ int msg_sortrule_set_bool(void *sort_rule, int field, bool value)
        if(!sort_rule)
                return MSG_ERR_NULL_POINTER;
 
-    MSG_SORT_RULE_S *pSort = (MSG_SORT_RULE_S *)sort_rule;
-    switch(field)
-    {
-    case MSG_SORT_RULE_ACSCEND_BOOL:
+       MSG_SORT_RULE_S *pSort = (MSG_SORT_RULE_S *)sort_rule;
+       switch(field)
+       {
+       case MSG_SORT_RULE_ACSCEND_BOOL:
                pSort->bAscending = value;
                break;
-    default:
+       default:
                err = MSG_ERR_UNKNOWN;
                break;
-    }
+       }
+       return err;
+}
+
+
+int msg_list_condition_set_bool(void *data, int field, bool value)
+{
+       msg_error_t err =  MSG_SUCCESS;
+       if(!data)
+               return MSG_ERR_NULL_POINTER;
+
+       MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S *)data;
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_PROTECTED_BOOL:
+               pCond->bProtected = value;
+               break;
+       case MSG_LIST_CONDITION_SCHEDULED_BOOL:
+               pCond->bScheduled = value;
+               break;
+       case MSG_LIST_CONDITION_AND_OPERATER_BOOL:
+               pCond->bAnd = value;
+               break;
+       default:
+               err = MSG_ERR_UNKNOWN;
+               break;
+       }
        return err;
 }
 
+
 int msg_sendopt_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value)
 {
        msg_error_t err =  MSG_SUCCESS;
@@ -2325,6 +2844,32 @@ int msg_thread_index_set_struct_handle(msg_struct_s *msg_struct, int field, msg_
        return err;
 }
 
+
+int msg_list_condition_set_struct_handle(msg_struct_s *msg_struct, int field, msg_struct_s *value)
+{
+       msg_error_t err =  MSG_SUCCESS;
+
+       if(!msg_struct || !value)
+               return MSG_ERR_NULL_POINTER;
+
+       MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S *)msg_struct->data;
+       msg_struct_s *pTmp = NULL;
+
+       switch(field)
+       {
+       case MSG_LIST_CONDITION_SORT_RULE_HND:
+               pTmp = (msg_struct_s *)pCond->sortRule;
+               memcpy(pTmp->data, value->data, sizeof(MSG_SORT_RULE_S));
+               break;
+       default:
+               err = MSG_ERR_UNKNOWN;
+               break;
+
+       }
+       return err;
+}
+
+
 int msg_address_info_set_int(void *addrinfo, int field, int value)
 {
        msg_error_t err =  MSG_SUCCESS;
@@ -2494,9 +3039,17 @@ EXPORT_API int msg_add_push_event(msg_handle_t handle, const msg_struct_t push_e
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || push_event == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -2520,9 +3073,17 @@ EXPORT_API int msg_delete_push_event(msg_handle_t handle, const msg_struct_t pus
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || push_event == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -2546,9 +3107,17 @@ EXPORT_API int msg_update_push_event(msg_handle_t handle, const msg_struct_t src
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || src_event == NULL || dst_event == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
index 9cfd830..81fa914 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <string.h>
@@ -21,6 +21,7 @@
 #include "MsgHandle.h"
 #include "MsgTextConvert.h"
 #include "MsgException.h"
+#include "MsgMemory.h"
 
 #include "msg_private.h"
 #include "msg.h"
                })\
 
 
+void __msg_release_list_item(gpointer data)
+{
+       if (data == NULL)
+               return;
+
+       msg_release_struct((msg_struct_t*)(&data));
+}
+
 
 EXPORT_API msg_struct_t msg_create_struct(int field)
 {
@@ -38,6 +47,7 @@ EXPORT_API msg_struct_t msg_create_struct(int field)
        memset(msg_struct, 0x00, sizeof(msg_struct_s));
 
        msg_struct->type = field;
+       msg_struct->data = NULL;
 
        switch(field)
        {
@@ -142,6 +152,20 @@ EXPORT_API msg_struct_t msg_create_struct(int field)
                memset(msg_struct->data, 0x00, sizeof(MSG_SEARCH_CONDITION_S));
                break;
        }
+       case MSG_STRUCT_MSG_LIST_CONDITION:
+       {
+               msg_struct->data = new MSG_LIST_CONDITION_S;
+               memset(msg_struct->data, 0x00, sizeof(MSG_LIST_CONDITION_S));
+
+               msg_struct_s *pStruct = new msg_struct_s;
+               ((MSG_LIST_CONDITION_S *)msg_struct->data)->sortRule = (msg_struct_t)pStruct;
+
+               pStruct->type = MSG_STRUCT_SORT_RULE;
+               pStruct->data = new MSG_SORT_RULE_S;
+               memset(pStruct->data, 0x00, sizeof(MSG_SORT_RULE_S));
+
+               break;
+       }
        case MSG_STRUCT_REPORT_STATUS_INFO:
        {
                msg_struct->data = new MSG_REPORT_STATUS_INFO_S;
@@ -154,6 +178,8 @@ EXPORT_API msg_struct_t msg_create_struct(int field)
         memset(msg_struct->data, 0x00, sizeof(MSG_SMSC_LIST_HIDDEN_S));
 
         MSG_SMSC_LIST_HIDDEN_S *pTmp = (MSG_SMSC_LIST_HIDDEN_S *)msg_struct->data;
+        memset(pTmp, 0x00, sizeof(MSG_SMSC_LIST_HIDDEN_S));
+        pTmp->simIndex = MSG_SIM_SLOT_ID_1; // default sim index
 
         msg_struct_list_s *smsc_list = (msg_struct_list_s *)new msg_struct_list_s;
         memset(smsc_list, 0x00, sizeof(msg_struct_list_s));
@@ -185,6 +211,7 @@ EXPORT_API msg_struct_t msg_create_struct(int field)
         memset(msg_struct->data, 0x00, sizeof(MSG_CBMSG_OPT_HIDDEN_S));
 
         MSG_CBMSG_OPT_HIDDEN_S *pTmp = (MSG_CBMSG_OPT_HIDDEN_S *)msg_struct->data;
+        pTmp->simIndex = MSG_SIM_SLOT_ID_1; // default sim index
 
         pTmp->channelData = (msg_struct_list_s *)new msg_struct_list_s;
         memset(pTmp->channelData, 0x00, sizeof(msg_struct_list_s));
@@ -238,6 +265,8 @@ EXPORT_API msg_struct_t msg_create_struct(int field)
        {
                msg_struct->data = new MSG_VOICEMAIL_OPT_S;
                memset(msg_struct->data, 0x00, sizeof(MSG_VOICEMAIL_OPT_S));
+               MSG_VOICEMAIL_OPT_S *pTmp = (MSG_VOICEMAIL_OPT_S *)msg_struct->data;
+               pTmp->simIndex = MSG_SIM_SLOT_ID_1; // default sim index
                break;
        }
        case MSG_STRUCT_SETTING_GENERAL_OPT :
@@ -308,19 +337,29 @@ EXPORT_API msg_struct_t msg_create_struct(int field)
        case MSG_STRUCT_MMS_META:
        case MSG_STRUCT_MMS_SMIL_TEXT:
        case MSG_STRUCT_MMS_SMIL_AVI:
+       case MSG_STRUCT_MULTIPART_INFO:
                msg_struct->data = msg_mms_create_struct_data(field);
                break;
        case MSG_STRUCT_PUSH_CONFIG_INFO:
                msg_struct->data = new MSG_PUSH_EVENT_INFO_S;
                memset(msg_struct->data, 0x00, sizeof(MSG_PUSH_EVENT_INFO_S));
                break;
+       case MSG_STRUCT_TRANSLATION_INFO:
+               msg_struct->data = new MSG_TRANSLATION_INFO_S;
+               memset(msg_struct->data, 0x00, sizeof(MSG_TRANSLATION_INFO_S));
+               break;
+
+       default :
+               delete msg_struct;
+               return NULL;
+               break;
        }
 
        return (msg_struct_t) msg_struct;
 }
 
 
-EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
+static int _release_msg_struct(msg_struct_t *msg_struct_handle)
 {
        msg_error_t err = MSG_SUCCESS;
 
@@ -351,6 +390,11 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
        {
                MSG_CONVERSATION_VIEW_S *pConv = (MSG_CONVERSATION_VIEW_S*)(msg_struct->data);
 
+               if (pConv->multipart_list) {
+                       g_list_free_full((GList *)pConv->multipart_list, __msg_release_list_item);
+                       pConv->multipart_list = NULL;
+               }
+
                if (pConv->pText) {
                        delete [] pConv->pText;
                        pConv->pText = NULL;
@@ -470,6 +514,24 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
 
                break;
        }
+       case MSG_STRUCT_MSG_LIST_CONDITION:
+       {
+               MSG_LIST_CONDITION_S *pCond = (MSG_LIST_CONDITION_S*)(msg_struct->data);
+               MSG_SORT_RULE_S *pSortRule = (MSG_SORT_RULE_S *)(((msg_struct_s *)pCond->sortRule)->data);
+
+               delete (MSG_SORT_RULE_S *)pSortRule;
+               ((msg_struct_s *)pCond->sortRule)->data = NULL;
+               delete (msg_struct_s *)pCond->sortRule;
+               pCond->sortRule = NULL;
+
+               delete (MSG_LIST_CONDITION_S*)(msg_struct->data);
+               msg_struct->data = NULL;
+
+               delete msg_struct;
+               *msg_struct_handle = NULL;
+
+               break;
+       }
        case MSG_STRUCT_REPORT_STATUS_INFO:
        {
                delete (MSG_REPORT_STATUS_INFO_S*)(msg_struct->data);
@@ -542,6 +604,7 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
        case MSG_STRUCT_MMS_META:
        case MSG_STRUCT_MMS_SMIL_TEXT:
        case MSG_STRUCT_MMS_SMIL_AVI:
+       case MSG_STRUCT_MULTIPART_INFO:
        {
                msg_mms_release_struct(&msg_struct);
                *msg_struct_handle = NULL;
@@ -558,13 +621,15 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
 
                for (int i = 0; i < SMSC_LIST_MAX; i++) {
                        smsc_info = (msg_struct_s *)smsc_list->msg_struct_info[i];
-                       delete [] (MSG_SMSC_DATA_S*)(smsc_info->data);
-                       delete [] smsc_info;
+                       delete (MSG_SMSC_DATA_S*)(smsc_info->data);
+                       delete smsc_info;
                }
 
                delete [] smsc_list->msg_struct_info;
 
-               delete [] (MSG_SMSC_LIST_HIDDEN_S*)pTmp;
+               delete smsc_list;
+
+               delete pTmp;
                msg_struct->data = NULL;
 
                delete msg_struct;
@@ -591,13 +656,15 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
 
                for (int i = 0; i < CB_CHANNEL_MAX; i++) {
                        cb_info = (msg_struct_s *)cb_list->msg_struct_info[i];
-                       delete [] (MSG_CB_CHANNEL_INFO_S*)(cb_info->data);
-                       delete [] cb_info;
+                       delete (MSG_CB_CHANNEL_INFO_S*)(cb_info->data);
+                       delete cb_info;
                }
 
                delete [] cb_list->msg_struct_info;
 
-               delete [] (MSG_CBMSG_OPT_HIDDEN_S*)pTmp;
+               delete cb_list;
+
+               delete pTmp;
                msg_struct->data = NULL;
 
                delete msg_struct;
@@ -685,6 +752,16 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
                *msg_struct_handle = NULL;
                break;
        }
+       case MSG_STRUCT_TRANSLATION_INFO:
+       {
+               delete (MSG_TRANSLATION_INFO_S*)(msg_struct->data);
+               msg_struct->data = NULL;
+
+               delete msg_struct;
+               *msg_struct_handle = NULL;
+               break;
+       }
+
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -693,7 +770,18 @@ EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
        return err;
 }
 
-int msg_release_list_struct(msg_struct_list_s *msg_struct_list)
+EXPORT_API int msg_release_struct(msg_struct_t *msg_struct_handle)
+{
+
+       int ret = _release_msg_struct(msg_struct_handle);
+
+       // Release Memory
+       MsgReleaseMemory();
+
+       return ret;
+}
+
+EXPORT_API int msg_release_list_struct(msg_struct_list_s *msg_struct_list)
 {
        msg_error_t err = MSG_SUCCESS;
 
@@ -712,17 +800,17 @@ int msg_release_list_struct(msg_struct_list_s *msg_struct_list)
 
                switch (structType)
                {
-               case MSG_STRUCT_ADDRESS_INFO :
-               {
-                       listCnt = MAX_TO_ADDRESS_CNT;
-                       break;
-               }
+//             case MSG_STRUCT_ADDRESS_INFO :
+//             {
+//                     listCnt = MAX_TO_ADDRESS_CNT;
+//                     break;
+//             }
                default :
                        break;
                }
 
                for(int i = 0; i < listCnt; i++) {
-                       msg_release_struct(&(msg_struct_list->msg_struct_info[i]));
+                       _release_msg_struct(&(msg_struct_list->msg_struct_info[i]));
                }
        }
 
@@ -730,6 +818,11 @@ int msg_release_list_struct(msg_struct_list_s *msg_struct_list)
        delete [] msg_struct_list->msg_struct_info;
        msg_struct_list->msg_struct_info = NULL;
 
+       msg_struct_list->nCount = 0;
+
+       // Release Memory
+       MsgReleaseMemory();
+
        return err;
 }
 
@@ -782,6 +875,9 @@ EXPORT_API int msg_get_int_value(msg_struct_t msg_struct_handle, int field, int
        case MSG_STRUCT_SEARCH_CONDITION :
                *value = msg_search_condition_get_int(msg_struct->data, field);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION :
+               *value = msg_list_condition_get_int(msg_struct->data, field);
+               break;
        case MSG_STRUCT_REPORT_STATUS_INFO :
                *value = msg_report_status_get_int(msg_struct->data, field);
                break;
@@ -812,6 +908,7 @@ EXPORT_API int msg_get_int_value(msg_struct_t msg_struct_handle, int field, int
        case MSG_STRUCT_MMS_META:
        case MSG_STRUCT_MMS_SMIL_TEXT:
        case MSG_STRUCT_MMS_SMIL_AVI:
+       case MSG_STRUCT_MULTIPART_INFO:
                err = msg_mms_get_int_value(msg_struct, field, value);
                break;
        case MSG_STRUCT_SETTING_SMSC_OPT :
@@ -824,6 +921,7 @@ EXPORT_API int msg_get_int_value(msg_struct_t msg_struct_handle, int field, int
        case MSG_STRUCT_SETTING_PUSH_MSG_OPT :
        case MSG_STRUCT_SETTING_GENERAL_OPT :
        case MSG_STRUCT_SETTING_MSGSIZE_OPT :
+       case MSG_STRUCT_SETTING_VOICE_MSG_OPT :
                err = msg_setting_get_int_value(msg_struct, field, value);
                break;
        default :
@@ -888,6 +986,13 @@ EXPORT_API int msg_get_str_value(msg_struct_t msg_struct_handle, int field, char
                else
                        strncpy(src, ret_str, size);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION :
+               ret_str = msg_list_condition_get_str(msg_struct->data, field, size);
+               if (ret_str == NULL)
+                       err = MSG_ERR_UNKNOWN;
+               else
+                       strncpy(src, ret_str, size);
+               break;
 
        case MSG_STRUCT_ADDRESS_INFO :
                ret_str = msg_address_info_get_str(msg_struct->data, field, size);
@@ -913,8 +1018,10 @@ EXPORT_API int msg_get_str_value(msg_struct_t msg_struct_handle, int field, char
        case MSG_STRUCT_MMS_META:
        case MSG_STRUCT_MMS_SMIL_TEXT:
        case MSG_STRUCT_MMS_SMIL_AVI:
+       case MSG_STRUCT_MULTIPART_INFO:
                err = msg_mms_get_str_value(msg_struct, field, src, size);
                break;
+       case MSG_STRUCT_SETTING_GENERAL_OPT :
        case MSG_STRUCT_SETTING_SMSC_INFO :
        case MSG_STRUCT_SETTING_CB_CHANNEL_INFO :
        case MSG_STRUCT_SETTING_VOICE_MSG_OPT :
@@ -977,6 +1084,9 @@ EXPORT_API int msg_get_bool_value(msg_struct_t msg_struct_handle, int field, boo
        case MSG_STRUCT_SORT_RULE:
                *value = msg_sortrule_get_bool(msg_struct->data, field);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION:
+               *value = msg_list_condition_get_bool(msg_struct->data, field);
+               break;
        case MSG_STRUCT_MMS_SENDOPT:
                *value = msg_mms_sendopt_get_bool(msg_struct->data, field);
                break;
@@ -1037,6 +1147,9 @@ EXPORT_API int msg_get_struct_handle(msg_struct_t msg_struct_handle, int field,
        case MSG_STRUCT_THREAD_LIST_INDEX:
                err = msg_thread_index_get_struct_handle(msg_struct, field, (void **)value);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION:
+               err = msg_list_condition_get_struct_handle(msg_struct, field, (void **)value);
+               break;
        case MSG_STRUCT_MMS_MEDIA:
                err = msg_mms_get_struct_handle(msg_struct, field, (msg_struct_s**)value);
                break;
@@ -1068,6 +1181,9 @@ EXPORT_API int msg_get_list_handle(msg_struct_t msg_struct_handle, int field, vo
        case MSG_STRUCT_MESSAGE_INFO :
                err = msg_message_get_list_hnd(msg_struct->data, field, value);
                break;
+       case MSG_STRUCT_CONV_INFO:
+               err = msg_conversation_get_list_hnd(msg_struct->data, field, value);
+               break;
        case MSG_STRUCT_MMS:
        case MSG_STRUCT_MMS_PAGE:
                err = msg_mms_get_list_handle(msg_struct, field, (msg_list_handle_t *)value);
@@ -1125,6 +1241,9 @@ EXPORT_API int msg_set_int_value(msg_struct_t msg_struct_handle, int field, int
        case MSG_STRUCT_SEARCH_CONDITION :
                err = msg_search_condition_set_int(msg_struct->data, field, value);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION :
+               err = msg_list_condition_set_int(msg_struct->data, field, value);
+               break;
        case MSG_STRUCT_REPORT_STATUS_INFO :
                err = msg_report_status_set_int(msg_struct->data, field, value);
                break;
@@ -1161,8 +1280,12 @@ EXPORT_API int msg_set_int_value(msg_struct_t msg_struct_handle, int field, int
        case MSG_STRUCT_SETTING_PUSH_MSG_OPT :
        case MSG_STRUCT_SETTING_GENERAL_OPT :
        case MSG_STRUCT_SETTING_MSGSIZE_OPT :
+       case MSG_STRUCT_SETTING_VOICE_MSG_OPT :
                err = msg_setting_set_int_value(msg_struct, field, value);
                break;
+       case MSG_STRUCT_TRANSLATION_INFO :
+               err = msg_translation_set_int(msg_struct->data, field, value);
+               break;
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -1197,6 +1320,9 @@ EXPORT_API int msg_set_str_value(msg_struct_t msg_struct_handle, int field, char
        case MSG_STRUCT_SEARCH_CONDITION :
                err = msg_search_condition_set_str(msg_struct->data, field, value, size);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION :
+               err = msg_list_condition_set_str(msg_struct->data, field, value, size);
+               break;
        case MSG_STRUCT_ADDRESS_INFO :
                err = msg_address_info_set_str(msg_struct->data, field, value, size);
                break;
@@ -1212,8 +1338,10 @@ EXPORT_API int msg_set_str_value(msg_struct_t msg_struct_handle, int field, char
        case MSG_STRUCT_MMS_META:
        case MSG_STRUCT_MMS_SMIL_TEXT:
        case MSG_STRUCT_MMS_SMIL_AVI:
+       case MSG_STRUCT_MULTIPART_INFO:
                err = msg_mms_set_str_value(msg_struct, field, value, size);
                break;
+       case MSG_STRUCT_SETTING_GENERAL_OPT :
        case MSG_STRUCT_SETTING_SMSC_INFO :
        case MSG_STRUCT_SETTING_CB_CHANNEL_INFO :
        case MSG_STRUCT_SETTING_VOICE_MSG_OPT :
@@ -1256,6 +1384,9 @@ EXPORT_API int msg_set_bool_value(msg_struct_t msg_struct_handle, int field, boo
        case MSG_STRUCT_SORT_RULE:
                err = msg_sortrule_set_bool(msg_struct->data, field, value);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION:
+               err = msg_list_condition_set_bool(msg_struct->data, field, value);
+               break;
        case MSG_STRUCT_MMS_SENDOPT:
                err = msg_mms_sendopt_set_bool(msg_struct->data, field, value);
                break;
@@ -1285,6 +1416,9 @@ EXPORT_API int msg_set_bool_value(msg_struct_t msg_struct_handle, int field, boo
        case MSG_STRUCT_PUSH_CONFIG_INFO:
                err = msg_push_config_set_bool(msg_struct->data, field, value);
                break;
+       case MSG_STRUCT_TRANSLATION_INFO :
+               err = msg_translation_set_bool(msg_struct->data, field, value);
+               break;
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
@@ -1319,6 +1453,9 @@ EXPORT_API int msg_set_struct_handle(msg_struct_t msg_struct_handle, int field,
        case MSG_STRUCT_THREAD_LIST_INDEX:
                err = msg_thread_index_set_struct_handle(msg_struct, field, (msg_struct_s *)value);
                break;
+       case MSG_STRUCT_MSG_LIST_CONDITION:
+               err = msg_list_condition_set_struct_handle(msg_struct, field, (msg_struct_s *)value);
+               break;
        case MSG_STRUCT_MMS_MEDIA:
                err = msg_mms_set_struct_handle(msg_struct, field, (msg_struct_s *)value);
                break;
@@ -1345,25 +1482,96 @@ EXPORT_API int msg_set_list_handle(msg_struct_t msg_struct_handle, int field, vo
        if (msg_struct->data == NULL)
                return MSG_ERR_NULL_POINTER;
 
+#if 0 // No operations
+
        switch (msg_struct->type)
        {
        default :
                err = MSG_ERR_INVALID_PARAMETER;
                break;
        }
+#endif
+
+       return err;
+}
+
+EXPORT_API int msg_list_add_item(msg_struct_t msg_struct_handle, int field, msg_struct_t *item)
+{
+       if (msg_struct_handle == NULL || item == NULL) {
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       msg_error_t err = MSG_SUCCESS;
+       msg_struct_s *msg_struct = (msg_struct_s *)msg_struct_handle;
+
+       switch(msg_struct->type) {
+       case MSG_STRUCT_MESSAGE_INFO:
+       {
+               err = msg_message_list_append(msg_struct_handle, field, item);
+       }
+       break;
+       case MSG_STRUCT_MMS:
+       case MSG_STRUCT_MMS_PAGE:
+       {
+               err = msg_mms_list_append(msg_struct_handle, field, item);
+       }
+       break;
+       default :
+               err = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
        return err;
 }
 
 EXPORT_API msg_struct_t msg_list_nth_data(msg_list_handle_t list_handle, int index)
 {
+       if (list_handle == NULL) {
+               return NULL;
+       }
+
        return (msg_struct_t)g_list_nth_data((GList *)list_handle,(guint)index);
 }
 
 EXPORT_API int msg_list_length(msg_list_handle_t list_handle)
 {
+       if (list_handle == NULL) {
+               return 0;
+       }
+
        return (int)g_list_length((GList *)list_handle);
 }
 
+EXPORT_API int msg_list_clear(msg_struct_t msg_struct_handle, int field)
+{
+       if (msg_struct_handle == NULL) {
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       msg_error_t err = MSG_SUCCESS;
+       msg_struct_s *msg_struct = (msg_struct_s *)msg_struct_handle;
+
+       switch(msg_struct->type) {
+       case MSG_STRUCT_MESSAGE_INFO:
+       {
+               err = msg_message_list_clear(msg_struct_handle, field);
+       }
+       break;
+//     case MSG_STRUCT_MMS:
+//     case MSG_STRUCT_MMS_PAGE:
+//     {
+//             err = msg_mms_list_append(msg_struct_handle, field, item);
+//     }
+//     break;
+       default :
+               err = MSG_ERR_INVALID_PARAMETER;
+               break;
+       }
+
+       return err;
+}
+
+
 EXPORT_API int msg_util_calculate_text_length(const char* msg_text, msg_encode_type_t msg_encode_type_to, unsigned int *text_size, unsigned int *segment_size, msg_encode_type_t *msg_encode_type_in)
 {
        msg_error_t err = MSG_SUCCESS;
@@ -1377,17 +1585,19 @@ EXPORT_API int msg_util_calculate_text_length(const char* msg_text, msg_encode_t
        MSG_LANGUAGE_ID_T langId = MSG_LANG_ID_RESERVED;
 
        int decodeLen = 0;
-       int bufSize = (160*MAX_SEGMENT_NUM) + 1;
+       int bufSize = 0;
        int textSize = 0;
 
        bool bAbnormal = false;
 
        textSize = strlen(msg_text);
 
-       unsigned char decodeData[bufSize];
+       bufSize = textSize * 4;
+
+       unsigned char decodeData[bufSize+1];
        memset(decodeData, 0x00, sizeof(decodeData));
 
-       MsgTextConvert textCvt;
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
 
        *text_size = 0;
        *segment_size = 0;
@@ -1395,13 +1605,13 @@ EXPORT_API int msg_util_calculate_text_length(const char* msg_text, msg_encode_t
        switch (msg_encode_type_to)
        {
        case MSG_ENCODE_GSM7BIT :
-               decodeLen = textCvt.convertUTF8ToGSM7bit(decodeData, bufSize, (const unsigned char*)msg_text, textSize, &langId, &bAbnormal);
+               decodeLen = textCvt->convertUTF8ToGSM7bit(decodeData, bufSize, (const unsigned char*)msg_text, textSize, &langId, &bAbnormal);
                break;
        case MSG_ENCODE_UCS2 :
-               decodeLen = textCvt.convertUTF8ToUCS2(decodeData, bufSize, (const unsigned char*)msg_text, textSize);
+               decodeLen = textCvt->convertUTF8ToUCS2(decodeData, bufSize, (const unsigned char*)msg_text, textSize);
                break;
        case MSG_ENCODE_AUTO :
-               decodeLen = textCvt.convertUTF8ToAuto(decodeData, bufSize, (const unsigned char*)msg_text, textSize, &encodeType);
+               decodeLen = textCvt->convertUTF8ToAuto(decodeData, bufSize, (const unsigned char*)msg_text, textSize, &langId, &encodeType);
                break;
        default :
                err = MSG_ERR_INVALID_PARAMETER;
@@ -1410,27 +1620,28 @@ EXPORT_API int msg_util_calculate_text_length(const char* msg_text, msg_encode_t
        }
 
        // calculate segment size.
-       int headerLen = 1;
+       int headerLen = 0;
        int concat = 5;
-//     int lang = 3;
+       int lang = 3;
 
-//     int headerSize = 0;
+       int headerSize = 0;
        int segSize = 0;
 
-//     if (langId != MSG_LANG_ID_RESERVED) {
-//             MSG_DEBUG("National Language Exists");
-//             headerSize += lang;
-//     }
+       if (langId != MSG_LANG_ID_RESERVED) {
+               MSG_DEBUG("National Language Exists");
+               headerSize += lang;
+               headerLen = 1;
+       }
 
        if (msg_encode_type_to == MSG_ENCODE_GSM7BIT || encodeType == MSG_ENCODE_GSM7BIT) {
                MSG_DEBUG("MSG_ENCODE_GSM7BIT");
 
-//             if (((decodeLen+headerSize)/160) > 1)
-//                     segSize = ((140*8) - ((headerLen + concat + headerSize)*8)) / 7;
-               if(decodeLen > 160)
-                       segSize = ((140*8) - ((headerLen + concat)*8)) / 7;
+               if ((decodeLen + headerSize) > 160) {
+                       headerLen = 1;
+                       segSize = ((140 - (headerLen + concat + headerSize)) * 8)/7;
+               }
                else
-                       segSize = 160;
+                       segSize = ((140 - headerLen - headerSize) * 8) / 7;
 
                if (bAbnormal)
                        *msg_encode_type_in = MSG_ENCODE_GSM7BIT_ABNORMAL;
@@ -1442,8 +1653,10 @@ EXPORT_API int msg_util_calculate_text_length(const char* msg_text, msg_encode_t
 
 //             if (((decodeLen+headerSize)/140) > 1)
 //                     segSize = 140 - (headerLen + concat + headerSize);
-               if(decodeLen > 140)
+               if(decodeLen > 140) {
+                       headerLen = 1;
                        segSize = 140 - (headerLen + concat);
+               }
                else
                        segSize = 140;
 
@@ -1455,6 +1668,8 @@ EXPORT_API int msg_util_calculate_text_length(const char* msg_text, msg_encode_t
                return err;
        }
 
+       MSG_DEBUG("decodeLen [%d] segSize [%d]", decodeLen, segSize);
+
        *text_size = decodeLen;
        *segment_size = segSize;
 
index 8b27132..861c69d 100755 (executable)
@@ -1,20 +1,21 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
+#include <privacy_checker_client.h>
 
 #include "MsgHandle.h"
 #include "MsgDebug.h"
@@ -33,9 +34,17 @@ EXPORT_API int msg_submit_req(msg_handle_t handle, msg_struct_t req)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL ||req == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -49,11 +58,7 @@ EXPORT_API int msg_submit_req(msg_handle_t handle, msg_struct_t req)
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-
-               if ((e.errorCode() == MsgException::IPC_ERROR) || (e.errorCode() == MsgException::FILE_ERROR))
-                       return MSG_ERR_STORAGE_ERROR;
-               else
-                       return MSG_ERR_TRANSPORT_ERROR;
+               return MSG_ERR_TRANSPORT_ERROR;
        }
 
        return err;
@@ -64,9 +69,17 @@ EXPORT_API int msg_reg_sent_status_callback(msg_handle_t handle, msg_sent_status
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -78,7 +91,10 @@ EXPORT_API int msg_reg_sent_status_callback(msg_handle_t handle, msg_sent_status
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -89,9 +105,17 @@ EXPORT_API int msg_reg_sms_message_callback(msg_handle_t handle, msg_sms_incomin
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -103,7 +127,10 @@ EXPORT_API int msg_reg_sms_message_callback(msg_handle_t handle, msg_sms_incomin
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -114,14 +141,22 @@ EXPORT_API int msg_reg_mms_conf_message_callback(msg_handle_t handle, msg_mms_co
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        if (app_id && strlen(app_id) > MAX_MMS_JAVA_APPID_LEN)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -133,7 +168,10 @@ EXPORT_API int msg_reg_mms_conf_message_callback(msg_handle_t handle, msg_mms_co
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -144,9 +182,17 @@ EXPORT_API int msg_reg_syncml_message_callback(msg_handle_t handle,  msg_syncml_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -158,7 +204,10 @@ EXPORT_API int msg_reg_syncml_message_callback(msg_handle_t handle,  msg_syncml_
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -169,9 +218,17 @@ EXPORT_API int msg_reg_lbs_message_callback(msg_handle_t handle, msg_lbs_msg_inc
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -183,7 +240,10 @@ EXPORT_API int msg_reg_lbs_message_callback(msg_handle_t handle, msg_lbs_msg_inc
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -194,9 +254,17 @@ EXPORT_API int msg_reg_syncml_message_operation_callback(msg_handle_t handle,  m
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -208,7 +276,10 @@ EXPORT_API int msg_reg_syncml_message_operation_callback(msg_handle_t handle,  m
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -219,14 +290,22 @@ EXPORT_API int msg_reg_push_message_callback(msg_handle_t handle,  msg_push_msg_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        if (app_id && strlen(app_id) > MAX_WAPPUSH_ID_LEN)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -238,7 +317,10 @@ EXPORT_API int msg_reg_push_message_callback(msg_handle_t handle,  msg_push_msg_
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
@@ -248,9 +330,17 @@ EXPORT_API int msg_reg_cb_message_callback(msg_handle_t handle, msg_cb_incoming_
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || cb == NULL)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -262,19 +352,67 @@ EXPORT_API int msg_reg_cb_message_callback(msg_handle_t handle, msg_cb_incoming_
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_CALLBACK_ERROR;
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
        }
 
        return err;
 }
 
+
+EXPORT_API int msg_reg_report_message_callback(msg_handle_t handle, msg_report_msg_incoming_cb cb, void *user_param)
+{
+       msg_error_t err =  MSG_SUCCESS;
+
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
+       if (handle == NULL || cb == NULL)
+       {
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       MsgHandle* pHandle = (MsgHandle*)handle;
+
+       try
+       {
+               err = pHandle->regReportMessageCallback(cb, user_param);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               if (e.errorCode() == MsgException::SERVER_READY_ERROR)
+                       return MSG_ERR_PERMISSION_DENIED;
+               else
+                       return MSG_ERR_CALLBACK_ERROR;
+       }
+
+       return err;
+}
+
+
 EXPORT_API int msg_syncml_message_operation(msg_handle_t handle,  msg_message_id_t msgId)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_READ_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || msgId < 1)
        {
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        MsgHandle* pHandle = (MsgHandle*)handle;
@@ -319,13 +457,13 @@ static int msg_send_single_sms(const char *phone_num, const char *sms_text, msg_
        if (phone_num == NULL || sms_text == NULL || cb == NULL)
        {
                MSG_DEBUG("Invalid parameter [%s] [%s] [%s]", phone_num, sms_text, cb);
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        if (strlen(phone_num) > MAX_PHONE_NUMBER_LEN)
        {
                MSG_DEBUG("Phone Number is too long [%s]", phone_num);
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        msg_struct_s req = {0,};
@@ -355,37 +493,51 @@ static int msg_send_single_sms(const char *phone_num, const char *sms_text, msg_
        msg_info.subType = MSG_NORMAL_SMS;
        msg_info.msgId = 0;
        msg_info.folderId = MSG_OUTBOX_ID;
+       msg_info.simIndex = MSG_SIM_SLOT_ID_1;
 
        /* fill the destination number in msgReq */
+       MSG_ADDRESS_INFO_S address = {0,};
+       memset(&address, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+       address.addressType = MSG_ADDRESS_TYPE_PLMN;
+       address.recipientType = MSG_RECIPIENTS_TYPE_TO;
+       snprintf(address.addressVal, MAX_ADDRESS_VAL_LEN, "%s", phone_num);
+
        msg_struct_list_s addr_list = {0,};
 
        addr_list.nCount = 1;
+       addr_list.msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*1];
+       addr_list.msg_struct_info[0] = (msg_struct_t)new msg_struct_s;
 
-       msg_struct_s addr_info[addr_list.nCount];
-       memset(addr_info, 0, sizeof(msg_struct_s) * addr_list.nCount);
-       addr_list.msg_struct_info = (msg_struct_t *)&addr_info;
+       msg_struct_s *pTmp;
+       pTmp = (msg_struct_s *)addr_list.msg_struct_info[0];
+       pTmp->type = MSG_STRUCT_ADDRESS_INFO;
+       pTmp->data = &address;
 
-       MSG_ADDRESS_INFO_S address[addr_list.nCount];
-       memset(address, 0, sizeof(MSG_ADDRESS_INFO_S) * addr_list.nCount);
+       msg_info.addr_list = (msg_struct_list_s *)&addr_list;
 
-       for (int i = 0; i < addr_list.nCount; i++) {
-               addr_info[i].type = MSG_STRUCT_ADDRESS_INFO;
-               addr_info[i].data = (void *)&address[i];
+       msg_info.bPortValid = false;
 
-               address[i].addressType = MSG_ADDRESS_TYPE_PLMN;
-               snprintf(address[i].addressVal, MAX_ADDRESS_VAL_LEN+1, "%s", phone_num);
+       /* fill the msg text in msgReq */
+       msg_info.dataSize = strlen(sms_text);
+       msg_info.pData = (void*)sms_text;
 
-               address[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
-       }
+       /* Send option */
+       msg_struct_s sendOpt = {0,};
+       MSG_SENDINGOPT_S send_info;
+       memset(&send_info, 0x00, sizeof(MSG_SENDINGOPT_S));
 
-       msg_info.addr_list = &addr_list;
+       sendOpt.type = MSG_STRUCT_SENDOPT;
+       sendOpt.data = (void *)&send_info;
 
-       msg_info.bPortValid = false;
+       msg_struct_s smsSendOpt = {0,};
+       SMS_SENDINGOPT_INFO_S sms_send_opt = {0,};
+       memset(&sms_send_opt, 0x00, sizeof(SMS_SENDINGOPT_INFO_S));
 
-       /* fill the msg text in msgReq */
-       msg_info.dataSize = strlen(sms_text);
-       msg_info.pData = (void*)malloc(msg_info.dataSize+1);
-       strncpy((char *)msg_info.pData, sms_text, msg_info.dataSize);
+       smsSendOpt.type = MSG_STRUCT_SMS_SENDOPT;
+       smsSendOpt.data = (void *)&sms_send_opt;
+
+       send_info.smsSendOpt = (msg_struct_t)&smsSendOpt;
 
        sentStatusCallback = cb;
 
@@ -401,9 +553,15 @@ static int msg_send_single_sms(const char *phone_num, const char *sms_text, msg_
 
        // sending message request
        msgReq.msg = (msg_struct_t)&msg;
+       msgReq.sendOpt = (msg_struct_t)&sendOpt;
 
        retVal = msg_submit_req(msgHandle, (msg_struct_t)&req);
 
+       if (addr_list.msg_struct_info) {
+               delete [] addr_list.msg_struct_info;
+               addr_list.msg_struct_info = NULL;
+       }
+
        if (retVal != MSG_SUCCESS)
        {
                MSG_DEBUG("msg_submit_req() is failed. Error Code = %d", retVal);
@@ -416,10 +574,18 @@ static int msg_send_single_sms(const char *phone_num, const char *sms_text, msg_
 
 EXPORT_API int msg_sms_send(const char *phone_num_list, const char *sms_text, msg_simple_sent_status_cb cb, void *user_param)
 {
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (phone_num_list == NULL || sms_text == NULL || cb == NULL)
        {
                MSG_DEBUG("Invalid parameter [%s] [%s] [%s]", phone_num_list, sms_text, cb);
-               return -EINVAL;
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
        char trimmed_num[strlen(phone_num_list)+1];
@@ -454,6 +620,14 @@ EXPORT_API int msg_sms_send_message(msg_handle_t handle, msg_struct_t req)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || !req) {
                MSG_FATAL("handle or req is NULL");
                return MSG_ERR_NULL_POINTER;
@@ -478,7 +652,7 @@ EXPORT_API int msg_sms_send_message(msg_handle_t handle, msg_struct_t req)
                reqmsg->mainType = MSG_SMS_TYPE;
        }
 
-       if (reqmsg->subType > MSG_CONCAT_SIM_SMS) {
+       if (reqmsg->subType > MSG_CONCAT_SIM_SMS && reqmsg->subType != MSG_UNSAVED_SMS) {
                MSG_DEBUG("subType is not SMS [%d]", reqmsg->subType);
                reqmsg->subType = MSG_NORMAL_SMS;
        }
@@ -486,6 +660,8 @@ EXPORT_API int msg_sms_send_message(msg_handle_t handle, msg_struct_t req)
        reqmsg->folderId = MSG_OUTBOX_ID; // outbox fixed
        reqmsg->networkStatus = MSG_NETWORK_SENDING;
 
+       MSG_DEBUG("Coding Scheme From App. = [%d]", reqmsg->encodeType);
+
        err = msg_submit_req(handle, req);
 
        if (err == MSG_SUCCESS)
@@ -501,6 +677,14 @@ EXPORT_API int msg_mms_send_message(msg_handle_t handle, msg_struct_t req)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || !req)
        {
                MSG_FATAL("handle or req is NULL");
@@ -518,7 +702,7 @@ EXPORT_API int msg_mms_send_message(msg_handle_t handle, msg_struct_t req)
 
        if (reqmsg->mmsDataSize <= 0)
        {
-               MSG_FATAL("MMS data size is invalid [%d]", reqmsg->mmsDataSize);
+               MSG_FATAL("MMS data size is invalid");
                return MSG_ERR_INVALID_PARAMETER;
        }
 
@@ -542,6 +726,14 @@ EXPORT_API int msg_mms_send_read_report(msg_handle_t handle, msg_message_id_t ms
 {
        msg_error_t err = MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL)
        {
                return MSG_ERR_INVALID_PARAMETER;
@@ -574,7 +766,6 @@ EXPORT_API int msg_mms_send_read_report(msg_handle_t handle, msg_message_id_t ms
        reqmsg->mainType = MSG_MMS_TYPE;
        reqmsg->subType = MSG_READREPLY_MMS;
 
-       reqmsg->dataSize = read_report_datasize;
        reqmsg->mmsDataSize = read_report_datasize;
        reqmsg->pMmsData = read_report_data;
 
@@ -598,6 +789,14 @@ EXPORT_API int msg_mms_forward_message(msg_handle_t handle, msg_struct_t req)
 {
        msg_error_t err =  MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || !req )
        {
                MSG_FATAL("handle or req is NULL");
@@ -633,6 +832,14 @@ EXPORT_API int msg_mms_retrieve_message(msg_handle_t handle, msg_struct_t req)
 {
        msg_error_t err = MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if ( handle == NULL|| !req)
        {
                MSG_FATAL("handle or req is NULL");
@@ -666,6 +873,14 @@ EXPORT_API int msg_mms_reject_message(msg_handle_t handle, msg_struct_t req)
 {
        msg_error_t err = MSG_SUCCESS;
 
+       //Privilege check
+       int ret = PRIV_MGR_ERROR_SUCCESS;
+       ret = privacy_checker_check_by_privilege(MSG_SERVICE_WRITE_PRIV_NAME);
+       if(ret != PRIV_MGR_ERROR_SUCCESS)
+       {
+               return MSG_ERR_PERMISSION_DENIED;
+       }
+
        if (handle == NULL || !req )
        {
                MSG_FATAL("handle or req is NULL");
diff --git a/msg-server b/msg-server
new file mode 100755 (executable)
index 0000000..d8f67c9
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+## A script for running msg-server in booting time.
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
+#For log
+# Launch msg-server
+/usr/bin/msg-server &
+
index f56f694..c987f54 100755 (executable)
@@ -5,8 +5,6 @@
 
        <assign>
                <filesystem path="/etc/rc.d/init.d/msg-server" label="_" exec_label="none"/>
-               <filesystem path="/etc/rc.d/rc3.d/S70msg-server" label="_" exec_label="none"/>
-               <filesystem path="/etc/rc.d/rc5.d/S70msg-server" label="_" exec_label="none"/>
                <filesystem path="/etc/config/sysinfo-message.xml" label="_"/>
        </assign>
 </manifest>
index 1a886d6..138d9d6 100755 (executable)
@@ -4,9 +4,6 @@
                <provide>
                        <label name="msg-service::read"/>
                        <label name="msg-service::write"/>
-                       <label name="msg-service::smstrigger"/>
-                       <label name="msg-service::cellbroadcast"/>
-                       <label name="msg-service::wappush"/>
                </provide>
        </define>
        <request>
@@ -23,7 +20,5 @@
                <filesystem path="/usr/lib/libmsg_transaction_proxy.so" label="_"/>
                <filesystem path="/usr/lib/libmsg_utils.so" label="_"/>
                <filesystem path="/usr/lib/libmsg_vobject.so" label="_"/>
-               <filesystem path="/usr/lib/systemd/system/msg-service.service" label="_" exec_label="none" />
-               <filesystem path="/usr/lib/systemd/system/network.target.wants/msg-service.service" label="_" exec_label="none" />
        </assign>
 </manifest>
index 4e0c758..5d04123 100755 (executable)
@@ -1,5 +1,5 @@
 prefix=/usr
-libdir=@LIB_INSTALL_DIR@
+libdir=${prefix}/lib
 includedir=${prefix}/include
 
 Name: MESSAGE-FRAMEWORK
old mode 100644 (file)
new mode 100755 (executable)
index 6f5203a..b9f5c30
@@ -1,42 +1,41 @@
-msg-service msg-service::db rw
-
-msg-service system::use_internet rw
-msg-service media-server rw
-msg-service system::vconf arwxt
-msg-service system::vconf_inhouse rw
-msg-service system::vconf_setting r
-
-msg-service telephony_framework::api_sms rwx
-msg-service telephony_framework::api_sim rw
-msg-service telephony_framework::api_sat x
-
-msg-service contacts-service::svc r
-msg-service contacts-service::phonelog rw
-
-msg-service ug-setting-call-efl::vconf r
-
-msg-service com.samsung.browser::vconf_public r
-
-msg-service testmode::vconf r
-
-msg-service data-provider-master::notification rw
-msg-service data-provider-master::notification.client w
-
-msg-service data-provider-master::badge rw
-msg-service data-provider-master::badge.client w
-
-msg-service oma-dm-agent::vconf_external r
-
-msg-service deviced::display rw
-
-org.tizen.quickpanel msg-service rx
-org.tizen.indicator msg-service rwx
-org.tizen.lockscreen msg-service rx
-
-msg-service net-config rw
-msg-service connman rw
-
-net-config msg-service rw
-connman msg-service rw
-
-system::use_internet msg-service rw
\ No newline at end of file
+msg-service msg-service::db rw---- ------
+msg-service system::use_internet rw---- ------
+msg-service media-server rw---- ------
+msg-service system::vconf rwxat- ------
+msg-service system::vconf_inhouse rw---- ------
+msg-service system::vconf_setting r----- ------
+msg-service telephony_framework::api_sms rwx--- ------
+msg-service telephony_framework::api_sim rw---- ------
+msg-service telephony_framework::api_sat --x--- ------
+msg-service telephony_framework::api_ps_public rw---- ------
+msg-service telephony_framework::api_ps_private rw---- ------
+msg-service telephony_framework::api_ps_profile rw---- ------
+msg-service telephony_framework::properties rw---- ------
+msg-service contacts-service::svc r----- ------
+msg-service contacts-service::phonelog rw---- ------
+msg-service ug-setting-call-efl::vconf r----- ------
+msg-service org.tizen.browser::vconf_public r----- ------
+msg-service testmode::vconf r----- ------
+msg-service data-provider-master::notification rw---- ------
+msg-service data-provider-master::notification.client -w---- ------
+msg-service data-provider-master::badge rw---- ------
+msg-service data-provider-master::badge.client -w---- ------
+msg-service oma-dm-agent::vconf_external r----- ------
+msg-service secure-storage rw---- ------
+msg-service deviced::display rw---- ------
+msg-service net-config rw---- ------
+msg-service connman rw---- ------
+msg-service connman::get rw---- ------
+msg-service connman::set rw---- ------
+msg-service connman::profile rw---- ------
+msg-service aul::launch --x--- ------
+msg-service alarm-server::alarm rw---- ------
+msg-service security-server::api-get-gid -w---- ------
+msg-service security-server::api-cookie-check -w---- ------
+msg-service security-server::api-privilege-by-pid -w---- ------
+net-config msg-service rw---- ------
+connman msg-service rw---- ------
+system::use_internet msg-service rw---- ------
+org.tizen.quickpanel msg-service r-x--- ------
+org.tizen.indicator msg-service rwx--- ------
+org.tizen.lockscreen msg-service r-x--- ------
diff --git a/msg_helper/CMakeLists.txt b/msg_helper/CMakeLists.txt
deleted file mode 100755 (executable)
index ad060c3..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(msg-server CXX)
-
-SET(CMAKE_SKIP_BUILD_RPATH TRUE)
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-       SET(CMAKE_BUILD_TYPE "Debug")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-
-SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -O0 -g -Wall")
-
-##########################################################
-# Define Test App
-##########################################################
-
-SET(MSG-HELPER-SRCS
-       ${CMAKE_SOURCE_DIR}/msg_helper/MsgSensorWrapper.cpp
-       ${CMAKE_SOURCE_DIR}/msg_helper/MsgSoundPlayer.cpp
-       ${CMAKE_SOURCE_DIR}/msg_helper/main.cpp
-)
-
-INCLUDE_DIRECTORIES(
-    ${CMAKE_SOURCE_DIR}/include/mapi
-       ${CMAKE_SOURCE_DIR}/include/common
-       ${CMAKE_SOURCE_DIR}/include/framework
-       ${CMAKE_SOURCE_DIR}/include/msg_helper
-       ${CMAKE_SOURCE_DIR}/include/utils
-)
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(msg_helper_pkgs REQUIRED glib-2.0 dlog vconf mm-fileinfo mm-player mm-sound sensor feedback)
-
-FOREACH(flag ${msg_helper_pkgs_CFLAGS})
-       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
-
-ADD_EXECUTABLE(msg-helper ${MSG-HELPER-SRCS})
-TARGET_LINK_LIBRARIES(msg-helper ${msg_helper_pkgs_LDFLAGS} ${UTILS-LIB})
-
-INSTALL(TARGETS msg-helper DESTINATION bin)
-
diff --git a/msg_helper/MsgSoundPlayer.cpp b/msg_helper/MsgSoundPlayer.cpp
deleted file mode 100755 (executable)
index ebfaf71..0000000
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <pthread.h>
-
-#include "MsgDebug.h"
-#include "MsgCppTypes.h"
-#include "MsgSettingTypes.h"
-#include "MsgGconfWrapper.h"
-#include "MsgUtilFile.h"
-#include "MsgHelper.h"
-
-#include <mm_error.h>
-#include <mm_player.h>
-#include <mm_session_private.h>
-#include <mm_sound.h>
-#include <feedback.h>
-
-extern void worker_done();
-
-/*==================================================================================================
-                                     VARIABLES
-==================================================================================================*/
-static MMHandleType hPlayerHandle = 0;
-static bool bPlaying = false;
-static bool bVibrating = false;
-
-pthread_mutex_t muMmPlay = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t cvMmPlay = PTHREAD_COND_INITIALIZER;
-
-/*==================================================================================================
-                                     FUNCTION IMPLEMENTATION
-==================================================================================================*/
-
-static gboolean MsgStopAndExit(void* data)
-{
-       MsgSoundPlayStop();
-       if(!bPlaying && !bVibrating)
-               worker_done();
-
-       return FALSE;
-}
-
-static gboolean MsgUninitAndExit(void* data)
-{
-       MsgSoundPlayUninit();
-       if(!bPlaying && !bVibrating)
-               worker_done();
-
-       return FALSE;
-}
-
-static gboolean MsgSoundMelodyTimeout(gpointer data)
-{
-       MSG_BEGIN();
-
-       MsgSoundPlayStop();
-       if(!bPlaying && !bVibrating)
-               worker_done();
-
-       MSG_END();
-
-       return FALSE;
-}
-
-static int MsgSoundPlayCallback(int message, void *param, void *user_param)
-{
-       switch (message)
-       {
-               case MM_MESSAGE_ERROR:
-                       MSG_DEBUG("ERROR is happened.");
-                       g_idle_add (MsgUninitAndExit, NULL);
-                       break;
-               case MM_MESSAGE_BEGIN_OF_STREAM:
-                       MSG_DEBUG("Play is started.");
-                       break;
-               case MM_MESSAGE_END_OF_STREAM:
-               case MM_MESSAGE_STATE_INTERRUPTED:
-                       MSG_DEBUG("EOS or Interrupted.");
-                       g_idle_add (MsgStopAndExit, NULL);
-                       break;
-               default:
-                       MSG_DEBUG("message = %d", message);
-                       break;
-       }
-
-       return 1;
-}
-
-
-void* MsgPlayThread(void *data)
-{
-       MSG_BEGIN();
-
-       bool bSoundOn = false;
-       bool bVibrationOn = false;
-       int callStatus = 0;
-       /* 0 - off, 1 - sound, 2 - vibration */
-       int alertOnCall = 0;
-
-       bool isEmergency = false;
-
-       if (data)
-               isEmergency = (bool)data;
-
-       char *msg_tone_file_path = NULL;
-       AutoPtr<char> buf(&msg_tone_file_path);
-
-       msg_tone_file_path = new char[MAX_SOUND_FILE_LEN];
-
-       if (isEmergency) {
-       } else {
-               char *tmpFileFath = NULL;
-
-               tmpFileFath = MsgSettingGetString(VCONFKEY_SETAPPL_NOTI_MSG_RINGTONE_PATH_STR);
-
-               if (tmpFileFath == NULL || MsgGetFileSize(tmpFileFath) < 1) {
-                       strncpy(msg_tone_file_path, DEFAULT_FILE, MAX_SOUND_FILE_LEN-1);
-               } else {
-                       strncpy(msg_tone_file_path, tmpFileFath, MAX_SOUND_FILE_LEN-1);
-                       free(tmpFileFath);
-                       tmpFileFath = NULL;
-               }
-       }
-
-       MSG_DEBUG("Emergency=[%d], Sound File [%s]", isEmergency, msg_tone_file_path);
-
-       MsgSettingGetBool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &bSoundOn);
-       MsgSettingGetBool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &bVibrationOn);
-
-       int err = MM_ERROR_NONE;
-
-       if (isEmergency)
-               err = mm_session_init(MM_SESSION_TYPE_EMERGENCY);
-       else
-               err = mm_session_init(MM_SESSION_TYPE_NOTIFY);
-
-       if(err != MM_ERROR_NONE)
-               MSG_DEBUG("MM Session Init Failed");
-       else
-               MSG_DEBUG("MM Session Init Success : %d", err);
-
-       hPlayerHandle = 0;
-
-       err = mm_player_create(&hPlayerHandle);
-
-       if (err != MM_ERROR_NONE) {
-               MSG_DEBUG("creating the player handle failed");
-               return NULL;
-       }
-
-       /* Setting the call back function msg_callback */
-       mm_player_set_message_callback(hPlayerHandle, MsgSoundPlayCallback, (void *)hPlayerHandle);
-
-       callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
-       MSG_DEBUG("Call Status = %d", callStatus);
-
-       if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
-               alertOnCall = MsgSettingGetInt(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT);
-               MSG_DEBUG("Alert On Call = %d", alertOnCall);
-
-               if (alertOnCall == 0) {
-                       MSG_DEBUG("Call is active & Alert on Call - Off");
-               } else if (alertOnCall == 1) {
-                       MSG_DEBUG("Call is active & Alert on Call - Sound");
-
-                       if (bSoundOn)
-                               MsgSoundPlayDtmf();
-               } else if (alertOnCall == 2) {
-                       MSG_DEBUG("Call is active & Alert on Call - Vibration");
-
-                       if (bVibrationOn)
-                               MsgSoundPlayVibration(true);
-               }
-       } else{
-               MSG_DEBUG("Call is not active");
-
-               if (bVibrationOn) {
-                       MSG_DEBUG("Play vibration.");
-                       MsgSoundPlayVibration(false);
-               }
-
-               if (bSoundOn) {
-                       MSG_DEBUG("Play sound.");
-                       MsgSoundPlayMelody(msg_tone_file_path, false);
-               }
-       }
-
-       err = mm_session_finish();
-
-       if (err != MM_ERROR_NONE)
-               MSG_DEBUG("MM Session Finish Failed");
-       else
-               MSG_DEBUG("MM Session Finish Success : %d", err);
-
-       if(!bPlaying && !bVibrating)
-               worker_done();
-
-       MSG_END();
-
-       return NULL;
-}
-
-
-msg_error_t MsgSoundPlayUninit()
-{
-       MSG_BEGIN();
-
-       int err = MM_ERROR_NONE;
-
-       /* Uninitializing the player module */
-       err = mm_player_unrealize(hPlayerHandle);
-
-       /* Destroying the player handle */
-       err = mm_player_destroy(hPlayerHandle);
-
-       pthread_mutex_lock(&muMmPlay);
-
-       bPlaying = false;
-
-       pthread_mutex_unlock(&muMmPlay);
-
-       pthread_cond_signal(&cvMmPlay);
-
-       hPlayerHandle = 0;
-
-       MSG_END();
-
-       return MSG_SUCCESS;
-}
-
-
-void MsgSoundPlayStart(bool isEmergency)
-{
-       MSG_BEGIN();
-
-       pthread_mutex_lock(&muMmPlay);
-
-       if (bPlaying == true) {
-               MSG_DEBUG("Ringtone is Playing...");
-               pthread_mutex_unlock(&muMmPlay);
-               return;
-       }
-
-       pthread_mutex_unlock(&muMmPlay);
-
-       pthread_t tid;
-
-       if (pthread_create(&tid, NULL, &MsgPlayThread, (void*)isEmergency) == 0) {
-               MSG_DEBUG("Ring alert thread created = %d", tid);
-       } else {
-               MSG_DEBUG("Creating Thread was failed");
-               return;
-       }
-
-       MSG_END();
-}
-
-
-void MsgSoundPlayStop()
-{
-       MSG_BEGIN();
-
-       pthread_mutex_lock(&muMmPlay);
-
-       if (bPlaying == false) {
-               MSG_DEBUG("Ringtone is Not Playing...");
-               pthread_mutex_unlock(&muMmPlay);
-               return;
-       }
-
-       pthread_mutex_unlock(&muMmPlay);
-
-       /* Stop playing media contents */
-       MSG_DEBUG("Before mm_player_stop, %p", hPlayerHandle);
-
-       int err = mm_player_stop(hPlayerHandle);
-
-       MSG_DEBUG("After mm_player_stop");
-
-       if (err != MM_ERROR_NONE) {
-               MSG_DEBUG("stopping the player handle failed");
-       }
-
-       MsgSoundPlayUninit();
-
-       MSG_END();
-}
-
-
-int MsgSoundPlayMelody(char *pMsgToneFilePath, bool bIncreasing)
-{
-       int err = MM_ERROR_NONE;
-
-       /* Setting fade in/out, Volume */
-       err = mm_player_set_attribute(hPlayerHandle, NULL, "sound_volume_type", MM_SOUND_VOLUME_TYPE_NOTIFICATION,
-                                                                                                       "profile_uri", pMsgToneFilePath, strlen(pMsgToneFilePath),
-                                                                                                       "sound_priority", 2, NULL);
-
-       if (err != MM_ERROR_NONE) {
-               MSG_DEBUG("error setting the profile attr");
-               return err;
-       }
-
-       err = mm_player_realize(hPlayerHandle);
-
-       if (err != MM_ERROR_NONE) {
-               MSG_DEBUG("mm_player_realize() error : [%d]", err);
-               return err;
-       }
-
-       /* Add Timer to stop playing after 5 sec. */
-       int g_contact_timer = -1;
-       g_contact_timer = g_timeout_add(5500, (GSourceFunc)MsgSoundMelodyTimeout, NULL);
-
-       err = mm_player_start(hPlayerHandle);
-
-       if (err != MM_ERROR_NONE) {
-               MSG_DEBUG("mm_player_start, FAIL [%x]", err);
-               bPlaying = false;
-
-               return err;
-       }
-
-       bPlaying = true;
-
-       pthread_mutex_lock(&muMmPlay);
-
-       while (bPlaying)
-       {
-               MSG_DEBUG("Ring Alert Playing");
-               pthread_cond_wait(&cvMmPlay, &muMmPlay);
-       }
-
-       pthread_mutex_unlock(&muMmPlay);
-
-       MSG_DEBUG("Ring Alert Idle");
-
-       return err;
-}
-
-
-void MsgSoundPlayVibration(bool isOnCall)
-{
-       MSG_BEGIN();
-
-       int ret = 0;
-
-       ret = feedback_initialize();
-
-       if (ret != FEEDBACK_ERROR_NONE) {
-               MSG_DEBUG("Fail to feedback_initialize : [%d]", ret);
-               return;
-       }
-
-       if (isOnCall)
-               ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE_ON_CALL);
-       else
-               ret = feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_MESSAGE);
-
-       if (ret != FEEDBACK_ERROR_NONE)
-               MSG_DEBUG("Fail to feedback_play_type");
-
-       ret = feedback_deinitialize();
-
-       if (ret != FEEDBACK_ERROR_NONE) {
-               MSG_DEBUG("Fail to feedback_deinitialize : [%d]", ret);
-               return;
-       }
-
-       MSG_END();
-}
-
-void MsgSoundPlayDtmf()
-{
-       MSG_BEGIN();
-
-       int ret = 0;
-       int hToneHandle = 0;
-
-       ret = mm_sound_play_tone(MM_SOUND_TONE_PROP_BEEP2, VOLUME_TYPE_SYSTEM, 1.0, 300, &hToneHandle);
-
-       if(ret < 0) {
-               MSG_DEBUG("play tone failed\n");
-       } else {
-               MSG_DEBUG("play tone success\n");
-       }
-
-       MSG_END();
-}
-
-
-int MsgSoundGetUnreadMsgCnt()
-{
-       int unreadCnt = 0;
-
-       /*  Get SMS Count */
-       unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
-
-       /*  Get MMS Count */
-       unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
-
-       MSG_DEBUG("unread count : [%d]", unreadCnt);
-
-       return unreadCnt;
-}
diff --git a/msg_helper/main.cpp b/msg_helper/main.cpp
deleted file mode 100755 (executable)
index 304ee0a..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdio.h>
-#include <glib.h>
-#include <sys/time.h>
-#include <stdlib.h>
-
-#include "MsgHelper.h"
-#include "MsgUtilFile.h"
-#include "MsgCppTypes.h"
-#include "MsgDebug.h"
-
-static GMainLoop *loop;
-
-static gboolean _worker_done(void* data)
-{
-       if (g_main_loop_is_running(loop))
-               g_main_loop_quit(loop);
-
-       return 0;
-}
-
-// may called by threads
-void worker_done()
-{
-       g_idle_add(_worker_done,NULL);
-}
-
-int main(int argc, char** argv)
-{
-
-       MSG_DEBUG("############### Start msg_helper ###############");
-
-#if !GLIB_CHECK_VERSION(2, 31, 0)
-       g_thread_init(NULL);
-#endif
-
-       bool notEnd = false;
-
-       if(argc < 1)
-       {
-               MSG_DEBUG("No arguments to run msg_helper.");
-               return 0;
-       }
-
-       MSG_DEBUG("argv[0] [%s] ", argv[0]);
-
-       if(g_strcmp0(argv[0], MSG_NORMAL_SOUND_START) == 0)
-       {
-               MsgSoundPlayStart(false);
-               notEnd = true;
-       }
-       if(g_strcmp0(argv[0], MSG_EMERGENCY_SOUND_START) == 0)
-       {
-               MsgSoundPlayStart(true);
-               notEnd = true;
-       }
-       else if(g_strcmp0(argv[0],MSG_SOUND_STOP) == 0)
-       {
-               MsgSoundPlayStop();
-       }
-
-       if(notEnd)
-       {
-               loop = g_main_loop_new(NULL, FALSE);
-
-               if (MsgSensorConnect() == MSG_SUCCESS)
-                       if (MsgRegSensorCB(&worker_done) != MSG_SUCCESS)
-                               MsgSensorDisconnect();
-
-               if (loop != NULL)
-               {
-                       MSG_DEBUG("Waiting for working jobs to be finished!!!");
-
-                       // Run GMainLoop
-                       g_main_loop_run(loop);
-               }
-               else
-               {
-                       MSG_DEBUG("Fail to create g_main_loop!!!");
-                       MsgSensorDisconnect();
-               }
-       }
-
-       return 0;
-}
diff --git a/packaging/msg-server.service b/packaging/msg-server.service
new file mode 100755 (executable)
index 0000000..458cbf6
--- /dev/null
@@ -0,0 +1,13 @@
+[Unit]
+Description=Message server
+After=tizen-runtime.target contacts-service.service
+Requires=tizen-runtime.target contacts-service.service
+
+[Service]
+Type=forking
+ExecStart=/etc/rc.d/init.d/msg-server
+Restart=always
+MemoryLimit=10M
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packaging/msg-service.service b/packaging/msg-service.service
deleted file mode 100755 (executable)
index 0c41b56..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=Messaging Framework
-
-[Service]
-ExecStart=/usr/bin/msg-server
-Nice=5
-OOMScoreAdjust=-100
-Restart=always
-
-[Install]
-WantedBy=multi-user.target
old mode 100644 (file)
new mode 100755 (executable)
index d00bed0..9829ee1
@@ -1,11 +1,10 @@
 Name:           msg-service
-Version:        0.9.11
+Version:        1.0.0
 Release:        1
-License:        Flora-1.1
+License:        Apache-2.0
 Summary:        Messaging Framework Library
 Group:          System/Libraries
 Source0:        %{name}-%{version}.tar.gz
-Source101:      msg-service.service
 
 Requires(post): /usr/bin/sqlite3
 Requires(post): /usr/bin/vconftool
@@ -15,14 +14,22 @@ Requires(post): systemd
 Requires(postun): systemd
 BuildRequires: cmake
 BuildRequires: pkgconfig(alarm-service)
-BuildRequires: pkgconfig(appsvc)
 BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(badge)
 BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(capi-network-connection)
+BuildRequires: pkgconfig(csr-framework)
 BuildRequires: pkgconfig(contacts-service2)
 BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(dbus-glib-1)
+BuildRequires: pkgconfig(deviced)
 BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(drm-client)
+BuildRequires: pkgconfig(feedback)
 BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gobject-2.0)
+BuildRequires: pkgconfig(iniparser)
+BuildRequires: pkgconfig(json-glib-1.0)
+BuildRequires: pkgconfig(lbs-dbus)
 BuildRequires: pkgconfig(libcurl)
 BuildRequires: pkgconfig(libsystemd-daemon)
 BuildRequires: pkgconfig(libxml-2.0)
@@ -32,25 +39,23 @@ BuildRequires: pkgconfig(mm-fileinfo)
 BuildRequires: pkgconfig(mm-player)
 BuildRequires: pkgconfig(mm-session)
 BuildRequires: pkgconfig(mm-sound)
-BuildRequires: pkgconfig(network)
-BuildRequires: pkgconfig(notification)
-BuildRequires: pkgconfig(pmapi)
 BuildRequires: pkgconfig(mmutil-imgp)
 BuildRequires: pkgconfig(mmutil-jpeg)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(privacy-manager-client)
+BuildRequires: pkgconfig(secure-storage)
 BuildRequires: pkgconfig(security-server)
 BuildRequires: pkgconfig(sensor)
-BuildRequires: pkgconfig(svi)
+BuildRequires: pkgconfig(storage)
 BuildRequires: pkgconfig(tapi)
 BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(feedback)
-BuildRequires: pkgconfig(capi-network-connection)
 
 %description
 Description: Messaging Framework Library
 
 
 %package devel
-License:        Flora License v1.1
+License:        Apache-2.0
 Summary:        Messaging Framework Library (development)
 Requires:       %{name} = %{version}-%{release}
 Group:          Development/Libraries
@@ -60,7 +65,7 @@ Description: Messaging Framework Library (development)
 
 
 %package tools
-License:        Flora License v1.1
+License:        Apache-2.0
 Summary:        Messaging server application
 Requires:       %{name} = %{version}-%{release}
 Group:          TO_BU / FILL_IN
@@ -74,7 +79,7 @@ Description:  Messaging server application
 
 
 %package -n sms-plugin
-License:        Flora License v1.1
+License:        Apache-2.0
 Summary:        SMS plugin library
 Requires:       %{name} = %{version}-%{release}
 Group:          System/Libraries
@@ -85,7 +90,7 @@ Requires(postun): /sbin/ldconfig
 Description: SMS plugin library
 
 %package -n mms-plugin
-License:        Flora License v1.1
+License:        Apache-2.0
 Summary:        MMS plugin library
 Requires:       %{name} = %{version}-%{release}
 Group:          System/Libraries
@@ -98,409 +103,232 @@ Description: MMS plugin library
 %prep
 %setup -q
 
-
 %build
-%cmake .
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+%ifarch i586
+-D_TIZEN_I586_ENABLED:BOOL=ON
+%else
+-D_TIZEN_I586_ENABLED:BOOL=OFF
+%endif
+
 make %{?jobs:-j%jobs}
 
 %install
 rm -rf %{buildroot}
-mkdir -p %{buildroot}/etc/config
-mkdir -p %{buildroot}/var/log/msgfw
 mkdir -p %{buildroot}/usr/share/license
-cp LICENSE.Flora %{buildroot}/usr/share/license/%{name}
-cp LICENSE.Flora %{buildroot}/usr/share/license/%{name}-devel
-cp LICENSE.Flora %{buildroot}/usr/share/license/%{name}-tools
-cp LICENSE.Flora %{buildroot}/usr/share/license/sms-plugin
-cp LICENSE.Flora %{buildroot}/usr/share/license/mms-plugin
+mkdir -p %{buildroot}/etc/config
 
 %make_install
 
-mkdir -p %{buildroot}/usr/lib/systemd/system/multi-user.target.wants
-ln -s ../msg-service.service %{buildroot}/usr/lib/systemd/system/multi-user.target.wants/msg-service.service
+mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
+ln -s ../msg-server.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/msg-server.service
 
-mkdir -p %{buildroot}/opt/usr/data/msg-service
+mkdir -p %{buildroot}/opt/usr/dbspace
+sqlite3 %{buildroot}/opt/usr/dbspace/.msg_service.db "PRAGMA journal_mode = PERSIST;"
+sqlite3 %{buildroot}/opt/usr/dbspace/.msg_service.db < %{buildroot}/usr/share/msg-service/msg-service-db.sql
 
-%if 0%{?simulator}
-rm %{buildroot}/etc/config/sysinfo-message.xml
-mv %{buildroot}/etc/config/sysinfo-message.emul.xml %{buildroot}/etc/config/sysinfo-message.xml
-%else
-rm %{buildroot}/etc/config/sysinfo-message.emul.xml
-%endif
+rm %{buildroot}/usr/share/msg-service/msg-service-db.sql
 
+%post tools
+/sbin/ldconfig
+
+chown :5000 /opt/usr/dbspace/.msg_service.db
+chown :5000 /opt/usr/dbspace/.msg_service.db-journal
+chmod 660 /opt/usr/dbspace/.msg_service.db
+chmod 660 /opt/usr/dbspace/.msg_service.db-journal
+
+if [ -f /usr/lib/rpm-plugins/msm.so ]
+then
+       chsmack -a 'msg-service::db' /opt/usr/dbspace/.msg_service.db*
+fi
 
-%post tools -p /sbin/ldconfig
 %post -n sms-plugin -p /sbin/ldconfig
 %post -n mms-plugin -p /sbin/ldconfig
 
 %post
 /sbin/ldconfig
 
-if [ ! -f /opt/usr/dbspace/.msg_service.db ]
-then
-    mkdir -p /opt/usr/dbspace/
-    sqlite3 /opt/usr/dbspace/.msg_service.db "PRAGMA journal_mode = PERSIST;
-
-    CREATE TABLE MSG_CONVERSATION_TABLE (
-       CONV_ID INTEGER PRIMARY KEY ,
-       UNREAD_CNT INTEGER DEFAULT 0 ,
-       SMS_CNT INTEGER DEFAULT 0 ,
-       MMS_CNT INTEGER DEFAULT 0 ,
-       MAIN_TYPE INTEGER DEFAULT 0 ,
-       SUB_TYPE INTEGER DEFAULT 0 ,
-       MSG_DIRECTION INTEGER DEFAULT 0 ,
-       DISPLAY_TIME DATETIME ,
-       DISPLAY_NAME TEXT ,
-       MSG_TEXT TEXT );
-
-    CREATE TABLE MSG_ADDRESS_TABLE (
-       ADDRESS_ID INTEGER PRIMARY KEY ,
-       CONV_ID INTEGER  NOT NULL ,
-       ADDRESS_TYPE INTEGER ,
-       RECIPIENT_TYPE INTEGER ,
-       ADDRESS_VAL TEXT ,
-       CONTACT_ID INTEGER ,
-       DISPLAY_NAME TEXT ,
-       FIRST_NAME TEXT ,
-       LAST_NAME TEXT ,
-       IMAGE_PATH TEXT ,
-       SYNC_TIME DATETIME ,
-       FOREIGN KEY (CONV_ID) REFERENCES MSG_CONVERSATION_TABLE (CONV_ID) );
-
-    CREATE TABLE MSG_FOLDER_TABLE (
-       FOLDER_ID INTEGER PRIMARY KEY ,
-       FOLDER_NAME TEXT NOT NULL ,
-       FOLDER_TYPE INTEGER DEFAULT 0 );
-
-    CREATE TABLE MSG_MESSAGE_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       CONV_ID INTEGER NOT NULL ,
-       FOLDER_ID INTEGER NOT NULL ,
-       STORAGE_ID INTEGER NOT NULL ,
-       MAIN_TYPE INTEGER NOT NULL ,
-       SUB_TYPE INTEGER NOT NULL ,
-       DISPLAY_TIME DATETIME ,
-       DATA_SIZE INTEGER DEFAULT 0 ,
-       NETWORK_STATUS INTEGER DEFAULT 0 ,
-       READ_STATUS INTEGER DEFAULT 0 ,
-       PROTECTED INTEGER DEFAULT 0 ,
-       PRIORITY INTEGER DEFAULT 0 ,
-       MSG_DIRECTION INTEGER NOT NULL ,
-       SCHEDULED_TIME DATETIME ,
-       BACKUP INTEGER DEFAULT 0 ,
-       SUBJECT TEXT ,
-       MSG_DATA TEXT ,
-       THUMB_PATH TEXT ,
-       MSG_TEXT TEXT ,
-       ATTACHMENT_COUNT INTEGER DEFAULT 0 ,
-       FOREIGN KEY (CONV_ID) REFERENCES MSG_CONVERSATION_TABLE (CONV_ID) ,
-       FOREIGN KEY (FOLDER_ID) REFERENCES MSG_FOLDER_TABLE (FOLDER_ID) );
-
-    CREATE TABLE MSG_SIM_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       SIM_ID INTEGER NOT NULL ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_PUSH_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       ACTION INTEGER ,
-       CREATED INTEGER ,
-       EXPIRES INTEGER ,
-       ID TEXT ,
-       HREF TEXT ,
-       CONTENT TEXT ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_CBMSG_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       CB_MSG_ID INTEGER NOT NULL ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_SYNCML_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       EXT_ID INTEGER NOT NULL ,
-       PINCODE INTEGER NOT NULL ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_SCHEDULED_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       ALARM_ID INTEGER NOT NULL ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_SMS_SENDOPT_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       DELREP_REQ INTEGER NOT NULL ,
-       KEEP_COPY INTEGER NOT NULL ,
-       REPLY_PATH INTEGER NOT NULL ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_FILTER_TABLE (
-       FILTER_ID INTEGER PRIMARY KEY ,
-       FILTER_TYPE INTEGER NOT NULL ,
-       FILTER_VALUE TEXT NOT NULL ,
-       FILTER_ACTIVE INTEGER DEFAULT 0 );
-
-    CREATE TABLE MSG_MMS_MESSAGE_TABLE (
-       MSG_ID INTEGER PRIMARY KEY ,
-       TRANSACTION_ID TEXT ,
-       MESSAGE_ID TEXT ,
-       FWD_MESSAGE_ID TEXT ,
-       CONTENTS_LOCATION TEXT ,
-       FILE_PATH TEXT ,
-       VERSION INTEGER NOT NULL ,
-       DATA_TYPE INTEGER DEFAULT -1 ,
-       DATE DATETIME ,
-       HIDE_ADDRESS INTEGER DEFAULT 0 ,
-       ASK_DELIVERY_REPORT INTEGER DEFAULT 0 ,
-       REPORT_ALLOWED INTEGER DEFAULT 0 ,
-       READ_REPORT_ALLOWED_TYPE INTEGER DEFAULT 0 ,
-       ASK_READ_REPLY INTEGER DEFAULT 0 ,
-       READ INTEGER DEFAULT 0 ,
-       READ_REPORT_SEND_STATUS INTEGER DEFAULT 0 ,
-       READ_REPORT_SENT INTEGER DEFAULT 0 ,
-       PRIORITY INTEGER DEFAULT 0 ,
-       KEEP_COPY INTEGER DEFAULT 0 ,
-       MSG_SIZE INTEGER NOT NULL ,
-       MSG_CLASS INTEGER DEFAULT -1 ,
-       EXPIRY_TIME DATETIME ,
-       CUSTOM_DELIVERY_TIME INTEGER DEFAULT 0 ,
-       DELIVERY_TIME DATETIME ,
-       MSG_STATUS INTEGER DEFAULT -1 ,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_MMS_PREVIEW_INFO_TABLE (
-       MSG_ID INTEGER NOT NULL ,
-       TYPE INTEGER,
-       VALUE TEXT,
-       COUNT INTEGER,
-       FOREIGN KEY(MSG_ID) REFERENCES MSG_MESSAGE_TABLE(MSG_ID) );
-
-    CREATE TABLE MSG_REPORT_TABLE (
-       MSG_ID INTEGER NOT NULL ,
-       ADDRESS_VAL TEXT ,
-       STATUS_TYPE INTEGER ,
-       STATUS INTEGER DEFAULT 0 ,
-       TIME DATETIME );
-
-    CREATE TABLE MSG_PUSHCFG_TABLE (
-       PUSH_ID INTEGER PRIMARY KEY ,
-       CONTENT_TYPE TEXT,
-       APP_ID TEXT,
-       PKG_NAME TEXT,
-       LAUNCH INTEGER,
-       APPCODE INTEGER,
-       SECURE INTEGER );
-
-       CREATE TABLE MSG_TMP_MSGID_TABLE (
-       MSG_ID INTEGER );
-
-    CREATE INDEX MSG_CONVERSATION_INDEX ON MSG_CONVERSATION_TABLE(CONV_ID);
-    CREATE INDEX MSG_FOLDER_INDEX ON MSG_FOLDER_TABLE(FOLDER_ID);
-    CREATE INDEX MSG_MESSAGE_INDEX ON MSG_MESSAGE_TABLE(MSG_ID, CONV_ID, FOLDER_ID);
-
-    INSERT INTO MSG_FOLDER_TABLE VALUES (1, 'INBOX', 1);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (2, 'OUTBOX', 2);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (3, 'SENTBOX', 2);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (4, 'DRAFT', 3);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (5, 'CBMSGBOX', 1);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (6, 'SPAMBOX', 4);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (7, 'SMS TEMPLATE', 5);
-    INSERT INTO MSG_FOLDER_TABLE VALUES (8, 'MMS TEMPLATE', 5);
-
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (1, 'text/vnd.wap.si', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 1, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (2, 'application/vnd.wap.sic', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 2, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (3, 'text/vnd.wap.sl', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 3, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (4, 'application/vnd.wap.slc', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 4, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (5, 'text/vnd.wap.co', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 5, 0);
-
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (6, 'application/vnd.wap.coc', 'X-Wap-Application-Id: x-wap-application:wml.ua', '', 0, 6, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (7, 'application/vnd.wap.mms-message', 'X-Wap-Application-Id: x-wap-application:mms.ua', '', 0, 7, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (8, 'application/vnd.wap.sia', 'X-Wap-Application-Id: x-wap-application:push.sia', '', 0, 8, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (9, 'application/vnd.syncml.dm+wbxml', 'X-Wap-Application-Id: x-wap-application:push.syncml.dm', '', 0, 9, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (10, 'application/vnd.syncml.dm+xml', 'X-Wap-Application-Id: x-wap-application:push.syncml.dm', '', 0, 10, 0);
-
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (11, 'application/vnd.syncml.notification', 'X-Wap-Application-Id: x-wap-application:push.syncml.dm', '', 0, 11, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (12, 'application/vnd.syncml.ds.notification', 'X-Wap-Application-Id: x-wap-application:push.syncml.ds', '', 0, 12, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (13, 'application/vnd.syncml+wbxml', 'X-Wap-Application-Id:x-wap-application:push.syncml', '', 0, 13, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (14, 'application/vnd.wap.locc+wbxml', 'X-Wap-Application-Id: x-wap-application:loc.ua', '', 0, 14, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (15, 'application/vnd.wap.loc+xml', 'X-Wap-Application-Id: x-wap-application:loc.ua', '', 0, 15, 0);
-
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (16, 'application/vnd.oma.dd+xml', 'X-Wap-Application-Id: x-wap-application:loc.ua', '', 0, 16, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (17, 'application/vnd.oma.drm.message', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 17, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (18, 'application/vnd.oma.drm.content', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 18, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (19, 'application/vnd.oma.drm.rights+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 19, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (20, 'application/vnd.oma.drm.rights+wbxml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 20, 0);
-
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (21, 'application/vnd.oma.drm.ro+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 21, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (22, 'application/vnd.oma.drm.roap-pdu+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 22, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (23, 'application/vnd.oma.drm.roap-trigger+xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 23, 0);
-    INSERT INTO MSG_PUSHCFG_TABLE VALUES (24, 'application/vnd.oma.drm.roap-trigger+wbxml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 24, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (25, 'text/vnd.wap.connectivity-xml', 'X-Wap-Application-Id: x-wap-application:drm.ua', '', 0, 26, 0);
-
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (26, 'application/vnd.wap.connectivity-wbxml', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 27, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (27, 'application/x-wap-prov.browser-settings', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 28, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (28, 'application/x-wap-prov.browser-bookmarks', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 29, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (29, 'application/x-wap-prov.syncset+xml', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 30, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (30, 'application/x-wap-prov.syncset+wbxml', 'X-Wap-Application-Id: x-wap-samsung:provisioning.ua', '', 0, 31, 0);
-
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (31, 'text/vnd.wap.emn+xml', 'X-Wap-Application-Id: x-wap-application:emn.ua', '', 0, 32, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (32, 'application/vnd.wap.emn+wbxml', 'X-Wap-Application-Id: x-wap-application:emn.ua', '', 0, 33, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (33, 'application/vnd.wv.csp.cir', 'X-Wap-Application-Id: x-wap-application:wv.ua', '', 0, 34, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (34, 'application/vnd.omaloc-supl-init', 'X-Wap-Application-Id: x-oma-application:ulp.ua', '', 0, 44, 0);
-       INSERT INTO MSG_PUSHCFG_TABLE VALUES (35, 'application/vnd.wap.emn+wbxml', 'X-oma-docomo:xmd.mail.ua', '', 0, 45, 1);"
-fi
-
-chown :6011 /opt/usr/dbspace/.msg_service.db
-chown :6011 /opt/usr/dbspace/.msg_service.db-journal
-chmod 660 /opt/usr/dbspace/.msg_service.db
-chmod 660 /opt/usr/dbspace/.msg_service.db-journal
 mkdir -p /opt/usr/data/msg-service
 chgrp db_msg_service /opt/usr/data/msg-service
 
 if [ -f /usr/lib/rpm-plugins/msm.so ]
 then
-       chsmack -a 'msg-service::db' /opt/usr/dbspace/.msg_service.db*
+       chsmack -a "_" -e "_" /etc/rc.d/init.d/msg-server
 fi
 
 ########## Setting Config Value (Internal keys) ##########
-vcuid=5000
 # Message Server Status
-vconftool set -t bool memory/msg/ready 0 -i -g 5000 -u $vcuid
+vconftool set -t bool memory/msg/ready 0 -i -g 5000 -s system::vconf_inhouse
 
 # SMS Send Options
-vconftool set -t int db/msg/network_mode 2 -u $vcuid
+vconftool set -t int db/msg/network_mode 2 -g 5000 -s system::vconf_inhouse
 
 # New Message Count
-vconftool set -t int db/msg/recv_sms 0 -u $vcuid
-vconftool set -t int db/msg/recv_mms 0 -u $vcuid
+vconftool set -t int db/msg/recv_sms 0 -g 5000 -s system::vconf_inhouse
+vconftool set -t int db/msg/recv_mms 0 -g 5000 -s system::vconf_inhouse
 
 ########## Setting Config Value (Private keys) ##########
 # General Options
-vconftool set -t bool db/private/msg-service/general/keep_copy 1 -u $vcuid
-vconftool set -t bool db/private/msg-service/general/auto_erase 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/general/block_msg 0 -u $vcuid
-vconftool set -t int db/private/msg-service/general/contact_sync_time 0 -u $vcuid
+vconftool set -t bool db/private/msg-service/general/keep_copy 1 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/general/auto_erase 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/general/block_msg 1 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/contact_sync_time 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/alert_rep_type 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/search_tags 31 -s msg-service::vconf -g 5000
+
+vconftool set -t int db/private/msg-service/general/page_limit 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/sms_mms_threshold 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/max_recipient 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/sms_storage 0 -s msg-service::vconf -g 5000
+
+vconftool set -t bool db/private/msg-service/general/block_unknown_msg 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/sms_limit 1000 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/mms_limit 100 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/general/notification 1 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/general/vibration 1 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/general/preview 1 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/general/ringtone_type 0 -s msg-service::vconf -g 5000
+vconftool set -t string db/private/msg-service/general/ringtone_path "" -s msg-service::vconf -g 5000
+
+vconftool set -t string db/private/msg-service/general/ua_profile "" -s msg-service::vconf -g 5000
+
+vconftool set -t int db/private/msg-service/general/msg_id_counter 0 -s msg-service::vconf -g 5000
 
 # SMS Send Options
-vconftool set -t int db/private/msg-service/sms_send/dcs 3 -u $vcuid
-vconftool set -t bool db/private/msg-service/sms_send/reply_path 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/sms_send/delivery_report 0 -u $vcuid
-vconftool set -t int db/private/msg-service/sms_send/save_storage 1 -u $vcuid
-
-# SMSC
-vconftool set -t int db/private/msg-service/smsc/total_count 1 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/selected 0 -u $vcuid
-
-vconftool set -t int db/private/msg-service/smsc/pid/0 1 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/val_period/0 255 -u $vcuid
-vconftool set -t string db/private/msg-service/smsc/name/0 "" -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/ton/0 1 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/npi/0 1 -u $vcuid
-vconftool set -t string db/private/msg-service/smsc/address/0 "" -u $vcuid
-
-vconftool set -t int db/private/msg-service/smsc/pid/1 0 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/val_period/1 0 -u $vcuid
-vconftool set -t string db/private/msg-service/smsc/name/1 "" -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/ton/1 0 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/npi/1 0 -u $vcuid
-vconftool set -t string db/private/msg-service/smsc/address/1 "" -u $vcuid
-
-vconftool set -t int db/private/msg-service/smsc/pid/2 0 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/val_period/2 0 -u $vcuid
-vconftool set -t string db/private/msg-service/smsc/name/2 "" -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/ton/2 0 -u $vcuid
-vconftool set -t int db/private/msg-service/smsc/npi/2 0 -u $vcuid
-vconftool set -t string db/private/msg-service/smsc/address/2 "" -u $vcuid
+vconftool set -t int db/private/msg-service/sms_send/dcs 3 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/sms_send/reply_path 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/sms_send/delivery_report 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sms_send/save_storage 1 -s msg-service::vconf -g 5000
 
 # MMS Send Options
-vconftool set -t int db/private/msg-service/mms_send/msg_class 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/priority 1 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/expiry_time 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/custom_delivery 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/sender_visibility 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/delivery_report 1 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/read_reply 1 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/keep_copy 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/body_replying 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/hide_recipients 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_send/report_allowed 1 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/reply_charging 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/reply_charging_deadline 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/reply_charging_size 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/delivery_time 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_send/creation_mode 2 -u $vcuid
+vconftool set -t int db/private/msg-service/mms_send/msg_class 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/priority 1 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/expiry_time 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/custom_delivery 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/sender_visibility 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/delivery_report 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/read_reply 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/keep_copy 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/body_replying 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/hide_recipients 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_send/report_allowed 1 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/reply_charging 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/reply_charging_deadline 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/reply_charging_size 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/delivery_time 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_send/creation_mode 2 -s msg-service::vconf -g 5000
 
 # MMS Receive Options
-vconftool set -t int db/private/msg-service/mms_recv/home_network 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_recv/abroad_network 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_recv/read_receipt 1 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_recv/delivery_receipt 1 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_recv/reject_unknown 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_recv/reject_advertisement 0 -u $vcuid
-
-# MMS Receive Options
-vconftool set -t int db/private/msg-service/mms_style/font_size 30 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_style/font_style/bold 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_style/font_style/italic 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/mms_style/font_style/underline 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/font_color/red 255 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/font_color/green 255 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/font_color/blue 255 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/font_color/hue 255 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/bg_color/red 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/bg_color/green 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/bg_color/blue 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/bg_color/hue 255 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/page_dur 2 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/page_custom_dur 0 -u $vcuid
-vconftool set -t int db/private/msg-service/mms_style/page_dur_manual 0 -u $vcuid
+vconftool set -t int db/private/msg-service/mms_recv/home_network 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_recv/abroad_network 1 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_recv/read_receipt 1 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_recv/delivery_receipt 1 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_recv/reject_unknown 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_recv/reject_advertisement 0 -s msg-service::vconf -g 5000
+
+# MMS Style Options
+vconftool set -t int db/private/msg-service/mms_style/font_size 30 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_style/font_style/bold 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_style/font_style/italic 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/mms_style/font_style/underline 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/font_color/red 255 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/font_color/green 255 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/font_color/blue 255 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/font_color/hue 255 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/bg_color/red 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/bg_color/green 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/bg_color/blue 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/bg_color/hue 255 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/page_dur 2 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/page_custom_dur 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/mms_style/page_dur_manual 0 -s msg-service::vconf -g 5000
 
 # Push Msg Options
-vconftool set -t bool db/private/msg-service/push_msg/recv_option 1 -u $vcuid
-vconftool set -t int db/private/msg-service/push_msg/service_load 1 -u $vcuid
+vconftool set -t bool db/private/msg-service/push_msg/recv_option 1 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/push_msg/service_load 1 -s msg-service::vconf -g 5000
 
 # CB Msg Options
-vconftool set -t bool db/private/msg-service/cb_msg/receive 1 -f -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/save 1 -f -u $vcuid
-vconftool set -t int db/private/msg-service/cb_msg/max_sim_count 0 -u $vcuid
-vconftool set -t int db/private/msg-service/cb_msg/channel_count 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/0 1 -f -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/1 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/2 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/3 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/4 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/5 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/6 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/7 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/8 0 -u $vcuid
-vconftool set -t bool db/private/msg-service/cb_msg/language/9 0 -u $vcuid
+vconftool set -t bool db/private/msg-service/cb_msg/receive 0 -f -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/save 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/cb_msg/max_sim_count/1 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/cb_msg/max_sim_count/2 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/cb_msg/max_sim_count/3 0 -f -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/0 1 -f -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/1 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/2 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/3 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/4 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/5 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/6 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/7 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/8 0 -s msg-service::vconf -g 5000
+vconftool set -t bool db/private/msg-service/cb_msg/language/9 0 -s msg-service::vconf -g 5000
 
 # Voice Mail Options
-vconftool set -t string db/private/msg-service/voice_mail/voice_mail_number "5500" -f -u $vcuid
-vconftool set -t int db/private/msg-service/voice_mail/voice_mail_count 0 -u $vcuid
+vconftool set -t string db/private/msg-service/voice_mail/voice_mail_number/1 "" -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/voice_mail/voice_mail_count/1 0 -f -s msg-service::vconf -g 5000
+vconftool set -t string db/private/msg-service/voice_mail/voice_mail_alphaid/1 "" -f -s msg-service::vconf -g 5000
+
+vconftool set -t string db/private/msg-service/voice_mail/voice_mail_number/2 "" -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/voice_mail/voice_mail_count/2 0 -f -s msg-service::vconf -g 5000
+vconftool set -t string db/private/msg-service/voice_mail/voice_mail_alphaid/2 "" -f -s msg-service::vconf -g 5000
+
+vconftool set -t string db/private/msg-service/voice_mail/voice_mail_number/3 "" -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/voice_mail/voice_mail_count/3 0 -f -s msg-service::vconf -g 5000
+vconftool set -t string db/private/msg-service/voice_mail/voice_mail_alphaid/3 "" -f -s msg-service::vconf -g 5000
 
 # MMS Size Options
-vconftool set -t int db/private/msg-service/size_opt/msg_size 300 -u $vcuid
+vconftool set -t int db/private/msg-service/size_opt/msg_size 300 -s msg-service::vconf -g 5000
 
 # SIM message count
-vconftool set -t int db/private/msg-service/sim_count/used_cnt 0 -u $vcuid
-vconftool set -t int db/private/msg-service/sim_count/total_cnt 0 -u $vcuid
+vconftool set -t int db/private/msg-service/sim_count/used_cnt/1 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_count/total_cnt/1 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_count/used_cnt/2 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_count/total_cnt/2 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_count/used_cnt/3 0 -f -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_count/total_cnt/3 0 -f -s msg-service::vconf -g 5000
 
 # SIM information
-vconftool set -t int memory/private/msg-service/sim_changed 0 -i -u $vcuid
-vconftool set -t string memory/private/msg-service/sim_imsi "" -i -u $vcuid
-vconftool set -t bool memory/private/msg-service/national_sim 0 -i -u $vcuid
-vconftool set -t string memory/private/msg-service/msisdn "" -i -u $vcuid
+vconftool set -t int memory/private/msg-service/sim_changed/1 0 -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/sim_imsi/1 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t bool memory/private/msg-service/national_sim/1 0 -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/msisdn/1 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/iccid/1 "" -i -f -s msg-service::vconf -g 5000
+
+vconftool set -t int memory/private/msg-service/sim_changed/2 0 -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/sim_imsi/2 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t bool memory/private/msg-service/national_sim/2 0 -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/msisdn/2 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/iccid/2 "" -i -f -s msg-service::vconf -g 5000
+
+vconftool set -t int memory/private/msg-service/sim_changed/3 0 -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/sim_imsi/3 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t bool memory/private/msg-service/national_sim/3 0 -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/msisdn/3 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t string memory/private/msg-service/iccid/3 "" -i -f -s msg-service::vconf -g 5000
+vconftool set -t int  memory/private/msg-service/default_network_sim 0 -i -f -s msg-service::vconf -g 5000
+
+# SST information
+vconftool set -t bool memory/private/msg-service/sim_st/1 1 -i -f -s msg-service::vconf -g 5000
+vconftool set -t bool memory/private/msg-service/sim_mo_ctrl/1 0 -i -f -s msg-service::vconf -g 5000
+
+vconftool set -t bool memory/private/msg-service/sim_st/2 1 -i -f -s msg-service::vconf -g 5000
+vconftool set -t bool memory/private/msg-service/sim_mo_ctrl/2 0 -i -f -s msg-service::vconf -g 5000
+
+vconftool set -t bool memory/private/msg-service/sim_st/3 1 -i -f -s msg-service::vconf -g 5000
+vconftool set -t bool memory/private/msg-service/sim_mo_ctrl/3 0 -i -f -s msg-service::vconf -g 5000
+
+# Notification
+vconftool set -t int db/private/msg-service/notification_priv_id 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/voice_noti_id1 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/voice_noti_id2 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/cb_noti_priv_id 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_msg_noti_priv_id 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/emergency_noti_id 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sentfail_noti_id 0 -s msg-service::vconf -g 5000
+vconftool set -t int db/private/msg-service/sim_full_noti_id 0 -s msg-service::vconf -g 5000
 
-vconftool set -t int db/private/msg-service/notification_priv_id 0 -u $vcuid
-vconftool set -t int db/private/msg-service/voice_noti_id1 0 -u $vcuid
-vconftool set -t int db/private/msg-service/cb_noti_priv_id 0 -u $vcuid
-
-/sbin/ldconfig
-/bin/systemctl daemon-reload
-if [ "$1" = "1" ]; then
-    systemctl stop msg-service.service
-fi
 
 %postun -p /sbin/ldconfig
 
@@ -511,166 +339,45 @@ fi
 %files
 %manifest msg-service.manifest
 %defattr(-,root,root,-)
-%dir %attr(775,root,db_msg_service) /opt/usr/data/msg-service
 %{_libdir}/libmsg_plugin_manager.so
 %{_libdir}/libmsg_mapi.so.*
 %{_libdir}/libmsg_framework_handler.so
 %{_libdir}/libmsg_transaction_manager.so
 %{_libdir}/libmsg_utils.so
+%{_libdir}/libmsg_externals.so
 %{_libdir}/libmsg_transaction_proxy.so
 %{_libdir}/libmsg_vobject.so
-/usr/share/license/%{name}
+/usr/share/license/msg-service/LICENSE.APLv2
 
 %files devel
 %defattr(-,root,root,-)
 %{_libdir}/libmsg_mapi.so
 %{_libdir}/pkgconfig/msg-service.pc
 %{_includedir}/msg-service/*
-/usr/share/license/%{name}-devel
 
 %files tools
 %manifest msg-service-tools.manifest
 %defattr(-,root,root,-)
-%{_bindir}/msg-helper
 %{_bindir}/msg-server
-%{_datadir}/media/Sherbet.wav
+%config(noreplace) /opt/usr/dbspace/.msg_service.db*
 %attr(0644,root,root)/usr/share/msg-service/plugin.cfg
-/usr/lib/systemd/system/msg-service.service
-/usr/lib/systemd/system/multi-user.target.wants/msg-service.service
-/usr/share/license/%{name}-tools
-/opt/etc/smack/accesses.d/msg-service.rule
-/etc/config/sysinfo-message.xml
-
-%attr(0755,app,app)/var/log/msgfw
-
+%{_sysconfdir}/rc.d/init.d/msg-server
+%{_libdir}/systemd/system/msg-server.service
+%{_libdir}/systemd/system/multi-user.target.wants/msg-server.service
+/usr/share/license/msg-service/LICENSE.APLv2
+/etc/smack/accesses.d/msg-service.rule
+/etc/config/*
 
 %files -n sms-plugin
 %manifest sms-plugin.manifest
 %defattr(-,root,root,-)
 %{_libdir}/libmsg_sms_plugin.so
-/usr/share/license/sms-plugin
+/usr/share/license/msg-service/LICENSE.APLv2
 
 %files -n mms-plugin
 %manifest mms-plugin.manifest
 %defattr(-,root,root,-)
 %{_libdir}/libmsg_mms_plugin.so
-/usr/share/license/mms-plugin
+/usr/share/license/msg-service/LICENSE.APLv2
 
 %changelog
-* Wed Oct 25 2012 Sangkoo Kim <sangkoo.kim@samsung.com>
-- New release version
-
-* Wed Aug 8 2012 KeeBum Kim <keebum.kim@samsung.com>
-- Apply New TAPI.
-- Modify transaction data size of sos recipient list.
-
-* Tue Aug 7 2012 KeeBum Kim <keebum.kim@samsung.com>
-- Fix contact sync defect.
-- New MessageFW API.
-
-* Fri Jul 27 2012 KeeBum Kim <keebum.kim@samsung.com>
-- Change devman_haptic.h to devman_managed.h.
-- Modify to set MSG_SERVER_READY before sim status check.
-- Fix bug in sim message save related operations.
-- Limit sim related APIs not to work on sim not available status.
-- Modify indicator icon image path & related.
-
-* Tue Jul 17 2012 KeeBum Kim <keebum.kim@samsung.com>
-- Modify MAX_SEGMENT_NUM to 15.
-- Modify MMplayer related to support interrupted event.
-- Fix bug in storage change callback which could cause on submit request.
-
-* Fri Jun 29 2012 Sangkoo Kim <sangkoo.kim@samsung.com>
-- Modify vconf key path for sos sending option.
-
-* Mon Jun 18 2012 Seunghwan Lee <sh.cat.lee@samsung.com>
-- Storage change callback for scheduled message
-- code chage to support glib2-2.32
-- Apply Backup && Restore of Mms Type
-
-* Fri Jun 15 2012 Sangkoo Kim <sangkoo.kim@samsung.com>
-- Update display time for scheduled message when it is sent.
-
-* Thu Jun 14 2012 Seunghwan Lee <sh.cat.lee@samsung.com>
-- Comment the test app in CMakefile.
-- Modify MMS BG color of vconf value.
-- Bug fixed wrong query in MsgStoCheckReadReportIsSent
-- Add '-i' option for vconf keys of memory type
-- Add smsc vconf keys(default value).
-- To avoid msg incoming sound and notification on SOS
-
-* Fri Jun 8 2012 Sangkoo Kim <sangkoo.kim@samsung.com>
-- Add '-i' option for vconf keys of memory type.
-- Add smsc vconf keys(default value).
-- To avoid msg incoming sound and notification on SOS state.
-- Change BGcolor to black && font colore to white.
-
-* Wed May 31 2012 Keebum Kim <keebum.kim@samsung.com>
-- Apply Mdm policy.
-- SOS message.
-- Fix horizontality development problem.
-- Remove vconf key for new message count. (db/badge/com.samsung.message)
-- Change vconf key path of "mms_send/msg_class" to private.
-
-* Thu May 24 2012 Keebum Kim <keebum.kim@samsung.com>
-- Add new MAPI.
-
-* Fri May 18 2012 Sangkoo Kim <sangkoo.kim@samsung.com>
-- Modify to support new DRM service.
-- Rename private vconf keys.
-- Modify .postinst and .spec file to pre-install used vconf keys.
-- Remove compile warnings.
-- Fix bug in manual retrieve operation.
-
-* Fri May 11 2012 Jaeyun Jeong <jyjeong@samsung.com>
-- Fix DB conflict which cause db lock.
-- Fix bug in Find My Mobile function.
-- Add '*' and '#' symbol as valid number.
-
-* Wed May 9 2012 Keebum Kim <keebum.kim@samsung.com>
-- Change mobile tracker related vconf key define values.
-- Apply MDM policy for allowing text messaging.
-- Fix bug for getting thumbnail path.
-- Enable functionality of scheduled message.
-- Change alarm setting of scheduled message from volatile type to non-volatile.
-- Fix error in search query.
-
-* Thu May 3 2012 Keebum Kim <keebum.kim@samsung.com>
-- Change some thread list related APIs to support DB change.
-- DB change to support multiple recipient.
-
-* Thu Apr 19 2012 Keebum Kim <keebum.kim@samsung.com>
-- Modify to manage contact sync time by vconf.
-- Use g_idle_add() routine for updating unread message count(vconf values).
-- apply try{}catch{} code for handling unexpected exception to avoid thread terminating.
-- Fix bug for allocated size of replacing string.
-- Resolve search problem for special characters.
-- add xmlFree.
-
-* Tue Apr 10 2012 Keebum Kim <keebum.kim@samsung.com>
-- Remove unused vconf keys.
-- Initialize SMSC selected_index.
-- Remove systemd related.
-
-* Thu Apr 05 2012 Jaeyun Jeong <jyjeong@samsung.com>
-- Add notification property(NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
-- Fix S1-2397/2417/2418/2419.
-- Remove sent status callback check during submit request.
-- Modify offset and limit operation on search.
-- Remove invalid folder and file.
-- Change browser launching API from aul to service-capi.
-- Remove unused file.
-- Invalid type checking is fixed.
-
-* Fri Mar 16 2012 Jaeyun Jeong <jyjeong@samsung.com>
-- Add #include <sys/stat.h> to support chmod related defines.
-- Fix DRM content issue(unregistered mo content)
-
-* Wed Mar 14 2012 Jaeyun Jeong <jyjeong@samsung.com>
-- Modify plugin configuration file location for FOTA.
-- Remove the db query which create sample data.
-
-* Wed Feb 29 2012 Jaeyun Jeong <jyjeong@samsung.com>
-- Update msg-service.spec for OBS.
-- Fix TC execute failure.
-- Fix S1-1419(Removed mms raw file issue after rebooting)
index a0f874a..b0e1341 100755 (executable)
@@ -24,28 +24,28 @@ SET(MMS-PLUGIN-SRCS
        MmsPluginStorage.cpp
        MmsPluginMessage.cpp
        MmsPluginMIME.cpp
-       MmsPluginAvCodec.cpp
        MmsPluginConnManWrapper.cpp
        MmsPluginUserAgent.cpp
        MmsPluginHttp.cpp
        MmsPluginInternal.cpp
-       MmsPluginSmil.cpp
-       MmsPluginSMILValidate.cpp
        MmsPluginDrm.cpp
        MmsPluginUtil.cpp
+       MmsPluginTcs.cpp
+       MmsPluginComposer.cpp
+       MmsPluginAppBase.cpp
 )
 
 INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/include/common
        ${CMAKE_SOURCE_DIR}/include/framework
-       #${CMAKE_SOURCE_DIR}/include/msg_helper
        ${CMAKE_SOURCE_DIR}/include/utils
+       ${CMAKE_SOURCE_DIR}/include/externals
        ${CMAKE_SOURCE_DIR}/include/mapi
        ${CMAKE_CURRENT_SOURCE_DIR}/include
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(mms_plugin_pkgs REQUIRED glib-2.0 network libxml-2.0 drm-client libcurl mm-fileinfo mmutil-jpeg vconf dlog media-thumbnail capi-network-connection)
+pkg_check_modules(mms_plugin_pkgs REQUIRED glib-2.0 libcurl mm-fileinfo mmutil-imgp mmutil-jpeg vconf dlog media-thumbnail csr-framework capi-network-connection db-util)
 
 FOREACH(flag ${mms_plugin_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -56,13 +56,12 @@ SET(CMAKE_CXX_FLAGS_DEBUG "-O2 -g")
 
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DFEATURE_JAVA_MMS")
-ADD_DEFINITIONS("-D__SUPPORT_DRM__")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
 
 ADD_LIBRARY(${MMS-PLUGIN-LIB} SHARED ${MMS-PLUGIN-SRCS})
-TARGET_LINK_LIBRARIES(${MMS-PLUGIN-LIB} ${mms_plugin_pkgs_LDFLAGS} ${UTILS-LIB})
+TARGET_LINK_LIBRARIES(${MMS-PLUGIN-LIB} ${mms_plugin_pkgs_LDFLAGS} ${UTILS-LIB} ${EXTERNALS-LIB})
 
-INSTALL(TARGETS ${MMS-PLUGIN-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${MMS-PLUGIN-LIB} LIBRARY DESTINATION lib)
 
diff --git a/plugin/mms_plugin/MmsPluginAppBase.cpp b/plugin/mms_plugin/MmsPluginAppBase.cpp
new file mode 100755 (executable)
index 0000000..14a02d0
--- /dev/null
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include "MsgMmsMessage.h"
+#include "MmsPluginDebug.h"
+#include "MmsPluginStorage.h"
+#include "MmsPluginMessage.h"
+#include "MmsPluginMIME.h"
+#include "MmsPluginAppBase.h"
+#include "MmsPluginUtil.h"
+#include "MmsPluginTcs.h"
+#include "MsgUtilFile.h"
+
+msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath);
+
+MmsPluginAppBase::MmsPluginAppBase(){}
+
+MmsPluginAppBase::MmsPluginAppBase(MMS_DATA_S *pMmsData)
+{
+       setMmsData(pMmsData);
+}
+
+MmsPluginAppBase::MmsPluginAppBase(MmsMsg *pMmsMsg)
+{
+       setMmsData(pMmsMsg);
+}
+
+MmsPluginAppBase::~MmsPluginAppBase()
+{
+       MsgMmsReleaseMmsLists(&mmsMsgData);
+}
+
+void MmsPluginAppBase::setMmsData(MmsMsg *pMmsMsg)
+{
+       MmsConvertMsgData(pMmsMsg, &mmsMsgData);
+}
+
+void MmsPluginAppBase::setMmsData(MMS_DATA_S *pMmsData)
+{
+       MsgMmsConvertMmsDataToMmsMessageData(pMmsData, &mmsMsgData);
+}
+
+void MmsPluginAppBase::makePreviewInfo(msg_message_id_t  msgId, bool allow_malware, const char *raw_filepath)
+{
+       MmsMakePreviewInfo(msgId, &mmsMsgData, allow_malware, raw_filepath);
+}
+
+void MmsPluginAppBase::getFirstPageTextFilePath(char *textBuf, int textBufSize)
+{
+
+       MMS_PAGE_S *pPage = NULL;
+       MMS_MEDIA_S *pMedia = NULL;
+
+       MMS_MESSAGE_DATA_S *pMmsMsgData = &mmsMsgData;
+
+       if (pMmsMsgData == NULL)
+               return;
+
+       // Get the text data from the 1st slide.
+       if (pMmsMsgData->pageCnt > 0) {
+
+               pPage = _MsgMmsGetPage(pMmsMsgData, 0);
+
+               if (pPage) {
+
+                       for (int j = 0; j < pPage->mediaCnt; ++j) {
+
+                               pMedia = _MsgMmsGetMedia(pPage, j);
+
+                               if (pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
+
+                                       MimeType mimeType = MIME_UNKNOWN;
+
+                                       MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
+
+                                       if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
+                                               MSG_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
+                                       } else {
+                                               MSG_DEBUG("Text path : [%s]", pMedia->szFilePath);
+                                               snprintf(textBuf, textBufSize, "%s", pMedia->szFilePath);//Set Text Filepath of First Pages
+                                       }
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       return;
+}
+
+
+//FIXME::need to move AppBase
+msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath)
+{
+       MMS_PAGE_S *pPage = NULL;
+       MMS_MEDIA_S *pMedia = NULL;
+       int bc_level = -1;
+
+       int ref_attach_count = 0;
+       const char * attachment_name = NULL;
+
+       if (pMmsMsg == NULL)
+               return MSG_ERR_NULL_POINTER;
+
+       MmsPluginStorage::instance()->removePreviewInfo(msgId); //remove exist previnfo
+
+       //scan malware in raw file
+       if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
+               int tcs_ret = MmsPluginTcsScanFile(raw_filepath, &bc_level);
+               if (tcs_ret == 0) {
+                       if (bc_level > -1) {
+                               MSG_DEBUG("malware exist, level = %d", bc_level);
+                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_MALWARE, "malware", bc_level);
+                       }
+               }
+       }
+
+       //check ref type and increase attach count
+       if (pMmsMsg->pageCnt > 0) {
+               for (int i = 0; i < pMmsMsg->pageCnt; i++) {
+                       pPage = _MsgMmsGetPage(pMmsMsg, i);
+                       if (pPage) {
+                               for (int j = 0; j < pPage->mediaCnt; j++) {
+                                       pMedia = _MsgMmsGetMedia(pPage, j);
+                                       if (pMedia) { //IF Vobject type add to Attach in Preview data
+
+                                               MimeType mimeType = MIME_UNKNOWN;
+                                               MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
+                                               if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD) {
+
+                                                       MSG_DEBUG("Unsupported File [%s] It will be add to attach list", pMedia->szFilePath);
+
+                                                       ref_attach_count++;
+
+                                                       if (attachment_name == NULL) {
+                                                               attachment_name = pMedia->szFileName;
+                                                       }
+                                               }
+
+                                       }
+                               }
+                       }
+               }
+       }
+
+
+       if (pMmsMsg->pageCnt > 0) {
+
+               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
+
+               pPage = _MsgMmsGetPage(pMmsMsg, 0);
+
+               if (pPage) {
+                       for (int j = 0; j < pPage->mediaCnt; j++) {
+
+                               pMedia = _MsgMmsGetMedia(pPage, j);
+
+                               if (pMedia == NULL) {
+                                       MSG_ERR("[%d]th pMedia is NULL", j);
+                                       continue;
+                               }
+
+                               MSG_SEC_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
+
+                               if (allow_malware == false && bc_level > -1) {
+                                       if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
+                                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
+                                       }
+                               } else {
+
+                                       if (j == 0) { //First Page, First Media
+                                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_1ST_MEDIA, pMedia->szFilePath);
+                                       }
+
+                                       if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
+                                               char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
+                                               char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
+                                               char *pszExt = NULL;
+
+                                               memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
+                                               memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
+
+                                               MSG_DEBUG("drm type = %d, %s", pMedia->drmType, pMedia->szFilePath);
+
+                                               if (pMedia->drmType == MSG_DRM_TYPE_NONE) {
+
+                                                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
+
+                                                       if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
+                                                               snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.png", MSG_THUMBNAIL_PATH, szFileName);
+                                                       } else {
+                                                               snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
+                                                       }
+
+                                                       if (MmsMakeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
+                                                               if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
+                                                                       MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
+                                                               } else {
+                                                                       MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
+                                                               }
+                                                       } else {
+                                                               MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
+                                                       }
+                                               }
+                                       } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
+                                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
+                                       }
+                               }
+                       }
+               } // end for
+       } else {
+               MSG_DEBUG("There is no page");
+       }
+
+       int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
+       if (attachCnt > 0) {
+
+               MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
+
+               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
+               MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt); // for Get Message
+
+               if (attachment_name == NULL) {
+                       attachment_name = pAttach->szFileName;
+               }
+
+       } else {
+               MSG_DEBUG("There is no attachment");
+       }
+
+       if (attachCnt + ref_attach_count > 0 && attachment_name) {
+
+               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, attachment_name, attachCnt + ref_attach_count);
+               MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt + ref_attach_count);
+       }
+
+       return MSG_SUCCESS;
+}
diff --git a/plugin/mms_plugin/MmsPluginAvCodec.cpp b/plugin/mms_plugin/MmsPluginAvCodec.cpp
deleted file mode 100755 (executable)
index 4c3cb00..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <string.h>
-#include "MmsPluginAvCodec.h"
-
-AvCodecType    AvGetFileCodecType(const char *szFileName)
-{
-       char szFileExt[FILEEXT_MAX] = {0, };
-       int iPos = 0;
-       int iStrLen = 0;
-       bool bMIME = false;
-
-       iStrLen = strlen(szFileName);
-
-       iPos = iStrLen;
-
-       while (iPos > 0) {
-               iPos--;
-
-               if (szFileName[iPos] == '.')
-                       break;
-               if (szFileName[iPos] == '/') {
-                       bMIME = true;
-                       break;
-               }
-       }
-
-       if (iPos == 0) {
-               return AV_CODEC_NONE;
-       }
-
-       if (FILEEXT_MAX > (iStrLen - iPos - 1)) {
-               strncpy(szFileExt, szFileName + iPos + 1, (iStrLen - iPos - 1));
-               szFileExt[iStrLen - iPos - 1] = '\0';
-       } else
-               return AV_CODEC_NONE;
-
-       if (strcasecmp(szFileExt, "mp3") == 0 || strcasecmp(szFileExt, "MP3") == 0)
-               return AV_DEC_AUDIO_MP3;
-
-       if (strcasecmp(szFileExt, "pvx") == 0 || strcasecmp(szFileExt, "PVX") == 0)
-               return AV_DEC_VIDEO_PVX;
-       else if (strcasecmp(szFileExt, "wav") == 0 || strcasecmp(szFileExt, "WAV") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidWAVE(szFileName) == true)
-                               return AV_DEC_AUDIO_WAVE;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_WAVE;
-       } else if (strcasecmp(szFileExt, "aac") == 0 || strcasecmp(szFileExt, "AAC") == 0)
-               return AV_DEC_AUDIO_AAC;
-#ifdef AV_DEBUG_MODE
-       else if (strcasecmp(szFileExt, "wma") == 0 || strcasecmp(szFileExt, "WMA") == 0)
-               return AvWMFFGetFileType(szFileName);
-       else if (strcasecmp(szFileExt, "wmv") == 0 || strcasecmp(szFileExt, "WMV") == 0)
-               return AvWMFFGetFileType(szFileName);
-       else if (strcasecmp(szFileExt, "asf") == 0 || strcasecmp(szFileExt, "ASF") == 0)
-               return AvWMFFGetFileType(szFileName);
-#endif
-       else if (strcasecmp(szFileExt, "amr") == 0 || strcasecmp(szFileExt, "AMR") == 0 ||
-                       strcasecmp(szFileExt, "x-amr") == 0 || strcasecmp(szFileExt, "X-AMR") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidAMR(szFileName) == true)
-                               return AV_DEC_AUDIO_AMR;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_AMR;
-       } else if (strcasecmp(szFileExt, "g7231") == 0 || strcasecmp(szFileExt, "G7231") == 0)
-               return AV_DEC_AUDIO_G723_1;
-       else if ((strcasecmp(szFileExt, "mid") == 0 || strcasecmp(szFileExt, "MID") == 0) ||
-                       (strcasecmp(szFileExt, "midi") == 0 || strcasecmp(szFileExt, "MIDI") == 0)) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidMIDI(szFileName) == true)
-                               return AV_DEC_AUDIO_MIDI;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_MIDI;
-       } else if (strcasecmp(szFileExt, "mmf") == 0 || strcasecmp(szFileExt, "MMF") == 0 || strcasecmp(szFileExt, "x-mmf") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidMMF(szFileName) == true)
-                               return AV_DEC_AUDIO_MMF;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_MMF;
-       } else if (strcasecmp(szFileExt, "pmd") == 0 || strcasecmp(szFileExt, "PMD") == 0) {
-                       return AV_DEC_AUDIO_MIDI;
-       } else if (strcasecmp(szFileExt, "xmf") == 0 || strcasecmp(szFileExt, "XMF") == 0 ||
-                               strcasecmp(szFileExt,  "mxmf") == 0 || strcasecmp(szFileExt,  "MXMF") == 0) {
-               return AV_DEC_AUDIO_XMF;
-       } else if (strcasecmp(szFileExt, "smp") == 0 || strcasecmp(szFileExt, "SMP") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidSMP(szFileName) == true)
-                               return AV_DEC_AUDIO_ADPCM;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_ADPCM;
-       } else if (strcasecmp(szFileExt, "spm") == 0 || strcasecmp(szFileExt, "SPM") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidMIDI(szFileName) == true)
-                               return AV_DEC_AUDIO_SPM;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_SPM;
-       } else if (strcasecmp(szFileExt, "spf") == 0 || strcasecmp(szFileExt, "SPF") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidMMF(szFileName) == true)
-                               return AV_DEC_AUDIO_MMF_PHRASE_L1;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_MMF_PHRASE_L1;
-       } else if (strcasecmp(szFileExt, "imy") == 0 || strcasecmp(szFileExt, "IMY") == 0 ||
-               strcasecmp(szFileExt, "iMelody") == 0 || strcasecmp(szFileExt, "x-iMelody") == 0 ||
-               strcasecmp(szFileExt, "Melody") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       if (__AvValidIMELODY(szFileName) == true)
-                               return AV_DEC_AUDIO_IMELODY;
-                       else
-                               return AV_CODEC_NONE;
-               } else
-#endif
-                       return AV_DEC_AUDIO_IMELODY;
-       } else if (strcasecmp(szFileExt, "dtmf") == 0)
-               return AV_DEC_AUDIO_DTMF_TONE;
-       else if (strcasecmp(szFileExt, "h263") == 0 || strcasecmp(szFileExt, "H263") == 0)
-               return AV_DEC_VIDEO_H263;
-       else if (strcasecmp(szFileExt, "mp4") == 0 || strcasecmp(szFileExt, "MP4") == 0 ||
-                       strcasecmp(szFileExt, "mpeg4") == 0 || strcasecmp(szFileExt, "MPEG4") == 0 ||
-                       strcasecmp(szFileExt, "m4a") == 0 || strcasecmp(szFileExt, "M4A") == 0) {
-#ifdef AV_DEBUG_MODE
-               if (!bMIME) {
-                       AvCodecType avCodecType = AV_CODEC_NONE;
-                       FmFileAttribute fileAttrib;
-                       size_t strLen;
-                       UINT32  dateTime = 0;
-
-                       if (!DrmGetFileAttributes(szFileName, &fileAttrib)) {
-                               return AV_CODEC_NONE;
-                       } else {
-                               dateTime =  TmDateTimeToSeconds(&fileAttrib.dt);
-                               strLen = strlen(szFileName);
-                               if ((strnicmp(lastAccessFileInfo.szFileName, szFileName, strLen) == 0) &&
-                                       (lastAccessFileInfo.fileSize == fileAttrib.fileSize) &&
-                                       (lastAccessFileInfo.dateTime == dateTime)) {
-                                       return lastAccessFileInfo.codecType;
-                               } else {
-                                       avCodecType = AvMP4FFGetFileType(szFileName);
-
-                                       if (strcasecmp(szFileExt, "3ga") == 0 || strcasecmp(szFileExt, "3GA") == 0 ||
-                                               strcasecmp(szFileExt, "m4a") == 0 || strcasecmp(szFileExt, "M4A") == 0) {
-                                               if (avCodecType | AV_DEC_AUDIO_MPEG4)
-                                                       avCodecType = AV_DEC_AUDIO_MPEG4;
-                                       }
-
-                                       if (avCodecType != AV_CODEC_NONE) {
-                                               strncpy(lastAccessFileInfo.szFileName, szFileName, strLen);
-                                               lastAccessFileInfo.szFileName[strLen] = '\0';
-                                               lastAccessFileInfo.fileSize = fileAttrib.fileSize;
-                                               lastAccessFileInfo.dateTime = dateTime;
-                                               lastAccessFileInfo.codecType = avCodecType;
-                                       }
-                                       return avCodecType;
-                               }
-                       }
-               }
-#endif
-               return AV_DEC_VIDEO_MPEG4;
-       } else if (strcasecmp(szFileExt, "3gp") == 0 || strcasecmp(szFileExt, "3GP") == 0 ||
-               strcasecmp(szFileExt, "3ga") == 0 || strcasecmp(szFileExt, "3GA") == 0 ||
-               strcasecmp(szFileExt, "3gpp") == 0 || strcasecmp(szFileExt, "3GPP") == 0) {
-               return AV_CODEC_NONE;
-       } else if (strcasecmp(szFileExt, "sdp") == 0 || strcasecmp(szFileExt, "SDP") == 0)
-               return AV_DEC_VIDEO_MPEG4;
-       else
-               return AV_CODEC_NONE;
-}
index a6538f0..a307588 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <ctype.h>
@@ -21,6 +21,9 @@
 #include "MmsPluginUtil.h"
 #include "MmsPluginTextConvert.h"
 
+#include <string>
+using namespace std;
+
 #define        MMS_MAX_FIELD_VALUE_COUNT       74
 #define        MMS_MAX_FIELD_TYPE_COUNT        21
 
@@ -155,35 +158,6 @@ const MmsField gMmsField[MMS_MAX_FIELD_TYPE_COUNT][MMS_MAX_FIELD_VALUE_COUNT] =
                {"Error-transient-message-not-found", 0x42},
                {"Error-transient-network-problem", 0x43},
 
-               {"Error-transient-failure", 0x44}, //reserved for future
-               {"Error-transient-failure", 0x45},
-               {"Error-transient-failure", 0x46},
-               {"Error-transient-failure", 0x47},
-               {"Error-transient-failure", 0x48},
-               {"Error-transient-failure", 0x49},
-               {"Error-transient-failure", 0x4A},
-               {"Error-transient-failure", 0x4B},
-               {"Error-transient-failure", 0x4C},
-               {"Error-transient-failure", 0x4D},
-               {"Error-transient-failure", 0x4E},
-               {"Error-transient-failure", 0x4F},
-               {"Error-transient-failure", 0x50},
-               {"Error-transient-failure", 0x51},
-               {"Error-transient-failure", 0x52},
-               {"Error-transient-failure", 0x53},
-               {"Error-transient-failure", 0x54},
-               {"Error-transient-failure", 0x55},
-               {"Error-transient-failure", 0x56},
-               {"Error-transient-failure", 0x57},
-               {"Error-transient-failure", 0x58},
-               {"Error-transient-failure", 0x59},
-               {"Error-transient-failure", 0x5A},
-               {"Error-transient-failure", 0x5B},
-               {"Error-transient-failure", 0x5C},
-               {"Error-transient-failure", 0x5D},
-               {"Error-transient-failure", 0x5E},
-               {"Error-transient-failure", 0x5F},
-
                {"Error-permanent-failure", 0x60},
                {"Error-permanent-service-denied", 0x61},
                {"Error-permanent-message-format-corrupt", 0x62},
@@ -194,31 +168,6 @@ const MmsField gMmsField[MMS_MAX_FIELD_TYPE_COUNT][MMS_MAX_FIELD_VALUE_COUNT] =
                {"Error-permanent-reply-charging-request-not-accepted", 0x67},
                {"Error-permanent-reply-charging-forwarding-denied", 0x68},
                {"Error-permanent-reply-charging-not-supported", 0x69},
-
-               {"Error-permanent-failure", 0x6A}, //reserved for future
-               {"Error-permanent-failure", 0x6B},
-               {"Error-permanent-failure", 0x6C},
-               {"Error-permanent-failure", 0x6D},
-               {"Error-permanent-failure", 0x6E},
-               {"Error-permanent-failure", 0x6F},
-               {"Error-permanent-failure", 0x70},
-               {"Error-permanent-failure", 0x71},
-               {"Error-permanent-failure", 0x72},
-               {"Error-permanent-failure", 0x73},
-               {"Error-permanent-failure", 0x74},
-               {"Error-permanent-failure", 0x75},
-               {"Error-permanent-failure", 0x76},
-               {"Error-permanent-failure", 0x77},
-               {"Error-permanent-failure", 0x78},
-               {"Error-permanent-failure", 0x79},
-               {"Error-permanent-failure", 0x7A},
-               {"Error-permanent-failure", 0x7B},
-               {"Error-permanent-failure", 0x7C},
-               {"Error-permanent-failure", 0x7D},
-               {"Error-permanent-failure", 0x7E},
-               {"Error-permanent-failure", 0x7F}
-
-
        },
 
        /* MmsCodeRetrieveStatus */
@@ -228,70 +177,10 @@ const MmsField gMmsField[MMS_MAX_FIELD_TYPE_COUNT][MMS_MAX_FIELD_VALUE_COUNT] =
                {"Error-transient-message-not-found", 0x41},
                {"Error-transient-network-problem", 0x42},
 
-               {"Error-transient-failure", 0x43}, //reserved for future
-               {"Error-transient-failure", 0x44},
-               {"Error-transient-failure", 0x45},
-               {"Error-transient-failure", 0x46},
-               {"Error-transient-failure", 0x47},
-               {"Error-transient-failure", 0x48},
-               {"Error-transient-failure", 0x49},
-               {"Error-transient-failure", 0x4A},
-               {"Error-transient-failure", 0x4B},
-               {"Error-transient-failure", 0x4C},
-               {"Error-transient-failure", 0x4D},
-               {"Error-transient-failure", 0x4E},
-               {"Error-transient-failure", 0x4F},
-               {"Error-transient-failure", 0x50},
-               {"Error-transient-failure", 0x51},
-               {"Error-transient-failure", 0x52},
-               {"Error-transient-failure", 0x53},
-               {"Error-transient-failure", 0x54},
-               {"Error-transient-failure", 0x55},
-               {"Error-transient-failure", 0x56},
-               {"Error-transient-failure", 0x57},
-               {"Error-transient-failure", 0x58},
-               {"Error-transient-failure", 0x59},
-               {"Error-transient-failure", 0x5A},
-               {"Error-transient-failure", 0x5B},
-               {"Error-transient-failure", 0x5C},
-               {"Error-transient-failure", 0x5D},
-               {"Error-transient-failure", 0x5E},
-               {"Error-transient-failure", 0x5F},
-
                {"Error-permanent-failure", 0x60},
                {"Error-permanent-service-denied", 0x61},
                {"Error-permanent-message-not-found", 0x62},
                {"Error-permanent-content-unsupported", 0x63},
-
-               {"Error-permanent-failure", 0x64}, //reserved for future
-               {"Error-permanent-failure", 0x65},
-               {"Error-permanent-failure", 0x66},
-               {"Error-permanent-failure", 0x67},
-               {"Error-permanent-failure", 0x68},
-               {"Error-permanent-failure", 0x69},
-               {"Error-permanent-failure", 0x6A},
-               {"Error-permanent-failure", 0x6B},
-               {"Error-permanent-failure", 0x6C},
-               {"Error-permanent-failure", 0x6D},
-               {"Error-permanent-failure", 0x6E},
-               {"Error-permanent-failure", 0x6F},
-               {"Error-permanent-failure", 0x70},
-               {"Error-permanent-failure", 0x71},
-               {"Error-permanent-failure", 0x72},
-               {"Error-permanent-failure", 0x73},
-               {"Error-permanent-failure", 0x74},
-               {"Error-permanent-failure", 0x75},
-               {"Error-permanent-failure", 0x76},
-               {"Error-permanent-failure", 0x77},
-               {"Error-permanent-failure", 0x78},
-               {"Error-permanent-failure", 0x79},
-               {"Error-permanent-failure", 0x7A},
-               {"Error-permanent-failure", 0x7B},
-               {"Error-permanent-failure", 0x7C},
-               {"Error-permanent-failure", 0x7D},
-               {"Error-permanent-failure", 0x7E},
-               {"Error-permanent-failure", 0x7F}
-
        },
 
        /* MmsCodeReadReply */
@@ -341,39 +230,31 @@ const MmsField gMmsField[MMS_MAX_FIELD_TYPE_COUNT][MMS_MAX_FIELD_VALUE_COUNT] =
 
        /* MmsCodeCharSet */
        {
-               {"us-ascii", 0x03},
+               {"US-ASCII", 0x03},
                {"UTF-16", 0x03F7},
-               {"ISO-10646-UCS-2", 0x03E8},
+               {"CSUNICODE", 0x03E8},
                {"UTF-8", 0x6A},
-
                {"ISO-2022-KR", 0x25},
                {"KS_C_5601-1987", 0x24},
                {"EUC-KR", 0x26},
                {"ISO-2022-JP", 0x27},
                {"ISO-2022-JP-2", 0x28},
-
                {"ISO_8859-1", 0x04},
                {"ISO_8859-2", 0x05},
                {"ISO-8859-3", 0x06},
                {"ISO-8859-4", 0x07},
                {"ISO-8859-5", 0x08},
                {"ISO-8859-6", 0x09},
-               {"ISO-8859-6-E", 0x51},
-               {"ISO-8859-6-I", 0x52},
                {"ISO-8859-7", 0x0a},
                {"ISO-8859-8", 0x0b},
-               {"ISO-8859-8-I", 0x85},
                {"ISO-8859-9", 0x0c},
                {"ISO-8859-10", 0x0d},
                {"ISO-8859-15", 0x6F},
-
-               {"Shift_JIS", 0x11},
+               {"SHIFT_JIS", 0x11},
                {"EUC-JP", 0x13},
                {"GB2312", 0x07E9},
                {"BIG5", 0x0d},
-               {"WIN1251", 0xFF},
-               {"WINDOW-1251", 0xFF},
-               {"WINDOWS-1251", 0xFF},
+               {"WINDOWS-1251", 0x08CB},
                {"KOI8-R", 0x0824},
                {"KOI8-U", 0x0828},
        },
@@ -387,100 +268,10 @@ const MmsField gMmsField[MMS_MAX_FIELD_TYPE_COUNT][MMS_MAX_FIELD_VALUE_COUNT] =
        },
 
 
-       /* MSG Specific (MsgMIMEExtern.h) -----------------------*/
-
-       /* Content-Type (http://www.wapforum.org/wina/wsp-content-type.htm) */
-       /* this group(Content-Type) will be replaced by utyMime */
+//     OMNA WSP Content Type Numbers
+//     http://technical.openmobilealliance.org/tech/omna/omna-wsp-content-type.aspx
        {
-               // {"Text/txt", 0x01},
-               {"Text/html", 0x02},
-               {"Text/plain", 0x03},
-               {"Text/vnd.wap.wml", 0x08},
-               {"Text/x-vCalendar", 0x06},
-               {"Text/x-vCard", 0x07},
-
-               {"Application/vnd.wap.multipart.*", 0x22},
-               {"Application/vnd.wap.multipart.mixed", 0x23},
-               {"Application/vnd.wap.multipart.related", 0x33},
-               {"Application/vnd.wap.multipart.alternative", 0x26},
-
-               {"application/vnd.oma.drm.message", 0x48},                      // 10
-               {"application/vnd.oma.drm.content", 0x49},
-               {"application/vnd.oma.drm.rights+xml", 0x4A},
-               {"application/vnd.oma.drm.rights+wbxml", 0x4B},
-
-               {"application/smil", 0xFFFF},
-               {"Multipart/mixed", 0x0c},
-               {"Multipart/related", 0x0B},
-               {"Multipart/alternative", 0x0F},
-
-               {"multipart/report", 0xffff},
-               {"Message/rfc822", 0xffff},
-
-       //   T E X T
-               {"Image/gif", 0x1D},                    // 20
-               {"Image/jpeg", 0x1E},
-               {"Image/jpg", 0xFFFF},
-               {"image/tiff", 0x1f},
-               {"Image/png", 0x20},
-
-
-               {"Image/vnd.wap.wbmp", 0x21},
-
-               {"Image/wbmp", 0xFFFF},
-               {"Image/pjpeg", 0xFFFF},
-
-               {"Image/bmp", 0xFFFF},
-
-       // A U D I O
-               {"Audio/basic", 0xFFFF},
-               {"Audio/mpeg", 0xFFFF},                 // 30
-               {"Audio/x-mpeg", 0xFFFF},
-               {"Audio/mp3", 0xFFFF},
-               {"audio/x-mp3", 0xFFFF},
-               {"audio/mpeg3", 0xFFFF},
-               {"audio/x-mpeg3", 0xFFFF},
-               {"audio/mpg", 0xFFFF},
-               {"audio/x-mpg", 0xFFFF},
-               {"audio/x-mpegaudio", 0xFFFF},
-               {"Audio/aac", 0xFFFF},                  // 39
-               {"Audio/g72", 0xFFFF},
-               {"Audio/amr", 0xFFFF},
-               {"audio/x-amr", 0xFFFF},
-               {"audio/x-mmf", 0xFFFF},
-               {"application/vnd.smaf",  0xffff},
-               {"application/x-smaf", 0xFFFF},
-               {"audio/mmf", 0xFFFF},
-
-               {"text/x-iMelody", 0xffff},
-               {"audio/x-iMelody", 0xffff},
-               {"audio/iMelody", 0xffff},              // 49
-               {"audio/mid",0xffff},
-               {"audio/midi", 0xffff},
-               {"audio/x-midi", 0xffff},
-               {"audio/sp-midi", 0xffff},
-               {"audio/wave", 0xffff},
-               {"audio/3gpp", 0xffff},
-               {"audio/vnd.rn-realaudio", 0xffff},
-               {"audio/x-pn-realaudio", 0xffff},
-               {"audio/mp4",  0xffff},
-
-       // V I D E O
-               {"video/mpeg4", 0xFFFF},
-               {"video/mp4", 0xffff},
-               {"video/x-mp4", 0xFFFF},
-               {"video/x-vp-mp4", 0xffff},
-               {"Video/h263", 0xFFFF},
-
-               {"video/3gpp", 0xffff},
-               {"video/3gp", 0xffff},
-               {"Video/avi", 0xFFFF},
-
-               {"video/sdp", 0xffff},                  // 70
-               {"application/vnd.rn-realmedia", 0xffff},
-               {"video/vnd.rn-realvideo", 0xffff},
-
-               {"application/octet-stream", 0xFFFF }
+       //NOT USED THIS TABLE
        },
 
        /* MmsCodeMsgDisposition : Wsp Header (By Wsp 8.4.2.53) */
@@ -573,25 +364,18 @@ UINT16 MmsGetBinaryValue(MmsCode i, int j)
        return gMmsField[i][j].binary;
 }
 
-// getting mime type (int) by binary type
 int MmsGetBinaryType(MmsCode i, UINT16 value)
 {
-       MSG_BEGIN();
-
-       if (i == MmsCodeContentType) {
-               //apply UtyMime
-               return MimeGetMimeIntFromBi(value);
-       }
 
        for (int j = 0; j < MMS_MAX_FIELD_VALUE_COUNT; j++) {
                if (gMmsField[i][j].binary == value) {
+                       MSG_DEBUG("code [%d], value [0x%02x], ret type [%d]", i, value, j);
                        return j;
                }
        }
 
-       MSG_END();
-
-       return MIME_UNKNOWN;
+       MSG_DEBUG("code [%d], value [0x%02x], ret type [Unknown]", i, value);
+       return -1;
 }
 
 int MmsGetTextType(MmsCode i, char *pValue)
@@ -884,246 +668,258 @@ bool MsgEncode2Base64(void *pSrc, unsigned long srcLen, unsigned long *len, unsi
        return true;
 }
 
-
-char *MsgDecodeText(char *pOri)
+int extract_encoded_word_param(char *encoded_word, char **charset,  char **encoding, char **encoded_text, unsigned int *encoded_word_size)
 {
-       MSG_BEGIN();
+       char *start_ptr = NULL;
+       char *end_ptr = NULL;
+       char *q1_ptr = NULL;
+       char *q2_ptr = NULL;
 
-       int size = 0;
-       int cnt = 0;
-       char *pSrc = NULL;
-       char *pTemp = NULL;
-       char *pRe = NULL;
-       char *pStrEnd = NULL;
-       char *pDecStart = NULL;
-       char *pDecEnd = NULL;
-       char *pDecQ = NULL;
-       char *pDecQ2 = NULL;
-       bool bEncoding = false;
-       int     nCharset = MSG_CHARSET_UTF8;
-       int     nTemp = 0;
-       char *pReturnStr = NULL;
-
-       char szTempBuf[MSG_LOCAL_TEMP_BUF_SIZE] = {0};
+       char *char_set = NULL;
+       char *l_encoded_text = NULL;
 
-       // copy original string
-       if (strlen(pOri) >= MSG_LOCAL_TEMP_BUF_SIZE) {
-               pSrc = MsgStrCopy( pOri );
-       } else {
-               memset(szTempBuf, 0, MSG_LOCAL_TEMP_BUF_SIZE);
-               strcpy(szTempBuf, pOri);
+       char l_encoding[2] = {0,};
 
-               pSrc = szTempBuf;
+       if (encoded_word == NULL)
+               goto __CATCH;
+
+       if ( 6 > strlen(encoded_word)) {
+               goto __CATCH;
        }
 
-       // it can be one or more encoding methods in a line
-       while (1) {
-               cnt++;
+       start_ptr = encoded_word;
 
-               bEncoding = false;
+       if ( (encoded_word[0] == '=' && encoded_word[1] == '?') //"=?"
+                        && ((q1_ptr = strchr(start_ptr + 2, MSG_CH_QUESTION)) != NULL) // '?'
+                        && ((q2_ptr = strchr(q1_ptr + 1, MSG_CH_QUESTION))!= NULL)             // '?'
+                        && ((end_ptr = strstr(q2_ptr + 1, MSG_STR_DEC_END))!= NULL)) //"?="
+       {
+
+               //extract character set
+               if ( q1_ptr - (start_ptr + 2) > 0 ) {
+
+                       char_set = (char*)calloc(1, q1_ptr - (start_ptr + 2) + 1);
 
-               /*
-                 (ex) "=?euc-kr?B?Y2NqMjEyMw==?="
+                       strncpy(char_set, (char*)((start_ptr + 2)), q1_ptr - (start_ptr + 2));
 
-                 pDecStart: charset                    (=?euc-kr?B?Y2NqMjEyMw==?=)
-                 pDecQ : Encoding type         (B?Y2NqMjEyMw==?=)
-                 pDecQ2        : Encoded text          (Y2NqMjEyMw==?=)
-                 pDecEnd       : Encoded of text       (?=)
-                */
-               if (pSrc == NULL)
+                       MSG_DEBUG("character set [%s][%d]", char_set, strlen(char_set));
+
+
+               } else {
+                       MSG_DEBUG("character set is NULL");
                        goto __CATCH;
+               }
+
+               //extract encode type
+               if ((*(q2_ptr - 1) == MSG_CH_BASE64_UPPER) || (*(q2_ptr - 1) == MSG_CH_BASE64_LOWER)
+                               || (*(q1_ptr + 1) == MSG_CH_BASE64_UPPER) || (*(q1_ptr + 1) == MSG_CH_BASE64_LOWER))
+               {
+                       l_encoding[0] = MSG_CH_BASE64_UPPER;
+               } else if ((*(q2_ptr-1) == MSG_CH_QPRINT_UPPER) || (*(q2_ptr-1) == MSG_CH_QPRINT_LOWER)
+                               || (*(q1_ptr+1) == MSG_CH_QPRINT_UPPER) || (*(q1_ptr+1) == MSG_CH_QPRINT_LOWER))
+               {
+                       //QPRINT
+                       l_encoding[0] = MSG_CH_QPRINT_UPPER;
 
-               if (((pDecStart = strstr(pSrc, MSG_STR_DEC_START)) != NULL)     //"=?"
-                    && ((pDecQ = strchr(pDecStart + 2, MSG_CH_QUESTION)) != NULL)      // '?'
-                    && ((pDecQ2 = strchr(pDecQ + 1, MSG_CH_QUESTION))!= NULL)          // '?'
-                    && ((pDecEnd = strstr(pDecQ2 + 1, MSG_STR_DEC_END))!= NULL)) {     //"=?"
-                       bEncoding = true;
-
-                       /* fixme: charset problem
-                        * pDecStart ~ pDecQ : charSet & MSG_CHARSET_USC2 ~ MSG_CHARSET_UTF8 & LATIN
-                        */
-
-                       *pDecQ = '\0';
-                       nCharset = _MsgGetCode(MSG_CHARSET, pDecStart + 2);
-                       if(nCharset < 0)
-                               goto __CATCH;
-                       *pDecQ = MSG_CH_QUESTION;
+               } else {
+                       MSG_DEBUG("unknown encoding");
+                       goto __CATCH;
                }
 
-               // End of encoding
-               if (!bEncoding)
-                       goto __RETURN;
+               //extract encoded text
+               if (end_ptr - q2_ptr > 1) {
+                       l_encoded_text = (char*)calloc(1, end_ptr - q2_ptr);
 
-               // find end of string
-               pStrEnd = pSrc + strlen(pSrc);
+                       strncpy(l_encoded_text, (char*)(q2_ptr + 1), end_ptr - q2_ptr -1);
 
-               // Decoding
-               if ((*(pDecQ2 - 1) == MSG_CH_BASE64_UPPER) ||
-                       (*(pDecQ2 - 1) == MSG_CH_BASE64_LOWER) ||
-                       (*(pDecQ + 1) == MSG_CH_BASE64_UPPER) ||
-                       (*(pDecQ + 1) == MSG_CH_BASE64_LOWER)) {
-                       pTemp = (char *)MsgDecodeBase64((UCHAR *)(pDecQ2 + 1), (ULONG)(pDecEnd - pDecQ2 - 1), (ULONG *)&size);
+                       MSG_DEBUG("encoded text [%s][%d]", l_encoded_text, strlen(l_encoded_text));
+               } else {
+                       MSG_DEBUG("encoded text is NULL");
+                       goto __CATCH;
+               }
 
-                       if (pTemp != NULL) {
-                               pTemp[size] = MSG_CH_NULL;
+               *charset = char_set;
+               *encoding = g_strdup(l_encoding);
+               *encoded_text = l_encoded_text;
+               *encoded_word_size = end_ptr - start_ptr + 2;
 
-                               if(pRe) {
-                                       free(pRe);
-                                       pRe = NULL;
-                               }
+       } else {
+               MSG_DEBUG("It is not encoded word type");
+               return -1;
+       }
 
-                               pRe = (char *)malloc((pDecStart-pSrc) + size + (pStrEnd - (pDecEnd + 2)) + 1);
-                               if (pRe == NULL) {
-                                       MSG_DEBUG("_MsgDecodeText: pRemalloc fail \n");
-                                       free(pTemp);
-                                       pTemp = NULL;
+       return 0;
 
-                                       goto __RETURN;
-                               }
+__CATCH:
+       MSG_FREE(char_set);
+       MSG_FREE(l_encoded_text);
+       return -1;
+}
 
-                               memcpy(pRe, pSrc, pDecStart - pSrc);
-                               memcpy(&pRe[pDecStart-pSrc], pTemp, size);
-                               memcpy(&pRe[(pDecStart - pSrc) + size], pDecEnd + 2, pStrEnd - (pDecEnd + 2));
-                               pRe[(pDecStart - pSrc) + size + (pStrEnd - (pDecEnd + 2))] = MSG_CH_NULL;
+char *MsgDecodeText(const char *pOri)
+{
+       MSG_BEGIN();
 
-                               free(pTemp);
-                               pTemp = NULL;
+       char *pSrc = NULL;
 
-                               if (pSrc != NULL && pSrc != szTempBuf) {
-                                       free(pSrc);
-                                       pSrc = NULL;
+       char *encoded_word_start_ptr = NULL;
+       char *normal_word_start_ptr = NULL;
+
+       char *charset = NULL;
+       char *encoding = NULL;
+       char *encoded_text = NULL;
+       char *decoded_text = NULL;
+
+       char *return_string= NULL;
+       string result_string;
+
+       bool b_encoded_word = false;
+
+       unsigned int encoded_word_size = 0;
+       unsigned int total_len = 0;
+       unsigned int decoded_len = 0;
+
+       // copy original string
+       if (pOri == NULL || strlen(pOri) <= 0) {
+               MSG_DEBUG("Invalid parameter : [%s]", pOri);
+               return NULL;
+       }
+
+       pSrc = g_strdup(pOri);
+       total_len = strlen(pOri);
+
+       MSG_DEBUG("input text : [%s][%d]", pSrc, total_len);
+
+       normal_word_start_ptr = pSrc;
+
+       while (normal_word_start_ptr < pSrc + total_len) {
+
+               encoded_word_start_ptr = strstr(normal_word_start_ptr, MSG_STR_DEC_START);
+
+               b_encoded_word = false;
+
+               //Find encoded word
+               while (b_encoded_word == false && encoded_word_start_ptr != NULL ) {
+
+                       if (extract_encoded_word_param(encoded_word_start_ptr, &charset, &encoding, &encoded_text, &encoded_word_size) == 0) {
+
+                               if (charset && encoding && encoded_text && encoded_word_size > 0) {
+                                       b_encoded_word = true;
+                                       MSG_DEBUG("charset [%s], encoding [%s], encoded_text [%s], encoded_word_size [%d]", charset, encoding, encoded_text, encoded_word_size);
+                                       break;
                                }
+
+                               MSG_FREE(charset);
+                               MSG_FREE(encoding);
+                               MSG_FREE(encoded_text);
+                               encoded_word_size = 0;
                        }
-               } else if ((*(pDecQ2-1) == MSG_CH_QPRINT_UPPER) ||
-                               (*(pDecQ2-1) == MSG_CH_QPRINT_LOWER) ||
-                               (*(pDecQ+1) == MSG_CH_QPRINT_UPPER) ||
-                               (*(pDecQ+1) == MSG_CH_QPRINT_LOWER)) {
 
-                       pTemp = (char *)MsgDecodeQuotePrintable((UCHAR *)( pDecQ2 + 1 ), (ULONG)(pDecEnd - pDecQ2 - 1), (ULONG *)&size);
+                       encoded_word_start_ptr = strstr(encoded_word_start_ptr+1, MSG_STR_DEC_START); //find next encoded_start_ptr
 
-                       if (pTemp != NULL) {
-                               int i;
-                               pTemp[size] = MSG_CH_NULL;
+               } // end of while
 
-                               for (i = 0; i < size; i++) {
-                                       if (pTemp[i] == MSG_CH_UNDERLINE) {
-                                               pTemp[i] = MSG_CH_SP;                         // change '_' to ' '
-                                       }
-                               }
+               if (b_encoded_word) {
 
-                               if(pRe) {
-                                       free(pRe);
-                                       pRe = NULL;
-                               }
+                       //copy normal text
+                       if (encoded_word_start_ptr - normal_word_start_ptr > 0) {
+                               result_string.append(normal_word_start_ptr, encoded_word_start_ptr - normal_word_start_ptr);
+                               MSG_DEBUG("copy normal text : [%s]", result_string.c_str());
+                       }
 
-                               pRe = (char *)malloc((pDecStart - pSrc) + size + (pStrEnd - (pDecEnd + 2)) + 1);
-                               if (pRe == NULL) {
-                                       MSG_DEBUG("_MsgDecodeText: pRemalloc fail \n");
-                                       free(pTemp);
-                                       pTemp = NULL;
+                       if (strcasecmp(encoding, "B") == 0) {
 
-                                       goto __RETURN;
-                               }
+                               MSG_DEBUG("Base64 encoded text [%s][%d]", encoded_text, strlen(encoded_text));
 
-                               memcpy(pRe, pSrc, pDecStart - pSrc);
-                               memcpy(&pRe[pDecStart - pSrc], pTemp, size);
-                               memcpy(&pRe[(pDecStart - pSrc) + size], pDecEnd + 2, pStrEnd - (pDecEnd + 2));
-                               pRe[(pDecStart - pSrc) + size + (pStrEnd - (pDecEnd + 2))] = MSG_CH_NULL;
+                               decoded_text = (char *)MsgDecodeBase64((unsigned char *)encoded_text, strlen(encoded_text), (ULONG *)&decoded_len);
 
-                               if (pTemp) {
-                                       free(pTemp);
-                                       pTemp = NULL;
-                               }
+                               if (decoded_text && decoded_len > 0) {
+
+                                       char *result_text = NULL;
+                                       int result_text_len = 0;
+
+                                       MSG_DEBUG("Base64 decoded text [%s][%d], outlen [%d]", decoded_text, strlen(decoded_text), decoded_len);
+
+                                       if (MmsPluginTextConvert("UTF-8", charset, decoded_text, decoded_len, &result_text, &result_text_len) == false) {
+                                               MSG_DEBUG("MmsPluginTextConvert Fail");
+                                       }
+
+                                       if(result_text) {
+                                               MSG_DEBUG("Text convert result [%s][%d]", result_text, strlen(result_text));
+
+                                               result_string.append(result_text, result_text_len);
 
-                               if (pSrc != NULL && pSrc != szTempBuf) {
-                                       free(pSrc);
-                                       pSrc = NULL;
+                                               MSG_FREE(result_text);
+                                       }
+
+                               } else {
+                                       MSG_DEBUG("Fail base64 decode");
                                }
-                       }
-               } else {
-                       goto __RETURN;
-               }
-       }
 
+                               MSG_FREE(decoded_text);
 
+                       } else if (strcasecmp(encoding, "Q") == 0) {
 
-__RETURN:
+                               char *result_text = NULL;
+                               int result_text_len = 0;
 
-       pTemp = strdup(pSrc);
-       nTemp = strlen(pSrc);
+                               MSG_DEBUG("Qprint encoded text [%s][%d]", encoded_text, strlen(encoded_text));
 
-       {//temp brace;
-               const char *pToCharSet = "UTF-8";
+                               decoded_text = (char *)MsgDecodeQuotePrintable((unsigned char *)encoded_text, strlen(encoded_text), (ULONG *)&decoded_len);
 
-               UINT16 charset_code =  MmsGetBinaryValue(MmsCodeCharSet, nCharset);
+                               if (decoded_text && decoded_len > 0) {
 
-               const char *pFromCharSet = MmsPluginTextConvertGetCharSet(charset_code);
+                                       MSG_DEBUG("Qprint decoded text [%s][%d], outlen [%d]", decoded_text, strlen(decoded_text), decoded_len);
 
-               if (pFromCharSet != NULL && strcmp(pFromCharSet, pToCharSet) != 0) {//Not UTF-8
-                       char *pDest = NULL;
-                       int destLen = 0;
+                                       if (MmsPluginTextConvert("UTF-8", charset, decoded_text, decoded_len, &result_text, &result_text_len) == false) {
+                                               MSG_DEBUG("MmsPluginTextConvert Fail");
+                                       }
 
-                       if (MmsPluginTextConvert(pToCharSet, pFromCharSet, pTemp, nTemp, &pDest, &destLen) == false) {
-                               MSG_DEBUG("MmsPluginTextConvert Fail");
-                       }
+                                       if(result_text) {
+                                               MSG_DEBUG("Text convert result [%s][%d]", result_text, strlen(result_text));
 
-                       if (pDest) {
-                               free(pTemp);
-                               pTemp = strdup(pDest);
-                               nTemp = destLen;
-                               free(pDest);
-                       }
-               }
+                                               result_string.append(result_text, result_text_len);
 
-       }
+                                               MSG_FREE(result_text);
+                                       }
 
-       pReturnStr = (char *)malloc(nTemp + 1);
+                               } else {
+                                       MSG_DEBUG("Fail Qprint decode");
+                               }
 
-       if (pReturnStr == NULL) {
-               goto __CATCH;
-       }
+                               MSG_FREE(decoded_text);
+                       }
 
-       memset(pReturnStr, 0, nTemp + 1);
+                       normal_word_start_ptr = encoded_word_start_ptr+encoded_word_size; //next
 
-       if (pTemp) {
-               memcpy(pReturnStr, pTemp, nTemp);
-               free(pTemp);
-               pTemp = NULL;
-       }
+                       MSG_FREE(charset);
+                       MSG_FREE(encoding);
+                       MSG_FREE(encoded_text);
+                       encoded_word_size = 0;
 
-       if(pRe) {
-               free(pRe);
-               pRe = NULL;
-       }
+               } else {
+                       //copy remain normal text
 
-       if (pSrc != NULL && pSrc != szTempBuf) {
-               free(pSrc);
-               pSrc = NULL;
-       }
+                       MSG_DEBUG("last text : [%s]", normal_word_start_ptr);
 
-       return pReturnStr;
+                       result_string.append(normal_word_start_ptr);
 
-__CATCH:
+                       break;
+               }
 
-       if(pRe) {
-               free(pRe);
-               pRe = NULL;
-       }
+       } //end of while
 
-       if (pSrc != NULL && pSrc != szTempBuf) {
-               free(pSrc);
-               pSrc = NULL;
+       if (result_string.length() > 0) {
+               return_string = g_strdup(result_string.c_str());
+               MSG_DEBUG("return string: [%s]", return_string);
        }
 
-       if (pTemp) {
-               free(pTemp);
-               pTemp = NULL;
-       }
+       MSG_FREE(pSrc);
 
-       return NULL;
+       MSG_END();
+       return return_string;
 }
 
-
 static char gszDebugStringBuf[50];
 
 static char *MmsDebugPrintUnknownValue(int value)
@@ -1360,6 +1156,8 @@ const char *MmsDebugGetMimeType(MimeType mimeType)
                return "MIME_TEXT_XML";
        case MIME_TEXT_IMELODY:
                return "MIME_TEXT_IMELODY";
+       case MIME_TEXT_CALENDAR:
+               return "MIME_TEXT_CALENDAR";
        case MIME_TEXT_VND_WAP_WMLSCRIPT:
                return "MIME_TEXT_VND_WAP_WMLSCRIPT";
        case MIME_TEXT_VND_WAP_WML:
@@ -1384,6 +1182,9 @@ const char *MmsDebugGetMimeType(MimeType mimeType)
                return "MIME_TEXT_X_VCARD";
        case MIME_TEXT_X_IMELODY:
                return "MIME_TEXT_X_IMELODY";
+       case MIME_TEXT_X_VTODO:
+               return "MIME_TEXT_X_VTODO";
+
 
        case MIME_VIDEO_MPEG4:
                return "MIME_VIDEO_MPEG4";
@@ -1399,6 +1200,10 @@ const char *MmsDebugGetMimeType(MimeType mimeType)
                return "MIME_VIDEO_AVI";
        case MIME_VIDEO_SDP:
                return "MIME_VIDEO_SDP";
+       case MIME_VIDEO_MP4_ES:
+               return "MIME_VIDEO_MP4_ES";
+       case MIME_VIDEO_MPEG:
+               return "MIME_VIDEO_MPEG";
        case MIME_VIDEO_VND_RN_REALVIDEO:
                return "MIME_VIDEO_VND_RN_REALVIDEO";
        case MIME_VIDEO_X_MP4:
@@ -1457,6 +1262,8 @@ const char *MmsDebugGetMmsReadStatus(msg_read_report_status_t readStatus)
                return "MMS_IS_READ";
        case MSG_READ_REPORT_IS_DELETED:
                return "MMS_IS_DELETED";
+       default:
+               break;
        }
 
        return MmsDebugPrintUnknownValue(readStatus);
@@ -1656,7 +1463,7 @@ const char *MmsDebugGetDataType(MmsDataType dataType)
 
 bool MmsInitMsgType(MsgType *pMsgType)
 {
-       MSG_DEBUG("MmsInitMsgType");
+       MSG_DEBUG("ptr : [%p]", pMsgType);
        pMsgType->offset = 0;
        pMsgType->size = 0;
        pMsgType->contentSize = 0;
@@ -1669,21 +1476,15 @@ bool MmsInitMsgType(MsgType *pMsgType)
        pMsgType->szContentID[0] = '\0';
        pMsgType->szContentLocation[0] = '\0';
 
-       pMsgType->szContentRepPos[0] = '\0';
-       pMsgType->szContentRepSize[0] = '\0';
-       pMsgType->szContentRepIndex[0] = '\0';
-
        MmsInitMsgContentParam(&pMsgType->param);
-#ifdef __SUPPORT_DRM__
        MmsInitMsgDRMInfo(&pMsgType->drmInfo);
-#endif
 
        return true;
 }
 
 bool MmsInitMsgBody(MsgBody *pMsgBody)
 {
-       MSG_DEBUG("MmsInitMsgBody");
+       MSG_DEBUG("ptr : [%p]", pMsgBody);
        pMsgBody->offset = 0;
        pMsgBody->size = 0;
        pMsgBody->body.pText = NULL;
@@ -1698,7 +1499,7 @@ bool MmsInitMsgBody(MsgBody *pMsgBody)
 
 bool MmsInitMsgContentParam(MsgContentParam *pMsgContentParam)
 {
-       MSG_DEBUG("MmsInitMsgContentParam");
+       MSG_DEBUG("ptr : [%p]", pMsgContentParam);
        pMsgContentParam->charset = MSG_CHARSET_UNKNOWN;
        pMsgContentParam->type = MIME_UNKNOWN;
        pMsgContentParam->szBoundary[0] = '\0';
@@ -1730,12 +1531,13 @@ bool MmsInitMsgAttrib(MmsAttrib *pAttrib)
 
        pAttrib->bHideAddress = false;
        pAttrib->date = 0;
-       pAttrib->bUseDeliveryCustomTime = false;
+
        pAttrib->deliveryTime.type = MMS_TIMETYPE_RELATIVE;
        pAttrib->deliveryTime.time = 0;
-       pAttrib->bUseExpiryCustomTime = false;
+
        pAttrib->expiryTime.type = MMS_TIMETYPE_RELATIVE;
        pAttrib->expiryTime.time = 0;
+
        memset(&pAttrib->expiryTime, 0, sizeof(MmsTimeStruct));
        pAttrib->msgClass = MMS_MSGCLASS_PERSONAL;
        pAttrib->msgStatus = MSG_DELIVERY_REPORT_NONE;
@@ -1745,13 +1547,6 @@ bool MmsInitMsgAttrib(MmsAttrib *pAttrib)
        pAttrib->contentType = MIME_UNKNOWN;
        pAttrib->msgSize = 0;
        pAttrib->bLeaveCopy = true;
-
-       pAttrib->specialMsgType = MMS_SPECIAL_MSG_TYPE_NONE;
-#ifdef __SUPPORT_DRM__
-       pAttrib->drmType = MSG_DRM_TYPE_NONE;
-       pAttrib->roWaitingTimerMax = 0;
-       pAttrib->pszDrmData = NULL;
-#endif
        pAttrib->version = MMS_VERSION;
 
        memset(pAttrib->szFrom, 0, MSG_LOCALE_ADDR_LEN + 10);
@@ -1772,9 +1567,10 @@ bool MmsInitMsgAttrib(MmsAttrib *pAttrib)
        return true;
 }
 
-#ifdef __SUPPORT_DRM__
+
 bool MmsInitMsgDRMInfo(MsgDRMInfo *pMsgDrmInfo)
 {
+       MSG_DEBUG("ptr : [%p]", pMsgDrmInfo);
        pMsgDrmInfo->contentType = MIME_UNKNOWN;
        pMsgDrmInfo->drmType = MSG_DRM_TYPE_NONE;
 
@@ -1836,7 +1632,6 @@ void MmsReleaseMsgDRMInfo(MsgDRMInfo *pDrmInfo)
        pDrmInfo->drmType = MSG_DRM_TYPE_NONE;
 }
 
-#endif
 
 bool MmsReleaseMmsAttrib(MmsAttrib *pAttrib)
 {
@@ -1917,15 +1712,14 @@ bool MmsReleaseMsgBody(MsgBody *pBody, int type)
                                pMulti = pMulti->pNext;
 
                                if (pCurrPart) {
-#ifdef __SUPPORT_DRM__
                                        MmsReleaseMsgDRMInfo(&pCurrPart->type.drmInfo);
-#endif
 
                                        if (pCurrPart->pBody) {
-                                               if (pCurrPart->pBody->body.pBinary) {
-                                                       free(pCurrPart->pBody->body.pBinary);
-                                                       pCurrPart->pBody->body.pBinary = NULL;
+                                               if (pCurrPart->pBody->body.pText) {
+                                                       free(pCurrPart->pBody->body.pText);
+                                                       pCurrPart->pBody->body.pText = NULL;
                                                }
+
                                                free(pCurrPart->pBody);
                                                pCurrPart->pBody = NULL;
                                        }
@@ -1952,9 +1746,9 @@ bool MmsReleaseMsgBody(MsgBody *pBody, int type)
 
        default:
                /* Any single part */
-               if (pBody->body.pBinary) {
-                       free(pBody->body.pBinary);
-                       pBody->body.pBinary = NULL;
+               if (pBody->body.pText) {
+                       free(pBody->body.pText);
+                       pBody->body.pText = NULL;
                }
 
                break;
@@ -1972,3 +1766,143 @@ void MmsReleaseMmsMsg(MmsMsg *pMmsMsg)
                bzero(pMmsMsg, sizeof(MmsMsg));
        }
 }
+
+bool MmsPrintMulitpart(MsgMultipart *pMultipart, int index)
+{
+       MSG_DEBUG("------------------------------");
+       MSG_INFO("[%dth] multipart info", index);
+       MSG_INFO("header size [%d], body size [%d]", pMultipart->type.size, pMultipart->type.contentSize);
+       MSG_SEC_INFO("content type [%s]", MmsDebugGetMimeType((MimeType)pMultipart->type.type));
+       MSG_SEC_INFO("content ID [%s]", pMultipart->type.szContentID);
+       MSG_SEC_INFO("content location [%s]", pMultipart->type.szContentLocation);
+       MSG_SEC_INFO("parameter Name [%s]", pMultipart->type.param.szName);
+       MSG_SEC_INFO("parameter Filename[%s]", pMultipart->type.param.szFileName);
+
+       if (pMultipart->type.type == MIME_TEXT_PLAIN) {
+               MSG_SEC_INFO("text info : charset [%d], name [%s]", pMultipart->type.param.charset, pMultipart->type.param.szName);
+       }
+
+       if (pMultipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
+               MSG_INFO("drm info");
+               MSG_INFO("drm type [%d] (0: NONE 1: Fowward Lock, 2:Combined Delivery, 3: Separated Delivery)", pMultipart->type.drmInfo.drmType);
+               MSG_SEC_INFO("drm content type [%s]", MmsDebugGetMimeType((MimeType)pMultipart->type.drmInfo.contentType));
+               MSG_SEC_INFO("drm content URI [%s]", pMultipart->type.drmInfo.szContentURI);
+               MSG_INFO("drm2FullPath [%s]", pMultipart->type.drmInfo.szDrm2FullPath);
+       }
+
+       MSG_DEBUG("------------------------------");
+       return true;
+}
+
+bool MmsIsTextType(int type)
+{
+       if (type == MIME_TEXT_PLAIN
+               || type == MIME_TEXT_HTML
+               || type == MIME_TEXT_VND_WAP_WML
+               || type == MIME_TEXT_X_VNOTE
+               || type == MIME_APPLICATION_SMIL
+               || type == MIME_TEXT_X_IMELODY)
+       {
+               return true;
+       } else {
+               return false;
+       }
+}
+
+bool MmsIsMultipart(int type)
+{
+       if (type == MIME_MULTIPART_RELATED
+               || type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED
+               || type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED
+               || type == MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC
+               || type == MIME_MULTIPART_MIXED
+               || type == MIME_MULTIPART_REPORT) {
+               return true;
+       } else {
+               return false;
+       }
+}
+
+bool MmsIsVitemContent(int type, char *pszName)
+{
+       switch (type) {
+       case MIME_TEXT_X_VCARD:
+       case MIME_TEXT_X_VCALENDAR:
+       case MIME_TEXT_X_VNOTE: // vnt
+       case MIME_TEXT_X_VTODO:
+       case MIME_TEXT_PLAIN:   // vbm - It SHOULD be distinguished from a normal text file.
+       {
+               char *pszExt = NULL;
+
+               if (!pszName)
+                       break;
+
+               // search file extension.
+               if ((pszExt = strrchr(pszName, '.')) == NULL)
+                       break;
+
+               if (!strcasecmp(pszExt, ".vbm")) {
+                       return true;
+               }
+
+               if (!strcasecmp(pszExt, ".vcs")) {
+                       return true;
+               }
+
+               if (!strcasecmp(pszExt, ".vcf")) {
+                       return true;
+               }
+
+               if (!strcasecmp(pszExt, ".vnt")) {
+                       return true;
+               }
+
+               if (!strcasecmp(pszExt, ".vts")) {
+                       return true;
+               }
+
+               break;
+       }
+       default:
+               break;
+       }
+
+       MSG_DEBUG("MmsIsVitemContent false.");
+       return false;
+}
+
+MsgMultipart *MmsAllocMultipart(void)
+{
+       MsgMultipart *pMultipart = NULL;
+
+       pMultipart = (MsgMultipart *)malloc(sizeof(MsgMultipart));
+
+       if (pMultipart == NULL)
+               goto __CATCH;
+
+       pMultipart->pBody = (MsgBody *)malloc(sizeof(MsgBody));
+
+       if (pMultipart->pBody == NULL)
+               goto __CATCH;
+
+       MmsInitMsgType(&pMultipart->type);
+       MmsInitMsgBody(pMultipart->pBody);
+
+       pMultipart->pNext = NULL;
+
+       return pMultipart;
+
+__CATCH:
+
+       if (pMultipart) {
+               if (pMultipart->pBody) {
+                       free(pMultipart->pBody);
+                       pMultipart->pBody = NULL;
+               }
+
+               free(pMultipart);
+               pMultipart = NULL;
+       }
+
+       return NULL;
+}
diff --git a/plugin/mms_plugin/MmsPluginComposer.cpp b/plugin/mms_plugin/MmsPluginComposer.cpp
new file mode 100755 (executable)
index 0000000..f83e94b
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "MsgCppTypes.h"
+#include "MsgStorageTypes.h"
+#include "MsgSettingTypes.h"
+#include "MsgUtilFile.h"
+#include "MsgGconfWrapper.h"
+#include "MsgMmsMessage.h"
+#include "MmsPluginTypes.h"
+#include "MmsPluginDebug.h"
+#include "MmsPluginMessage.h"
+#include "MmsPluginMIME.h"
+#include "MmsPluginStorage.h"
+#include "MmsPluginUtil.h"
+#include "MmsPluginTcs.h"
+#include "MsgSmil.h"
+
+
+#include "MmsPluginComposer.h"
+#include "MsgSerialize.h"
+
+bool composeSendReqHeader(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_DATA_S *pMsgData);
+
+MmsPluginComposer *MmsPluginComposer::pInstance = NULL;
+
+MmsPluginComposer *MmsPluginComposer::instance()
+{
+       if (!MmsPluginComposer::pInstance)
+               MmsPluginComposer::pInstance = new MmsPluginComposer();
+
+       return MmsPluginComposer::pInstance;
+}
+
+MmsPluginComposer::MmsPluginComposer(){}
+MmsPluginComposer::~MmsPluginComposer(){}
+
+void MmsPluginComposer::composeSendReq(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_DATA_S *pMmsData)
+{
+
+       if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
+
+               if (pMmsData->header == NULL) {//send req from user
+                       pMmsData->header = MsgMmsCreateHeader();
+               }
+
+               composeSendReqHeader(pMsgInfo, pSendOptInfo, pMmsData);
+               //TODO:: apply MmsReplaceNonAsciiUtf8 to all multipart FileName;
+
+               int len = g_list_length(pMmsData->multipartlist);
+
+               for (int i = 0; i < len; i++) {
+
+                       MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMmsData->multipartlist, i);
+
+                       if (multipart) {
+                               if (multipart->type == MIME_UNKNOWN && strlen(multipart->szContentType) == 0) {
+                                       const char *content_type = NULL;
+                                       MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, multipart->szFileName, &multipart->type, &content_type);
+                                       snprintf(multipart->szContentType, sizeof(multipart->szContentType), "%s", content_type);
+                               }
+                       }
+               } //end for
+       }
+}
+
+MMSList *getAddressList(const MSG_MESSAGE_INFO_S *pMsgInfo, int recipientType)
+{
+       MSG_BEGIN();
+
+       MMSList * addressList = NULL;
+
+       int nAddressCnt = 0;
+
+       nAddressCnt = pMsgInfo->nAddressCnt;
+
+       // Calculate allocated buffer size
+       for (int i = 0; i < nAddressCnt; ++i) {
+
+               MSG_SEC_DEBUG("recipientType: %d, address value: %s", pMsgInfo->addressList[i].recipientType, pMsgInfo->addressList[i].addressVal);
+
+               if (pMsgInfo->addressList[i].recipientType == MSG_RECIPIENTS_TYPE_UNKNOWN)
+                       pMsgInfo->addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
+
+               if (pMsgInfo->addressList[i].recipientType == recipientType) {
+
+                       MMS_ADDRESS_DATA_S * pAddressData = NULL;
+                       if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_PLMN) {
+                               pAddressData = MsgMmsCreateAddress(MSG_ADDRESS_TYPE_PLMN, pMsgInfo->addressList[i].addressVal);
+                       } else if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_EMAIL) {
+                               pAddressData = MsgMmsCreateAddress(MSG_ADDRESS_TYPE_EMAIL, pMsgInfo->addressList[i].addressVal);
+                       } else
+                               ; // Need to consider IPV4, IPV6, and Alias formatted address
+
+                       if (pAddressData)
+                               addressList = g_list_append(addressList, pAddressData);
+               }
+       }
+
+       MSG_END();
+       return addressList;
+}
+
+bool composeSendReqHeader(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_DATA_S *pMsgData)
+{
+       MSG_BEGIN();
+
+       bool bAskDeliveryReport = false;
+       bool bAskReadReply = false;
+       MmsPriority priority;
+       MmsTimeStruct expiryTime;
+       MmsTimeStruct deliveryTime;
+       MmsMsgClass msgClass;
+
+       struct tm *timeInfo = NULL;
+       time_t RawTime = 0;
+       time_t nTimeInSecs = 0;
+
+       MMS_HEADER_DATA_S *pHeaderData = pMsgData->header;
+       if (pSendOptInfo) {
+               if (pSendOptInfo->bSetting == false) {
+                       unsigned int settingTime;
+
+                       priority = (MmsPriority)MsgSettingGetInt(MMS_SEND_PRIORITY);
+
+                       settingTime = (unsigned int)MsgSettingGetInt(MMS_SEND_EXPIRY_TIME);
+                       if (settingTime == 0) {
+                               expiryTime.type = MMS_TIMETYPE_NONE;
+                               expiryTime.time = 0;
+                       } else {
+                               expiryTime.type = MMS_TIMETYPE_RELATIVE;
+                               expiryTime.time = settingTime;
+                       }
+
+                       settingTime = (unsigned int)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
+                       if (settingTime == 0) {
+                               deliveryTime.type = MMS_TIMETYPE_NONE;
+                               deliveryTime.time = 0;
+                       } else {
+                               deliveryTime.type = MMS_TIMETYPE_RELATIVE;
+                               deliveryTime.time = (unsigned int)settingTime;
+                       }
+
+                       MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &bAskDeliveryReport);
+                       MsgSettingGetBool(MMS_SEND_READ_REPLY, &bAskReadReply);
+               } else {
+                       priority = (MmsPriority)pSendOptInfo->option.mmsSendOptInfo.priority;
+
+                       expiryTime.type = pSendOptInfo->option.mmsSendOptInfo.expiryTime.type;
+                       expiryTime.time = pSendOptInfo->option.mmsSendOptInfo.expiryTime.time;
+
+                       deliveryTime.type = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.type;
+                       deliveryTime.time = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time;
+
+                       bAskDeliveryReport = pSendOptInfo->bDeliverReq;
+                       bAskReadReply = pSendOptInfo->option.mmsSendOptInfo.bReadReq;
+               }
+
+               msgClass = (MmsMsgClass)MsgSettingGetInt(MMS_SEND_MSG_CLASS);
+
+               //set Header
+               time(&RawTime);
+               timeInfo = localtime(&RawTime);
+               nTimeInSecs = mktime(timeInfo);
+               pHeaderData->date = nTimeInSecs;
+
+               pHeaderData->bDeliveryReport = bAskDeliveryReport;
+               pHeaderData->delivery.type = deliveryTime.type;
+               pHeaderData->delivery.time = deliveryTime.time;
+
+               pHeaderData->expiry.type = expiryTime.type;
+               pHeaderData->expiry.time = expiryTime.time;
+
+               pHeaderData->messageClass = msgClass;
+               pHeaderData->messageType = MMS_MSGTYPE_SEND_REQ;
+               pHeaderData->mmsVersion = MMS_VERSION;
+               pHeaderData->mmsPriority = priority;
+               pHeaderData->bReadReport = bAskReadReply;
+               pHeaderData->bHideAddress = false;
+       }
+
+       if (pMsgData->smil) {
+               pHeaderData->contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
+       } else {
+               pHeaderData->contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
+       }
+
+       char *content_type = MimeGetMimeStringFromMimeInt(pHeaderData->contentType);
+       if (content_type) {
+               snprintf(pHeaderData->szContentType, sizeof(pHeaderData->szContentType), "%s", content_type);
+       }
+
+       snprintf(pHeaderData->szSubject, sizeof(pHeaderData->szSubject), "%s", pMsgInfo->subject);
+
+       //setting adddress
+       pHeaderData->to = getAddressList(pMsgInfo, MSG_RECIPIENTS_TYPE_TO);
+       pHeaderData->cc = getAddressList(pMsgInfo, MSG_RECIPIENTS_TYPE_CC);
+       pHeaderData->bcc = getAddressList(pMsgInfo, MSG_RECIPIENTS_TYPE_BCC);
+
+       //snprintf(pHeaderData->szFrom, sizeof(pHeaderData->szFrom), "%s", pMmsMsg->mmsAttrib.szFrom);
+
+       return true;
+}
index 5dac38c..8a9ade5 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
 #include "MmsPluginHttp.h"
 #include <glib.h>
 #include "net_connection.h"
+#include "MmsPluginUtil.h"
 
 #define MMS_CONTEXT_INVOKE_WAIT_TIME   30
-#define MMS_CONNECTION_API_WAIT_TIME   50
-
-#define MMS_FREE(obj)\
-       if (obj){\
-               free(obj);\
-               obj = NULL;\
-       }
-
+#define MMS_CONNECTION_API_WAIT_TIME   420
 
 static Mutex g_mx;
 static CndVar g_cv;
-static connection_h connection = NULL;
+static connection_h g_connection = NULL;
+static connection_profile_h g_profile = NULL;
 
 void __connection_profile_print(connection_profile_h profile)
 {
@@ -61,147 +56,157 @@ void __connection_profile_print(connection_profile_h profile)
 
        MSG_DEBUG("**************************************************************************************************");
        ret = connection_profile_get_id(profile, &profile_id);
-       MSG_DEBUG("Profile Id = [%s]", profile_id);
+       MSG_DEBUG("return value of connection_profile_get_id [%d]", ret);
+       MSG_SEC_INFO("Profile Id = [%s]", profile_id);
 
        ret = connection_profile_get_name(profile, &profile_name);
-       MSG_DEBUG("Profile Name = [%s]", profile_name);
+       MSG_SEC_INFO("Profile Name = [%s]", profile_name);
 
        ret = connection_profile_get_type(profile, &profile_type);
 
        if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
-               MSG_DEBUG("Profile Type = [CELLULAR]");
+               MSG_SEC_INFO("Profile Type = [CELLULAR]");
        } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
-               MSG_DEBUG("Profile Type = [WIFI]");
+               MSG_SEC_INFO("Profile Type = [WIFI]");
        } else if (profile_type == CONNECTION_PROFILE_TYPE_ETHERNET) {
-               MSG_DEBUG("Profile Type = [ETHERNET]");
+               MSG_SEC_INFO("Profile Type = [ETHERNET]");
        } else if (profile_type == CONNECTION_PROFILE_TYPE_BT) {
-               MSG_DEBUG("Profile Type = [BT]");
+               MSG_SEC_INFO("Profile Type = [BT]");
        } else {
-               MSG_DEBUG("Profile Type = Unknown [%d]", profile_type);
+               MSG_SEC_INFO("Profile Type = Unknown [%d]", profile_type);
        }
 
        ret = connection_profile_get_network_interface_name(profile, &interface_name);
-       MSG_DEBUG("Profile Interface Name = [%s]", interface_name);
+       MSG_SEC_INFO("Profile Interface Name = [%s]", interface_name);
 
        ret = connection_profile_get_state(profile, &profile_state);
        if (profile_state == CONNECTION_PROFILE_STATE_DISCONNECTED) {
-               MSG_DEBUG("Profile State = [DISCONNECTED]");
+               MSG_SEC_INFO("Profile State = [DISCONNECTED]");
        } else if (profile_state == CONNECTION_PROFILE_STATE_ASSOCIATION) {
-               MSG_DEBUG("Profile State = [ASSOCIATION]");
+               MSG_SEC_INFO("Profile State = [ASSOCIATION]");
        } else if (profile_state == CONNECTION_PROFILE_STATE_CONFIGURATION) {
-               MSG_DEBUG("Profile State = [CONFIGURATION]");
+               MSG_SEC_INFO("Profile State = [CONFIGURATION]");
        } else if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED) {
-               MSG_DEBUG("Profile State = [CONNECTED]");
+               MSG_SEC_INFO("Profile State = [CONNECTED]");
        } else {
-               MSG_DEBUG("Profile State = Unknown [%d]", profile_state);
+               MSG_SEC_INFO("Profile State = Unknown [%d]", profile_state);
        }
 
        ret = connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type);
-       MSG_DEBUG("Profile Ip Config Type = [%d]", ip_type);
+       MSG_SEC_INFO("Profile Ip Config Type = [%d]", ip_type);
 
        ret = connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_address);
-       MSG_DEBUG("Profile Ip Address = [%s]", ip_address);
+       MSG_SEC_INFO("Profile Ip Address = [%s]", ip_address);
 
        ret = connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet_mask);
-       MSG_DEBUG("Profile Subnet Mask = [%s]", subnet_mask);
+       MSG_SEC_INFO("Profile Subnet Mask = [%s]", subnet_mask);
 
        ret = connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway_address);
-       MSG_DEBUG("Profile Gateway Address = [%s]", gateway_address);
+       MSG_SEC_INFO("Profile Gateway Address = [%s]", gateway_address);
 
        ret = connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns_address);
-       MSG_DEBUG("Profile Dns Address = [%s]", dns_address);
+       MSG_SEC_INFO("Profile Dns Address = [%s]", dns_address);
 
        ret = connection_profile_get_proxy_type(profile, &proxy_type);
-       MSG_DEBUG("Profile Proxy Type = [%d]", proxy_type);
+       MSG_SEC_INFO("Profile Proxy Type = [%d]", proxy_type);
 
        ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
-       MSG_DEBUG("Profile Proxy Address = [%s]", proxy_address);
+       MSG_SEC_INFO("Profile Proxy Address = [%s]", proxy_address);
 
        ret = connection_profile_get_cellular_service_type(profile, &service_type);
        if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) {
-               MSG_DEBUG("Profile Service Type = [INTERNET]");
+               MSG_SEC_INFO("Profile Service Type = [INTERNET]");
        } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) {
-               MSG_DEBUG("Profile Service Type = [MMS]");
+               MSG_SEC_INFO("Profile Service Type = [MMS]");
        } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET) {
-               MSG_DEBUG("Profile Service Type = [PREPAID_INTERNET]");
+               MSG_SEC_INFO("Profile Service Type = [PREPAID_INTERNET]");
        } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS) {
-               MSG_DEBUG("Profile Service Type = [PREPAID_MMS]");
+               MSG_SEC_INFO("Profile Service Type = [PREPAID_MMS]");
        } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING) {
-               MSG_DEBUG("Profile Service Type = [TETHERING]");
+               MSG_SEC_INFO("Profile Service Type = [TETHERING]");
        } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION) {
-               MSG_DEBUG("Profile Service Type = [APPLICATION]");
+               MSG_SEC_INFO("Profile Service Type = [APPLICATION]");
        } else {
-               MSG_DEBUG("Profile Service Type = [Unknown][%d]", service_type);
+               MSG_SEC_INFO("Profile Service Type = [Unknown][%d]", service_type);
        }
 
        ret = connection_profile_get_cellular_apn(profile, &apn);
-       MSG_DEBUG("Profile Apn = [%s]", apn);
+       MSG_SEC_INFO("Profile Apn = [%s]", apn);
 
        ret = connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password);
-       MSG_DEBUG("Profile Auth Type = [%d]", &auth_type);
-       MSG_DEBUG("Profile Auth Name = [%s]", &user_name);
-       MSG_DEBUG("Profile Auth Passward = [%s]", &password);
+       MSG_SEC_INFO("Profile Auth Type = [%d]", &auth_type);
+       MSG_SEC_INFO("Profile Auth Name = [%s]", &user_name);
+       MSG_SEC_INFO("Profile Auth Passward = [%s]", &password);
 
        ret = connection_profile_get_cellular_home_url(profile, &home_url);
-       MSG_DEBUG("Profile Home Url = [%s]", home_url);
+       MSG_SEC_INFO("Profile Home Url = [%s]", home_url);
 
        ret = connection_profile_is_cellular_roaming(profile, &is_roaming);
-       MSG_DEBUG("Profile Roaming = [%d]", is_roaming);
+       MSG_SEC_INFO("Profile Roaming = [%d]", is_roaming);
        MSG_DEBUG("**************************************************************************************************");
 
-       MMS_FREE(profile_id);
-       MMS_FREE(profile_name);
-       MMS_FREE(interface_name);
-       MMS_FREE(ip_address);
-       MMS_FREE(subnet_mask);
-       MMS_FREE(gateway_address);
-       MMS_FREE(dns_address);
-       MMS_FREE(proxy_address);
-       MMS_FREE(apn);
-       MMS_FREE(user_name);
-       MMS_FREE(password);
-       MMS_FREE(home_url);
+       MSG_FREE(profile_id);
+       MSG_FREE(profile_name);
+       MSG_FREE(interface_name);
+       MSG_FREE(ip_address);
+       MSG_FREE(subnet_mask);
+       MSG_FREE(gateway_address);
+       MSG_FREE(dns_address);
+       MSG_FREE(proxy_address);
+       MSG_FREE(apn);
+       MSG_FREE(user_name);
+       MSG_FREE(password);
+       MSG_FREE(home_url);
 }
 
 static void __connection_type_changed_cb(connection_type_e type, void* user_data)
 {
-       MSG_DEBUG("Type changed callback, connection type : %d", type);
+       MSG_INFO("Type changed callback, connection type : %d", type);
 }
 
 static void __connection_ip_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
 {
-       MSG_DEBUG("IP changed callback, IPv4 address : %s, IPv6 address : %s",
+       MSG_INFO("IP changed callback, IPv4 address : %s, IPv6 address : %s",
                        ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
 }
 
 static void __connection_proxy_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
 {
-       MSG_DEBUG("Proxy changed callback, IPv4 address : %s, IPv6 address : %s",
+       MSG_INFO("Proxy changed callback, IPv4 address : %s, IPv6 address : %s",
                        ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
 }
 
 static void __connection_profile_opened_cb(connection_error_e result, void* user_data)
 {
        if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS)
-               MSG_DEBUG("Connection open Succeeded [%d]", result);
+               MSG_INFO("Connection open Succeeded [%d]", result);
        else
-               MSG_DEBUG("Connection open Failed, err : %d", result);
+               MSG_ERR("Connection open Failed, err : %d", result);
 
        MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
 
-       cmAgent->open_callback(result, user_data);
+       cmAgent->connection_profile_open_callback(result, user_data);
 }
 
 static void __connection_profile_closed_cb(connection_error_e result, void* user_data)
 {
        if (result ==  CONNECTION_ERROR_NONE)
-               MSG_DEBUG("Connection close Succeeded");
+               MSG_INFO("Connection close Succeeded");
        else
-               MSG_DEBUG("Connection close Failed, err : %d", result);
+               MSG_ERR("Connection close Failed, err : %d", result);
 
        MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
 
-       cmAgent->close_callback(result, user_data);
+       cmAgent->connection_profile_close_callback(result, user_data);
+}
+
+
+void __connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data)
+{
+       MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
+
+       cmAgent->connection_profile_state_changed_cb(state, user_data);
+
 }
 
 static gboolean __connection_create(void *pVoid)
@@ -211,20 +216,42 @@ static gboolean __connection_create(void *pVoid)
        bool ret = false;
        bool *ret_val = (bool *)pVoid;
 
-       if (connection) {
-               MSG_DEBUG("connection already exist");
+       if (g_connection) {
+               MSG_INFO("connection already exist");
                ret = true;
        } else {
-               int err = connection_create(&connection);
+               int err = connection_create(&g_connection);
 
                if (CONNECTION_ERROR_NONE == err) {
-                       connection_set_type_changed_cb(connection, __connection_type_changed_cb, NULL);
-                       connection_set_ip_address_changed_cb(connection, __connection_ip_changed_cb, NULL);
-                       connection_set_proxy_address_changed_cb(connection, __connection_proxy_changed_cb, NULL);
-                       ret = true;
-                       MSG_DEBUG("Client registration success [%p] ", connection);
+
+                       connection_cellular_state_e cellular_state;
+                       connection_type_e net_state;
+
+                       err = connection_get_cellular_state(g_connection, &cellular_state);
+
+                       err = connection_get_type(g_connection, &net_state);
+
+                       if (cellular_state == CONNECTION_CELLULAR_STATE_AVAILABLE
+                               || cellular_state == CONNECTION_CELLULAR_STATE_CONNECTED) {
+
+                               MSG_INFO("Client registration success [%p], cellular_state [%d], net_state [%d]", g_connection, cellular_state, net_state);
+
+                               err = connection_set_type_changed_cb(g_connection, __connection_type_changed_cb, NULL);
+
+                               err = connection_set_ip_address_changed_cb(g_connection, __connection_ip_changed_cb, NULL);
+
+                               err = connection_set_proxy_address_changed_cb(g_connection, __connection_proxy_changed_cb, NULL);
+
+                               ret = true;
+                       } else {
+
+                               MSG_INFO("Client registration Failed,  cellular state [%d], net_state [%d]", cellular_state, net_state);
+                               connection_destroy(g_connection);
+                               g_connection = NULL;
+                       }
+
                } else {
-                       MSG_DEBUG("Client registration failed %d", err);
+                       MSG_WARN("Client registration failed %d", err);
                }
        }
 
@@ -241,17 +268,18 @@ static gboolean __connection_destroy(void *pVoid)
        MSG_BEGIN();
 
        int rv;
-       int netOpenResult = NET_ERR_NONE;
 
-       if (connection != NULL) {
-               rv = connection_destroy(connection);
-               connection = NULL;
-               MSG_DEBUG("connection destory !!");
+       if (g_connection != NULL) {
+               rv = connection_destroy(g_connection);
+               g_connection = NULL;
+               MSG_INFO("connection destory !!");
        } else {
-               MSG_DEBUG("Cannot connection destroy : Handle is NULL");
+               MSG_ERR("Cannot connection destroy : Handle is NULL");
                rv = CONNECTION_ERROR_INVALID_OPERATION;
        }
 
+       MSG_DEBUG("return value of connection destroy [%d]", rv);
+
        MSG_END();
        return FALSE;
 }
@@ -260,29 +288,37 @@ static gboolean __connection_profile_open(void *pVoid)
 {
        MSG_BEGIN();
 
-       int netOpenResult = NET_ERR_NONE;
+       int netOpenResult = MSG_CM_ERR_NONE;
        int *ret_val = (int *)pVoid;
-
-       connection_profile_h profile;
        int err;
 
-       err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
+       if (g_profile) {
+               MSG_WARN("connection profile Already exist!!, It will destroy");
+               connection_profile_unset_state_changed_cb(g_profile);
+               connection_profile_destroy(g_profile);
+               g_profile = NULL;
+       }
+
+       err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &g_profile);
 
        if (err != CONNECTION_ERROR_NONE) {
-               MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err);
-               netOpenResult = NET_ERR_UNKNOWN;
+               MSG_ERR("connection_get_default_cellular_service_profile Failed!! [%d]", err);
+               netOpenResult = MSG_CM_ERR_UNKNOWN;
        } else {
 
-               if (connection_open_profile(connection, profile, __connection_profile_opened_cb, NULL) != CONNECTION_ERROR_NONE) {
-                       MSG_DEBUG("Connection open Failed!!");
-                       netOpenResult = NET_ERR_UNKNOWN;
+               err = connection_profile_set_state_changed_cb(g_profile, __connection_profile_state_changed_cb, g_profile);
+
+               if (connection_open_profile(g_connection, g_profile, __connection_profile_opened_cb, NULL) != CONNECTION_ERROR_NONE) {
+                       MSG_ERR("Connection open Failed!!");
+                       netOpenResult = MSG_CM_ERR_UNKNOWN;
                }
-       }
 
-       connection_profile_destroy(profile);
+
+       }
 
        if (ret_val) {
                *ret_val = netOpenResult;
+               MSG_DEBUG("[%d]", netOpenResult);
        }
 
        MSG_END();
@@ -294,29 +330,22 @@ static gboolean __connection_profile_close(void *pVoid)
 {
        MSG_BEGIN();
 
-       int netOpenResult = NET_ERR_NONE;
+       int netOpenResult = MSG_CM_ERR_NONE;
 
        int *ret_val = (int *)pVoid;
 
-       connection_profile_h profile;
-       int err;
-
-       err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
-
-       if (err  != CONNECTION_ERROR_NONE) {
-               MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err);
-               netOpenResult = NET_ERR_UNKNOWN;
-       } else {
+       if (g_profile) {
+               connection_profile_unset_state_changed_cb(g_profile);
 
-               if (connection_close_profile(connection, profile, __connection_profile_closed_cb, NULL) != CONNECTION_ERROR_NONE) {
-                       MSG_DEBUG("Connection close Failed!!");
-                       netOpenResult = NET_ERR_UNKNOWN;
+               if (connection_close_profile(g_connection, g_profile, __connection_profile_closed_cb, NULL) != CONNECTION_ERROR_NONE) {
+                       MSG_ERR("Connection close Failed!!");
+                       netOpenResult = MSG_CM_ERR_UNKNOWN;
                }
 
+               connection_profile_destroy(g_profile);
+               g_profile = NULL;
        }
 
-       connection_profile_destroy(profile);
-
        if (ret_val) {
                *ret_val = netOpenResult;
        }
@@ -331,7 +360,7 @@ void context_invoke_end_cb(gpointer data)
 {
        g_mx.lock();
 
-       MSG_DEBUG("@@ SIGNAL @@");
+       MSG_INFO("@@ SIGNAL @@");
 
        g_cv.signal();
 
@@ -349,17 +378,18 @@ void context_invoke(GSourceFunc func, void *ret)
 
        g_mx.lock();
 
-       g_main_context_invoke_full(NULL, G_PRIORITY_HIGH, func, ret,  context_invoke_end_cb);
+       g_main_context_invoke_full(NULL, G_PRIORITY_DEFAULT, func, ret,  context_invoke_end_cb);
 
-       MSG_DEBUG("@@ WAIT @@");
+       MSG_INFO("@@ WAIT @@");
 
        time_ret = g_cv.timedwait(g_mx.pMutex(), MMS_CONTEXT_INVOKE_WAIT_TIME);
+
        g_mx.unlock();
 
        if (time_ret == ETIMEDOUT) {
-               MSG_DEBUG("@@ WAKE by timeout@@");
+               MSG_INFO("@@ WAKE by timeout@@");
        } else {
-               MSG_DEBUG("@@ WAKE by signal@@");
+               MSG_INFO("@@ WAKE by signal@@");
        }
 
        MSG_END();
@@ -381,8 +411,6 @@ MmsPluginCmAgent::MmsPluginCmAgent()
 
        isCmOpened = false;
 
-       isCmRegistered = false;
-
        home_url = NULL;
        interface_name = NULL;
        proxy_address = NULL;
@@ -391,64 +419,69 @@ MmsPluginCmAgent::MmsPluginCmAgent()
 
 MmsPluginCmAgent::~MmsPluginCmAgent()
 {
-       MMS_FREE(home_url);
-       MMS_FREE(interface_name);
-       MMS_FREE(proxy_address);
+       MSG_FREE(home_url);
+       MSG_FREE(interface_name);
+       MSG_FREE(proxy_address);
 }
 
 bool MmsPluginCmAgent::open()
 {
        MSG_BEGIN();
 
-       int netOpenResult = NET_ERR_NONE;
-
+       int netOpenResult = MSG_CM_ERR_NONE;
+       int bConnection = false;
+       int time_ret = 0;
        lock();
 
-       if (isCmOpened == false) {
-
-               isCmRegistered = false;
-
-               context_invoke(__connection_create, &isCmRegistered);
-
-               if (isCmRegistered == true) {
+       //create connection
+       context_invoke(__connection_create, &bConnection);
 
-                       MSG_DEBUG("net_open_connection for MMS");
-
-                       context_invoke(__connection_profile_open, &netOpenResult);
-
-                       if (netOpenResult == NET_ERR_NONE) {
-
-                               MSG_DEBUG("## WAITING UNTIL Network Connection Open. ##");
+       if (bConnection == false || g_connection == NULL) {
+               MSG_ERR("Failed __connection_create");
+               goto __ERR_RETURN;
+       }
 
-                               int time_ret = 0;
+       if (g_profile) {
+               MSG_WARN("connection profile already exist");
+               //TODO:: get data;
+               //goto __RETURN;
+       }
 
-                               time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); // isCmOpened will changed by processCBdatas
+       waitProfileOpen = true;
 
-                               MSG_DEBUG("## WAKE ##");
+       context_invoke(__connection_profile_open, &netOpenResult);
 
-                               if (time_ret == ETIMEDOUT) {
-                                       MSG_DEBUG("Network Connection Open Time Out.");
-                               }
+       if (netOpenResult != MSG_CM_ERR_NONE) {
+               MSG_ERR("Failed __connection_profile_open. [%d]", netOpenResult);
+               goto __ERR_RETURN;
+       }
 
-                               if(!isCmOpened) {
-                                       MSG_DEBUG("Network Connection Open Failed");
-                               }
+       MSG_INFO("## WAITING UNTIL __connection_profile_state CONNECT. ##");
 
-                       } else { //error
-                               MSG_FATAL("Error!! net_open_connection_with_profile() failed. [%d]", netOpenResult);
-                       }
+//     cv.wait(mx.pMutex());
+//     MSG_INFO("## WAKE by SIGNAL ##");
 
-                       if (isCmOpened == false) {
-                               context_invoke( __connection_destroy, NULL);
-                       }
+       time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); // isCmOpened will changed by processCBdatas
 
-               } else {
-                       MSG_FATAL("## Failed network callback registration ##");
-               }
+       if (time_ret == ETIMEDOUT) {
+               MSG_WARN("## WAKE by timeout ##");
        } else {
-               MSG_DEBUG("Network is already opened.");
+               MSG_INFO("## WAKE by SIGNAL ##");
+       }
+
+       if(isCmOpened == false) {
+               MSG_WARN("");
+               goto __ERR_RETURN;
        }
 
+//__RETURN:
+       unlock();
+       MSG_END();
+       return isCmOpened;
+
+__ERR_RETURN:
+       context_invoke(__connection_profile_close, NULL);
+       context_invoke( __connection_destroy, NULL);
        unlock();
        MSG_END();
        return isCmOpened;
@@ -461,102 +494,215 @@ void MmsPluginCmAgent::close()
 
        lock();
 
-       if (isCmOpened) {
-               int netOpenResult = NET_ERR_NONE;
-
-               context_invoke(__connection_profile_close, &netOpenResult);
-
-               if (netOpenResult == NET_ERR_NONE) {
+       int netOpenResult = MSG_CM_ERR_NONE;
+       int time_ret = 0;
 
-                       MSG_DEBUG("## WAITING UNTIL Network Connection Close. ##");
+       isCmOpened = false;
 
-                       int time_ret = 0;
+       if (g_profile == NULL) {
+               MSG_INFO("connection profile is NULL");
+               goto __RETURN;
+       }
 
-                       time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME);
+       context_invoke(__connection_profile_close, &netOpenResult);
 
-                       MSG_DEBUG("## WAKE ##");
+       if (netOpenResult != MSG_CM_ERR_NONE) {
+               MSG_ERR("Failed __connection_profile_close. [%d]", netOpenResult);
+               goto __RETURN;
+       }
 
-                       if (time_ret == ETIMEDOUT) {
-                               MSG_DEBUG("Network Connection Close Timed Out.");
-                       }
+       MSG_INFO("## WAITING UNTIL connection_profile_close_callback ##");
 
-               } else {
-                       MSG_DEBUG("Error!! net_close_connection() failed");
-               }
+       time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME);
 
-               isCmOpened = false;
+       if (time_ret == ETIMEDOUT) {
+               MSG_WARN("## WAKE by timeout ##");
        } else {
-               MSG_DEBUG ("Network Connection is not opened.");
+               MSG_INFO("## WAKE by SIGNAL ##");
        }
 
-       if (isCmRegistered == true) {
+
+__RETURN:
+       if (g_connection)
                context_invoke(__connection_destroy, NULL);
-               isCmRegistered = false;
-       }
+
+       g_profile = NULL;
+       g_connection = NULL;
+
+       MSG_FREE(this->home_url);
+       MSG_FREE(this->interface_name);
+       MSG_FREE(this->proxy_address);
 
        unlock();
 
        MSG_END();
 }
 
-void MmsPluginCmAgent::open_callback(connection_error_e result, void* user_data)
+//profile open callback
+void MmsPluginCmAgent::connection_profile_open_callback(connection_error_e result, void* user_data)
 {
        lock();
 
-       connection_profile_h profile;
        connection_cellular_state_e state;
+       connection_profile_h profile = NULL;
+       connection_profile_state_e  profile_state;
        int err;
 
        if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS) {
 
-               err = connection_get_cellular_state(connection, &state);
+               err = connection_get_cellular_state(g_connection, &state);
 
                MSG_DEBUG("connection_get_cellular_state ret [%d], state [%d]", err, state);
 
-               err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
-               if (err != CONNECTION_ERROR_NONE) {
-                       MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err);
+               err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
+               if (err != CONNECTION_ERROR_NONE || profile == NULL) {
+
+                       MSG_ERR("Failed connection_get_default_cellular_service_profile. err [%d], profile [%p]", err, profile);
+                       goto __SIGNAL_RETURN;
                }
 
-               if (profile) {
-                       isCmOpened = true;
+               err = connection_profile_get_state(profile, &profile_state);
+
+               MSG_DEBUG("profile state [%d]", profile_state);
+
+               if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED && waitProfileOpen == true) {
 
-                       MMS_FREE(this->home_url);
-                       MMS_FREE(this->interface_name);
-                       MMS_FREE(this->proxy_address);
+                       __connection_profile_print(profile);
+
+                       MSG_FREE(this->home_url);
+                       MSG_FREE(this->interface_name);
+                       MSG_FREE(this->proxy_address);
 
                        err = connection_profile_get_cellular_home_url(profile, &this->home_url);
+                       if (err != CONNECTION_ERROR_NONE) {
+                               MSG_ERR("Failed connection_profile_get_cellular_home_url");
+                       }
+
                        err = connection_profile_get_network_interface_name(profile, &this->interface_name);
+                       if (err != CONNECTION_ERROR_NONE) {
+                               MSG_ERR("Failed connection_profile_get_cellular_home_url");
+                       }
+
                        err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
+                       if (err != CONNECTION_ERROR_NONE) {
+                               MSG_ERR("Failed connection_profile_get_cellular_home_url");
+                       }
 
-                       __connection_profile_print(profile);
+                       isCmOpened = true;
+
+                       goto __SIGNAL_RETURN; //open success
 
-                       connection_profile_destroy(profile);
+               } else {
+                       goto __NO_SIGNAL_RETURN; //Just open success
                }
 
        } else {
-               MSG_DEBUG("connection open profile Failed!! [%d]", result);
+               MSG_ERR("connection open profile Failed!! [%d]", result);
+               isCmOpened = false;
+               goto __SIGNAL_RETURN;
+
+       }
+
+__NO_SIGNAL_RETURN: //Just Open
+       if (profile)
+               connection_profile_destroy(profile);
+       unlock();
+       return;
+
+__SIGNAL_RETURN: //Error or Already connected
+       if (profile)
+               connection_profile_destroy(profile);
+
+       if (waitProfileOpen == true) {//open fail
+               waitProfileOpen = false;
+               MSG_INFO("## SIGNAL ##");
+               signal();
        }
+       unlock();
+       return;
+}
 
-       MSG_DEBUG("## SIGNAL ##");
+
+void MmsPluginCmAgent::connection_profile_close_callback(connection_error_e result, void* user_data)
+{
+       lock();
+       MSG_INFO("result [%d]", result);
+       MSG_INFO("## SIGNAL ##");
        signal();
 
        unlock();
 }
 
-void MmsPluginCmAgent::close_callback(connection_error_e result, void* user_data)
+void MmsPluginCmAgent::connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data)
 {
+       MSG_BEGIN();
+
        lock();
 
-       MMS_FREE(this->home_url);
-       MMS_FREE(this->interface_name);
-       MMS_FREE(this->proxy_address);
+       int err;
+       connection_profile_h profile = NULL;
 
-       isCmOpened = false;
-       MSG_DEBUG("## SIGNAL ##");
-       signal();
+       MSG_INFO("state [%d]", state);
+
+       if (state != CONNECTION_PROFILE_STATE_CONNECTED) {
+               isCmOpened = false;
+               goto __NO_SIGNAL_RETURN;
+       }
+
+       if (isCmOpened == true) {
+               MSG_INFO("already opened");
+               goto __SIGNAL_RETURN;
+       }
+
+       /* Should get profile to get latest profile info*/
+       err = connection_get_default_cellular_service_profile(g_connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
+       if (err != CONNECTION_ERROR_NONE || profile == NULL) {
+
+               MSG_ERR("Failed connection_get_default_cellular_service_profile. err [%d], profile [%p]", err, profile);
+               goto __SIGNAL_RETURN;
+       }
+
+       if (state == CONNECTION_PROFILE_STATE_CONNECTED ) {
+               __connection_profile_print(profile);
 
+               MSG_FREE(this->home_url);
+               MSG_FREE(this->interface_name);
+               MSG_FREE(this->proxy_address);
+
+               err = connection_profile_get_cellular_home_url(profile, &this->home_url);
+               if (err != CONNECTION_ERROR_NONE) {
+                       MSG_ERR("Failed connection_profile_get_cellular_home_url");
+               }
+
+               err = connection_profile_get_network_interface_name(profile, &this->interface_name);
+               if (err != CONNECTION_ERROR_NONE) {
+                       MSG_ERR("Failed connection_profile_get_cellular_home_url");
+               }
+
+               err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
+               if (err != CONNECTION_ERROR_NONE) {
+                       MSG_ERR("Failed connection_profile_get_cellular_home_url");
+               }
+
+               isCmOpened = true;
+               goto __SIGNAL_RETURN;
+       }
+
+__NO_SIGNAL_RETURN://Default
+       unlock();
+       return;
+
+__SIGNAL_RETURN: //Error or connected
+       if (profile)
+               connection_profile_destroy(profile);
+
+       if (waitProfileOpen == true) {
+               waitProfileOpen = false;
+               MSG_INFO("## SIGNAL ##");
+               signal();
+       }
        unlock();
+       return;
 }
 
 bool MmsPluginCmAgent::getInterfaceName(const char **deviceName)
index b7851f9..cf6e5a6 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -21,6 +21,8 @@
 #include <errno.h>
 
 #include "MsgUtilFile.h"
+#include "MsgSmil.h"
+#include "MsgMmsMessage.h"
 
 #include "MmsPluginDebug.h"
 #include "MmsPluginDecode.h"
 #include "MmsPluginStorage.h"
 #include "MmsPluginDebug.h"
 #include "MmsPluginMIME.h"
-#include "MmsPluginAvCodec.h"
-#include "MmsPluginSmil.h"
 #include "MmsPluginTextConvert.h"
 #include "MmsPluginUtil.h"
 
-#ifdef __SUPPORT_DRM__
 #include "MmsPluginDrm.h"
 #include "MsgDrmWrapper.h"
-#endif
-
 
 /*Decode wsp*/
 static int __MmsGetDecodeOffset(void);
@@ -75,9 +72,6 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
 
 static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int totalLength);
 
-#ifdef __SUPPORT_DRM__
-static bool __MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int bodyLength, int totalLength);
-#endif
 
 //util funcion
 static void __MsgRemoveFilePath(char *pSrc);
@@ -93,14 +87,12 @@ static char *__MsgGetStringUntilDelimiter(char *pszString, char delimiter);
 static bool __MsgParseParameter(MsgType *pType, char *pSrc);
 static char *__MsgSkipWS(char *s);
 static char *__MsgSkipComment(char *s, long trim);
-static MsgMultipart *__MsgAllocMultipart(void);
 
 static char *__MsgConvertLatin2UTF8FileName(char *pSrc);
-static bool __MsgIsUTF8String(unsigned char *szSrc, int nChar);
-static bool __MsgIsPercentSign(char *pSrc);
+
+//static bool __MsgIsPercentSign(char *pSrc);
 static bool __MsgIsMultipartRelated(int type);
 static bool __MsgIsPresentablePart(int type);
-static bool __MsgIsText(int type);
 static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody);
 static bool __MsgIsHexChar(char *pSrc);
 static char __MsgConvertHexValue(char *pSrc);
@@ -112,14 +104,7 @@ static bool __MsgIsMultipartMixed(int type);
 static bool __MsgIsInvalidFileNameChar(char ch);
 
 static int __MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar);
-static int __MsgLatin5code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
-static int __MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar);
 static int __MsgLatin2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
-static int __MsgLatin7code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
-static int __MsgGetLatin72UTFCodeSize(unsigned char *szSrc, int nChar);
-static int __MsgUnicode2UTF(unsigned char *des, int outBufSize, unsigned short *szSrc, int nChar);
-static int __MsgGetUnicode2UTFCodeSize(unsigned short *szSrc, int nChar);
-static bool __MmsAddrUtilCheckEmailAddress(char *pszAddr);
 static int __MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar);
 static void __MsgMIMERemoveQuote(char *szSrc);
 static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody, char *pszMailboxPath, char *pszMsgFilename, int index, bool bSave);
@@ -127,32 +112,23 @@ static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody,
 static bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE *pFile);
 static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue, int msgTypeValue, int msgCharsetValue, int *npRead);
 
-#ifndef        __SUPPORT_DRM__
-static bool __MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex);
-#else
 static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex, char *outBuf, int outBufLen);
-#endif
 
-static bool __MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index);
 
-static char gszMmsLoadBuf1[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
-static char gszMmsLoadBuf2[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
+__thread char gszMmsLoadBuf1[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
+__thread char gszMmsLoadBuf2[MSG_MMS_DECODE_BUFFER_MAX + 1] = {0, };
 
-static char *gpCurMmsDecodeBuff = NULL;
-static int gCurMmsDecodeBuffPos = 0;   /* next decoding position in gpCurMmsDecodeBuff  */
-static int gMmsDecodeMaxLen = 0;
-static int gMmsDecodeCurOffset = 0;    /* current offset in file (last read) */
-static int gMmsDecodeBufLen = 0;               /* number of last read characters */
+__thread char *gpCurMmsDecodeBuff = NULL;
+__thread int gCurMmsDecodeBuffPos = 0; /* next decoding position in gpCurMmsDecodeBuff  */
+__thread int gMmsDecodeMaxLen = 0;
+__thread int gMmsDecodeCurOffset = 0;  /* current offset in file (last read) */
+__thread int gMmsDecodeBufLen = 0;             /* number of last read characters */
 
-static char *gpMmsDecodeBuf1 = NULL;
-static char *gpMmsDecodeBuf2 = NULL;
+__thread char *gpMmsDecodeBuf1 = NULL;
+__thread char *gpMmsDecodeBuf2 = NULL;
 
-__thread MmsHeader     mmsHeader =
+__thread MmsHeader mmsHeader =
 {
-       false,                                                                  //bActive
-       NULL,                                                                   //pszOwner
-       -1,                                                                             //msgID
-
        (MmsMsgType)MMS_MSGTYPE_ERROR,                  //MmsMsgType                    iType;
        "",                                                                             //char[]                                szTrID;
        //"",                                                                           //short int                             version;
@@ -200,13 +176,10 @@ __thread MmsHeader        mmsHeader =
        0,                                                                              //UINT32                                msgSize;
 };
 
-#ifdef __SUPPORT_DRM__
-
 #define        MMS_DRM2_CONVERT_BUFFER_MAX     4*1024
 const UINT32 MMS_UINTVAR_LENGTH_1 =  0x0000007f;               //7bit
 const UINT32 MMS_UINTVAR_LENGTH_2 =  0x00003fff;               //14bit
 const UINT32 MMS_UINTVAR_LENGTH_3 =  0x001fffff;               //21bit
-#endif
 
 static bool __MmsDecodeInitialize(void)
 {
@@ -266,9 +239,7 @@ void MmsInitHeader()
 
        memset(mmsHeader.szMsgID, 0, MMS_MSG_ID_LEN + 1);
        mmsHeader.msgSize = 0;
-#ifdef __SUPPORT_DRM__
        mmsHeader.drmType = MSG_DRM_TYPE_NONE;
-#endif
 
        __MmsDecodeInitialize();
 }
@@ -414,58 +385,58 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                switch (MmsGetBinaryType(MmsCodeFieldCode, fieldCode)) {
                case MMS_CODE_RESPONSESTATUS:
+               {
+                       MmsResponseStatus resposeStatus = MMS_RESPSTATUS_ERROR;
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
                                MSG_DEBUG("responseStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
+                       fieldValue = oneByte;
+
                        // range 197 to 223 as it does to the value 192 (Error-transient-failure).
                        // range 236 to 255 as it does to the value 224 (Error-permanent-failure).
-                       if (fieldValue >= 0x0045 && fieldValue <= 0x005F) {
-                               fieldValue = 0x0040;
-                       } else if (fieldValue >= 0x006A && fieldValue <= 0x007F) {
-                               fieldValue = 0x0060;
+                       if (fieldValue >= 197 && fieldValue <= 223) {
+                               fieldValue = 192;
+                       } else if (fieldValue >= 236 && fieldValue <= 255) {
+                               fieldValue = 224;
                        }
 
-                       fieldValue = MmsGetBinaryType(MmsCodeResponseStatus, (UINT16)(oneByte & 0x7F));
-
-                       if (fieldValue == 0xFFFF) {
-                               MSG_DEBUG("responseStatus error");
-                               goto __CATCH;
-                       }
+                       resposeStatus = (MmsResponseStatus)MmsGetBinaryType(MmsCodeResponseStatus, (UINT16)(fieldValue & 0x7F));
 
-                       mmsHeader.responseStatus = (MmsResponseStatus)fieldValue;
+                       mmsHeader.responseStatus = (MmsResponseStatus)resposeStatus;
 
-                       MSG_DEBUG("X-Mms-Response-Status = [0x%02x][%s]", oneByte, MmsDebugGetResponseStatus(mmsHeader.responseStatus));
+                       MSG_SEC_INFO("X-Mms-Response-Status = [0x%02x][0x%02x][%s]", oneByte, fieldValue, MmsDebugGetResponseStatus(mmsHeader.responseStatus));
                        break;
-
+               }
                case MMS_CODE_RETRIEVESTATUS:
+               {
+                       MmsRetrieveStatus RetrieveStatus = MMS_RETRSTATUS_ERROR;
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
                                MSG_DEBUG("retrieveStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
-                       fieldValue = MmsGetBinaryType(MmsCodeRetrieveStatus, (UINT16)(oneByte & 0x7F));
+                       fieldValue = oneByte;
 
-                       if (fieldValue == 0xFFFF) {
-                               MSG_DEBUG("retrieveStatus error");
-                               goto __CATCH;
+                       //195 to 223 as it does to the value 192 (Error-transient-failure).
+                       //228 to 255 as it does to the value 224 (Error-permanent-failure).
+                       if (fieldValue >= 195 && fieldValue <= 223) {
+                               fieldValue = 192; // 192; Error-transient-failure
+                       } else if (fieldValue >= 228 && fieldValue <= 255) {
+                               fieldValue = 224; //224; Error-permanent-failure
                        }
 
-                       if (fieldValue >= 0x0043 && fieldValue <= 0x005F) {
-                               fieldValue = 0x0040; // 192; Error-transient-failure
-                       } else if (fieldValue >= 0x0064 && fieldValue <= 0x007F) {
-                               fieldValue = 0x0060; //224; Error-permanent-failure
-                       }
+                       RetrieveStatus = (MmsRetrieveStatus)MmsGetBinaryType(MmsCodeRetrieveStatus, (UINT16)(fieldValue & 0x7F));
 
-                       mmsHeader.retrieveStatus = (MmsRetrieveStatus)fieldValue;
+                       mmsHeader.retrieveStatus = (MmsRetrieveStatus)RetrieveStatus;
 
-                       MSG_DEBUG("X-Mms-Retrieve-Status = [0x%02x][%s]", oneByte, MmsDebugGetRetrieveStatus(mmsHeader.retrieveStatus));
+                       MSG_SEC_INFO("X-Mms-Retrieve-Status = [0x%02x][0x%02x][%s]", oneByte, fieldValue, MmsDebugGetRetrieveStatus(mmsHeader.retrieveStatus));
 
                        break;
-
+               }
                case MMS_CODE_RESPONSETEXT:
 
                        if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szResponseText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
@@ -473,7 +444,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("X-Mms-Response-Text = [%s]", mmsHeader.szResponseText);
+                       MSG_SEC_INFO("X-Mms-Response-Text = [%s]", mmsHeader.szResponseText);
                        break;
 
                case MMS_CODE_RETRIEVETEXT:
@@ -483,7 +454,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("X-Mms-Retrieve-Text = [%s]", mmsHeader.szRetrieveText);
+                       MSG_SEC_INFO("X-Mms-Retrieve-Text = [%s]", mmsHeader.szRetrieveText);
                        break;
 
                case MMS_CODE_MSGID:
@@ -493,9 +464,9 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("Message-ID =[%s]", mmsHeader.szMsgID);
+                       MSG_SEC_INFO("Message-ID =[%s]", mmsHeader.szMsgID);
 
-                       if (MsgStrlen (mmsHeader.szMsgID) > 2)
+                       if (strlen(mmsHeader.szMsgID) > 2)
                                __MsgMIMERemoveQuote (mmsHeader.szMsgID);
 
                        break;
@@ -530,7 +501,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                pLimitData = NULL;
                        }
 
-                       MSG_DEBUG("Subject = [%s]", mmsHeader.szSubject);
+                       MSG_SEC_INFO("Subject = [%s]", mmsHeader.szSubject);
                        break;
 
                case MMS_CODE_FROM:
@@ -574,14 +545,14 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                        mmsHeader.pFrom->pNext = NULL;
                                }
 
-                               MSG_DEBUG("From = [%s]", mmsHeader.pFrom->szAddr);
+                               MSG_SEC_INFO("From = [%s]", mmsHeader.pFrom->szAddr);
                                // DRM_TEMPLATE - end
                        } else if (oneByte == (MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN)|0x80)) {
                                /* Present Token only */
-                               MSG_DEBUG("From = [insert token]");
+                               MSG_SEC_INFO("From = [insert token]");
                        } else {
                                /* from data broken */
-                               MSG_DEBUG("from addr broken");
+                               MSG_WARN("from addr broken");
                                gCurMmsDecodeBuffPos--;
                                goto __CATCH;
                        }
@@ -604,7 +575,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                pLastTo = pAddr;
                        }
 
-                       MSG_DEBUG("To = [%s]", mmsHeader.pTo->szAddr);
+                       MSG_SEC_INFO("To = [%s]", pAddr->szAddr);
                        break;
 
                case MMS_CODE_BCC:
@@ -624,7 +595,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                pLastBcc = pAddr;
                        }
 
-                       MSG_DEBUG("Bcc = [%s]", mmsHeader.pBcc->szAddr);
+                       MSG_SEC_INFO("Bcc = [%s]", pAddr->szAddr);
                        break;
 
                case MMS_CODE_CC:
@@ -643,7 +614,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                        pLastCc->pNext = pAddr;
                                pLastCc = pAddr;
                        }
-                       MSG_DEBUG("Cc = [%s]", mmsHeader.pCc->szAddr);
+                       MSG_SEC_INFO("Cc = [%s]", pAddr->szAddr);
                        break;
 
                case MMS_CODE_CONTENTLOCATION:
@@ -652,7 +623,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                MSG_DEBUG("MMS_CODE_CONTENTLOCATION is invalid");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("X-Mms-Content-Location = [%s]", mmsHeader.szContentLocation);
+                       MSG_SEC_DEBUG("X-Mms-Content-Location = [%s]", mmsHeader.szContentLocation);
                        break;
 
                case MMS_CODE_DATE:
@@ -662,7 +633,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("Date = [%u]", mmsHeader.date);
+                       MSG_SEC_INFO("Date = [%u]", mmsHeader.date);
                        break;
 
                case MMS_CODE_DELIVERYREPORT:
@@ -681,7 +652,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                        mmsHeader.deliveryReport = (MmsReport)fieldValue;
 
-                       MSG_DEBUG("X-Mms-Delivery-Report =[0x%02x][%s]", oneByte, MmsDebugGetMmsReport(mmsHeader.deliveryReport));
+                       MSG_SEC_INFO("X-Mms-Delivery-Report =[0x%02x][%s]", oneByte, MmsDebugGetMmsReport(mmsHeader.deliveryReport));
                        break;
 
                case MMS_CODE_DELIVERYTIME:
@@ -719,7 +690,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                        goto __CATCH;
                                }
                        }
-                       MSG_DEBUG("X-Mms-Delivery-Time : type = [%d], time= [%u]", mmsHeader.deliveryTime.type, mmsHeader.deliveryTime.time);
+                       MSG_SEC_INFO("X-Mms-Delivery-Time : type = [%d], time= [%u]", mmsHeader.deliveryTime.type, mmsHeader.deliveryTime.time);
                        break;
 
                case MMS_CODE_EXPIRYTIME:
@@ -753,7 +724,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                mmsHeader.expiryTime.type = MMS_TIMETYPE_RELATIVE;
 
                                if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, &tmpIntLen, totalLength) == false) {
-                                       MSG_DEBUG("__MmsBinaryDecodeInteger fail...");
+                                       MSG_INFO("__MmsBinaryDecodeInteger fail...");
                                        goto __CATCH;
                                }
                        }
@@ -780,7 +751,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                }
                        }
 
-                       MSG_DEBUG("X-Mms-Message-Class =[%s]", MmsDebugGetMsgClass(mmsHeader.msgClass));
+                       MSG_SEC_INFO("X-Mms-Message-Class =[%s]", MmsDebugGetMsgClass(mmsHeader.msgClass));
                        break;
 
                case MMS_CODE_MSGSIZE:
@@ -790,7 +761,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("X-Mms-Message-Size = [%d]", mmsHeader.msgSize);
+                       MSG_SEC_INFO("X-Mms-Message-Size = [%d]", mmsHeader.msgSize);
                        break;
 
                case MMS_CODE_MSGSTATUS:
@@ -801,7 +772,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        }
 
                        mmsHeader.msgStatus =  (msg_delivery_report_status_t)MmsGetBinaryType(MmsCodeMsgStatus, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Status = [%s]", MmsDebugGetMsgStatus(mmsHeader.msgStatus));
+                       MSG_SEC_INFO("X-Mms-Status = [%s]", MmsDebugGetMsgStatus(mmsHeader.msgStatus));
                        break;
 
                case MMS_CODE_MSGTYPE:
@@ -812,7 +783,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        }
 
                        mmsHeader.type = (MmsMsgType)MmsGetBinaryType(MmsCodeMsgType, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Message-Type = [%s]", MmsDebugGetMsgType(mmsHeader.type));
+                       MSG_SEC_INFO("X-Mms-Message-Type = [%s]", MmsDebugGetMsgType(mmsHeader.type));
                        break;
 
                case MMS_CODE_PRIORITY:
@@ -822,7 +793,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
                        mmsHeader.priority = (MmsPriority)MmsGetBinaryType(MmsCodePriority, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Priority = [%d]", mmsHeader.priority);
+                       MSG_SEC_INFO("X-Mms-Priority = [%d]", mmsHeader.priority);
                        break;
 
                case MMS_CODE_READREPLY:
@@ -832,7 +803,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
                        mmsHeader.readReply = (MmsReport)MmsGetBinaryType(MmsCodeReadReply, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Read-Report = [0x%02x][%s]", oneByte, MmsDebugGetMmsReport(mmsHeader.readReply));
+                       MSG_SEC_INFO("X-Mms-Read-Report = [0x%02x][%s]", oneByte, MmsDebugGetMmsReport(mmsHeader.readReply));
                        break;
 
                case MMS_CODE_REPORTALLOWED:
@@ -842,7 +813,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
                        mmsHeader.reportAllowed =  (MmsReportAllowed)MmsGetBinaryType(MmsCodeReportAllowed, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Report-Allowed = [%d]", MmsDebugGetMmsReportAllowed(mmsHeader.reportAllowed));
+                       MSG_SEC_INFO("X-Mms-Report-Allowed = [%d]", MmsDebugGetMmsReportAllowed(mmsHeader.reportAllowed));
                        break;
 
                case MMS_CODE_SENDERVISIBILLITY:
@@ -852,7 +823,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                goto __CATCH;
                        }
                        mmsHeader.hideAddress= (MmsSenderVisible)!(MmsGetBinaryType(MmsCodeSenderVisibility, (UINT16)(oneByte &0x7F)));
-                       MSG_DEBUG("X-Mms-Sender-Visibility = [%d]", mmsHeader.hideAddress);
+                       MSG_SEC_INFO("X-Mms-Sender-Visibility = [%d]", mmsHeader.hideAddress);
                        break;
 
                case MMS_CODE_TRID:
@@ -861,7 +832,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                MSG_DEBUG("Transaction ID Too Long");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("X-Mms-Transaction-Id = [%s]", mmsHeader.szTrID);
+                       MSG_SEC_INFO("X-Mms-Transaction-Id = [%s]", mmsHeader.szTrID);
                        break;
 
                case MMS_CODE_VERSION:
@@ -871,7 +842,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        }
                        mmsHeader.version = oneByte;
 
-                       MSG_DEBUG("X-Mms-MMS-Version = [0x%02x]", mmsHeader.version);
+                       MSG_SEC_INFO("X-Mms-MMS-Version = [0x%02x]", mmsHeader.version);
                        break;
 
                case MMS_CODE_CONTENTTYPE:
@@ -896,7 +867,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        }
 
                        mmsHeader.readStatus =  (msg_read_report_status_t)MmsGetBinaryType(MmsCodeReadStatus, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Read-Status = [%s]", MmsDebugGetMmsReadStatus(mmsHeader.readStatus));
+                       MSG_SEC_INFO("X-Mms-Read-Status = [%s]", MmsDebugGetMmsReadStatus(mmsHeader.readStatus));
                        break;
 
                case MMS_CODE_REPLYCHARGING:
@@ -909,7 +880,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        }
 
                        mmsHeader.replyCharge.chargeType =  (MmsReplyChargeType)MmsGetBinaryType(MmsCodeReplyCharging, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("X-Mms-Reply-Charging = [%d]", mmsHeader.replyCharge.chargeType);
+                       MSG_SEC_INFO("X-Mms-Reply-Charging = [%d]", mmsHeader.replyCharge.chargeType);
                        break;
 
                case MMS_CODE_REPLYCHARGINGDEADLINE:
@@ -942,7 +913,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                }
                        }
 
-                       MSG_DEBUG("X-Mms-Reply-Charging-Deadline : type = [%d], time = [%u]", mmsHeader.replyCharge.deadLine.type, mmsHeader.replyCharge.deadLine.time);
+                       MSG_SEC_INFO("X-Mms-Reply-Charging-Deadline : type = [%d], time = [%u]", mmsHeader.replyCharge.deadLine.type, mmsHeader.replyCharge.deadLine.time);
                        // DRM_TEMPLATE - end
                        break;
 
@@ -953,7 +924,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                MSG_DEBUG("1. __MmsBinaryDecodeText fail. (szReplyChargingID)");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("X-Mms-Reply-Charging-ID = [%s]", mmsHeader.replyCharge.szChargeID);
+                       SECURE_SLOGD("X-Mms-Reply-Charging-ID = [%s]", mmsHeader.replyCharge.szChargeID);
                        break;
 
                case MMS_CODE_REPLYCHARGINGSIZE:
@@ -963,7 +934,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                MSG_DEBUG("MMS_CODE_REPLYCHARGINGSIZE is invalid");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("X-Mms-Reply-Charging-Size = [%d]", mmsHeader.replyCharge.chargeSize);
+                       MSG_SEC_INFO("X-Mms-Reply-Charging-Size = [%d]", mmsHeader.replyCharge.chargeSize);
                        break;
 
                case MMS_CODE_PREVIOUSLYSENTBY:
@@ -1085,7 +1056,7 @@ __RETURN:
                free(pLastBcc);
        }
 
-       MSG_DEBUG("## Decode Header Success ##");
+       MSG_INFO("## Decode Header Success ##");
        MSG_END();
        return true;
 
@@ -1183,10 +1154,6 @@ bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength)
                break;
        }
 
-#ifdef __SUPPORT_DRM__
-       mmsHeader.drmType = MsgGetDRMType(&mmsHeader.msgType, &mmsHeader.msgBody);
-#endif
-
 __RETURN:
        MSG_END();
        return true;
@@ -1281,8 +1248,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                        }
 
                        if (oneByte > 0x7f) {
-                               pMsgType->param.type = MmsGetBinaryType(MmsCodeContentType,
-                                                                                                                 (UINT16)(oneByte & 0x7f));
+                               pMsgType->param.type = MimeGetMimeIntFromBi((UINT16)(oneByte & 0x7f));//MmsGetBinaryType(MmsCodeContentType,(UINT16)(oneByte & 0x7f));
                                if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, 1) == false)
                                        goto __RETURN;
                        } else {
@@ -1290,8 +1256,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
 
                                textLength = 0;
                                szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
-                               pMsgType->param.type = MmsGetTextType(MmsCodeContentType, szTypeString);
-
+                               pMsgType->param.type = MimeGetMimeIntFromMimeString(szTypeString);
                                if (szTypeString) {
                                        free(szTypeString);
                                        szTypeString = NULL;
@@ -1390,18 +1355,19 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                                                        pMsgType->param.szApplicationID = (char*) malloc(textLength + 1);
                                                        memset(pMsgType->param.szApplicationID,  0,  textLength + 1);
                                                        strncpy(pMsgType->param.szApplicationID, szTypeValue, textLength);
-                                                       MSG_DEBUG("Application-ID:%s",pMsgType->param.szApplicationID);
+                                                       MSG_SEC_DEBUG("Application-ID:%s",pMsgType->param.szApplicationID);
                                                } else if (strcasecmp(szTypeString,"Reply-To-Application-ID") == 0) {
                                                        pMsgType->param.szReplyToApplicationID= (char*) malloc(textLength + 1);
                                                        memset(pMsgType->param.szReplyToApplicationID, 0, textLength + 1);
                                                        strncpy(pMsgType->param.szReplyToApplicationID, szTypeValue, textLength);
-                                                       MSG_DEBUG("ReplyToApplication-ID:%s",pMsgType->param.szReplyToApplicationID);
+                                                       MSG_SEC_DEBUG("ReplyToApplication-ID:%s",pMsgType->param.szReplyToApplicationID);
 #endif
                                                }
+
+                                               MSG_DEBUG("Unsupported parameter(%s)\n", szTypeValue);
                                                free(szTypeValue);
                                                szTypeValue = NULL;
 
-                                               MSG_DEBUG("Unsupported parameter(%s)\n", szTypeValue);
                                                if (__MmsBinaryDecodeCheckAndDecreaseLength(&valueLength, textLength) == false)
                                                        goto __RETURN;
                                        }
@@ -1477,7 +1443,10 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
 
                if (oneByte > 0x7F) {
                        /* Short-integer */
-                       pMsgType->type = MmsGetBinaryType(MmsCodeContentType, (UINT16)(oneByte & 0x7F));
+                       pMsgType->type = MimeGetMimeIntFromBi((UINT16)(oneByte & 0x7f));
+
+                       MSG_SEC_DEBUG("Constrained-media : Short-integer : Content Type = [0x%04x], MimeType = [0x%04x]", oneByte, pMsgType->type);
+
                        length = 1;
                } else {
                        char *pszTemp = NULL;
@@ -1489,6 +1458,9 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
                        szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
 
                        if (szTypeString && (strchr(szTypeString, ';')) != NULL) {
+
+                               MSG_SEC_DEBUG("Constrained-media : Extension-Media : Content Type with delimiter = [%s]", szTypeString);
+
                                pszTemp = __MsgGetStringUntilDelimiter(szTypeString, ';');
                                if (pszTemp) {
                                        free(szTypeString);
@@ -1496,7 +1468,9 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
                                }
                        }
 
-                       pMsgType->type = MmsGetTextType(MmsCodeContentType, szTypeString);
+                       pMsgType->type = MimeGetMimeIntFromMimeString(szTypeString);
+
+                       MSG_SEC_DEBUG("Constrained-media : Extension-Media : Content Type = [%s], MimeType = [0x%04x]", szTypeString, pMsgType->type);
 
                        length = textLength;
 
@@ -1520,7 +1494,8 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
 
                if (oneByte > 0x7F) {
                        /* Well-known-media */
-                       pMsgType->type = MmsGetBinaryType(MmsCodeContentType, (UINT16)(oneByte & 0x7F));
+                       pMsgType->type = MimeGetMimeIntFromBi((UINT16)(oneByte & 0x7f));
+                       MSG_SEC_DEBUG("Content-general-form : Well-known-media : Content Type = [0x%04x], MimeType = [0x%04x]", oneByte, pMsgType->type);
                        valueLength--;
                } else {
                        /* Extension-Media */
@@ -1528,7 +1503,11 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
 
                        textLength = 0;
                        szTypeString = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
-                       pMsgType->type = MmsGetTextType(MmsCodeContentType, szTypeString);
+
+                       pMsgType->type = MimeGetMimeIntFromMimeString(szTypeString);
+
+                       MSG_SEC_DEBUG("Content-general-form : Extension-Media : Content Type = [%s], MimeType = [0x%04x]", szTypeString, pMsgType->type);
+
                        valueLength -= textLength;
 
                        if (szTypeString) {
@@ -1537,7 +1516,7 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
                        }
                }
 
-               MSG_DEBUG("Content-Type = [%s]", MmsDebugGetMimeType((MimeType)pMsgType->type));
+               MSG_SEC_DEBUG("Content-Type = [%s]", MmsDebugGetMimeType((MimeType)pMsgType->type));
 
                if (__MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
                        MSG_DEBUG("Content-Type parameter fail");
@@ -1610,21 +1589,14 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        goto __CATCH;
                                }
 
-                               szSrc = MsgChangeHexString(pLatinBuff);
-
+                               szSrc = __MsgConvertLatin2UTF8FileName(pLatinBuff);
                                if (szSrc) {
-                                       strcpy(pLatinBuff, szSrc);
+                                       snprintf(pMsgType->szContentLocation, sizeof(pMsgType->szContentLocation), "%s", szSrc);
+                                       MSG_DEBUG("Content Location : [%s]", pMsgType->szContentLocation);
                                        free(szSrc);
                                        szSrc = NULL;
                                }
 
-                               textLength = strlen(pLatinBuff);
-
-                               if (__MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
-                                       MSG_DEBUG("MsgLatin2UTF fail");
-                                       goto __CATCH;
-                               }
-
                                free(pLatinBuff);
                                pLatinBuff = NULL;
 
@@ -1635,7 +1607,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                        case 0x40:      // Content-ID
                        {
-                               char szContentID[MMS_CONTENT_ID_LEN + 1];
+                               char szContentID[MMS_CONTENT_ID_LEN + 1] = {0, };
 
                                pLatinBuff = (char *)malloc(MMS_CONTENT_ID_LEN + 1);
                                if (pLatinBuff == NULL)
@@ -1648,23 +1620,18 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        goto __CATCH;
                                }
 
-                               szSrc = MsgChangeHexString(pLatinBuff);
-
+                               szSrc = __MsgConvertLatin2UTF8FileName(pLatinBuff);
                                if (szSrc) {
-                                       strcpy(pLatinBuff, szSrc);
+                                       snprintf(szContentID, sizeof(szContentID), "%s", szSrc);
+                                       MSG_DEBUG("Content ID : [%s]", szContentID);
                                        free(szSrc);
                                        szSrc = NULL;
                                }
 
-                               textLength = strlen(pLatinBuff);
-                               if (__MsgLatin2UTF ((unsigned char*)szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
-                                       MSG_DEBUG("MsgLatin2UTF fail");
-                                       goto __CATCH;
-                               }
                                free(pLatinBuff);
                                pLatinBuff = NULL;
 
-                               removeLessGreaterMark(szContentID, pMsgType->szContentID, sizeof(pMsgType->szContentID));//remove "< >"
+                               MmsRemoveLessGreaterChar(szContentID, pMsgType->szContentID, sizeof(pMsgType->szContentID));//remove "< >"
 
                                if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
                                        goto __RETURN;
@@ -1701,7 +1668,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                if (oneByte >= 0x80) {
                                        pMsgType->disposition = MmsGetBinaryType(MmsCodeMsgDisposition, (UINT16)(oneByte & 0x7F));
 
-                                       if (pMsgType->disposition == INVALID_HOBJ) {
+                                       if (pMsgType->disposition == -1) {
                                                MSG_DEBUG("Content-Disposition MmsGetBinaryType fail.");
                                                pMsgType->disposition = MSG_DISPOSITION_ATTACHMENT;             // default
                                        }
@@ -1972,7 +1939,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        goto __CATCH;
                                }
 
-                               removeLessGreaterMark(szContentID, pMsgType->szContentID, sizeof(pMsgType->szContentID));//remove "< >"
+                               MmsRemoveLessGreaterChar(szContentID, pMsgType->szContentID, sizeof(pMsgType->szContentID));//remove "< >"
 
                                free(pLatinBuff);
                                pLatinBuff = NULL;
@@ -2073,7 +2040,7 @@ static bool __MmsBinaryDecodeEntries(FILE *pFile, UINT32 *npEntries, int totalLe
                goto __CATCH;
        }
 
-       MSG_DEBUG("Number of Entries = [%d]", *npEntries);
+       MSG_INFO("Number of Entries = [%d]", *npEntries);
 
        return true;
 
@@ -2157,7 +2124,7 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
        UINT32 nEntries = 0;
        MsgMultipart *pMultipart = NULL;
        MsgMultipart *pLastMultipart = NULL;
-       MsgMultipart *pPreMultipart     = NULL;
+//     MsgMultipart *pPreMultipart     = NULL;
        int offset = 0;
        int     index = 0;
 
@@ -2186,10 +2153,12 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
                MSG_DEBUG("decoding [%d]th multipart", index);
 
                offset = __MmsGetDecodeOffset();
-               if (offset >= totalLength)
-                       goto __RETURN;
+               if (offset >= totalLength) {
+                       MSG_DEBUG("offset is over totalLength");
+                       break;
+               }
 
-               if ((pMultipart = __MsgAllocMultipart()) == NULL) {
+               if ((pMultipart = MmsAllocMultipart()) == NULL) {
                        MSG_DEBUG("MsgAllocMultipart Fail");
                        goto __CATCH;
                }
@@ -2220,18 +2189,18 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
                if (pLastMultipart == NULL) {
                        pMsgBody->body.pMultipart = pMultipart;
                        pLastMultipart = pMultipart;
-                       pPreMultipart = NULL;
+//                     pPreMultipart = NULL;
                } else {
                        pLastMultipart->pNext = pMultipart;
                        pLastMultipart = pMultipart;
-                       pPreMultipart = pMultipart;
+//                     pPreMultipart = pMultipart;
                }
 
                pMsgType->contentSize += pMultipart->pBody->size;
 
                nEntries--;
 
-               __MmsDebugPrintMulitpartEntry(pMultipart, index++);
+               MmsPrintMulitpart(pMultipart, index++);
 
        }
 
@@ -2244,7 +2213,7 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
                goto __CATCH;
        }
 
-__RETURN:
+//__RETURN:
        return true;
 
 __CATCH:
@@ -2357,35 +2326,6 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
 
                break;
 
-
-#ifdef __SUPPORT_DRM__
-
-       case MIME_APPLICATION_VND_OMA_DRM_MESSAGE: /* Contains forwardLock OR combined-delivery media part */
-               MSG_DEBUG("MIME_APPLICATION_VND_OMA_DRM_MESSAGE Part");
-
-               if (__MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
-                       goto __CATCH;
-
-               offset = __MmsGetDecodeOffset();
-               if (offset >= totalLength)
-                       goto __RETURN;
-
-               break;
-
-       case MIME_APPLICATION_VND_OMA_DRM_CONTENT: /* Contains seperate-delivery media part (DCF) */
-
-               MSG_DEBUG("MIME_APPLICATION_VND_OMA_DRM_CONTENT Part");
-
-               if (__MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
-                       goto __CATCH;
-
-               offset = __MmsGetDecodeOffset();
-               if (offset >= totalLength)
-                       goto __RETURN;
-
-               break;
-#endif
-
        default:
                MSG_DEBUG("Normal Part");
 
@@ -2414,655 +2354,152 @@ __CATCH:
        return false;
 }
 
-#ifdef __SUPPORT_DRM__
-static bool __MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *pMsgType, MsgBody *pMsgBody, unsigned int bodyLength, int totalLength)
-{
-       int offset = 0;
-       char szTempFilePath[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"drm.dcf";
-       char *pRawData = NULL;
-       bool isFileCreated = false;
-
-       MSG_DEBUG("bodyLength: %d\n", bodyLength);
-
-       offset = __MmsGetDecodeOffset();
-
-       if (offset >= totalLength)
-               goto __RETURN;
-
-       if (szFilePath != NULL)
-               strncpy(pMsgBody->szOrgFilePath, szFilePath, strlen(szFilePath));
-       if (szFilePath != NULL)
-               strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
+/* --------------------------------------------------------------------
+ *
+ *     B  I  N  A  R  Y       D  E  C  D  E      U  T  I  L  I  T  Y
+ *
+ * --------------------------------------------------------------------*/
 
-       pRawData = (char *)malloc(bodyLength);
-       if (pRawData == NULL) {
-               MSG_DEBUG("pRawData alloc FAIL");
-               goto __CATCH;
-       }
+bool __MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength)
+{
+       int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
 
-       if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
-               MSG_DEBUG("MsgFseek() returns -1");
-               goto __CATCH;
-       }
-       if (MsgReadFile(pRawData, sizeof(char), bodyLength, pFile) != (size_t)bodyLength) {
-               MSG_DEBUG("FmReadFile() returns false");
-               goto __CATCH;
-       }
-       if (MsgOpenCreateAndOverwriteFile(szTempFilePath, pRawData, bodyLength) == false) {
-               MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false");
+       if (pFile == NULL || pOneByte == NULL)
+       {
+               MSG_DEBUG("invalid file or buffer");
                goto __CATCH;
        }
 
-       isFileCreated = true;
-
-       if (pMsgType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE) {
-               if (MsgDRM2GetDRMInfo(szTempFilePath, pMsgType) == false) {
-                       MSG_DEBUG("MsgDRM2GetDRMInfo() returns false");
+       if (length < 1) {
+               if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
+                                                                          gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
        }
 
-       if(remove(szTempFilePath) != 0)
-               MSG_DEBUG("remove fail");
-       isFileCreated = false;
-
-       if (__MmsBinaryDecodeMovePointer(pFile, offset + bodyLength, totalLength) == false)
-               goto __CATCH;
-
-__RETURN:
-
-       if (pRawData) {
-               free(pRawData);
-               pRawData = NULL;
-       }
+       *pOneByte = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
 
        return true;
 
 __CATCH:
-       if (isFileCreated)
-               if(remove(szTempFilePath) != 0)
-                       MSG_DEBUG("remove fail");
-
-       if (pRawData) {
-               free(pRawData);
-               pRawData = NULL;
-       }
-
        return false;
 }
 
-static int __MmsDrm2BinaryEncodeUintvarLen(UINT32 integer)
+/*
+ * @remark: bufLen < gMmsDecodeMaxLen
+ */
+bool __MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
 {
-       UINT32 length   = 0;
-
-       /* Find encoded unitvar length */
-       if (integer  <= MMS_UINTVAR_LENGTH_1) {
-               length = 1;
-       } else {
-               if (integer <= MMS_UINTVAR_LENGTH_2) {
-                       length = 2;
-               } else {
-                       if (integer <= MMS_UINTVAR_LENGTH_3) {
-                               length = 3;
-                       } else {
-                               length = 4;
-                       }
-               }
-       }
-
-       return length;
-}
+       int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
+       int i = 0;
 
-static bool __MmsDrm2BinaryEncodeUintvar(UINT32 integer, int length, char *pszOutput)
-{
-       const char ZERO = 0x00;
-       int i = 2;
-       char szReverse[MSG_STDSTR_LONG] = {0, };
 
-       union {
-               UINT32 integer;
-               char bytes[4];
-       } source;
-       source.integer = integer;
-       memset(szReverse, 0, MSG_STDSTR_LONG);
+       if (pFile == NULL || szBuff == NULL || bufLen == 0 || bufLen > gMmsDecodeMaxLen)
+               goto __CATCH;
 
-       /* Seperate integer to 4 1 byte integer */
-       szReverse[3] = source.bytes[3] & 0x0f;
-       szReverse[0] = source.bytes[0];
-       szReverse[0] = szReverse[0] & 0x7f;
+       memset(szBuff, 0, bufLen);
 
-       while (length >= i) {// initially, i = 2
-               /* Move integer bit to proper position */
-               source.integer = source.integer << 1;
-               source.integer = source.integer >> 8;
-               source.bytes[3] = ZERO;
+       if (length < bufLen) {
+               if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
+                                                                          gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
+                       MSG_DEBUG("fail to load to buffer");
+                       goto __CATCH;
+               }
+       }
 
-               /* Retrive 1 encode uintvar */
-               szReverse[i-1] = source.bytes[0];
-               szReverse[i-1] = szReverse[i-1] | 0x80;
-               i++;
+       for (i = 0; i < bufLen - 1; i++) {
+               szBuff[i] = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
        }
 
-       for (i=0; i < length; i++)
-               pszOutput[i] = szReverse[length - i - 1];
+       gCurMmsDecodeBuffPos++; //NULL
 
        return true;
+
+__CATCH:
+       return false;
 }
 
-static int __MmsDrm2GetEntriesValueLength(FILE *pFile, int orgOffset)
+bool __MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
 {
-       char szEntries[5] = {0, };
-       UINT8 oneByte   = 0;
-       int j = 0;                      //j is the length of nEntries value
-
-       if (MsgReadFile(szEntries, sizeof(char), 4, pFile) != (size_t)4) {
-               MSG_DEBUG("FmReadFile() returns false");
-               return false;
-       }
+       int iPos = 0;
 
-       while (true) {
-               oneByte = szEntries[j++];
+       if (pFile == NULL || szBuff == NULL || bufLen == 0)
+               goto __CATCH;
 
-               if (oneByte <= 0x7f)
-                       break;
-       }
+       memset(szBuff, 0, bufLen);
 
-       //move file pointer to point nEntries
-       if (MsgFseek(pFile, orgOffset, SEEK_SET) < 0) {
-               MSG_DEBUG("fail to seek file pointer");
-               return false;
+       if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
+                                                                  gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
+               MSG_DEBUG("fail to load to buffer");
+               goto __CATCH;
        }
 
-       return j;
-}
-
-static bool __MmsDrm2WriteDataToConvertedFile(FILE *pSrcFile, FILE *pDestinationFile, char *pszMmsLoadTempBuf, int length, int bufLen)
-{
-       int loadLen = 0, totalLoadLen = 0, nRead = 0;
-
-       for (int i=0; i<(length/bufLen)+1; i++) {
-               loadLen = (length-totalLoadLen < bufLen) ? length-totalLoadLen : bufLen;
-
-               memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
-
-               nRead = MsgReadFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pSrcFile);
-               if (nRead != (size_t)loadLen) {
-                       MSG_DEBUG("FmReadFile() returns false, nRead = %d, loadLen = %d", nRead, loadLen);
+       while ((bufLen - iPos) >= gMmsDecodeMaxLen) {
+               if (__MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, gMmsDecodeMaxLen, totalLength) == false) {
+                       MSG_DEBUG("__MmsBinaryDecodeGetBytes fail");
+                       goto __CATCH;
                }
 
-               if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), nRead, pDestinationFile) != (size_t)nRead) {
-                       MSG_DEBUG("File Writing is failed.");
-                       return false;
+               iPos += gMmsDecodeMaxLen;
+       }
+
+       if ((bufLen - iPos) > 0) {
+               if (__MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, (bufLen - iPos), totalLength) == false) {
+                       MSG_DEBUG("__MmsBinaryDecodeGetBytes fail");
+                       goto __CATCH;
                }
 
-               totalLoadLen += nRead;
+               iPos += (bufLen - iPos);
        }
 
        return true;
-}
 
-/*************************************************************************
- * description : make new message file converting CD & FL part of original message file to SD type
- * argument : void
- * return value
-    - bool :  result of converting
-**************************************************************************/
-bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
-{
-       FILE *pFile = NULL;
-       FILE *hConvertedFile = NULL;
-       FILE *hTempFile = NULL;
-       FILE *hFile = NULL;
-       MsgMultipart *pMultipart = NULL;
-       char szTempFilePath[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"Drm_Convert";
-       char szTempFile[MSG_FILEPATH_LEN_MAX] = MSG_DATA_PATH"temp.dm";
-       char *pszMmsLoadTempBuf = NULL;
-       char *pszOrgData = NULL;
-       int length = 0;
-       int bufLen = MMS_DRM2_CONVERT_BUFFER_MAX;
-       int curOffset = 0;
+__CATCH:
+       return false;
+}
 
-       MSG_DEBUG("start convert~~~~~~");
+/**
+ * Decode uintvar to 32bit unsigned integer
+ *
+ * @param      pEncodedData    [in] encoded data
+ * @param      pUintVar                [out] Decode uintvar (32bit unsigned integer)
+ * @return     The length of uintvar (-1, if cannot be converted to a uintvar)
+ *
+ * 0 XXXXXXX -> 0-bit: continue bit & 1~7bit: integer value
+ * - -------
+ */
+static const UINT32 uintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00100000, 0x08000000 };
 
-       pFile = MsgOpenFile(szOriginFilePath, "rb");
-       if (pFile == NULL) {
-               MSG_DEBUG("Open decode temporary file fail");
-               goto __CATCH;
-       }
+static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLength)
+{
+       UINT8 count = 0;
+       UINT8 oneByte = 0;
+       UINT32 decodedUintvar = 0;
+       UINT8 iBuff[5] = {0};
+       int length = MSG_MMS_DECODE_BUFFER_MAX - gCurMmsDecodeBuffPos;
 
-       hConvertedFile = MsgOpenFile(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, "wb+");
-       if (hConvertedFile == NULL) {
-               MSG_DEBUG("Open decode temporary file fail");
-               goto __CATCH;
-       }
 
-       pszMmsLoadTempBuf = (char*)malloc(MMS_DRM2_CONVERT_BUFFER_MAX + 1);
-       if (pszMmsLoadTempBuf == NULL) {
-               MSG_DEBUG("malloc for pszMmsLoadTempBuf failed");
-               goto __CATCH;
-       }
-       memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
+       if (pFile == NULL || pUintVar == NULL)
+               return -1;
 
-       // MMS Header  copy
-       length = mmsHeader.msgBody.offset;
-       if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-               MSG_DEBUG("Write header data fail");
-               goto __CATCH;
+       if (length < 5) {
+               if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
+                                                                          gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
+                       MSG_DEBUG("fail to load to buffer");
+                       goto __CATCH;
+               }
        }
 
-       curOffset += length;    //change offset
-
-       // MMS Body copy
-       if (MsgIsMultipart(mmsHeader.msgType.type) == true)
-       {
-               // nEntries copy
-               length = __MmsDrm2GetEntriesValueLength(pFile, curOffset);      // getting nEntries value's length
-
-               if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                       MSG_DEBUG("Write nEntries fail");
+       while (true) {
+               if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
                        goto __CATCH;
-               }
-
-               curOffset += length;    //change offset
-
-               // each Multipart entry copy
-               pMultipart = mmsHeader.msgBody.body.pMultipart;
-
-               while (pMultipart) {
-                       if (pMultipart->type.type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE) {
-                               int orgDataLen = pMultipart->pBody->size;
-                               int nSize = 0;
-
-                               MSG_DEBUG("Write MIME_APPLICATION_VND_OMA_DRM_MESSAGE multipart data(orgDataLen = %d).\n", orgDataLen);
-
-                               pszOrgData = (char *)malloc(orgDataLen + 1);
-                               if (pszOrgData == NULL) {
-                                       MSG_DEBUG("pszOrgData is NULL");
-                                       goto __CATCH;
-                               }
-                               memset(pszOrgData, 0, orgDataLen + 1);
-
-                               // move file pointer to data
-                               if (MsgFseek(pFile, pMultipart->pBody->offset, SEEK_SET) < 0) {
-                                       MSG_DEBUG("fail to seek file pointer 1");
-                                       goto __CATCH;
-                               }
-
-                               if (MsgReadFile(pszOrgData, sizeof(char), orgDataLen, pFile) != (size_t)orgDataLen) {
-                                       MSG_DEBUG("FmReadFile() returns false for orgData");
-                                       goto __CATCH;
-                               }
-
-                               if((hFile = MsgOpenFile(szTempFile, "wb+")) == NULL) {
-                                       MSG_DEBUG("file open failed [%s]", szTempFile);
-                                       goto __CATCH;
-                               }
-
-                               if (MsgWriteFile(pszOrgData, sizeof(char), orgDataLen, hFile) != (size_t)orgDataLen) {
-                                       MSG_DEBUG("File write error");
-                                       goto __CATCH;
-                               }
-
-                               if (pszOrgData) {
-                                       free(pszOrgData);
-                                       pszOrgData = NULL;
-                               }
-
-                               MsgFflush(hFile);
-                               MsgCloseFile(hFile);
-
-                               hFile = NULL;
-
-                               // --> invoking drm agent api, converting data part start
-                               MSG_DEBUG("start data part convert by callling drm agent api");
-
-                               int ret = 0;
-                               ret = MsgDrmConvertDmtoDcfType(szTempFile, szTempFilePath);
-                               MSG_DEBUG("MsgDrmConvertDmtoDcfType returned %s", ret ? "true": "false");
-
-                               if (MsgGetFileSize(szTempFilePath, &nSize) == false) {
-                                       MSG_DEBUG("MsgGetFileSize error");
-                                       goto __CATCH;
-                               }
-                               MSG_DEBUG("end data part convert(converted data len = %d)\n", nSize);
-
-                               // move file pointer to the head of multipart
-                               if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
-                                       MSG_DEBUG("fail to seek file pointer 2");
-                                       goto __CATCH;
-                               }
-
-                               // read headerLen, dataLen
-                               length = pMultipart->type.offset - curOffset;
-                               memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
-                               if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), length, pFile) != (size_t)length) {
-                                       MSG_DEBUG("FmReadFile() returns false for headerLen, dataLen");
-                                       goto __CATCH;
-                               }
-
-                               curOffset += length;
-
-                               // change dataLen based on converted data
-                               {
-                                       UINT8   oneByte = 0;
-                                       int             j = 0;
-                                       int             encodeLen = 0;
-                                       char    szOutput[MSG_STDSTR_LONG] = {0, };
-
-                                       while (true) {
-                                               oneByte = pszMmsLoadTempBuf[j++];
-
-                                               if (oneByte <= 0x7f)
-                                                       break;
-                                       }
-
-                                       encodeLen = __MmsDrm2BinaryEncodeUintvarLen((UINT32)nSize);
-                                       __MmsDrm2BinaryEncodeUintvar((UINT32)nSize, encodeLen, szOutput);
-
-                                       strncpy(&(pszMmsLoadTempBuf[j]), szOutput, encodeLen);
-                                       pszMmsLoadTempBuf[j+encodeLen] = '\0';
-
-                                       if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), length, hConvertedFile) != (size_t)length) {
-                                               MSG_DEBUG("FmWriteFile() returns false for dateLen");
-                                               goto __CATCH;
-                                       }
-                               }
-
-
-                               length = pMultipart->pBody->offset - pMultipart->type.offset;
-
-                               if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                                       MSG_DEBUG("Write content type, headers fail");
-                                       goto __CATCH;
-                               }
-
-                               curOffset += length;
-
-                               // write converted data
-                               hTempFile = MsgOpenFile(szTempFilePath, "rb");
-                               if (hTempFile == NULL) {
-                                       MSG_DEBUG("Open decode temporary file fail");
-                                       goto __CATCH;
-                               }
-
-                               length = nSize;
-
-                               if (__MmsDrm2WriteDataToConvertedFile(hTempFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                                       MSG_DEBUG("Write converted data fail");
-                                       goto __CATCH;
-                               }
-
-                               if (hTempFile != NULL) {
-                                       MsgCloseFile(hTempFile);
-                                       hTempFile = NULL;
-                               }
-
-                               curOffset += pMultipart->pBody->size;
-
-                               // move file pointer to the head of multipart
-                               if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
-                                       MSG_DEBUG("fail to seek file pointer");
-                                       goto __CATCH;
-                               }
-                       } else {        // it doesn't need to convert if it is not CD or FL
-                               MSG_DEBUG("Write normal multipart data");
-
-                               length = pMultipart->pBody->offset + pMultipart->pBody->size - curOffset;
-
-                               if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                                       MSG_DEBUG("Write multipart data fail");
-                                       goto __CATCH;
-                               }
-
-                               curOffset += length;
-                       }
-
-                       pMultipart = pMultipart->pNext;
-               }
-       }
-
-       MSG_DEBUG("end convert~~~~~~");
-
-       if (pFile != NULL) {
-               MsgCloseFile(pFile);
-               pFile = NULL;
-       }
-
-       if (hConvertedFile != NULL) {
-               MsgCloseFile(hConvertedFile);
-               hConvertedFile = NULL;
-       }
-
-       if (pszMmsLoadTempBuf) {
-               free(pszMmsLoadTempBuf);
-               pszMmsLoadTempBuf = NULL;
-       }
-
-       if(remove(szTempFile) != 0)
-               MSG_DEBUG("remove fail");
-       if(remove(szTempFilePath) != 0)
-               MSG_DEBUG("remove fail");
-
-       return true;
-
-__CATCH:
-
-       if (pFile != NULL) {
-               MsgCloseFile(pFile);
-               pFile = NULL;
-       }
-
-       if (hConvertedFile != NULL) {
-               MsgCloseFile(hConvertedFile);
-               hConvertedFile = NULL;
-       }
-
-       if (hTempFile != NULL) {
-               MsgCloseFile(hTempFile);
-               hTempFile = NULL;
-       }
-
-       if (pszMmsLoadTempBuf) {
-               free(pszMmsLoadTempBuf);
-               pszMmsLoadTempBuf = NULL;
-       }
-
-       if (pszOrgData) {
-               free(pszOrgData);
-               pszOrgData = NULL;
-       }
-
-       if (hFile != NULL)
-       {
-               MsgCloseFile(hFile);
-               hFile = NULL;
-       }
-
-       if (remove(szTempFile) != 0)
-               MSG_DEBUG("remove fail");
-
-       if (remove(szTempFilePath) != 0)
-               MSG_DEBUG("remove fail");
-
-       if (remove(MMS_DECODE_DRM_CONVERTED_TEMP_FILE) != 0)
-               MSG_DEBUG("remove fail");       //remove convertin result if it goes to __CATCH
-
-       return false;
-}
-
-/*************************************************************************
- * description : Function for decoding a converted file
- * argument : void
- * return value
-    - bool :  result of converting
-**************************************************************************/
-
-bool MmsDrm2ReadMsgConvertedBody(MSG_MESSAGE_INFO_S *pMsg, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath)
-{
-       MmsMsg *pMmsMsg;
-       MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
-       MmsUnregisterDecodeBuffer();
-#ifdef __SUPPORT_DRM__
-       MmsReleaseMsgDRMInfo(&pMmsMsg->msgType.drmInfo);
-#endif
-       MmsReleaseMsgBody(&pMmsMsg->msgBody, pMmsMsg->msgType.type);
-
-       if (MmsReadMsgBody(pMsg->msgId, bSavePartsAsTempFiles, bRetrieved, retrievedPath) == false) {
-               MSG_DEBUG("_MmsReadMsgBody with converted file is failed");
-               return false;
-       }
-
-       return true;
-}
-
-#endif
-
-/* --------------------------------------------------------------------
- *
- *     B  I  N  A  R  Y       D  E  C  D  E      U  T  I  L  I  T  Y
- *
- * --------------------------------------------------------------------*/
-
-bool __MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength)
-{
-       int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
-
-       if (pFile == NULL || pOneByte == NULL)
-       {
-               MSG_DEBUG("invalid file or buffer");
-               goto __CATCH;
-       }
-
-       if (length < 1) {
-               if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
-                                                                          gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("fail to load to buffer");
-                       goto __CATCH;
-               }
-       }
-
-       *pOneByte = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
-
-       return true;
-
-__CATCH:
-       return false;
-}
-
-/*
- * @remark: bufLen < gMmsDecodeMaxLen
- */
-bool __MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
-{
-       int length = gMmsDecodeMaxLen - gCurMmsDecodeBuffPos;
-       int i = 0;
-
-
-       if (pFile == NULL || szBuff == NULL || bufLen == 0 || bufLen > gMmsDecodeMaxLen)
-               goto __CATCH;
-
-       memset(szBuff, 0, bufLen);
-
-       if (length < bufLen) {
-               if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
-                                                                          gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("fail to load to buffer");
-                       goto __CATCH;
-               }
-       }
-
-       for (i = 0; i < bufLen - 1; i++)
-               szBuff[i] = gpCurMmsDecodeBuff[gCurMmsDecodeBuffPos++];
-
-
-       gCurMmsDecodeBuffPos++; //NULL
-
-       return true;
-
-__CATCH:
-       return false;
-}
-
-bool __MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int totalLength)
-{
-       int iPos = 0;
-
-       if (pFile == NULL || szBuff == NULL || bufLen == 0)
-               goto __CATCH;
-
-       memset(szBuff, 0, bufLen);
-
-       if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
-                                                                  gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("fail to load to buffer");
-               goto __CATCH;
-       }
-
-       while ((bufLen - iPos) >= gMmsDecodeMaxLen) {
-               if (__MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, gMmsDecodeMaxLen, totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeGetBytes fail");
-                       goto __CATCH;
-               }
-
-               iPos += gMmsDecodeMaxLen;
-       }
-
-       if ((bufLen - iPos) > 0) {
-               if (__MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, (bufLen - iPos), totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeGetBytes fail");
-                       goto __CATCH;
-               }
-
-               iPos += (bufLen - iPos);
-       }
-
-       return true;
-
-__CATCH:
-       return false;
-}
-
-/**
- * Decode uintvar to 32bit unsigned integer
- *
- * @param      pEncodedData    [in] encoded data
- * @param      pUintVar                [out] Decode uintvar (32bit unsigned integer)
- * @return     The length of uintvar (-1, if cannot be converted to a uintvar)
- *
- * 0 XXXXXXX -> 0-bit: continue bit & 1~7bit: integer value
- * - -------
- */
-static const UINT32 uintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00100000, 0x08000000 };
-
-static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLength)
-{
-       UINT8 count = 0;
-       UINT8 oneByte = 0;
-       UINT32 decodedUintvar = 0;
-       UINT8 iBuff[5] = {0};
-       int length = MSG_MMS_DECODE_BUFFER_MAX - gCurMmsDecodeBuffPos;
-
-
-       if (pFile == NULL || pUintVar == NULL)
-               return -1;
-
-       if (length < 5) {
-               if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
-                                                                          gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("fail to load to buffer");
-                       goto __CATCH;
-               }
-       }
-
-       while (true) {
-               if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false)
-                       goto __CATCH;
-
-               if (oneByte > 0x7f)     {
-                       iBuff[count++] = oneByte;
-               } else {
-                       iBuff[count++] = oneByte;
-                       break;
+
+               if (oneByte > 0x7f)     {
+                       iBuff[count++] = oneByte;
+               } else {
+                       iBuff[count++] = oneByte;
+                       break;
                }
 
                if (count > 4) {
@@ -3866,7 +3303,7 @@ static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSe
        }
 
        *nCharSet = MmsGetBinaryType(MmsCodeCharSet, (UINT16)integer);
-
+       MSG_DEBUG("Decoded charset MIBenum = [%d], charset enum = [%d]", integer, *nCharSet);
        if (*nCharSet == MIME_UNKNOWN) {
                MSG_DEBUG("MmsGetBinaryType fail..");
                *nCharSet = MSG_CHARSET_UNKNOWN;
@@ -3933,6 +3370,7 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
                }
 
                nTemp = __MmsBinaryDecodeText(pFile, szBuff, bufLen, totalLength);
+
                if (nTemp < 0) {
                        /* There can be some error in data - no NULL -> try again with value length */
 
@@ -3974,9 +3412,13 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
                                MSG_DEBUG("MmsPluginTextConvert Fail");
 
                        } else {
-
                                memset(szBuff, 0x00, bufLen);
-                               snprintf(szBuff, destLen, "%s", pDest);
+                               snprintf(szBuff, destLen+1, "%s", pDest);
+                       }
+
+                       if (pDest) {
+                               free(pDest);
+                               pDest = NULL;
                        }
                }
                break;
@@ -4162,19 +3604,19 @@ static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int tot
        if (pLatinBuff) {
                szSrc = MsgRemoveQuoteFromFilename(pLatinBuff);
                if (szSrc) {
-                       strcpy(pLatinBuff, szSrc);
+                       strncpy(pLatinBuff, szSrc, textLength);
                        free(szSrc);
                        szSrc = NULL;
                }
 
                szSrc2 = MsgChangeHexString(pLatinBuff);
                if (szSrc2) {
-                       strcpy(pLatinBuff, szSrc2);
+                       strncpy(pLatinBuff, szSrc2, textLength);
                        free(szSrc2);
                        szSrc2 = NULL;
                }
 
-               if (__MsgIsUTF8String((unsigned char*)pLatinBuff, strlen(pLatinBuff)) == false) {
+               if (MmsIsUtf8String((unsigned char*)pLatinBuff, strlen(pLatinBuff)) == false) {
                        length = strlen(pLatinBuff);
 
                        int             utf8BufSize = 0;
@@ -4210,13 +3652,15 @@ static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int tot
 
                length = strlen(pUTF8Buff);
                if ((pExt = strrchr(pUTF8Buff, '.')) != NULL) {
-                       int nameLength  = 0;
+                       int nameLength = 0;
                        nameLength = (length < bufLen) ? (length - strlen(pExt)) : (bufLen - strlen(pExt));
                        strncpy(szBuff, pUTF8Buff, nameLength);
-                       strcat (szBuff, pExt);
+                       g_strlcat(szBuff, pExt,(gsize)bufLen);
+
                } else {
                        strncpy(szBuff, pUTF8Buff, bufLen - 1);
                }
+
                free(pUTF8Buff);
                pUTF8Buff = NULL;
 
@@ -4264,7 +3708,7 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
        if (bRetrieved && (retrievedPath != NULL)) {
                strncpy(szFullPath, retrievedPath, (strlen(retrievedPath) > MSG_FILEPATH_LEN_MAX ? MSG_FILEPATH_LEN_MAX:strlen(retrievedPath)));
        } else {
-               MmsPluginStorage::instance()->getMmsRawFilePath(msgID, szFullPath);
+               MmsPluginStorage::instance()->getMmsRawFilePath(msgID, szFullPath, sizeof(szFullPath));
        }
 
        pMsg->msgID = msgID;
@@ -4272,8 +3716,8 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
        /*      read from MMS raw file  */
        strncpy(pMsg->szFileName, szFullPath + strlen(MSG_DATA_PATH), strlen(szFullPath + strlen(MSG_DATA_PATH)));
 
-       MSG_DEBUG("msg_id = [%d]", msgID);
-       MSG_DEBUG("raw file path = [%s]", szFullPath);
+       MSG_SEC_DEBUG("msg_id = [%d]", msgID);
+       MSG_SEC_DEBUG("raw file path = [%s]", szFullPath);
 
        if (MsgGetFileSize(szFullPath, &nSize) == false) {
                MSG_FATAL("Fail MsgGetFileSize");
@@ -4282,7 +3726,7 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
 
        pFile = MsgOpenFile(szFullPath, "rb");
        if (pFile == NULL) {
-               MSG_DEBUG("Fail MsgOpenFile [%s]", szFullPath);
+               MSG_SEC_DEBUG("Fail MsgOpenFile [%s]", szFullPath);
                goto __CATCH;
        }
 
@@ -4376,7 +3820,7 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
        }
 
        /*      make temporary  */
-       snprintf(szTempMediaDir, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s.dir", pMsg->szFileName);
+       snprintf(szTempMediaDir, MSG_FILEPATH_LEN_MAX, "%s%s.dir", MSG_DATA_PATH, pMsg->szFileName);
 
        if (MsgIsMultipart(pMsg->msgType.type) == true) {
                int partIndex = 0;
@@ -4385,13 +3829,13 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
                if (bSavePartsAsTempFiles) {
                        if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
                                if (errno == EEXIST) {
-                                       MSG_DEBUG("exist dir : [%s]", szTempMediaDir);
+                                       MSG_SEC_DEBUG("exist dir : [%s]", szTempMediaDir);
                                } else {
-                                       MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
+                                       MSG_SEC_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
                                        goto __CATCH;
                                }
                        } else {
-                               MSG_DEBUG("make dir : [%s]", szTempMediaDir);
+                               MSG_SEC_DEBUG("make dir : [%s]", szTempMediaDir);
                        }
                }
 
@@ -4407,6 +3851,8 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
                                                                                        (char*)MSG_DATA_PATH, pMsg->szFileName, partIndex, bSavePartsAsTempFiles) == false)
                                goto __CATCH;
 
+                       MmsPrintMulitpart(pMultipart, partIndex);
+
                        pMultipart = pMultipart->pNext;
                        partIndex ++;
                }
@@ -4446,9 +3892,8 @@ __CATCH:
                pFile = NULL;
        }
 
-#ifdef __SUPPORT_DRM__
+
        MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
-#endif
 
        MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
 
@@ -4641,23 +4086,23 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                pDec = MsgDecodeText(pName);
                        }
 
-                       switch (_MsgGetCode(MSG_PARAM, pSrc)) {
+                       switch (MmsGetTextType(MmsCodeParameterCode, pSrc)) {
                        case MSG_PARAM_BOUNDARY:
 
                                /* RFC 822: boundary := 0*69<bchars> bcharsnospace */
 
                                memset (pType->param.szBoundary, 0, MSG_BOUNDARY_LEN + 1);
                                strncpy(pType->param.szBoundary, pDec, MSG_BOUNDARY_LEN);
-                               MSG_DEBUG("szBoundary = [%s]", pType->param.szBoundary);
+                               MSG_SEC_INFO("szBoundary = [%s]", pType->param.szBoundary);
                                break;
 
                        case MSG_PARAM_CHARSET:
-                               pType->param.charset = _MsgGetCode(MSG_CHARSET, pDec);
+                               pType->param.charset = MmsGetTextType(MmsCodeParameterCode, pDec);
 
-                               if (pType->param.charset == INVALID_HOBJ)
+                               if (pType->param.charset == -1)
                                        pType->param.charset = MSG_CHARSET_UNKNOWN;
 
-                               MSG_DEBUG("type = %d    [charset] = %d", pType->type, pType->param.charset);
+                               MSG_SEC_INFO("type = %d    [charset] = %d", pType->type, pType->param.charset);
                                break;
 
                        case MSG_PARAM_NAME:
@@ -4675,7 +4120,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                                }
 
                                                strncpy(pType->param.szName, pUTF8Buff, nameLen);
-                                               strcat (pType->param.szName, pExt);
+                                               g_strlcat(pType->param.szName, pExt, sizeof(pType->param.szName));
                                        } else {
                                                strncpy(pType->param.szName, pUTF8Buff, (MSG_LOCALE_FILENAME_LEN_MAX-1));
                                        }
@@ -4695,10 +4140,10 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                        // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
                                        __MsgRemoveFilePath(pType->param.szName);
                                } else {
-                                       MSG_DEBUG("MsgConvertLatin2UTF8FileName(%s) return NULL", pDec);
+                                       MSG_SEC_DEBUG("MsgConvertLatin2UTF8FileName(%s) return NULL", pDec);
                                }
 
-                               MSG_DEBUG("szName = %s", pType->param.szName);
+                               MSG_SEC_INFO("szName = %s", pType->param.szName);
                                break;
 
                        case MSG_PARAM_FILENAME:
@@ -4716,15 +4161,16 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                                }
 
                                                strncpy(pType->param.szFileName, pUTF8Buff, nameLen);
-                                               strcat (pType->param.szFileName, pExt);
+                                               g_strlcat (pType->param.szFileName, pExt, sizeof(pType->param.szFileName));
                                        } else {
                                                strncpy(pType->param.szFileName, pUTF8Buff, (MSG_FILENAME_LEN_MAX-1));
                                        }
                                        free(pUTF8Buff);
                                        pUTF8Buff = NULL;
 
-                                       if (__MsgChangeSpace(pType->param.szFileName, &szSrc) == true)
-                                               strcpy(pType->param.szFileName, szSrc);
+                                       if (__MsgChangeSpace(pType->param.szFileName, &szSrc) == true) {
+                                               snprintf(pType->param.szFileName, sizeof(pType->param.szFileName), "%s", szSrc);
+                                       }
 
                                        if (szSrc) {
                                                free(szSrc);
@@ -4734,10 +4180,10 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                        // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
                                        __MsgRemoveFilePath(pType->param.szFileName);
                                } else {
-                                       MSG_DEBUG("MsgConvertLatin2UTF8FileName(%s) return NULL", pDec);
+                                       MSG_SEC_DEBUG("MsgConvertLatin2UTF8FileName(%s) return NULL", pDec);
                                }
 
-                               MSG_DEBUG("szFileName = %s", pType->param.szFileName);
+                               MSG_SEC_INFO("szFileName = %s", pType->param.szFileName);
 
                                break;
 
@@ -4745,8 +4191,8 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
 
                                /* type/subtype of root. Only if content-type is multipart/related */
 
-                               pType->param.type = _MsgGetCode(MSG_TYPE, pDec);
-                               MSG_DEBUG("type = %d", pType->param.type);
+                               pType->param.type = MimeGetMimeIntFromMimeString(pDec);
+                               MSG_SEC_INFO("type = %d", pType->param.type);
 
                                break;
 
@@ -4757,7 +4203,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                memset (pType->param.szStart, 0, MSG_MSG_ID_LEN + 1);
                                strncpy(pType->param.szStart, pDec, MSG_MSG_ID_LEN);
 
-                               MSG_DEBUG("szStart = %s", pType->param.szStart);
+                               MSG_SEC_INFO("szStart = %s", pType->param.szStart);
 
                                break;
 
@@ -4768,7 +4214,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                memset (pType->param.szStartInfo, 0, MSG_MSG_ID_LEN + 1);
                                strncpy(pType->param.szStartInfo, pDec, MSG_MSG_ID_LEN);
 
-                               MSG_DEBUG("szStartInfo = %s", pType->param.szStartInfo);
+                               MSG_SEC_INFO("szStartInfo = %s", pType->param.szStartInfo);
 
                                break;
 
@@ -4782,7 +4228,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                        pType->param.reportType = MSG_PARAM_REPORT_TYPE_UNKNOWN;
                                }
 
-                               MSG_DEBUG("reportType = %s", pDec);
+                               MSG_SEC_INFO("reportType = %s", pDec);
                                break;
 
                        default:
@@ -4828,7 +4274,7 @@ static char *__MsgSkipComment (char *s,long trim)
                switch (*s1) {
                case '(':
                        if (!__MsgSkipComment (s1,(long)NULL))
-                               return NULL;
+                               goto __NULL_RETURN;
                        t = --s1;
                        break;
                case ')':
@@ -4846,28 +4292,27 @@ static char *__MsgSkipComment (char *s,long trim)
                                break;
                case '\0':
                        *s = '\0';
-                       return NULL;
+                       goto __NULL_RETURN;
                case ' ':
                        break;
                default:
                        t = s1;
                        break;
                }
-       }while (s1++);
+       } while (s1++);
 
-       /* DEADCODE
+__NULL_RETURN:
        return NULL;
-       */
 }
 
 static char *__MsgConvertLatin2UTF8FileName(char *pSrc)
 {
        char *pUTF8Buff  = NULL;
-       char *pData = NULL;
+//     char *pData = NULL;
 
 
        //convert utf8 string
-       if (__MsgIsUTF8String((unsigned char*)pSrc, strlen(pSrc)) == false) {
+       if (MmsIsUtf8String((unsigned char*)pSrc, strlen(pSrc)) == false) {
                int length  = 0;
                int utf8BufSize = 0;
 
@@ -4900,14 +4345,13 @@ static char *__MsgConvertLatin2UTF8FileName(char *pSrc)
        }
 
        //convert hex string
-       if (__MsgIsPercentSign(pUTF8Buff) == true) {
-               pData = MsgChangeHexString(pUTF8Buff);
-               if (pData) {
-                       strcpy(pUTF8Buff, pData);
-                       free(pData);
-                       pData = NULL;
-               }
-       }
+//     if (__MsgIsPercentSign(pUTF8Buff) == true) {
+//             pData = MsgChangeHexString(pUTF8Buff);
+//             if (pData) {
+//                     free(pUTF8Buff);
+//                     pUTF8Buff = pData;
+//             }
+//     }
 
        return pUTF8Buff;
 
@@ -4972,7 +4416,7 @@ static void __MsgRemoveFilePath(char *pSrc)
        }
 
        if (pPath) {
-               MSG_DEBUG("filename(%s)", pSrc);
+               MSG_SEC_DEBUG("filename(%s)", pSrc);
 
                // case : images/vf7.gif -> vf7.gif
                if (pPath != NULL && *(pPath+1) != '\0') {
@@ -4990,108 +4434,23 @@ static void __MsgRemoveFilePath(char *pSrc)
        }
 }
 
-static bool __MsgIsUTF8String(unsigned char *szSrc, int nChar)
-{
-       MSG_DEBUG("MsgIsUTF8String: ---------------");
-
-       if (szSrc == NULL) {
-               MSG_DEBUG("szSrc is NULL !!!! ---------------");
-               return true;
-       }
-
-       while (nChar > 0 && (*szSrc != '\0')) {
-               if (*szSrc < 0x80) {
-                       szSrc++;
-                       nChar--;
-               } else if ((0xC0 <= *szSrc) && (*szSrc < 0xE0)) {
-                       if (*(szSrc + 1) >= 0x80) {
-                               szSrc += 2;
-                               nChar -= 2;
-                       } else {
-                               MSG_DEBUG("1. NOT utf8 range!");
-                               goto __CATCH;
-                       }
-               } else if (*szSrc >= 0xE0) {
-                       if (*(szSrc + 1) >= 0x80) {
-                               if (*(szSrc + 2) >= 0x80) {
-                                       szSrc += 3;
-                                       nChar -= 3;
-                               } else {
-                                       MSG_DEBUG("2. NOT utf8 range!");
-                                       goto __CATCH;
-                               }
-                       } else {
-                               MSG_DEBUG("3. NOT utf8 range!");
-                               goto __CATCH;
-                       }
-               } else {
-                       MSG_DEBUG("4. NOT utf8 range!");
-                       goto __CATCH;
-               }
-       }
-
-       return true;
-
-__CATCH:
-       return false;
-}
-
+#if 0
 static bool __MsgIsPercentSign(char *pSrc)
 {
-       char *pCh = NULL;
-       bool bRet = false;
-
-       pCh = strchr(pSrc , '%');
-
-       if (pCh != NULL) {
-               bRet = true;
-       } else {
-               bRet = false;
-       }
-
-       return bRet;
-}
-
-static MsgMultipart *__MsgAllocMultipart(void)
-{
-       MsgMultipart *pMultipart = NULL;
-
-       MSG_BEGIN();
-
-       pMultipart = (MsgMultipart*)malloc(sizeof(MsgMultipart));
-       if (pMultipart == NULL) {
-               MSG_DEBUG("pMultipart malloc Fail");
-               goto __CATCH;
-       }
-
-       pMultipart->pBody = (MsgBody*)malloc(sizeof(MsgBody));
-       if (pMultipart->pBody == NULL) {
-               MSG_DEBUG("pMultipart->pBody malloc Fail");
-               goto __CATCH;
-       }
-
-       MmsInitMsgType(&pMultipart->type);
-       MmsInitMsgBody(pMultipart->pBody);
-
-       pMultipart->pNext = NULL;
-
-       MSG_END();
-       return pMultipart;
-
-__CATCH:
+       char *pCh = NULL;
+       bool bRet = false;
 
-       if (pMultipart) {
-               if (pMultipart->pBody) {
-                       free(pMultipart->pBody);
-                       pMultipart->pBody = NULL;
-               }
+       pCh = strchr(pSrc , '%');
 
-               free(pMultipart);
-               pMultipart = NULL;
+       if (pCh != NULL) {
+               bRet = true;
+       } else {
+               bRet = false;
        }
 
-       return NULL;
+       return bRet;
 }
+#endif
 
 static MsgPresentationFactor __MsgIsPresentationEx(MsgType *multipartType, char* szStart, MimeType typeParam)
 {
@@ -5185,9 +4544,9 @@ static void __MsgConfirmPresentationPart(MsgType *pMsgType, MsgBody *pMsgBody, M
                                pMsgType->contentSize -= pPresentationInfo->pCurPresentation->pBody->size;
                                pMsgBody->size -= pPresentationInfo->pCurPresentation->pBody->size;
                                if (pPresentationInfo->pCurPresentation) {
-#ifdef __SUPPORT_DRM__
+
                                        MmsReleaseMsgDRMInfo(&pPresentationInfo->pCurPresentation->type.drmInfo);
-#endif
+
                                        free(pPresentationInfo->pCurPresentation);
                                        pPresentationInfo->pCurPresentation = NULL;
                                }
@@ -5201,7 +4560,7 @@ static void __MsgConfirmPresentationPart(MsgType *pMsgType, MsgBody *pMsgBody, M
                                        pPresentationInfo->pCurPresentation = NULL;
                                }
                        }
-               } else if (pPresentationInfo->pCurPresentation != NULL && __MsgIsText(pPresentationInfo->pCurPresentation->type.type)) {
+               } else if (pPresentationInfo->pCurPresentation != NULL && MmsIsTextType(pPresentationInfo->pCurPresentation->type.type)) {
                        /* NON-Presentable Part is some PLAIN part such as, text/plain, multipart/alternative.
                         * In this case, leave the Presentation part as a multipart and remove other multiparts.
                         */
@@ -5229,9 +4588,9 @@ static void __MsgConfirmPresentationPart(MsgType *pMsgType, MsgBody *pMsgBody, M
                        }
                } else {
 
-#ifdef __SUPPORT_DRM__
+
                        MmsReleaseMsgDRMInfo(&pMsgBody->presentationType.drmInfo);
-#endif
+
                        MmsInitMsgType(&pMsgBody->presentationType);
                        pMsgBody->pPresentationBody = NULL;
                }
@@ -5257,70 +4616,6 @@ static bool __MsgIsPresentablePart(int type)
        }
 }
 
-#ifdef __SUPPORT_DRM__
-
-bool MsgCopyDrmInfo(MsgType *pPartType)
-{
-       char *pExt = NULL;
-       char *pTmpBuf = NULL;
-
-       //convert application/vnd.oma.drm.content to media type
-       pPartType->type = pPartType->drmInfo.contentType;
-
-       // fix wrong file name presentation on save media screen.
-       if (pPartType->szContentID[0] == '\0' && pPartType->drmInfo.szContentURI)
-               strncpy(pPartType->szContentID, pPartType->drmInfo.szContentURI, MSG_MSG_ID_LEN);
-
-       /* set title name (content name) */
-       if (pPartType->param.szName[0] == '\0') {
-               /*      szName is vitual name, real filename is *.dcf or *.dm   */
-               if (pPartType->drmInfo.szContentName && pPartType->drmInfo.szContentName[0] != '\0') {
-                       /* In case of szContentName retrieved from DRM agent is exist. */
-                       pTmpBuf = pPartType->drmInfo.szContentName;
-               } else if (pPartType->szContentLocation[0] != '\0')     {
-                       /* In case of szContentLocation parsed from MMS header */
-                       pTmpBuf = strrchr(pPartType->szContentLocation, '/');
-                       if (pTmpBuf == NULL)
-                               pTmpBuf = pPartType->szContentLocation;
-               } else {
-                       /* use another name */
-                       /* possible NULL pointer assignment*/
-                       pTmpBuf = strdup("untitled");
-               }
-
-               if ((pExt = strrchr(pTmpBuf, '.')) != NULL) {
-                       int extLen = 0;
-                       int fileNameLen = 0;
-                       int tmpLen = 0;
-
-                       extLen = strlen(pExt);
-                       tmpLen = strlen(pTmpBuf);
-                       fileNameLen = (tmpLen - extLen < MSG_LOCALE_FILENAME_LEN_MAX - extLen)?(tmpLen - extLen):(MSG_LOCALE_FILENAME_LEN_MAX - extLen);
-                       strncpy(pPartType->param.szName, pTmpBuf, fileNameLen);
-                       strcpy (pPartType->param.szName + fileNameLen, pExt);
-               } else {
-                       strncpy(pPartType->param.szName, pTmpBuf, MSG_LOCALE_FILENAME_LEN_MAX);
-                       __MsgMakeFileName(pPartType->type, pPartType->param.szName, MSG_DRM_TYPE_NONE, 0, pPartType->param.szName, sizeof(pPartType->param.szName));
-               }
-       }
-
-       return true;
-}
-
-#endif
-
-static bool __MsgIsText(int type)
-{
-       if (type == MIME_TEXT_PLAIN || type == MIME_TEXT_HTML || type == MIME_TEXT_VND_WAP_WML ||
-               type == MIME_TEXT_X_VNOTE || type == MIME_APPLICATION_SMIL || type == MIME_TEXT_X_IMELODY) {
-               return true;
-       } else {
-               return false;
-       }
-}
-
-
-
 static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
 {
        MSG_BEGIN();
@@ -5385,9 +4680,9 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                pSelectedPart->pNext = NULL;
 
                if (pRemoveList) {
-#ifdef __SUPPORT_DRM__
+
                        MmsReleaseMsgDRMInfo(&pRemoveList->type.drmInfo);
-#endif
+
                        MmsReleaseMsgBody(pRemoveList->pBody, pRemoveList->type.type);
 
                        free(pRemoveList->pBody);
@@ -5403,9 +4698,8 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                        memcpy(pPartBody, pSelectedPart->pBody, sizeof(MsgBody));
 
                if (pSelectedPart != NULL) {
-#ifdef __SUPPORT_DRM__
+
                        MmsReleaseMsgDRMInfo(&pSelectedPart->type.drmInfo);
-#endif
 
                        if (pSelectedPart->pBody != NULL) {
                                free(pSelectedPart->pBody);
@@ -5459,9 +4753,9 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                                }
 
                                if (pSelectedPart) {
-#ifdef __SUPPORT_DRM__
+
                                        MmsReleaseMsgDRMInfo(&pSelectedPart->type.drmInfo);
-#endif
+
                                        free(pSelectedPart->pBody);
                                        free(pSelectedPart);
                                }
@@ -5532,9 +4826,8 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
 
                                pPartType->type = pSelectedPart->type.type;
 
-#ifdef __SUPPORT_DRM__
                                MmsReleaseMsgDRMInfo(&pSelectedPart->type.drmInfo);
-#endif
+
                                free(pSelectedPart->pBody);
                                free(pSelectedPart);
 
@@ -5593,9 +4886,9 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                pTmpMultipart = pRemoveList;
 
                while (pTmpMultipart) {
-#ifdef __SUPPORT_DRM__
+
                        MmsReleaseMsgDRMInfo(&pTmpMultipart->type.drmInfo);
-#endif
+
                        MmsReleaseMsgBody(pTmpMultipart->pBody, pTmpMultipart->type.type);
                        pNextRemovePart = pTmpMultipart->pNext;
 
@@ -5614,9 +4907,8 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                        if (pSelectedPart->pBody != NULL)
                                memcpy(pPartBody, pSelectedPart->pBody, sizeof(MsgBody));
 
-#ifdef __SUPPORT_DRM__
                        MmsReleaseMsgDRMInfo(&pSelectedPart->type.drmInfo);
-#endif
+
                        if (pSelectedPart->pBody != NULL) {
                                free(pSelectedPart->pBody);
                                pSelectedPart->pBody = NULL;
@@ -5667,7 +4959,8 @@ char *MsgResolveContentURI(char *szSrc)
        }
 
        memset(szTemp, 0, length);
-       strcpy(szTemp, szSrc);
+
+       strncpy(szTemp, szSrc, length - 1);
 
        szReturn = MsgChangeHexString(szTemp);
 
@@ -5714,7 +5007,7 @@ char *MsgRemoveQuoteFromFilename(char *pSrc)
                cLen--;
                strncpy(pBuff, &pSrc[1], cLen);
        } else {
-               strcpy(pBuff, pSrc);
+               strncpy(pBuff, pSrc, cLen);
        }
 
        // remove last qoute
@@ -5796,51 +5089,47 @@ static bool __MsgCopyNestedMsgType(MsgType *pMsgType1, MsgType *pMsgType2)
        if(!pMsgType1 || !pMsgType2)
                return false;
 
-       if (pMsgType1->section == INVALID_HOBJ)
+       //if (pMsgType1->section == INVALID_HOBJ)
                pMsgType1->section = pMsgType2->section;
 
-#ifdef __SUPPORT_DRM__
-       int             length = 0;
+       int length = 0;
 
        if (pMsgType1->drmInfo.drmType == MSG_DRM_TYPE_NONE)
                pMsgType1->drmInfo.drmType = pMsgType2->drmInfo.drmType;
 
 
        if (pMsgType1->szContentID[0] == '\0') {
-               strcpy(pMsgType1->szContentID, pMsgType2->szContentID);
+               snprintf(pMsgType1->szContentID, sizeof(pMsgType1->szContentID), "%s", pMsgType2->szContentID);
+       }
 
-               if (pMsgType2->szContentID[0]) {
-                       length = MsgStrlen(pMsgType2->szContentID);
-                       if (pMsgType2->szContentID[0] == '<' && pMsgType2->szContentID[length - 1] == '>') {
-                               pMsgType1->drmInfo.szContentURI = MsgStrNCopy(pMsgType2->szContentID + 1, length - 2);
-                       } else {
-                               pMsgType1->drmInfo.szContentURI = MsgStrCopy(pMsgType2->szContentID);
-                       }
-               }
-       } else {
-               length = MsgStrlen(pMsgType1->szContentID);
+       if (pMsgType1->szContentID[0] != '\0') {
+
+               length = strlen(pMsgType1->szContentID);
                if (pMsgType1->szContentID[0] == '<' && pMsgType1->szContentID[length - 1] == '>') {
-                       pMsgType1->drmInfo.szContentURI = MsgStrNCopy(pMsgType1->szContentID + 1, length - 2);
+                       char szTempString[MSG_MSG_ID_LEN + 1];
+                       MmsRemoveLessGreaterChar(pMsgType1->szContentID, szTempString, sizeof(szTempString));
+                       pMsgType1->drmInfo.szContentURI = g_strdup(szTempString);
                } else {
-                       pMsgType1->drmInfo.szContentURI = MsgStrCopy(pMsgType1->szContentID);
+                       pMsgType1->drmInfo.szContentURI = g_strdup(pMsgType1->szContentID);
                }
        }
-#endif
 
-       if (pMsgType1->szContentLocation[0] == '\0')
-               strcpy(pMsgType1->szContentLocation, pMsgType2->szContentLocation);
+       if (pMsgType1->szContentLocation[0] == '\0') {
+               strncpy(pMsgType1->szContentLocation, pMsgType2->szContentLocation, MSG_MSG_ID_LEN);
+       }
 
        /* Copy informations - we shoud open the pMsgType2's orgFile
         * concerning its offset and size.
         */
-       if (pMsgType2->szOrgFilePath[0] != '\0')
-               strcpy(pMsgType1->szOrgFilePath, pMsgType2->szOrgFilePath);
+       if (pMsgType2->szOrgFilePath[0] != '\0') {
+               strncpy(pMsgType1->szOrgFilePath, pMsgType2->szOrgFilePath, MSG_FILEPATH_LEN_MAX-1);
+       }
 
-       if (pMsgType2->disposition != INVALID_HOBJ)
+       if (pMsgType2->disposition != -1)
                pMsgType1->disposition = pMsgType2->disposition;
 
        if ((pMsgType1->type != MIME_APPLICATION_VND_OMA_DRM_MESSAGE && pMsgType1->type != MIME_APPLICATION_VND_OMA_DRM_CONTENT) &&
-                pMsgType2->encoding != INVALID_HOBJ)
+                pMsgType2->encoding != -1)
                pMsgType1->encoding = pMsgType2->encoding;
 
        pMsgType1->contentSize = pMsgType2->contentSize;
@@ -5851,332 +5140,93 @@ static bool __MsgCopyNestedMsgType(MsgType *pMsgType1, MsgType *pMsgType2)
        __MsgCopyNestedMsgParam(&(pMsgType1->param), &(pMsgType2->param));
 
        if (pMsgType1->param.szName[0]) {
-#ifdef __SUPPORT_DRM__
-               pMsgType1->drmInfo.szContentName = MsgStrCopy(pMsgType2->param.szName);
-#endif
-       }
-
-       return true;
-}
-
-static bool __MsgCopyNestedMsgParam(MsgContentParam *pParam1, MsgContentParam *pParam2)
-{
-       if (pParam1->charset == MSG_CHARSET_UNKNOWN)
-               pParam1->charset = pParam2->charset;
-
-       if (pParam1->type == MIME_UNKNOWN)
-               pParam1->type = pParam2->type;
-
-       /* Don't copy pParam2->pPresentation */
-
-       /* For alternative: copy the boundary string */
-       if (pParam2->szBoundary[0] !='\0')
-               strcpy(pParam1->szBoundary, pParam2->szBoundary);
-
-       if (pParam1->szFileName[0] =='\0')
-               strcpy(pParam1->szFileName, pParam2->szFileName);
-
-       if (pParam1->szName[0] =='\0')
-               strcpy(pParam1->szName, pParam2->szName);
-
-       if (pParam1->szStart[0] =='\0')
-               strcpy(pParam1->szStart, pParam2->szStart);
-
-       if (pParam1->szStartInfo[0] =='\0')
-               strcpy(pParam1->szStartInfo, pParam2->szStartInfo);
-
-       return true;
-}
-
-static bool __MsgIsMultipartMixed(int type)
-{
-       if (type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED || type == MIME_MULTIPART_MIXED) {
-               return true;
-       } else {
-               return false;
-       }
-}
-
-bool MmsGetMsgAttrib(MmsMsgID msgID, MmsAttrib* pAttrib)
-{
-       MmsMsg *pMsg = NULL;
-
-       memset(pAttrib, 0, sizeof(MmsAttrib));
-       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-       memcpy(pAttrib, &(pMsg->mmsAttrib), sizeof(MmsAttrib));
-
-       MSG_DEBUG("msgID = %lu ---------------------\n", msgID);
-
-       if ('\0' != pMsg->szTrID[0])
-               MSG_DEBUG("szTrID = %s \n", pMsg->szTrID);
-
-       MSG_END();
-       return true;
-}
-
-static bool __MsgIsInvalidFileNameChar(char ch)
-{
-       if ((ch == 0x5C /* \ */) ||
-               (ch == 0x2F /* / */) ||
-               (ch == 0x3A /* : */) ||
-               (ch == 0x2A /* * */) ||
-               (ch == 0x3F /* ? */) ||
-               (ch == 0x22 /* " */) ||
-               (ch == 0x3C /* < */) ||
-               (ch == 0x3E /* > */) ||
-               (ch == 0x7C /* | */))
-               return true;
-
-       return false;
-}
-
-bool MmsDataUpdateLastStatus(MmsMsg *pMsg)
-{
-       MmsMsgMultiStatus*      pStatus = NULL;
-
-       pStatus = pMsg->mmsAttrib.pMultiStatus;
-
-       while (pStatus != NULL) {
-               pStatus->bDeliveyrReportIsLast = false;
-               pStatus->bReadReplyIsLast = false;
-               pStatus = pStatus->pNext;
+               pMsgType1->drmInfo.szContentName = g_strdup(pMsgType2->param.szName);
        }
 
        return true;
 }
 
+static bool __MsgCopyNestedMsgParam(MsgContentParam *pParam1, MsgContentParam *pParam2)
+{
+       if (pParam1->charset == MSG_CHARSET_UNKNOWN)
+               pParam1->charset = pParam2->charset;
 
-bool MmsAddrUtilCompareAddr(char *pszAddr1, char *pszAddr2)
-{
-       int len1;
-       int len2;
-       char *p;
-
-       MmsAddrUtilRemovePlmnString(pszAddr1);
-       MmsAddrUtilRemovePlmnString(pszAddr2);
-
-       MSG_DEBUG("##### pszAddr1 = %s #####", pszAddr1);
-       MSG_DEBUG("##### pszAddr2 = %s #####", pszAddr2);
-       if (!strcmp(pszAddr1, pszAddr2))
-               return true;
-
-       len1 = strlen(pszAddr1);
-       len2 = strlen(pszAddr2);
-
-       if (len1 > len2) {
-               p = strstr(pszAddr1, pszAddr2);
-       } else {
-               p = strstr(pszAddr2, pszAddr1);
-       }
-
-       if (p)
-               return true;
-
-       return false;
-}
-
-static int __MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar)
-{
-       int nCount = 0;
-
-       MSG_DEBUG("---------------");
-
-       if ((szSrc == NULL) || (nChar <= 0)) {
-               MSG_DEBUG("szSrc is NULL !!!! ---------------");
-               return 0;
-       }
-
-       while ((nChar > 0) && (*szSrc != '\0')) {
-               if (0x01 <= *szSrc && *szSrc <= 0x7F) {
-                       nCount += 1;
-                       szSrc++;
-                       nChar--;
-               } else {
-                       nCount += 2;
-                       szSrc++;
-                       nChar--;
-               }
-       }
-
-       return nCount;
-}
-
-static int __MsgLatin5code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
-{
-       unsigned char *org;
-       unsigned char t1;
-       unsigned char t2;
-       unsigned short temp = 0;
-
-       org = des;
-       outBufSize--;   //Null Character
-
-       while ((nChar > 0) && (*szSrc != '\0')) {
-
-               if (*szSrc >= 0x01 && *szSrc <= 0x7F) { //basic common
-                       temp = (unsigned short)(*szSrc);
-
-                       outBufSize --;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       *des = (unsigned char) ((*szSrc) & 0x007F);
-
-                       des++;
-                       szSrc++;
-                       nChar--;
-               } else if ((*szSrc == 0x00) || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
-                                       (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) ||
-                                       (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
-                                       (*szSrc == 0xFF)) {//uni 0x00A0 ~ 0x00CF
-
-                       temp = (unsigned short)(*szSrc);
-
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xD0) {//empty section OR vendor specific codes.
-
-                       temp = 0x011E;
-
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xDD) {
-                       temp = 0x0130;
-
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xDE) {
-                       temp = 0x015E;
-
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xF0) {
-                       temp = 0x011F;
-                               outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xFD) {
-                       temp = 0x0131;
+       if (pParam1->type == MIME_UNKNOWN)
+               pParam1->type = pParam2->type;
 
-                       outBufSize -= 2;
+       /* Don't copy pParam2->pPresentation */
 
-                       if (outBufSize < 0)
-                               goto __RETURN;
+       /* For alternative: copy the boundary string */
+       if (pParam2->szBoundary[0] !='\0') {
+               strncpy(pParam1->szBoundary, pParam2->szBoundary, MSG_BOUNDARY_LEN);
+       }
 
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
+       if (pParam1->szFileName[0] =='\0') {
+               strncpy(pParam1->szFileName, pParam2->szFileName, MSG_FILENAME_LEN_MAX);
+       }
 
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
+       if (pParam1->szName[0] =='\0') {
+               strncpy(pParam1->szName, pParam2->szName, MSG_LOCALE_FILENAME_LEN_MAX);
+       }
 
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xFE) {
-                       temp = 0x015F;
+       if (pParam1->szStart[0] =='\0') {
+               strncpy(pParam1->szStart, pParam2->szStart, MSG_MSG_ID_LEN);
+       }
 
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+       if (pParam1->szStartInfo[0] =='\0') {
+               strncpy(pParam1->szStartInfo, pParam2->szStartInfo, MSG_MSG_ID_LEN);
+       }
+       return true;
+}
 
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
+static bool __MsgIsMultipartMixed(int type)
+{
+       if (type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED || type == MIME_MULTIPART_MIXED) {
+               return true;
+       } else {
+               return false;
+       }
+}
 
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
+static bool __MsgIsInvalidFileNameChar(char ch)
+{
+       if ((ch == 0x5C /* \ */) ||
+               (ch == 0x2F /* / */) ||
+               (ch == 0x3A /* : */) ||
+               (ch == 0x2A /* * */) ||
+               (ch == 0x3F /* ? */) ||
+               (ch == 0x22 /* " */) ||
+               (ch == 0x3C /* < */) ||
+               (ch == 0x3E /* > */) ||
+               (ch == 0x7C /* | */))
+               return true;
 
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else {
-                       return -1;
-               }
-       }
-__RETURN:
-       *des = 0;
-       return(des-org);
+       return false;
 }
 
-static int __MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar)
+static int __MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar)
 {
        int nCount = 0;
 
        MSG_DEBUG("---------------");
 
-       if ((szSrc == NULL) || (nChar <= 0))
+       if ((szSrc == NULL) || (nChar <= 0)) {
+               MSG_DEBUG("szSrc is NULL !!!! ---------------");
                return 0;
+       }
 
        while ((nChar > 0) && (*szSrc != '\0')) {
-               if (*szSrc >= 0x01 && *szSrc <= 0x7F) {
+               if (0x01 <= *szSrc && *szSrc <= 0x7F) {
                        nCount += 1;
                        szSrc++;
                        nChar--;
-               } else if (*szSrc == 0x00 || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
-                                       (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) ||
-                                       (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
-                                       *szSrc == 0xD0 || *szSrc == 0xDD || *szSrc == 0xDE || *szSrc == 0xF0 ||
-                                       *szSrc == 0xFD || *szSrc == 0xFE        || *szSrc == 0xFF) { //uni 0x00A0 ~ 0x00CF
+               } else {
                        nCount += 2;
                        szSrc++;
                        nChar--;
-               } else {
-                       return -1;
                }
        }
+
        return nCount;
 }
 
@@ -6228,262 +5278,162 @@ __RETURN:
        return (des - org);
 }
 
-
-static int __MsgLatin7code2UTF(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
+bool MmsAddrUtilCheckEmailAddress(char *pszAddr)
 {
-       unsigned char *org;
-       unsigned char t1;
-       unsigned char t2;
-       unsigned char t3;
-       unsigned short temp = 0;
-
-       MSG_DEBUG("---------------");
-
-       org = des;
-       outBufSize--;   //Null Character
-
-       while ((nChar > 0) && (*szSrc != '\0')) {
-               if (*szSrc >= 0x01 && *szSrc <= 0x7F) {
-                       temp = (unsigned short)(*szSrc);
-
-                       outBufSize --;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       *des = (unsigned char) (temp & 0x007F);
-
-                       des++;
-                       szSrc++;
-                       nChar--;
-
-               } else if ((*szSrc == 0x00) || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
-                                       (*szSrc >= 0xA3 && *szSrc <= 0xAD) || (*szSrc == 0xBB)) { // consider 0xA4, 0xA5
-
-                       temp = (unsigned short)(*szSrc);
-
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0xC0) >> 6);              //      right most 2 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des + 1) = 0x80 | (t2 & 0x3F);
-
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else if (*szSrc == 0xA0) {
-                       temp = 0x0020;
-                       //*des = temp to utf-8
-                       outBufSize--;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       *des = (unsigned char) (temp & 0x007F);
-
-                       des++;
-                       szSrc++;
-                       nChar--;
-
-               } else if (*szSrc == 0xA1) {
-                       temp = 0x2018;
-
-                       outBufSize -= 3;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t3 = (unsigned char) (temp & 0x003F);                                   //      right most 6 bit
-                       t2 = (unsigned char) ((temp & 0x0FC0) >> 6);                    //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0xF000) >> 12);                   //      right most 4 bit
-
-                       *des = 0xE0 | (t1 & 0x0F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-                       *(des+2) = 0x80 | (t3 & 0x3F);
-
-                       des += 3;
-                       szSrc += 1;
-                       nChar -= 1;
-
-               } else if (*szSrc == 0xA2) {
-                       temp = 0x2019;
-
-                       outBufSize -= 3;
-                       if (outBufSize < 0)
-                               goto __RETURN;
-
-                       t3 = (unsigned char) (temp & 0x003F);                                   //      right most 6 bit
-                       t2 = (unsigned char) ((temp & 0x0FC0) >> 6);                    //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0xF000) >> 12);                   //      right most 4 bit
+       if (!pszAddr || pszAddr[0] == 0)
+               return false;
 
-                       *des = 0xE0 | (t1 & 0x0F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-                       *(des+2) = 0x80 | (t3 & 0x3F);
+       if (!strchr (pszAddr, MSG_MMS_CH_EMAIL_AT))
+               return false;
 
-                       des += 3;
-                       szSrc += 1;
-                       nChar -= 1;
+       return true;
+}
 
-               } else if (*szSrc == 0xAF) {
-                       temp = 0x2015;
+bool MmsAddrUtilRemovePlmnString(char *pszAddr)
+{
+       char *pszAddrCopy = NULL;
+       char *pszStrStart = NULL;
+       char *pszStrTemp = NULL;
+       int strLen = 0;
 
-                       outBufSize -= 3;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+       if ((!pszAddr) || (pszAddr[0] == 0)) {
+               MSG_DEBUG("pszAddr is null or zero");
+               return false;
+       }
 
-                       t3 = (unsigned char) (temp & 0x003F);                                   //      right most 6 bit
-                       t2 = (unsigned char) ((temp & 0x0FC0) >> 6);                    //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0xF000) >> 12);                   //      right most 4 bit
+       strLen = strlen(pszAddr);
 
-                       *des = 0xE0 | (t1 & 0x0F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-                       *(des+2) = 0x80 | (t3 & 0x3F);
+       pszAddrCopy = (char*)calloc(1,strLen + 1);
+       if (!pszAddrCopy) {
+               MSG_DEBUG("pszAddrCopy is NULL, mem alloc failed");
+               return false;
+       }
 
-                       des += 3;
-                       szSrc += 1;
-                       nChar -= 1;
+       strncpy(pszAddrCopy, pszAddr, strLen);
 
-               } else if (0xB0 <= *szSrc && *szSrc <= 0xB4) { //0x00B0 ~ 0x00B4
+       pszAddr[0] = 0;
+       pszStrStart = pszAddrCopy;
 
-                       temp = (unsigned short)(*szSrc);
+       while (true) {
+               char*   pszStrEnd = NULL;
+               int     addressLen = 0;
 
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+               if (MmsAddrUtilCheckEmailAddress(pszAddrCopy))
+                       pszStrEnd = strstr(pszStrStart, "/TYPE=PLMN");
+               else
+                       pszStrEnd = strstr(pszStrStart, "/");
 
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
+               if (!pszStrEnd) {
+                       char *pszStart = NULL;
+                       char *pszEnd = NULL;
+                       // "/TYPE=PLMN" not found
 
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
+                       int remainedLen = strlen(pszStrStart);
 
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
+                       if (remainedLen <= 0)
+                               break;
+                       //Email addresscan occur with Sender Name<email-address> format
+                       //remove the Sender name and only retain the email address.
+                       pszStart = strstr(pszStrStart, "<");
+                       if (pszStart) {
+                               pszEnd = strstr(pszStrStart, ">");
+
+                               if (pszEnd) {
+                                       pszStart++; //skip "<"
+                                       g_strlcat(pszAddr, pszStart, pszEnd - pszStart + 1);
+                                       break;
+                               }
+                       }
 
-               } else if ((0xB5 <= *szSrc &&  *szSrc <= 0xBA) ||
-                               (0xBC <= *szSrc && *szSrc <= 0xD1) ||
-                               (0xD3 <= *szSrc && *szSrc <= 0xFE)) {
-                       temp= (unsigned short)(*szSrc + 0x02D0);
+                       //strcat(pszAddr, pszStrStart);
+                       g_strlcat(pszAddr, pszStrStart, strLen + 1);
+                       break;
+               }
 
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+               // Get one address length
+               addressLen = pszStrEnd - pszStrStart;
 
-                       t2 = (unsigned char) (temp & 0x003F);                           //      right most 6 bit
-                       t1 = (unsigned char) ((temp & 0x07C0) >> 6);            //      right most 5 bit
+               strncat(pszAddr, pszStrStart, addressLen);
 
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
+               // Find next address
+               pszStrStart = pszStrEnd;
 
-                       des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
+               pszStrTemp = strstr(pszStrStart, MSG_MMS_STR_ADDR_DELIMETER);
 
+               if (pszStrTemp) {
+                       addressLen = pszStrTemp - pszStrEnd;
+                       pszStrStart += addressLen;
                } else {
-                       return -1;
+                       pszStrStart += strlen(pszStrEnd);
                }
 
-       }
-
-__RETURN:
-       *des = 0;
-       return(des - org);
-}
-
-static int __MsgGetLatin72UTFCodeSize(unsigned char *szSrc, int nChar)
-{
-       int nCount = 0;
+               if (pszStrStart[0] == 0)        // end of string
+                       break;
 
-       MSG_DEBUG(" ---------------");
 
-       if ((szSrc == NULL) || (nChar <= 0))
-               return 0;
+               g_strlcat(pszAddr, MSG_MMS_STR_ADDR_DELIMETER, strLen + 1);     // add ';'
+               pszStrStart++;  // remove ';'
+       }
 
-       while ((nChar > 0) && (*szSrc != '\0')) {
+       if (pszAddr[0] == 0)
+               strncpy(pszAddr, pszAddrCopy, strLen);
 
-               if ((*szSrc >= 0x01 && *szSrc <= 0x7F) || (*szSrc == 0xA0)) {
-                       nCount += 1;
-                       szSrc++;
-                       nChar--;
-               } else if (*szSrc == 0x00 || (0x80 <= *szSrc && *szSrc <= 0x9F) || (0xA3 <= *szSrc && *szSrc <= 0xAD) ||
-                                       (0xB0 <= *szSrc && *szSrc <= 0xB4) || (0xB5 <= *szSrc && *szSrc <= 0xFE)) {
-                       nCount += 2;
-                       szSrc++;
-                       nChar--;
-               } else if (*szSrc == 0xA1 ||*szSrc == 0xA2 || *szSrc == 0xAF) {
-                       nCount += 3;
-                       szSrc += 1;
-                       nChar -= 1;
+       free(pszAddrCopy);
 
-               } else {
-                       return -1;
-               }
-       }
-       return nCount;
+       return true;
 }
 
-static int __MsgUnicode2UTF(unsigned char *des, int outBufSize, unsigned short *szSrc, int nChar)
+static int __MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
 {
        unsigned char *org;
-       unsigned char t1;
-       unsigned char t2;
-       unsigned char t3;
 
-       MSG_DEBUG(" ---------------");
+       MSG_DEBUG("---------------");
 
        org = des;
        outBufSize--;                   // NULL character
 
        while ((nChar > 0) && (*szSrc != '\0')) {
-               if (0x0001 <= *szSrc && *szSrc <= 0x007F) {
-                       /* check outbuffer's room for this UTF8 character */
-
+               if (*szSrc < 0x80) {
                        outBufSize --;
                        if (outBufSize < 0)
                                goto __RETURN;
 
-                       *des = (unsigned char) (*szSrc & 0x007F);
-
+                       *des = *szSrc;
                        des++;
                        szSrc++;
-                       nChar--;
-               } else if  ((*szSrc == 0x0000) || (0x0080 <= *szSrc && *szSrc <= 0x07FF)) {
-                       /* check outbuffer's room for this UTF8 character */
-
+               } else if  (((0xC0 <= *szSrc) && (*szSrc < 0xE0)) && (*(szSrc+1) >= 0x80)) {
                        outBufSize -= 2;
                        if (outBufSize < 0)
                                goto __RETURN;
 
-                       t2 = (unsigned char) (*szSrc & 0x003F);                         //      right most 6 bit
-                       t1 = (unsigned char) ((*szSrc & 0x07C0) >> 6);          //      right most 5 bit
-
-                       *des = 0xC0 | (t1 & 0x1F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
+                       *des = *szSrc;
+                       *(des + 1) = *(szSrc + 1);
 
                        des += 2;
-                       szSrc += 1;
-                       nChar -= 1;
-               } else {
-                       /* check outbuffer's room for this UTF8 character */
-
+                       szSrc += 2;
+               } else if  ((*szSrc >= 0xE0) && (*(szSrc+1) >= 0x80) && (*(szSrc+2) >= 0x80)) {
                        outBufSize -= 3;
                        if (outBufSize < 0)
                                goto __RETURN;
 
-                       t3 = (unsigned char) (*szSrc & 0x003F);                                 //      right most 6 bit
-                       t2 = (unsigned char) ((*szSrc & 0x0FC0) >> 6);                  //      right most 6 bit
-                       t1 = (unsigned char) ((*szSrc & 0xF000) >> 12);                 //      right most 4 bit
+                       *des = *szSrc;
+                       *(des + 1) = *(szSrc + 1);
+                       *(des + 2) = *(szSrc + 2);
 
-                       *des = 0xE0 | (t1 & 0x0F);
-                       *(des+1) = 0x80 | (t2 & 0x3F);
-                       *(des+2) = 0x80 | (t3 & 0x3F);
+                       des += 3;
+                       szSrc += 3;
+               } else {
+                       outBufSize --;
+                       if (outBufSize < 0)
+                               goto __RETURN;
 
-                       des += 3;
-                       szSrc += 1;
-                       nChar -= 1;
+                       *des = *szSrc;
+                       des++;
+                       szSrc++;
+                       MSG_DEBUG("utf8 incorrect range!");
                }
+
+               nChar--;
        }
 
 __RETURN:
@@ -6492,961 +5442,971 @@ __RETURN:
        return (des - org);
 }
 
-static int __MsgGetUnicode2UTFCodeSize(unsigned short *szSrc, int nChar)
+static void __MsgMIMERemoveQuote(char *szSrc)
 {
-       int nCount = 0;
+       int length = 0;
 
-       MSG_DEBUG(" ---------------");
+       length = strlen(szSrc);
+       if (szSrc[0] == MSG_CH_QUOT && szSrc[length-1] == MSG_CH_QUOT) {
+               int index = 0;
 
-       if ((szSrc == NULL) || (nChar <= 0)) {
-               MSG_DEBUG("szSrc is NULL !!!! ---------------");
-               return 0;
+               for (index = 0; index < length-2; index++)
+                       szSrc[index] = szSrc[index+1];
+               szSrc[index] = '\0';
        }
+}
 
-       while ((nChar > 0) && (*szSrc != '\0')) {
-               if (0x0001 <= *szSrc && *szSrc <= 0x007F) {
-                       nCount += 1;
-                       szSrc++;
-                       nChar--;
-               } else if  ((*szSrc == 0x0000) || (0x0080 <= *szSrc && *szSrc <= 0x07FF)) {
-                       nCount += 2;
-                       szSrc++;
-                       nChar--;
-               } else {
-                       nCount += 3;
-                       szSrc++;
-                       nChar--;
-               }
+static bool __MsgLoadDataToDecodeBuffer(FILE *pFile, char **ppBuf, int *pPtr, int *pOffset, char *pInBuf1, char *pInBuf2, int maxLen, int *pBufLen, int endOfFile)
+{
+       MSG_BEGIN();
+       int nRead = 0;
+       int length= 0;
+
+       if (pFile == NULL) {
+               MSG_DEBUG("Error");
+
+               *pBufLen = 0;
+               return false;
        }
 
-       return nCount;
-}
+       if (pPtr == NULL || pInBuf1 == NULL || pInBuf2 == NULL) {
+               MSG_DEBUG("Error");
 
-static bool __MmsAddrUtilCheckEmailAddress(char *pszAddr)
-{
-       if (!pszAddr || pszAddr[0] == 0)
+               *pBufLen = 0;
                return false;
+       }
 
-       if (!strchr (pszAddr, MSG_MMS_CH_EMAIL_AT))
+       if (*pBufLen == 0) {
+               length = maxLen - (*pPtr);
+       } else {
+               length = (*pBufLen) - (*pPtr);
+       }
+
+       if (length < 0)
+               length = 0;
+
+       if ((*ppBuf) == NULL) {
+               memset(pInBuf1, 0, maxLen);
+               (*ppBuf) = pInBuf1;
+       } else if ((*ppBuf) == pInBuf1) {
+               memset(pInBuf2, 0, maxLen);
+               if (length)
+                       memcpy(pInBuf2, pInBuf1 + (*pPtr), length);
+               (*ppBuf) = pInBuf2;
+       } else {
+               memset(pInBuf1, 0, maxLen);
+               if (length)
+                       memcpy(pInBuf1, pInBuf2 + (*pPtr), length);
+               (*ppBuf) = pInBuf1;
+       }
+
+       (*pPtr) = 0;
+
+       if (*pOffset == endOfFile) {
+               *pBufLen = length;
+               return true;
+       }
+
+       if (maxLen == length) {
+               /* (*pPtr) was 0 */
+               if (MsgReadFileForDecode(pFile, (*ppBuf), maxLen, &nRead) == false)
+                       return false;
+
+               *pBufLen = nRead;
+       } else {
+               if (MsgReadFileForDecode(pFile, (*ppBuf) + length, maxLen - length, &nRead) == false)
+                       return false;
+
+               *pBufLen = length + nRead;
+       }
+
+       if ((*pOffset = MsgFtell(pFile)) == -1L) {
+               MSG_DEBUG("MsgFtell Error");
                return false;
+       }
+
+       MSG_END();
 
        return true;
 }
 
-bool MmsAddrUtilRemovePlmnString(char *pszAddr)
+/*
+ *     This function write media data from raw data to file.
+ *     @param  pMsg
+ *     @param  pPartBody
+ *     @param  pszMailboxPath  : path of mailbox
+ *     @param  pszMsgFilename  : name of msg file
+ *     @param  index                   : used for file naming
+ *     @param  bSave                   : if true, file will be save otherwise just filename will be stored.
+ */
+static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody, char *pszMailboxPath, char *pszMsgFilename, int index, bool bSave)
 {
-       char *pszAddrCopy = NULL;
-       char *pszStrStart = NULL;
-       char *pszStrTemp = NULL;
-       int strLen = 0;
+       FILE *pFile = NULL;
+       char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };        // file name of temp file
+       char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, }; // full absolute path of temp file.
+       bool bFileExist = false;
+       MSG_BEGIN();
 
-       if ((!pszAddr) || (pszAddr[0] == 0)) {
-               MSG_DEBUG("pszAddr is null or zero");
+       if (!pPartType) {
+               MSG_DEBUG("pPartType is NULL");
                return false;
        }
 
-       strLen = strlen(pszAddr);
+       if (pPartType->type == MIME_APPLICATION_SMIL) {
+               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", "smil.txt");
+       } else {
 
-       pszAddrCopy = (char*)calloc(1,strLen + 1);
-       if (!pszAddrCopy) {
-               MSG_DEBUG("pszAddrCopy is NULL, mem alloc failed");
-               return false;
+               if (pPartType->param.szName[0] != '\0') {
+                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", pPartType->param.szName);
+               } else if (pPartType->param.szFileName[0] != '\0') {
+                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", pPartType->param.szFileName);
+               } else if (pPartType->szContentLocation[0] != '\0') {
+                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", pPartType->szContentLocation);
+               } else {
+                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%lu", (unsigned long)index);
+               }
        }
 
-       strcpy(pszAddrCopy, pszAddr);
+       // make full path for save
+       __MsgMakeFileName(pPartType->type, szFileName, pPartType->drmInfo.drmType, 0, szFileName, sizeof(szFileName));  //FL & CD -> extension(.dm) SD -> extension(.dcf)
 
+       snprintf(szFullPath, MSG_FILEPATH_LEN_MAX, "%s%s.dir/%s", pszMailboxPath, pszMsgFilename, szFileName);  // get absolute path of each temp file of each part
 
-       pszAddr[0] = 0;
-       pszStrStart = pszAddrCopy;
+       if (pPartType->type == MIME_APPLICATION_OCTET_STREAM)
+               MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, szFullPath, (MimeType *)&pPartType->type, NULL);
 
-       while (true) {
-               char*   pszStrEnd = NULL;
-               int             addressLen = 0;
+       // save file
+       bFileExist = MsgAccessFile(szFullPath, F_OK);
 
-               if (__MmsAddrUtilCheckEmailAddress(pszAddrCopy))
-                       pszStrEnd = strstr(pszStrStart, "/TYPE=PLMN");
-               else
-                       pszStrEnd = strstr(pszStrStart, "/");
+       MSG_SEC_DEBUG("save flag  [%d],  filepath [%s], file exist [%d]", bSave, szFullPath, bFileExist);
 
-               if (!pszStrEnd) {
-                       // "/TYPE=PLMN" not found
+       if (bSave == true && bFileExist == false) {
 
-                       int remainedLen = strlen(pszStrStart);
+               if ((pFile = MsgOpenFile(szFullPath, "wb+")) == NULL) {
+                       MSG_DEBUG("MsgOpenFile failed");
+                       goto __CATCH;
+               }
 
-                       if (remainedLen <= 0)
-                               break;
+               if (__MmsGetMediaPartData(pPartType, pPartBody, pFile) == false) {
+                       MSG_DEBUG("MmsGetMediaPartData fail [index:%d]\n", index);
+                       goto __CATCH;
+               }
+
+               MsgCloseFile(pFile);
+               pFile = NULL;
 
-                       strcat(pszAddr, pszStrStart);
+               snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", szFullPath);
 
-                       break;
+               //IF DRM type Convert to dcf
+               if (pPartType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE
+                       || pPartType->type == MIME_APPLICATION_VND_OMA_DRM_CONTENT)
+               {
+                       char destDrmPath[MSG_FILEPATH_LEN_MAX] = {0,};
+
+                       if (MsgDrmConvertDmtoDcfType(pPartBody->szOrgFilePath, destDrmPath) == true) {
+                               MSG_INFO("Success Convert to Dcf");
+
+                               bFileExist = MsgAccessFile(destDrmPath, F_OK);
+
+                               if (bFileExist) {
+                                       snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", destDrmPath);
+                                       MsgGetFileName(pPartBody->szOrgFilePath, szFileName, MSG_FILENAME_LEN_MAX);
+                               }
+
+                       } else {
+                               MSG_INFO("Fail Convert to Dcf");
+                       }
+
+                       if (MsgDrmIsDrmFile(pPartBody->szOrgFilePath) == true)
+                               MmsPluginDrmGetInfo(pPartBody->szOrgFilePath, pPartType);
+
+                       MSG_SEC_INFO("Drm File Path [%s] isdrm [%d]", pPartBody->szOrgFilePath, MsgDrmIsDrmFile(pPartBody->szOrgFilePath));
                }
 
-               // Get one address length
-               addressLen = pszStrEnd - pszStrStart;
+               pPartBody->offset = 0;
+               pPartBody->size = MsgGetFileSize(pPartBody->szOrgFilePath);
 
-               strncat(pszAddr, pszStrStart, addressLen);
+               if (pPartType->drmInfo.drmType != MSG_DRM_TYPE_NONE) {
+                       MsgDrmRegisterFile(MSG_MODE_FILE, pPartBody->szOrgFilePath, strlen(pPartBody->szOrgFilePath));
 
-               // Find next address
-               pszStrStart = pszStrEnd;
+                       /* change szDrm2FullPath as current content path*/
+                       if (pPartType->drmInfo.szDrm2FullPath) {
+                               free(pPartType->drmInfo.szDrm2FullPath);
+                               pPartType->drmInfo.szDrm2FullPath = g_strdup(pPartBody->szOrgFilePath);
+                       }
+               }
 
-               pszStrTemp = strstr(pszStrStart, MSG_MMS_STR_ADDR_DELIMETER);
+               MSG_SEC_DEBUG("Save Part File to [%s]", pPartBody->szOrgFilePath);
 
-               if (pszStrTemp) {
-                       addressLen = pszStrTemp - pszStrEnd;
-                       pszStrStart += addressLen;
-               } else {
-                       pszStrStart += strlen(pszStrEnd);
+       } else {
+               snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", szFullPath);
+
+               //IF DRM type check dcf exist
+               if (pPartType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE
+                       || pPartType->type == MIME_APPLICATION_VND_OMA_DRM_CONTENT)
+               {
+                       char destDrmPath[MSG_FILEPATH_LEN_MAX] = {0,};
+
+                       MsgGetFileNameWithoutExtension(destDrmPath, pPartBody->szOrgFilePath);
+                       strncat(destDrmPath, ".dcf", 4);
+
+                       bFileExist = MsgAccessFile(destDrmPath, F_OK);
+
+                       if (bFileExist) {
+                               snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", destDrmPath);
+                               MsgGetFileName(pPartBody->szOrgFilePath, szFileName, MSG_FILENAME_LEN_MAX);
+                       }
+
+                       if (MsgDrmIsDrmFile(pPartBody->szOrgFilePath) == true)
+                               MmsPluginDrmGetInfo(pPartBody->szOrgFilePath, pPartType);
                }
 
-               if (pszStrStart[0] == 0)        // end of string
-                       break;
+               pPartBody->offset = 0;
+               pPartBody->size = MsgGetFileSize(pPartBody->szOrgFilePath);
 
+               MSG_SEC_DEBUG("Set Part File to [%s]", pPartBody->szOrgFilePath);
+       }
 
-               strcat(pszAddr, MSG_MMS_STR_ADDR_DELIMETER);    // add ';'
-               pszStrStart++;  // remove ';'
+       //file name fix
+       if (szFileName[0]  != '\0') {
+               snprintf(pPartType->param.szFileName, MSG_FILENAME_LEN_MAX+1, "%s.dir/%s", pszMsgFilename, szFileName);// store relative path of each temp file of each part including sub folder.
+               snprintf(pPartType->param.szName, MSG_LOCALE_FILENAME_LEN_MAX+1, "%s", szFileName);
+               MSG_SEC_DEBUG("Set Name : %s", pPartType->param.szName);
        }
 
-       if (pszAddr[0] == 0)
-               strcpy(pszAddr, pszAddrCopy);
+       MSG_END();
+       return true;
 
-       free(pszAddrCopy);
+__CATCH:
 
-       return true;
+       if (pFile != NULL) {
+               MsgCloseFile(pFile);
+               pFile = NULL;
+       }
+       MSG_END();
+       return false;
 }
 
-static int __MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *szSrc, int nChar)
+bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE* pFile)
 {
-       unsigned char *org;
+       int nRead = 0;
+       int nRead2 = 0;
+       char *pData = NULL;
+       char *pNewData = NULL;
+       char *pTempData = NULL;
+       int msgEncodingValue = 0;
+       int msgTypeValue = 0;
+       int msgCharsetValue     = 0;
 
-       MSG_DEBUG("---------------");
+       int offset = 0;
+       int size = 0;
 
-       org = des;
-       outBufSize--;                   // NULL character
+       msgEncodingValue = pPartType->encoding;
+       msgTypeValue = pPartType->type;
+       msgCharsetValue = pPartType->param.charset;
 
-       while ((nChar > 0) && (*szSrc != '\0')) {
-               if (*szSrc < 0x80) {
-                       outBufSize --;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+       offset = pPartBody->offset;
+       size = pPartBody->size;
+
+       if (pPartBody->szOrgFilePath[0]) {
+               pTempData = MsgOpenAndReadMmsFile(pPartBody->szOrgFilePath, offset, size, &nRead);
 
-                       *des = *szSrc;
-                       des++;
-                       szSrc++;
-               } else if  (((0xC0 <= *szSrc) && (*szSrc < 0xE0)) && (*(szSrc+1) >= 0x80)) {
-                       outBufSize -= 2;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+               if (pTempData == NULL) {
+                       MSG_DEBUG("pTempData read fail");
+                       goto __CATCH;
+               }
 
-                       *des = *szSrc;
-                       *(des + 1) = *(szSrc + 1);
+               pData = pTempData;
+       } else if (pPartBody->body.pText) {
+               pData = pPartBody->body.pText;
+               nRead = pPartBody->size;
+       }
 
-                       des += 2;
-                       szSrc += 2;
-               } else if  ((*szSrc >= 0xE0) && (*(szSrc+1) >= 0x80) && (*(szSrc+2) >= 0x80)) {
-                       outBufSize -= 3;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+       if (pData == NULL) {
+               MSG_DEBUG("there is no data");
+               goto __RETURN;
+       }
 
-                       *des = *szSrc;
-                       *(des + 1) = *(szSrc + 1);
-                       *(des + 2) = *(szSrc + 2);
+       pNewData = __MmsGetBinaryUTF8Data(pData, nRead, msgEncodingValue, msgTypeValue, msgCharsetValue, &nRead2);
 
-                       des += 3;
-                       szSrc += 3;
-               } else {
-                       outBufSize --;
-                       if (outBufSize < 0)
-                               goto __RETURN;
+       if (pNewData) {
+               pPartType->encoding = MSG_ENCODING_BINARY;
 
-                       *des = *szSrc;
-                       des++;
-                       szSrc++;
-                       MSG_DEBUG("utf8 incorrect range!");
+               if (MmsIsTextType(msgTypeValue))
+                       pPartType->param.charset = MSG_CHARSET_UTF8;
+
+               if (MsgWriteFile(pNewData, sizeof(char), nRead2,  pFile) != (size_t)nRead2) {
+                       MSG_DEBUG("file writing fail");
+                       goto __CATCH;
                }
 
-               nChar--;
+       } else {
+               if (MsgWriteFile(pData, sizeof(char), nRead,  pFile) != (size_t)nRead) {
+                       MSG_DEBUG("file writing fail");
+                       goto __CATCH;
+               }
        }
 
 __RETURN:
 
-       *des = 0;
-       return (des - org);
-}
+       if (pNewData) {
+               free(pNewData);
+               pNewData = NULL;
+       }
 
-static void __MsgMIMERemoveQuote(char *szSrc)
-{
-       int             length = 0;
+       if (pTempData) {
+               free(pTempData);
+               pTempData = NULL;
+       }
 
-       length = MsgStrlen(szSrc);
-       if (szSrc[0] == MSG_CH_QUOT && szSrc[length-1] == MSG_CH_QUOT) {
-               int index = 0;
+       return true;
 
-               for (index = 0; index < length-2; index++)
-                       szSrc[index] = szSrc[index+1];
-               szSrc[index] = '\0';
+__CATCH:
+
+       if (pNewData) {
+               free(pNewData);
+               pNewData = NULL;
+       }
+
+       if (pTempData) {
+               free(pTempData);
+               pTempData = NULL;
        }
+
+       return false;
 }
 
-static bool __MsgLoadDataToDecodeBuffer(FILE *pFile, char **ppBuf, int *pPtr, int *pOffset, char *pInBuf1, char *pInBuf2, int maxLen, int *pBufLen, int endOfFile)
+char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue, int msgTypeValue, int msgCharsetValue, int *npRead)
 {
-       MSG_BEGIN();
-       int nRead = 0;
-       int length= 0;
+       int nByte = 0;
+       int nTemp = 0;
+       char *pTemp = NULL;
 
-       if (pFile == NULL) {
-               MSG_DEBUG("Error");
+       char *pConvertedStr     = NULL;
+       char *pConvertedData = NULL;
+       char *pNewData = NULL;
+       char *pReturnData = NULL;
 
-               *pBufLen = 0;
-               return false;
-       }
+       const char *pToCodeSet = "UTF-8";
+       const char *pFromCodeSet = NULL;
 
-       if (pPtr == NULL || pInBuf1 == NULL || pInBuf2 == NULL) {
-               MSG_DEBUG("Error");
+       switch (msgEncodingValue) {
+       case MSG_ENCODING_BASE64:
 
-               *pBufLen = 0;
-               return false;
-       }
+               pConvertedData = (char*)MsgDecodeBase64((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
+               MSG_DEBUG("MSG_ENCODING_BASE64 bodyLength [%d]", nByte);
 
-       if (*pBufLen == 0) {
-               length = maxLen - (*pPtr);
-       } else {
-               length = (*pBufLen) - (*pPtr);
-       }
+               pTemp = pConvertedData;
+               nTemp = nByte;
 
-       if (length < 0)
-               length = 0;
+               break;
 
-       if ((*ppBuf) == NULL) {
-               memset(pInBuf1, 0, maxLen);
-               (*ppBuf) = pInBuf1;
-       } else if ((*ppBuf) == pInBuf1) {
-               memset(pInBuf2, 0, maxLen);
-               if (length)
-                       memcpy(pInBuf2, pInBuf1 + (*pPtr), length);
-               (*ppBuf) = pInBuf2;
-       } else {
-               memset(pInBuf1, 0, maxLen);
-               if (length)
-                       memcpy(pInBuf1, pInBuf2 + (*pPtr), length);
-               (*ppBuf) = pInBuf1;
-       }
+       case MSG_ENCODING_QUOTE_PRINTABLE:
 
-       (*pPtr) = 0;
+               pConvertedData = (char*)MsgDecodeQuotePrintable((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
+               MSG_DEBUG("MSG_ENCODING_QUOTE_PRINTABLE bodyLength [%d]", nByte);
 
-       if (*pOffset == endOfFile) {
-               *pBufLen = length;
-               return true;
-       }
+               pTemp = pConvertedData;
+               nTemp = nByte;
 
-       if (maxLen == length) {
-               /* (*pPtr) was 0 */
-               if (MsgReadFileForDecode(pFile, (*ppBuf), maxLen, &nRead) == false)
-                       return false;
+               break;
 
-               *pBufLen = nRead;
-       } else {
-               if (MsgReadFileForDecode(pFile, (*ppBuf) + length, maxLen - length, &nRead) == false)
-                       return false;
+       default:
 
-               *pBufLen = length + nRead;
-       }
+               MSG_DEBUG("encoding val [%d] bodyLength [%d]", msgEncodingValue, nRead);
+               pTemp = pData;
+               nTemp = nRead;
 
-       if ((*pOffset = MsgFtell(pFile)) == -1L) {
-               MSG_DEBUG("MsgFtell Error");
-               return false;
+               break;
        }
 
-       MSG_END();
+       if (MmsIsTextType(msgTypeValue)) {
 
-       return true;
-}
+               if (msgCharsetValue == MSG_CHARSET_US_ASCII) {
+                       pNewData = pTemp;
+                       *npRead = nTemp;
+               } else if (msgCharsetValue == MSG_CHARSET_UTF8) {
 
+                       // skip BOM (Byte Order Mark) bytes .. (Please refer to the http://www.unicode.org/faq/utf_bom.html#BOM)
+                       if (nTemp >= 3) {
+                               if (((UINT8)pTemp[0]) == 0xEF && ((UINT8)pTemp[1]) == 0xBB && ((UINT8)pTemp[2]) == 0xBF) {
+                                       pTemp += 3;
+                                       nTemp -= 3;
+                               }
+                       }
 
-bool MsgGetTypeByFileName(int *type, char *szFileName)
-{
-       char *pExt   = NULL;
-       AvCodecType AvType = AV_CODEC_NONE;
+                       pNewData = pTemp;
+                       *npRead = nTemp;
+               } else {
 
-       pExt = strrchr(szFileName, '.');
-       if (pExt == NULL || pExt[0] == '\0')
-               goto __CATCH;
+                       UINT16 MIBenum = MmsGetBinaryValue(MmsCodeCharSet, msgCharsetValue);
 
-       pExt++;
+                       pFromCodeSet = MmsGetTextByCode(MmsCodeCharSet, MIBenum);
 
-       if (strcasecmp(pExt, "mp4") == 0 ||strcasecmp(pExt, "mpeg4") == 0 ||strcasecmp(pExt, "3gp") == 0 ||strcasecmp(pExt, "3gpp") == 0) {
+                       MSG_DEBUG("char set enum = [%d], MIBenum = [%d], str = [%s]", msgCharsetValue, MIBenum, pFromCodeSet);
 
-               if (szFileName[0] != '/')
-                       goto __CATCH;
+                       if (pFromCodeSet) {
+                               MSG_DEBUG("Convert to UTF-8");
 
-               AvType = AvGetFileCodecType(szFileName);
-               MSG_DEBUG("AvType(0x%x)\n", AvType);
+                               if (MmsPluginTextConvert(pToCodeSet, pFromCodeSet, pTemp, nTemp, &pConvertedStr, npRead) == true) {
+                                       pNewData = pConvertedStr;
+                               } else {
+                                       MSG_DEBUG("Failed MmsPluginTextConvert");
+                                       pNewData = pTemp;
+                                       *npRead = nTemp;
+                               }
 
-               switch (AvType) {
-               case AV_DEC_AUDIO_MPEG4:
-                       *type = MIME_AUDIO_MP4;
-                       break;
+                       } else {//unsupported charset
+                               MSG_DEBUG("unsupported charset");
+                               pNewData = pTemp;
+                               *npRead = nTemp;
+                       }
+               }
 
-               case AV_DEC_VIDEO_MPEG4:
-                       *type = MIME_VIDEO_MP4;
-                       break;
+       } else {
+               pNewData = pTemp;
+               *npRead = nTemp;
+       }
 
-               default:
-                       *type = MIME_VIDEO_3GPP;
-                       break;
-               }
-               return true;
+       pReturnData = (char *)malloc(*npRead);
+       if (pReturnData == NULL) {
+               MSG_DEBUG("pReturnData alloc fail.");
+               goto __CATCH;
        }
 
-       if (strcasecmp(pExt, "amr") == 0) {
-               *type = MIME_AUDIO_AMR;
-               return true;
-       } else if ((strcasecmp(pExt, "mid") == 0) || (strcasecmp(pExt, "midi") == 0)) {
-               *type = MIME_AUDIO_MIDI;
-               return true;
-       } else if (strcasecmp(pExt, "imy") == 0) {
-               *type = MIME_TEXT_X_IMELODY;
-               return true;
+       if (pNewData != NULL) {
+               memset(pReturnData, 0, *npRead);
+               memcpy(pReturnData, pNewData, *npRead);
        }
 
-       *type = MimeGetMimeFromExtInt((const char*)pExt);
-       MSG_DEBUG("filename [%s], type [%d]", szFileName, *type);
-       return true;
+       if (pConvertedData) {
+               free(pConvertedData);
+               pConvertedData = NULL;
+       }
+
+       if (pConvertedStr) {
+               free(pConvertedStr);
+               pConvertedStr = NULL;
+       }
+
+       return pReturnData;
 
 __CATCH:
 
-       *type = MIME_UNKNOWN;
-       MSG_DEBUG("filename [%s], type [%d]", szFileName, *type);
-       return false;
+       if (pConvertedData) {
+               free(pConvertedData);
+               pConvertedData = NULL;
+       }
 
-}
+       if (pConvertedStr) {
+               free(pConvertedStr);
+               pConvertedStr = NULL;
+       }
 
+       return NULL;
+}
 
-/*
- *     This function write media data from raw data to file.
- *     @param  pMsg
- *     @param  pPartBody
- *     @param  pszMailboxPath  : path of mailbox
- *     @param  pszMsgFilename  : name of msg file
- *     @param  index                   : used for file naming
- *     @param  bSave                   : if true, file will be save otherwise just filename will be stored.
- */
-static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody, char *pszMailboxPath, char *pszMsgFilename, int index, bool bSave)
+static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex, char *outBuf, int outBufLen)
 {
-       FILE *pFile = NULL;
-       char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };        // file name of temp file
-       char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, }; // full absolute path of temp file.
-       bool bFileExist = false;
-       MSG_BEGIN();
+       char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
+       char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
+       const char *pExt = NULL;
 
-       if (!pPartType) {
-               MSG_DEBUG("pPartType is NULL");
+       SECURE_SLOGD("Input : type  [0x%x], drmType [%d], filename [%s]", iMsgType, drmType, szFileName);
+
+       if (szFileName == NULL)
                return false;
-       }
 
-       if (pPartType->type == MIME_APPLICATION_SMIL) {
-               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", "smil.txt");
+       //Filename
+       int inp_len = strlen(szFileName);
+       if (inp_len > 0) {
+
+               pExt = strrchr(szFileName, '.');
+
+               if (pExt != NULL && *(pExt + 1) != '\0') {
+                       pExt = pExt +1;
+               } else {
+                       pExt = NULL;
+               }
+
+               MsgGetFileNameWithoutExtension(szTempFileName, szFileName);
        } else {
-               if (pPartType->param.szName[0] != '\0') {
-                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", pPartType->param.szName);
-               } else if (pPartType->param.szFileName[0] != '\0') {
-                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", pPartType->param.szFileName);
+               if (nUntitleIndex >= 1) {
+                       snprintf(szTempFileName, sizeof(szTempFileName), "%s_%d", "untitled", nUntitleIndex);
                } else {
-                       snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%lu", (unsigned long)index);
+                       snprintf(szTempFileName, sizeof(szTempFileName), "%s", "untitled");
                }
        }
 
+       //extension
+       if (iMsgType == MIME_APPLICATION_VND_OMA_DRM_MESSAGE)
+               pExt = "dm";
+       else if (iMsgType == MIME_APPLICATION_VND_OMA_DRM_CONTENT)
+               pExt = "dcf";
 
-#ifndef __SUPPORT_DRM__
-       __MsgMakeFileName(pPartType->type, szFileName, 0);      //FL & CD -> extension(.dm) SD -> extension(.dcf)
-#else
-       __MsgMakeFileName(pPartType->type, szFileName, pPartType->drmInfo.drmType, 0, szFileName, sizeof(szFileName));  //FL & CD -> extension(.dm) SD -> extension(.dcf)
-       if (MsgDRMIsForwardLockType(pPartType->drmInfo.drmType))
-               MsgChangeDrm2FileName(szFileName);
-#endif
+       if (pExt == NULL) { // find ext from content type
 
+               if (iMsgType == MIME_APPLICATION_OCTET_STREAM || iMsgType == MIME_UNKNOWN) {
+                       MSG_DEBUG("unsupported MsgType [%d]", iMsgType);
+                       goto __CATCH;
+               }
 
-       snprintf(szFullPath, MSG_FILEPATH_LEN_MAX, "%s%s.dir/%s", pszMailboxPath, pszMsgFilename, szFileName);  // get absolute path of each temp file of each part
-       snprintf(pPartType->param.szFileName, MSG_FILENAME_LEN_MAX+1, "%s.dir/%s", pszMsgFilename, szFileName);// store relative path of each temp file of each part including sub folder.
+               pExt = MimeGetExtFromMimeInt((MimeType)iMsgType);
+       }
 
-       if (pPartType->param.szName[0]  == '\0') {
-               snprintf(pPartType->param.szName, MSG_LOCALE_FILENAME_LEN_MAX+1, "%s", szFileName);
-               MSG_DEBUG("Set Name : %s", pPartType->param.szName);
+       //Filename + extension
+       if (pExt) {
+               snprintf(szTemp, sizeof(szTemp), "%s.%s", szTempFileName, pExt);
+       } else {
+               MSG_DEBUG("Failed to get extension of that mime data file.");
+               goto __CATCH;
        }
 
-       if (pPartType->type == MIME_APPLICATION_OCTET_STREAM)
-               MsgGetTypeByFileName(&pPartType->type, szFullPath);
+       snprintf(outBuf, outBufLen, "%s", szTemp);
+       SECURE_SLOGD("Result : filename [%s]", outBuf);
+       return true;
 
-       // save file
-       bFileExist = MsgAccessFile(szFullPath, F_OK);
+__CATCH:
+       return false;
+}
 
-       MSG_DEBUG("save flag  [%d],  filepath [%s], file exist [%d]", bSave, szFullPath, bFileExist);
+bool MsgGetFileNameWithoutExtension (char *szOutputName, char *szName)
+{
+       char *pszExt = NULL;
 
-       if (bSave == true && bFileExist == false) {
+       if (szOutputName == NULL) {
+               MSG_DEBUG("szOutputName is NULL");
+               return false;
+       }
 
-               if ((pFile = MsgOpenFile(szFullPath, "wb+")) == NULL) {
-                       MSG_DEBUG("MsgOpenFile failed");
-                       goto __CATCH;
-               }
+       strncpy(szOutputName, szName, strlen(szName));
 
-               if (__MmsGetMediaPartData(pPartType, pPartBody, pFile) == false) {
-                       MSG_DEBUG("MmsGetMediaPartData fail [index:%d]\n", index);
-                       goto __CATCH;
+       if ((pszExt = strrchr(szOutputName, '.'))) {
+               if (pszExt[0] == '.')
+                       pszExt[0] = '\0';
+       }
+
+       return true;
+}
+
+bool MsgGetFileName(char *szFilePath, char *szFileName, int size)
+{
+       char *filename = NULL;
+       if (szFilePath) {
+               filename = strrchr(szFilePath, '/');
+               if (filename != NULL) {
+                       snprintf(szFileName, size, "%s", filename + 1);
+               } else {
+                       snprintf(szFileName, size, "%s", szFilePath);
                }
+       } else {
+               return false;
+       }
 
-               MsgCloseFile(pFile);
-               pFile = NULL;
+       return true;
+}
 
-               snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", szFullPath);
-               pPartBody->offset = 0;
-               pPartBody->size = MsgGetFileSize(pPartBody->szOrgFilePath);
+bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
+{
+       MmsMsg *pMsg = NULL;
+       MsgMultipart *pPart = NULL;
 
+       if (pHeader == NULL) {
+               MSG_DEBUG("Invalid pHeader input. It's null");
+               return false;
+       }
 
-               if (pPartType->drmInfo.drmType != MSG_DRM_TYPE_NONE) {
-                       MsgDrmRegisterFile(MSG_MODE_FILE, szFullPath, strlen(szFullPath));
+       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
 
-                       /* change szDrm2FullPath as current content path*/
-                       if (pPartType->drmInfo.szDrm2FullPath) {
-                               free(pPartType->drmInfo.szDrm2FullPath);
-                               pPartType->drmInfo.szDrm2FullPath = MsgStrCopy(szFullPath);
-                       }
+       MmsInitMsgType(pHeader);
+
+
+       /* Requires header of non-presentation */
+       if (MsgIsMultipart(pMsg->msgType.type)) {
+               MSG_DEBUG("Multipart header [index = %d] \n", index);
+
+               pPart = pMsg->msgBody.body.pMultipart;
+
+               while (pPart && index--)
+                       pPart = pPart->pNext;
+
+               if (pPart == NULL) {
+                       MSG_DEBUG("There is no such msg part.");
+                       return false;
                }
-               MSG_DEBUG("Save Part File to [%s]", pPartBody->szOrgFilePath);
+
+               memcpy(pHeader, &pPart->type, sizeof(MsgType));
        } else {
-               snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", szFullPath);
-               pPartBody->offset = 0;
-               pPartBody->size = MsgGetFileSize(pPartBody->szOrgFilePath);
-               MSG_DEBUG("Set Part File to [%s]", pPartBody->szOrgFilePath);
+               MSG_DEBUG("Requires singlepart header");
+               memcpy(pHeader, &pMsg->msgType, sizeof(MsgType));
        }
 
-       MSG_END();
        return true;
+}
 
-__CATCH:
 
-       if (pFile != NULL) {
-               MsgCloseFile(pFile);
-               pFile = NULL;
-       }
-       MSG_END();
-       return false;
+///////////////////////////////////////////////////////////////////////////////
+
+MmsPluginDecoder *MmsPluginDecoder::pInstance = NULL;
+
+MmsPluginDecoder *MmsPluginDecoder::instance()
+{
+       if (!MmsPluginDecoder::pInstance)
+               MmsPluginDecoder::pInstance = new MmsPluginDecoder();
+
+       return MmsPluginDecoder::pInstance;
 }
 
-bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE* pFile)
+MmsPluginDecoder::MmsPluginDecoder(){}
+MmsPluginDecoder::~MmsPluginDecoder(){}
+
+void MmsPluginDecoder::decodeMmsPdu(MmsMsg *pMsg, msg_message_id_t msgID, const char *pduFilePath)
 {
-       int nRead = 0;
-       int nRead2 = 0;
-       char *pData = NULL;
-       char *pNewData = NULL;
-       char *pTempData = NULL;
-       int msgEncodingValue = 0;
-       int msgTypeValue = 0;
-       int msgCharsetValue     = 0;
-       int cidLen = 0;
-       char *szCid = NULL;
-       int offset = 0;
-       int size = 0;
+       MSG_BEGIN();
 
-       msgEncodingValue = pPartType->encoding;
-       msgTypeValue = pPartType->type;
-       msgCharsetValue = pPartType->param.charset;
+       FILE *pFile     = NULL;
+       MsgMultipart *pMultipart = NULL;
+       int nSize = 0;
+       char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
+       char szTempMediaDir[MSG_FILEPATH_LEN_MAX] = {0, };
 
-       cidLen = MsgStrlen(szCid);
+       MmsInitHeader();
 
-       offset = pPartBody->offset;
-       size = pPartBody->size;
+       pMsg->msgID = msgID;
 
-       if (pPartBody->szOrgFilePath[0]) {
-               pTempData = MsgOpenAndReadMmsFile(pPartBody->szOrgFilePath, offset, size, &nRead);
+       snprintf(szFullPath, sizeof(szFullPath), "%s", pduFilePath);
 
-               if (pTempData == NULL) {
-                       MSG_DEBUG("pTempData read fail");
-                       goto __CATCH;
-               }
+       MsgGetFileName(szFullPath, pMsg->szFileName, sizeof(pMsg->szFileName));
 
-               pData = pTempData;
-       } else if (pPartBody->body.pText) {
-               pData = pPartBody->body.pText;
-               nRead = pPartBody->size;
+       if (MsgGetFileSize(szFullPath, &nSize) == false) {
+               MSG_FATAL("Fail MsgGetFileSize");
+               goto __CATCH;
        }
 
-       if (pData == NULL) {
-               MSG_DEBUG("there is no data");
-               goto __RETURN;
+       pFile = MsgOpenFile(szFullPath, "rb");
+       if (pFile == NULL) {
+               MSG_SEC_DEBUG("Fail MsgOpenFile [%s]", szFullPath);
+               goto __CATCH;
        }
 
-       pNewData = __MmsGetBinaryUTF8Data(pData, nRead, msgEncodingValue, msgTypeValue, msgCharsetValue, &nRead2);
-       pPartType->encoding = MSG_ENCODING_BINARY;
-
-       if (__MsgIsText(msgTypeValue))
-               pPartType->param.charset = MSG_CHARSET_UTF8;
+       MmsRegisterDecodeBuffer();
 
-       if (MsgWriteFile(pNewData, sizeof(char), nRead2,  pFile) != (size_t)nRead2) {
-               MSG_DEBUG("file writing fail");
+       if (MmsBinaryDecodeMsgHeader(pFile, nSize) == false) {
+               MSG_FATAL("Fail to MmsBinaryDecodeMsgHeader");
+               goto __CATCH;
+       }
 
+       if (MmsBinaryDecodeMsgBody(pFile, szFullPath, nSize) == false) {
+               MSG_FATAL("Fail to MmsBinaryDecodeMsgBody");
                goto __CATCH;
        }
 
-__RETURN:
+       /* Set mmsHeader.msgType & msgBody to pMsg ----------- */
 
-       if (pNewData) {
-               free(pNewData);
-               pNewData = NULL;
-       }
+       memcpy(&(pMsg->msgType), &(mmsHeader.msgType), sizeof(MsgType));
+       memcpy(&(pMsg->msgBody), &(mmsHeader.msgBody), sizeof(MsgBody));
 
-       if (pTempData) {
-               free(pTempData);
-               pTempData = NULL;
-       }
+{//attribute convert mmsHeader -> mmsAttribute
 
-       return true;
+       pMsg->mmsAttrib.contentType = (MimeType)mmsHeader.msgType.type;
 
-__CATCH:
+       pMsg->mmsAttrib.date = mmsHeader.date;
 
-       if (pNewData) {
-               free(pNewData);
-               pNewData = NULL;
+       if (mmsHeader.deliveryReport == MMS_REPORT_YES) {
+               pMsg->mmsAttrib.bAskDeliveryReport = true;
        }
 
-       if (pTempData) {
-               free(pTempData);
-               pTempData = NULL;
-       }
+       memcpy(&pMsg->mmsAttrib.deliveryTime, &mmsHeader.deliveryTime, sizeof(MmsTimeStruct));
 
-       return false;
-}
+       memcpy(&pMsg->mmsAttrib.expiryTime, &mmsHeader.expiryTime, sizeof(MmsTimeStruct));
 
-static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue, int msgTypeValue, int msgCharsetValue, int *npRead)
-{
-       int nChar = 0;
-       int nByte = 0;
-       int nTemp = 0;
-       char *pTemp = NULL;
-       unsigned short *mszTempStr = NULL;
-       char *pConvertedStr     = NULL;
-       char *pConvertedData = NULL;
-       char *pNewData = NULL;
-       char *pReturnData = NULL;
+       pMsg->mmsAttrib.msgClass = mmsHeader.msgClass;
 
+       snprintf(pMsg->szMsgID, sizeof(pMsg->szMsgID), "%s", mmsHeader.szMsgID);
 
-       switch (msgEncodingValue) {
-       case MSG_ENCODING_BASE64:
+       pMsg->mmsAttrib.msgType = mmsHeader.type;
 
-               pConvertedData = (char*)MsgDecodeBase64((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
-               MSG_DEBUG("MSG_ENCODING_BASE64 bodyLength [%d]", nByte);
+       pMsg->mmsAttrib.version = mmsHeader.version;
 
-               pTemp = pConvertedData;
-               nTemp = nByte;
+       pMsg->mmsAttrib.msgSize = mmsHeader.msgSize;
 
-               break;
+       pMsg->mmsAttrib.priority = mmsHeader.priority;
 
-       case MSG_ENCODING_QUOTE_PRINTABLE:
+       if (mmsHeader.readReply == MMS_REPORT_YES) {
+               pMsg->mmsAttrib.bAskReadReply = true;
+       }
 
-               pConvertedData = (char*)MsgDecodeQuotePrintable((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
-               MSG_DEBUG("MSG_ENCODING_QUOTE_PRINTABLE bodyLength [%d]", nByte);
+       snprintf(pMsg->mmsAttrib.szSubject, sizeof(pMsg->mmsAttrib.szSubject), "%s", mmsHeader.szSubject);
 
-               pTemp = pConvertedData;
-               nTemp = nByte;
+       snprintf(pMsg->szTrID, sizeof(pMsg->szTrID), "%s", mmsHeader.szTrID);
 
-               break;
+       pMsg->mmsAttrib.retrieveStatus = mmsHeader.retrieveStatus;
 
-       default:
+       //FIXME:: mmsHeader will release after delete global mmsHeader
+       //memset(&(mmsHeader.msgBody), 0x00, sizeof(MsgBody));//After copy to MmsMsg
+}
+       if (pMsg->msgBody.pPresentationBody) {
+               if(MsgFseek(pFile, pMsg->msgBody.pPresentationBody->offset, SEEK_SET) < 0)
+                       goto __CATCH;
 
-               MSG_DEBUG("encoding val [%d] bodyLength [%d]", msgEncodingValue, nRead);
-               pTemp = pData;
-               nTemp = nRead;
+               pMsg->msgBody.pPresentationBody->body.pText = (char *)malloc(pMsg->msgBody.pPresentationBody->size + 1);
+               if (pMsg->msgBody.pPresentationBody->body.pText == NULL)
+                       goto __CATCH;
 
-               break;
+               memset(pMsg->msgBody.pPresentationBody->body.pText, 0, pMsg->msgBody.pPresentationBody->size + 1);
+
+               ULONG nRead = 0;
+               nRead = MsgReadFile(pMsg->msgBody.pPresentationBody->body.pText, sizeof(char), pMsg->msgBody.pPresentationBody->size, pFile);
+               if (nRead == 0)
+                       goto __CATCH;
+
+       }
+
+       MsgCloseFile(pFile);
+       pFile = NULL;
+       /* nPartCount */
+       pMsg->nPartCount = 0;
+
+       if (MsgIsMultipart(mmsHeader.msgType.type) == true) {
+               pMultipart = pMsg->msgBody.body.pMultipart;
+               while (pMultipart) {
+                       pMsg->nPartCount++;
+                       pMultipart = pMultipart->pNext;
+               }
+       } else {
+               if (pMsg->msgBody.size > 0)
+                       pMsg->nPartCount++;
        }
 
-       if (__MsgIsText(msgTypeValue)) {
-               /* charset converting */
-
-               switch (msgCharsetValue) {
-               case MSG_CHARSET_UTF16:
-               case MSG_CHARSET_USC2:
-
-                       MSG_DEBUG("MSG_CHARSET_USC2");
+       /*      make temporary  */
+       snprintf(szTempMediaDir, MSG_FILEPATH_LEN_MAX, "%s%s.dir", MSG_DATA_PATH, pMsg->szFileName);
 
-                       if (((UINT8)pTemp[0]) == 0xFF && ((UINT8)pTemp[1]) == 0xFE) {
-                               nChar = (nTemp / 2 - 1);
+       if (MsgIsMultipart(pMsg->msgType.type) == true) {
+               int partIndex = 0;
+               pMultipart = pMsg->msgBody.body.pMultipart;
 
-                               mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
-                               if (mszTempStr == NULL) {
-                                       MSG_DEBUG("Memory Full !!!");
+               //if (bSavePartsAsTempFiles) {
+                       if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+                               if (errno == EEXIST) {
+                                       MSG_SEC_DEBUG("exist dir : [%s]", szTempMediaDir);
+                               } else {
+                                       MSG_SEC_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
                                        goto __CATCH;
                                }
-
-                               memcpy(mszTempStr, ((unsigned short*)pTemp + 1), nChar * sizeof(unsigned short));
-
-                               nByte = __MsgGetUnicode2UTFCodeSize(((unsigned short*)pTemp + 1), nChar);
-                               if (nByte < 3)
-                                       nByte = 3; //min value
-
-                               pConvertedStr = (char *)malloc(nByte + 1);
-                               if (pConvertedStr != NULL)
-                                       __MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
                        } else {
-                               nChar = (nTemp / 2);
-
-                               mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
-                               if (mszTempStr == NULL) {
-                                       MSG_DEBUG("Memory Full !!!");
-                                       goto __CATCH;
-                               }
-
-                               memcpy(mszTempStr, ((unsigned short*)pTemp), nChar * sizeof(unsigned short));
-
-                               nByte = __MsgGetUnicode2UTFCodeSize(((unsigned short*)pTemp), nChar);
-
-                               pConvertedStr = (char *)malloc(nByte + 1);
-                               if (pConvertedStr)
-                                       __MsgUnicode2UTF ((unsigned char*)pConvertedStr, nByte + 1, mszTempStr, nChar);
+                               MSG_SEC_DEBUG("make dir : [%s]", szTempMediaDir);
                        }
+               //}
 
-                       if (pConvertedStr != NULL)
-                               pNewData = pConvertedStr;
-
-                       *npRead = nByte + 1;
+               if (pMsg->msgBody.pPresentationBody) {
+                       if (__MmsMultipartSaveAsTempFile(&pMsg->msgBody.presentationType, pMsg->msgBody.pPresentationBody,
+                                                                                               (char*)MSG_DATA_PATH, pMsg->szFileName, 0, true) == false)
+                               goto __CATCH;
+               }
 
-                       break;
+               while (pMultipart) {
 
-               case MSG_CHARSET_US_ASCII:
+                       if (__MmsMultipartSaveAsTempFile(&pMultipart->type, pMultipart->pBody,
+                                                                                       (char*)MSG_DATA_PATH, pMsg->szFileName, partIndex, true) == false)
+                               goto __CATCH;
 
-                       MSG_DEBUG("MSG_CHARSET_US_ASCII");
+                       MmsPrintMulitpart(pMultipart, partIndex);
 
-                       /* fall through */
-               case MSG_CHARSET_UTF8:
+                       pMultipart = pMultipart->pNext;
+                       partIndex ++;
+               }
 
-                       MSG_DEBUG("MSG_CHARSET_UTF8 or Others");
+       } else { //single part
+               if (pMsg->nPartCount > 0) {
 
-                       // skip BOM (Byte Order Mark) bytes .. (Please refer to the http://www.unicode.org/faq/utf_bom.html#BOM)
-                       if (nTemp >= 3) {
-                               if (((UINT8)pTemp[0]) == 0xEF && ((UINT8)pTemp[1]) == 0xBB && ((UINT8)pTemp[2]) == 0xBF) {
-                                       pTemp += 3;
-                                       nTemp -= 3;
+                       //if (bSavePartsAsTempFiles) {
+                               if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+                                       if (errno == EEXIST) {
+                                               MSG_DEBUG("exist dir : [%s]", szTempMediaDir);
+                                       } else {
+                                               MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
+                                               goto __CATCH;
+                                       }
+                               } else {
+                                       MSG_DEBUG("make dir : [%s]", szTempMediaDir);
                                }
-                       }
-                       pNewData = pTemp;
-                       *npRead = nTemp;
+                       //}
 
-                       break;
-
-               case MSG_CHARSET_ISO_8859_7:
-
-                       /* Greek */
-
-                       MSG_DEBUG("MSG_CHARSET_ISO_8859_7");
+                       if (__MmsMultipartSaveAsTempFile(&pMsg->msgType, &pMsg->msgBody,
+                                                                                       (char*)MSG_DATA_PATH, pMsg->szFileName, 0, true) == false)
+                               goto __CATCH;
+               }
+       }
+       MSG_DEBUG("### Success ###");
+       MSG_END();
+       return;
 
-                       nByte = __MsgGetLatin72UTFCodeSize((unsigned char*)pTemp, nTemp);
-                       pConvertedStr = (char *)malloc(nByte + 1);
-                       if (pConvertedStr)
-                               __MsgLatin7code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
+__CATCH:
 
-                       pNewData = pConvertedStr;
-                       *npRead = nByte + 1;
+       MmsInitHeader();
+       MmsUnregisterDecodeBuffer();
 
-                       break;
+       if (pFile != NULL) {
+               MsgCloseFile(pFile);
+               pFile = NULL;
+       }
 
-               case MSG_CHARSET_ISO_8859_9:
 
-                       /* Turkish */
-                       MSG_DEBUG("MSG_CHARSET_ISO_8859_9");
+       MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
 
-                       nByte = __MsgGetLatin52UTFCodeSize((unsigned char*)pTemp, nTemp);
-                       pConvertedStr = (char *)malloc(nByte + 1);
-                       if (pConvertedStr)
-                                       __MsgLatin5code2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
+       MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
 
-                       pNewData = pConvertedStr;
-                       *npRead = nByte + 1;
+       MSG_DEBUG("### Fail ###");
+       MSG_END();
+       return;
 
-                       break;
+}
 
-               default:
+//CID 41989: Removed function decodeMmsPdu which is unused.
+#if 0
+void MmsPluginDecoder::decodeMmsPdu(MMS_DATA_S *pMmsData, const char *pduFilePath)
+{
+       MSG_BEGIN();
 
-                       MSG_DEBUG("Other charsets");
+       FILE *pFile     = NULL;
+       MsgMultipart * iter_multipart = NULL;
+       int nSize = 0;
+       char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
 
-                       nByte = __MsgGetLatin2UTFCodeSize((unsigned char*)pTemp, nTemp);
-                       pConvertedStr = (char *)malloc(nByte + 1);
-                       if (pConvertedStr)
-                               __MsgLatin2UTF((unsigned char*)pConvertedStr, nByte + 1, (unsigned char*)pTemp, nTemp);
+       MmsInitHeader();
 
-                       pNewData = pConvertedStr;
-                       *npRead = nByte + 1;
+       //pMsg->msgID = msgID;
 
-                       break;
-               }
-       } else {
-               pNewData = pTemp;
-               *npRead = nTemp;
-       }
+       snprintf(szFullPath, sizeof(szFullPath), "%s", pduFilePath);
 
-       pReturnData = (char *)malloc(*npRead);
-       if (pReturnData == NULL) {
-               MSG_DEBUG("pReturnData alloc fail.");
+       //MsgGetFileName(szFullPath, pMsg->szFileName, sizeof(pMsg->szFileName));
 
+       if (MsgGetFileSize(szFullPath, &nSize) == false) {
+               MSG_FATAL("Fail MsgGetFileSize");
                goto __CATCH;
        }
 
-       if (pNewData != NULL) {
-               memset(pReturnData, 0, *npRead);
-               memcpy(pReturnData, pNewData, *npRead);
-       }
-
-       if (pConvertedData) {
-               free(pConvertedData);
-               pConvertedData = NULL;
+       pFile = MsgOpenFile(szFullPath, "rb");
+       if (pFile == NULL) {
+               MSG_SEC_DEBUG("Fail MsgOpenFile [%s]", szFullPath);
+               goto __CATCH;
        }
 
-       if (pConvertedStr) {
-               free(pConvertedStr);
-               pConvertedStr = NULL;
-       }
+       MmsRegisterDecodeBuffer();
 
-       if (mszTempStr) {
-               free(mszTempStr);
-               mszTempStr = NULL;
+       if (MmsBinaryDecodeMsgHeader(pFile, nSize) == false) {
+               MSG_FATAL("Fail to MmsBinaryDecodeMsgHeader");
+               goto __CATCH;
        }
 
-       return pReturnData;
-
-__CATCH:
-
-       if (pConvertedData) {
-               free(pConvertedData);
-               pConvertedData = NULL;
+       if (MmsBinaryDecodeMsgBody(pFile, szFullPath, nSize) == false) {
+               MSG_FATAL("Fail to MmsBinaryDecodeMsgBody");
+               goto __CATCH;
        }
 
-       if (pConvertedStr) {
-               free(pConvertedStr);
-               pConvertedStr = NULL;
+       //set header
+       if (pMmsData->header == NULL) {
+               pMmsData->header = MsgMmsCreateHeader();
        }
 
-       if (mszTempStr) {
-               free(mszTempStr);
-               mszTempStr = NULL;
-       }
+       pMmsData->header->messageType = mmsHeader.type;
 
-       return NULL;
-}
+       pMmsData->header->mmsVersion = mmsHeader.version;
 
-#ifndef __SUPPORT_DRM__
-static bool __MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex)
-{
-       char szText[MSG_FILENAME_LEN_MAX+1]={0,};
-       char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
-       char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
-       char *pExt = NULL;
+       pMmsData->header->contentType = mmsHeader.msgType.type;
 
+       pMmsData->header->date = mmsHeader.date;
 
-       MSG_DEBUG("iMsgType = %d, szFileName = %s", iMsgType, szFileName);
+       pMmsData->header->messageSize  = mmsHeader.msgSize;
 
-       if (szFileName == NULL)
-               return false;
+       pMmsData->header->mmsPriority = mmsHeader.priority;
 
-       if (szFileName && (szFileName[0] != '\0')) {
-               MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
+       pMmsData->header->messageClass = mmsHeader.msgClass;
 
-               pExt = strrchr(szTempFileName, '.');
-               if (pExt == NULL) {
-                       memset  (szText, 0, MSG_FILENAME_LEN_MAX+1);
-                       strncpy(szText, szTempFileName, MSG_FILEPATH_LEN_MAX - 1);
-                       strcat(szText, ".");                    // add '.'
-               } else {
-                       memset  (szText, 0, MSG_FILENAME_LEN_MAX+1);
-                       strncpy(szText, szTempFileName, pExt+1 - szFileName);   // add '.'
-               }
-       } else {
-               if (nUntitleIndex >= 1) {
-                       snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s_%d.", "Untitled", nUntitleIndex);
-               } else {
-                       snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s.", "Untitled");
-               }
+       if (mmsHeader.deliveryReport == MMS_REPORT_YES) {
+               pMmsData->header->bDeliveryReport = true;
        }
 
-       if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
-               MSG_DEBUG("unsupported MsgType");
-               goto __CATCH;
-       } else {
-               int             nLen = 0;
-               strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
-               if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
-                       MSG_DEBUG("Failed to get extension of that mime data file.");
-                       goto __CATCH;
-               }
-               nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
-               strncat(szTemp, pExt, nLen);
+       if (mmsHeader.readReply == MMS_REPORT_YES) {
+               pMmsData->header->bReadReport = true;
        }
 
+       memcpy(&pMmsData->header->delivery, &mmsHeader.deliveryTime, sizeof(MmsTimeStruct));
 
-       strcpy(szFileName, szTemp);
+       memcpy(&pMmsData->header->expiry, &mmsHeader.expiryTime, sizeof(MmsTimeStruct));
 
-       MSG_DEBUG("made szFileName = %s", szFileName);
 
-       return true;
+       snprintf(pMmsData->header->messageID, sizeof(pMmsData->header->messageID), "%s", mmsHeader.szMsgID);
 
-__CATCH:
-       {
-               char *p = NULL;
-               p = strrchr(szText, '.');
-               if (p != NULL)
-                       *p = 0;
-               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", szText);
+       snprintf(pMmsData->header->szSubject, sizeof(pMmsData->header->szSubject), "%s", mmsHeader.szSubject);
 
-               return false;
-       }
-}
-#else
-static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex, char *outBuf, int outBufLen)
-{
-       char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
-       char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
-       char *pExt = NULL;
+       snprintf(pMmsData->header->trID, sizeof(pMmsData->header->trID), "%s", mmsHeader.szTrID);
 
-       MSG_DEBUG("Input : type  [0x%x], drmType [%d], filename [%s]", iMsgType, drmType, szFileName);
+       //CID 41989: Moving assignment of iter_multipart before its de-referencing.
+       iter_multipart = mmsHeader.msgBody.body.pMultipart;
+       //set multipart
+       if (pMmsData->header->contentType == MIME_MULTIPART_RELATED || pMmsData->header->contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
 
-       if (szFileName == NULL)
-               return false;
+               MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
 
-       int inp_len = strlen(szFileName);
-       if (inp_len >0) {
-               MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
-       } else {
-               if (nUntitleIndex >= 1) {
-                       snprintf(szTempFileName, sizeof(szTempFileName), "%s_%d", "untitled", nUntitleIndex);
-               } else {
-                       snprintf(szTempFileName, sizeof(szTempFileName), "%s", "untitled");
-               }
-       }
+               pMultipart->type = MIME_APPLICATION_SMIL;
+               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", "application/smil");
+               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", mmsHeader.msgBody.presentationType.szContentID);
+               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", mmsHeader.msgBody.presentationType.szContentLocation);
+               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", mmsHeader.msgBody.presentationType.param.szName);
 
-       if (drmType == MSG_DRM_TYPE_SD) {
-               snprintf(szTemp, sizeof(szTemp), "%s.dcf", szTempFileName);
-       } else if (MsgDRMIsForwardLockType(drmType)) {
-               snprintf(szTemp, sizeof(szTemp), "%s.dm", szTempFileName);
-       } else {
-               if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
-                       MSG_DEBUG("unsupported MsgType");
-                       goto __CATCH;
-               } else {
+               //snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), MSG_DATA_PATH"%s", mmsHeader.msgBody.presentationType.param.szFileName);
 
-                       if (iMsgType == MIME_UNKNOWN) {
-                               MSG_DEBUG("Failed to get extension of that mime data file.");
-                               goto __CATCH;
-                       }
+               MsgBody *pBody = iter_multipart->pBody;
+               pMultipart->pMultipartData = MsgOpenAndReadMmsFile(pBody->szOrgFilePath, pBody->offset, pBody->size, (int*)&pMultipart->nMultipartDataLen);
 
-                       pExt = MimeGetExtFromMimeInt((MimeType)iMsgType);
-                       if (pExt) {
-                               snprintf(szTemp, sizeof(szTemp), "%s.%s", szTempFileName, pExt);
-                       } else {
-                               MSG_DEBUG("Failed to get extension of that mime data file.");
-                               goto __CATCH;
-                       }
-               }
+               pMmsData->smil = pMultipart;
        }
 
-       snprintf(outBuf, outBufLen, "%s", szTemp);
-       MSG_DEBUG("Result : filename [%s]", outBuf);
-       return true;
-
-__CATCH:
-       return false;
-}
-#endif
-
-bool MsgGetFileNameWithoutExtension (char *szOutputName, char *szName)
-{
-       char *pszExt = NULL;
-
-       if (szOutputName == NULL) {
-               MSG_DEBUG("szOutputName is NULL");
-               return false;
-       }
 
-       strncpy(szOutputName, szName, strlen(szName));
+       while (iter_multipart) {
 
-       if ((pszExt = strrchr(szOutputName, '.'))) {
-               if (pszExt[0] == '.')
-                       pszExt[0] = '\0';
-       }
+               MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
 
-       return true;
-}
+               pMultipart->type = (MimeType)iter_multipart->type.type;
 
-int MmsGetMediaPartCount(msg_message_id_t msgId)
-{
-       MmsMsg *pMsg;
+               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s",MimeGetMimeStringFromMimeInt(iter_multipart->type.type));
+               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", iter_multipart->type.szContentID);
+               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", iter_multipart->type.szContentLocation);
+               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", iter_multipart->type.param.szName);
 
-       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
+               //snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", iter_multipart->pBody->szOrgFilePath);
 
-       if (msgId != pMsg->msgID) {
-               MSG_DEBUG("Invalid Message Id");
-               return -1;
-       }
+               MsgBody *pBody = iter_multipart->pBody;
+               pMultipart->pMultipartData = MsgOpenAndReadMmsFile(pBody->szOrgFilePath, pBody->offset, pBody->size, (int*)&pMultipart->nMultipartDataLen);
 
-       return pMsg->nPartCount;
-}
 
-bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
-{
-       MmsMsg *pMsg = NULL;
-       MsgMultipart *pPart = NULL;
+#ifdef __SUPPORT_DRM__
+               if (iter_multipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
+                       pMultipart->drmType = iter_multipart->type.drmInfo.drmType;
+               }
+#endif
 
-       if (pHeader == NULL) {
-               MSG_DEBUG("Invalid pHeader input. It's null");
-               return false;
+               pMmsData->multipartlist = g_list_append(pMmsData->multipartlist, pMultipart);
+               iter_multipart = iter_multipart->pNext;
        }
 
-       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-
-       MmsInitMsgType(pHeader);
-
-
-       /* Requires header of non-presentation */
-       if (MsgIsMultipart(pMsg->msgType.type)) {
-               MSG_DEBUG("Multipart header [index = %d] \n", index);
-
-               pPart = pMsg->msgBody.body.pMultipart;
 
-               while (pPart && index--)
-                       pPart = pPart->pNext;
+       MSG_DEBUG("### SUCCESS ###");
+       MSG_END();
+       return;
+__CATCH:
 
-               if (pPart == NULL) {
-                       MSG_DEBUG("There is no such msg part.");
-                       return false;
-               }
+       MmsInitHeader();
+       MmsUnregisterDecodeBuffer();
 
-               memcpy(pHeader, &pPart->type, sizeof(MsgType));
-       } else {
-               MSG_DEBUG("Requires singlepart header");
-               memcpy(pHeader, &pMsg->msgType, sizeof(MsgType));
+       if (pFile != NULL) {
+               MsgCloseFile(pFile);
+               pFile = NULL;
        }
 
-       return true;
+       MSG_DEBUG("### Fail ###");
+       MSG_END();
+       return;
 }
-
-static bool __MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index)
-{
-       MSG_DEBUG("------------------------------");
-       MSG_DEBUG("[%dth] multipart info", index);
-       MSG_DEBUG("header size [%d], body size [%d]", pMultipart->type.size, pMultipart->type.contentSize);
-       MSG_DEBUG("content type [%s]", MmsDebugGetMimeType((MimeType)pMultipart->type.type));
-       MSG_DEBUG("content ID [%s]", pMultipart->type.szContentID);
-       MSG_DEBUG("content location [%s]", pMultipart->type.szContentLocation);
-       MSG_DEBUG("parameter Name [%s]", pMultipart->type.param.szName);
-       MSG_DEBUG("parameter Filename[%s]", pMultipart->type.param.szFileName);
-
-       if (pMultipart->type.type == MIME_TEXT_PLAIN) {
-               MSG_DEBUG("text info : charset [%d], name [%s]", pMultipart->type.param.charset, pMultipart->type.param.szName);
-       }
-#ifdef __SUPPORT_DRM__
-       if (pMultipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
-               MSG_DEBUG("drm info");
-               MSG_DEBUG("drm type [%d] (0: NONE 1: Fowward Lock, 2:Combined Delivery, 3: Separated Delivery)", pMultipart->type.drmInfo.drmType);
-               MSG_DEBUG("drm content type [%s]", MmsDebugGetMimeType((MimeType)pMultipart->type.drmInfo.contentType));
-               MSG_DEBUG("drm content URI [%s]", pMultipart->type.drmInfo.szContentURI);
-               MSG_DEBUG("drm2FullPath [%s]", pMultipart->type.drmInfo.szDrm2FullPath);
-       }
 #endif
-       MSG_DEBUG("------------------------------");
-       return true;
-}
index a349358..160abdb 100755 (executable)
@@ -1,90 +1,55 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <string.h>
+
+#if MSG_DRM_SUPPORT
 #include <drm_client_types.h>
 #include <drm_client.h>
-#include "MsgMmsTypes.h"
+#endif
+
 #include "MsgDrmWrapper.h"
 #include "MmsPluginDrm.h"
 #include "MmsPluginCodec.h"
 #include "MmsPluginMIME.h"
 #include "MmsPluginDebug.h"
-#include "MmsPluginUtil.h"
-
-#ifdef __SUPPORT_DRM__
-
-MmsDrm2ConvertState    mmsDrm2ConvertState;
-
-MsgDrmType MsgGetDRMType(MsgType *pMsgType, MsgBody *pMsgBody)
-{
-       MsgDrmType drmType = MSG_DRM_TYPE_NONE;
-       MsgMultipart *pMultipart = NULL;
-
-       if (MsgIsMultipart(pMsgType->type)) {
-               pMultipart = pMsgBody->body.pMultipart;
-               while (pMultipart) {
-                       if (drmType < pMultipart->type.drmInfo.drmType)
-                               drmType = pMultipart->type.drmInfo.drmType;
-
-                       pMultipart = pMultipart->pNext;
-               }
-       } else {
-               drmType = pMsgType->drmInfo.drmType;
-       }
-
-       return drmType;
-}
 
-void MmsDrm2SetConvertState(MmsDrm2ConvertState newConvertState)
-{
-       mmsDrm2ConvertState = newConvertState;
-       MSG_DEBUG("MmsDrm2SetConvertState: mmsDrm2ConvertState = %d\n", mmsDrm2ConvertState);
-}
-
-MmsDrm2ConvertState MmsDrm2GetConvertState(void)
-{
-       return mmsDrm2ConvertState;
-}
-
-bool MsgDRM2GetDRMInfo(char *szFilePath, MsgType *pMsgType)
+bool MmsPluginDrmGetInfo(const char *szFilePath, MsgType *pMsgType)
 {
+#if MSG_DRM_SUPPORT
        if (szFilePath == NULL || pMsgType == NULL) {
                MSG_DEBUG("Param is NULL szFilePath = %d, pMsgType = %d", szFilePath, pMsgType);
                return false;
        }
 
-       char szMimeType[DRM_MAX_LEN_MIME + 1];
-       char szContentID[DRM_MAX_LEN_CID + 1];
+       char szMimeType[DRM_MAX_LEN_MIME + 1] = {0,};
+       char szContentID[DRM_MAX_LEN_CID + 1] = {0,};
        MSG_DRM_TYPE drmType = MSG_DRM_NONE;
        int ret = 0;
 
        MsgDrmGetDrmType(szFilePath, &drmType);
        MsgDrmGetMimeTypeEx(szFilePath, szMimeType, sizeof(szMimeType));
        MsgDrmGetContentID(szFilePath, szContentID, sizeof(szContentID));
-       MSG_DEBUG("drmType: %d", drmType);
+
+       MSG_DEBUG("drmType: [%d], mimetype: [%s], contentID: [%s]", drmType, szMimeType, szContentID);
 
        switch (drmType) {
        case MSG_DRM_FORWARD_LOCK:
                pMsgType->drmInfo.drmType = MSG_DRM_TYPE_FL;
-               pMsgType->drmInfo.contentType = (MimeType)_MsgGetCode(MSG_TYPE, szMimeType);
-               if (MsgCopyDrmInfo(pMsgType) == false) {
-                       MSG_DEBUG("MsgDRM2GetDRMInfo : MsgCopyDrmInfo failed");
-                       return false;
-               }
+               pMsgType->drmInfo.contentType = MimeGetMimeIntFromMimeString(szMimeType);
                break;
 
        case MSG_DRM_COMBINED_DELIVERY:
@@ -94,22 +59,23 @@ bool MsgDRM2GetDRMInfo(char *szFilePath, MsgType *pMsgType)
 
        case MSG_DRM_SEPARATE_DELIVERY:
                pMsgType->drmInfo.drmType = MSG_DRM_TYPE_SD;
-
-               pMsgType->drmInfo.contentType = (MimeType)_MsgGetCode(MSG_TYPE, szMimeType);
+               pMsgType->drmInfo.contentType = MimeGetMimeIntFromMimeString(szMimeType);
 
                drm_content_info_s dcfHdrInfo;
                bzero(&dcfHdrInfo, sizeof(drm_content_info_s));
                ret = drm_get_content_info(szFilePath, &dcfHdrInfo);
-               MSG_DEBUG("drm_get_content_info is failed, ret=[%d]", ret);
+               if (ret != DRM_RETURN_SUCCESS)
+                       MSG_DEBUG("drm_get_content_info is failed, ret=[%d]", ret);
 
                drm_file_info_s fileInfo;
                bzero(&fileInfo, sizeof(drm_file_info_s));
                ret = drm_get_file_info(szFilePath, &fileInfo);
-               MSG_DEBUG("drm_get_file_info is failed, ret=[%d]", ret);
+               if (ret != DRM_RETURN_SUCCESS)
+                       MSG_DEBUG("drm_get_file_info is failed, ret=[%d]", ret);
 
                if (fileInfo.oma_info.version == DRM_OMA_DRMV1_RIGHTS) {
                        pMsgType->drmInfo.szContentName = MsgRemoveQuoteFromFilename(dcfHdrInfo.title);
-                       pMsgType->drmInfo.szContentDescription = MsgStrCopy(dcfHdrInfo.description);
+                       pMsgType->drmInfo.szContentDescription = g_strdup(dcfHdrInfo.description);
                }
                break;
 
@@ -118,60 +84,9 @@ bool MsgDRM2GetDRMInfo(char *szFilePath, MsgType *pMsgType)
                break;
        }
 
-       pMsgType->drmInfo.szDrm2FullPath = MsgStrCopy(szFilePath);
+       pMsgType->drmInfo.szDrm2FullPath = g_strdup(szFilePath);
        MSG_DEBUG("pMsgType->drmInfo.szDrm2FullPath: %s", pMsgType->drmInfo.szDrm2FullPath);
 
+#endif
        return true;
 }
-
-bool MsgDRMIsForwardLockType(MsgDrmType        drmType)
-{
-       switch (drmType) {
-       case MSG_DRM_TYPE_FL:
-       case MSG_DRM_TYPE_CD:
-               return true;
-
-       case MSG_DRM_TYPE_NONE:         //SD & plain can be forwarded
-       case MSG_DRM_TYPE_SD:
-       default:
-               return false;
-       }
-}
-
-bool MsgChangeDrm2FileName(char *szFileName)
-{
-       char szTempFileName[MSG_FILENAME_LEN_MAX] = {0,};
-
-       if (szFileName == NULL || szFileName[0] == '\0')
-               return false;
-
-       MsgGetFileNameWithoutExtension(szTempFileName, szFileName);
-
-       if (strrchr(szTempFileName, '.'))
-               return true;
-
-       strcat(szTempFileName, ".dcf");
-       strcpy(szFileName, szTempFileName);
-
-       MSG_DEBUG("MsgChangeDrm2FileName: made szFileName = %s \n", szFileName);
-
-       return true;
-}
-
-bool MsgIsDCFFile(char *szFilePath)
-{
-       int length = 0;
-
-       MSG_DEBUG("MsgIsDCFFile: szFilePath = %s \n", szFilePath);
-
-       length = MsgStrlen(szFilePath);
-       if (szFilePath[length - 4] == '.' &&
-               (szFilePath[length - 3] == 'd' || szFilePath[length - 3] == 'D') &&
-               (szFilePath[length - 2] == 'c' || szFilePath[length - 2] == 'C') &&
-               (szFilePath[length - 1] == 'f' || szFilePath[length - 1] == 'F'))
-               return true;
-
-       return false;
-}
-
-#endif
index 2ddccd8..dac05ed 100755 (executable)
@@ -1,22 +1,24 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <time.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <errno.h>
+#include <sys/stat.h>
 #include "MsgUtilFile.h"
 #include "MmsPluginDebug.h"
 #include "MmsPluginEncode.h"
@@ -72,7 +74,7 @@ static        bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen);
 static bool __MmsBinaryEncodeMsgID(FILE *pFile, const char *szMsgID);  /** 2005-05-24, added for read-reply PDU 1.2 */
 static bool __MmsBinaryEncodeFrom(FILE *pFile);
 static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeStruct time);
-static bool __MmsBinaryEncodeDate(FILE *pFile);
+static bool __MmsBinaryEncodeDate(FILE *pFile, time_t inpDateSec);
 static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char *szAddrStr);
 static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *szAddr);
 
@@ -91,6 +93,8 @@ static        bool __MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length)
 static bool __MmsBinaryEncodeMmsVersion2(FILE *pFile);
 static bool __MmsBinaryEncodeFieldCodeAndValue2(FILE *pFile, UINT8 fieldCode, UINT8 fieldValue);
 
+static char *_MsgSkipWS3(char *s);
+
 /** -----------------------------------------------------------------
  *                                     M   M   S       E   N   C   O   D   E
  * * -----------------------------------------------------------------*/
@@ -186,8 +190,6 @@ static void __MmsUnregisterEncodeBuffer2(void)
 */
 static bool __MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length)
 {
-       MSG_DEBUG("MmsBinaryEncodeTextString2: \n");
-
        /**
         * make text string
         * Text-string = [Quote] *TEXT End-of-string
@@ -198,14 +200,14 @@ static bool __MmsBinaryEncodeTextString2(FILE *pFile, UINT8 *source, int length)
         */
 
        if (pFile == NULL || source == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeTextString2: source == NULL \n");
+               MSG_DEBUG("source == NULL");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                        gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeTextString2: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -230,18 +232,18 @@ static    bool __MmsBinaryEncodeFieldCodeAndValue2(FILE *pFile, UINT8 fieldCode, UI
        if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < 2) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                        gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
        if (fieldCode == 0xff) {
-               MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldCode \n");
+               MSG_DEBUG("invalid fieldCode");
                goto __CATCH;
        }
 
        if (fieldValue == 0xff) {
-               MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldValue \n");
+               MSG_DEBUG("invalid fieldValue");
                return true;
        }
 
@@ -259,17 +261,15 @@ static bool __MmsBinaryEncodeMmsVersion2(FILE *pFile)
        UINT8 majorVer = MMS_MAJOR_VERSION;
        UINT8 minorVer = MMS_MINOR_VERSION;
 
-       MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: \n");
-
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: invalid input file \n");
+               MSG_DEBUG("invalid input file");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < 2) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                        gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeMmsVersion2: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -295,8 +295,8 @@ static bool __MmsBinaryEncodeAckIndHdr(FILE *pFile, char *szTrID, bool bReportAl
        UINT8 fieldCode = 0xff;
        UINT8 fieldValue = 0xff;
 
-       MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: szTrID = %s\n", szTrID);
-       MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: bReportAllowed = %d\n", bReportAllowed);
+       MSG_DEBUG("szTrID = %s", szTrID);
+       MSG_DEBUG("bReportAllowed = %d", bReportAllowed);
 
        __MmsCleanEncodeBuff2();
 
@@ -304,21 +304,21 @@ static bool __MmsBinaryEncodeAckIndHdr(FILE *pFile, char *szTrID, bool bReportAl
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_ACKNOWLEDGE_IND) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: msgType error\n");
+               MSG_DEBUG("msgType error");
                goto __CATCH;
        }
 
        /* trID (other type of message) */
        length = __MmsBinaryEncodeTextStringLen((UINT8*)szTrID);
        if (length == -1) {
-               MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MmsBinaryEncodeTextStringLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeTextStringLen fail");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < (length + 1)) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                        gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -326,13 +326,13 @@ static bool __MmsBinaryEncodeAckIndHdr(FILE *pFile, char *szTrID, bool bReportAl
        gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
 
        if (__MmsBinaryEncodeTextString2(pFile, (UINT8*)szTrID, length) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: MmsBinaryEncodeTextString fail\n");
+               MSG_DEBUG("MmsBinaryEncodeTextString fail");
                goto __CATCH;
        }
 
 
        if (__MmsBinaryEncodeMmsVersion2(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: __MmsBinaryEncodeMmsVersion error\n");
+               MSG_DEBUG("__MmsBinaryEncodeMmsVersion error");
                goto __CATCH;
        }
 
@@ -347,14 +347,14 @@ static bool __MmsBinaryEncodeAckIndHdr(FILE *pFile, char *szTrID, bool bReportAl
        }
 
        if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: Report Allowed error\n");
+               MSG_DEBUG("Report Allowed error");
                goto __CATCH;
        }
 
        /* flush remained data on encoding file */
        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeAckIndHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
+               MSG_DEBUG("remained data MsgWriteDataFromEncodeBuffer fail");
                goto __CATCH;
        }
 
@@ -371,9 +371,9 @@ static bool __MmsBinaryEncodeNotiRespIndHdr(FILE *pFile, char *szTrID, msg_deliv
        UINT8 fieldCode = 0xff;
        UINT8 fieldValue = 0xff;
 
-       MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: szTrID = %s\n", szTrID);
-       MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: iStatus = %d\n", iStatus);
-       MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: bReportAllowed = %d\n", bReportAllowed);
+       MSG_DEBUG("szTrID = %s", szTrID);
+       MSG_DEBUG("iStatus = %d", iStatus);
+       MSG_DEBUG("bReportAllowed = %d", bReportAllowed);
 
        __MmsCleanEncodeBuff2();
 
@@ -382,7 +382,7 @@ static bool __MmsBinaryEncodeNotiRespIndHdr(FILE *pFile, char *szTrID, msg_deliv
        fieldValue = MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_NOTIFYRESP_IND) | 0x80;
 
        if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: msgType error\n");
+               MSG_DEBUG("msgType error");
                goto __CATCH;
        }
 
@@ -390,39 +390,39 @@ static bool __MmsBinaryEncodeNotiRespIndHdr(FILE *pFile, char *szTrID, msg_deliv
        /* trID (other type of message) */
        length = __MmsBinaryEncodeTextStringLen((UINT8*)szTrID);
        if (length == -1) {
-               MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MmsBinaryEncodeTextStringLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeTextStringLen fail");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen2 - gCurMmsEncodeBuffPos2) < (length + 1)) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                        gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
        gpMmsEncodeBuf2[gCurMmsEncodeBuffPos2++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
        if (__MmsBinaryEncodeTextString2(pFile, (UINT8*)szTrID, length) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MmsBinaryEncodeTextString fail\n");
+               MSG_DEBUG("MmsBinaryEncodeTextString fail");
                goto __CATCH;
        }
 
 
        if (__MmsBinaryEncodeMmsVersion2(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: __MmsBinaryEncodeMmsVersion error\n");
+               MSG_DEBUG("__MmsBinaryEncodeMmsVersion error");
                goto __CATCH;
        }
 
 
        /* MsgStatus */
-       MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgStatus = %d\n", iStatus);
+       MSG_DEBUG("MsgStatus = %d", iStatus);
 
        if (iStatus != MSG_DELIVERY_REPORT_NONE) {
                fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGSTATUS) | 0x80;
                fieldValue = MmsGetBinaryValue(MmsCodeMsgStatus, iStatus) | 0x80;
                if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: MsgStatus error\n");
+                       MSG_DEBUG("MsgStatus error");
                        goto __CATCH;
                }
        }
@@ -438,14 +438,14 @@ static bool __MmsBinaryEncodeNotiRespIndHdr(FILE *pFile, char *szTrID, msg_deliv
        }
 
        if (__MmsBinaryEncodeFieldCodeAndValue2(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: Report Allowed error\n");
+               MSG_DEBUG("Report Allowed error");
                goto __CATCH;
        }
 
        /* flush remained data on encoding file */
        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf2, &gCurMmsEncodeBuffPos2,
                                                                                gMmsEncodeMaxLen2, &gMmsEncodeCurOffset2) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeNotiRespIndHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
+               MSG_DEBUG("remained data MsgWriteDataFromEncodeBuffer fail");
                goto __CATCH;
        }
 
@@ -460,10 +460,10 @@ bool MmsEncodeAckInd(FILE *pFile, char *pTrID, bool bReportAllowed)
 {
        __MmsRegisterEncodeBuffer2(gszMmsEncodeBuf2, MSG_MMS_ENCODE_BUFFER_MAX);
 
-       MSG_DEBUG("_MmsEncodeAckInd: Start Binary Encoding now ============= \n");
+       MSG_DEBUG("Start Binary Encoding now =============");
 
        if (__MmsBinaryEncodeAckIndHdr(pFile, pTrID, bReportAllowed) == false) {
-               MSG_DEBUG("_MmsEncodeAckInd: SendReq Binary encoding fail \n");
+               MSG_DEBUG("SendReq Binary encoding fail");
                goto __CATCH;
        }
 
@@ -473,7 +473,7 @@ bool MmsEncodeAckInd(FILE *pFile, char *pTrID, bool bReportAllowed)
 
 __CATCH:
 
-       MSG_DEBUG("## _MmsEncodeAckInd: failed");
+       MSG_DEBUG("Failed");
        __MmsUnregisterEncodeBuffer2();
 
        return false;
@@ -483,10 +483,10 @@ bool MmsEncodeNotiRespInd(FILE *pFile, char *pTrID, msg_delivery_report_status_t
 {
        __MmsRegisterEncodeBuffer2(gszMmsEncodeBuf2, MSG_MMS_ENCODE_BUFFER_MAX);
 
-       MSG_DEBUG("_MmsEncodeNotiRespInd: Start Binary Encoding now ============= \n");
+       MSG_DEBUG("Start Binary Encoding now =============");
 
        if (__MmsBinaryEncodeNotiRespIndHdr(pFile, pTrID, iStatus, bReportAllowed) == false) {
-               MSG_DEBUG("_MmsEncodeNotiRespInd: SendReq Binary encoding fail \n");
+               MSG_DEBUG("SendReq Binary encoding fail");
                goto __CATCH;
        }
 
@@ -512,14 +512,13 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
 
        struct  tm      *dateTime = NULL;
        time_t  RawTime = 0;
-       time_t  dateSec = 0;
 
        MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
 
-       MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now V1.0============= \n");
+       MSG_DEBUG("Start Binary Encoding now V1.0=============");
 
        if (__MmsBinaryEncodeReadReport10Hdr(pFile, pMsg, mmsReadStatus) == false) {
-               MSG_DEBUG("_MmsEncodeReadReport10: SendReq Binary encoding fail \n");
+               MSG_DEBUG("SendReq Binary encoding fail");
                goto __CATCH;
        }
 
@@ -528,7 +527,7 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
 
        pText = (char *)malloc(MSG_STDSTR_LONG);
        if (pText == NULL) {
-               MSG_DEBUG("__MmsSendReadReportV10: text body malloc fail \n");
+               MSG_DEBUG("text body malloc fail");
                goto __CATCH;
        }
 
@@ -536,7 +535,6 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
 
        time(&RawTime);
        dateTime = localtime(&RawTime);
-       dateSec = mktime(dateTime);
 
        // get report message
        if (mmsReadStatus == MSG_READ_REPORT_IS_DELETED) {
@@ -549,7 +547,7 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
        maxLen = strlen (pszReportMsg) +16 /* date string */ + 8 /* enter chars */ ;
 
        if (maxLen > MSG_STDSTR_LONG) {
-               snprintf (pText, MSG_STDSTR_LONG, "%s\n", pszReportMsg);
+               snprintf (pText, MSG_STDSTR_LONG, "%s", pszReportMsg);
        } else {
                snprintf(pText, MSG_STDSTR_LONG, "%s\r\n\r\n%.4d/%.2d/%.2d %.2d:%.2d\r\n",
                                                pszReportMsg, dateTime->tm_year+1900, dateTime->tm_mon+1, dateTime->tm_mday, dateTime->tm_hour, dateTime->tm_min);
@@ -562,7 +560,7 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
 
        // make body
        if ((pPart = MmsAllocMultipart()) == NULL) {
-               MSG_DEBUG("__MmsSendReadReportV10: MsgAllocMultipart Fail \n");
+               MSG_DEBUG("MsgAllocMultipart Fail");
                goto __CATCH;
        }
 
@@ -572,7 +570,7 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
        pPart->type.param.charset = MSG_CHARSET_UTF8;
 
        if (pPart->pBody == NULL) {
-               MSG_DEBUG("__MmsSendReadReportV10: pPart->pBody is NULL \n");
+               MSG_DEBUG("pPart->pBody is NULL");
                goto __CATCH;
        }
 
@@ -582,11 +580,11 @@ bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
        msgBody.body.pMultipart = pPart;
 
        if (__MmsBinaryEncodeMsgBody(pFile, &msgType, &msgBody, 1, false) == false) {
-               MSG_DEBUG("__MmsSendReadReportV10: MmsBinaryEncodeMsgBody fail \n");
+               MSG_DEBUG("MmsBinaryEncodeMsgBody fail");
                goto __CATCH;
        }
 
-       MSG_DEBUG("__MmsSendReadReportV10:  Send To RM ReadReport Msg \n");
+       MSG_DEBUG(" Send To RM ReadReport Msg");
 
        if (pText) {
                free(pText);
@@ -631,10 +629,10 @@ bool MmsEncodeReadReport11(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t m
 {
        MmsRegisterEncodeBuffer(gszMmsEncodeBuf, MSG_MMS_ENCODE_BUFFER_MAX);
 
-       MSG_DEBUG("_MmsEncodeMsg: Start Binary Encoding now V1.1============= \n");
+       MSG_DEBUG("Start Binary Encoding now V1.1=============");
 
        if (__MmsBinaryEncodeReadReport11Hdr(pFile, pMsg, mmsReadStatus) == false) {
-               MSG_DEBUG("_MmsEncodeMsg: SendReq Binary encoding fail \n");
+               MSG_DEBUG("SendReq Binary encoding fail");
                goto __CATCH;
        }
 
@@ -698,26 +696,26 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_SEND_REQ) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: msgType error\n");
+               MSG_DEBUG("msgType error");
                goto __CATCH;
        }
 
+       MSG_SEC_INFO("X-Mms-Message-Type = [%s]", MmsDebugGetMsgType(MMS_MSGTYPE_SEND_REQ));
+
        /* trID (other type of message) */
        if (__MmsBinaryEncodeTrID(pFile, pMsg->szTrID, MMS_TR_ID_LEN + 1) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: trID error\n");
+               MSG_DEBUG("trID error");
                goto __CATCH;
        }
 
-       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr:                pMsg->szTrID = %s\n", pMsg->szTrID);
-
        if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeMmsVersion error\n");
+               MSG_DEBUG("__MmsBinaryEncodeMmsVersion error");
                goto __CATCH;
        }
 
        /* From : Insert Token mode */
        if (__MmsBinaryEncodeFrom(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeFrom fail\n");
+               MSG_DEBUG("__MmsBinaryEncodeFrom fail");
                goto __CATCH;
        }
 
@@ -725,40 +723,38 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
        /* To = Encoded-string-value */
        if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szTo) == false)
        {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: To __MmsBinaryEncodeAddress fail\n");
+               MSG_DEBUG("To __MmsBinaryEncodeAddress fail");
                goto __CATCH;
        }
 
 
        /* Cc = Encoded-string-value */
        if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_CC, pMsg->mmsAttrib.szCc) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: Cc __MmsBinaryEncodeAddress fail\n");
+               MSG_DEBUG("Cc __MmsBinaryEncodeAddress fail");
                goto __CATCH;
        }
 
 
        /* Bcc = Encoded-string-value */
-
        if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_BCC, pMsg->mmsAttrib.szBcc) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: Bcc __MmsBinaryEncodeAddress fail\n");
+               MSG_DEBUG("Bcc __MmsBinaryEncodeAddress fail");
                goto __CATCH;
        }
 
-
-       MSG_DEBUG("_MmsBinaryEnocdeSendReqHdr() pMsg->mmsAttrib.szSubject =%s\n",pMsg->mmsAttrib.szSubject);
+       MSG_SEC_INFO("Subject = [%s]", pMsg->mmsAttrib.szSubject);
 
        /* Subject = Encoded-string-value */
        if (pMsg->mmsAttrib.szSubject[0]) {
                length = __MmsBinaryEncodeEncodedStringLen((UINT8*)pMsg->mmsAttrib.szSubject);
                if (length == -1) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MmsBinaryEncodeEncodedStringLen fail \n");
+                       MSG_DEBUG("subject MmsBinaryEncodeEncodedStringLen fail");
                        goto __CATCH;
                }
 
                if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
                        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MsgWriteDataFromEncodeBuffer fail \n");
+                               MSG_DEBUG("subject MsgWriteDataFromEncodeBuffer fail");
                                goto __CATCH;
                        }
                }
@@ -766,7 +762,7 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                fieldCode = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SUBJECT) | 0x80;
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
                if (__MmsBinaryEncodeEncodedString(pFile, (UINT8*)pMsg->mmsAttrib.szSubject, length) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: subject MmsBinaryEncodeEncodedString fail \n");
+                       MSG_DEBUG("subject MmsBinaryEncodeEncodedString fail");
                        goto __CATCH;
                }
        }
@@ -776,42 +772,38 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGCLASS) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeMsgClass,  (int)pMsg->mmsAttrib.msgClass) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: msgClass error\n");
+               MSG_DEBUG("msgClass error");
                goto __CATCH;
        }
+
+       MSG_SEC_INFO("X-Mms-Message-Class = [%s]", MmsDebugGetMsgClass(pMsg->mmsAttrib.msgClass));
+
        /* MMS-1.3-con-739 */
        /* MMS-1.3-con-733 */
        /* Date = Long-integer */
-       if (!__MmsBinaryEncodeDate(pFile)) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: __MmsBinaryEncodeDate error\n");
-                       goto __CATCH;
+       if (!__MmsBinaryEncodeDate(pFile, 0)) {
+               MSG_DEBUG("__MmsBinaryEncodeDate error");
+               goto __CATCH;
        }
        /* MMS-1.3-con-733 */
 
        /* Expiry Time  : Value-length Absolute-token Date-value */
-       if (pMsg->mmsAttrib.bUseExpiryCustomTime == true) {
-               if (__MmsBinaryEncodeTime(pFile, MMS_CODE_EXPIRYTIME, pMsg->mmsAttrib.expiryCustomTime) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
-                       goto __CATCH;
-               }
-       } else if (pMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE) {      // for avoiding the creation of the expiry field in case the user selects the maximum
+       if (pMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE) {     // for avoiding the creation of the expiry field in case the user selects the maximum
                if (__MmsBinaryEncodeTime(pFile, MMS_CODE_EXPIRYTIME, pMsg->mmsAttrib.expiryTime) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: expiryTime __MmsBinaryEncodeTime fail\n");
+                       MSG_DEBUG("expiryTime __MmsBinaryEncodeTime fail");
                        goto __CATCH;
                }
+
+               MSG_DEBUG("X-Mms-Expiry : type = [%d], time = [%u]", pMsg->mmsAttrib.expiryTime.type, pMsg->mmsAttrib.expiryTime.time);
        }
 
-       /* Use Custom time for Delivery Time */
-       if (pMsg->mmsAttrib.bUseDeliveryCustomTime == true) {
-               if (__MmsBinaryEncodeTime(pFile, MMS_CODE_DELIVERYTIME, pMsg->mmsAttrib.deliveryCustomTime) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
-                       goto __CATCH;
-               }
-       } else {
+       if (pMsg->mmsAttrib.deliveryTime.type != MMS_TIMETYPE_NONE) {
                if (__MmsBinaryEncodeTime(pFile, MMS_CODE_DELIVERYTIME, pMsg->mmsAttrib.deliveryTime) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: deliveryTime __MmsBinaryEncodeTime fail\n");
+                       MSG_DEBUG("deliveryTime __MmsBinaryEncodeTime fail");
                        goto __CATCH;
                }
+
+               MSG_DEBUG("X-Mms-Delivery-Time : type = [%d], time = [%u]", pMsg->mmsAttrib.deliveryTime.type, pMsg->mmsAttrib.deliveryTime.time);
        }
 
        /* Priority */
@@ -822,9 +814,11 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                fieldValue = MmsGetBinaryValue(MmsCodePriority, pMsg->mmsAttrib.priority)|0x80;
 
                if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: priority error\n");
+                       MSG_DEBUG("priority error");
                        goto __CATCH;
                }
+
+               MSG_SEC_INFO("X-Mms-Priority = [%d]", pMsg->mmsAttrib.priority);
        }
 
        /* Sender Visible (hide | show) */
@@ -833,11 +827,13 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                fieldValue = MmsGetBinaryValue(MmsCodeSenderVisibility, MMS_SENDER_HIDE) | 0x80;
 
                if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: sender visibility error\n");
+                       MSG_DEBUG("sender visibility error");
                        goto __CATCH;
                }
        }
 
+       MSG_SEC_INFO("X-Mms-Sender-Visibility = [%d]", pMsg->mmsAttrib.bHideAddress);
+
        /* Delivery Report (yes | no) */
        fieldCode = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT)|0x80;
 
@@ -847,8 +843,10 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                fieldValue = MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_NO) | 0x80;
        }
 
+       MSG_SEC_INFO("X-Mms-Delivery-Report = [%d]", pMsg->mmsAttrib.bAskDeliveryReport);
+
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: sender visibility error\n");
+               MSG_DEBUG("sender visibility error");
                goto __CATCH;
        }
 
@@ -860,8 +858,10 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                fieldValue = MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_NO)|0x80;
        }
 
+       MSG_SEC_INFO("X-Mms-Read-Report = [%d]", pMsg->mmsAttrib.bAskReadReply);
+
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: read reply error\n");
+               MSG_DEBUG("read reply error");
                goto __CATCH;
        }
 
@@ -873,14 +873,14 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                fieldValue = MmsGetBinaryValue(MmsCodeReadReply, pMsg->mmsAttrib.replyCharge.chargeType)|0x80;
 
                if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyCharging error\n");
+                       MSG_DEBUG("replyCharging error");
                        goto __CATCH;
                }
 
                /** fixme: Reply-charging-deadline */
                if (pMsg->mmsAttrib.replyCharge.deadLine.time > 0) {
                        if (__MmsBinaryEncodeTime(pFile, MMS_CODE_REPLYCHARGINGDEADLINE, pMsg->mmsAttrib.replyCharge.deadLine) == false) {
-                               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyCharging __MmsBinaryEncodeTime fail\n");
+                               MSG_DEBUG("replyCharging __MmsBinaryEncodeTime fail");
                                goto __CATCH;
                        }
                }
@@ -892,7 +892,7 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
                                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
+                                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                                        goto __CATCH;
                                }
                        }
@@ -900,7 +900,7 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGINGSIZE) | 0x80;
 
                        if (__MmsBinaryEncodeInteger(pFile, pMsg->mmsAttrib.replyCharge.chargeSize, length) == false)   {
-                               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: replyChargingSize MmsBinaryEncodeInteger error\n");
+                               MSG_DEBUG("replyChargingSize MmsBinaryEncodeInteger error");
                                goto __CATCH;
                        }
                }
@@ -909,14 +909,14 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                if (pMsg->mmsAttrib.replyCharge.szChargeID[0]) {
                        length = __MmsBinaryEncodeTextStringLen((UINT8*)pMsg->mmsAttrib.replyCharge.szChargeID);
                        if (length == -1) {
-                               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: szReplyChargingID MmsBinaryEncodeTextStringLen fail\n");
+                               MSG_DEBUG("szReplyChargingID MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
 
                        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
                                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
+                                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                                        goto __CATCH;
                                }
                        }
@@ -924,7 +924,7 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_REPLYCHARGINGID) | 0x80;
 
                        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)pMsg->mmsAttrib.replyCharge.szChargeID, length) == false) {
-                               MSG_DEBUG("szContentLocation MmsBinaryEncodeTextString fail\n");
+                               MSG_DEBUG("szContentLocation MmsBinaryEncodeTextString fail");
                                goto __CATCH;
                        }
                }
@@ -932,7 +932,7 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
 
        /* flush remained data on encoding file */
        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
+               MSG_DEBUG("remained data MsgWriteDataFromEncodeBuffer fail");
                goto __CATCH;
        }
 
@@ -940,7 +940,7 @@ static bool __MmsBinaryEncodeSendReqHdr(FILE *pFile, MmsMsg *pMsg)
 
 __CATCH:
 
-       MSG_DEBUG("## _MmsBinaryEncodeSendReqHdr: failed");
+       MSG_DEBUG("Failed");
        return false;
 }
 
@@ -957,7 +957,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
                goto __CATCH;
        }
 
-       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: mmsReadStatus = %d\n", mmsReadStatus);
+       MSG_DEBUG("mmsReadStatus = %d", mmsReadStatus);
 
        __MmsCleanEncodeBuff();
 
@@ -965,49 +965,49 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_SEND_REQ) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: msgType error\n");
+               MSG_DEBUG("msgType error");
                goto __CATCH;
        }
 
        /* trID (other type of message) */
        if (__MmsBinaryEncodeTrID(pFile, NULL, 0) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeTrID error\n");
+               MSG_DEBUG("__MmsBinaryEncodeTrID error");
                goto __CATCH;
        }
 
        if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeMmsVersion error\n");
+               MSG_DEBUG("__MmsBinaryEncodeMmsVersion error");
                goto __CATCH;
        }
 
        /* Date = Long-integer */
-       if (!__MmsBinaryEncodeDate(pFile)) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: date __MmsBinaryEncodeDate error\n");
+       if (!__MmsBinaryEncodeDate(pFile, 0)) {
+               MSG_DEBUG("date __MmsBinaryEncodeDate error");
                goto __CATCH;
        }
 
        /* From : Insert Token mode */
        if (__MmsBinaryEncodeFrom(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: __MmsBinaryEncodeFrom fail\n");
+               MSG_DEBUG("__MmsBinaryEncodeFrom fail");
                goto __CATCH;
        }
 
-       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", pMsg->mmsAttrib.szFrom);
+       MSG_DEBUG("To = %s", pMsg->mmsAttrib.szFrom);
 
        /* To = Encoded-string */
        if (pMsg && (strchr(pMsg->mmsAttrib.szFrom, '/') == NULL)) {
                length = strlen(pMsg->mmsAttrib.szFrom);
                szTo = (char *)malloc(length + 11);
                if (szTo == NULL) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: szTo alloc fail\n");
+                       MSG_DEBUG("szTo alloc fail");
                        goto __CATCH;
                }
 
                snprintf(szTo, length + 11, "%s/TYPE=PLMN", pMsg->mmsAttrib.szFrom);
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", szTo);
+               MSG_DEBUG("To = %s", szTo);
 
                if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, szTo) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
+                       MSG_DEBUG("To __MmsBinaryEncodeAddress fail");
                        goto __CATCH;
                }
 
@@ -1017,7 +1017,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
                }
        } else {
                if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szFrom) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
+                       MSG_DEBUG("To __MmsBinaryEncodeAddress fail");
                        goto __CATCH;
                }
        }
@@ -1040,13 +1040,13 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
 
        length = __MmsBinaryEncodeEncodedStringLen((UINT8*)szSubject);
        if (length == -1) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MmsBinaryEncodeEncodedStringLen fail \n");
+               MSG_DEBUG("subject MmsBinaryEncodeEncodedStringLen fail");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("subject MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -1054,7 +1054,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SUBJECT) | 0x80;
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
        if (__MmsBinaryEncodeEncodedString(pFile, (UINT8*)szSubject, length) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: subject MmsBinaryEncodeEncodedString fail \n");
+               MSG_DEBUG("subject MmsBinaryEncodeEncodedString fail");
                goto __CATCH;
        }
 
@@ -1062,7 +1062,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGCLASS) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeMsgClass, MMS_MSGCLASS_AUTO) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: msgClass error\n");
+               MSG_DEBUG("msgClass error");
                goto __CATCH;
        }
 
@@ -1071,7 +1071,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DELIVERYREPORT) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeDeliveryReport, MMS_REPORT_NO) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Delivery Report error\n");
+               MSG_DEBUG("Delivery Report error");
                goto __CATCH;
        }
 
@@ -1080,7 +1080,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_READREPLY) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeReadReply, MMS_REPORT_NO) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Read Reply error\n");
+               MSG_DEBUG("Read Reply error");
                goto __CATCH;
        }
 
@@ -1089,7 +1089,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_SENDERVISIBILLITY) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeSenderVisibility, MMS_SENDER_SHOW) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: Sender Visible error\n");
+               MSG_DEBUG("Sender Visible error");
                goto __CATCH;
        }
 
@@ -1100,7 +1100,7 @@ static bool __MmsBinaryEncodeReadReport10Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        /* flush remained data on encoding file */
        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
+               MSG_DEBUG("remained data MsgWriteDataFromEncodeBuffer fail");
                goto __CATCH;
        }
 
@@ -1127,13 +1127,13 @@ static bool __MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldCode  = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGTYPE) | 0x80;
        fieldValue = MmsGetBinaryValue(MmsCodeMsgType, MMS_MSGTYPE_READREC_IND) | 0x80;
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: msgType error\n");
+               MSG_DEBUG("msgType error");
                goto __CATCH;
        }
 
        /* MMS version */
        if (__MmsBinaryEncodeMmsVersion(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeMmsVersion error\n");
+               MSG_DEBUG("__MmsBinaryEncodeMmsVersion error");
                goto __CATCH;
        }
 
@@ -1147,15 +1147,15 @@ static bool __MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
                szTo = (char *)malloc(length + 11);
 
                if (szTo == NULL) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: szTo alloc fail\n");
+                       MSG_DEBUG("szTo alloc fail");
                        goto __CATCH;
                }
 
                snprintf(szTo, length + 11,"%s/TYPE=PLMN", pMsg->mmsAttrib.szFrom);
-               MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To = %s\n", szTo);
+               MSG_DEBUG("To = %s", szTo);
 
                if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, szTo) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport10Hdr: To __MmsBinaryEncodeAddress fail\n");
+                       MSG_DEBUG("To __MmsBinaryEncodeAddress fail");
                        goto __CATCH;
                }
 
@@ -1165,20 +1165,20 @@ static bool __MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
                }
        } else {
                if (__MmsBinaryEncodeAddress(pFile, MMS_CODE_TO, pMsg->mmsAttrib.szFrom) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: To __MmsBinaryEncodeAddress fail\n");
+                       MSG_DEBUG("To __MmsBinaryEncodeAddress fail");
                        goto __CATCH;
                }
        }
 
        /* From : Insert Token mode */
        if (__MmsBinaryEncodeFrom(pFile) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeFrom fail\n");
+               MSG_DEBUG("__MmsBinaryEncodeFrom fail");
                goto __CATCH;
        }
 
        /* Date = Long-integer */
-       if (!__MmsBinaryEncodeDate(pFile)) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: __MmsBinaryEncodeDate error\n");
+       if (!__MmsBinaryEncodeDate(pFile, 0)) {
+               MSG_DEBUG("__MmsBinaryEncodeDate error");
                goto __CATCH;
        }
 
@@ -1187,13 +1187,13 @@ static bool __MmsBinaryEncodeReadReport11Hdr(FILE *pFile, MmsMsg *pMsg, msg_read
        fieldValue = MmsGetBinaryValue(MmsCodeReadStatus, mmsReadStatus) | 0x80;
 
        if (__MmsBinaryEncodeFieldCodeAndValue(pFile, fieldCode, fieldValue) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: Read Status error\n");
+               MSG_DEBUG("Read Status error");
                goto __CATCH;
        };
 
        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-               MSG_DEBUG("_MmsBinaryEncodeReadReport11Hdr: remained data MsgWriteDataFromEncodeBuffer fail \n");
+               MSG_DEBUG("remained data MsgWriteDataFromEncodeBuffer fail");
                goto __CATCH;
        }
 
@@ -1211,12 +1211,13 @@ __CATCH:
 static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody, int nPartCount, bool bTemplate)
 {
        int length = 0;
+       int index = 0;
        MsgMultipart *pMultipart = NULL;
 
-       MSG_DEBUG("MmsBinaryEncodeMsgBody: nPartCount = %d\n", nPartCount);
+       MSG_DEBUG("nPartCount = %d", nPartCount);
 
        if (pFile == NULL || pType == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeMsgBody: invalid file handle\n");
+               MSG_DEBUG("invalid file handle");
                goto __CATCH;
        }
 
@@ -1232,14 +1233,14 @@ static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody
                /* Content type */
                length = __MmsBinaryEncodeContentTypeLen(pType);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgBody: MmsBinaryEncodeContentTypeLen fail \n");
+                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen fail");
                        goto __CATCH;
                }
                if (bTemplate == false)
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_CONTENTTYPE) | 0x80;
 
                if (__MmsBinaryEncodeContentType(pFile, pType, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgBody: MmsBinaryEncodeContentType fail \n");
+                       MSG_DEBUG("MmsBinaryEncodeContentType fail");
                        goto __CATCH;
                }
 
@@ -1255,11 +1256,11 @@ static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody
                if (nEntries >= 0) {
                        length = __MmsBinaryEncodeUintvarLen(nEntries);
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeMsgBody: nEntries MmsBinaryEncodeUintvarLen fail \n");
+                               MSG_DEBUG("nEntries MmsBinaryEncodeUintvarLen fail");
                                goto __CATCH;
                        }
                        if (__MmsBinaryEncodeUintvar(pFile, nEntries, length) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeMsgBody: nEntries MmsBinaryEncodeUintvar fail \n");
+                               MSG_DEBUG("nEntries MmsBinaryEncodeUintvar fail");
                                goto __CATCH;
                        }
 
@@ -1269,7 +1270,7 @@ static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody
                if (nEntries > 0) {
                        if (nEntries && pBody->pPresentationBody) {
                                if (__MmsBinaryEncodeMsgPart(pFile, pType->type, &pBody->presentationType, pBody->pPresentationBody) == false) {
-                                       MSG_DEBUG("MmsBinaryEncodeMsgBody: __MmsBinaryEncodeMsgPart fail \n");
+                                       MSG_DEBUG("__MmsBinaryEncodeMsgPart fail");
                                        goto __CATCH;
                                }
 
@@ -1279,16 +1280,19 @@ static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody
                        pMultipart = pBody->body.pMultipart;
                        while (nEntries && pMultipart) {
                                if (__MmsBinaryEncodeMsgPart(pFile, pType->type, &pMultipart->type, pMultipart->pBody) == false) {
-                                       MSG_DEBUG("MmsBinaryEncodeMsgBody: __MmsBinaryEncodeMsgPart fail \n");
+                                       MSG_DEBUG("__MmsBinaryEncodeMsgPart fail");
                                        goto __CATCH;
                                }
+
+                               MmsPrintMulitpart(pMultipart, index++);
+
                                pMultipart = pMultipart->pNext;
                                nEntries--;
                        }
                } else {
                        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeMsgBody: Empty message body MsgWriteDataFromEncodeBuffer fail \n");
+                               MSG_DEBUG("Empty message body MsgWriteDataFromEncodeBuffer fail");
                                goto __CATCH;
                        }
                }
@@ -1305,7 +1309,7 @@ static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody
 
                length = __MmsBinaryEncodeContentTypeLen(pType);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgBody: Singlepart MmsBinaryEncodeContentTypeLen fail \n");
+                       MSG_DEBUG("Singlepart MmsBinaryEncodeContentTypeLen fail");
                        goto __CATCH;
                }
 
@@ -1321,7 +1325,7 @@ static bool __MmsBinaryEncodeMsgBody(FILE *pFile, MsgType *pType, MsgBody *pBody
        return true;
 
 __CATCH:
-       MSG_DEBUG("## MmsBinaryEncodeMsgBody: failed\n");
+       MSG_DEBUG("Failed");
 
        return false;
 }
@@ -1334,7 +1338,9 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
        const char *szTextType = NULL;
        int     contentType = MIME_UNKNOWN;
 
-       MSG_DEBUG("MSmsBinaryEncodeContentTypeLen:  type\n");
+       bool isAscii = true;
+       unsigned  long tmpLength = 0;
+       unsigned char tmpFileName[MSG_LOCALE_FILENAME_LEN_MAX+1];
 
        /*
         * Content-type-value = Constrained-media | Content-general-form
@@ -1357,7 +1363,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
                if (szTextType != NULL) {
                        length  = __MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
                        if (length == -1) {
-                               MSG_DEBUG("MSmsBinaryEncodeContentTypeLen: szTextType MmsBinaryEncodeTextStringLen fail \n");
+                               MSG_DEBUG("szTextType MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
                        totalLength += length;
@@ -1370,20 +1376,18 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
 
        /* Parameters -------------------------------------------------------------- */
 
-       MSG_DEBUG("MSmsBinaryEncodeContentTypeLen:  parameters    \n\n");
-
        /* Well-known-charset = Any-charset | Integer-value ----------------------- */
 
        if (pType->param.charset != MSG_CHARSET_UNKNOWN) {
                fieldValue = MmsGetBinaryValue(MmsCodeCharSet, pType->param.charset);
                length     = __MmsBinaryEncodeIntegerLen(fieldValue);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: charSet MmsBinaryEncodeIntegerLen fail \n");
+                       MSG_DEBUG("charSet MmsBinaryEncodeIntegerLen fail");
                        goto __CATCH;
                }
                totalLength += (length + 1);
        } else {
-               if (MmsIsText(contentType)) {   // Any-charset
+               if (MmsIsTextType(contentType)) {       // Any-charset
                        if (!MmsIsVitemContent (contentType, pType->param.szName))
                                totalLength += 2;
                }
@@ -1394,50 +1398,35 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
 
        if (pType->param.szName[0]) {
                char* pszName = NULL;
-
-               if (MsgIsASCII (pType->param.szName)) {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is consisted of ascii char-set chars. \n");
-
-                       pszName = (char *)malloc(strlen(pType->param.szName) +1);
-                       memset(pszName, 0, (strlen(pType->param.szName)+1));
-                       strcpy(pszName, pType->param.szName);
+               if (MmsIsAsciiString (pType->param.szName)) {
+                       MSG_DEBUG("Name is consisted of ascii char-set chars.");
                } else {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is not consisted of ascii char-set chars. \n");
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pType->param.szName : %s\n", pType->param.szName);
-
-                       /* if msg-server can't support non ascii, then convert non-ascii to '_' by using _MsgReplaceNonAscii*/
-                       int filelen = strlen(pType->param.szName);
-
-                       pszName = (char *)malloc(filelen + 1);
-                       memset(pszName, 0, (filelen + 1));
-                       strncpy(pszName, pType->param.szName, filelen);
-
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pszName : %s\n", pszName);
+                       isAscii = false;
+                       MSG_DEBUG("Name is NOT consisted of ascii char-set chars.");
                }
 
-               //change empty space to '_' in the file name
-               if (MsgIsSpace(pszName)) {
-                       char *pszTempName = NULL;
-
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName has space(' '). \n");
+               pszName = g_strdup(pType->param.szName);
 
-                       MsgReplaceSpecialChar(pszName, &pszTempName, ' ');
+               //change empty space to '_' in the file name
+               MmsReplaceSpaceChar(pszName);
 
-                       if (pszTempName) {
-                               free(pszName);
-                               pszName = pszTempName;
+               if (isAscii == false) {
+                       if (MsgEncode2Base64(pszName, strlen(pszName), &tmpLength, tmpFileName) == true) {
+                               g_free(pszName);
+                               pszName = g_strdup_printf("=?UTF-8?B?%s?=", tmpFileName);
+                               MSG_DEBUG("base64 encode filename=[%s]", pszName);
                        }
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: pszName : %s\n", pszName);
                }
 
                length = __MmsBinaryEncodeTextStringLen((UINT8*)pszName);
-               free(pszName);
 
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName MmsBinaryEncodeIntegerLen fail \n");
+                       MSG_DEBUG("szName MmsBinaryEncodeIntegerLen fail");
                        goto __CATCH;
                }
 
+               g_free(pszName);
+
                totalLength += (length + 1);
        }
 
@@ -1445,7 +1434,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
        if (pType->param.szApplicationID) {
                length = __MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szApplicationID);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szApplicationID MmsBinaryEncodeTextStrinLen fail \n");
+                       MSG_DEBUG("szApplicationID MmsBinaryEncodeTextStrinLen fail");
                        goto __CATCH;
                }
 
@@ -1460,7 +1449,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
        if (pType->param.szReplyToApplicationID) {
                length = __MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szReplyToApplicationID);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szApplicationID MmsBinaryEncodeTextStrinLen fail \n");
+                       MSG_DEBUG("szApplicationID MmsBinaryEncodeTextStrinLen fail");
                        goto __CATCH;
                }
 
@@ -1483,7 +1472,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
                        if (szTextType != NULL) {
                                length  = __MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: type param MmsBinaryEncodeTextStringLen fail \n");
+                                       MSG_DEBUG("type param MmsBinaryEncodeTextStringLen fail");
                                        goto __CATCH;
                                }
                                totalLength += (length + 1);
@@ -1499,7 +1488,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
                        /* start = Text-string */
                        length  = __MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStart);
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextStringLen fail \n");
+                               MSG_DEBUG("szStart MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
 
@@ -1512,7 +1501,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
                        /* StartInfo (with multipart/related) = Text-string */
                        length  = __MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStartInfo);
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextStringLen fail \n");
+                               MSG_DEBUG("szStartInfo MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
 
@@ -1524,7 +1513,7 @@ static int __MmsBinaryEncodeContentTypeLen(MsgType *pType)
 
 __CATCH:
 
-       MSG_DEBUG("## MmsBinaryEncodeContentTypeLen: failed");
+       MSG_DEBUG("Failed");
        return -1;
 }
 
@@ -1535,13 +1524,13 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
        const char *szTextType = NULL;
        int contentType = MIME_UNKNOWN;
 
+       bool isAscii = true;
+       unsigned  long tmpLength = 0;
+       unsigned char tmpFileName[MSG_LOCALE_FILENAME_LEN_MAX+1];
+
 #ifdef FEATURE_JAVA_MMS
        const char *szParameter = NULL;
 #endif
-
-       MSG_DEBUG("************************************************************************************\n");
-       MSG_DEBUG("MmsBinaryEncodeContentType:  C O N T E N T     T Y P E    \n\n");
-
        /*
         * Content-type-value = Constrained-media | Content-general-form
         * Constrained-media  = Constrained-encoding
@@ -1552,7 +1541,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
         */
 
        if (pFile == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeContentType: invalid file handle\n");
+               MSG_DEBUG("invalid file handle");
                goto __CATCH;
        }
 
@@ -1561,17 +1550,19 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
 
        length = __MmsBinaryEncodeValueLengthLen(typeLength);
        if (length == -1) {
-               MSG_DEBUG("MSmsBinaryEncodeContentType : MmsBinaryEncodeValueLengthLen fail.\n");
+               MSG_DEBUG("MmsBinaryEncodeValueLengthLen fail.");
                goto __CATCH;
        }
 
        if (__MmsBinaryEncodeValueLength(pFile, typeLength, length) == false) {
-               MSG_DEBUG("MSmsBinaryEncodeContentType : MmsBinaryEncodeValueLength fail.\n");
+               MSG_DEBUG("MmsBinaryEncodeValueLength fail.");
                goto __CATCH;
        }
 
        contentType = pType->type;
 
+       MSG_SEC_DEBUG("Content Type : %s", MmsGetTextValue(MmsCodeContentType, (int)contentType));
+
        fieldValue = MmsGetBinaryValue(MmsCodeContentType, (int)contentType);
        if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
                /* Extension-media type */
@@ -1585,83 +1576,66 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
        } else {
                length  = __MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
                if (length == -1) {
-                       MSG_DEBUG("MSmsBinaryEncodeContentType: szTextType MmsBinaryEncodeTextStringLen fail \n");
+                       MSG_DEBUG("szTextType MmsBinaryEncodeTextStringLen fail");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeTextString(pFile, (UINT8*)szTextType, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szTextType MmsBinaryEncodeTextString fail \n");
+                       MSG_DEBUG("szTextType MmsBinaryEncodeTextString fail");
                        goto __CATCH;
                }
        }
 
-       /* Parameters -------------------------------------------------------------- */
-
-       MSG_DEBUG("MmsBinaryEncodeContentType:  P A R M E T E R S    \n\n");
-
        /* Name = Text-string ------------------------------------------------------ */
-
        if (pType->param.szName[0]) {
-               char* pszName = NULL;
-
-               if (MsgIsASCII (pType->param.szName)) {
-
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szName is consisted of ascii char-set chars. \n");
-
-                       pszName = (char *)malloc(strlen(pType->param.szName) +1);
-                       memset(pszName, 0, (strlen(pType->param.szName)+1));
-                       strcpy(pszName, pType->param.szName);
+               MSG_SEC_DEBUG("Parameter Name : %s", pType->param.szName);
+               char *pszName = NULL;
+               if (MmsIsAsciiString (pType->param.szName)) {
+                       MSG_DEBUG("Name is consisted of ascii char-set chars.");
                } else {
-                       MSG_DEBUG("MmsBinaryEncodeContentTypeLen: szName is not consisted of ascii char-set chars. \n");
-
-                       /* if msg-server can't support non ascii, then convert non-ascii to '_' by using _MsgReplaceNonAscii*/
-                       int filelen = strlen(pType->param.szName);
-
-                       pszName = (char *)malloc(filelen + 1);
-                       memset(pszName, 0, (filelen + 1));
-                       strncpy(pszName, pType->param.szName, filelen);
-
-                       MSG_DEBUG("MmsBinaryEncodeContentType: pszName : %s\n", pszName);
+                       isAscii = false;
+                       MSG_DEBUG("Name is NOT consisted of ascii char-set chars.");
                }
 
-               //change empty space to '_' in the file name
-               if (MsgIsSpace(pszName)) {
-                       char*   pszTempName = NULL;
+               pszName = g_strdup(pType->param.szName);
 
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szName has space(' '). \n");
+               //change empty space to '_' in the file name
+               MmsReplaceSpaceChar(pszName);
 
-                       MsgReplaceSpecialChar(pszName, &pszTempName, ' ');
+               gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_NAME) | 0x80;
 
-                       if (pszTempName) {
-                               free(pszName);
-                               pszName = pszTempName;
+               if (isAscii == false) {
+                       if (MsgEncode2Base64(pszName, strlen(pszName), &tmpLength, tmpFileName) == true) {
+                               g_free(pszName);
+                               pszName = g_strdup_printf("=?UTF-8?B?%s?=", tmpFileName);
+                               length =  __MmsBinaryEncodeTextStringLen((UINT8*)pszName);
+                               MSG_DEBUG("base64 encode filename=[%s]", pszName);
                        }
-                       MSG_DEBUG("MmsBinaryEncodeContentType: pszName : %s\n", pszName);
                }
 
                length = __MmsBinaryEncodeTextStringLen((UINT8*)pszName);
+
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szName MmsBinaryEncodeIntegerLen fail \n");
+                       MSG_DEBUG("szName MmsBinaryEncodeIntegerLen fail");
                        free(pszName);
                        goto __CATCH;
                }
-               gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_NAME) | 0x80;
 
                if (__MmsBinaryEncodeTextString(pFile, (UINT8*)pszName, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szName MmsBinaryEncodeTextString fail\n");
+                       MSG_DEBUG("szName MmsBinaryEncodeTextString fail");
                        free(pszName);
                        goto __CATCH;
                }
                free(pszName);
        }
 #ifdef FEATURE_JAVA_MMS
-       MSG_DEBUG(" MmsBinaryEncodeContentType: Application-ID \n");
 
        /* Application-ID: Text-string */
        if (pType->param.szApplicationID) {
+               MSG_SEC_DEBUG("Parameter Application ID : %s", pType->param.szApplicationID);
                length = __MmsBinaryEncodeTextStringLen((UINT8*) pType->param.szApplicationID);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeIntegerLen Fail \n");
+                       MSG_DEBUG("szApplicationID MmsBinaryEncodeIntegerLen Fail");
                        goto __CATCH;
                }
 
@@ -1671,7 +1645,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                        szParameter = MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_APPLICATION_ID);
 
                if (szParameter == NULL) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szParameter is NULL \n");
+                       MSG_DEBUG("szParameter is NULL");
                        goto __CATCH;
                }
 
@@ -1680,7 +1654,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] =(UINT8)NULL;
 
                if (__MmsBinaryEncodeTextString(pFile, (UINT8*) pType->param.szApplicationID, length) == false) {
-                       MSG_DEBUG(" MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeTextString fail\n");
+                       MSG_DEBUG(" szApplicationID MmsBinaryEncodeTextString fail");
                        goto __CATCH;
                }
 
@@ -1688,9 +1662,10 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
 
        /* ReplyToApplicationID: Text-string */
        if (pType->param.szReplyToApplicationID) {
+               MSG_SEC_DEBUG("Parameter Reply To Application-ID : %s", pType->param.szReplyToApplicationID);
                length = __MmsBinaryEncodeTextStringLen((UINT8*) pType->param.szReplyToApplicationID);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szReplyToApplicationID MmsBinaryEncodeIntegerLen Fail \n");
+                       MSG_DEBUG("szReplyToApplicationID MmsBinaryEncodeIntegerLen Fail");
                        goto __CATCH;
                }
 
@@ -1700,7 +1675,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                        szParameter = MmsGetTextValue(MmsCodeParameterCode, MSG_PARAM_REPLY_TO_APPLICATION_ID);
 
                if (szParameter == NULL) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: szParameter is NULL \n");
+                       MSG_DEBUG("szParameter is NULL");
                        goto __CATCH;
                }
 
@@ -1709,7 +1684,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] =(UINT8)NULL;
 
                if (__MmsBinaryEncodeTextString(pFile, (UINT8*) pType->param.szReplyToApplicationID, length) == false) {
-                       MSG_DEBUG(" MmsBinaryEncodeContentType: szApplicationID MmsBinaryEncodeTextString fail\n");
+                       MSG_DEBUG("szApplicationID MmsBinaryEncodeTextString fail");
                        goto __CATCH;
                }
        }
@@ -1718,21 +1693,22 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
        /* Well-known-charset = Any-charset | Integer-value ----------------------- */
 
        if (pType->param.charset != MSG_CHARSET_UNKNOWN) {
+               MSG_DEBUG("Parameter Charset : %d", pType->param.charset);
                fieldValue = MmsGetBinaryValue(MmsCodeCharSet, pType->param.charset);
                length = __MmsBinaryEncodeIntegerLen(fieldValue);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: charSet MmsBinaryEncodeIntegerLen fail \n");
+                       MSG_DEBUG("charSet MmsBinaryEncodeIntegerLen fail");
                        goto __CATCH;
                }
 
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_CHARSET) | 0x80;
                if (__MmsBinaryEncodeInteger(pFile, fieldValue, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeContentType: charSet MmsBinaryEncodeInteger fail\n");
+                       MSG_DEBUG("charSet MmsBinaryEncodeInteger fail");
                        goto __CATCH;
                }
        } else {
                /* Any-charset */
-               if (MmsIsText(contentType)) {
+               if (MmsIsTextType(contentType)) {
                        if (!MmsIsVitemContent (contentType, pType->param.szName)) {
                                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_CHARSET) | 0x80;
                                fieldValue = 0x0000;    //laconic_warning, just to remove warning message
@@ -1743,6 +1719,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
 
        /* type, start, & startInfo : multipart/related only parameters -------------- */
        if (contentType == MIME_MULTIPART_RELATED || contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
+               MSG_SEC_DEBUG("Parameter Content Type : %s", MmsGetTextValue(MmsCodeContentType, pType->param.type));
                /* type ------------------------------------- */
                fieldValue = MmsGetBinaryValue(MmsCodeContentType, pType->param.type);
                if (fieldValue == UNDEFINED_BINARY || fieldValue == 0x0049) {
@@ -1758,13 +1735,13 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                } else {
                        length  = __MmsBinaryEncodeTextStringLen((UINT8*)szTextType);
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: type param MmsBinaryEncodeTextStringLen fail \n");
+                               MSG_DEBUG("type param MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
 
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_TYPE) | 0x80;
                        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)szTextType, length) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: type param MmsBinaryEncodeTextString fail \n");
+                               MSG_DEBUG("type param MmsBinaryEncodeTextString fail");
                                goto __CATCH;
                        }
                }
@@ -1772,16 +1749,17 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                /* start = Text-string ----------------------- */
                if (pType->param.szStart[0]) {
                        /* start = Text-string */
+                       MSG_DEBUG("Parameter Start: %s", pType->param.szStart);
                        length  = __MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStart);
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextStringLen fail \n");
+                               MSG_DEBUG("szStart MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
 
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode,
                                                                                                                                                 MSG_PARAM_START) | 0x80;
                        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)pType->param.szStart, length) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: szStart MmsBinaryEncodeTextString fail \n");
+                               MSG_DEBUG("szStart MmsBinaryEncodeTextString fail");
                                goto __CATCH;
                        }
                }
@@ -1789,15 +1767,16 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
                /* startInfo = Text-string -------------------- */
                if (pType->param.szStartInfo[0]) {
                        /* StartInfo (with multipart/related) = Text-string */
+                       MSG_DEBUG("Parameter StartInfo: %s", pType->param.szStartInfo);
                        length  = __MmsBinaryEncodeTextStringLen((UINT8*)pType->param.szStartInfo);
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextStringLen fail \n");
+                               MSG_DEBUG("szStartInfo MmsBinaryEncodeTextStringLen fail");
                                goto __CATCH;
                        }
 
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeParameterCode, MSG_PARAM_START_INFO) | 0x80;
                        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)pType->param.szStartInfo, length) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeContentType: szStartInfo MmsBinaryEncodeTextString fail \n");
+                               MSG_DEBUG("szStartInfo MmsBinaryEncodeTextString fail");
                                goto __CATCH;
                        }
                }
@@ -1806,7 +1785,7 @@ static bool __MmsBinaryEncodeContentType(FILE *pFile, MsgType *pType, int typeLe
        return true;
 
 __CATCH:
-       MSG_DEBUG("## MmsBinaryEncodeContentType: failed");
+       MSG_DEBUG("Failed");
        return false;
 }
 
@@ -1822,23 +1801,23 @@ static bool __MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pTyp
 
                length = __MmsBinaryEncodeUintvarLen(pType->size);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. headerLeng MmsBinaryEncodeUintvarLen fail \n");
+                       MSG_DEBUG("1. headerLeng MmsBinaryEncodeUintvarLen fail");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeUintvar(pFile, pType->size, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. eaderLeng fail \n");
+                       MSG_DEBUG("1. eaderLeng fail");
                        goto __CATCH;
                }
 
                length = __MmsBinaryEncodeUintvarLen(pBody->size);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. bodyLeng MmsBinaryEncodeUintvarLen fail \n");
+                       MSG_DEBUG("1. bodyLeng MmsBinaryEncodeUintvarLen fail");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeUintvar(pFile, pBody->size, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. bodyLeng fail \n");
+                       MSG_DEBUG("1. bodyLeng fail");
                        goto __CATCH;
                }
 
@@ -1849,7 +1828,7 @@ static bool __MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pTyp
                                goto __CATCH;
 
                        if (MsgFseek(pFile2, pType->offset, SEEK_SET) < 0) {
-                               MSG_DEBUG("MmsBinaryEncodeMsgPart: MsgFseek fail \n");
+                               MSG_DEBUG("MsgFseek fail");
                                goto __CATCH;
                        }
 
@@ -1858,7 +1837,7 @@ static bool __MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pTyp
                        if ((nRead = MsgReadFile(pData, sizeof(char), pType->size, pFile2)) == 0) {
                                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                                       MSG_DEBUG("MmsBinaryEncodeMsgPart: 1. header MsgWriteDataFromEncodeBuffer fail \n");
+                                       MSG_DEBUG("1. header MsgWriteDataFromEncodeBuffer fail");
                                        goto __CATCH;
                                }
                                pType->offset = __MmsGetEncodeOffset();
@@ -1887,36 +1866,36 @@ static bool __MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pTyp
                contentHdrLen  = __MmsBinaryEncodeContentHeaderLen((MimeType)contentType, pType, true);
 
                if (contentTypeLen == -1 || length == -1 || contentHdrLen == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng calculation fail \n");
+                       MSG_DEBUG("headerLeng calculation fail");
                        goto __CATCH;
                }
 
                headerLeng = contentTypeLen + contentHdrLen + length;
                length = __MmsBinaryEncodeUintvarLen(headerLeng);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng MmsBinaryEncodeUintvarLen fail \n");
+                       MSG_DEBUG("headerLeng MmsBinaryEncodeUintvarLen fail");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeUintvar(pFile, headerLeng, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: headerLeng fail \n");
+                       MSG_DEBUG("headerLeng fail");
                        goto __CATCH;
                }
 
                length = __MmsBinaryEncodeUintvarLen(pBody->size);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: bodyLeng MmsBinaryEncodeUintvarLen fail \n");
+                       MSG_DEBUG("bodyLeng MmsBinaryEncodeUintvarLen fail");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeUintvar(pFile, pBody->size, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: bodyLeng fail \n");
+                       MSG_DEBUG("bodyLeng fail");
                        goto __CATCH;
                }
 
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: 2. header MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("2. header MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
 
@@ -1924,12 +1903,12 @@ static bool __MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pTyp
                pType->offset = __MmsGetEncodeOffset();
 
                if (__MmsBinaryEncodeContentType(pFile, pType, contentTypeLen) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentType fail \n");
+                       MSG_DEBUG("MmsBinaryEncodeContentType fail");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeContentHeader(pFile, (MimeType)contentType, pType, true) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeMsgPart: MmsBinaryEncodeContentHeader fail \n");
+                       MSG_DEBUG("MmsBinaryEncodeContentHeader fail");
                        goto __CATCH;
                }
 
@@ -1937,13 +1916,13 @@ static bool __MmsBinaryEncodeMsgPart(FILE *pFile, int contentType, MsgType *pTyp
        }
 
        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos, gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-               MSG_DEBUG("MmsBinaryEncodeMsgPart: contentBody MsgWriteDataFromEncodeBuffer fail \n");
+               MSG_DEBUG("contentBody MsgWriteDataFromEncodeBuffer fail");
                goto __CATCH;
        }
 
        /* content-body --------------------------- */
        if (__MmsBinaryEncodeContentBody(pFile, pBody) == false) {
-               MSG_DEBUG("MmsBinaryEncodeMsgPart: __MmsBinaryEncodeContentBody fail \n");
+               MSG_DEBUG("__MmsBinaryEncodeContentBody fail");
                goto __CATCH;
        }
 
@@ -1961,7 +1940,7 @@ __CATCH:
                pData = NULL;
        }
 
-       MSG_DEBUG("## MmsBinaryEncodeMsgPart: failed\n");
+       MSG_DEBUG("Failed");
        if (pFile2) {
                MsgCloseFile(pFile2);
                pFile2 = NULL;
@@ -1976,9 +1955,6 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
        int     totalLength = 0;
        const char *szTextValue = NULL;
 
-
-       MSG_DEBUG("MmsBinaryEncodeContentHeaderLen: S T A R T \n\n");
-
        /* content-id ------------------------------------------------- */
        if (pType->szContentID[0]) {
                if (bMultipart) { //Binary Encoding
@@ -1987,7 +1963,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
                        /* content-id = Quoted-string */
                        length = __MmsBinaryEncodeTextStringLen((UINT8*)"Content-ID");
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentHeaderLen: Content-ID MmsBinaryEncodeTextStringLen fail.\n");
+                               MSG_DEBUG("Content-ID MmsBinaryEncodeTextStringLen fail.");
                                goto __CATCH;
                        }
 
@@ -1996,7 +1972,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
 
                length = __MmsBinaryEncodeQuotedStringLen((UINT8*)pType->szContentID);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedStringLen fail.\n");
+                       MSG_DEBUG("pType->szContentID MmsBinaryEncodeQuotedStringLen fail.");
                        goto __CATCH;
                }
                totalLength += length;
@@ -2010,7 +1986,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
                        /* content-location = Quoted-string */
                        length = __MmsBinaryEncodeTextStringLen((UINT8*)"Content-Location");
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextStringLen fail.\n");
+                               MSG_DEBUG("Content-Location MmsBinaryEncodeTextStringLen fail.");
                                goto __CATCH;
                        }
 
@@ -2019,7 +1995,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
 
                length = __MmsBinaryEncodeTextStringLen((UINT8*)pType->szContentLocation);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextStringLen fail.\n");
+                       MSG_DEBUG("pType->szContentLocation MmsBinaryEncodeTextStringLen fail.");
                        goto __CATCH;
                }
 
@@ -2050,7 +2026,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
                        if (szTextValue) {
                                length = __MmsBinaryEncodeTextStringLen((UINT8*)"Content-Disposition");
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
+                                       MSG_DEBUG("Content-Disposition MmsBinaryEncodeTextStringLen fail.");
                                        goto __CATCH;
                                }
 
@@ -2058,7 +2034,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
 
                                length = __MmsBinaryEncodeTextStringLen((UINT8*)szTextValue);
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
+                                       MSG_DEBUG("Content-Disposition MmsBinaryEncodeTextStringLen fail.");
                                        goto __CATCH;
                                }
                                totalLength += length;
@@ -2069,8 +2045,7 @@ static int __MmsBinaryEncodeContentHeaderLen(MimeType contentType, MsgType *pTyp
        return totalLength;
 
 __CATCH:
-       MSG_DEBUG("## MmsBinaryEncodeContentHeadeLen: failed");
-
+       MSG_DEBUG("Failed");
        return -1;
 }
 
@@ -2079,73 +2054,78 @@ static bool __MmsBinaryEncodeContentHeader(FILE *pFile, MimeType contentType, Ms
        int     length = 0;
        const char *szTextValue = NULL;
 
-       MSG_DEBUG("MmsBinaryEncodeContentHeader: S T A R T \n\n");
-
        /* content-id ------------------------------------------------- */
        if (pType->szContentID[0]) {
+
+               MSG_SEC_DEBUG("Content ID : %s", pType->szContentID);
+
                if (bMultipart) { //Binary Encoding
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_CONTENTID) | 0x80;
                } else {
                        /* content-id = Quoted-string */
                        length = __MmsBinaryEncodeTextStringLen((UINT8*)"Content-ID");
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-ID MmsBinaryEncodeTextStringLen fail.\n");
+                               MSG_DEBUG("Content-ID MmsBinaryEncodeTextStringLen fail.");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-ID", length) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-ID MmsBinaryEncodeTextString fail.\n");
+                               MSG_DEBUG("Content-ID MmsBinaryEncodeTextString fail.");
                                goto __CATCH;
                        }
                }
 
                length = __MmsBinaryEncodeQuotedStringLen((UINT8*)pType->szContentID);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedStringLen fail.\n");
+                       MSG_DEBUG("pType->szContentID MmsBinaryEncodeQuotedStringLen fail.");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeQuotedString(pFile, (UINT8*)pType->szContentID, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentID MmsBinaryEncodeQuotedString fail.\n");
+                       MSG_DEBUG("pType->szContentID MmsBinaryEncodeQuotedString fail.");
                        goto __CATCH;
                }
        }
 
        if (pType->szContentLocation[0]) {
+
+               MSG_SEC_DEBUG("Content Location : %s", pType->szContentLocation);
+
                if (bMultipart) { //Binary Encoding
                        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeMsgBodyHeaderCode, MMS_BODYHDR_CONTENTLOCATION) | 0x80;
                } else {
                        /* content-location = Quoted-string */
                        length = __MmsBinaryEncodeTextStringLen((UINT8*)"Content-Location");
                        if (length == -1) {
-                               MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextStringLen fail.\n");
+                               MSG_DEBUG("Content-Location MmsBinaryEncodeTextStringLen fail.");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-Location", length) == false) {
-                               MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Location MmsBinaryEncodeTextString fail.\n");
+                               MSG_DEBUG("Content-Location MmsBinaryEncodeTextString fail.");
                                goto __CATCH;
                        }
                }
 
                length = __MmsBinaryEncodeTextStringLen((UINT8*)pType->szContentLocation);
                if (length == -1) {
-                       MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextStringLen fail.\n");
+                       MSG_DEBUG("pType->szContentLocation MmsBinaryEncodeTextStringLen fail.");
                        goto __CATCH;
                }
 
                if (__MmsBinaryEncodeTextString(pFile, (UINT8*)pType->szContentLocation, length) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeContentHeader: pType->szContentLocation MmsBinaryEncodeTextString fail.\n");
+                       MSG_DEBUG("pType->szContentLocation MmsBinaryEncodeTextString fail.");
                        goto __CATCH;
                }
        }
 
-       /* MIME_APPLICATION_VND_WAP_MULTIPART_RELATEDrequires always "inline" */
+       /* MIME_APPLICATION_VND_WAP_MULTIPART_RELATED requires always "inline" */
 
        if (contentType != MIME_APPLICATION_VND_WAP_MULTIPART_RELATED &&
                contentType != MIME_MULTIPART_RELATED &&
                pType->disposition != INVALID_VALUE) {
 
+               MSG_DEBUG("Content Disposition : %d", pType->disposition);
                /*
                 * Content-disposition-value = Value-length Disposition *(Parameter)
                 * Disposition = Form-data | Attachment | Inline | Token-text
@@ -2174,23 +2154,23 @@ static bool __MmsBinaryEncodeContentHeader(FILE *pFile, MimeType contentType, Ms
                        if (szTextValue) {
                                length = __MmsBinaryEncodeTextStringLen((UINT8*)"Content-Disposition");
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
+                                       MSG_DEBUG("Content-Disposition MmsBinaryEncodeTextStringLen fail.");
                                        goto __CATCH;
                                }
 
                                if (__MmsBinaryEncodeTextString(pFile, (UINT8*)"Content-Disposition", length) == false) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextString fail.\n");
+                                       MSG_DEBUG("Content-Disposition MmsBinaryEncodeTextString fail.");
                                        goto __CATCH;
                                }
 
                                length = __MmsBinaryEncodeTextStringLen((UINT8*)szTextValue);
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextStringLen fail.\n");
+                                       MSG_DEBUG("Content-Disposition MmsBinaryEncodeTextStringLen fail.");
                                        goto __CATCH;
                                }
 
                                if (__MmsBinaryEncodeTextString(pFile, (UINT8*)szTextValue, length) == false) {
-                                       MSG_DEBUG("MmsBinaryEncodeContentHeader: Content-Disposition MmsBinaryEncodeTextString fail.\n");
+                                       MSG_DEBUG("Content-Disposition MmsBinaryEncodeTextString fail.");
                                        goto __CATCH;
                                }
                        }
@@ -2200,7 +2180,7 @@ static bool __MmsBinaryEncodeContentHeader(FILE *pFile, MimeType contentType, Ms
        return true;
 
 __CATCH:
-       MSG_DEBUG("## MmsBinaryEncodeContentHeader: failed");
+       MSG_DEBUG("Failed");
        return false;
 }
 
@@ -2254,7 +2234,7 @@ static bool __MmsBinaryEncodeContentBody(FILE *pFile, MsgBody *pBody)
        return true;
 
 __CATCH:
-       MSG_DEBUG("## __MmsBinaryEncodeContentBody: failed\n");
+       MSG_DEBUG("##failed");
        if (pData) {
                free(pData);
                pData = NULL;
@@ -2307,14 +2287,14 @@ static bool __MmsBinaryEncodeInteger(FILE *pFile, UINT32 integer, int length)
 
 
        if (pFile == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeInteger: source == NULL \n");
+               MSG_DEBUG("source == NULL");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeInteger: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -2387,14 +2367,14 @@ static bool __MmsBinaryEncodeLongInteger(FILE *pFile, UINT32 integer, int length
         */
 
        if (pFile == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeLongInteger: source == NULL \n");
+               MSG_DEBUG("pFile == NULL");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeLongInteger: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -2419,10 +2399,8 @@ static int __MmsBinaryEncodeTextStringLen(UINT8 *source)
 {
        int      length = 0;
 
-       MSG_DEBUG("MmsBinaryEncodeTextStringLen: \n");
-
        if (source == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeTextStringLen: source == NULL \n");
+               MSG_DEBUG("source == NULL");
                return -1;
        }
 
@@ -2444,9 +2422,6 @@ static int __MmsBinaryEncodeTextStringLen(UINT8 *source)
 */
 static bool __MmsBinaryEncodeTextString(FILE *pFile, UINT8 *source, int length)
 {
-
-       MSG_DEBUG("MmsBinaryEncodeTextString: \n");
-
        /*
         * make text string
         * Text-string = [Quote] *TEXT End-of-string
@@ -2457,14 +2432,14 @@ static bool __MmsBinaryEncodeTextString(FILE *pFile, UINT8 *source, int length)
         */
 
        if (pFile == NULL || source == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeTextString: source == NULL \n");
+               MSG_DEBUG("pFile == %p, source = %p", pFile, source);
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeTextString: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -2529,14 +2504,14 @@ static bool __MmsBinaryEncodeUintvar(FILE *pFile, UINT32 integer, int length)
        } source;
 
        if (pFile == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeUintvar: pFile == INVALID_HBOJ \n");
+               MSG_DEBUG("pFile == INVALID_HBOJ");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeUintvar: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -2600,14 +2575,14 @@ static bool __MmsBinaryEncodeValueLength(FILE *pFile, UINT32 integer, int length
         */
 
        if (pFile == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeValueLength: pFile == INVALID_HBOJ \n");
+               MSG_DEBUG("pFile == INVALID_HBOJ");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeValueLength: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -2617,7 +2592,7 @@ static bool __MmsBinaryEncodeValueLength(FILE *pFile, UINT32 integer, int length
        } else {
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = (UINT8)LENGTH_QUOTE;
                if (__MmsBinaryEncodeUintvar(pFile, integer, length - 1) == false) {    // LENGTH_QUOTE
-                       MSG_DEBUG("MmsBinaryEncodeValueLength: MmsBinaryEncodeUintvar fail\n");
+                       MSG_DEBUG("MmsBinaryEncodeUintvar fail");
                        goto __CATCH;
                }
        }
@@ -2631,7 +2606,7 @@ __CATCH:
 static int __MmsBinaryEncodeQuotedStringLen(UINT8 *pSrc)
 {
        if (pSrc == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeQuotedStringLen: invalid file\n");
+               MSG_DEBUG("invalid file");
                goto __CATCH;
        }
 
@@ -2653,14 +2628,14 @@ __CATCH:
 static bool __MmsBinaryEncodeQuotedString(FILE *pFile, UINT8 *source, int length)
 {
        if (source == NULL || pFile == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeQuotedString: invalid file\n");
+               MSG_DEBUG("invalid file");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeQuotedString: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -2683,26 +2658,23 @@ static int __MmsBinaryEncodeEncodedStringLen(UINT8 *source)
        int textLeng            = 0;
        int valueLengthLen      = 0;
 
-
-       MSG_DEBUG("MmsBinaryEncodeEncodedStringLen: \n");
-
        /* value-length charSet text-string */
        /* Estimate charset value length and text string length */
        charLeng = __MmsBinaryEncodeIntegerLen(charset);
        if (charLeng == -1) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : charLeng MmsBinaryEncodeTextStringLen fail.\n");
+               MSG_DEBUG(" charLeng MmsBinaryEncodeTextStringLen fail.");
                goto __CATCH;;
        }
 
        textLeng = __MmsBinaryEncodeTextStringLen((UINT8*)source);
        if (textLeng == -1)     {
-               MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : textLeng MmsBinaryEncodeTextStringLen fail.\n");
+               MSG_DEBUG(" textLeng MmsBinaryEncodeTextStringLen fail.");
                goto __CATCH;;
        }
 
        valueLengthLen = __MmsBinaryEncodeValueLengthLen(charLeng + textLeng);
        if (valueLengthLen == -1) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedStringLen : valLengthLen MmsBinaryEncodeTextStringLen fail.\n");
+               MSG_DEBUG(" valLengthLen MmsBinaryEncodeTextStringLen fail.");
                goto __CATCH;
        }
 
@@ -2725,65 +2697,60 @@ static bool __MmsBinaryEncodeEncodedString(FILE *pFile, UINT8 *source, int lengt
        int textLeng = 0;
        int valLengthLen = 0;
 
-
-       MSG_DEBUG("MmsBinaryEncodeEncodedString: \n");
-
        /* value-length charSet text-string */
-
        if (pFile == NULL || source == NULL) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString: invalid input parameter\n");
+               MSG_DEBUG("invalid input parameter");
                goto __CATCH;
        }
 
        /* Estimate charset value length and text string length */
        charLeng = __MmsBinaryEncodeIntegerLen(charset);
        if (charLeng == -1) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString : charLeng MmsBinaryEncodeTextStringLen fail.\n");
+               MSG_DEBUG("charLeng MmsBinaryEncodeTextStringLen fail.");
                goto __CATCH;;
        }
 
        textLeng = __MmsBinaryEncodeTextStringLen((UINT8*)source);
        if (textLeng == -1) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString : textLeng MmsBinaryEncodeTextStringLen fail.\n");
+               MSG_DEBUG("textLeng MmsBinaryEncodeTextStringLen fail.");
                goto __CATCH;;
        }
 
        valLengthLen = __MmsBinaryEncodeValueLengthLen(charLeng + textLeng);
        if (valLengthLen == -1) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeValueLengthLen fail.\n");
+               MSG_DEBUG("MmsBinaryEncodeValueLengthLen fail.");
                goto __CATCH;
        }
 
        if (length != (charLeng + textLeng + valLengthLen))
        {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString: invalid length\n");
+               MSG_DEBUG("invalid length");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("MmsBinaryEncodeEncodedString: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
        /* Value length of charset value and text string */
        if (__MmsBinaryEncodeValueLength(pFile, charLeng + textLeng, valLengthLen) == false) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeValueLength fail.\n");
+               MSG_DEBUG("MmsBinaryEncodeValueLength fail.");
                goto __CATCH;
        }
 
        /* fixme: Write charset on buffer -> integer value not long-integer */
        if (__MmsBinaryEncodeInteger(pFile, charset, charLeng) == false) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeInteger fail.\n");
+               MSG_DEBUG("MmsBinaryEncodeInteger fail.");
                goto __CATCH;
        }
 
-
        /* Write text string on buffer */
        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)source, textLeng) == false) {
-               MSG_DEBUG("MmsBinaryEncodeEncodedString : MmsBinaryEncodeTextString fail.\n");
+               MSG_DEBUG("MmsBinaryEncodeTextString fail.");
                goto __CATCH;
        }
 
@@ -2798,18 +2765,18 @@ static  bool __MmsBinaryEncodeFieldCodeAndValue(FILE *pFile, UINT8 fieldCode, UIN
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
        if (fieldCode == 0xff) {
-               MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldCode \n");
+               MSG_DEBUG("invalid fieldCode");
                goto __CATCH;
        }
 
        if (fieldValue == 0xff) {
-               MSG_DEBUG("__MmsBinaryEncodeFieldCodeAndValue: invalid fieldValue \n");
+               MSG_DEBUG("invalid fieldValue");
                return true;
        }
 
@@ -2835,34 +2802,36 @@ static bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen)
        dateTime = localtime(&RawTime);
        dateSec = mktime(dateTime);
 
-
        fieldCode = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_TRID) | 0x80;
        if (fieldCode == 0xff) {
-               MSG_DEBUG("__MmsBinaryEncodeTrID: invalid fieldCode \n");
+               MSG_DEBUG("Invalid fieldCode[0x%02x]", fieldCode & 0x7F);
                goto __CATCH;
        }
 
-       snprintf(szBuff, MMS_TR_ID_LEN + 1, "%lu.%lu", dateSec, (unsigned long)random());
-       MSG_DEBUG("__MmsBinaryEncodeTrID: 2. szBuff = %s\n", szBuff);
+       if (szTrID && strlen(szTrID)) {
+               snprintf(szBuff, MMS_TR_ID_LEN + 1, "%s", szTrID);
+       } else {
+               snprintf(szBuff, MMS_TR_ID_LEN + 1, "%lu.%lu", dateSec, (unsigned long)random());
+               MSG_SEC_DEBUG("Generated Transaction ID = %s", szBuff);
+       }
 
        length = __MmsBinaryEncodeTextStringLen((UINT8*)szBuff);
        if (length == -1) {
-               MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextStringLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeTextStringLen fail");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeTrID: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
-
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)szBuff, length) == false) {
-               MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextString fail\n");
+               MSG_DEBUG("MmsBinaryEncodeTextString fail");
                goto __CATCH;
        }
 
@@ -2871,6 +2840,7 @@ static bool __MmsBinaryEncodeTrID(FILE *pFile, char *szTrID, int bufLen)
                strncpy(szTrID, szBuff, bufLen - 1);
        }
 
+       MSG_SEC_INFO("X-Mms-Transaction-Id = [%s]", szBuff);
        return true;
 
 __CATCH:
@@ -2885,29 +2855,29 @@ static bool __MmsBinaryEncodeMsgID(FILE *pFile, const char *szMsgID)
 
        fieldCode = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_MSGID) | 0x80;
        if (fieldCode == 0xff) {
-               MSG_DEBUG("__MmsBinaryEncodeTrID: invalid fieldCode \n");
+               MSG_DEBUG("invalid fieldCode");
                goto __CATCH;
        }
 
-       MSG_DEBUG("__MmsBinaryEncodeMsgID: 2. szBuff = %s\n", szMsgID);
+       MSG_DEBUG("2. szBuff = %s", szMsgID);
 
        length = __MmsBinaryEncodeTextStringLen((UINT8*)szMsgID);
        if (length == -1) {
-               MSG_DEBUG("__MmsBinaryEncodeMsgID: MmsBinaryEncodeTextStringLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeTextStringLen fail");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeTrID: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = fieldCode;
        if (__MmsBinaryEncodeTextString(pFile, (UINT8*)szMsgID, length) == false)       {
-               MSG_DEBUG("__MmsBinaryEncodeTrID: MmsBinaryEncodeTextString fail\n");
+               MSG_DEBUG("MmsBinaryEncodeTextString fail");
                goto __CATCH;
        }
 
@@ -2923,28 +2893,28 @@ static bool __MmsBinaryEncodeMmsVersion(FILE *pFile)
        UINT8 majorVer = MMS_MAJOR_VERSION;
        UINT8 minorVer = MMS_MINOR_VERSION;
 
-       MSG_DEBUG("__MmsBinaryEncodeMmsVersion: \n");
-
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsBinaryEncodeMmsVersion: invalid input file \n");
+               MSG_DEBUG("invalid input file");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 2) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeMmsVersion: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
 
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_VERSION) | 0x80;
 
-       MSG_DEBUG("__MmsBinaryEncodeMmsVersion: major version (%d)\n", majorVer);
-       MSG_DEBUG("__MmsBinaryEncodeMmsVersion: minor version (%d)\n", minorVer);
+       MSG_DEBUG("major version (%d)", majorVer);
+       MSG_DEBUG("minor version (%d)", minorVer);
 
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos] = (majorVer << 4) | (minorVer & 0x0f) | MSB;
 
+       MSG_SEC_INFO("X-Mms-MMS-Version = [0x%02x]", gpMmsEncodeBuf[gCurMmsEncodeBuffPos]);
+
        if (gpMmsEncodeBuf[gCurMmsEncodeBuffPos] < 0x80) {
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] |= 0x80;
        } else {
@@ -2957,15 +2927,19 @@ __CATCH:
        return false;
 }
 
-static bool __MmsBinaryEncodeDate(FILE *pFile)
+static bool __MmsBinaryEncodeDate(FILE *pFile, time_t inpDateSec)
 {
        struct  tm      *dateTime = NULL;
        time_t  dateSec = 0;
 
-       dateSec = time(NULL);
+       if(inpDateSec > 0)
+               dateSec = inpDateSec;
+       else
+               dateSec = time(NULL);
+
        dateTime = localtime(&dateSec);
 
-       MSG_DEBUG("%d - %d - %d, %d : %d (SYSTEM)", dateTime->tm_year + 1900, dateTime->tm_mon + 1, dateTime->tm_mday
+       MSG_SEC_INFO("%d - %d - %d, %d : %d (SYSTEM)", dateTime->tm_year + 1900, dateTime->tm_mon + 1, dateTime->tm_mday
                , dateTime->tm_hour, dateTime->tm_min);
 
        if (dateSec > 0) {
@@ -2975,7 +2949,7 @@ static bool __MmsBinaryEncodeDate(FILE *pFile)
                if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < (length + 1)) { // + fieldCode
                        if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                                gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                               MSG_DEBUG("__MmsBinaryEncodeDate: MsgWriteDataFromEncodeBuffer fail \n");
+                               MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                                goto __CATCH;
                        }
                }
@@ -2983,11 +2957,12 @@ static bool __MmsBinaryEncodeDate(FILE *pFile)
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeFieldCode, MMS_CODE_DATE) | 0x80;
 
                if (__MmsBinaryEncodeLongInteger(pFile, dateSec, length) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeDate: date MmsBinaryEncodeLongInteger error\n");
+                       MSG_DEBUG("date MmsBinaryEncodeLongInteger error");
                        goto __CATCH;
                }
+
        } else {
-               MSG_DEBUG("__MmsBinaryEncodeDate: date has a negative value (%d) \n", dateSec);
+               MSG_DEBUG("date has a negative value (%d)", dateSec);
                goto __CATCH;
        }
        return true;
@@ -2999,14 +2974,14 @@ __CATCH:
 static bool __MmsBinaryEncodeFrom(FILE *pFile)
 {
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsBinaryEncodeFrom: invalid input file \n");
+               MSG_DEBUG("invalid input file");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < 3) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeFrom: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -3015,6 +2990,8 @@ static bool __MmsBinaryEncodeFrom(FILE *pFile)
        /* length of MMS_INSERT_ADDRESS_TOKEN value */
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = 0x01;
        gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN) | 0x80;
+
+       MSG_SEC_INFO("From  = [INSERT_ADDRESS_TOKEN]");
        return true;
 
 __CATCH:
@@ -3026,7 +3003,7 @@ static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char
        int length = 0;
 
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsBinaryEncodeOneAddress: invalid input file \n");
+               MSG_DEBUG("invalid input file");
                goto __CATCH;
        }
 
@@ -3034,14 +3011,14 @@ static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char
        length = __MmsBinaryEncodeEncodedStringLen((UINT8*)szAddrStr);
 
        if (length == -1) {
-               MSG_DEBUG("__MmsBinaryEncodeOneAddress: MmsBinaryEncodeEncodedStringLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeEncodedStringLen fail");
                goto __CATCH;
        }
 
        if ((gMmsEncodeMaxLen - gCurMmsEncodeBuffPos) < length + 1) {
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeOneAddress: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -3050,10 +3027,18 @@ static bool __MmsBinaryEncodeOneAddress(FILE *pFile, MmsFieldCode addrType, char
 
 
        if (__MmsBinaryEncodeEncodedString(pFile, (UINT8*)szAddrStr, length) == false) {
-               MSG_DEBUG("__MmsBinaryEncodeOneAddress: MmsBinaryEncodeEncodedString fail \n");
+               MSG_DEBUG("MmsBinaryEncodeEncodedString fail");
                goto __CATCH;
        }
 
+       if (addrType == MMS_CODE_TO )
+               MSG_SEC_INFO("To = [%s]", szAddrStr);
+       else if (addrType == MMS_CODE_CC)
+               MSG_SEC_INFO("CC = [%s]", szAddrStr);
+       else if (addrType == MMS_CODE_BCC)
+               MSG_SEC_INFO("Bcc = [%s]", szAddrStr);
+
+
        return true;
 
 __CATCH:
@@ -3066,7 +3051,7 @@ static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *s
 
 
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsBinaryEncodeAddress: invalid input file \n");
+               MSG_DEBUG("invalid input file");
                goto __CATCH;
        }
 
@@ -3080,7 +3065,7 @@ static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *s
 
                        *pSingleAddr = MSG_CH_NULL;
                        if (__MmsBinaryEncodeOneAddress(pFile, addrType, szAddr) == false) {
-                               MSG_DEBUG("__MmsBinaryEncodeAddress: __MmsBinaryEncodeAddress fail\n");
+                               MSG_DEBUG("__MmsBinaryEncodeAddress fail");
                                goto __CATCH;
                        }
                        *pSingleAddr = MSG_CH_SEMICOLON;
@@ -3089,7 +3074,7 @@ static bool __MmsBinaryEncodeAddress(FILE *pFile, MmsFieldCode addrType, char *s
                        pSingleAddr  = NULL;
                } else {
                        if (__MmsBinaryEncodeOneAddress(pFile, addrType, szAddr) == false) {
-                               MSG_DEBUG("__MmsBinaryEncodeAddress: __MmsBinaryEncodeAddress fail\n");
+                               MSG_DEBUG("__MmsBinaryEncodeAddress fail");
                                goto __CATCH;
                        }
 
@@ -3109,14 +3094,14 @@ static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeSt
        int             length   = 0;
 
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsBinaryEncodeTime: invalid input file \n");
+               MSG_DEBUG("invalid input file");
                goto __CATCH;
        }
 
        if (time.time == 0 ||
                (fieldCode != MMS_CODE_EXPIRYTIME && fieldCode != MMS_CODE_DELIVERYTIME && fieldCode != MMS_CODE_REPLYCHARGINGDEADLINE) ||
                (time.type != MMS_TIMETYPE_ABSOLUTE && time.type != MMS_TIMETYPE_RELATIVE)) {
-               MSG_DEBUG("__MmsBinaryEncodeTime: time.type = %d \n", time.type);
+               MSG_DEBUG("time.type = %d", time.type);
                return true;
        }
 
@@ -3132,13 +3117,13 @@ static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeSt
        }
 
        if (timeLen <= 0) {
-               MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongIntegerLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeLongIntegerLen fail");
                goto __CATCH;
        }
 
        length = __MmsBinaryEncodeValueLengthLen(timeLen + 1);  //time length + time type token
        if (length == -1) {
-               MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeValueLengthLen fail \n");
+               MSG_DEBUG("MmsBinaryEncodeValueLengthLen fail");
                goto __CATCH;
        }
 
@@ -3146,7 +3131,7 @@ static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeSt
 
                if (MsgWriteDataFromEncodeBuffer(pFile, gpMmsEncodeBuf, &gCurMmsEncodeBuffPos,
                                                                                        gMmsEncodeMaxLen, &gMmsEncodeCurOffset) == false) {
-                       MSG_DEBUG("_MmsBinaryEncodeSendReqHdr: MsgWriteDataFromEncodeBuffer fail \n");
+                       MSG_DEBUG("MsgWriteDataFromEncodeBuffer fail");
                        goto __CATCH;
                }
        }
@@ -3156,7 +3141,7 @@ static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeSt
 
        /* value length */
        if (__MmsBinaryEncodeValueLength(pFile, timeLen + 1, length) == false) {
-               MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeValueLength fail \n");
+               MSG_DEBUG("MmsBinaryEncodeValueLength fail");
                goto __CATCH;
        }
 
@@ -3164,13 +3149,13 @@ static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeSt
        if (time.type == MMS_TIMETYPE_RELATIVE) {
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_RELATIVE) | 0x80;
                if (__MmsBinaryEncodeInteger(pFile, time.time, timeLen) == false)       {
-                       MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongInteger fail \n");
+                       MSG_DEBUG("MmsBinaryEncodeLongInteger fail");
                        goto __CATCH;
                }
        } else {
                gpMmsEncodeBuf[gCurMmsEncodeBuffPos++] = MmsGetBinaryValue(MmsCodeTimeType, MMS_TIMETYPE_ABSOLUTE) | 0x80;
                if (__MmsBinaryEncodeLongInteger(pFile, time.time, timeLen) == false) {
-                       MSG_DEBUG("__MmsBinaryEncodeTime: MmsBinaryEncodeLongInteger fail \n");
+                       MSG_DEBUG("MmsBinaryEncodeLongInteger fail");
                        goto __CATCH;
                }
        }
@@ -3180,3 +3165,109 @@ static bool __MmsBinaryEncodeTime(FILE *pFile, MmsFieldCode fieldCode, MmsTimeSt
 __CATCH:
        return false;
 }
+
+char *_MsgSkipWS3(char *s)
+{
+       while (true) {
+               if ((*s == MSG_CH_CR) ||
+                       (*s == MSG_CH_LF) ||
+                       (*s == MSG_CH_SP) ||
+                       (*s == MSG_CH_TAB))
+                       ++s;
+               else
+                       return s;
+       }
+}
+//////////////////////////////////////////////////////////////////////////////
+static bool __EncodeMmsMessage(MmsMsg *pMmsMsg, const char *raw_filepath)
+{
+       bool encode_ret = false;
+       mode_t file_mode = (S_IRUSR | S_IWUSR);
+
+       if (pMmsMsg == NULL || raw_filepath == NULL) {
+               MSG_DEBUG("Invalid Parameter pMmsMsg = %p , raw_filepath = %p", pMmsMsg, raw_filepath);
+               return false;
+       }
+
+       FILE *pFile = MsgOpenFile(raw_filepath, "wb+");
+
+       if (pFile == NULL) {
+               MSG_FATAL("File Open Error: %s", strerror(errno));
+               goto __CATCH;
+       }
+
+       if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
+               MSG_DEBUG("File Fseek Error: %s", strerror(errno));
+               goto __CATCH;
+       }
+
+       if (fchmod(fileno(pFile), file_mode) < 0) {
+               MSG_DEBUG("File chmod Error: %s", strerror(errno));
+               goto __CATCH;
+       }
+
+       switch(pMmsMsg->mmsAttrib.msgType)
+       {
+               case MMS_MSGTYPE_SEND_REQ:
+               case MMS_MSGTYPE_SEND_CONF:
+                       encode_ret = MmsEncodeSendReq(pFile, pMmsMsg);
+                       if (encode_ret == false) {
+                               MSG_DEBUG("Fail to MmsEncodeSendReq");
+                               goto __CATCH;
+                       }
+               break;
+               default:
+                       MSG_DEBUG("Not Support msg type : %d", pMmsMsg->mmsAttrib.msgType);
+                       goto __CATCH;
+               break;
+       }
+
+       MsgFsync(pFile);        //file is written to device immediately, it prevents missing file data from unexpected power off
+       MsgCloseFile(pFile);
+
+       return true;
+
+__CATCH:
+       if (pFile) {
+               MsgCloseFile(pFile);
+       }
+
+       return false;
+}
+
+MmsPluginEncoder *MmsPluginEncoder::pInstance = NULL;
+
+MmsPluginEncoder *MmsPluginEncoder::instance()
+{
+       if (!MmsPluginEncoder::pInstance)
+               MmsPluginEncoder::pInstance = new MmsPluginEncoder();
+
+       return MmsPluginEncoder::pInstance;
+}
+
+MmsPluginEncoder::MmsPluginEncoder(){}
+MmsPluginEncoder::~MmsPluginEncoder(){}
+
+void MmsPluginEncoder::encodeMmsPdu(MMS_DATA_S *pMmsData, msg_message_id_t msgID, const char *pduFilePath)
+{
+       MmsMsg *pMmsMsg = (MmsMsg *)calloc(1, sizeof(MmsMsg));
+
+       if (MmsConvertMmsMsg(pMmsMsg, pMmsData) != true) {
+               MSG_DEBUG("Fail to Compose MMS Message");
+               goto __CATCH;
+       }
+
+       encodeMmsPdu(pMmsMsg, msgID, pduFilePath);
+
+__CATCH:
+       MmsReleaseMmsMsg(pMmsMsg);
+       MSG_FREE(pMmsMsg);
+
+}
+
+void MmsPluginEncoder::encodeMmsPdu(MmsMsg *pMmsMsg, msg_message_id_t msgID, const char *pduFilePath)
+{
+       pMmsMsg->msgID = msgID;
+
+       __EncodeMmsMessage(pMmsMsg, pduFilePath);
+}
index 74b2aa5..15c4490 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -23,7 +23,7 @@
 #include "MmsPluginInternal.h"
 
 /*==================================================================================================
-                                     IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
+                                     IMPLEMENTATION OF MmsPluginEventHandler - Member Functions
 ==================================================================================================*/
 MmsPluginEventHandler *MmsPluginEventHandler::pInstance = NULL;
 
@@ -75,6 +75,10 @@ void MmsPluginEventHandler::handleMmsReceivedData(mmsTranQEntity *pRequest, char
        // received data is retrieve-conf
        case eMMS_RETRIEVE_AUTO_CONF:
        case eMMS_RETRIEVE_MANUAL_CONF:
+               MSG_ADDRESS_INFO_S addrInfo;
+               memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+               msgInfo.addressList = &addrInfo;
+
                MmsPluginInternal::instance()->processRetrieveConf(&msgInfo, pRequest, pRetrievedFilePath);
 
                // callback to MSG FW
@@ -106,6 +110,11 @@ void MmsPluginEventHandler::handleMmsError(mmsTranQEntity *pRequest)
 
        MSG_DEBUG("pRequest->msgId [%d]", pRequest->msgId);
 
+       time_t curTime;
+       curTime = time(NULL);
+
+       msgInfo.displayTime = curTime;
+
        switch (pRequest->eMmsPduType) {
        case eMMS_SEND_REQ:
        case eMMS_SEND_CONF:
@@ -157,6 +166,8 @@ void MmsPluginEventHandler::handleMmsError(mmsTranQEntity *pRequest)
                break;
        }
 
+       MSG_DEBUG("Error value of MsgMmsConfIncomingListner [%d]", err);
+
        MSG_END();
 }
 
index 5d5a4f9..9e382bb 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdlib.h>
 #include "MmsPluginHttp.h"
 #include "MmsPluginUserAgent.h"
 #include "MmsPluginConnManWrapper.h"
-
-#define MMS_FREE(obj)\
-       if (obj){\
-               free(obj);\
-               obj = NULL;\
-       }
-
+#include "MsgGconfWrapper.h"
+#include "MmsPluginUtil.h"
 
 static void __http_print_profile(CURL *curl);
 static int __http_debug_cb (CURL *input_curl, curl_infotype input_info_type, char *input_data , size_t input_size, void *input_void);
@@ -39,15 +34,15 @@ static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen);
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
-static int __http_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
-{
-       MSG_DEBUG("download(%.0f/%.0f) : upload(%.0f/%.0f)", dlnow, dltotal, ulnow, ultotal);
-       return 0;
-}
+//static int __http_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+//{
+//     MSG_INFO("download(%.0f/%.0f) : upload(%.0f/%.0f)", dlnow, dltotal, ulnow, ultotal);
+//     return 0;
+//}
 
 static int __http_debug_cb (CURL *input_curl, curl_infotype input_info_type, char *input_data , size_t input_size, void *input_void)
 {
-       MSG_DEBUG("curl_infotype [%d] : %s", input_info_type, input_data);
+       MSG_INFO("curl_infotype [%d] : %s", input_info_type, input_data);
        return 0;
 }
 
@@ -75,54 +70,54 @@ static void __http_print_profile(CURL *curl)
 
        //time
        curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
-       MSG_DEBUG("profile http Time: total %.3f seconds", total_time);
+       MSG_SEC_INFO("profile http Time: total %.3f seconds", total_time);
 
        //url
        curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
-       MSG_DEBUG("profile http Url: %s", url);
+       MSG_SEC_INFO("profile http Url: %s", url);
 
        //size
        curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &size_up);
-       MSG_DEBUG("profile http Size: upload %.3f bytes", size_up);
+       MSG_SEC_INFO("profile http Size: upload %.3f bytes", size_up);
 
        curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &size_down);
-       MSG_DEBUG("profile http Size: download %.3f bytes", size_down);
+       MSG_SEC_INFO("profile http Size: download %.3f bytes", size_down);
 
        curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &size);
-       MSG_DEBUG("profile http Size: header %ld bytes", size);
+       MSG_SEC_INFO("profile http Size: header %ld bytes", size);
 
        curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &size);
-       MSG_DEBUG("profile http Size: request %ld bytes", size);
+       MSG_SEC_INFO("profile http Size: request %ld bytes", size);
 
        //speed
        curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
-       MSG_DEBUG("profile http Speed: upload %.3f bytes/sec", speed_upload);
+       MSG_SEC_INFO("profile http Speed: upload %.3f bytes/sec", speed_upload);
 
        curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed_download);
-       MSG_DEBUG("profile http Speed: download %.3f bytes/sec", speed_download);
+       MSG_SEC_INFO("profile http Speed: download %.3f bytes/sec", speed_download);
 
        //content
        curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &content_type);
-       MSG_DEBUG("profile http Content: type %s", content_type);
+       MSG_SEC_INFO("profile http Content: type %s", content_type);
 
        curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_length);
-       MSG_DEBUG("profile http Content: length download %.3f", content_length);
+       MSG_SEC_INFO("profile http Content: length download %.3f", content_length);
 
        curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &content_length);
-       MSG_DEBUG("profile http Content: length upload %.3f", content_length);
+       MSG_SEC_INFO("profile http Content: length upload %.3f", content_length);
 
        //ip & port
        curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
-       MSG_DEBUG("profile http primary: ip %s", ip);
+       MSG_SEC_INFO("profile http primary: ip %s", ip);
 
        curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
-       MSG_DEBUG("profile http primary: port %ld", port);
+       MSG_SEC_INFO("profile http primary: port %ld", port);
 
        curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip);
-       MSG_DEBUG("profile http local: ip %s", ip);
+       MSG_SEC_INFO("profile http local: ip %s", ip);
 
        curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
-       MSG_DEBUG("profile http local: port %ld", port);
+       MSG_SEC_INFO("profile http local: port %ld", port);
 
        MSG_DEBUG("**************************************************************************************************");
 }
@@ -135,7 +130,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
        bool nResult = __httpGetHeaderField(MMS_HH_CONTENT_TYPE, szBuffer);
        if (nResult) {
                snprintf(pcheader, HTTP_REQUEST_LEN, "Content-Type: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 
@@ -145,7 +140,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
                snprintf(szBuffer, 1024, "%d", ulContentLen);
                if (nResult) {
                        snprintf(pcheader, HTTP_REQUEST_LEN, "Content-Length: %s", szBuffer);
-                       MSG_DEBUG("%s", pcheader);
+                       MSG_INFO("%s", pcheader);
                        *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
                }
        }
@@ -156,7 +151,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
        __httpGetHost(szUrl, szBuffer, 1024);
        if (strlen(szBuffer)){
                snprintf(pcheader, HTTP_REQUEST_LEN, "Host: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 
@@ -165,7 +160,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
        nResult = __httpGetHeaderField(MMS_HH_ACCEPT, szBuffer);
        if (nResult) {
                snprintf(pcheader, HTTP_REQUEST_LEN, "Accept: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 
@@ -174,7 +169,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
        nResult = __httpGetHeaderField(MMS_HH_ACCEPT_CHARSET, szBuffer);
        if (nResult) {
                snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Charset: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 
@@ -183,7 +178,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
        nResult = __httpGetHeaderField(MMS_HH_ACCEPT_LANGUAGE, szBuffer);
        if (nResult) {
                snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Language: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 /* NOW not support gzip, deflate encoding in MMS Plugin
@@ -201,16 +196,16 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
        nResult = __httpGetHeaderField(MMS_HH_USER_AGENT, szBuffer);
        if (nResult) {
                snprintf(pcheader, HTTP_REQUEST_LEN, "User-Agent: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 
        memset(szBuffer, 0, 1025);
        memset(pcheader, 0, HTTP_REQUEST_LEN);
-       nResult = __httpGetHeaderField(MMS_HH_WAP_PROFILE, szBuffer);
+       nResult = __httpGetHeaderField(MMS_HH_UA_PROFILE, szBuffer);
        if (nResult) {
                snprintf(pcheader, HTTP_REQUEST_LEN, "X-wap-profile: %s", szBuffer);
-               MSG_DEBUG("%s", pcheader);
+               MSG_INFO("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
 
@@ -253,29 +248,38 @@ static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *s
                case MMS_HH_USER_AGENT:
                        {
                                char szUserAgent[1024 + 1];
-
-                               memset(szUserAgent, 0x00, sizeof(szUserAgent));
-                               snprintf(szUserAgent, 1024, "%s", MSG_MMS_HH_USER_AGENT);
+                               char *uagent = NULL;
+
+                               uagent = MsgSettingGetString(VCONFKEY_BROWSER_USER_AGENT);
+                               if (uagent) {
+                                       MSG_SEC_INFO("Get UserAgent : %s = %s", VCONFKEY_BROWSER_USER_AGENT, uagent);
+                                       memset(szUserAgent, 0x00, sizeof(szUserAgent));
+                                       MmsRemoveMarkup(uagent, szUserAgent, sizeof(szUserAgent));
+                                       free(uagent);
+                                       uagent = NULL;
+                               } else {
+                                       memset(szUserAgent, 0x00, sizeof(szUserAgent));
+                                       MSG_SEC_INFO("Get Default UserAgent : %s", MSG_MMS_HH_USER_AGENT);
+                                       snprintf(szUserAgent, 1024, "%s", MSG_MMS_HH_USER_AGENT);
+                               }
 
                                snprintf((char *)szHeaderBuffer, 1024, "%s", szUserAgent);
                                result = true;
                        }
                        break;
 
-               case MMS_HH_WAP_PROFILE:
+               case MMS_HH_UA_PROFILE:
                        {
-                               char szUAProfile[1024 + 1] = {0,};
-
-                               memset(szUAProfile, 0x00, (sizeof(char)*(1024+1) ));
-                               snprintf(szUAProfile, 1024, "%s", MSG_MMS_WAP_PROFILE);
+                               char *szUAProfile = MsgSettingGetString(MSG_MMS_UA_PROFILE);
 
                                snprintf((char *)szHeaderBuffer, 1024, "%s", szUAProfile);
+                               free(szUAProfile);
                                result = true;
                        }
                        break;
 
                default:
-                       MSG_DEBUG("invalid param");
+                       MSG_WARN("invalid param [%d]", httpHeaderItem);
                        break;
                }
        }
@@ -337,7 +341,7 @@ static int __http_multi_perform(void *session)
 
        int still_running;
        int ret = 0;
-       bool abort_flag = false;
+       bool connection_open_flag = false;
 
        CURLMsg *msg;
        int msgs_left;
@@ -345,14 +349,14 @@ static int __http_multi_perform(void *session)
        multi_handle = curl_multi_init();
 
        if (curl_multi_add_handle(multi_handle, session) != 0) {
-               MSG_DEBUG("curl_multi_add_handle is failed");
+               MSG_ERR("curl_multi_add_handle is failed");
                curl_multi_cleanup(multi_handle);
                return -1;
        }
 
        /* we start some action by calling perform right away */
        rcm = curl_multi_perform(multi_handle, &still_running);
-       MSG_DEBUG("curl_multi_perform first end : rcm = %d, still_running = %d", rcm, still_running);
+       MSG_INFO("curl_multi_perform first end : rcm = %d, still_running = %d", rcm, still_running);
 
        do {
                struct timeval timeout;
@@ -363,25 +367,25 @@ static int __http_multi_perform(void *session)
                fd_set fdexcep;
                int maxfd = -1;
 
-               long curl_timeo = -1;
+//             long curl_timeo = -1;
 
                FD_ZERO(&fdread);
                FD_ZERO(&fdwrite);
                FD_ZERO(&fdexcep);
 
                /* set a suitable timeout to play around with */
-               timeout.tv_sec = 10;
+               timeout.tv_sec = 120;
                timeout.tv_usec = 0;
 
-               curl_multi_timeout(multi_handle, &curl_timeo);
-               if(curl_timeo >= 0) {
-                       MSG_DEBUG("curl_timeo = %ld", curl_timeo);
-                       timeout.tv_sec = curl_timeo / 1000;
-                       if(timeout.tv_sec > 1)
-                               timeout.tv_sec = 1;
-                       else
-                               timeout.tv_usec = (curl_timeo % 1000) * 1000;
-               }
+//             curl_multi_timeout(multi_handle, &curl_timeo);
+//             if(curl_timeo >= 0) {
+//                     MSG_DEBUG("curl_timeo = %ld", curl_timeo);
+//                     timeout.tv_sec = curl_timeo / 1000;
+//                     if(timeout.tv_sec > 1)
+//                             timeout.tv_sec = 1;
+//                     else
+//                             timeout.tv_usec = (curl_timeo % 1000) * 1000;
+//             }
 
                curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
 
@@ -393,35 +397,41 @@ static int __http_multi_perform(void *session)
 
                rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
 
-               switch(rc) {
-                       case -1:
-                               /* select error */
-                               MSG_DEBUG("select error");
+               if (rc == -1){/* select error */
+                       MSG_ERR("select error");
+                       ret = -1;
                        break;
-                       case 0: /* timeout */
-                       default: /* action */
-                               rcm = curl_multi_perform(multi_handle, &still_running);
+               } else if (rc == 0){    /* timeout */
+                       MSG_ERR("time out");
+                       ret = -1;
                        break;
+               } else {/* action */
+                       MSG_DEBUG("rc = %d", rc);
+                       rcm = curl_multi_perform(multi_handle, &still_running);
                }
 
-               abort_flag = MmsPluginHttpAgent::instance()->getAbortFlag();
-               if (abort_flag == true) {
-                       MSG_DEBUG("abort flag is Set");
+               connection_open_flag = MmsPluginCmAgent::instance()->getCmStatus();
+               if (connection_open_flag == false) {
+                       MSG_DEBUG("Connection Closed");
                        ret = -1;
                }
 
-               MSG_DEBUG("curl_multi_perform end : rcm = %d, still_running = %d, abort_flag = %d", rcm, still_running, abort_flag);
+               MSG_INFO("curl_multi_perform end : rcm = %d, still_running = %d, cm_open = %d", rcm, still_running, connection_open_flag);
 
-       } while(still_running && (abort_flag == false));
+       } while(still_running && (connection_open_flag == true));
 
        while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
                if (msg->msg == CURLMSG_DONE) {
 
                        if (msg->easy_handle == session) {
-                               MSG_DEBUG("HTTP transfer completed with status %d", msg->data.result);
+                               MSG_INFO("HTTP transfer completed with status %d", msg->data.result);
+                               if (msg->data.result != 0) {
+                                       ret = msg->data.result;
+                               }
+
                                curl_multi_remove_handle(multi_handle, session);
                        } else {
-                               MSG_DEBUG("Unknown handle HTTP transfer completed with status %d", msg->data.result);
+                               MSG_WARN("Unknown handle HTTP transfer completed with status %d", msg->data.result);
                        }
                }
        }
@@ -543,6 +553,7 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_inf
                        && request_info.transaction_type != MMS_HTTP_TRANSACTION_TYPE_POST)
        {
                MSG_ERR("transaction_type of request_info is Invaild [%d]", request_info.transaction_type);
+               http_error = MMS_HTTP_ERROR_TRANSACTION_TYPE;
                goto __CATCH;
        }
 
@@ -550,12 +561,14 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_inf
 
                if (request_info.post_data == NULL || request_info.post_data_len == 0) {
                        MSG_ERR("post data info is Invaild");
+                       http_error = MMS_HTTP_ERROR_SESSION;
                        goto __CATCH;
                }
        }
 
        if (request_info.url == NULL || request_info.proxy == NULL || request_info.interface == NULL) {
                MSG_ERR("request_info parameter invalid url [%s], proxy [%s] interface [%s]", request_info.url, request_info.proxy, request_info.interface);
+               http_error = MMS_HTTP_ERROR_SESSION;
                goto __CATCH;
        }
 
@@ -570,12 +583,13 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_inf
                content_len = 0;
        }
 
-       url = strdup(request_info.url);
+       url = g_strdup(request_info.url);
 
        if (url) {
                __httpAllocHeaderInfo((curl_slist**)&session_header, url, content_len);
                if (session_header == NULL) {
-                       MSG_ERR("Failed to __httpAllocHeaderInfo");
+                       MSG_ERR("Failed to httpAllocHeaderInfo");
+                       http_error = MMS_HTTP_ERROR_SESSION;
                        goto __CATCH;
                }
 
@@ -590,7 +604,8 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_inf
        //Set curl option
        session_option = curl_easy_init();
        if (session_option == NULL) {
-               MSG_DEBUG("curl_easy_init() failed");
+               MSG_ERR("curl_easy_init() failed");
+               http_error = MMS_HTTP_ERROR_SESSION;
                goto __CATCH;
        }
 
@@ -619,7 +634,11 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_inf
        return http_error;
 
 __CATCH:
-
+       //CID 338211: freeing url (with check) in case of error
+       if(url) {
+               free(url);
+               url = NULL;
+       }
        clearSession();
 
        MSG_END();
@@ -636,7 +655,7 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::startTransaction()
        __http_print_profile(session_option);
 
        if (rc != 0) {
-               MSG_DEBUG("curl_easy_perform return error rc [%d]", rc);
+               MSG_ERR("curl_easy_perform return error rc [%d]", rc);
                http_error = MMS_HTTP_ERROR_TRANSACTION;
        }
 
@@ -659,14 +678,14 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::httpRequest(http_request_info_s &request_in
        //set session
        http_error = this->setSession(request_info);
        if (http_error != MMS_HTTP_ERROR_NONE) {
-               MSG_DEBUG("Fail to setSession");
+               MSG_ERR("Fail to setSession");
                goto __CATCH;
        }
 
        //transaction
        http_error = this->startTransaction();
        if (http_error != MMS_HTTP_ERROR_NONE) {
-               MSG_DEBUG("Fail to startTransaction");
+               MSG_ERR("Fail to startTransaction");
                goto __CATCH;
        }
 
@@ -677,7 +696,7 @@ MMS_HTTP_ERROR_E MmsPluginHttpAgent::httpRequest(http_request_info_s &request_in
                respfile = NULL;
 
                if (g_file_get_contents(conf_filename, &request_info.response_data, &request_info.response_data_len, NULL) == false) {
-                       MSG_DEBUG("Fail to g_file_get_contents");
+                       MSG_WARN("Fail to g_file_get_contents");
                }
        }
 
index cb1c262..c81a571 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdlib.h>
 #include "MsgMmsMessage.h"
 #include "MsgGconfWrapper.h"
 #include "MsgStorageHandler.h"
+#include "MsgSerialize.h"
+#include "MsgSpamFilter.h"
 #include "MmsPluginDebug.h"
 #include "MmsPluginTypes.h"
 #include "MmsPluginCodec.h"
 #include "MmsPluginInternal.h"
 #include "MmsPluginStorage.h"
-#include "MmsPluginSmil.h"
+#include "MmsPluginAppBase.h"
+#include "MmsPluginMIME.h"
+
 /*==================================================================================================
                                      IMPLEMENTATION OF MmsPluginInternal - Member Functions
 ==================================================================================================*/
@@ -67,19 +71,19 @@ void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQ
                if(MsgCreateFileName(fileName) == false)
                        THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
 
-               MSG_DEBUG("File name = %s", fileName);
+               MSG_SEC_DEBUG("File name = %s", fileName);
 
                if(MsgWriteIpcFile(fileName, pMsgInfo->msgText, pMsgInfo->dataSize) == false)
                        THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
 
-               snprintf(fullPath, MAX_FULL_PATH_SIZE+1, MSG_IPC_DATA_PATH"%s", fileName);
+               snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, fileName);
 
                memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
                memcpy(pMsgInfo->msgData, fullPath, strlen(fullPath));
                pMsgInfo->bTextSms = false;
        }
 
-       MSG_DEBUG("MMS File Path = %s", pMsgInfo->msgData);
+       MSG_SEC_DEBUG("MMS File Path = %s", pMsgInfo->msgData);
 
        MmsInitHeader();
        MmsRegisterDecodeBuffer();
@@ -91,7 +95,9 @@ void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQ
                if (!MmsBinaryDecodeMsgHeader(pFile, pMsgInfo->dataSize))
                        MSG_DEBUG("Decoding Header Failed \r\n");
 
-               MsgDeleteFile(pMsgInfo->msgData + strlen(MSG_IPC_DATA_PATH));
+               MsgCloseFile(pFile);
+
+               remove(pMsgInfo->msgData);
 
                switch (mmsHeader.type) {
                case MMS_MSGTYPE_NOTIFICATION_IND:
@@ -116,8 +122,6 @@ void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQ
                default:
                        break;
                }
-
-               MsgCloseFile(pFile);
        }
 
        MSG_END();
@@ -126,12 +130,12 @@ void MmsPluginInternal::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQ
 bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest)
 {
        MSG_DEBUG("MmsProcessNotiInd");
-       msg_error_t     err = MSG_SUCCESS;
 
        MSG_MMS_HOME_RETRIEVE_TYPE_T retrieveType;
        bool bReportAllowed;
 
        MmsAttrib attrib;
+       MsgDbHandler *dbHandle = getDbHandle();
 
        MmsInitMsgAttrib(&attrib);
 
@@ -147,32 +151,129 @@ bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST
 
        attrib.expiryTime = mmsHeader.expiryTime;
 
-       MmsPluginStorage *pStorage = MmsPluginStorage::instance();
-       err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
-
        if (mmsHeader.pFrom) {
                MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
                // From
                strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
+               if (MmsAddrUtilCheckEmailAddress(pMsgInfo->addressList[0].addressVal)) {
+                       pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_EMAIL;
+               }
+       }
+
+       MMS_DATA_S *mms_data = MsgMmsCreate();
+       {
+               mms_data->header = MsgMmsCreateHeader();
+
+               MMS_HEADER_DATA_S *pHeader = mms_data->header;
+
+               pHeader->messageType = mmsHeader.type;
+
+               snprintf(pHeader->trID, sizeof(pHeader->trID), "%s", mmsHeader.szTrID);
+
+               pHeader->mmsVersion = mmsHeader.version;
+
+               //From
+               if (mmsHeader.pFrom) {
+                       MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
+                       snprintf(pHeader->szFrom, sizeof(pHeader->szFrom), "%s", mmsHeader.pFrom->szAddr);
+               }
+
+               //Subject
+               snprintf(pHeader->szSubject, sizeof(pHeader->szSubject), "%s", mmsHeader.szSubject);
+               //Delivery Report
+               pHeader->bDeliveryReport = mmsHeader.deliveryReport;
+               //Message Class
+               pHeader->messageClass = mmsHeader.msgClass;
+
+               //Priority
+               pHeader->mmsPriority = mmsHeader.priority;
+
+               //Message Size : pMmsMsg->mmsAttrib.msgSize = mmsHeader.msgSize;
+               //Expiry
+               pHeader->expiry.type = mmsHeader.expiryTime.type;
+               pHeader->expiry.time = mmsHeader.expiryTime.time;
+
+               time_t curTime = time(NULL);
+
+               if (pHeader->expiry.type == MMS_TIMETYPE_RELATIVE) {
+                       pHeader->expiry.type = MMS_TIMETYPE_ABSOLUTE;
+                       pHeader->expiry.time += curTime;
+               }
+
+               //Charge
+               //contentclass
+               //int contentClass;//text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich
+               strncpy(pHeader->contentLocation, mmsHeader.szContentLocation, MMS_LOCATION_LEN);
+
+               pHeader->messageSize = mmsHeader.msgSize;
+
+               MSG_DEBUG("Message size = [%d]", pHeader->messageSize);
+
+               char *pSerializedMms = NULL;
+               int serializeDataSize = 0;
+
+               char pTempFileName[MSG_FILENAME_LEN_MAX+1] = {0};
+               char pTempFilePath[MSG_FILEPATH_LEN_MAX+1] = {0};
+
+               serializeDataSize = MsgSerializeMms(mms_data, &pSerializedMms);
+
+               if (pSerializedMms) {
+                       if (MsgCreateFileName(pTempFileName) == true) {
+                               pMsgInfo->bTextSms = false;
+
+                               snprintf(pTempFilePath, sizeof(pTempFilePath), MSG_IPC_DATA_PATH"%s", pTempFileName);
+
+                               MsgOpenCreateAndOverwriteFile(pTempFilePath, pSerializedMms, serializeDataSize);
+
+                               //set file name
+                               snprintf(pMsgInfo->msgData, sizeof(pMsgInfo->msgData), "%s", pTempFileName);
+                       }
+
+                       free(pSerializedMms);
+               }
+       }
+       MsgMmsRelease(&mms_data);
+
+       // Check contents-location is in noti.ind
+       if (mmsHeader.szContentLocation[0] == '\0') {
+               THROW(MsgException::INCOMING_MSG_ERROR, "######## Contents-location is empty in MMS-Noti-Ind  #######");
+               return false;
        }
 
        int roamState = 0;
+       char pPduFilePath[MAX_FULL_PATH_SIZE] = {0};
 
        roamState = MsgSettingGetInt(VCONFKEY_TELEPHONY_SVC_ROAM);
        MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed);
 
-       if (checkRejectNotiInd(roamState, bReportAllowed, pMsgInfo->msgData)) {
+       if (checkRejectNotiInd(roamState, bReportAllowed, pPduFilePath)) {
                MSG_DEBUG("MMS Message Rejected......");
 
-               pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
-               pMsgInfo->bTextSms = true;
+               pMsgInfo->dataSize = strlen(pPduFilePath);
                memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
-
+               snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
                pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
 
                return false;
        }
 
+       if (MsgCheckFilter(dbHandle, pMsgInfo)){
+               encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
+
+               pMsgInfo->dataSize = strlen(pPduFilePath);
+
+               pRequest->msgInfo.bTextSms = false;
+
+               memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+
+               snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
+               MSG_DEBUG("pRequest->msgInfo.msgData = %s", pRequest->msgInfo.msgData);
+               pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
+               pRequest->msgInfo.folderId = MSG_SPAMBOX_ID;
+
+               return true;
+       }
+
        if (roamState == VCONFKEY_TELEPHONY_SVC_ROAM_OFF) {
                retrieveType = (MSG_MMS_HOME_RETRIEVE_TYPE_T)MsgSettingGetInt(MMS_RECV_HOME_NETWORK);
                MSG_DEBUG("$$$$$$$$$$ MMS_RECV_HOME_NETWORK = %d $$$$$$$$$$$$$", retrieveType);
@@ -183,14 +284,16 @@ bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST
                if (retrieveType == MSG_ABROAD_RESTRICTED) {
                        MSG_DEBUG("MMS Receiving Setting Restricted was selected.");
                        // m-notify-resp-ind encoding process
-                       memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
+                       encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
+
+                       pMsgInfo->dataSize = strlen(pPduFilePath);
 
-                       encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pMsgInfo->msgData);
+                       pRequest->msgInfo.bTextSms = false;
 
-                       pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
-                       pMsgInfo->bTextSms = true;
                        memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
 
+                       snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
+
                        pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
 
                        return true;
@@ -199,34 +302,57 @@ bool MmsPluginInternal::processNotiInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST
 
        // should send http 'GET'
        if (retrieveType == MSG_HOME_AUTO_DOWNLOAD || retrieveType == MSG_ABROAD_AUTO_DOWNLOAD) {
-               MSG_DEBUG("=========== START AUTO RETRIEVE MODE ============");
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
+               //Check if current request sim index is different from default network SIM
+               //Convert auto-retrieve to manual retrieve in case sim indexes are different
+               int default_sim = 0;
+               default_sim = MsgSettingGetInt(MSG_NETWORK_SIM);
 
-               memcpy(pMsgInfo->msgData, mmsHeader.szContentLocation, strlen(mmsHeader.szContentLocation)) ;
+               MSG_DEBUG("default_sim = %d, pMsgInfo->sim_idx = %d", default_sim, pMsgInfo->sim_idx);
 
-               pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
+               if (default_sim == (int)pMsgInfo->sim_idx) {
+                       MSG_DEBUG("=========== START AUTO RETRIEVE MODE ============");
 
-               pMsgInfo->bTextSms = true;
+                       pMsgInfo->dataSize = strlen(mmsHeader.szContentLocation);
 
-               memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+                       pRequest->msgInfo.bTextSms = true;
+
+                       memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+
+                       snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", mmsHeader.szContentLocation);
+
+                       pRequest->msgInfo.msgType.subType = MSG_GET_MMS;
 
-               pRequest->msgInfo.msgType.subType = MSG_GET_MMS;
+                       MSG_DEBUG("MSG SUBTYPE = %d msg data %s bTextsms %d", pRequest->msgInfo.msgType.subType, pRequest->msgInfo.msgData, pRequest->msgInfo.bTextSms);
+               } else {
+                       encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
 
-               MSG_DEBUG("MSG SUBTYPE = %d msg data %s bTextsms %d", pRequest->msgInfo.msgType.subType, pRequest->msgInfo.msgData, pRequest->msgInfo.bTextSms);
+                       pMsgInfo->dataSize = strlen(pPduFilePath);
+
+                       pRequest->msgInfo.bTextSms = false;
+
+                       memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+
+                       snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
+                       MSG_DEBUG("pRequest->msgInfo.msgData = %s", pRequest->msgInfo.msgData);
+                       pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
+               }
        } else {
-       // should send m-notify-resp-ind
+               // should send m-notify-resp-ind
                MSG_DEBUG("=========== START MANUAL RETRIEVE MODE ===========");
                // m-notify-resp-ind encoding process
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
 
                if (retrieveType == MSG_HOME_MANUAL || retrieveType == MSG_ABROAD_MANUAL) {
-                       encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pMsgInfo->msgData);
+                       encodeNotifyRespInd(mmsHeader.szTrID, MSG_DELIVERY_REPORT_DEFERRED, bReportAllowed, pPduFilePath);
                }
 
-               pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
-               pMsgInfo->bTextSms = true;
+               pMsgInfo->dataSize = strlen(pPduFilePath);
+
+               pRequest->msgInfo.bTextSms = false;
+
                memcpy(&pRequest->msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
 
+               snprintf(pRequest->msgInfo.msgData, sizeof(pRequest->msgInfo.msgData), "%s", pPduFilePath);
+               MSG_DEBUG("pRequest->msgInfo.msgData = %s", pRequest->msgInfo.msgData);
                pRequest->msgInfo.msgType.subType = MSG_NOTIFYRESPIND_MMS;
        }
 
@@ -361,6 +487,11 @@ void MmsPluginInternal::processSendConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEn
                                                                                                        , addressinfo.addressVal
                                                                                                        , (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS)?"Success":"Fail");
 
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
+
        // set message-id from mmsc
        strncpy(recvData.szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
        strncpy(recvData.szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
@@ -373,30 +504,20 @@ void MmsPluginInternal::processSendConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEn
 
        pMsgInfo->displayTime = curTime;
 
-
-       MmsInitHeader();
-#if 0 // Not Need Release
        MmsMsg *pMsg = NULL;
        MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-#ifdef __SUPPORT_DRM__
+       MmsInitHeader();
        MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
-#endif
        MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
-#endif
 
        MSG_END();
 }
 
-
+#if 1
 void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest, char *pRetrievedFilePath)
 {
        MSG_BEGIN();
 
-       int partCnt = 0;
-       int attachCount = 0;
-       MsgType partHeader;
-       bool bMultipartRelated = false;
-
        msg_error_t err = MSG_SUCCESS;
        MMS_RECV_DATA_S recvData = {{0}, };
 
@@ -449,12 +570,27 @@ void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTra
                                                                                                                , (mmsHeader.pFrom)?mmsHeader.pFrom->szAddr:"YOU"
                                                                                                                , (msisdn == NULL)?"ME":msisdn
                                                                                                                , (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS)?"Success":"Fail");
+       /* PLM P141008-05143 :  Notification.Ind address is 1, but MMS retreived Conf address is correct.
+        So adding correct address to addressList buf to compare address in DB while MsgStoUpdateMMSMessage */
+       if (mmsHeader.pFrom) {
+               pMsgInfo->nAddressCnt = 1;
+               strncpy(pMsgInfo->addressList[0].addressVal, mmsHeader.pFrom->szAddr, MAX_ADDRESS_VAL_LEN);
+       }
+
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
+
        pMsgInfo->dataSize = pRequest->getDataLen;
 
        // set message-id & MMS TPDU file path
-       strcpy(recvData.szMsgID, mmsHeader.szMsgID);
+       snprintf(recvData.szMsgID, sizeof(recvData.szMsgID), "%s", mmsHeader.szMsgID);
+
        if (pRetrievedFilePath)
-               strncpy(recvData.retrievedFilePath, pRetrievedFilePath, sizeof(recvData.retrievedFilePath));
+               strncpy(recvData.retrievedFilePath, pRetrievedFilePath, sizeof(recvData.retrievedFilePath)-1);
+
+       char *filename = NULL;
 
 #ifdef FEATURE_JAVA_MMS
        if (mmsHeader.msgType.param.szApplicationID || mmsHeader.msgType.param.szReplyToApplicationID) {
@@ -466,21 +602,20 @@ void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTra
 
                char fullPath[MAX_FULL_PATH_SIZE+1] = {0, };
 
-               char *filename = NULL;
-               filename = strrchr(pRetrievedFilePath, '/');
+               filename = MsgGetFileName(pRetrievedFilePath);
 
-               snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, filename + 1);
+               snprintf(fullPath, MAX_FULL_PATH_SIZE+1, "%s%s", MSG_IPC_DATA_PATH, filename);
 
                int ret  = rename(pRetrievedFilePath, fullPath);
                if (ret != 0) {
                        MSG_DEBUG("File rename Error: %s", strerror(errno));
                }
 
-               if (chmod(fullPath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) != 0) {
+               if (MsgChmod(fullPath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == false) {
                        MSG_DEBUG("File Write Error: %s", strerror(errno));
                }
 
-               if (chown(fullPath, 0, 6502 ) != 0) {
+               if (MsgChown(fullPath, 0, 6502 ) == false) {
                        MSG_DEBUG("File Write Error: %s", strerror(errno));
                }
        }
@@ -494,97 +629,170 @@ void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTra
 
        MmsPluginStorage *pStorage = MmsPluginStorage::instance();
 
-       MMS_MESSAGE_DATA_S msgData;
-       memset(&msgData, 0, sizeof(MMS_MESSAGE_DATA_S));
+       err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
+
+       MSG_DEBUG("Error value of updateMmsAttrib [%d]", err);
+
+       {//make MmsData & insert multipart
+       MmsMsg *pMmsMsg = NULL;
+       MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
+
+       MMS_DATA_S *pMmsData = MsgMmsCreate();
+       pMmsData->header = MsgMmsCreateHeader();
+
+       MmsConvertMmsData(pMmsMsg, pMmsData);
+       //CID 41996 : MmsConvertMmsData always returns true
+       /*if (MmsConvertMmsData(pMmsMsg, pMmsData) != true) {
+               MSG_DEBUG("Fail to Compose MMS Message");
+               goto __CATCH;
+       }*/
+
+       bool bFiltered = checkFilterMmsBody(pMmsData);
+       if (bFiltered == true) {
+               pMsgInfo->folderId = MSG_SPAMBOX_ID;
+       }
+
+       MMS_MULTIPART_DATA_S *pSmilMultipart = pMmsData->smil;
+       if (pSmilMultipart) {
+               MmsPluginStorage::instance()->insertMultipart(pMsgInfo->msgId, pSmilMultipart);
+       }
+
+       MMSList *multipart_list = pMmsData->multipartlist;
+
+       for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+               MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+               MmsPluginStorage::instance()->insertMultipart(pMsgInfo->msgId, pMultipart);
+       }
+
+       {//make Preview info for APP
+               MmsPluginAppBase appBase(pMmsData);
+               appBase.makePreviewInfo(pMsgInfo->msgId, false, pRetrievedFilePath);
+               appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
+       }
+
+       MsgMmsRelease(&pMmsData);
+
+       if (MsgGetFileSize(pRetrievedFilePath, (int *)&pMsgInfo->dataSize) == false) {
+               MSG_SEC_DEBUG("Fail to get mms file size [%s]", pRetrievedFilePath);
+               goto __CATCH;
+       }
+       }//make MmsData & insert multipart
 
-       // Conversation is supported only Multipart Related message, Presentation info should be provided
-       if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
-               char *pSmilDoc = NULL;
+__CATCH:
+       {
                MmsMsg *pMsg = NULL;
-               char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
+               pStorage->getMmsMessage(&pMsg);
+               MmsInitHeader();
+               MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
+               MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
+               g_free(filename); filename = NULL;
+       }
+       MSG_END();
+}
+#else //NEW process RetrieveConf
+void MmsPluginInternal::processRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, mmsTranQEntity *pRequest, char *pRetrievedFilePath)
+{
+       MSG_BEGIN();
 
-               msgData.regionCnt = 0;
-               msgData.pageCnt = 0;
-               msgData.attachCnt = 0;
-               msgData.transitionCnt = 0;
-               msgData.metaCnt = 0;
-               memset(msgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
+       msg_error_t err = MSG_SUCCESS;
 
-               pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
-               MmsSmilParseSmilDoc(&msgData, pSmilDoc);
-               MmsRemovePims(&msgData);
+       pMsgInfo->msgId = pRequest->msgId;
 
-               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-               strcpy(szFileName, pMsg->szFileName);
+       pMsgInfo->msgType.mainType = MSG_MMS_TYPE;
+       if (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)
+               pMsgInfo->msgType.subType = MSG_RETRIEVE_AUTOCONF_MMS;
+       else
+               pMsgInfo->msgType.subType = MSG_RETRIEVE_MANUALCONF_MMS;
+
+       strncpy(pMsgInfo->subject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
+       strncpy(pRequest->transactionId, mmsHeader.szTrID, MMS_TR_ID_LEN);
+
+       time_t curTime;
+       curTime = time(NULL);
+
+       pMsgInfo->displayTime = curTime;
 
-               err = pStorage->getMsgText(&msgData, pMsgInfo->msgText);
-               bMultipartRelated = true;
+       if (mmsHeader.retrieveStatus == MMS_RETRSTATUS_OK) {
+               pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
+               pMsgInfo->folderId = MSG_INBOX_ID;
        } else {
-               MSG_DEBUG("Multipart mixed message doesn't support mms conversation");
+               pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
+               pMsgInfo->folderId = MSG_INBOX_ID;
+               // If failed MMS Retrieve, then saved as MMS Noti Ind Message.
+               // It will changed in MsgHandleMmsConfIncomingMsg
+               //pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
        }
 
-       err = pStorage->updateMmsAttrib(pMsgInfo->msgId, &attrib, pMsgInfo->msgType.subType);
+       char *msisdn = NULL;
+       msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
 
-       partCnt = MmsGetMediaPartCount(pMsgInfo->msgId);
-       MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt );
+       if (mmsHeader.pFrom)
+               MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr);
 
-       if (partCnt < 0) {
-               MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt );
-       } else {
-               for (int i = 0; i < partCnt; ++i) {
-                       if (!MmsGetMediaPartHeader(i, &partHeader)) {
-                               MSG_DEBUG("MmsUiGetMediaAttachInfo: MmsGetMediaPartHeader failed\n" );
-                               break;
-                       }
+       MSG_MMS_VLD_INFO("%d, MMS Receive %s End %s->%s %s", pMsgInfo->msgId
+                                                                                                               , (pRequest->eMmsPduType == eMMS_RETRIEVE_AUTO_CONF)?"Auto":"Manual"
+                                                                                                               , (mmsHeader.pFrom)?mmsHeader.pFrom->szAddr:"YOU"
+                                                                                                               , (msisdn == NULL)?"ME":msisdn
+                                                                                                               , (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS)?"Success":"Fail");
 
-                       if (partHeader.contentSize > 0) {
-                               char szBuf[MSG_FILEPATH_LEN_MAX + 1];
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
+
+       pMsgInfo->dataSize = pRequest->getDataLen;
 
-                               strcpy((char *)szBuf, partHeader.param.szFileName);
-                               sprintf(partHeader.param.szFileName, MSG_DATA_PATH"%s", szBuf);
-                               if (!bMultipartRelated || MmsCheckAdditionalMedia(&msgData, &partHeader)) {
-                                       MMS_ATTACH_S *attachment = NULL;
-                                       int tempType;
 
-                                       attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
+       {
+               MmsMsg *pMmsMsg = NULL;
+               MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
 
-                                       MsgGetTypeByFileName(&tempType, partHeader.param.szFileName);
-                                       attachment->mediatype = (MimeType)tempType;
+               MMS_DATA_S *pMmsData = MsgMmsCreate();
+               pMmsData->header = MsgMmsCreateHeader();
 
-                                       strcpy(attachment->szFilePath, partHeader.param.szFileName);
+               if (MmsConvertMmsData(pMmsMsg, pMmsData) != true) {
+                       MSG_DEBUG("Fail to Compose MMS Message");
+                       goto __CATCH;
+               }
 
-                                       strncpy(attachment->szFileName, partHeader.param.szName, MSG_FILENAME_LEN_MAX - 1);
+               char *pSerializedData = NULL;
 
-                                       attachment->fileSize = partHeader.contentSize;
+               MsgSerializeMms(pMmsData, &pSerializedData);
 
-                                       _MsgMmsAddAttachment(&msgData, attachment);
-                                       attachCount++;
+               MsgMmsRelease(&pMmsData);
 
-                               }
 
-                       }
+               char fileName[MSG_FILENAME_LEN_MAX] = {0};
+               char fileFilePath[MSG_FILEPATH_LEN_MAX] = {0};
+
+               if (MsgCreateFileName(fileName) == false)
+                       goto __CATCH;
+
+               snprintf(fileFilePath, sizeof(fileFilePath), "%s%s", MSG_DATA_PATH, fileName);
+
+               if (!MsgOpenCreateAndOverwriteFile(fileFilePath, (char *)pSerializedData, (int)strlen(pSerializedData))) {
+                       goto __CATCH;
                }
-       }
 
-       MmsMakePreviewInfo(pMsgInfo->msgId, &msgData);
-       MSG_DEBUG("attachCount [%d]", attachCount);
-       err = pStorage->updateMmsAttachCount(pMsgInfo->msgId, attachCount);
+               snprintf(pMsgInfo->msgData, sizeof(pMsgInfo->msgData), "%s", fileFilePath);
 
-       if (bMultipartRelated) {
-               MsgMmsReleaseMmsLists(&msgData);
+               if (MsgGetFileSize(pRetrievedFilePath, (int *)&pMsgInfo->dataSize) == false) {
+                       MSG_SEC_DEBUG("Fail to get mms file size [%s]", pRetrievedFilePath);
+                       goto __CATCH;
+               }
        }
 
-       MmsMsg *pMsg = NULL;
-       pStorage->getMmsMessage(&pMsg);
-       MmsInitHeader();
-#ifdef __SUPPORT_DRM__
-       MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
-#endif
-       MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
-
+__CATCH:
+       {
+               MmsMsg *pMsg = NULL;
+               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
+               MmsInitHeader();
+               MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
+               MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
+       }
        MSG_END();
 }
-
+#endif
 void MmsPluginInternal::processForwardConf(MSG_MESSAGE_INFO_S *msgInfo, mmsTranQEntity *pRequest)
 {
 
@@ -608,7 +816,7 @@ bool MmsPluginInternal::encodeNotifyRespInd(char *szTrID, msg_delivery_report_st
        if (MsgCreateFileName(pTempFileName) == false)
                return false;
 
-       snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"%s.noti.ind", pTempFileName);
+       snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, "%s%s.noti.ind", MSG_DATA_PATH, pTempFileName);
 
        pFile = MsgOpenMMSFile(pTempFilePath);
 
@@ -626,7 +834,8 @@ bool MmsPluginInternal::encodeNotifyRespInd(char *szTrID, msg_delivery_report_st
        MsgCloseFile(pFile);
 
        if (pSendFilePath) {
-               snprintf(pSendFilePath, MAX_MSG_DATA_LEN+1, "%s.mms", pTempFilePath);
+               //CID 41993: replaced size 'MAX_MSG_DATA_LEN+1' with MAX_FULL_PATH_SIZE
+               snprintf(pSendFilePath, MAX_FULL_PATH_SIZE, "%s.mms", pTempFilePath);
        } else {
                MSG_DEBUG("[ERROR] pSendFilePath is NULL");
                return false;
@@ -653,7 +862,7 @@ bool MmsPluginInternal::encodeAckInd(char *szTrID, bool bReportAllowed, char *pS
        if (MsgCreateFileName(pTempFileName) == false)
                return false;
 
-       snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"%s.ack.ind", pTempFileName);
+       snprintf(pTempFilePath, MAX_FULL_PATH_SIZE, "%s%s.ack.ind", MSG_DATA_PATH, pTempFileName);
 
        pFile = MsgOpenMMSFile(pTempFilePath);
        if (!pFile) {
@@ -733,6 +942,70 @@ bool MmsPluginInternal::checkRejectNotiInd(int roamState, bool bReportAllowed, c
 
 }
 
+
+bool MmsPluginInternal::checkFilterMmsBody(MMS_DATA_S *pMmsData)
+{
+
+       if (pMmsData == NULL)
+               return false;
+
+       bool bFiltered = false;
+       MMS_MESSAGE_DATA_S mmsMsg;
+       MMS_PAGE_S *pPage = NULL;
+       MMS_MEDIA_S *pMedia = NULL;
+       char filePath[MSG_FILEPATH_LEN_MAX + 1];
+       gchar *fileContent = NULL;
+       MsgDbHandler *dbHandle = getDbHandle();
+       MimeType mimeType = MIME_UNKNOWN;
+
+       memset(&mmsMsg, 0x00, sizeof(MMS_MESSAGE_DATA_S));
+       MsgMmsConvertMmsDataToMmsMessageData(pMmsData, &mmsMsg);
+
+       // Get the text data from the 1st slide.
+       if (mmsMsg.pageCnt <= 0) {
+               MSG_WARN("pageCnt : %d", mmsMsg.pageCnt);
+               MsgMmsReleaseMmsLists(&mmsMsg);
+               return false;
+       }
+
+       pPage = _MsgMmsGetPage(&mmsMsg, 0);
+
+       if (!pPage) {
+               MSG_WARN("page is NULL");
+               MsgMmsReleaseMmsLists(&mmsMsg);
+               return false;
+       }
+
+       for (int j = 0; j < pPage->mediaCnt; ++j) {
+               pMedia = _MsgMmsGetMedia(pPage, j);
+
+               if (pMedia && pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
+
+                       MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
+
+                       if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
+                               MSG_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
+                       } else {
+                               strncpy(filePath, pMedia->szFilePath, MSG_FILEPATH_LEN_MAX);
+
+                               g_file_get_contents((const gchar *)filePath, &fileContent, NULL, NULL);
+
+                               bFiltered = MsgCheckFilterByWord(dbHandle, (const char *)fileContent);
+
+                               g_free(fileContent);
+                               fileContent = NULL;
+
+                               if (bFiltered == true)
+                                       break;
+                       }
+               }
+       }
+
+       MsgMmsReleaseMmsLists(&mmsMsg);
+
+       return bFiltered;
+}
+
 bool MmsPluginInternal::getMmsReport(MmsReport mmsReport)
 {
        bool result = false;
index 8c481c7..de8bb40 100755 (executable)
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <string>
 #include <stdlib.h>
 #include "MmsPluginMIME.h"
 #include "MmsPluginDebug.h"
-#include "MmsPluginSmil.h"
 
-#ifndef        NULL
-#define        NULL    0
-#endif
+typedef enum _MimeAppType {
+       MIME_APPLICATION_NONE,
 
+       MIME_APPLICATION_CAMERA,
+       MIME_APPLICATION_VIDEORECORDER,
 
-/* Header field */
-static const char *szMsgField[MSG_FIELD_NUM] =
-{
-       "Return-Path",
-       "Message-ID",
-       "From" ,
-       "To" ,
-       "Cc" ,
-       "Subject",
-       "Date",
-       "Mime-Version",
-       "Content-Type",
-       "Content-Transfer-Encoding",
-       "Content-Disposition", //If start param is given in multipart/related, this field will be ignored
-       "Content-ID", //for start part of multipart/related body
-       "Content-Location",
-       "Content-Name",
-       "Content-Description",
-       "Content-Vendor",
-       "Rights-Issuer",
-       "Return-Receipt-To",                    /* Delivery confirm */
-       "Disposition-Notification-To",  /* Read confirm */
-       "Content-Rep-Pos",
-       "Content-Rep-Size",
-       "Content-Rep-Index"
-};
+       MIME_APPLICATION_IMAGEVIEWER,
+       MIME_APPLICATION_FLASHVIEWER,
+       MIME_APPLICATION_IMAGEEDITOR,
+       MIME_APPLICATION_THEMEVIEWER,
 
-/*  MIME header field parameter */
-static const char *szMsgParam[MSG_PARAM_NUM] =
-{
-       "charset",
-       "name",
-       "filename",
-       "type",         //Only if content-type is multipart/related,
-       "start",        //Only if content-type is multipart/related
-       "start-info",   //Only if content-type is multipart/related
-       "boundary",
-       "report-type", // only used as parameter of Content-Type: multipart/report; report-type=delivery-status;
-#ifdef FEATURE_JAVA_MMS
-       "Application-ID",                               //laconic_javaParamFix
-       "Reply-To-Application-ID",              //laconic_javaParamFix
-#endif
-};
+       MIME_APPLICATION_SOUNDPLAYER,
+       MIME_APPLICATION_MEDIAPLAYER,
+       MIME_APPLICATION_VOICEMEMO,
 
-/* Content-Transfer-Encoding header value */
-static const char *szMsgEncoding[MSG_ENCODING_NUM] =
-{
-       "7bit",
-       "8bit",
-       "binary",
-       "base64",
-       "quoted-printable"
-};
+       MIME_APPLICATION_PICSELVIEWER,
 
-/* Content-Disposition header value */
-static const char *szMsgDisposition[MSG_DISPOSITION_NUM] =
-{
-       "form-data",
-       "attachment",
-       "inline"
-};
+       MIME_APPLICATION_CONTACT,
+       MIME_APPLICATION_ORGANIZER,
 
-static const char *szMsgAddrType[MSG_ADDR_TYPE_NUM] =
-{
-       "/TYPE=PLMN",
-       "",
-       "/TYPE=IPV4",
-       "/TYPE=IPV6",
-       ""
-};
+       MIME_APPLICATION_MAX
+} MimeAppType;
 
-/* character-set value */
-static const char *szMsgCharset [MSG_CHARSET_NUM] =
-{
-       "us-ascii",
-       "utf-16",
-       "usc-2",
-       "utf-8",
-       /* MIME character-set value */
-
-       "iso-2022-kr",
-       "ks_c_5601-1987",
-       "euc_kr",
-       "iso-2022-jp",
-       "iso-2022-jp-2",
-       "iso-8859-1",
-       "iso-8859-2",
-       "iso-8859-3",
-       "iso-8859-4",
-       "iso-8859-5",
-       "iso-8859-6",
-       "iso-8859-6-e",
-       "iso-8859-6-i",
-       "iso-8859-7",
-       "iso-8859-8",
-       "iso-8859-8-i",
-       "iso-8859-9",
-       "iso-8859-10",
-       "iso-8859-15",
-       "Shift_jis",
-       "euc-jp",
-       "gb2312",
-       "big5",
-       "win1251",
-       "window-1251",
-       "windows-1251",
-       "koi8-r",
-       "koi8-u"
-};
 
+typedef struct _MimeTable {
+       const char *szMIME;
+       const char *szExt;
+       bool bDownloadable;
+       MimeType mime;                  /* index of mime type */
+       MimeType contentType;   /* representative mime type */
+       MimeAppType appType;
+       MimeMainType mainType;
+       int binary;
+} MimeTable;
 
 /**************************************************     MIME definition     ***************************************************/
 static const MimeTable mimeTable[] = {
@@ -216,8 +134,8 @@ static const MimeTable mimeTable[] = {
        {"audio/amr-wb",                                                                                "amr",                          true,           MIME_AUDIO_AMR_WB,                                                              MIME_AUDIO_AMR_WB,                                              MIME_APPLICATION_VOICEMEMO,                             MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
        {"audio/mmf",                                                                                   "mmf",                          true,           MIME_AUDIO_MMF,                                                                 MIME_AUDIO_MMF,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
        {"audio/smaf",                                                                                  "mmf",                          true,           MIME_AUDIO_SMAF,                                                                MIME_AUDIO_SMAF,                                                MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
-       {"audio/iMelody",                                                                               "imy",                          true,           MIME_AUDIO_IMELODY,                                                             MIME_AUDIO_IMELODY,                                             MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
-       {"audio/imelody",                                                                               "imy",                          true,           MIME_AUDIO_IMELODY2,                                                            MIME_AUDIO_IMELODY,                                             MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
+       {"audio/imelody",                                                                               "imy",                          true,           MIME_AUDIO_IMELODY,                                                             MIME_AUDIO_IMELODY,                                             MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
+       {"audio/iMelody",                                                                               "imy",                          true,           MIME_AUDIO_IMELODY2,                                                            MIME_AUDIO_IMELODY,                                             MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
        {"audio/melody",                                                                                "imy",                          true,           MIME_AUDIO_MELODY,                                                              MIME_AUDIO_IMELODY,                                             MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
        {"audio/mid",                                                                                   "mid",                          true,           MIME_AUDIO_MID,                                                                 MIME_AUDIO_MID,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
        {"audio/midi",                                                                                  "mid"/*,midi"*/,        true,           MIME_AUDIO_MIDI,                                                                MIME_AUDIO_MID,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,                    UNDEFINED_BINARY        },
@@ -292,14 +210,15 @@ static const MimeTable mimeTable[] = {
        {"multipart/voice-message",                                                     "",                                     false,          MIME_MULTIPART_VOICE_MESSAGE,                                   MIME_MULTIPART_VOICE_MESSAGE,                   MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_APPLICATION,      UNDEFINED_BINARY        },
 
        //128
-       {"text/txt",                                                                                    "txt",                          false,          MIME_TEXT_TXT,                                                                  MIME_TEXT_TXT,                                                  MIME_APPLICATION_PICSELVIEWER,                  MIME_MAINTYPE_TEXT,                     UNDEFINED_BINARY        },
+       {"text/txt",                                                                                    "",                             false,          MIME_TEXT_TXT,                                                                  MIME_TEXT_TXT,                                                  MIME_APPLICATION_PICSELVIEWER,                  MIME_MAINTYPE_TEXT,                     UNDEFINED_BINARY        },
        {"text/html",                                                                                   "html"/*,htm"*/,        false,          MIME_TEXT_HTML,                                                                 MIME_TEXT_HTML,                                                 MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x02    },
        {"text/plain",                                                                                  "txt"/*,vbm,url"*/,                             false,          MIME_TEXT_PLAIN,                                                                MIME_TEXT_PLAIN,                                                MIME_APPLICATION_PICSELVIEWER,                  MIME_MAINTYPE_TEXT,                     0x03    },
        {"text/css",                                                                                    "",                                     false,          MIME_TEXT_CSS,                                                                  MIME_TEXT_CSS,                                                  MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x3d    },
        {"text/xml",                                                                                    "",                                     false,          MIME_TEXT_XML,                                                                  MIME_TEXT_XML,                                                  MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x28    },
        {"text/iMelody",                                                                                "imy",                          true,           MIME_TEXT_IMELODY,                                                              MIME_TEXT_IMELODY,                                              MIME_APPLICATION_SOUNDPLAYER,                   MIME_MAINTYPE_AUDIO,            UNDEFINED_BINARY        },
+       {"text/calendar",                                                                               "ics",                          true,   MIME_TEXT_CALENDAR,                                                             MIME_TEXT_CALENDAR,                                             MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,             UNDEFINED_BINARY },
 
-       //134
+       //135
        {"text/vnd.wap.wmlscript",                                                              "",                                     false,          MIME_TEXT_VND_WAP_WMLSCRIPT,                                    MIME_TEXT_VND_WAP_WMLSCRIPT,                    MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x09    },
        {"text/vnd.wap.wml",                                                                    "wml",                          false,          MIME_TEXT_VND_WAP_WML,                                                  MIME_TEXT_VND_WAP_WML,                                  MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x08    },
        {"text/vnd.wap.wta-event",                                                              "",                                     false,          MIME_TEXT_VND_WAP_WTA_EVENT,                                    MIME_TEXT_VND_WAP_WTA_EVENT,                    MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x0a    },
@@ -310,30 +229,32 @@ static const MimeTable mimeTable[] = {
        {"text/vnd.sun.j2me.app-descriptor",                                    "jad",                          true,           MIME_TEXT_VND_SUN_J2ME_APP_DESCRIPTOR,                  MIME_TEXT_VND_SUN_J2ME_APP_DESCRIPTOR,  MIME_APPLICATION_NONE,                                          MIME_MAINTYPE_ETC,                      UNDEFINED_BINARY        },
 
 
-       //142
+       //143
        {"text/x-hdml",                                                                         "",                                     false,          MIME_TEXT_X_HDML,                                                               MIME_TEXT_X_HDML,                                               MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x04    },
-       {"text/x-vCalendar",                                                                    "vcs",                          true,           MIME_TEXT_X_VCALENDAR,                                                  MIME_TEXT_X_VCALENDAR,                                  MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x06    },
-       {"text/x-vCard",                                                                                "vcf",                          true,           MIME_TEXT_X_VCARD,                                                              MIME_TEXT_X_VCARD,                                              MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     0x07    },
+       {"text/x-vCalendar",                                                                    "vcs",                          true,           MIME_TEXT_X_VCALENDAR,                                                  MIME_TEXT_X_VCALENDAR,                                  MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_ETC,                      0x06    },
+       {"text/x-vCard",                                                                                "vcf",                          true,           MIME_TEXT_X_VCARD,                                                              MIME_TEXT_X_VCARD,                                              MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_ETC,                      0x07    },
        {"text/x-iMelody",                                                                              "imy",                          true,           MIME_TEXT_X_IMELODY,                                                    MIME_TEXT_X_IMELODY,                                    MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,            UNDEFINED_BINARY        },
        {"text/x-imelody",                                                                              "imy",                          true,           MIME_TEXT_X_IMELODY2,                                                   MIME_TEXT_X_IMELODY,                                    MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_AUDIO,            UNDEFINED_BINARY        },
        {"text/x-vnote",                                                                                "vnt",                          true,           MIME_TEXT_X_VNOTE,                                                              MIME_TEXT_X_VNOTE,                                              MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     UNDEFINED_BINARY        },
+       {"text/x-vtodo",                                                                                "vts",                          true,           MIME_TEXT_X_VTODO,                                                              MIME_TEXT_X_VNOTE,                                              MIME_APPLICATION_NONE,                                  MIME_MAINTYPE_TEXT,                     UNDEFINED_BINARY        },
 
-       //148
+       //150
        {"video/mpeg4",                                                                         "mp4",                          true,           MIME_VIDEO_MPEG4,                                                               MIME_VIDEO_MP4,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/mp4",                                                                                   "mp4",                          true,           MIME_VIDEO_MP4,                                                                 MIME_VIDEO_MP4,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
-       {"video/h263",                                                                                  "3gp"/*,3gpp,mp4"*/,true,               MIME_VIDEO_H263,                                                                MIME_VIDEO_H263,                                                MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
+       {"video/h263",                                                                                  ""/*,3gpp,mp4"*/,true,          MIME_VIDEO_H263,                                                                MIME_VIDEO_H263,                                                MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/3gpp",                                                                                  "3gp"/*,3gpp"*/,        true,           MIME_VIDEO_3GPP,                                                                MIME_VIDEO_3GPP,                                                MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/3gp",                                                                                   "3gp"/*,3gpp"*/,        true,           MIME_VIDEO_3GP,                                                                 MIME_VIDEO_3GP,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/avi",                                                                                   "avi",                          false,          MIME_VIDEO_AVI,                                                                 MIME_VIDEO_AVI,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/sdp",                                                                                   "sdp",                          true,           MIME_VIDEO_SDP,                                                                 MIME_APPLICATION_SDP,                                                   MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/mp4v-es",                                                                                       "3gp",                          true,           MIME_VIDEO_MP4_ES,                                                                      MIME_VIDEO_3GP,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
        {"video/mpeg",                                                                                  "3gp",                          true,           MIME_VIDEO_MPEG,                                                                        MIME_VIDEO_3GP,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
+       {"video/quicktime",                                                                             "mov",                          true,           MIME_VIDEO_MOV,                                                                 MIME_VIDEO_3GP,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,            UNDEFINED_BINARY        },
 
-       // 157
+       // 160
        {"video/vnd.rn-realvideo",                                                              "rm",                           true,           MIME_VIDEO_VND_RN_REALVIDEO,                                    MIME_VIDEO_VND_RN_REALVIDEO,                    MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,                    UNDEFINED_BINARY        },
        {"video/vnd.rn-realmedia",                                                              "rm",                           true,           MIME_VIDEO_VND_RN_REALMEDIA,                                    MIME_VIDEO_VND_RN_REALMEDIA,                    MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,                    UNDEFINED_BINARY        },
 
-       //159
+       //162
        {"video/x-mp4",                                                                         "mp4",                          true,           MIME_VIDEO_X_MP4,                                                               MIME_VIDEO_MP4,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,                    UNDEFINED_BINARY        },
        {"video/x-pv-mp4",                                                                              "mp4",                          true,           MIME_VIDEO_X_PV_MP4,                                                    MIME_VIDEO_MP4,                                                 MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,                    UNDEFINED_BINARY        },
        {"video/x-pn-realvideo",                                                                "rv",                           true,           MIME_VIDEO_X_PN_REALVIDEO,                                              MIME_VIDEO_VND_RN_REALVIDEO,                    MIME_APPLICATION_MEDIAPLAYER,                   MIME_MAINTYPE_VIDEO,                    UNDEFINED_BINARY        },
@@ -351,84 +272,10 @@ static const int mimeTableIndex[] = {
        105,            116,            119,
        120,            120,            120,
        121,            121,            121,
-       128,            134,            142,
-       148,            157,            159
+       128,            135,            143,
+       150,            160,            162
 };
 
-
-/*****************             Extension definition      *****************/
-static const ExtTable extTable[] = {
-
-       {"txt",                 MIME_TEXT_PLAIN},
-       {"html",                        MIME_TEXT_HTML},
-       {"htm",                 MIME_TEXT_HTML},
-       {"xhtml",                       MIME_APPLICATION_XHTML_XML},
-       {"wml",                 MIME_TEXT_VND_WAP_WML},
-       {"vcs",                 MIME_TEXT_X_VCALENDAR},
-       {"vcf",                 MIME_TEXT_X_VCARD},
-       {"vnt",                 MIME_TEXT_X_VNOTE},
-       {"smil",                        MIME_APPLICATION_SMIL},
-       {"eml",                 MIME_MESSAGE_RFC822},
-       {"gif",                 MIME_IMAGE_GIF},
-       {"jpeg",                        MIME_IMAGE_JPEG},
-       {"jpg",                 MIME_IMAGE_JPEG},
-       {"jpe",                 MIME_IMAGE_JPEG},
-       {"jpz",                 MIME_IMAGE_JPEG},
-       {"tiff",                        MIME_IMAGE_TIFF},
-       {"tif",                 MIME_IMAGE_TIFF},
-       {"png",                 MIME_IMAGE_PNG},
-       {"pnz",                 MIME_IMAGE_PNG},
-       {"wbmp",                        MIME_IMAGE_VND_WAP_WBMP},
-       {"bmp",                 MIME_IMAGE_BMP},
-       {"au",                          MIME_AUDIO_BASIC},
-       {"snd",                 MIME_AUDIO_BASIC},
-       {"mp3",                 MIME_AUDIO_MP3},
-       {"aac",                 MIME_AUDIO_AAC},
-       {"mp4",                 MIME_AUDIO_MP4},
-       {"m4a",                 MIME_AUDIO_M4A},
-       {"amr",                 MIME_AUDIO_X_AMR},
-       {"mmf",                 MIME_APPLICATION_VND_SMAF},
-       {"imy",                 MIME_AUDIO_X_IMELODY},
-       {"mid",                 MIME_AUDIO_MID},
-       {"midi",                        MIME_AUDIO_MID},
-       {"spm",                 MIME_AUDIO_SP_MIDI},
-       {"wav",                 MIME_AUDIO_WAVE},
-       {"3gp",                 MIME_AUDIO_3GPP},
-       {"3gpp",                        MIME_VIDEO_3GPP},
-       {"rm",                          MIME_VIDEO_VND_RN_REALVIDEO},
-       {"ra",                          MIME_AUDIO_VND_RN_REALAUDIO},
-       {"ram",                 MIME_AUDIO_VND_RN_REALAUDIO},
-       {"wma",                 MIME_AUDIO_X_MS_WMA},
-       {"smp",                 MIME_APPLICATION_STUDIOM},
-       {"avi",                 MIME_VIDEO_AVI},
-       {"sdp",                 MIME_APPLICATION_SDP},
-       {"vbm",                 MIME_TEXT_PLAIN},
-       {"url",                 MIME_TEXT_PLAIN},
-       {"jad",                 MIME_TEXT_VND_SUN_J2ME_APP_DESCRIPTOR},
-       {"jar",                 MIME_APPLICATION_VND_SUN_J2ME_JAVA_ARCHIVE},
-       {"dd",                          MIME_APPLICATION_VND_OMA_DD_XML},
-       {"dm",                          MIME_APPLICATION_VND_OMA_DRM_MESSAGE},
-       {"dcf",                 MIME_APPLICATION_VND_OMA_DRM_CONTENT},
-       {"rv",                          MIME_VIDEO_X_PN_REALVIDEO},
-       {"ro",                          MIME_APPLICATION_VND_OMA_DRM_RIGHTS_XML},
-       {"thm",                 MIME_APPLICATION_VND_SAMSUNG_THEME},
-       {"xls",                 MIME_APPLICATION_X_EXCEL},
-       {"pdf",                 MIME_APPLICATION_PDF},
-       {"ppt",                 MIME_APPLICATION_X_POWERPOINT},
-       {"swf",                 MIME_APPLICATION_X_FLASH},
-       {"svg",                 MIME_IMAGE_SVG},
-       {"doc",                 MIME_APPLICATION_MSWORD},
-       {"wmv",                 MIME_VIDEO_X_MS_WMV},
-       {"asf",                 MIME_VIDEO_X_MS_ASF},
-       {"3ga",                 MIME_AUDIO_M4A},
-       {"xmf",                 MIME_AUDIO_XMF},
-       {"mxmf",                        MIME_AUDIO_MOBILE_XMF},
-       {"pvx",                 MIME_VIDEO_X_PV_PVX},
-       {"oro",                 MIME_APPLICATION_VND_OMA_DRM_RO_XML},
-       {"odf",                 MIME_APPLICATION_VND_OMA_DRM_DCF}
-};
-
-
 static int mimeTableEnum[] =
 {
        MIME_ASTERISK   ,
@@ -584,6 +431,7 @@ static int mimeTableEnum[] =
        MIME_TEXT_CSS   ,
        MIME_TEXT_XML   ,
        MIME_TEXT_IMELODY       ,
+       MIME_TEXT_CALENDAR,
        MIME_TEXT_VND_WAP_WMLSCRIPT     ,
        MIME_TEXT_VND_WAP_WML   ,
        MIME_TEXT_VND_WAP_WTA_EVENT     ,
@@ -598,7 +446,7 @@ static int mimeTableEnum[] =
        MIME_TEXT_X_IMELODY     ,
        MIME_TEXT_X_IMELODY2 ,
        MIME_TEXT_X_VNOTE ,
-
+       MIME_TEXT_X_VTODO,
 
        MIME_VIDEO_MPEG4        ,
        MIME_VIDEO_MP4  ,
@@ -609,6 +457,7 @@ static int mimeTableEnum[] =
        MIME_VIDEO_SDP  ,
        MIME_VIDEO_MP4_ES,
        MIME_VIDEO_MPEG ,
+       MIME_VIDEO_MOV  ,
        MIME_VIDEO_VND_RN_REALVIDEO     ,
        MIME_VIDEO_VND_RN_REALMEDIA     ,
        MIME_VIDEO_X_MP4        ,
@@ -623,8 +472,8 @@ static int mimeTableEnum[] =
 };
 
 
-#define MIME_MAX_NUM   166
-#define EXT_MAX        67
+#define MIME_MAX_NUM   167
+#define EXT_MAX        68
 #define MIME_SUB_TYPE_VND      1
 #define MIME_SUB_TYPE_X                2
 
@@ -632,41 +481,6 @@ int __MimeGetTableIndexInt(MimeType mime);
 int __MimeGetTableIndexString(const char *szMime);
 MimeMainType __MimeGetMainTypeName(const char *szType);
 
-
-/*
- * This function checks whether a mime is downloadable or not.
- *
- * @param      mime [in] Enumeration number for a MIME type.
- * @return     This function returns true if downloadable, or false.
- */
-bool MimeIsDownloadableInt(MimeType mime)
-{
-       int index;
-
-       index = __MimeGetTableIndexInt(mime);
-       if (index == MIME_UNKNOWN)
-               return false;
-
-       return mimeTable[index].bDownloadable;
-}
-
-/*
- * This function checks whether a mime is downloadable or not.
- *
- * @param      mime [in] MIME string.
- * @return     This function returns true if downloadable, or false.
- */
-bool MimeIsDownloadableString(const char *szMime)
-{
-       int index;
-
-       index = __MimeGetTableIndexString(szMime);
-       if (index == MIME_UNKNOWN)
-               return false;
-
-       return mimeTable[index].bDownloadable;
-}
-
 /*
  * This function checks main type of a MIME.
  *
@@ -684,22 +498,6 @@ MimeMainType MimeGetMainTypeInt(MimeType mime)
        return mimeTable[index].mainType;
 }
 
-/*
- * This function checks main type of a MIME.
- *
- * @param      mime [in] MIME string.
- * @return     This function returns main type of a MIME.
- */
-MimeMainType MimeGetMainTypeString(const char *szMime)
-{
-       int index;
-
-       index = __MimeGetTableIndexString(szMime);
-       if (index == MIME_UNKNOWN)
-               return MIME_MAINTYPE_ETC;
-
-       return mimeTable[index].mainType;
-}
 
 /*
  * This function returns a extension name for a specified MIME.
@@ -719,67 +517,6 @@ char *MimeGetExtFromMimeInt(MimeType mime)
 }
 
 /*
- * This function returns a extension name for a specified MIME.
- *
- * @param      mime [in] MIME string.
- * @return     This function returns Extension string.
- */
-char *MimeGetExtFromMimeString(const char *szMime)
-{
-       int index;
-
-       index = __MimeGetTableIndexString(szMime);
-       if (index == MIME_UNKNOWN)
-               return NULL;
-
-       return (char *)mimeTable[index].szExt;
-}
-
-
-/*
- * This function returns a MIME type for a specified Extension.
- *
- * @param      mime [in] Extension string.
- * @return     This function returns MIME string.
- */
-char *MimeGetMimeFromExtString(const char *szExt)
-{
-       int i;
-
-       for (i = 0; i < EXT_MAX; i++) {
-               if (!strcasecmp( extTable[i].szExt, szExt)) {
-                       int index;
-
-                       index = __MimeGetTableIndexInt(extTable[i].mimeType);
-                       if (index == MIME_UNKNOWN)
-                               return NULL;
-
-                       return (char *)mimeTable[index].szMIME;
-               }
-       }
-
-       return NULL;
-}
-
-/*
- * This function returns a MIME type for a specified Extension.
- *
- * @param      mime [in] Extension string.
- * @return     This function returns MIME string.
- */
-MimeType MimeGetMimeFromExtInt(const char *szExt)
-{
-       int i;
-
-       for (i = 0; i < EXT_MAX; i++) {
-               if (!strcasecmp( extTable[i].szExt, szExt))
-                       return extTable[i].mimeType;
-       }
-
-       return MIME_UNKNOWN;
-}
-
-/*
  * This function returns index number in MIME definition table with MIME enumeration.
  * Internal function.
  */
@@ -807,8 +544,6 @@ int __MimeGetTableIndexInt(MimeType mime)
        return tableIndex;
 }
 
-
-#define MIME_MAX_LEN   43
 /*
  * This function returns index number in MIME definition table with MIME string.
  * Internal function.
@@ -846,7 +581,8 @@ int __MimeGetTableIndexString(const char *szMime)
                free(szMIMEType);
                return 0;
        }
-       strcpy(szMIMEType, szMime);
+
+       strncpy(szMIMEType, szMime, strlen(szMime));
        type = 0;
        subtype = 0;
 
@@ -949,7 +685,7 @@ MimeMainType __MimeGetMainTypeName(const char *szType)
 }
 
 
-
+//For Decode
 // MimeString -> MimeInt
 MimeType MimeGetMimeIntFromMimeString(char *szMimeStr)
 {
@@ -989,22 +725,6 @@ MimeType MimeGetMimeIntFromBi(int binCode)
        return MIME_UNKNOWN;
 }
 
-// BinaryCode -> MimeInt
-char *MimeGetMimeStringFromBi(int binCode)
-{
-       int index;
-
-       if (binCode < 0x00 || binCode > 0x4b)
-               return NULL;
-
-       for (index = 0; index < MIME_MAX_NUM; index++) {
-               if (binCode == mimeTable[index].binary)
-                       return (char *)mimeTable[index].szMIME;
-       }
-
-       return NULL;
-}
-
 // Mimeint -> Binary Value
 int MimeGetBinaryValueFromMimeInt(MimeType mime)
 {
@@ -1017,309 +737,146 @@ int MimeGetBinaryValueFromMimeInt(MimeType mime)
        return mimeTable[index].binary;
 }
 
-// MimeString -> Binary value
-int MimeGetBinaryValueFromMimeString(const char *szMime)
-{
-       int index;
-
-       index = __MimeGetTableIndexString(szMime);
-       if (index == MIME_UNKNOWN)
-               return UNDEFINED_BINARY;
-
-       return mimeTable[index].binary;
-}
+typedef struct {
+       const char *szExt;
+       int mainType;
+       int enumMime;
+       const char *szContentType;
+} ExtTableItem;
+
+#define EXT_TABLE_SIZE (56)
+
+const ExtTableItem extTable[EXT_TABLE_SIZE] = {
+
+       //text
+       {"txt",   MIME_MAINTYPE_TEXT, MIME_TEXT_PLAIN, "text/plain"},
+       {"html",  MIME_MAINTYPE_TEXT, MIME_TEXT_HTML, "text/html"},
+       {"xhtml", MIME_MAINTYPE_TEXT, MIME_APPLICATION_XHTML_XML, "application/xhtml+xml"},
+       {"vcs",   MIME_MAINTYPE_TEXT, MIME_TEXT_X_VCALENDAR, "text/x-vCalendar"},
+       {"vcf",   MIME_MAINTYPE_TEXT, MIME_TEXT_X_VCARD, "text/x-vCard"},
+       {"vnt",   MIME_MAINTYPE_TEXT, MIME_TEXT_X_VNOTE, "text/x-vnote"},
+       {"vts",   MIME_MAINTYPE_TEXT, MIME_TEXT_X_VTODO, "text/x-vtodo"},
+       {"ics",   MIME_MAINTYPE_TEXT, MIME_TEXT_CALENDAR, "text/calendar"},
+
+       //image
+       {"gif",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_GIF, "image/gif"},
+       //{"jpg",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_JPG, "image/jpg"},
+       {"jpg",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_JPEG, "image/jpeg"},
+       {"jpeg",  MIME_MAINTYPE_IMAGE, MIME_IMAGE_JPEG, "image/jpeg"},
+       {"tiff",  MIME_MAINTYPE_IMAGE, MIME_IMAGE_TIFF, "image/tiff"},
+       {"tif",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_TIF, "image/tif"},
+       {"png",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_PNG, "image/png"},
+       {"wbmp",  MIME_MAINTYPE_IMAGE, MIME_IMAGE_VND_WAP_WBMP, "image/vnd.wap.wbmp"},
+       {"bmp",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_BMP, "image/bmp"},
+       {"svg",   MIME_MAINTYPE_IMAGE, MIME_IMAGE_SVG, "image/svg+xml"},
+
+       //audio
+       {"snd",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_BASIC, "audio/basic"},
+       {"amr",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_AMR, "audio/amr"},
+       {"m4a",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_M4A, "audio/m4a"},
+       {"3gp",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_3GPP, "audio/3gpp"},
+       {"3gpp",  MIME_MAINTYPE_AUDIO, MIME_AUDIO_3GPP, "audio/3gpp"},
+       {"mp3",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_MPEG, "audio/mpeg"},
+       {"aac",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_AAC, "audio/aac"},
+       {"imy",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_IMELODY, "audio/imelody"},
+       {"mid",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_MID, "audio/mid"},
+       {"mmf",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_MMF, "audio/mmf"},
+       {"spm",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_SP_MIDI, "audio/sp-midi"},
+       {"wav",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_WAV, "audio/wav"},
+       {"mp4",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_MP4, "audio/mp4"},
+       {"wma",   MIME_MAINTYPE_AUDIO, MIME_AUDIO_X_MS_WMA, "audio/x-ms-wma"},
+       {"rm",    MIME_MAINTYPE_AUDIO, MIME_AUDIO_VND_RN_REALAUDIO, "audio/vnd.rn-realaudio"},
+       {"ra",    MIME_MAINTYPE_AUDIO, MIME_AUDIO_VND_RN_REALAUDIO, "audio/vnd.rn-realaudio"},
+
+       //video
+       {"3gp",   MIME_MAINTYPE_VIDEO, MIME_VIDEO_3GPP, "video/3gpp"},
+       {"3gpp",  MIME_MAINTYPE_VIDEO, MIME_VIDEO_3GPP, "video/3gpp"},
+       {"mp4",   MIME_MAINTYPE_VIDEO, MIME_VIDEO_MP4, "video/mp4"},
+       {"rm",    MIME_MAINTYPE_VIDEO, MIME_VIDEO_VND_RN_REALVIDEO, "video/vnd.rn-realvideo"},
+       {"rv",    MIME_MAINTYPE_VIDEO, MIME_VIDEO_VND_RN_REALVIDEO, "video/vnd.rn-realvideo"},
+       {"avi",   MIME_MAINTYPE_VIDEO, MIME_VIDEO_AVI, "video/avi"},
+       {"asf",   MIME_MAINTYPE_VIDEO, MIME_VIDEO_X_MS_ASF, "video/x-ms-asf"},
+       {"mov", MIME_MAINTYPE_VIDEO, MIME_VIDEO_MOV, "video/quicktime"},
+
+       //application
+       {"smil",  MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_SMIL, "application/smil"},
+       {"rm",    MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_RN_REALMEDIA, "application/vnd.rn-realmedia"},
+       {"ram",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_RAM, "application/ram"},
+       {"ppt",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_POWERPOINT, "application/vnd.ms-powerpoint"},
+       {"xls",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_EXCEL, "application/vnd.ms-excel"},
+       {"doc",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_MSWORD, "applcation/vnd.ms-word"},
+       {"pdf",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_PDF, "application/pdf"},
+       {"swf",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_X_FLASH, "application/x-shockwave-flash"},
+       {"dm",    MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DRM_MESSAGE, "application/vnd.oma.drm.message"},
+       {"dcf",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DRM_CONTENT, "application/vnd.oma.drm.content"},
+       {"dd",    MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DD_XML, "application/vnd.oma.dd+xml"},
+       {"ro",    MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DRM_RIGHTS_XML, "application/vnd.oma.drm.rights+xml"},
+       {"ro",    MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DRM_RIGHTS_WBXML, "application/vnd.oma.drm.rights+wbxml"},
+       {"oro",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DRM_RO_XML, "application/vnd.oma.drm.ro+xml"},
+       {"odf",   MIME_MAINTYPE_APPLICATION, MIME_APPLICATION_VND_OMA_DRM_DCF, "application/vnd.oma.drm.dcf"},
 
+};
 
-/*
- * This function checks main type of a MIME.
- *
- * @param      mime [in] Enumeration number for a MIME type.
- * @return     This function returns application type of a MIME.
- */
-MimeAppType MimeGetAppTypeFromInt(MimeType mime)
+//GetMimeType from File Extension
+bool MmsGetMimeTypeFromExt(MimeMainType mainType, const char *pExt, MimeType *pMimeType, const char **ppszMimeType)
 {
-       int index;
-
-       index = __MimeGetTableIndexInt(mime);
-       if (index == MIME_UNKNOWN)
-               return MIME_APPLICATION_NONE;
-
-       return mimeTable[index].appType;
-}
+       const ExtTableItem *matchedItem = NULL;
 
-/*
- * This function checks main type of a MIME.
- *
- * @param      mime [in] MIME string.
- * @return     This function returns application type of a MIME.
- */
-MimeAppType MimeGetAppTypeFromString(const char *szMime)
-{
-       int index;
+       if (pExt == NULL)
+               return false;
 
-       index = __MimeGetTableIndexString(szMime);
-       if (index == MIME_UNKNOWN)
-               return MIME_APPLICATION_NONE;
+       if (pMimeType == NULL && ppszMimeType == NULL)
+               return false;
 
-       return mimeTable[index].appType;
-}
+       int extTableMainSize = sizeof(extTable)/sizeof(ExtTableItem);;
 
+       for (int i = 0; i < extTableMainSize; i++) {
 
-/*
- * This function returns a application type for a specified Extension.
- *
- * @param      mime [in] Extension string.
- * @return     This function returns application type.
- */
-MimeAppType MimeGetAppTypeFromExtString(const char *szExt)
-{
-       int i;
+               if (strcasecmp(extTable[i].szExt, pExt) == 0) {
 
-       for (i = 0; i < EXT_MAX; i++) {
-               if (!strcasecmp( extTable[i].szExt, szExt)) {
-                       int index;
+                       matchedItem = &extTable[i];
 
-                       index = __MimeGetTableIndexInt(extTable[i].mimeType);
-                       if (index == MIME_UNKNOWN)
-                               return MIME_APPLICATION_NONE;
-                       return mimeTable[index].appType;
+                       if (mainType == extTable[i].mainType) {
+                               break;
+                       }
                }
        }
 
-       return MIME_APPLICATION_NONE;
-}
+       if (matchedItem) {
+               MSG_DEBUG("Found ext = [%s], mainType = [%d], mimeType = [0x%04x], ContentType = [%s]"
+                               , matchedItem->szExt
+                               , matchedItem->mainType
+                               , matchedItem->enumMime
+                               , matchedItem->szContentType);
 
-/*
- * This function gets the representative mime type from MimeType
- *
- * @param      mime [in] Enumeration number for a MIME type.
- * @return     representative mime type Enumeration number
- */
+               if (pMimeType)
+                       *pMimeType = (MimeType)matchedItem->enumMime;
 
-MimeType MimeGetContentTypeFromInt(MimeType mime)
-{
-       int index;
+               if (ppszMimeType)
+                       *ppszMimeType = matchedItem->szContentType;
 
-       for (index = 0; index < MIME_MAX_NUM; index++) {
-               if (mime == mimeTable[index].mime)
-                       return mimeTable[index].contentType;
+               return true;
        }
 
-       return MIME_UNKNOWN;
+       return false;
 }
 
-/*
- * This function gets the representative mime type from mime string
- *
- * @param      szMime - string name of MimeType
- * @return     representative mime type Enumeration number
- */
-
-MimeType MimeGetContentTypeFromString(const char *szMime)
-{
-       int index;
-
-       for (index = 0; index < MIME_MAX_NUM; index++) {
-               if (!strcasecmp(szMime, mimeTable[index].szMIME))
-                       return mimeTable[index].contentType;
-       }
-
-       return MIME_UNKNOWN;
-}
-
-/*
- * This function gets the index from mime string
- *
- * @param      szMime - string name of MimeType
- * @return     Enumeration number for a MIME type.
- */
-
-MimeType MimeGetMimeTypeFromString(const char *szMime)
+bool MmsGetMimeTypeFromFileName(MimeMainType mainType, const char *pFileName, MimeType *pMimeType, const char **ppszMimeType)
 {
-       int index;
-
-       for (index = 0; index < MIME_MAX_NUM; index++) {
-               if (!strcasecmp(szMime, mimeTable[index].szMIME))
-                       return mimeTable[index].mime;
-       }
+       const char *pExt = NULL;
 
-       return MIME_UNKNOWN;
-}
-
-
-int MsgGetCode(MsgHeaderField tableId, char *pStr)
-{
-       int cCode = 0;
-       int nNum = MSG_FIELD_UNKNOWN;
-       char **pTable = NULL;
-
-       switch (tableId) {
-       case MSG_FIELD:
-               nNum = MSG_FIELD_NUM;
-               pTable = (char **)szMsgField;
-               break;
-
-       case MSG_PARAM:
-               nNum = MSG_PARAM_NUM;
-               pTable = (char **)szMsgParam;
-               break;
-
-       case MSG_TYPE:
-               return MimeGetMimeIntFromMimeString(pStr);
-
-       case MSG_CHARSET:
-               nNum = MSG_CHARSET_NUM;
-               pTable = (char **)szMsgCharset;
-               break;
-
-       case MSG_ENCODING:
-               nNum = MSG_ENCODING_NUM;
-               pTable = (char **)szMsgEncoding;
-               break;
-
-       case MSG_DISPOSITION:
-               nNum = MSG_DISPOSITION_NUM;
-               pTable = (char **)szMsgDisposition;
-               break;
-
-       case MSG_ADDR_TYPE:
-               nNum = MSG_ADDR_TYPE_NUM;
-               pTable = (char **)szMsgAddrType;
-               break;
-
-       default:
-               break;
-       }
-
-       for (cCode = 0; cCode < nNum; cCode++) {
-               if (!strcasecmp(pStr, pTable[cCode])) {
-                       return cCode;
-               }
-       }
-
-       return -1;
-}
-
-
-char *MsgGetString(MsgHeaderField tableId, int code)
-{
-       int nNum = MSG_FIELD_UNKNOWN;
-       char **pTable = NULL;
-
-       switch (tableId) {
-       case MSG_FIELD:
-               nNum = MSG_FIELD_NUM;
-               pTable = (char **)szMsgField;
-               break;
-
-       case MSG_PARAM:
-               nNum = MSG_PARAM_NUM;
-               pTable = (char **)szMsgParam;
-               break;
-
-       case MSG_TYPE:
-               if (code != MIME_UNKNOWN && code != -1)
-                       return MimeGetMimeStringFromMimeInt(code);
-               else
-                       return (char *)MSG_UNKNOWN_TYPE_STRING;
-
-       case MSG_CHARSET:
-               nNum = MSG_CHARSET_NUM;
-               pTable = (char **)szMsgCharset;
-               break;
-
-       case MSG_ENCODING:
-               nNum = MSG_ENCODING_NUM;
-               pTable = (char **)szMsgEncoding;
-               break;
-
-       case MSG_DISPOSITION:
-               nNum = MSG_DISPOSITION_NUM;
-               pTable = (char **)szMsgDisposition;
-               break;
-
-       case MSG_ADDR_TYPE:
-               nNum = MSG_ADDR_TYPE_NUM;
-               pTable = (char **)szMsgAddrType;
-               break;
-
-       default:
-               break;
-       }
-
-       if (code < 0 || code >= nNum || !pTable)
-               return (char *)MSG_UNKNOWN_TYPE_STRING;
-
-       return pTable[code];
-}
+       if (pFileName == NULL)
+               return false;
 
-char *_MsgSkipWS3(char *s)
-{
-       while (true) {
-               if ((*s == MSG_CH_CR) ||
-                       (*s == MSG_CH_LF) ||
-                       (*s == MSG_CH_SP) ||
-                       (*s == MSG_CH_TAB))
-                       ++s;
-               else
-                       return s;
-       }
-}
+       if (pMimeType == NULL && ppszMimeType == NULL)
+               return false;
 
+       pExt = strrchr(pFileName, '.');
 
-int _MsgGetCode(MsgHeaderField tableId, char *pStr)
-{
-       int cCode = 0;
-       int nNum = MSG_FIELD_UNKNOWN;
-       char **pTable = NULL;
-
-       switch (tableId) {
-       case MSG_FIELD:
-               nNum = MSG_FIELD_NUM;
-               pTable = (char **)szMsgField;
-               break;
-
-       case MSG_PARAM:
-               nNum = MSG_PARAM_NUM;
-               pTable = (char **)szMsgParam;
-               break;
-
-       case MSG_TYPE:
-               return MimeGetMimeIntFromMimeString(pStr);
-
-       case MSG_CHARSET:
-               nNum = MSG_CHARSET_NUM;
-               pTable = (char **)szMsgCharset;
-               break;
-
-       case MSG_ENCODING:
-               nNum = MSG_ENCODING_NUM;
-               pTable = (char **)szMsgEncoding;
-               break;
-
-       case MSG_DISPOSITION:
-               nNum = MSG_DISPOSITION_NUM;
-               pTable = (char **)szMsgDisposition;
-               break;
-
-       case MSG_ADDR_TYPE:
-               nNum = MSG_ADDR_TYPE_NUM;
-               pTable = (char **)szMsgAddrType;
-               break;
-
-       default:
-               MSG_DEBUG("_MsgGetCode: Invalid tableId [%d] \n", tableId);
-               break;
-       }
+       if (pExt == NULL || *(pExt + 1) == '\0')
+               return false;
 
-       for (cCode = 0; cCode < nNum; cCode++) {
-               if (pTable[cCode] != NULL) {
-                       if (!strcasecmp( pStr, pTable[cCode])) {
-                               return cCode;
-                       }
-               }
-       }
+       pExt = pExt + 1;
 
-       return INVALID_HOBJ;
+       return MmsGetMimeTypeFromExt(mainType, pExt, pMimeType, ppszMimeType);
 }
-
index ead9151..21e7b6e 100755 (executable)
@@ -1,23 +1,25 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
 #include "MsgException.h"
 #include "MsgGconfWrapper.h"
 #include "MsgUtilFile.h"
+#include "MsgMmsMessage.h"
+#include "MsgSerialize.h"
 #include "MmsPluginDebug.h"
 #include "MmsPluginTypes.h"
 #include "MmsPluginMain.h"
@@ -76,7 +78,7 @@ msg_error_t MmsInitialize()
        MSG_BEGIN();
 
        // remove temp files
-       MsgMmsInitDir();
+       //MsgMmsInitDir();
 
        MSG_END();
 
@@ -114,6 +116,10 @@ msg_error_t MmsSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
                MmsPluginTransport::instance()->submitRequest(pReqInfo);
        } catch (MsgException& e) {
                MSG_FATAL("%s", e.what());
+
+               if (e.errorCode() == MsgException::REQ_EXIST_ERROR)
+                       return MSG_SUCCESS;
+
                return MSG_ERR_PLUGIN_TRANSPORT;
        } catch (exception& e) {
                MSG_FATAL("%s", e.what());
@@ -140,7 +146,7 @@ msg_error_t MmsAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *p
                return MSG_ERR_PLUGIN_TRANSPORT;
        }
 
-       //MSG_END();
+       MSG_END();
 
        return MSG_SUCCESS;
 }
@@ -175,14 +181,15 @@ msg_error_t MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S
        msg_error_t err = MSG_SUCCESS;
 
        try {
-               if (pMsgInfo->networkStatus == MSG_NETWORK_NOT_SEND || pMsgInfo->networkStatus == MSG_NETWORK_SENDING) {
+               if (pMsgInfo->networkStatus == MSG_NETWORK_NOT_SEND || pMsgInfo->networkStatus == MSG_NETWORK_SENDING) { //draft update
                        err = MmsPluginStorage::instance()->updateMessage(pMsgInfo, pSendOptInfo, pFileData);
+
                } else {
                        //[Update Message ID & File path only in case of retrieve. Else update Message ID]
-                       if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
+                       if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) { //retrieve conf
                                err = MmsPluginStorage::instance()->updateConfMessage(pMsgInfo);
                        } else {
-                               err = MmsPluginStorage::instance()->updateMsgServerID(pMsgInfo, pSendOptInfo);
+                               err = MmsPluginStorage::instance()->updateMsgServerID(pMsgInfo, pSendOptInfo); //update send conf
                        }
                }
        } catch (MsgException& e) {
@@ -199,14 +206,14 @@ msg_error_t MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S
 }
 
 
-msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg)
+msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
 {
        MSG_BEGIN();
 
        msg_error_t     err = MSG_SUCCESS;
 
        try {
-               err = MmsPluginStorage::instance()->plgGetMmsMessage(pMsg, pSendOptInfo, pDestMsg);
+               err = MmsPluginStorage::instance()->getMessage(pMsg, pSendOptInfo, pDestMsg);
        } catch (MsgException& e) {
                MSG_FATAL("%s", e.what());
                return MSG_ERR_PLUGIN_STORAGE;
@@ -279,7 +286,7 @@ msg_error_t MmsComposeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
        return MSG_SUCCESS;
 }
 
-
+//FIXME::It used for kies but not now
 msg_error_t MmsRestoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char *pRcvBody, int rcvdBodyLen, char *filePath)
 {
        MSG_BEGIN();
@@ -303,7 +310,7 @@ msg_error_t MmsRestoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char *pRcvBody, int rcvd
                MSG_DEBUG(":::%d :%s ",rcvdBodyLen, pRcvBody);
 
                if (filePath) {
-                       snprintf(filePath, MAX_FULL_PATH_SIZE, MSG_DATA_PATH"BODY_%lu.DATA", random() % 1000000000 + 1);
+                       snprintf(filePath, MAX_FULL_PATH_SIZE, "%sBODY_%lu.DATA", MSG_DATA_PATH, random() % 1000000000 + 1);
                } else {
                        return MSG_ERR_NULL_POINTER;
                }
index 17b223d..7aee565 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
 #include "MmsPluginDebug.h"
 #include "MmsPluginMessage.h"
 #include "MmsPluginMIME.h"
-#include "MmsPluginAvCodec.h"
 #include "MmsPluginStorage.h"
-#include "MmsPluginSMILValidate.h"
-#include "MmsPluginSmil.h"
 #include "MmsPluginUtil.h"
+#include "MmsPluginTcs.h"
+#include "MsgSmil.h"
+#include "MmsPluginAppBase.h"
 
 #define PRINT_KEY_VAL_STR(key, val)\
 if (val) {\
@@ -48,71 +48,78 @@ MSG_DEBUG("%-20s: %d", key, val);\
 }\
 
 static MsgMultipart *MmsGetNthMultipart(MmsMsg *pMsg, int index);
+static MsgMultipart *MmsMakeMultipart(MimeType mimeType, char *szTitleName, char *szOrgFilePath, char *szContentID, char *szContentLocation);
 static bool MmsSetMsgAddressList(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S *pMsgInfo);
 static char *MmsComposeAddress(const MSG_MESSAGE_INFO_S *pMsgInfo, int recipientType);
-static bool MmsGetSmilRawData(MMS_MESSAGE_DATA_S *pMsgBody, char *pRawData, int *nSize);
 static bool MmsInsertPresentation(MmsMsg *pMsg, MimeType mimeType, const char *content_id, char *pData, int size);
-static bool MmsInsertPartFromFile(MmsMsg *pMsg, char *szTitleName, char *szOrgFilePath, char *szContentID);
 static bool MmsInsertPartFromMultipart(MmsMsg *pMsg, MMS_MULTIPART_DATA_S *pNewMultipart);
-static bool MmsGetTypeByFileName(int *type, char *szFileName);
 static bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart);
+static bool MmsInsertMixedPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart);
+static void printMmsAttribute(MmsAttrib *pAttrib);
 
-bool MmsSetMsgAddressList(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S * pMsgInfo)
-{
-       MSG_DEBUG("MmsSetMsgAddressList");
-       pAttrib->szTo = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_TO);
-       MSG_DEBUG("To address: %s", pAttrib->szTo);
-       pAttrib->szCc = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_CC);
-       MSG_DEBUG("Cc address: %s", pAttrib->szCc);
-       pAttrib->szBcc = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_BCC);
-       MSG_DEBUG("Bcc address: %s", pAttrib->szBcc);
+bool convertMediaToMultipart(MMS_MEDIA_S *pSrcMedia, MMS_MULTIPART_DATA_S *pDestMultipart);
+bool convertAttachToMultipart(MMS_ATTACH_S *pSrcMedia, MMS_MULTIPART_DATA_S *pDestMultipart);
+MMSList * MmsConvertAddressToNewStyle(const char *szAddr);
+char *MmsConvertAddressToOldStyle(MMSList *pAddressList);
 
-       return true;
+void printMmsAttribute(MmsAttrib *pAttrib)
+{
+       MSG_ERR_RET_M(pAttrib == NULL, "attribute is NULL");
+
+       MSG_DEBUG("# LeaveCopy [%d]", pAttrib->bLeaveCopy);
+       MSG_DEBUG("# DeliveryTime type [%d], time [%d]", pAttrib->deliveryTime.type, pAttrib->deliveryTime.time);
+       MSG_DEBUG("# ExpiryTime type [%d], time [%d]", pAttrib->expiryTime.type, pAttrib->expiryTime.time);
+       MSG_DEBUG("# Priority [%d]", pAttrib->priority);
+       MSG_DEBUG("# AskDeliveryReport [%d]", pAttrib->bAskDeliveryReport);
+       MSG_DEBUG("# AskReadReply [%d]", pAttrib->bAskReadReply);
 }
 
-void MmsSetMsgMultiStatus(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S *pMsgInfo)
+bool MmsSetMsgAddressList(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S * pMsgInfo)
 {
-       int     nAddressCnt = 0;
+       MSG_BEGIN();
 
-       nAddressCnt = pMsgInfo->nAddressCnt;
+       pAttrib->szTo = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_TO);
+       if (pAttrib->szTo) {
+               MSG_SEC_DEBUG("To address: %s", pAttrib->szTo);
+       }
 
-       for (int i = 0; i < nAddressCnt; ++i) {
-               pAttrib->pMultiStatus = (MmsMsgMultiStatus *)malloc(sizeof(MmsMsgMultiStatus));
-
-               memset(pAttrib->pMultiStatus->szTo, 0, MAX_ADDRESS_VAL_LEN + 1);
-               strncpy(pAttrib->pMultiStatus->szTo, pMsgInfo->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
-
-               MSG_DEBUG("### pMultistatus->szTo = %s ####", pAttrib->pMultiStatus->szTo);
-               pAttrib->pMultiStatus->bDeliveryReportIsRead = false;
-               pAttrib->pMultiStatus->bDeliveyrReportIsLast = false;
-               pAttrib->pMultiStatus->msgStatus = MMS_MSGSTATUS_NONE;
-               pAttrib->pMultiStatus->handledTime = 0;
-               pAttrib->pMultiStatus->bReadReplyIsRead = false;
-               pAttrib->pMultiStatus->bReadReplyIsLast = false;
-               pAttrib->pMultiStatus->readStatus = MMS_READSTATUS_NONE;
-               pAttrib->pMultiStatus->readTime = 0;
-
-               pAttrib->pMultiStatus = pAttrib->pMultiStatus->pNext;
+       pAttrib->szCc = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_CC);
+       if (pAttrib->szCc) {
+               MSG_SEC_DEBUG("Cc address: %s", pAttrib->szCc);
+       }
+
+       pAttrib->szBcc = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_BCC);
+       if (pAttrib->szBcc) {
+               MSG_SEC_DEBUG("Bcc address: %s", pAttrib->szBcc);
        }
+
+       MSG_END();
+       return true;
 }
 
 char *MmsComposeAddress(const MSG_MESSAGE_INFO_S *pMsgInfo, int recipientType)
 {
-       MSG_DEBUG("MmsComposeAddress");
+       MSG_BEGIN();
        int     addrLen = 0;
        int     nAddressCnt = 0;
        int nRecpCnt = 0;
        char pString[MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3] = {0, };
        char *szCompose;
+       const char *typePlmn = "/TYPE=PLMN";
 
        nAddressCnt = pMsgInfo->nAddressCnt;
 
        // Calculate allocated buffer size
        for (int i = 0; i < nAddressCnt; ++i) {
-               MSG_DEBUG("recipientType: %d, address value: %s", pMsgInfo->addressList[i].recipientType, pMsgInfo->addressList[i].addressVal);
+
+               MSG_SEC_DEBUG("recipientType: %d, address value: %s", pMsgInfo->addressList[i].recipientType, pMsgInfo->addressList[i].addressVal);
+
+               if (pMsgInfo->addressList[i].recipientType == MSG_RECIPIENTS_TYPE_UNKNOWN)
+                       pMsgInfo->addressList[i].recipientType = MSG_RECIPIENTS_TYPE_TO;
+
                if (pMsgInfo->addressList[i].recipientType == recipientType) {
                        if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_PLMN) {
-                               addrLen += strlen(MsgGetString(MSG_ADDR_TYPE, MSG_ADDR_TYPE_PHONE));
+                               addrLen += strlen(typePlmn);
                                addrLen += strlen(pMsgInfo->addressList[i].addressVal);
                        } else if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_EMAIL) {
                                addrLen += strlen(pMsgInfo->addressList[i].addressVal);
@@ -131,49 +138,23 @@ char *MmsComposeAddress(const MSG_MESSAGE_INFO_S *pMsgInfo, int recipientType)
        for (int i = 0; i < nAddressCnt; ++i) {
                if (pMsgInfo->addressList[i].recipientType == recipientType) {
                        if (strlen(szCompose) > 0)
-                               strcat(szCompose, MSG_STR_ADDR_DELIMETER);
+                               g_strlcat(szCompose, MSG_STR_ADDR_DELIMETER, addrLen + 1);
 
                        memset(pString, 0x00, (MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3) * sizeof(char));
                        if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_PLMN) {
-                               snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s%s", pMsgInfo->addressList[i].addressVal, MsgGetString(MSG_ADDR_TYPE, MSG_ADDR_TYPE_PHONE));
+                               snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s%s", pMsgInfo->addressList[i].addressVal, typePlmn);
                                MSG_DEBUG("%s", pString);
                        } else if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_EMAIL) {
                                snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s", pMsgInfo->addressList[i].addressVal);
                        } else
                                ; // Need to consider IPV4, IPV6, and Alias formatted address
 
-                       strcat(szCompose, pString);
+                       g_strlcat(szCompose, pString, addrLen + 1);
                }
        }
 
-       return szCompose;
-}
-
-
-bool MmsGetMsgBodyfromMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, MMS_MESSAGE_DATA_S *pMsgBody, char *pFileData)
-{
-       MSG_DEBUG("MmsGetMsgBodyfromMsgInfo");
-       memset(pMsgBody, 0, sizeof(MMS_MESSAGE_DATA_S));
-
-       if (pMsgInfo->bTextSms == false) {       //if  the message body was stored in file.
-               _MsgMmsDeserializeMessageData(pMsgBody, pFileData);
-       }
-
-       return true;
-}
-
-bool MmsGetSmilRawData(MMS_MESSAGE_DATA_S *pMsgBody, char **pRawdata)
-{
-       MSG_BEGIN();
-
-       if (MsgReadSmilFile(pMsgBody->szSmilFilePath, pRawdata) < 0)
-               return false;
-
-       MsgDeleteSmilFile(pMsgBody->szSmilFilePath);
-
        MSG_END();
-
-       return true;
+       return szCompose;
 }
 
 bool MmsInsertPresentation(MmsMsg *pMsg, MimeType mimeType, const char *content_id, char *pData, int size)
@@ -234,214 +215,12 @@ __CATCH:
        return false;
 }
 
-bool MmsInsertPartFromFile(MmsMsg *pMsg, char *szTitleName, char *szOrgFilePath, char *szContentID)
-{
-       MSG_DEBUG("MmsInsertPartFromFile");
-
-       MsgMultipart *pMultipart = NULL;
-       MsgMultipart *pLastPart = NULL;
-       int nFileSize;
-       MimeType mimeType = MIME_UNKNOWN;
-       char *pExt = NULL;
-
-       pExt = strrchr(szOrgFilePath, '.');
-
-       if (pExt == NULL || pExt[0] == '\0' || strrchr(pExt, '/'))
-               mimeType = MIME_UNKNOWN;
-       else {
-               if (strcasecmp(pExt, ".dcf") == 0)
-                       mimeType = MIME_APPLICATION_VND_OMA_DRM_CONTENT;
-               else {
-                       if (MmsGetTypeByFileName((int *)&mimeType, szOrgFilePath) == false)
-                               goto __CATCH;
-               }
-       }
-
-       MSG_DEBUG("MmsInsertPartFromFile: type = %d, name = %s, filepath = %s, cid = %s", mimeType, szTitleName, szOrgFilePath, szContentID);
-
-       if (mimeType == MIME_UNKNOWN)
-               mimeType = MIME_APPLICATION_OCTET_STREAM;
-
-       if (MmsIsMultipart(pMsg->msgType.type) == true) {
-               /* Insert as a multipart */
-               if (MsgGetFileSize(szOrgFilePath, &nFileSize) == false) {
-                       MSG_DEBUG("MsgGetFileSize: failed");
-                       goto __CATCH;
-               }
-
-               pMultipart = MmsMakeMultipart(mimeType, szTitleName, szOrgFilePath, szContentID, NULL);
-               if (pMultipart == NULL)
-                       goto __CATCH;
-
-               if (pMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
-                       pMsg->mmsAttrib.contentType == MIME_MULTIPART_MIXED)
-                       pMultipart->type.disposition = MSG_DISPOSITION_ATTACHMENT;
-
-               if (pMsg->msgBody.body.pMultipart == NULL) {
-                       pMsg->msgBody.body.pMultipart = pMultipart;
-               } else {
-                       pLastPart = pMsg->msgBody.body.pMultipart;
-                       while (pLastPart->pNext) {
-                               pLastPart = pLastPart->pNext;
-                       }
-
-                       pLastPart->pNext = pMultipart;
-               }
-
-               pMsg->msgBody.size += pMultipart->pBody->size;
-               pMsg->msgType.contentSize += pMultipart->pBody->size;
-       } else {
-               /* Single part - Insert as a message body */
-               if (pMsg->mmsAttrib.contentType != mimeType || pMsg->msgType.type != mimeType)
-                       goto __CATCH;
-
-               strncpy(pMsg->msgType.param.szName, szTitleName, MSG_LOCALE_FILENAME_LEN_MAX);
-
-               if (MmsIsText(pMsg->msgType.type) == true) {
-                       pMsg->msgType.param.charset = MSG_CHARSET_UTF8;
-               }
-
-               strncpy(pMsg->msgBody.szOrgFilePath, szOrgFilePath, MSG_FILEPATH_LEN_MAX - 1);
-               if (MsgGetFileSize(szOrgFilePath, &nFileSize) == false) {
-                       MSG_DEBUG("MsgGetFileSize: failed");
-                       goto __CATCH;
-               }
-
-               pMsg->msgBody.offset = 0;
-               pMsg->msgBody.size = nFileSize;
-               pMsg->msgType.contentSize = nFileSize;
-       }
-
-       pMsg->nPartCount++;
-
-       return true;
-
-__CATCH:
-       return false;
-
-}
-
-bool MmsIsMultipart(int type)
-{
-       MSG_DEBUG("MmsIsMultipart");
-       if (type == MIME_MULTIPART_RELATED ||
-               type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
-               type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED ||
-               type == MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC ||
-               type == MIME_MULTIPART_MIXED ||
-               type == MIME_MULTIPART_REPORT) {
-               return true;
-       } else {
-               return false;
-       }
-}
-
-bool MmsIsText(int type)
-{
-       if (type == MIME_TEXT_PLAIN ||
-               type == MIME_TEXT_HTML ||
-               type == MIME_TEXT_VND_WAP_WML ||
-               type == MIME_TEXT_X_VCARD ||
-               type == MIME_TEXT_X_VCALENDAR ||
-               type == MIME_TEXT_X_VNOTE ||
-               type == MIME_APPLICATION_SMIL ||
-               type == MIME_TEXT_X_IMELODY) {
-               MSG_DEBUG("MmsIsText true.");
-               return true;
-       } else {
-               MSG_DEBUG("MmsIsText false.");
-               return false;
-       }
-}
-
-bool MmsIsVitemContent (int type, char *pszName)
-{
-       switch (type) {
-
-/*
-*      To make Encoding information right.
-*              case MIME_TEXT_X_VCARD :
-*              case MIME_TEXT_X_VCALENDAR :
-*              case MIME_TEXT_X_VNOTE :        // vnt
-*              {
-*                      MSG_DEBUG("MmsIsVitemContent true.");
-*                      return true;
-*              }
-*
-*/
-       case MIME_TEXT_X_VCARD:
-       case MIME_TEXT_X_VCALENDAR:
-       case MIME_TEXT_X_VNOTE: // vnt
-       case MIME_TEXT_PLAIN:           // vbm - It SHOULD be distinguished from a normal text file.
-               {
-                       char *pszExt = NULL;
-
-                       if (!pszName)
-                               break;
-
-                       // search file extension.
-                       if ((pszExt = strrchr(pszName, '.')) == NULL)
-                               break;
-
-                       if (!strcasecmp(pszExt, ".vbm")) {
-                               MSG_DEBUG("MmsIsVitemContent true.");
-                               return true;
-                       }
-               }
-               break;
-
-       default:
-               break;
-       }
-
-       MSG_DEBUG("MmsIsVitemContent false.");
-       return false;
-}
-
-
-
-MsgMultipart *MmsAllocMultipart(void)
-{
-       MsgMultipart *pMultipart = NULL;
-
-       pMultipart = (MsgMultipart *)malloc(sizeof(MsgMultipart));
-
-       if (pMultipart == NULL)
-               goto __CATCH;
-
-       pMultipart->pBody = (MsgBody *)malloc(sizeof(MsgBody));
-
-       if (pMultipart->pBody == NULL)
-               goto __CATCH;
-
-       MmsInitMsgType(&pMultipart->type);
-       MmsInitMsgBody(pMultipart->pBody);
-
-       pMultipart->pNext = NULL;
-
-       return pMultipart;
-
-__CATCH:
-
-       if (pMultipart) {
-               if (pMultipart->pBody) {
-                       free(pMultipart->pBody);
-                       pMultipart->pBody = NULL;
-               }
-
-               free(pMultipart);
-               pMultipart = NULL;
-       }
-
-       return NULL;
-}
-
 MsgMultipart *MmsMakeMultipart(MimeType mimeType, char *szTitleName, char *szOrgFilePath, char *szContentID, char *szContentLocation)
 {
        MsgMultipart *pMultipart = NULL;
 
        if ((pMultipart = MmsAllocMultipart()) == NULL)
-               return NULL;
+               goto __CATCH;
 
        pMultipart->type.type = mimeType;
 
@@ -460,7 +239,7 @@ MsgMultipart *MmsMakeMultipart(MimeType mimeType, char *szTitleName, char *szOrg
                snprintf(pMultipart->type.szContentLocation, MSG_MSG_ID_LEN + 1, "%s", szContentLocation);
        }
 
-       if (MmsIsText(mimeType) == true) {
+       if (MmsIsTextType(mimeType) == true) {
                if (!MmsIsVitemContent (mimeType, pMultipart->type.param.szName)) {
                        pMultipart->type.param.charset = MSG_CHARSET_UTF8;
                }
@@ -471,85 +250,80 @@ MsgMultipart *MmsMakeMultipart(MimeType mimeType, char *szTitleName, char *szOrg
 
        if (szOrgFilePath) {
                strncpy(pMultipart->pBody->szOrgFilePath, szOrgFilePath, MSG_FILEPATH_LEN_MAX - 1);
+               strncpy(pMultipart->type.szOrgFilePath, szOrgFilePath, MSG_FILEPATH_LEN_MAX - 1);
                pMultipart->pBody->offset = 0;
                pMultipart->pBody->size = MsgGetFileSize(szOrgFilePath);
        }
        return pMultipart;
+
+__CATCH:
+
+       return NULL;
 }
 
-bool MmsGetTypeByFileName(int *type, char *szFileName)
+void MmsComposeNotiMessage(MmsMsg *pMmsMsg, msg_message_id_t msgID)
 {
-       char *pExt   = NULL;
-       AvCodecType AvType = AV_CODEC_NONE;
+       MSG_BEGIN();
 
-       /* AVMS unknown or text/image file format identify type from file extention  */
+       struct tm *timeInfo = NULL;
+       time_t RawTime = 0;
+       time_t nTimeInSecs = 0;
 
-       pExt = strrchr(szFileName, '.');
-       if (pExt == NULL || pExt[0] == '\0')
-               goto __CATCH;
+       MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
+       MmsInitMsgType(&pMmsMsg->msgType);
+       MmsInitMsgBody(&pMmsMsg->msgBody);
 
-       pExt++;
+       pMmsMsg->msgID = msgID;
 
-       if (strcasecmp(pExt, "mp4") == 0 || strcasecmp(pExt, "mpeg4") == 0 ||
-               strcasecmp(pExt, "3gp") == 0 || strcasecmp(pExt, "3gpp") == 0) {
-               /* Audio / Video format. If file exists already, AvGetFileCodecType() can identify the format  */
-               if (szFileName[0] != '/')
-                       goto __CATCH;
+       pMmsMsg->mmsAttrib.version = mmsHeader.version;
 
-               AvType = AvGetFileCodecType(szFileName);
+       // setting date
+       time(&RawTime);
+       timeInfo = localtime(&RawTime);
+       nTimeInSecs = mktime(timeInfo);
+       pMmsMsg->mmsAttrib.date = nTimeInSecs;
 
-               switch (AvType) {
-               case AV_DEC_AUDIO_MPEG4:
-                       *type = MIME_AUDIO_MP4;//*type = MIME_AUDIO_3GPP;
-                       break;
+       pMmsMsg->mmsAttrib.bReportAllowed = mmsHeader.reportAllowed;
+       pMmsMsg->mmsAttrib.bAskDeliveryReport = mmsHeader.deliveryReport;
 
-               case AV_DEC_VIDEO_MPEG4:
-                       *type = MIME_VIDEO_MP4;
-                       break;
+       MSG_DEBUG("######## Version = %d ########", pMmsMsg->mmsAttrib.version);
 
-               default:
-                       *type = MIME_VIDEO_3GPP;
-                       break;
-               }
-               return true;
-       }
+       strncpy(pMmsMsg->szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
+       strncpy(pMmsMsg->szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
+       pMmsMsg->szForwardMsgID[0] = '\0';
 
-       if (strcasecmp(pExt, "amr") == 0) {
-               *type = MIME_AUDIO_AMR;
-               return true;
-       } else if ((strcasecmp(pExt, "mid") == 0) || (strcasecmp(pExt, "midi") == 0)) {
-               *type = MIME_AUDIO_MIDI;
-               return true;
-       } else if (strcasecmp(pExt, "imy") == 0) {
-               *type = MIME_TEXT_X_IMELODY;
-               return true;
+       if (mmsHeader.pFrom) {
+               MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr );
+               strncpy(pMmsMsg->mmsAttrib.szFrom, mmsHeader.pFrom->szAddr, MSG_LOCALE_ADDR_LEN + 9);
        }
 
-       *type = MimeGetMimeFromExtInt((const char *)pExt);
+       strncpy(pMmsMsg->mmsAttrib.szSubject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
+       strncpy(pMmsMsg->szContentLocation, mmsHeader.szContentLocation, MMS_LOCATION_LEN);
 
-       return true;
+       pMmsMsg->mmsAttrib.msgClass = mmsHeader.msgClass;
+       pMmsMsg->mmsAttrib.msgSize = mmsHeader.msgSize;
+       pMmsMsg->mmsAttrib.expiryTime.type = mmsHeader.expiryTime.type;
+       pMmsMsg->mmsAttrib.expiryTime.time = mmsHeader.expiryTime.time;
+       pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_NOTIFY;
+       pMmsMsg->mmsAttrib.bRead = false;
+       pMmsMsg->mailbox = MSG_INBOX_ID;
 
-__CATCH:
+       pMmsMsg->mmsAttrib.replyCharge.chargeType = mmsHeader.replyCharge.chargeType;
+       pMmsMsg->mmsAttrib.replyCharge.deadLine.type = mmsHeader.replyCharge.deadLine.type;
+       pMmsMsg->mmsAttrib.replyCharge.deadLine.time = mmsHeader.replyCharge.deadLine.time;
+       pMmsMsg->mmsAttrib.replyCharge.chargeSize = mmsHeader.replyCharge.chargeSize;
 
-       *type = MIME_UNKNOWN;
-       return false;
+       strncpy(pMmsMsg->mmsAttrib.replyCharge.szChargeID, mmsHeader.replyCharge.szChargeID, MMS_MSG_ID_LEN);
 
+       MSG_END();
 }
 
-bool MmsComposeMessage(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMsgData, char *pFileData)
+void MmsComposeReadReportMessage(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, msg_message_id_t selectedMsgId)
 {
-       MSG_BEGIN();
-
-       char *pRawData = NULL;
-       AutoPtr<char> buf(&pRawData);
-
        struct tm *timeInfo = NULL;
        time_t RawTime = 0;
        time_t nTimeInSecs = 0;
 
-       msg_error_t     err = MSG_SUCCESS;
-
-       // Initialize mmsMsg structure
        MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
        MmsInitMsgType(&pMmsMsg->msgType);
        MmsInitMsgBody(&pMmsMsg->msgBody);
@@ -560,441 +334,76 @@ bool MmsComposeMessage(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDIN
 
        memset(pMmsMsg->szTrID, 0, MMS_TR_ID_LEN + 1);
        memset(pMmsMsg->szContentLocation, 0, MMS_LOCATION_LEN + 1);
-       memset(pMmsMsg->szMsgID, 0, MMS_MSG_ID_LEN + 1);
        memset(pMmsMsg->szForwardMsgID, 0, MMS_MSG_ID_LEN + 1);
 
        pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_DRAFT;
 
-       MSG_DEBUG("## delivery = %d ##", pSendOptInfo->bDeliverReq);
-       MSG_DEBUG("## read = %d ##", pSendOptInfo->option.mmsSendOptInfo.bReadReq);
-       MSG_DEBUG("## priority = %d ##", pSendOptInfo->option.mmsSendOptInfo.priority);
-       MSG_DEBUG("## expiryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.expiryTime.time);
-
-       if (pSendOptInfo->bSetting == false) {
-               unsigned int expiryTime;
-               MSG_MMS_DELIVERY_TIME_T deliveryTime;
-
-               pMmsMsg->mmsAttrib.priority = (MmsPriority)MsgSettingGetInt(MMS_SEND_PRIORITY);
-
-               MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pMmsMsg->mmsAttrib.bAskDeliveryReport);
-               MsgSettingGetBool(MMS_SEND_READ_REPLY, &pMmsMsg->mmsAttrib.bAskReadReply);
-               MsgSettingGetBool(MSG_KEEP_COPY, &pMmsMsg->mmsAttrib.bLeaveCopy);
-
-               expiryTime = (unsigned int)MsgSettingGetInt(MMS_SEND_EXPIRY_TIME);
-
-               if (expiryTime == 0)
-                       pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_NONE;
-               else {
-                       pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_RELATIVE;
-                       pMmsMsg->mmsAttrib.expiryTime.time = expiryTime;
-               }
-
-               deliveryTime = (MSG_MMS_DELIVERY_TIME_T)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
-
-               if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
-                       pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = true;
-
-                       pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
-                       pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY);
-               } else {
-                       pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = false;
-
-                       pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
-                       pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)deliveryTime;
-               }
-       } else {
-               pMmsMsg->mmsAttrib.priority = (MmsPriority)pSendOptInfo->option.mmsSendOptInfo.priority;
-               pMmsMsg->mmsAttrib.bAskDeliveryReport = pSendOptInfo->bDeliverReq;
-               pMmsMsg->mmsAttrib.bAskReadReply = pSendOptInfo->option.mmsSendOptInfo.bReadReq;
-               pMmsMsg->mmsAttrib.expiryTime.type = pSendOptInfo->option.mmsSendOptInfo.expiryTime.type;
-               pMmsMsg->mmsAttrib.bLeaveCopy = pSendOptInfo->bKeepCopy;
-
-               if (pMmsMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE)
-                       pMmsMsg->mmsAttrib.expiryTime.time = pSendOptInfo->option.mmsSendOptInfo.expiryTime.time;
-
-               pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime;
-               pMmsMsg->mmsAttrib.deliveryTime.type = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.type;
-               pMmsMsg->mmsAttrib.deliveryTime.time = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time;
-       }
-
-       MSG_DEBUG("pSendOptInfo->bSetting = %d", pSendOptInfo->bSetting);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.bLeaveCopy = %d", pMmsMsg->mmsAttrib.bLeaveCopy);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = %d", pMmsMsg->mmsAttrib.bUseDeliveryCustomTime);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.type = %d", pMmsMsg->mmsAttrib.deliveryTime.type);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.time = %d", pMmsMsg->mmsAttrib.deliveryTime.time);
-
-       /* MMS-1.3-con-739 */
-       pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)MsgSettingGetInt(MMS_SEND_MSG_CLASS);
-       /* MMS-1.3-con-739 */
-#ifdef MMS_13_CON_742_ENABLED
-       /* MMS-1.3-con-742 */
-       pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
-       /* MMS-1.3-con-742 */
-#endif
-
-       MSG_DEBUG("@@@ pMmsMsg->mmsAttrib.bAskDeliveryReport = %d @@@", pMmsMsg->mmsAttrib.bAskDeliveryReport);
-       MSG_DEBUG("@@@ pMmsMsg->mmsAttrib.bAskReadReply = %d @@@", pMmsMsg->mmsAttrib.bAskReadReply);
-       MSG_DEBUG("@@@ pMmsMsg->mmsAttrib.priority = %d @@@", pMmsMsg->mmsAttrib.priority);
-
        // setting date
        time(&RawTime);
        timeInfo = localtime(&RawTime);
        nTimeInSecs = mktime(timeInfo);
-       pMmsMsg->mmsAttrib.date = nTimeInSecs;  // todo: need to subtract timeline value to make GMT+0 time
+       pMmsMsg->mmsAttrib.date = nTimeInSecs;
+
+       // setting szMsgId
+       MmsPluginStorage::instance()->getMmsMessageId(selectedMsgId, pMmsMsg);
 
        //setting subject
-       strcpy(pMmsMsg->mmsAttrib.szSubject, pMsgInfo->subject);
+       snprintf(pMmsMsg->mmsAttrib.szSubject, sizeof(pMmsMsg->mmsAttrib.szSubject), "%s", pMsgInfo->subject);
 
        //setting adddress
        MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
-       //MmsGetMsgBodyfromMsgInfo(pMsgInfo, pMsgData, pFileData);
 
-       int pageCnt = _MsgMmsGetPageCount(pMsgData);
+       if (pMmsMsg->mmsAttrib.szTo)
+               strncpy(pMmsMsg->mmsAttrib.szFrom, pMmsMsg->mmsAttrib.szTo, strlen(pMmsMsg->mmsAttrib.szTo));
+}
+
+msg_error_t MmsMakeMultipartThumbnailInfo(MMS_MULTIPART_DATA_S *pMultipart, char *thumbnail_path)
+{
+       if (pMultipart == NULL || thumbnail_path == NULL)
+               return MSG_ERR_NULL_POINTER;
 
-       if (pageCnt == 0) {     // Multipart mixed
-               pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
-               pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
-               MmsMakePreviewInfo(pMsgInfo->msgId, pMsgData);
-       } else {        // Multipart related
+//     if (MimeGetMainTypeString(MimeGetMimeStringFromMimeInt(pMultipart->type)) != MIME_MAINTYPE_VIDEO)
+//             return MSG_ERR_INVALID_PARAMETER;
 
-               int RawDataSize = 0;
+       char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
+       char szFileNameWoExt[MSG_FILENAME_LEN_MAX+1] = {0, };
+       char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
+       char *pszExt = NULL;
+       char *pszOrgFileName = NULL;
 
-               time_t RawTime = 0;
-               time(&RawTime);
-               snprintf(pMsgData->szSmilFilePath, MSG_FILEPATH_LEN_MAX, "%lu", RawTime);
+       memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
+       memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
 
-               MsgMMSCreateSMIL(pMsgData);
+       MSG_DEBUG("drm type = %d, %s", pMultipart->drmType, pMultipart->szFilePath);
 
-               RawDataSize = MmsGetSmilRawData(pMsgData, &pRawData);
-               if (RawDataSize < 0) {
-                       MSG_DEBUG("Smil file size is less than 0");
-                       return false;
-               }
-               MSG_DEBUG("%s", pRawData);
-               if (pRawData)
-                       MmsInsertPresentation(pMmsMsg, MIME_APPLICATION_SMIL, NULL, pRawData, strlen(pRawData));
-
-               pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
-               pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
-
-               for (int i = 0; i < pageCnt; ++i) {
-                       MMS_PAGE_S *pPage = _MsgMmsGetPage(pMsgData, i);
-                       int mediaCnt = pPage->mediaCnt;
-                       MSG_DEBUG("PAGE %d's media Cnt: %d", i+1, mediaCnt);
-
-                       for (int j = 0; j < mediaCnt; ++j) {
-                               MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
-
-                               switch (pMedia->mediatype) {
-                               case MMS_SMIL_MEDIA_IMG:
-                               case MMS_SMIL_MEDIA_VIDEO:
-                               case MMS_SMIL_MEDIA_AUDIO:
-                               case MMS_SMIL_MEDIA_TEXT:
-                                       if (pMedia->szFilePath[0] != 0) {
-                                               if (!MmsInsertPartFromFile(pMmsMsg, pMedia->szFileName, pMedia->szFilePath, pMedia->szContentID))
-                                                       return false;
-                                       }
-                                       break;
+       if (pMultipart->drmType == MSG_DRM_TYPE_NONE) {
+               pszOrgFileName = strrchr(pMultipart->szFilePath, '/');
+               pszExt = strrchr(pMultipart->szFilePath, '.');
 
-                               default:
-                                       break;
-                               }
-                       }
+               if (NULL == pszOrgFileName || NULL == pszExt) {
+                       MSG_DEBUG("Fail in getting filename without extension string");
+                       return MSG_ERR_PLUGIN_STORAGE;
                }
 
-               char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };;
-               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms", pMsgInfo->msgId);
+               strncpy(szFileNameWoExt, pszOrgFileName + 1, strlen(pszOrgFileName + 1) - strlen(pszExt));
+               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "thumb_msg_%s", szFileNameWoExt);
 
-               MmsPluginStorage *pStorage = MmsPluginStorage::instance();
-               err = pStorage->getMsgText(pMsgData, pMsgInfo->msgText);
-               MmsMakePreviewInfo(pMsgInfo->msgId, pMsgData);
-       }
-
-#ifdef FEATURE_JAVA_MMS
-       MSG_DEBUG("msgAppId: valid:%d appId:%s replyToAppId:%s", pMsgData->msgAppId.valid, pMsgData->msgAppId.appId, pMsgData->msgAppId.replyToAppId);
-       if (pMsgData->msgAppId.valid) { // check if msgAppId.valid is true, both appId and replytoappId must have a meaning data
-               if (pMsgData->msgAppId.appId[0] != 0) {
-                       pMmsMsg->msgType.param.szApplicationID = (char *)malloc(strlen(pMsgData->msgAppId.appId) + 1);
-                       if (pMmsMsg->msgType.param.szApplicationID == NULL) {
-                               MSG_DEBUG("Error: out of Memory");
-                               return false;
-                       }
-                       memset(pMmsMsg->msgType.param.szApplicationID, 0, strlen(pMsgData->msgAppId.appId) + 1);
+               if (!strcasecmp(pszExt, ".png")) {
+                       snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, MSG_THUMBNAIL_PATH"%s.png", szFileName);
+               } else {
+                       snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, MSG_THUMBNAIL_PATH"%s.jpg", szFileName);
+               }
 
-                       strcpy(pMmsMsg->msgType.param.szApplicationID, pMsgData->msgAppId.appId);
+               if (MmsMakeImageThumbnail(pMultipart->szFilePath, thumbPath) == true) {
+                       memcpy(thumbnail_path, &thumbPath, strlen(thumbPath));
+                       MSG_DEBUG("Generated thumbnail: %s ", thumbnail_path);
+                       return MSG_SUCCESS;
+               } else {
+                       MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMultipart->szFilePath, thumbPath);
                }
+       }
 
-               if (pMsgData->msgAppId.replyToAppId[0] != 0) {
-                       pMmsMsg->msgType.param.szReplyToApplicationID = (char *)malloc(strlen(pMsgData->msgAppId.replyToAppId) + 1);
-                       if (pMmsMsg->msgType.param.szReplyToApplicationID == NULL) {
-                               MSG_DEBUG("Error: out of Memory");
-                               return false;
-                       }
-                       memset(pMmsMsg->msgType.param.szReplyToApplicationID, 0, strlen(pMsgData->msgAppId.replyToAppId) + 1);
-
-                       strcpy(pMmsMsg->msgType.param.szReplyToApplicationID, pMsgData->msgAppId.replyToAppId);
-               }
-       }
-#endif
-
-       //Processing Attachment List
-       for (int i = 0; i < _MsgMmsGetAttachCount(pMsgData); ++i) {
-               MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pMsgData, i);
-               if (pMedia->szFilePath[0] != 0) {
-                       if (!MmsInsertPartFromFile(pMmsMsg, pMedia->szFileName, pMedia->szFilePath, NULL)) {
-                               free(pMedia);
-                               return false;
-                       }
-               }
-       }
-
-       return true;
-}
-
-void MmsComposeNotiMessage(MmsMsg *pMmsMsg, msg_message_id_t msgID)
-{
-       MSG_BEGIN();
-
-       struct tm *timeInfo = NULL;
-       time_t RawTime = 0;
-       time_t nTimeInSecs = 0;
-
-       MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
-       MmsInitMsgType(&pMmsMsg->msgType);
-       MmsInitMsgBody(&pMmsMsg->msgBody);
-
-       pMmsMsg->msgID = msgID;
-
-       pMmsMsg->mmsAttrib.version = mmsHeader.version;
-
-       // setting date
-       time(&RawTime);
-       timeInfo = localtime(&RawTime);
-       nTimeInSecs = mktime(timeInfo);
-       pMmsMsg->mmsAttrib.date = nTimeInSecs;
-
-       pMmsMsg->mmsAttrib.bReportAllowed = mmsHeader.reportAllowed;
-       pMmsMsg->mmsAttrib.bAskDeliveryReport = mmsHeader.deliveryReport;
-
-       MSG_DEBUG("######## Version = %d ########", pMmsMsg->mmsAttrib.version);
-
-       strncpy(pMmsMsg->szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
-       strncpy(pMmsMsg->szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
-       pMmsMsg->szForwardMsgID[0] = '\0';
-
-       if (mmsHeader.pFrom) {
-               MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr );
-               strncpy(pMmsMsg->mmsAttrib.szFrom, mmsHeader.pFrom->szAddr, MSG_LOCALE_ADDR_LEN + 9);
-       }
-
-       strncpy(pMmsMsg->mmsAttrib.szSubject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
-       strncpy(pMmsMsg->szContentLocation, mmsHeader.szContentLocation, MMS_LOCATION_LEN);
-
-       pMmsMsg->mmsAttrib.msgClass = mmsHeader.msgClass;
-       pMmsMsg->mmsAttrib.msgSize = mmsHeader.msgSize;
-       pMmsMsg->mmsAttrib.expiryTime.type = mmsHeader.expiryTime.type;
-       pMmsMsg->mmsAttrib.expiryTime.time = mmsHeader.expiryTime.time;
-       pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_NOTIFY;
-       pMmsMsg->mmsAttrib.bRead = false;
-       pMmsMsg->mailbox = MSG_INBOX_ID;
-
-       pMmsMsg->mmsAttrib.replyCharge.chargeType = mmsHeader.replyCharge.chargeType;
-       pMmsMsg->mmsAttrib.replyCharge.deadLine.type = mmsHeader.replyCharge.deadLine.type;
-       pMmsMsg->mmsAttrib.replyCharge.deadLine.time = mmsHeader.replyCharge.deadLine.time;
-       pMmsMsg->mmsAttrib.replyCharge.chargeSize = mmsHeader.replyCharge.chargeSize;
-
-       strncpy(pMmsMsg->mmsAttrib.replyCharge.szChargeID, mmsHeader.replyCharge.szChargeID, MMS_MSG_ID_LEN);
-
-       MSG_END();
-}
-
-void MmsComposeReadReportMessage(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, msg_message_id_t selectedMsgId)
-{
-       struct tm *timeInfo = NULL;
-       time_t RawTime = 0;
-       time_t nTimeInSecs = 0;
-
-       MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
-       MmsInitMsgType(&pMmsMsg->msgType);
-       MmsInitMsgBody(&pMmsMsg->msgBody);
-
-       // setting mmsMsg structure
-       pMmsMsg->mailbox = pMsgInfo->folderId;
-       pMmsMsg->msgID = pMsgInfo->msgId;
-
-       memset(pMmsMsg->szTrID, 0, MMS_TR_ID_LEN + 1);
-       memset(pMmsMsg->szContentLocation, 0, MMS_LOCATION_LEN + 1);
-       memset(pMmsMsg->szForwardMsgID, 0, MMS_MSG_ID_LEN + 1);
-
-       pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_DRAFT;
-
-       // setting date
-       time(&RawTime);
-       timeInfo = localtime(&RawTime);
-       nTimeInSecs = mktime(timeInfo);
-       pMmsMsg->mmsAttrib.date = nTimeInSecs;
-
-       // setting szMsgId
-       MmsPluginStorage::instance()->getMmsMessageId(selectedMsgId, pMmsMsg);
-
-       //setting subject
-       strcpy(pMmsMsg->mmsAttrib.szSubject, pMsgInfo->subject);
-
-       //setting adddress
-       MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
-
-       if (pMmsMsg->mmsAttrib.szTo)
-               strncpy(pMmsMsg->mmsAttrib.szFrom, pMmsMsg->mmsAttrib.szTo, strlen(pMmsMsg->mmsAttrib.szTo));
-}
-
-bool MmsFindMatchedMedia(MMS_MESSAGE_DATA_S *pMsgData, char *pszFilePath)
-{
-       if (pMsgData == NULL || pszFilePath == NULL)
-               return false;
-
-       if (pMsgData->pagelist) {
-               for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
-                       MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
-
-                       if (page && page->medialist) {
-                               for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
-                                       MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
-                                       if (media) {
-                                               if (strcmp(pszFilePath, media->szFilePath) == 0)
-                                                       return true;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       return false;
-}
-
-bool MmsCheckAdditionalMedia(MMS_MESSAGE_DATA_S *pMsgData, MsgType *partHeader)
-{
-       if (MmsFindMatchedMedia(pMsgData, partHeader->param.szFileName))
-               return false;
-       else
-               return true;
-}
-
-/*PIM objects SHALL be supported as attachments to an MM*/
-bool MmsRemovePims(MMS_MESSAGE_DATA_S *pMsgData)
-{
-       GList *cur_page = NULL;
-       GList *cur_media = NULL;
-
-       if (pMsgData == NULL)
-               return false;
-
-       cur_page = pMsgData->pagelist;
-
-       while(cur_page) {
-               MMS_PAGE_S *page = (MMS_PAGE_S *)cur_page->data;
-               if (page) {
-                       cur_media = page->medialist;
-
-                       while(cur_media) {
-                               MMS_MEDIA_S *pMedia = (MMS_MEDIA_S *)cur_media->data;
-                               if (pMedia) {
-                                       int tempType;
-                                       MsgGetTypeByFileName(&tempType, pMedia->szFilePath);
-                                       if (tempType == MIME_TEXT_X_VCALENDAR || tempType == MIME_TEXT_X_VCARD) {
-                                               page->medialist = g_list_remove_all(page->medialist, pMedia);
-                                               page->mediaCnt = g_list_length(page->medialist);
-                                               cur_media = page->medialist;
-                                               free(pMedia);
-                                       } else {
-                                               cur_media =  g_list_next(cur_media);
-                                       }
-                               } else {
-                                       cur_media =  g_list_next(cur_media);
-                               }
-                       } //cur_media while for remove pims file in list
-
-                       if (page->medialist == NULL) {//remove empty page
-                               pMsgData->pagelist = g_list_remove_all(pMsgData->pagelist, page);
-                               pMsgData->pageCnt = g_list_length(pMsgData->pagelist);
-                               cur_page = pMsgData->pagelist;
-                               free(page);
-                       } else {
-                               cur_page =  g_list_next(cur_page);
-                       }
-               }
-       }//cur_page while
-
-
-       return true;
-}
-
-msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg)
-{
-       MMS_PAGE_S *pPage = NULL;
-       MMS_MEDIA_S *pMedia = NULL;
-
-       if (pMmsMsg == NULL)
-               return MSG_ERR_NULL_POINTER;
-
-       MmsPluginStorage::instance()->removePreviewInfo(msgId); //remove exist previnfo
-
-       if (pMmsMsg->pageCnt > 0) {
-
-               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
-
-               pPage = _MsgMmsGetPage(pMmsMsg, 0);
-               for (int j = 0; j < pPage->mediaCnt; j++) {
-
-                       pMedia = _MsgMmsGetMedia(pPage, j);
-                       MSG_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
-
-                       if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
-                               char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
-                               char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
-                               char *pszExt = NULL;
-
-                               memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
-                               memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
-
-                               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
-
-                               if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
-                                       snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, MSG_THUMBNAIL_PATH"/%s.png", szFileName);
-                               } else {
-                                       snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, MSG_THUMBNAIL_PATH"/%s.jpg", szFileName);
-                               }
-
-                               if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
-                                       if (makeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
-                                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
-                                       } else {
-                                               MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
-                                       }
-                               } else {
-                                       if (makeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
-                                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
-                                       } else {
-                                               MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
-                                       }
-                               }
-
-                       } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
-                               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
-                       }
-               }
-       } else {
-               MSG_DEBUG("There is no page");
-       }
-
-       int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
-       if (attachCnt > 0) {
-               MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
-               MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
-       } else {
-               MSG_DEBUG("There is no attachment");
-       }
-
-       return MSG_SUCCESS;
+       return MSG_ERR_PLUGIN_STORAGE;
 }
 
 void MmsPrintFileInfoForVLD(MMS_MESSAGE_DATA_S *pMmsMsg)
@@ -1033,42 +442,34 @@ void MmsPrintFileInfoForVLD(MMS_MESSAGE_DATA_S *pMmsMsg)
        }
 }
 
-MMS_MEDIA_S *MmsFindMediaWithCID(MMS_MESSAGE_DATA_S *pMsgData, const char *szContentID)
+bool IsMatchedMedia(MMS_MEDIA_S *media, MMS_MULTIPART_DATA_S *pMultipart)
 {
+       if (strlen(pMultipart->szContentID) > 0) {
 
-       if (pMsgData == NULL || szContentID == NULL || strlen(szContentID) == 0) {
-               MSG_DEBUG("Invalid Parameter pMsgData = %p, szContentID = %p", pMsgData, szContentID);
-               return NULL;
-       }
-
-       if (pMsgData->pagelist) {
-               for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
-
-                       MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
-
-                       if (page && page->medialist) {
+               char szTempContentID[MSG_MSG_ID_LEN + 1] = {0,};
+               MmsRemoveLessGreaterChar(pMultipart->szContentID, szTempContentID, sizeof(szTempContentID));
 
-                               for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
+               if (strcmp(media->szContentID,  szTempContentID) == 0) {
+                       return true;
+               }
 
-                                       MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
+               if (strcmp(media->szContentLocation,  szTempContentID) == 0) {
+                       return true;
+               }
+       }
 
-                                       if (media) {
-                                               if (strcmp(media->szContentID,  szContentID) == 0) {
-                                                       MSG_DEBUG("Find media with Content ID [%s] from pMsgData", szContentID);
-                                                       return media;
-                                               }
+       if (strlen(pMultipart->szContentLocation) > 0) {
+               if (strcmp(media->szContentID,  pMultipart->szContentLocation) == 0) {
+                       return true;
+               }
 
-                                       } else {
-                                               MSG_DEBUG("Error media NULL");
-                                               return NULL;
-                                       }
-                               } //end for media list
-                       }
-               } //end for page list
+               if (strcmp(media->szContentLocation,  pMultipart->szContentLocation) == 0) {
+                       return true;
+               }
        }
 
-       MSG_DEBUG("Not exist Matched media with [%s]", szContentID);
-       return NULL;
+       MSG_DEBUG("There is not matched media cid [%s], cl, [%s], multipart cid [%s], cl, [%s]", media->szContentID, media->szContentLocation, pMultipart->szContentID, pMultipart->szContentLocation);
+       return false;
 }
 
 MsgMultipart *MmsGetNthMultipart(MmsMsg *pMsg, int index)
@@ -1096,151 +497,175 @@ MsgMultipart *MmsGetNthMultipart(MmsMsg *pMsg, int index)
        return NULL;
 }
 
-bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
+bool MmsFindAndInsertPart(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
 {
-       MMS_MEDIA_S * match_media = NULL;
-       bool isPimsFile = false;
-       int tempType;//MimeType
+       bool insert_media = false;
 
-       if (pMsgData == NULL || pMultipart == NULL) {
-               return false;
-       }
+       if (pMsgData->pagelist) {
+               for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
 
-       //for pims file add to attach
-       MsgGetTypeByFileName(&tempType, pMultipart->szFilePath);
-       if (tempType == MIME_TEXT_X_VCALENDAR || tempType == MIME_TEXT_X_VCARD) {
-               MSG_DEBUG("Pims File");
-               isPimsFile = true;
-       } else {
+                       MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
+
+                       if (page && page->medialist) {
+
+                               for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
+
+                                       MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
+
+                                       if (media) { // add media
+                                               if (IsMatchedMedia(media, pMultipart) == true) { //matched media
 
-               if (strlen(pMultipart->szContentID) > 0) {
-                       char szTempContentID[MSG_MSG_ID_LEN + 1] = {0,};
-                       removeLessGreaterMark(pMultipart->szContentID, szTempContentID, sizeof(szTempContentID));
-                       match_media = MmsFindMediaWithCID(pMsgData, szTempContentID);
+//                                                     if (media->mediatype == MMS_SMIL_MEDIA_IMG_OR_VIDEO) { // ref type is not insert part
+//                                                             MSG_DEBUG("## Matched but media type is ref ##");
+//                                                             return false;
+//                                                     }
 
-                       if (match_media == NULL && strlen(pMultipart->szContentLocation) > 0 ) {
-                               match_media = MmsFindMediaWithCID(pMsgData, pMultipart->szContentLocation);
+                                                       insert_media = true;
+                                                       media->drmType = pMultipart->drmType;
+                                                       snprintf(media->szFilePath, sizeof(media->szFilePath), "%s", pMultipart->szFilePath);
+                                                       snprintf(media->szFileName, sizeof(media->szFileName), "%s", pMultipart->szFileName);
+                                                       snprintf(media->szContentID, sizeof(media->szContentID), "%s", pMultipart->szContentID);
+                                                       snprintf(media->szContentLocation, sizeof(media->szContentLocation), "%s", pMultipart->szContentLocation);
+                                                       snprintf(media->szContentType, sizeof(media->szContentType), "%s", pMultipart->szContentType);
+
+                                                       MSG_SEC_DEBUG("InsertPart to pageIndx [%d] mediaIdx[%d] media[%p] : path = [%s], name = [%s], cid = [%s], cl = [%s], ct = [%s]"\
+                                                                       , pageIdx, mediaIdx, media, media->szFilePath, media->szFileName, media->szContentID, media->szContentLocation, media->szContentType);
+                                               }
+                                       }
+                               } //end for media list
                        }
+               } //end for page list
+       }
 
-               } else {
-                       MSG_DEBUG("ContentID is NULL");
-                       match_media = NULL;
-               }
+       return insert_media;
+}
 
+bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       MSG_BEGIN();
+
+       bool isInsert = false;
+
+       if (pMsgData == NULL || pMultipart == NULL) {
+               return false;
        }
 
-       if (match_media && isPimsFile == false) { // set file path
-               snprintf(match_media->szFilePath, sizeof(match_media->szFilePath), "%s", pMultipart->szFilePath);
-               snprintf(match_media->szFileName, sizeof(match_media->szFileName), "%s", pMultipart->szFileName);
-               snprintf(match_media->szContentID, sizeof(match_media->szContentID), "%s", pMultipart->szContentID);
-               snprintf(match_media->szContentLocation, sizeof(match_media->szContentLocation), "%s", pMultipart->szContentLocation);
-               snprintf(match_media->szContentType, sizeof(match_media->szContentType), "%s", pMultipart->szContentType);
-       } else { // add attach
+       isInsert = MmsFindAndInsertPart(pMsgData, pMultipart);
 
+       if (isInsert == false) {
                MMS_ATTACH_S *attachment = NULL;
                attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
+               attachment->drmType = pMultipart->drmType;
+
+               if (strlen(pMultipart->szContentType) > 0) {
+                       snprintf(attachment->szContentType, sizeof(attachment->szContentType), "%s", pMultipart->szContentType);
+                       attachment->mediatype =  pMultipart->type;
+               }
 
-               attachment->mediatype = (MimeType)tempType;
-               snprintf(attachment->szContentType, sizeof(attachment->szContentType), "%s", pMultipart->szContentType);
                snprintf(attachment->szFilePath, sizeof(attachment->szFilePath), "%s", pMultipart->szFilePath);
                snprintf(attachment->szFileName, sizeof(attachment->szFileName), "%s", pMultipart->szFileName);
                attachment->fileSize = MsgGetFileSize(attachment->szFilePath);
 
+               MSG_SEC_DEBUG("Insert Attach to attachment[%p] : path = [%s], name = [%s], ct = [%s], size = [%d]"\
+                                               , attachment, attachment->szFilePath, attachment->szFileName, attachment->szContentType, attachment->fileSize);
+
                if (_MsgMmsAddAttachment(pMsgData, attachment) != MSG_SUCCESS) {
                        g_free(attachment);
                        return false;
                }
        }
 
+       MSG_END();
        return true;
 }
 
-bool MmsEncodeMmsMessage(MmsMsg *pMmsMsg, const char *raw_filepath)
+bool MmsInsertMixedPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
 {
-       bool encode_ret = false;
-       mode_t file_mode = (S_IRUSR | S_IWUSR);
+       MSG_BEGIN();
 
-       if (pMmsMsg == NULL || raw_filepath == NULL) {
-               MSG_DEBUG("Invalid Parameter pMmsMsg = %p , raw_filepath = %p", pMmsMsg, raw_filepath);
+       if (pMsgData == NULL || pMultipart == NULL) {
                return false;
        }
 
-       FILE *pFile = MsgOpenFile(raw_filepath, "wb+");
-
-       if (pFile == NULL) {
-               MSG_FATAL("File Open Error: %s", strerror(errno));
-               goto __CATCH;
-       }
-
-       if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
-               MSG_DEBUG("File Fseek Error: %s", strerror(errno));
-               goto __CATCH;
-       }
+       MimeMainType mainType = MimeGetMainTypeInt(pMultipart->type);
+       MmsSmilMediaType mediatype = MMS_SMIL_MEDIA_INVALID;
 
-       if (fchmod(fileno(pFile), file_mode) < 0) {
-               MSG_DEBUG("File chmod Error: %s", strerror(errno));
-               goto __CATCH;
-       }
-
-       switch(pMmsMsg->mmsAttrib.msgType)
-       {
-               case MMS_MSGTYPE_SEND_REQ:
-               case MMS_MSGTYPE_SEND_CONF:
-                       encode_ret = MmsEncodeSendReq(pFile, pMmsMsg);
-                       if (encode_ret == false) {
-                               MSG_DEBUG("Fail to MmsEncodeSendReq");
-                               goto __CATCH;
-                       }
+       switch(mainType) {
+       case MIME_MAINTYPE_AUDIO:
+               mediatype = MMS_SMIL_MEDIA_AUDIO;
                break;
-               default:
-                       MSG_DEBUG("Not Support msg type : %d", pMmsMsg->mmsAttrib.msgType);
-                       goto __CATCH;
+       case MIME_MAINTYPE_IMAGE:
+               mediatype = MMS_SMIL_MEDIA_IMG;
+               break;
+       case MIME_MAINTYPE_TEXT:
+               mediatype = MMS_SMIL_MEDIA_TEXT;
+               break;
+       case MIME_MAINTYPE_VIDEO:
+               mediatype = MMS_SMIL_MEDIA_VIDEO;
+               break;
+       default :
+               mediatype = MMS_SMIL_MEDIA_INVALID;
                break;
        }
 
-       MsgFsync(pFile);        //file is written to device immediately, it prevents missing file data from unexpected power off
-       MsgCloseFile(pFile);
+       if (mediatype != MMS_SMIL_MEDIA_INVALID) {
+               MMS_PAGE_S *pPage = (MMS_PAGE_S *)calloc(1, sizeof(MMS_PAGE_S));
+               MMS_MEDIA_S *media = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
 
-       return true;
+               media->mediatype = mediatype;
+               media->drmType = pMultipart->drmType;
+               snprintf(media->szFilePath, sizeof(media->szFilePath), "%s", pMultipart->szFilePath);
+               snprintf(media->szFileName, sizeof(media->szFileName), "%s", pMultipart->szFileName);
+               snprintf(media->szContentID, sizeof(media->szContentID), "%s", pMultipart->szContentID);
+               snprintf(media->szContentLocation, sizeof(media->szContentLocation), "%s", pMultipart->szContentLocation);
+               snprintf(media->szContentType, sizeof(media->szContentType), "%s", pMultipart->szContentType);
 
-__CATCH:
-       if (pFile) {
-               MsgCloseFile(pFile);
-       }
+               MSG_SEC_DEBUG("InsertPart to media[%p] type[%d] : path = [%s], name = [%s], cid = [%s], cl = [%s], ct = [%s]"\
+                               , media, mediatype,  media->szFilePath, media->szFileName, media->szContentID, media->szContentLocation, media->szContentType);
 
-       return false;
-}
+               if (_MsgMmsAddMedia(pPage, media) != MSG_SUCCESS) {
+                       g_free(pPage);
+                       g_free(media);
+                       return false;
+               }
 
-bool MmsInsertPartFromMultipart(MmsMsg *pMsg, MMS_MULTIPART_DATA_S *pNewMultipart)
-{
-       MsgMultipart *pMultipart = NULL;
-       MsgMultipart *pLastPart = NULL;
+               if (_MsgMmsAddPage(pMsgData, pPage) != MSG_SUCCESS) {
+                       g_free(pPage);
+                       g_free(media);
+                       return false;
+               }
 
-       MimeType mimeType = MIME_UNKNOWN;
-       char *pExt = NULL;
+       } else {
+               MMS_ATTACH_S *attachment = NULL;
+               attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
 
-       pExt = strrchr(pNewMultipart->szFilePath, '.');
+               attachment->mediatype =  pMultipart->type;
+               attachment->drmType = pMultipart->drmType;
+               snprintf(attachment->szContentType, sizeof(attachment->szContentType), "%s", pMultipart->szContentType);
+               snprintf(attachment->szFilePath, sizeof(attachment->szFilePath), "%s", pMultipart->szFilePath);
+               snprintf(attachment->szFileName, sizeof(attachment->szFileName), "%s", pMultipart->szFileName);
+               attachment->fileSize = MsgGetFileSize(attachment->szFilePath);
+               MSG_SEC_DEBUG("Insert Attach to attachment[%p] : path = [%s], name = [%s], ct = [%s], size = [%d]"\
+                                               , attachment, attachment->szFilePath, attachment->szFileName, attachment->szContentType, attachment->fileSize);
 
-       if (pExt == NULL || pExt[0] == '\0' || strrchr(pExt, '/')) {
-               //mimeType = MIME_UNKNOWN;
-               mimeType = MimeGetMimeIntFromMimeString(pNewMultipart->szContentType);
-       } else {
-               if (strcasecmp(pExt, ".dcf") == 0)
-                       mimeType = MIME_APPLICATION_VND_OMA_DRM_CONTENT;
-               else {
-                       if (MmsGetTypeByFileName((int *)&mimeType, pNewMultipart->szFilePath) == false)
-                               goto __CATCH;
+               if (_MsgMmsAddAttachment(pMsgData, attachment) != MSG_SUCCESS) {
+                       g_free(attachment);
+                       return false;
                }
        }
 
-       MSG_DEBUG("type = %d, name = %s, filepath = %s, cid = %s, cl = %s", mimeType, pNewMultipart->szFileName, pNewMultipart->szFilePath, pNewMultipart->szContentID, pNewMultipart->szContentLocation);
+       MSG_END();
+       return true;
+}
 
-       if (mimeType == MIME_UNKNOWN)
-               mimeType = MIME_APPLICATION_OCTET_STREAM;
+bool MmsInsertPartFromMultipart(MmsMsg *pMsg, MMS_MULTIPART_DATA_S *pNewMultipart)
+{
+       MsgMultipart *pMultipart = NULL;
+       MsgMultipart *pLastPart = NULL;
 
        if (MmsIsMultipart(pMsg->msgType.type) == true) {
                /* Insert as a multipart */
-               pMultipart = MmsMakeMultipart(mimeType, pNewMultipart->szFileName, pNewMultipart->szFilePath, pNewMultipart->szContentID, pNewMultipart->szContentLocation);
+               pMultipart = MmsMakeMultipart(pNewMultipart->type, pNewMultipart->szFileName, pNewMultipart->szFilePath, pNewMultipart->szContentID, pNewMultipart->szContentLocation);
 
                if (pMultipart == NULL)
                        goto __CATCH;
@@ -1264,12 +689,12 @@ bool MmsInsertPartFromMultipart(MmsMsg *pMsg, MMS_MULTIPART_DATA_S *pNewMultipar
                pMsg->msgType.contentSize += pMultipart->pBody->size;
        } else {
                /* Single part - Insert as a message body */
-               if (pMsg->mmsAttrib.contentType != mimeType || pMsg->msgType.type != mimeType)
+               if (pMsg->mmsAttrib.contentType != pNewMultipart->type || pMsg->msgType.type != pNewMultipart->type)
                        goto __CATCH;
 
                strncpy(pMsg->msgType.param.szName, pNewMultipart->szFileName, MSG_LOCALE_FILENAME_LEN_MAX);
 
-               if (MmsIsText(pMsg->msgType.type) == true) {
+               if (MmsIsTextType(pMsg->msgType.type) == true) {
                        pMsg->msgType.param.charset = MSG_CHARSET_UTF8;
                }
 
@@ -1288,11 +713,11 @@ __CATCH:
 
 }
 
-bool MmsMakeMmsData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg)
+bool MmsConvertMsgData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg)
 {
        MSG_BEGIN();
 
-       bzero(pMmsMsg, sizeof(MMS_MESSAGE_DATA_S));
+       //bzero(pMmsMsg, sizeof(MMS_MESSAGE_DATA_S));
        pMmsMsg->regionCnt = 0;
        pMmsMsg->pageCnt = 0;
        pMmsMsg->attachCnt = 0;
@@ -1302,12 +727,11 @@ bool MmsMakeMmsData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg)
 
        if (pMsg->mmsAttrib.contentType == MIME_MULTIPART_RELATED || pMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
                char *pSmilDoc = NULL;
-
                if (pMsg->msgBody.pPresentationBody) {
                        if (pMsg->msgBody.pPresentationBody->body.pText) {
                                pSmilDoc = pMsg->msgBody.pPresentationBody->body.pText;
                                if (pSmilDoc) {
-                                       MmsSmilParseSmilDocOnlyLayout(pMmsMsg, pSmilDoc);
+                                       MsgSmilParseSmilDoc(pMmsMsg, pSmilDoc);
                                }
 
                                pMmsMsg->smil.type = MIME_APPLICATION_SMIL;
@@ -1315,37 +739,106 @@ bool MmsMakeMmsData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg)
                                snprintf(pMmsMsg->smil.szContentID, MSG_MSG_ID_LEN, "%s", pMsg->msgBody.presentationType.szContentID);
                                snprintf(pMmsMsg->smil.szContentLocation, MSG_MSG_ID_LEN, "%s", pMsg->msgBody.presentationType.szContentLocation);
                                snprintf(pMmsMsg->smil.szFileName, MSG_FILENAME_LEN_MAX, "%s", pMsg->msgBody.presentationType.param.szName);
-                               snprintf(pMmsMsg->smil.szFilePath, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s", pMsg->msgBody.presentationType.param.szFileName);
+                               snprintf(pMmsMsg->smil.szFilePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, pMsg->msgBody.presentationType.param.szFileName);
+                       }
+               } else {
+                       MSG_DEBUG("Not Exist pPresentationBody");
+               }
+       }
+
+       /*If mms content type is TEXTPLAN add to First Page*/
+       if (pMsg->mmsAttrib.contentType == MIME_TEXT_PLAIN) {
+               MsgType partHeader;
+               int partCnt = pMsg->nPartCount;
+
+               if (partCnt <= 0) {
+                       MSG_DEBUG("partCnt=%d\n", partCnt );
+               } else {
+
+                       if (MmsGetMediaPartHeader(0, &partHeader) == false) {
+                               MSG_DEBUG("Failed to get MediaPart MmsGetMediaPartHeader" );
+                               goto FREE_CATCH;
+                       }
+
+                       if (partHeader.contentSize > 0) {
+                               char szBuf[MSG_FILEPATH_LEN_MAX + 1] = {0,};
+                               MMS_PAGE_S *page = NULL;
+                               MMS_MEDIA_S *media = NULL;
+
+                               snprintf(szBuf, sizeof(szBuf), "%s", partHeader.param.szFileName);
+                               snprintf(partHeader.param.szFileName, sizeof(partHeader.param.szFileName), "%s%s", MSG_DATA_PATH, szBuf);
+
+                               page =  (MMS_PAGE_S *)calloc(1, sizeof(MMS_PAGE_S));
+                               if (page == NULL) {
+                                       MSG_FATAL("page allocation error");
+                                       goto FREE_CATCH;
+                               }
+
+                               media = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               if (media == NULL) {
+                                       MSG_FATAL("media allocation error");
+                                       free(page);
+                                       goto FREE_CATCH;
+                               }
+
+                               media->mediatype = MMS_SMIL_MEDIA_TEXT;
+                               snprintf(media->szFilePath, sizeof(media->szFilePath), "%s", partHeader.param.szFileName);
+                               snprintf(media->szFileName, sizeof(media->szFileName), "%s", partHeader.param.szName);
+                               snprintf(media->szContentID, sizeof(media->szContentID), "%s", partHeader.szContentID);
+                               snprintf(media->szContentLocation, sizeof(media->szContentLocation), "%s", partHeader.szContentLocation);
+
+                               _MsgMmsAddMedia(page, media);
+
+                               _MsgMmsAddPage(pMmsMsg, page);
                        }
-               } else {
-                       MSG_DEBUG("Not Exist pPresentationBody");
+
                }
-       }
+       } else {
 
-       int partCnt = pMsg->nPartCount;
+               int partCnt = pMsg->nPartCount;
 
-       for (int i = 0; i < partCnt; ++i) {
+               for (int i = 0; i < partCnt; ++i) {
 
-               MsgMultipart *multipart = MmsGetNthMultipart(pMsg, i);
-               MMS_MULTIPART_DATA_S pMultipart;
+                       MsgMultipart *multipart = MmsGetNthMultipart(pMsg, i);
+                       MMS_MULTIPART_DATA_S pMultipart;
 
-               if (multipart == NULL) {
-                       MSG_DEBUG("multipart is NULL [%d]", i);
-                       goto FREE_CATCH;
-               }
+                       if (multipart == NULL) {
+                               MSG_DEBUG("multipart is NULL [%d]", i);
+                               goto FREE_CATCH;
+                       }
+
+                       bzero(&pMultipart, sizeof(MMS_MULTIPART_DATA_S));
+
+                       pMultipart.type = (MimeType)multipart->type.type;
+                       MSG_DEBUG("Mime Type : %s :%d", MimeGetMimeStringFromMimeInt(multipart->type.type), multipart->type.type);
+                       snprintf(pMultipart.szContentID, sizeof(pMultipart.szContentID), "%s", multipart->type.szContentID);
+                       snprintf(pMultipart.szContentLocation, sizeof(pMultipart.szContentLocation), "%s", multipart->type.szContentLocation);
+                       snprintf(pMultipart.szFileName, sizeof(pMultipart.szFileName), "%s", multipart->type.param.szName);
+                       snprintf(pMultipart.szFilePath, sizeof(pMultipart.szFilePath), "%s", multipart->pBody->szOrgFilePath);
+                       snprintf(pMultipart.szContentType, sizeof(pMultipart.szContentType), "%s",MimeGetMimeStringFromMimeInt(multipart->type.type));
+
+                       if (multipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
+                               pMultipart.drmType = multipart->type.drmInfo.drmType;
+                       }
 
-               bzero(&pMultipart, sizeof(MMS_MULTIPART_DATA_S));
-               snprintf(pMultipart.szContentID, sizeof(pMultipart.szContentID), "%s", multipart->type.szContentID);
-               snprintf(pMultipart.szContentLocation, sizeof(pMultipart.szContentLocation), "%s", multipart->type.szContentLocation);
-               snprintf(pMultipart.szFileName, sizeof(pMultipart.szFileName), "%s", multipart->type.param.szName);
-               snprintf(pMultipart.szFilePath, sizeof(pMultipart.szFilePath), "%s", multipart->pBody->szOrgFilePath);
-               snprintf(pMultipart.szContentType, sizeof(pMultipart.szContentType), "%s",MimeGetMimeStringFromMimeInt(multipart->type.type));
+                       _MsgMmsMultipartPrint(&pMultipart);
 
-               if (MmsInsertPartToMmsData(pMmsMsg, &pMultipart) == false) {
-                       MSG_DEBUG("Fail to MmsSetMultipartToMmsData");
-                       goto FREE_CATCH;
+                       if (pMsg->mmsAttrib.contentType == MIME_MULTIPART_RELATED || pMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
+                               if (MmsInsertPartToMmsData(pMmsMsg, &pMultipart) == false) {
+                                       MSG_DEBUG("Fail to MmsSetMultipartToMmsData");
+                                       goto FREE_CATCH;
+                               }
+                       } else {
+                               if (MmsInsertMixedPartToMmsData(pMmsMsg, &pMultipart) == false) {
+                                       MSG_DEBUG("Fail to MmsSetMultipartToMmsData");
+                                       goto FREE_CATCH;
+                               }
+                       }
                }
        }
+
+       _MsgMmsRemoveEmptyObject(pMmsMsg);
+
        MSG_END();
        return true;
 FREE_CATCH:
@@ -1387,239 +880,584 @@ void MmsPrintMmsMsg(const MmsMsg *pMmsMsg)
 
 }
 
-bool MmsComposeSendReq(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMsgData)
+int MmsUpdateMultipartList(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
+       MMSList *multipart_list = NULL;
 
-       char *pRawData = NULL;
-       AutoPtr<char> buf(&pRawData);
-       struct tm *timeInfo = NULL;
-       time_t RawTime = 0;
-       time_t nTimeInSecs = 0;
+       if (MmsPluginStorage::instance()->getMultipartList(pMsgInfo->msgId, &multipart_list) != MSG_SUCCESS)
+               return -1;
+
+       for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+               MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+               MmsPluginStorage::instance()->updateMultipart(pMsgInfo->msgId, true, pMultipart);
+       }
+
+       MSG_END();
+       return 0;
+}
+
+int MmsUpdatePreviewData(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
+
+       char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
+       MmsMsg mmsMsg;
+
+       memset(&mmsMsg, 0, sizeof(MmsMsg));
+
+       MmsPluginStorage::instance()->getMmsRawFilePath(pMsgInfo->msgId, szFullPath, sizeof(szFullPath));
+       MmsPluginDecoder::instance()->decodeMmsPdu(&mmsMsg, pMsgInfo->msgId, szFullPath);
+
+       {//make Preview info for APP
+               MmsPluginAppBase appBase(&mmsMsg);
+               appBase.makePreviewInfo(pMsgInfo->msgId, true, szFullPath);
+               appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
+       }
+       MmsReleaseMmsMsg(&mmsMsg);
+       MSG_END();
+       return 0;
+}
+
+//MmsMsg -> MMS_DATA_S
+bool MmsConvertMmsData(MmsMsg *pMmsMsg, MMS_DATA_S *pMmsData)
+{
+       MSG_BEGIN();
+
+       MMS_HEADER_DATA_S *pHeaderData = pMmsData->header;
+       if (pHeaderData) {
+
+               snprintf(pHeaderData->messageID,  sizeof(pHeaderData->messageID), "%s", pMmsMsg->szMsgID);
+               snprintf(pHeaderData->trID,  sizeof(pHeaderData->trID), "%s", pMmsMsg->szTrID);
+               snprintf(pHeaderData->contentLocation,  sizeof(pHeaderData->contentLocation), "%s", pMmsMsg->szContentLocation);
+               snprintf(pHeaderData->szContentType,  sizeof(pHeaderData->szContentType), "%s", MimeGetMimeStringFromMimeInt(pMmsMsg->mmsAttrib.contentType));
+
+               pHeaderData->messageType = pMmsMsg->mmsAttrib.msgType;
+               pHeaderData->mmsVersion = pMmsMsg->mmsAttrib.version;
+               pHeaderData->messageClass = pMmsMsg->mmsAttrib.msgClass;
+               pHeaderData->contentClass = 0;
+               pHeaderData->mmsPriority = pMmsMsg->mmsAttrib.priority;
+               pHeaderData->expiry.type = pMmsMsg->mmsAttrib.expiryTime.type;
+               pHeaderData->expiry.time = pMmsMsg->mmsAttrib.expiryTime.time;
+
+               pHeaderData->bDeliveryReport = pMmsMsg->mmsAttrib.bAskDeliveryReport;
+               pHeaderData->date = pMmsMsg->mmsAttrib.date;
+               pHeaderData->mmsVersion = pMmsMsg->mmsAttrib.version;
+
+               pHeaderData->bReadReport = pMmsMsg->mmsAttrib.bAskReadReply;
+               pHeaderData->bHideAddress = pMmsMsg->mmsAttrib.bHideAddress;
+
+               snprintf(pHeaderData->szSubject, sizeof(pHeaderData->szSubject), "%s", pMmsMsg->mmsAttrib.szSubject);
+
+               pHeaderData->to = MmsConvertAddressToNewStyle(pMmsMsg->mmsAttrib.szTo);
+               pHeaderData->cc = MmsConvertAddressToNewStyle(pMmsMsg->mmsAttrib.szCc);
+               pHeaderData->bcc = MmsConvertAddressToNewStyle(pMmsMsg->mmsAttrib.szBcc);
+
+               snprintf(pHeaderData->szFrom, sizeof(pHeaderData->szFrom), "%s", pMmsMsg->mmsAttrib.szFrom);
+       }
+
+       if (pMmsMsg->mmsAttrib.contentType == MIME_MULTIPART_RELATED || pMmsMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
+
+               MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+
+               pMultipart->type = MIME_APPLICATION_SMIL;
+               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", "application/smil");
+               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMmsMsg->msgBody.presentationType.szContentID);
+               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMmsMsg->msgBody.presentationType.szContentLocation);
+               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMmsMsg->msgBody.presentationType.param.szName);
+               snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), MSG_DATA_PATH"%s", pMmsMsg->msgBody.presentationType.param.szFileName);
+
+               pMmsData->smil = pMultipart;
+       }
+
+       int partCnt = pMmsMsg->nPartCount;
+
+       for (int i = 0; i < partCnt; ++i) {
+
+               MsgMultipart *multipart = MmsGetNthMultipart(pMmsMsg, i);
+
+               if (multipart) {
+
+                       MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+
+                       pMultipart->type = (MimeType)multipart->type.type;
+
+                       snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s",MimeGetMimeStringFromMimeInt(multipart->type.type));
+                       snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", multipart->type.szContentID);
+                       snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", multipart->type.szContentLocation);
+                       snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", multipart->type.param.szName);
+                       snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", multipart->pBody->szOrgFilePath);
+
+#ifdef __SUPPORT_DRM__
+                       if (multipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
+                               pMultipart->drmType = multipart->type.drmInfo.drmType;
+                       }
+#endif
+                       pMmsData->multipartlist = g_list_append(pMmsData->multipartlist, pMultipart);
+               }
+       }
+
+       MSG_END();
+       return true;
+}
+
+//For Encode raw file
+bool MmsConvertMmsMsg(MmsMsg *pMmsMsg, MMS_DATA_S *pMmsData)
+{
+       MSG_BEGIN();
 
        // Initialize mmsMsg structure
        MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
        MmsInitMsgType(&pMmsMsg->msgType);
        MmsInitMsgBody(&pMmsMsg->msgBody);
 
-       // setting mmsMsg structure
-       pMmsMsg->mailbox = pMsgInfo->folderId;
-       pMmsMsg->msgID = pMsgInfo->msgId;
-
-       memset(pMmsMsg->szTrID, 0, MMS_TR_ID_LEN + 1);
-       memset(pMmsMsg->szContentLocation, 0, MMS_LOCATION_LEN + 1);
-       memset(pMmsMsg->szMsgID, 0, MMS_MSG_ID_LEN + 1);
-       memset(pMmsMsg->szForwardMsgID, 0, MMS_MSG_ID_LEN + 1);
-
        pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_DRAFT;
-       pMmsMsg->mmsAttrib.msgType = MMS_MSGTYPE_SEND_REQ;
 
-       if (pSendOptInfo->bSetting == false) {
-               unsigned int expiryTime;
-               MSG_MMS_DELIVERY_TIME_T deliveryTime;
+       MMS_HEADER_DATA_S *pHeaderData = pMmsData->header;
+
+       if (pHeaderData) {
 
-               pMmsMsg->mmsAttrib.priority = (MmsPriority)MsgSettingGetInt(MMS_SEND_PRIORITY);
+               if (strlen(pHeaderData->contentLocation) > 0) {
+                       snprintf(pMmsMsg->szContentLocation, sizeof(pMmsMsg->szContentLocation), "%s", pHeaderData->contentLocation);
+               }
 
-               MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pMmsMsg->mmsAttrib.bAskDeliveryReport);
-               MsgSettingGetBool(MMS_SEND_READ_REPLY, &pMmsMsg->mmsAttrib.bAskReadReply);
-               MsgSettingGetBool(MSG_KEEP_COPY, &pMmsMsg->mmsAttrib.bLeaveCopy);
+               pMmsMsg->mmsAttrib.contentType = (MimeType)pHeaderData->contentType;
+               pMmsMsg->msgType.type = pHeaderData->contentType;
+               pMmsMsg->mmsAttrib.date = pHeaderData->date;
+               pMmsMsg->mmsAttrib.bAskDeliveryReport = pHeaderData->bDeliveryReport;
+               pMmsMsg->mmsAttrib.deliveryTime.type = pHeaderData->delivery.type;
+               pMmsMsg->mmsAttrib.deliveryTime.time = pHeaderData->delivery.time;
+               pMmsMsg->mmsAttrib.expiryTime.type = pHeaderData->expiry.type;
+               pMmsMsg->mmsAttrib.expiryTime.time = pHeaderData->expiry.time;
+               pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)pHeaderData->messageClass;
+
+               if (strlen(pHeaderData->messageID) > 0) {
+                       snprintf(pMmsMsg->szMsgID, sizeof(pMmsMsg->szMsgID), "%s", pHeaderData->messageID);
+               }
 
-               expiryTime = (unsigned int)MsgSettingGetInt(MMS_SEND_EXPIRY_TIME);
+               pMmsMsg->mmsAttrib.msgType = (MmsMsgType)pHeaderData->messageType;
+               pMmsMsg->mmsAttrib.version  = pHeaderData->mmsVersion;
+               pMmsMsg->mmsAttrib.priority = (MmsPriority)pHeaderData->mmsPriority;
+               pMmsMsg->mmsAttrib.bAskReadReply = pHeaderData->bReadReport;
+               pMmsMsg->mmsAttrib.bHideAddress = pHeaderData->bHideAddress;
 
-               if (expiryTime == 0)
-                       pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_NONE;
-               else {
-                       pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_RELATIVE;
-                       pMmsMsg->mmsAttrib.expiryTime.time = expiryTime;
+               if (strlen(pHeaderData->trID) > 0) {
+                       snprintf(pMmsMsg->szTrID, sizeof(pMmsMsg->szTrID), "%s", pHeaderData->trID);
                }
 
-               deliveryTime = (MSG_MMS_DELIVERY_TIME_T)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
 
-               if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
-                       pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = true;
+               snprintf(pMmsMsg->mmsAttrib.szSubject, sizeof(pMmsMsg->mmsAttrib.szSubject), "%s", pHeaderData->szSubject);
+
+               pMmsMsg->mmsAttrib.szTo = MmsConvertAddressToOldStyle(pHeaderData->to);
+               pMmsMsg->mmsAttrib.szCc = MmsConvertAddressToOldStyle(pHeaderData->cc);
+               pMmsMsg->mmsAttrib.szBcc = MmsConvertAddressToOldStyle(pHeaderData->bcc);
+
+               snprintf(pMmsMsg->mmsAttrib.szFrom, sizeof(pMmsMsg->mmsAttrib.szFrom), "%s", pHeaderData->szFrom);
+       } //CID 41988: Moving all de-referencing of pHeaderData inside null-check block
+
+       printMmsAttribute(&pMmsMsg->mmsAttrib);
+
+       if (pMmsData->multipartlist) {
+
+               if (pMmsData->smil) {
+
+                       MMS_MULTIPART_DATA_S *smil_multipart = pMmsData->smil;
+
+                       if (smil_multipart) {
+
+                               pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
+                               pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
 
-                       pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
-                       pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY);
+                               gchar *contents = NULL;
+                               gsize length = 0;
+
+                               if (MsgAccessFile(smil_multipart->szFilePath, F_OK)) {
+                                       g_file_get_contents(smil_multipart->szFilePath, &contents, &length, NULL);
+
+                                       MmsInsertPresentation(pMmsMsg, MIME_APPLICATION_SMIL, NULL, contents, length);
+
+                                       g_free(contents);
+
+                               } else {
+                                       contents = smil_multipart->pMultipartData;
+                                       length = smil_multipart->nMultipartDataLen;
+
+                                       MmsInsertPresentation(pMmsMsg, MIME_APPLICATION_SMIL, NULL, contents, length);
+                               }
+                       }
                } else {
-                       pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = false;
+                       pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
+                       pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
+               }
+
+               int len = g_list_length(pMmsData->multipartlist);
+
+               for (int i = 0; i < len; i++) {
+
+                       MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMmsData->multipartlist, i);
+
+                       if (multipart) {
+                               if (multipart->type == MIME_UNKNOWN)
+                                       multipart->type = MimeGetMimeIntFromMimeString(multipart->szContentType);
+
+                               if (MmsInsertPartFromMultipart(pMmsMsg, multipart) == false) {
+                                       return false;
+                               }
+                       }
+               } //end for
+       }
+
+       MSG_END();
+       return true;
+}
+
+char *MmsConvertAddressToOldStyle(MMSList *pAddressList)
+{
+       MSG_BEGIN();
+       int     addrLen = 0;
+       int     nAddressCnt = 0;
+       char pString[MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3] = {0, };
+       char *szCompose = NULL;
+
+       nAddressCnt = g_list_length(pAddressList);
+
+       // Calculate allocated buffer size
+       for (int i = 0; i < nAddressCnt; ++i) {
 
-                       pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
-                       pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)deliveryTime;
+               MMS_ADDRESS_DATA_S * pAddressData = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pAddressList, i);
+               if (pAddressData) {
+                       MSG_SEC_DEBUG("address type : %d, address value: %s", pAddressData->address_type, pAddressData->address_val);
+                       if (pAddressData->address_type == MSG_ADDRESS_TYPE_PLMN) {
+                               addrLen += strlen("/TYPE=PLMN");
+                               addrLen += strlen(pAddressData->address_val);
+                       } else {
+                               addrLen += strlen(pAddressData->address_val);
+                       }
                }
-       } else {
-               pMmsMsg->mmsAttrib.priority = (MmsPriority)pSendOptInfo->option.mmsSendOptInfo.priority;
-               pMmsMsg->mmsAttrib.bAskDeliveryReport = pSendOptInfo->bDeliverReq;
-               pMmsMsg->mmsAttrib.bAskReadReply = pSendOptInfo->option.mmsSendOptInfo.bReadReq;
-               pMmsMsg->mmsAttrib.expiryTime.type = pSendOptInfo->option.mmsSendOptInfo.expiryTime.type;
-               pMmsMsg->mmsAttrib.bLeaveCopy = pSendOptInfo->bKeepCopy;
-
-               if (pMmsMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE)
-                       pMmsMsg->mmsAttrib.expiryTime.time = pSendOptInfo->option.mmsSendOptInfo.expiryTime.time;
-
-               pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime;
-               pMmsMsg->mmsAttrib.deliveryTime.type = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.type;
-               pMmsMsg->mmsAttrib.deliveryTime.time = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time;
        }
 
-       MSG_DEBUG("pSendOptInfo->bSetting = %d", pSendOptInfo->bSetting);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.bLeaveCopy = %d", pMmsMsg->mmsAttrib.bLeaveCopy);
+       if (nAddressCnt > 1)
+               addrLen = addrLen + nAddressCnt - 1;
 
-       MSG_DEBUG("pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = %d", pMmsMsg->mmsAttrib.bUseDeliveryCustomTime);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.type = %d", pMmsMsg->mmsAttrib.deliveryTime.type);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.time = %d", pMmsMsg->mmsAttrib.deliveryTime.time);
+       szCompose = (char *)calloc(addrLen + 1, 1);
 
-       MSG_DEBUG("pMmsMsg->mmsAttrib.priority = %d", pMmsMsg->mmsAttrib.priority);
+       // Address String copy
+       for (int i = 0; i < nAddressCnt; ++i) {
 
-       MSG_DEBUG("pMmsMsg->mmsAttrib.bAskDeliveryReport = %d", pMmsMsg->mmsAttrib.bAskDeliveryReport);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.bAskReadReply = %d", pMmsMsg->mmsAttrib.bAskReadReply);
+               MMS_ADDRESS_DATA_S * pAddressData = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pAddressList, i);
 
-       MSG_DEBUG("pMmsMsg->mmsAttrib.expiryTime.type = %d", pMmsMsg->mmsAttrib.expiryTime.type);
-       MSG_DEBUG("pMmsMsg->mmsAttrib.expiryTime.time = %d", pMmsMsg->mmsAttrib.expiryTime.time);
+               if (pAddressData) {
+                       if (strlen(szCompose) > 0)
+                               strcat(szCompose, MSG_STR_ADDR_DELIMETER);
 
-       /* MMS-1.3-con-739 */
-       pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)MsgSettingGetInt(MMS_SEND_MSG_CLASS);
-       /* MMS-1.3-con-739 */
-#ifdef MMS_13_CON_742_ENABLED
-       /* MMS-1.3-con-742 */
-       pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
-       /* MMS-1.3-con-742 */
-#endif
+                       memset(pString, 0x00, (MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3) * sizeof(char));
+                       if (pAddressData->address_type == MSG_ADDRESS_TYPE_PLMN) {
+                               snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s%s", pAddressData->address_val, "/TYPE=PLMN");
+                               MSG_DEBUG("%s", pString);
+                       } else {
+                               snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s", pAddressData->address_val);
+                       }
 
-       // setting date
-       time(&RawTime);
-       timeInfo = localtime(&RawTime);
-       nTimeInSecs = mktime(timeInfo);
-       pMmsMsg->mmsAttrib.date = nTimeInSecs;  // todo: need to subtract timeline value to make GMT+0 time
+                       strcat(szCompose, pString);
+               }
 
-       //setting subject
-       strcpy(pMmsMsg->mmsAttrib.szSubject, pMsgInfo->subject);
+       }
 
-       //setting adddress
-       MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
+       MSG_END();
+       return szCompose;
 
-       //default type mixed
-       pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
-       pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
+}
 
-       int pageCnt = _MsgMmsGetPageCount(pMsgData);
+MMSList * MmsConvertAddressToNewStyle(const char *szAddr)
+{
+       MMSList *pAddressList = NULL;
+       MMS_ADDRESS_DATA_S *pAddressData = NULL;
 
-       if (pageCnt >  0) {     // Multipart related
+       char *pTempChar = NULL;
+       char *pStartPtr= NULL;
+       char *pEndPtr= NULL;
 
-               int RawDataSize = 0;
-               time_t RawTime = 0;
-               time(&RawTime);
+       if (szAddr == NULL)
+               return NULL;
 
-               snprintf(pMsgData->szSmilFilePath, MSG_FILEPATH_LEN_MAX, "%lu", RawTime);
+       pTempChar = strdup(szAddr);
 
-               MsgMMSCreateSMIL(pMsgData);
+       pStartPtr = pTempChar;
 
-               RawDataSize = MmsGetSmilRawData(pMsgData, &pRawData);
-               if (RawDataSize < 0) {
-                       MSG_DEBUG("Smil file size is less than 0");
-                       return false;
-               }
-               MSG_DEBUG("%s", pRawData);
-               if (pRawData)
-                       MmsInsertPresentation(pMmsMsg, MIME_APPLICATION_SMIL, NULL, pRawData, strlen(pRawData));
+       while (pStartPtr && pStartPtr[0]) {
 
-               pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
-               pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
+               int addLen = 0;
+               char tempAddress[512] = {0,};
+               char tempAddress2[512] = {0,};
 
-       }
+               pEndPtr = strchr(pStartPtr, MSG_CH_SEMICOLON);
 
-       if (pMmsMsg->msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
-
-               int pageCnt = _MsgMmsGetPageCount(pMsgData);
-
-               for (int i = 0; i < pageCnt; ++i) {
-                       MMS_PAGE_S *pPage = _MsgMmsGetPage(pMsgData, i);
-                       int mediaCnt = pPage->mediaCnt;
-                       MSG_DEBUG("PAGE %d's media Cnt: %d", i+1, mediaCnt);
-
-                       for (int j = 0; j < mediaCnt; ++j) {
-                               MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
-                               if (pMedia->szFilePath[0] != 0) {
-                                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
-                                       if (pMultipart) {
-                                               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szContentID);
-                                               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szContentLocation);
-                                               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
-                                               snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
-                                               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
-
-                                               if (!MmsInsertPartFromMultipart(pMmsMsg, pMultipart)) {
-                                                       free(pMultipart);
-                                                       pMultipart = NULL;
-                                                       return false;
-                                               }
+               if (pEndPtr) {
+                       addLen = pEndPtr - pStartPtr;
+               } else {
+                       addLen = strlen(pStartPtr);
+               }
 
-                                               free(pMultipart);
-                                               pMultipart = NULL;
-                                       }
-                               }
+               if (addLen) {
+                       strncpy(tempAddress, pStartPtr, addLen);
+                       int addr_type;
+                       int addLen2;
+                       char *pSlash = strchr(tempAddress, '/');
+
+                       if (pSlash) {
+                               addLen2 = pSlash - tempAddress;
+                               addr_type = MSG_ADDRESS_TYPE_PLMN;
+                       } else {
+                               addLen2 = strlen(tempAddress);
+                               addr_type = MSG_ADDRESS_TYPE_EMAIL;
+                       }
+
+                       if (addLen2) {
+                               strncpy(tempAddress2, tempAddress, addLen2);
+                               pAddressData = MsgMmsCreateAddress(addr_type, tempAddress2);
                        }
+
+                       if (pAddressData)
+                               pAddressList = g_list_append(pAddressList, pAddressData);
+
+                       pStartPtr = pStartPtr + addLen + 1;
+               } else {
+                       break;
                }
        }
 
-       //Processing Attachment List
-       for (int i = 0; i < _MsgMmsGetAttachCount(pMsgData); ++i) {
-               MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pMsgData, i);
-               if (pMedia->szFilePath[0] != 0) {
-                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
-                       if (pMultipart) {
-                               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szFileName);
-                               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szFileName);
-                               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
-                               snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
-                               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
-
-                               if (!MmsInsertPartFromMultipart(pMmsMsg, pMultipart)) {
-                                       free(pMultipart);
-                                       pMultipart = NULL;
-                                       return false;
-                               }
+       if (pTempChar)
+               free(pTempChar);
 
-                               free(pMultipart);
-                               pMultipart = NULL;
-                       }
+       MSG_END();
+       return pAddressList;
+}
+
+bool convertMediaToMultipart(MMS_MEDIA_S *pSrcMedia, MMS_MULTIPART_DATA_S *pDestMultipart)
+{
+       bzero(pDestMultipart, sizeof(MMS_MULTIPART_DATA_S));
+
+       snprintf(pDestMultipart->szContentID, sizeof(pDestMultipart->szContentID), "%s", pSrcMedia->szContentID);
+       snprintf(pDestMultipart->szContentLocation, sizeof(pDestMultipart->szContentLocation), "%s", pSrcMedia->szContentLocation);
+       snprintf(pDestMultipart->szFileName, sizeof(pDestMultipart->szFileName), "%s", pSrcMedia->szFileName);
+       snprintf(pDestMultipart->szFilePath, sizeof(pDestMultipart->szFilePath), "%s", pSrcMedia->szFilePath);
+
+
+       if (strlen(pSrcMedia->szContentType) > 0) {
+               snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", pSrcMedia->szContentType);
+               pDestMultipart->type = MimeGetMimeIntFromMimeString(pSrcMedia->szContentType);
+
+       } else {
+               MimeMainType mainType = MIME_MAINTYPE_UNKNOWN;
+               MimeType pMimeType = MIME_UNKNOWN;
+               const char *pszMimeType = NULL;
+
+               if (pSrcMedia->mediatype == MMS_SMIL_MEDIA_IMG)
+                       mainType = MIME_MAINTYPE_IMAGE;
+               else if (pSrcMedia->mediatype == MMS_SMIL_MEDIA_AUDIO)
+                       mainType = MIME_MAINTYPE_AUDIO;
+               else if (pSrcMedia->mediatype ==  MMS_SMIL_MEDIA_VIDEO)
+                       mainType = MIME_MAINTYPE_VIDEO;
+               else if (pSrcMedia->mediatype == MMS_SMIL_MEDIA_TEXT)
+                       mainType = MIME_MAINTYPE_TEXT;
+
+               MmsGetMimeTypeFromFileName(mainType, pSrcMedia->szFilePath, &pMimeType, &pszMimeType);
+
+               if (pszMimeType) {
+                       snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", pszMimeType);
+                       pDestMultipart->type = pMimeType;
+               } else {
+                       snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", "application/octet-stream");
+                       pDestMultipart->type = MIME_APPLICATION_OCTET_STREAM;
                }
        }
 
        return true;
 }
 
-int MmsUpdatePreviewData(MSG_MESSAGE_INFO_S *pMsgInfo)
+bool convertAttachToMultipart(MMS_ATTACH_S *pSrcMedia, MMS_MULTIPART_DATA_S *pDestMultipart)
 {
-       MSG_BEGIN();
-       MmsMsg *pMmsMsg;
-       MMS_MESSAGE_DATA_S msgData = {0,};
+       bzero(pDestMultipart, sizeof(MMS_MULTIPART_DATA_S));
+
+       snprintf(pDestMultipart->szFileName, sizeof(pDestMultipart->szFileName), "%s", pSrcMedia->szFileName);
+       snprintf(pDestMultipart->szFilePath, sizeof(pDestMultipart->szFilePath), "%s", pSrcMedia->szFilePath);
 
-       MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
+       if (strlen(pSrcMedia->szContentType) > 0) {
+               snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", pSrcMedia->szContentType);
+               pDestMultipart->type = MimeGetMimeIntFromMimeString(pSrcMedia->szContentType);
+       } else {
 
-       MmsReleaseMmsMsg(pMmsMsg);
+               MimeMainType mainType = MIME_MAINTYPE_UNKNOWN;
+               MimeType pMimeType = MIME_UNKNOWN;
+               const char *pszMimeType = NULL;
 
-       if (MmsReadMsgBody(pMsgInfo->msgId, true, false, NULL) == false) {
-               MSG_DEBUG("Fail to MmsReadMsgBody");
-               goto __CATCH;
+               MmsGetMimeTypeFromFileName(mainType, pSrcMedia->szFilePath, &pMimeType, &pszMimeType);
+
+               if (pszMimeType) {
+                       snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", pszMimeType);
+                       pDestMultipart->type = pMimeType;
+               } else {
+                       snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", "application/octet-stream");
+                       pDestMultipart->type = MIME_APPLICATION_OCTET_STREAM;
+               }
        }
 
-       if (MmsMakeMmsData(pMmsMsg, &msgData) == false) {
-               MSG_DEBUG("Fail to makeMmsMessageData");
-               goto __CATCH;
+       return true;
+}
+
+bool convertMsgMultipartToMultipart(MsgMultipart *pSrcMultipart, MMS_MULTIPART_DATA_S *pDestMultipart)
+{
+       pDestMultipart->type = (MimeType)pSrcMultipart->type.type;
+
+       MSG_DEBUG("Mime Type : %s :%d", MimeGetMimeStringFromMimeInt(pSrcMultipart->type.type), pSrcMultipart->type.type);
+       snprintf(pDestMultipart->szContentID, sizeof(pDestMultipart->szContentID), "%s", pSrcMultipart->type.szContentID);
+       snprintf(pDestMultipart->szContentLocation, sizeof(pDestMultipart->szContentLocation), "%s", pSrcMultipart->type.szContentLocation);
+       snprintf(pDestMultipart->szFileName, sizeof(pDestMultipart->szFileName), "%s", pSrcMultipart->type.param.szName);
+       snprintf(pDestMultipart->szFilePath, sizeof(pDestMultipart->szFilePath), "%s", pSrcMultipart->pBody->szOrgFilePath);
+
+       snprintf(pDestMultipart->szContentType, sizeof(pDestMultipart->szContentType), "%s", MimeGetMimeStringFromMimeInt(pSrcMultipart->type.type));
+
+       if (pSrcMultipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
+               pDestMultipart->drmType = pSrcMultipart->type.drmInfo.drmType;
        }
 
-       MmsMakePreviewInfo(pMsgInfo->msgId, &msgData);
+       return true;
+}
 
-       MmsPluginStorage::instance()->getMsgText(&msgData, pMsgInfo->msgText);
+gint __compare_str(gconstpointer a, gconstpointer b)
+{
+       return g_strcmp0((char *)a, (char *)b);
+}
 
-       MmsReleaseMmsMsg(pMmsMsg);
-       MsgMmsReleaseMmsLists(&msgData);
+// change file name to Ascii & space -> '_'
+// If replaced filename is duplicated, then it append number
+bool MmsChangeFileNameToAscii(MMS_MESSAGE_DATA_S *pMsgData)
+{
+       int pageCnt;
+       int mediaCnt;
+       int attachCnt;
 
-       MSG_END();
-       return 0;
+       GList *r_list = NULL;//renamed file list
 
-__CATCH:
-       MmsReleaseMmsMsg(pMmsMsg);
-       MsgMmsReleaseMmsLists(&msgData);
-       return -1;
+       pageCnt = g_list_length(pMsgData->pagelist);
+
+       for (int i = 0; i < pageCnt; i++) {
+               MMS_PAGE_S *pPage = NULL;
+               pPage = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, i);
+               if (pPage == NULL) {
+                       //CID 355351: Freeing r_list in case of error too to prevent memory leak
+                       if(r_list != NULL)
+                               g_list_free(r_list);
+                       return false;
+               }
+
+               mediaCnt = g_list_length(pPage->medialist);
+               for (int j = 0; j < mediaCnt; j++) {
+                       MMS_MEDIA_S *pMedia = NULL;
+                       pMedia = (MMS_MEDIA_S *)g_list_nth_data(pPage->medialist, j);
+                       if (pMedia == NULL) {
+                               //CID 355351: Freeing r_list in case of error too to prevent memory leak
+                               if(r_list != NULL)
+                                       g_list_free(r_list);
+                               return false;
+                       }
+
+                       if (strlen(pMedia->szFileName) > 0) {
+                               char *str = NULL;
+
+                               MmsReplaceSpaceChar(pMedia->szFileName);
+
+                               str = MmsReplaceNonAsciiUtf8(pMedia->szFileName, '_');
+
+                               if (str) {
+                                       int count = 1;
+                                       char *str2 = g_strdup(str);
+                                       char *ext = strrchr(str, '.');
+
+                                       if (ext == NULL || *(ext + 1) == '\0') {
+                                               ext = NULL;
+                                       } else {
+                                               *ext = '\0';
+                                               ext = ext + 1;
+                                       }
+
+                                       while (g_list_find_custom(r_list, str2, __compare_str) != NULL) {
+
+                                               g_free(str2);
+
+                                               if (ext)
+                                                       str2 = g_strdup_printf("%s_%d.%s", str, count++, ext);
+                                               else
+                                                       str2 = g_strdup_printf("%s_%d", str, count++);
+                                       }
+
+                                       g_free(str);
+
+                                       snprintf(pMedia->szFileName, sizeof(pMedia->szFileName), "%s", str2);
+
+                                       MSG_DEBUG("replace filename [%s]", pMedia->szFileName);
+
+                                       r_list = g_list_append(r_list, pMedia->szFileName);
+
+                                       g_free(str2);
+                               }
+                       }
+               }//end for media
+       }//end for page
+
+       attachCnt = g_list_length(pMsgData->attachlist);
+       for (int i = 0; i < attachCnt; i++) {
+               MMS_ATTACH_S *pAttach = NULL;
+               pAttach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, i);
+               if (pAttach == NULL) {
+                       //CID 355351: Freeing r_list in case of error too to prevent memory leak
+                       if(r_list != NULL)
+                               g_list_free(r_list);
+                       return false;
+               }
+
+               if (strlen(pAttach->szFileName) > 0) {
+                       char *str = NULL;
+
+                       MmsReplaceSpaceChar(pAttach->szFileName);
+
+                       str = MmsReplaceNonAsciiUtf8(pAttach->szFileName, '_');
+                       if (str) {
+                               int count = 1;
+                               char *str2 = g_strdup(str);
+                               char *ext = strrchr(str, '.');
+
+                               if (ext == NULL || *(ext + 1) == '\0') {
+                                       ext = NULL;
+                               } else {
+                                       *ext = '\0';
+                                       ext = ext + 1;
+                               }
+
+                               while (g_list_find_custom(r_list, str2, __compare_str) != NULL) {
+
+                                       g_free(str2);
+
+                                       if (ext)
+                                               str2 = g_strdup_printf("%s_%d.%s", str, count++, ext);
+                                       else
+                                               str2 = g_strdup_printf("%s_%d", str, count++);
+                               }
+
+                               g_free(str);
+
+                               snprintf(pAttach->szFileName, sizeof(pAttach->szFileName), "%s", str2);
+
+                               MSG_DEBUG("replace filename [%s]", pAttach->szFileName);
+
+                               g_free(str2);
+                       }
+               }
+
+       }//end for attach
+
+       g_list_free(r_list);
+
+       return true;
 }
+
index 3fc947b..3c5ab54 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgMmsMessage.h"
@@ -22,7 +22,7 @@
 
 #define MSG_RETURN_VAL_IF_FAIL(Expr, Val)                                      \
                if (!(Expr)) {                                                                          \
-                       MSG_DEBUG("%s:[%s] Failed - %d\n", __FUNCTION__, __LINE__, Val); \
+                       MSG_DEBUG("%s:[%d] Failed - %d\n", __FUNCTION__, __LINE__, Val); \
                        return Val;                                                                             \
                };
 
@@ -103,7 +103,7 @@ MSG_SMIL_ERR_E _MsgMMSAddDefaultSMILRootLayout(MMS_MESSAGE_DATA_S *pMsgData)
        pMsgData->rootlayout.height.value = MSG_SMIL_ROOT_LAYOUT_HEIGHT;
        pMsgData->rootlayout.height.bUnitPercent = MSG_SMIL_ROOT_LAYOUT_IN_PERCENT;
 
-       pMsgData->rootlayout.bgColor = MmsSmilAtoIHexa((char *)&pContent[1]);
+       pMsgData->rootlayout.bgColor = MsgSmilAtoIHexa((char *)&pContent[1]);
 
        MSG_END();
        return MSG_SMIL_SUCCESS;
@@ -235,7 +235,7 @@ MSG_SMIL_ERR_E _MsgMMSAddDefaultFirstSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bo
                pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
        else
                pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
-       pRegion->bgColor = MmsSmilAtoIHexa((char *)&pContent[1]);
+       pRegion->bgColor = MsgSmilAtoIHexa((char *)&pContent[1]);
 
        pRegion->nLeft.value = MSG_SMIL_FIRST_REG_LEFT;
        pRegion->nLeft.bUnitPercent = true;
@@ -285,7 +285,7 @@ MSG_SMIL_ERR_E _MsgMMSAddDefaultSecondSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, b
                pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
        else
                pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
-       pRegion->bgColor = MmsSmilAtoIHexa((char *)&pContent[1]);
+       pRegion->bgColor = MsgSmilAtoIHexa((char *)&pContent[1]);
 
        pRegion->nLeft.value = MSG_SMIL_SECOND_REG_LEFT;
        pRegion->nLeft.bUnitPercent = true;
@@ -335,7 +335,7 @@ MSG_SMIL_ERR_E _MsgMMSAddDefaultFullSMILRegion(MMS_MESSAGE_DATA_S *pMsgData)
                pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
        else
                pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
-       pRegion->bgColor = MmsSmilAtoIHexa((char *)&pContent[1]);
+       pRegion->bgColor = MsgSmilAtoIHexa((char *)&pContent[1]);
 
        pRegion->nLeft.value = MSG_SMIL_FULL_REG_LEFT;
        pRegion->nLeft.bUnitPercent = true;
diff --git a/plugin/mms_plugin/MmsPluginSmil.cpp b/plugin/mms_plugin/MmsPluginSmil.cpp
deleted file mode 100755 (executable)
index 79ce1c9..0000000
+++ /dev/null
@@ -1,2660 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <ctype.h>
-
-#include "MsgMmsMessage.h"
-#include "MsgUtilFile.h"
-#include "MmsPluginTypes.h"
-#include "MmsPluginSmil.h"
-#include "MmsPluginMIME.h"
-#include "MmsPluginStorage.h"
-#include "MmsPluginDebug.h"
-#include "MmsPluginCodec.h"
-
-#define MSG_STDSTR_SHORT                       0x7F
-
-/* static variables */
-static char gszEmptyRawDoc[] = "<smil><head><layout></layout></head><body></body></smil>";
-static MmsSmilDoc *__gpaMmsSmilDoc[MMS_SMIL_MAX_DOC]={NULL, };
-static char gszColor[MMS_SMIL_COLOR_SIZE] = {0, };
-
-
-char *MmsSmilGetPresentationData(msg_message_id_t msgId)
-{
-       MmsMsg *pMsg;
-
-       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-
-       if (pMsg == NULL) {
-               MSG_DEBUG("pMsg is NULL");
-               goto _LCATCH;
-       }
-
-       if (msgId != pMsg->msgID) {
-               MSG_DEBUG("Invalid Message Id");
-               return NULL;
-       }
-
-       if (!pMsg->msgBody.pPresentationBody)
-               goto _LCATCH;
-
-       if (!pMsg->msgBody.pPresentationBody->body.pText)
-               goto _LCATCH;
-       else
-               return pMsg->msgBody.pPresentationBody->body.pText;
-
-_LCATCH:
-       return NULL;
-}
-
-bool MmsSmilParseSmilDoc(MMS_MESSAGE_DATA_S *pMmsMsg, char *pSmilDoc)
-{
-       xmlDocPtr doc;
-       xmlNodePtr cur;
-       MSG_DEBUG("%s", pSmilDoc);
-       doc = xmlParseMemory(pSmilDoc, strlen(pSmilDoc));
-
-       if (doc == NULL) {
-               MSG_DEBUG("Document not parsed successfully. \n");
-               return false;
-       }
-
-       cur = xmlDocGetRootElement(doc);
-
-       if (cur == NULL) {
-               MSG_DEBUG("empty document\n");
-               xmlFreeDoc(doc);
-               return false;
-       }
-
-       if (xmlStrcmp(cur->name, (const xmlChar *) "smil")) {
-               MSG_DEBUG("document of the wrong type, root node != smil");
-               xmlFreeDoc(doc);
-               return false;
-       }
-
-       MmsSmilGetElement(pMmsMsg, cur);
-
-       xmlFreeDoc(doc);
-
-       return true;
-}
-
-void MmsSmilGetElement(MMS_MESSAGE_DATA_S *pMmsMsg, xmlNode *a_node)
-{
-       MSG_BEGIN();
-
-       int elementType;
-       int attrType;
-       MMS_SMIL_ROOTLAYOUT rootlayout = {};
-       static bool cmd[ELEMENT_MAX] = {false, };
-       static MMS_SMIL_REGION *pRegion;
-       static MMS_PAGE_S *pPage;
-       static MMS_MEDIA_S *pMedia;
-       static MMS_SMIL_TRANSITION *pTransition;
-       static MMS_SMIL_META *pMeta;
-
-       xmlNode *cur_node = NULL;
-
-       for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
-               MSG_DEBUG("******* node, name: %s ***\n", cur_node->name);
-
-               if (cur_node->type == XML_ELEMENT_NODE) {
-                       // Get Smil Element =====================================================
-                       MSG_DEBUG("*** node type: Element, name: %s ***\n", cur_node->name);
-
-                       switch (elementType = MmsSmilGetElementID((char *)cur_node->name)) {
-                       case ELEMENT_ROOTLAYOUT:
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_ROOTLAYOUT] = true;
-                               break;
-
-                       case ELEMENT_REGION:
-                               pRegion = (MMS_SMIL_REGION *)calloc(sizeof(MMS_SMIL_REGION), 1);
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_REGION] = true;
-                               break;
-
-                       case ELEMENT_TRANSITION:
-                               pTransition = (MMS_SMIL_TRANSITION *)calloc(sizeof(MMS_SMIL_TRANSITION), 1);
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_TRANSITION] = true;
-                               break;
-
-                       case ELEMENT_META:
-                               pMeta = (MMS_SMIL_META *)calloc(sizeof(MMS_SMIL_META), 1);
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_META] = true;
-                               break;
-
-                       case ELEMENT_PAR:
-                               pPage = (MMS_PAGE_S *)calloc(sizeof(MMS_PAGE_S), 1);
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_PAR] = true;
-                               break;
-
-                       case ELEMENT_PARAM: // Need to check the original element type
-                               break;
-
-                       case ELEMENT_TEXT:
-                               pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
-                               pMedia->mediatype = MMS_SMIL_MEDIA_TEXT;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_TEXT] = true;
-                               break;
-
-                       case ELEMENT_IMG:
-                               pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
-                               pMedia->mediatype = MMS_SMIL_MEDIA_IMG;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_IMG] = true;
-                               break;
-
-                       case ELEMENT_AUDIO:
-                               pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
-                               pMedia->mediatype = MMS_SMIL_MEDIA_AUDIO;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_AUDIO] = true;
-                               break;
-
-                       case ELEMENT_VIDEO:
-                               pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
-                               pMedia->mediatype = MMS_SMIL_MEDIA_VIDEO;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_VIDEO] = true;
-                               break;
-
-                       case ELEMENT_REF:
-                               pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
-                               pMedia->mediatype = MMS_SMIL_MEDIA_IMG_OR_VIDEO;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_REF] = true;
-                               break;
-
-                       case ELEMENT_ANIMATE:
-                               pMedia = (MMS_MEDIA_S *)calloc(sizeof(MMS_MEDIA_S), 1);
-                               pMedia->mediatype = MMS_SMIL_MEDIA_ANIMATE;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_ANIMATE] = true;
-                               break;
-
-                       default:
-                               memset(cmd, 0, ELEMENT_MAX);
-                               break;
-                       }
-
-                       //Get Smil Attribute =====================================================
-                       xmlAttr *pAttr = cur_node->properties;
-                       SMIL_ATTRIBUTE_T paramType = ATTRIBUTE_UNKNOWN;
-
-                       for ( ; pAttr; pAttr = pAttr->next) {
-                               MSG_DEBUG("AttributeType: (%s, %s) ", pAttr->name, pAttr->children->content);
-                               switch (attrType = MmsSmilGetAttrID((char *)pAttr->name)) {
-                               case ATTRIBUTE_ID:
-                                       {
-                                               if (cmd[ELEMENT_REGION]) {
-                                                       strncpy(pRegion->szID, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
-                                               } else if (cmd[ELEMENT_TRANSITION]) {
-                                                       strncpy(pTransition->szID, (char *)pAttr->children->content, MAX_SMIL_TRANSITION_ID - 1);
-                                               } else if (cmd[ELEMENT_META]) {
-                                                       strncpy(pMeta->szID, (char *)pAttr->children->content, MAX_SMIL_META_ID - 1);
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_TOP:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->nTop.bUnitPercent = bUnitPercent;
-                                                       pRegion->nTop.value = value;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_LEFT:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->nLeft.bUnitPercent = bUnitPercent;
-                                                       pRegion->nLeft.value = value;
-                                               }
-                                       }
-                                       break;
-
-
-                               case ATTRIBUTE_WIDTH:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_ROOTLAYOUT]) {
-                                                       rootlayout.width.bUnitPercent = bUnitPercent;
-                                                       rootlayout.width.value = value;
-                                               } else if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->width.bUnitPercent = bUnitPercent;
-                                                       pRegion->width.value = value;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_HEIGHT:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_ROOTLAYOUT]) {
-                                                       rootlayout.height.bUnitPercent = bUnitPercent;
-                                                       rootlayout.height.value = value;
-                                               } else if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->height.bUnitPercent = bUnitPercent;
-                                                       pRegion->height.value = value;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_FIT:
-                                       if (cmd[ELEMENT_REGION]) {
-                                               if (!strcmp((char *)pAttr->children->content, "meet")) {
-                                                       pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
-                                               } else {
-                                                       pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_BGCOLOR:
-                                       if (cmd[ELEMENT_ROOTLAYOUT]) {
-                                               rootlayout.bBgColor = true;
-                                               rootlayout.bgColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       } else if (cmd[ELEMENT_REGION]) {
-                                               pRegion->bBgColor = true;
-                                               pRegion->bgColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       } else if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
-
-                                       break;
-
-                               case ATTRIBUTE_DUR:
-                                       if (cmd[ELEMENT_PAR])
-                                               pPage->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
-                                       else if (cmd[ELEMENT_TRANSITION])
-                                               pTransition->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
-                                       else if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
-
-#ifdef MMS_SMIL_ANIMATE
-                                       if (cmd[ELEMENT_ANIMATE])
-                                               pMedia->sMedia.sAVI.nDur = MmsSmilGetTime((char *)pAttr->children->content);
-#endif
-                                       break;
-
-                               case ATTRIBUTE_SRC:
-                               {
-                                       char *szSrc;
-                                       char szTmpSrc[MSG_FILEPATH_LEN_MAX] = {0,};
-                                       char szOutBuf[MSG_FILEPATH_LEN_MAX] = {0, };
-                                       int cLen;
-                                       int ret;
-                                       MsgMultipart *pPart = NULL;
-                                       MmsMsg *pMsg;
-
-                                       szSrc = MsgChangeHexString((char *)pAttr->children->content);
-                                       if (szSrc == NULL)
-                                               break;
-
-                                       memcpy(pMedia->szSrc, szSrc, strlen(szSrc) + 1);
-                                       free(szSrc);
-
-                                       cLen = strlen(pMedia->szSrc);
-                                       if (!strncasecmp(pMedia->szSrc, "cid:", 4)) {
-                                               strncpy(szTmpSrc, pMedia->szSrc + 4, cLen - 4);
-                                               szTmpSrc[cLen - 4] = '\0';
-                                       } else {
-                                               strncpy(szTmpSrc, pMedia->szSrc, cLen);
-                                               szTmpSrc[cLen] = '\0';
-                                       }
-
-                                       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-                                       pPart = pMsg->msgBody.body.pMultipart;
-#ifndef __SUPPORT_DRM__
-                                       ret = MmsSmilGetMediaSrcForNormalMsg(szOutBuf, szTmpSrc, pPart);
-#else
-                                       ret = MmsSmilGetMediaSrcForNormalMsg(szOutBuf, szTmpSrc, pPart, pMedia);
-#endif
-                                       if (ret >= 0 && strlen(szOutBuf) > 0) {
-                                               strcpy(pMedia->szSrc, szOutBuf);
-                                               MmsSmilGetMediaFilePath(pMedia, szTmpSrc, pMsg->msgID);
-                                       }
-                                       break;
-                               }
-                               case ATTRIBUTE_COLOR:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_SIZE:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nSize = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_BOLD:
-                                       if (cmd[ELEMENT_TEXT]) {
-                                               pMedia->sMedia.sText.bBold = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_UNDERLINE:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.bUnderLine = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_ITALIC:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.bItalic = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_REVERSE:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.bReverse = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_DIRECTION:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nDirection = MmsSmilGetFontDirection((char *)pAttr->children->content);
-                                       break;
-                               case ATTRIBUTE_REGION:
-                                       strncpy(pMedia->regionId, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
-                                       break;
-
-                               case ATTRIBUTE_TRANSIN:
-                                       if (cmd[ELEMENT_TEXT])
-                                               strncpy(pMedia->sMedia.sText.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
-                                       else
-                                               strncpy(pMedia->sMedia.sAVI.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
-                                       break;
-
-                               case ATTRIBUTE_TRANSOUT:
-                                       if (cmd[ELEMENT_TEXT])
-                                               strncpy(pMedia->sMedia.sText.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
-                                       else
-                                               strncpy(pMedia->sMedia.sAVI.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
-                                       break;
-
-                               case ATTRIBUTE_BEGIN:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_END:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_REPEAT_COUNT:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nRepeat = atoi((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nRepeat = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_NAME:
-                                       if (!strcmp((char *)pAttr->children->content, "foreground-color") || !strcmp((char *)pAttr->children->content, "foregroundcolor"))
-                                               paramType = ATTRIBUTE_FGCOLOR;
-                                       else if (!strcmp((char *)pAttr->children->content, "background-color") || !strcmp((char *)pAttr->children->content, "backgroundcolor"))
-                                               paramType = ATTRIBUTE_BGCOLOR;
-                                       else if (!strcmp((char *)pAttr->children->content, "textsize"))
-                                               paramType = ATTRIBUTE_SIZE;
-                                       else if (!strcmp((char *)pAttr->children->content, "textattribute"))
-                                               paramType = ATTRIBUTE_TEXTFORMAT;
-
-                                       if (cmd[ELEMENT_META])
-                                               strncpy(pMeta->szName, (char *)pAttr->children->content, MAX_SMIL_META_NAME - 1);
-                                       break;
-
-                               case ATTRIBUTE_VALUE:
-                                       if (paramType == ATTRIBUTE_SIZE && cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nSize = MmsSmilGetFontSizeValue((char *)pAttr->children->content);
-                                       else if (paramType == ATTRIBUTE_FGCOLOR && cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nColor =  MmsSmilGetColorValue(pAttr->children->content);
-                                       else if (paramType == ATTRIBUTE_BGCOLOR && cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nBgColor =  MmsSmilGetColorValue(pAttr->children->content);
-                                       else if (paramType == ATTRIBUTE_TEXTFORMAT && cmd[ELEMENT_TEXT]) {
-                                               MmsSmilFontType fontType;
-
-                                               fontType = MmsSmilGetFontTypeValue((char *)pAttr->children->content);
-
-                                               if (fontType == MMS_SMIL_FONT_TYPE_BOLD)
-                                                       pMedia->sMedia.sText.bBold = true;
-                                               else
-                                                       pMedia->sMedia.sText.bBold = false;
-
-                                               if (fontType == MMS_SMIL_FONT_TYPE_ITALIC)
-                                                       pMedia->sMedia.sText.bItalic = true;
-                                               else
-                                                       pMedia->sMedia.sText.bItalic = false;
-
-                                               if (fontType == MMS_SMIL_FONT_TYPE_UNDERLINE)
-                                                       pMedia->sMedia.sText.bUnderLine = true;
-                                               else
-                                                       pMedia->sMedia.sText.bUnderLine = false;
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_ALT:
-                                       strncpy(pMedia->szAlt, (char *)pAttr->children->content, MAX_SMIL_ALT_LEN - 1);
-                                       break;
-
-                               case ATTRIBUTE_TYPE:
-                                       pTransition->nType = (MmsSmilTransType)atoi((char *)pAttr->children->content);
-
-                                       switch (pTransition->nType) {
-                                       case MMS_SMIL_TRANS_SLIDEWIPE:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_FROM_LEFT;
-                                               break;
-                                       case MMS_SMIL_TRANS_BARWIPE:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_TOP_TO_BOTTOM;
-                                               break;
-                                       case MMS_SMIL_TRANS_BARNDOORWIPE:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_HORIZONTAL;
-                                               break;
-                                       default:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_NONE;
-                                               break;
-                                       }
-
-                                       break;
-
-                               case ATTRIBUTE_SUBTYPE:
-                                       pTransition->nSubType = (MmsSmilTransSubType)atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_CONTENT:
-                                       strncpy(pMeta->szContent, (char *)pAttr->children->content, MAX_SMIL_META_CONTENT - 1);
-                                       break;
-#ifdef MMS_SMIL_ANIMATE
-                               case ATTRIBUTE_ATTRIBUTE_NAME:
-                                       strcpy(pMedia->sMedia.sAVI.nAttributeName, (char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_ATTRIBUTE_TYPE:
-                                       strcpy(pMedia->sMedia.sAVI.nAttributeType, (char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_TARGET_ELEMENT:
-                                       strcpy(pMedia->sMedia.sAVI.nTargetElement, (char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_FROM:
-                                       pMedia->sMedia.sAVI.nFrom = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_TO:
-                                       pMedia->sMedia.sAVI.nTo = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_BY:
-                                       pMedia->sMedia.sAVI.nBy = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_VALUES:
-                                       pMedia->sMedia.sAVI.nValues = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_CALCMODE:
-                                       strcpy(pMedia->sMedia.sAVI.nCalcMode, (char *)pAttr->children->content);
-                                       break;
-#endif
-                               default:
-                                       MSG_DEBUG("Undefined Attribute was found!!!!!");
-                               }
-                       }
-
-                       if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_REGION]) {
-                               // Insert a region to region list
-                               _MsgMmsAddRegion(pMmsMsg, pRegion);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_PAR]) {
-                               //Insert a page to page list
-                               _MsgMmsAddPage(pMmsMsg, pPage);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && (cmd[ELEMENT_TEXT] ||cmd[ELEMENT_IMG] ||cmd[ELEMENT_AUDIO] ||cmd[ELEMENT_VIDEO] ||cmd[ELEMENT_ANIMATE])) {
-                               //Insert a media to media list
-                               _MsgMmsAddMedia(pPage, pMedia);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_ROOTLAYOUT]) {
-                               _MsgMmsSetRootLayout(pMmsMsg, &rootlayout);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_TRANSITION]) {
-                               //Insert a transition to transition list
-                               _MsgMmsAddTransition(pMmsMsg, pTransition);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_META]) {
-                               //Insert a meta to meta list
-                               _MsgMmsAddMeta(pMmsMsg, pMeta);
-                       }
-
-                       paramType = ATTRIBUTE_UNKNOWN;
-               }
-
-               MmsSmilGetElement(pMmsMsg, cur_node->children);
-       }
-
-       MSG_END();
-}
-
-
-int MmsSmilGetColorValue(xmlChar *content)
-{
-       int color;
-
-       if (content[0] == '#')  // RGB value
-               color = MmsSmilAtoIHexa((char *)&content[1]);
-       else if (content[0] == '0' && (content[1] == 'x' || content[1] == 'X'))
-               color = MmsSmilAtoIHexa((char *)&content[2]);
-       else {
-               MSG_DEBUG("Invalid Color Value");
-               color = -1;
-       }
-
-       return color;
-}
-
-int MmsSmilAtoIHexa(char *pInput)
-{
-       int res = 0;
-       int len = 0;
-       int temp = 1;
-       int i  = 0;
-       int j = 0;
-       char *pOutput = NULL;
-
-       MSG_DEBUG("__MmsSmilAtoIHexa() enter..\n");
-
-       len = strlen(pInput);
-       pOutput = (char *)malloc(len + 1);
-
-       if (pOutput == NULL) {
-               MSG_DEBUG("__MmsSmilAtoIHexa: Memory full \n");
-               goto __CATCH;
-       }
-
-       memset(pOutput, 0, len + 1);
-
-       for (i = len - 1; i >= 0; i--) {
-               for (j = 0; j < (len - 1 - i); j++) {
-                       temp *= 16;
-               }
-
-               switch (pInput[i]) {
-               case '0':
-                       pOutput[i] = 0;
-                       break;
-
-               case '1':
-                       pOutput[i] = 1;
-                       break;
-
-               case '2':
-                       pOutput[i] = 2;
-                       break;
-
-               case '3':
-                       pOutput[i] = 3;
-                       break;
-
-               case '4':
-                       pOutput[i] = 4;
-                       break;
-
-               case '5':
-                       pOutput[i] = 5;
-                       break;
-
-               case '6':
-                       pOutput[i] = 6;
-                       break;
-
-               case '7':
-                       pOutput[i] = 7;
-                       break;
-
-               case '8':
-                       pOutput[i] = 8;
-                       break;
-
-               case '9':
-                       pOutput[i] = 9;
-                       break;
-
-               case 'a':
-               case 'A':
-                       pOutput[i] = 10;
-                       break;
-
-               case 'b':
-               case 'B':
-                       pOutput[i] = 11;
-                       break;
-
-               case 'c':
-               case 'C':
-                       pOutput[i] = 12;
-                       break;
-
-               case 'd':
-               case 'D':
-                       pOutput[i] = 13;
-                       break;
-
-               case 'e':
-               case 'E':
-                       pOutput[i] = 14;
-                       break;
-
-               case 'f':
-               case 'F':
-                       pOutput[i] = 15;
-                       break;
-               }
-
-               res += (pOutput[i] * temp);
-               temp = 1;
-       }
-
-__CATCH:
-
-       if (pOutput) {
-               free(pOutput);
-               pOutput = NULL;
-       }
-
-       return res;
-}
-
-int MmsSmilGetTime(char *pValue)
-{
-       char *pTemp = NULL;
-       bool bMSec = false;
-       int retVal = 0;
-       int i = 0;
-       int len = 0;
-
-       if (pValue == NULL || pValue[0] == '\0')
-               return 0;
-
-       len = strlen(pValue);
-
-       /* Default time unit -> millisecond */
-       if (strstr(pValue, "msec"))
-               bMSec = true;
-
-       if (strstr(pValue, "ms"))
-               bMSec = true;
-
-       pTemp = (char *)malloc(strlen(pValue) + 1);
-
-       if (NULL == pTemp) {
-               MSG_DEBUG("__MmsSmilGetTime : malloc for <time> attribute is failed \n");
-               return 0;
-       }
-
-       while (isdigit(pValue[i])) {
-               pTemp[i] = pValue[i];
-               i++;
-       }
-       pTemp[i] = '\0';
-
-       /* Detect 's' and 'ms' here */
-       retVal = atoi(pTemp);
-
-       if (bMSec == false)
-               retVal *= 1000;
-
-       if (pTemp) {
-               free(pTemp);
-               pTemp = NULL;
-       }
-
-       return retVal;
-}
-#ifndef __SUPPORT_DRM__
-int MmsSmilGetMediaSrcForNormalMsg(char *szOutbuf, char *szInBuf, MsgMultipart *pPart)
-#else
-int MmsSmilGetMediaSrcForNormalMsg(char *szOutbuf, char *szInBuf, MsgMultipart *pPart, MMS_MEDIA_S *pMedia)
-#endif
-{
-       char szContentID[MSG_MSG_ID_LEN + 1] = {0, };
-       char szContentLI[MSG_MSG_ID_LEN + 1] = {0, };
-       int cLen  = 0;
-       int nPart = 0;
-
-       MSG_DEBUG("szInBuf: %s", szInBuf);
-       while (pPart && pPart->pBody) {
-               if (pPart->type.szContentID[0]) {
-                       cLen = strlen(pPart->type.szContentID);
-
-                       if (pPart->type.szContentID[0] == '<' && pPart->type.szContentID[cLen - 1] == '>') {
-                               strncpy(szContentID, &pPart->type.szContentID[1], cLen - 2);
-                               szContentID[cLen - 2] = '\0';
-                       } else if (pPart->type.szContentID[0] == MSG_CH_QUOT && pPart->type.szContentID[cLen-1] == MSG_CH_QUOT) {
-                               strncpy(szContentID, &pPart->type.szContentID[1], cLen - 2);
-                               szContentID[cLen - 2] = '\0';
-                       } else {
-                               strncpy(szContentID, pPart->type.szContentID, cLen);
-                               szContentID[cLen] = '\0';
-                       }
-               } else {
-                       szContentID[0] = '\0';
-               }
-
-               MSG_DEBUG("szContentID: %s", szContentID);
-
-               if (pPart->type.szContentLocation[0]) {
-                       cLen = strlen(pPart->type.szContentLocation);
-
-                       if (pPart->type.szContentLocation[0] == MSG_CH_QUOT &&
-                               pPart->type.szContentLocation[cLen-1] == MSG_CH_QUOT) {
-                               strncpy(szContentLI, &pPart->type.szContentLocation[1], cLen-2);
-                               szContentLI[cLen-2] = '\0';
-                       } else {
-                               strncpy(szContentLI, pPart->type.szContentLocation, cLen);
-                               szContentLI[cLen] = '\0';
-                       }
-               } else {
-                       szContentLI[0] = '\0';
-               }
-
-               MSG_DEBUG("szContentLocation: %s", szContentLI);
-
-               if (strcasecmp(szContentID, szInBuf) == 0) {
-                       strcpy(szOutbuf, pPart->type.param.szFileName);
-                       MSG_DEBUG("match with szContentID");
-                       goto RETURN;
-               } else if (strcasecmp(szContentLI, szInBuf) == 0) {
-                       strcpy(szOutbuf, pPart->type.param.szFileName);
-                       MSG_DEBUG("match with szContentLocation");
-                       goto RETURN;
-               } else if (strcasecmp(pPart->type.param.szName, szInBuf) == 0) {
-                       strcpy(szOutbuf, pPart->type.param.szFileName);
-                       MSG_DEBUG("match with Parameter Name");
-                       goto RETURN;
-               }
-
-               nPart++;
-               pPart = pPart->pNext;
-       }
-
-       return -1;
-
-RETURN:
-#ifdef __SUPPORT_DRM__
-       pMedia->drmType = pPart->type.drmInfo.drmType;
-
-       if (pPart->type.drmInfo.szDrm2FullPath != NULL) {
-               MSG_DEBUG("szDrm2FullPath: %s", pPart->type.drmInfo.szDrm2FullPath);
-               strncpy(pMedia->szDrm2FullPath, pPart->type.drmInfo.szDrm2FullPath, MSG_FILEPATH_LEN_MAX - 1);
-       }
-#endif
-       return nPart;
-
-}
-
-int    MmsSmilGetElementID(char *pString)
-{
-       if (!strcmp(pString, "smil"))
-               return ELEMENT_SMIL;
-       else if (!strcmp(pString, "head"))
-               return ELEMENT_HEAD;
-       else if (!strcmp(pString, "layout"))
-               return ELEMENT_LAYOUT;
-       else if (!strcmp(pString, "root-layout"))
-               return ELEMENT_ROOTLAYOUT;
-       else if (!strcmp(pString, "region"))
-               return ELEMENT_REGION;
-       else if (!strcmp(pString, "body"))
-               return ELEMENT_BODY;
-       else if (!strcmp(pString, "par"))
-               return ELEMENT_PAR;
-       else if (!strcmp(pString, "param"))
-               return ELEMENT_PARAM;
-       else if (!strcmp(pString, "text"))
-               return ELEMENT_TEXT;
-       else if (!strcmp(pString, "img"))
-               return ELEMENT_IMG;
-       else if (!strcmp(pString, "audio"))
-               return ELEMENT_AUDIO;
-       else if (!strcmp(pString, "video"))
-               return ELEMENT_VIDEO;
-       else if (!strcmp(pString, "ref"))
-               return ELEMENT_REF;
-       else if (!strcmp(pString, "animate"))
-               return ELEMENT_ANIMATE;
-       else if (!strcmp(pString, "root-layout"))
-               return ELEMENT_HEAD;
-       else if (!strcmp(pString, "transition"))
-               return ELEMENT_TRANSITION;
-       else if (!strcmp(pString, "meta"))
-               return ELEMENT_META;
-       else
-               return -1;
-}
-
-int    MmsSmilGetAttrID(char *pString)
-{
-       if (!strcmp(pString, "id"))
-               return ATTRIBUTE_ID;
-       else if (!strcmp(pString, "top"))
-               return ATTRIBUTE_TOP;
-       else if (!strcmp(pString, "left"))
-               return ATTRIBUTE_LEFT;
-       else if (!strcmp(pString, "width"))
-               return ATTRIBUTE_WIDTH;
-       else if (!strcmp(pString, "height"))
-               return ATTRIBUTE_HEIGHT;
-       else if (!strcmp(pString, "fit"))
-               return ATTRIBUTE_FIT;
-       else if (!strcmp(pString, "backgroundColor") || !strcmp(pString, "background-color"))
-               return ATTRIBUTE_BGCOLOR;
-       else if (!strcmp(pString, "dur"))
-               return ATTRIBUTE_DUR;
-       else if (!strcmp(pString, "src"))
-               return ATTRIBUTE_SRC;
-       else if (!strcmp(pString, "color"))
-               return ATTRIBUTE_COLOR;
-       else if (!strcmp(pString, "bold"))
-               return ATTRIBUTE_BOLD;
-       else if (!strcmp(pString, "underline"))
-               return ATTRIBUTE_UNDERLINE;
-       else if (!strcmp(pString, "italic"))
-               return ATTRIBUTE_ITALIC;
-       else if (!strcmp(pString, "reverse"))
-               return ATTRIBUTE_REVERSE;
-       else if (!strcmp(pString, "direction"))
-               return ATTRIBUTE_DIRECTION;
-       else if (!strcmp(pString, "size"))
-               return ATTRIBUTE_SIZE;
-       else if (!strcmp(pString, "font"))
-               return ATTRIBUTE_FONT;
-       else if (!strcmp(pString, "region"))
-               return ATTRIBUTE_REGION;
-       else if (!strcmp(pString, "name"))
-               return ATTRIBUTE_NAME;
-       else if (!strcmp(pString, "value"))
-               return ATTRIBUTE_VALUE;
-       else if (!strcmp(pString, "alt"))
-               return ATTRIBUTE_ALT;
-       else if (!strcmp(pString, "type"))
-               return ATTRIBUTE_TYPE;
-       else if (!strcmp(pString, "subtype"))
-               return ATTRIBUTE_SUBTYPE;
-       else if (!strcmp(pString, "content"))
-               return ATTRIBUTE_CONTENT;
-       else if (!strcmp(pString, "transIn"))
-               return ATTRIBUTE_TRANSIN;
-       else if (!strcmp(pString, "transOut"))
-               return ATTRIBUTE_TRANSOUT;
-       else if (!strcmp(pString, "begin"))
-               return ATTRIBUTE_BEGIN;
-       else if (!strcmp(pString, "end"))
-               return ATTRIBUTE_END;
-       else if (!strcmp(pString, "repeatCount"))
-               return ATTRIBUTE_REPEAT_COUNT;
-#ifdef MMS_SMIL_ANIMATE
-       else if (!strcmp(pString, "attributeName"))
-               return ATTRIBUTE_ATTRIBUTE_NAME;
-       else if (!strcmp(pString, "attributeType"))
-               return ATTRIBUTE_ATTRIBUTE_TYPE;
-       else if (!strcmp(pString, "targetElement"))
-               return ATTRIBUTE_TARGET_ELEMENT;
-       else if (!strcmp(pString, "from"))
-               return ATTRIBUTE_FROM;
-       else if (!strcmp(pString, "to"))
-               return ATTRIBUTE_TO;
-       else if (!strcmp(pString, "by"))
-               return ATTRIBUTE_BY;
-       else if (!strcmp(pString, "values"))
-               return ATTRIBUTE_VALUES;
-       else if (!strcmp(pString, "calcMode"))
-               return ATTRIBUTE_CALCMODE;
-#endif
-       else
-               return -1;
-}
-
-bool MmsSmilGetFontAttrib(char *pString)
-{
-       if (!strcmp(pString, "true"))
-               return true;
-       else
-               return false;
-}
-
-MmsTextDirection MmsSmilGetFontDirection(char *pString)
-{
-       MmsTextDirection direction = MMS_TEXT_DIRECTION_INVALID;
-
-       if (!strcmp(pString, "right"))
-               direction = MMS_TEXT_DIRECTION_RIGHT;
-       else if (!strcmp(pString, "down"))
-               direction = MMS_TEXT_DIRECTION_DOWN;
-
-       return direction;
-}
-
-int MmsSmilGetFontSizeValue(char *pString)
-{
-       MSG_DEBUG(" #### content = %s #### ", pString);
-       if (!strcmp(pString, "small"))
-               return MMS_SMIL_FONT_SIZE_SMALL;
-       else if (!strcmp(pString, "normal"))
-               return MMS_SMIL_FONT_SIZE_NORMAL;
-       else if (!strcmp(pString, "large"))
-               return MMS_SMIL_FONT_SIZE_LARGE;
-       else
-               return atoi(pString);
-}
-
-MmsSmilFontType MmsSmilGetFontTypeValue(char *pString)
-{
-       MSG_DEBUG(" #### content = %s #### ", pString);
-
-       if (!strcmp(pString, "normal"))
-               return MMS_SMIL_FONT_TYPE_NORMAL;
-       else if (!strcmp(pString, "italic"))
-               return MMS_SMIL_FONT_TYPE_ITALIC;
-       else if (!strcmp(pString, "bold"))
-               return MMS_SMIL_FONT_TYPE_BOLD;
-       else if (!strcmp(pString, "underline"))
-               return MMS_SMIL_FONT_TYPE_UNDERLINE;
-       else
-               return MMS_SMIL_FONT_TYPE_NORMAL;
-}
-
-bool MmsSmilGetMediaFilePath(MMS_MEDIA_S *pMedia, char *pszTemp, int msgID)
-{
-       if (!pMedia) {
-               MSG_DEBUG("pMedia is NULL");
-               return false;
-       }
-
-       snprintf(pMedia->szFilePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, pMedia->szSrc);
-       MSG_DEBUG("pMedia's filePath: %s", pMedia->szFilePath);
-
-       __MmsGetRealFileName(pMedia->mediatype, pMedia->szSrc, pMedia->szFileName, msgID);
-       MSG_DEBUG("pMedia's fileName: %s", pMedia->szFileName);
-
-       snprintf(pMedia->szContentID, MSG_MSG_ID_LEN+1, "%s", pszTemp);
-       MSG_DEBUG("pMedia's ContentID: %s", pMedia->szContentID);
-
-       return true;
-}
-
-
-/**    @fn             bool MMSGenerateSmilBuffer(MMS_MESSAGE_DATA_S *pstMsgBody)
- *     @brief  Forms Smil Buffer using pstMsgBody. \n
- *     @param[in/out]  pstMsgBody is Message handle. \n
- *     @retval TRUE                            In case of Success. \n
- *     @retval FALSE                           In case of failure. \n
- */
-bool MMSGenerateSmilBuffer(MMS_MESSAGE_DATA_S *pstMsgBody)
-{
-       HMmsSmil hSmilDoc = INVALID_HOBJ;
-       int nIndex;
-       int nMediaIndex;
-       int nTotalPageNum;
-       int nTotalMediaNum;
-       int nRegionCount;
-       MMS_PAGE_S *pstPage;
-       MMS_MEDIA_S *pstMedia;
-       MMS_SMIL_REGION *pstRegion;
-       char *pszRawData;
-
-       MSG_BEGIN();
-
-       hSmilDoc = MmsSmilCreateEmptySmilDoc();
-       MSG_DEBUG("Smil Doc =%d",hSmilDoc);
-       if (INVALID_HOBJ == hSmilDoc) {
-               MSG_DEBUG("Invalid SmilDoc[%d]",hSmilDoc);
-               return false;
-       }
-       // Add Root Layout to Smil Document
-       if (false == MmsSmilAddRootLayout(hSmilDoc, &(pstMsgBody->rootlayout))) {
-               MSG_DEBUG("MmsSmilAddRootLayout Failed");
-               MmsSmilDestroyDoc(hSmilDoc);
-       }
-       //Add Region list to Smil Document
-       nRegionCount = pstMsgBody->regionCnt;
-       MSG_DEBUG(" Region Count =%d",nRegionCount);
-       for (nIndex = 0; nIndex < nRegionCount; nIndex++) {
-               MSG_DEBUG("Calling _MsgMmsGetSmilRegion");
-               pstRegion = _MsgMmsGetSmilRegion(pstMsgBody, nIndex);
-               if (NULL == pstRegion) {
-                       MSG_DEBUG("pstRegion is NULL");
-                       MmsSmilDestroyDoc(hSmilDoc);
-                       return false;
-               }
-               MSG_DEBUG("Calling MmsSmilAddRegion");
-               if (false == MmsSmilAddRegion(hSmilDoc, pstRegion)) {
-                       MSG_DEBUG("Adding Region to smil doc failed");
-                       MmsSmilDestroyDoc(hSmilDoc);
-                       return false;
-               }
-       }
-       // Add page list to Smil Document
-        nTotalPageNum = pstMsgBody->pageCnt ;
-       MSG_DEBUG(" Page Count =%d",nTotalPageNum);
-       for (nIndex = 0; nIndex < nTotalPageNum; nIndex++) {
-               MSG_DEBUG("Calling _MsgMmsGetPage");
-               pstPage = _MsgMmsGetPage(pstMsgBody, nIndex);
-               if (NULL == pstPage) {
-                       MSG_DEBUG("pstPage is NULL");
-                       MmsSmilDestroyDoc(hSmilDoc);
-                       return false;
-               }
-               // Add page to smil doc
-               MSG_DEBUG("Calling MmsSmilAddPage");
-               if (false == MmsSmilAddPage(hSmilDoc, pstPage)) {
-                       MSG_DEBUG("Adding page to smil doc failed");
-                       MmsSmilDestroyDoc(hSmilDoc);
-                       return false;
-               }
-               nTotalMediaNum = pstPage->mediaCnt;
-               MSG_DEBUG(" Media Count =%d",nTotalMediaNum);
-               for (nMediaIndex = 0; nMediaIndex < nTotalMediaNum; nMediaIndex++) {
-                       MSG_DEBUG("Calling _MsgMmsGetMedia");
-                       pstMedia = _MsgMmsGetMedia(pstPage, nMediaIndex);
-                       if (NULL == pstMedia) {
-                               MSG_DEBUG("pMedia is NULL");
-                               MmsSmilDestroyDoc(hSmilDoc);
-                               return false;
-                       }
-                       MSG_DEBUG("Calling MmsSmilAddMedia");
-                       if (false == MmsSmilAddMedia(hSmilDoc, nIndex, nMediaIndex, pstMedia, pstMedia->szContentID)) {
-                               MSG_DEBUG("MmsSmilAddMedia failed");
-                               MmsSmilDestroyDoc(hSmilDoc);
-                               return false;
-                       }
-               }
-       }
-       MSG_DEBUG("MMSGenerateSmilBuffer: Start update template");
-       pszRawData = MmsSmilGetRawData(hSmilDoc);
-       if (NULL == pszRawData) {
-               MSG_DEBUG("MMSGenerateSmilBuffer: MmsSmilGetRawData failed");
-               MmsSmilDestroyDoc(hSmilDoc);
-               return false;
-       }
-
-       char fullpath[MSG_FILEPATH_LEN_MAX] = {0,};
-       snprintf(fullpath, MSG_FILEPATH_LEN_MAX, MSG_SMIL_FILE_PATH"%s", pstMsgBody->szSmilFilePath);
-
-       if (MsgWriteSmilFile(fullpath, pszRawData, strlen(pszRawData) + 1) == false) {
-               MSG_DEBUG("MMSGenerateSmilBuffer: MsgWriteSmilFile failed");
-               xmlFree((xmlChar*)pszRawData);
-               MmsSmilDestroyDoc(hSmilDoc);
-               return false;
-       }
-
-       MSG_DEBUG("MMSGenerateSmilBuffer: complete update template\n");
-       xmlFree((xmlChar*)pszRawData);
-       MmsSmilDestroyDoc(hSmilDoc);
-       MSG_END();
-       return true;
-}
-
-/**    @fn             static HMmsSmil MmsSmilCreateEmptySmilDoc(void)
- *     @brief  Creates default Smil Doc based on input gszEmptyRawDoc. \n
- *     @retval Returns Smil Document number. \n
- */
-HMmsSmil MmsSmilCreateEmptySmilDoc(void)
-{
-       HMmsSmil hMmsSmil;
-
-       MSG_BEGIN();
-
-       hMmsSmil = MmsSmilCreateSmilDoc(gszEmptyRawDoc);
-
-       MSG_DEBUG("Create an empty smilDoc.(Handle = %d)", hMmsSmil);
-
-       MSG_END();
-
-       return hMmsSmil;
-}
-
-/**    @fn                     static HMmsSmil MmsSmilCreateSmilDoc(char *pszRawData)
- *     @brief          Creates Smil Doc based on input pszRawData. \n
- *     @param[in]      pszRawData is smil buffer. \n
- *     @retval         Returns Smil Document number. \n
- */
-HMmsSmil MmsSmilCreateSmilDoc(char *pszRawData)
-{
-       int nSmilDocNo = 0;
-       xmlNodePtr stRootNode;
-
-       MSG_BEGIN();
-
-       // Destroy smil doc if present
-       if (NULL != __gpaMmsSmilDoc[nSmilDocNo]) {
-               MSG_DEBUG("Calling MmsSmilDestroyDoc");
-               if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
-                       MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
-               }
-       }
-
-       for (nSmilDocNo = 0; nSmilDocNo < MMS_SMIL_MAX_DOC; nSmilDocNo++) {
-               if (NULL == __gpaMmsSmilDoc[nSmilDocNo])
-                       break;
-       }
-
-       if (MMS_SMIL_MAX_DOC == nSmilDocNo) {
-               MSG_DEBUG("SmilDoc table is full. Can't create.");
-               return INVALID_HOBJ;
-       }
-       __gpaMmsSmilDoc[nSmilDocNo] = (MmsSmilDoc*)malloc(sizeof(MmsSmilDoc));
-       if (NULL ==  __gpaMmsSmilDoc[nSmilDocNo]) {
-               MSG_DEBUG("Memory Allocation Failed.");
-               return INVALID_HOBJ;
-       }
-       memset(__gpaMmsSmilDoc[nSmilDocNo], 0, sizeof(MmsSmilDoc));
-
-       __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc = xmlParseMemory(pszRawData, strlen(pszRawData));
-       if (NULL == __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc) {
-               MSG_DEBUG("Document not parsed successfully.");
-               if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
-                       MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
-               }
-               return INVALID_HOBJ;
-       }
-       stRootNode = xmlDocGetRootElement(__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc);
-       if (NULL == stRootNode) {
-               MSG_DEBUG("Empty document\n");
-               if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
-                       MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
-               }
-               return INVALID_HOBJ;
-       }
-       if (xmlStrcmp(stRootNode->name, (const xmlChar *) "smil")) {
-               MSG_DEBUG("Document of the wrong type, root node != smil");
-               if (false == MmsSmilDestroyDoc(nSmilDocNo)) {
-                       MSG_DEBUG("MmsSmilDestroyDoc: Failed!");
-               }
-               return INVALID_HOBJ;
-       }
-
-       __gpaMmsSmilDoc[nSmilDocNo]->pstRootNode = stRootNode;
-
-       MSG_END();
-       return ((HMmsSmil)nSmilDocNo);
-}
-
-/**    @fn                     static bool MmsSmilDestroyDoc(HMmsSmil hSmilDoc)
- *     @brief          Destroys Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @retval TRUE                            In case of Success. \n
- *     @retval FALSE                           In case of failure. \n
- */
-bool MmsSmilDestroyDoc(HMmsSmil hSmilDoc)
-{
-       int nSmilDocNo = (int)hSmilDoc;
-       bool bFlag = true;
-       MSG_BEGIN();
-
-       if (0 <= nSmilDocNo &&
-               nSmilDocNo < MMS_SMIL_MAX_DOC &&
-               __gpaMmsSmilDoc[nSmilDocNo]) {
-               if (__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc) {
-                       xmlFreeDoc(__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc);
-               }
-
-               if (__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode) {
-                       //Need to Check
-               }
-               free(__gpaMmsSmilDoc[nSmilDocNo]);
-               __gpaMmsSmilDoc[nSmilDocNo] = NULL;
-       } else {
-               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
-               bFlag =  false;
-       }
-
-       MSG_END();
-       return bFlag;
-}
-
-/**    @fn                     static bool IsValidSmilDocNo(int nSmilDocNo)
- *     @brief          Form Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @retval         Returns Smil Buffer     In case of success. \n
- *     @retval         Returns NULL                    In case of failure. \n
- */
-bool IsValidSmilDocNo(int nSmilDocNo)
-{
-       bool bIsValidSmil = false;
-
-       MSG_BEGIN();
-
-       if (0 <= nSmilDocNo &&
-               nSmilDocNo < MMS_SMIL_MAX_DOC &&
-               __gpaMmsSmilDoc[nSmilDocNo] &&
-               __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc) {
-               bIsValidSmil = true;
-       }
-
-       MSG_END();
-       return bIsValidSmil;
-}
-
-/**    @fn                     static char  MmsSmilGetRawData(HMmsSmil hSmilDoc)
- *     @brief          Form Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @retval         Returns Smil Buffer     In case of success. \n
- *     @retval         Returns NULL                    In case of failure. \n
- */
-char *MmsSmilGetRawData(HMmsSmil hSmilDoc)
-{
-       int nSmilDocNo = (int)hSmilDoc;
-       char *pszRawData = NULL;
-
-       MSG_BEGIN();
-
-       if (IsValidSmilDocNo(nSmilDocNo)) {
-               xmlSaveFormatFileEnc("-", __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc, "UTF-8", 1);
-               xmlDocDumpMemory(__gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc, (xmlChar **)(&pszRawData) , NULL);
-               if (NULL == pszRawData) {
-                       MSG_DEBUG("Invalid pSmilDoc (now wellformed document)");
-               }
-               MSG_END();
-       } else {
-               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
-       }
-       return pszRawData;
-}
-
-/**    @fn                     static bool MmsSmilAddPage(HMmsSmil hSmilDoc, MMS_PAGE_S *pstSmilPage)
- *     @brief          Add Page to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      pstSmilPage specifies page information. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddPage(HMmsSmil hSmilDoc, MMS_PAGE_S *pstSmilPage)
-{
-       int nSmilDocNo = hSmilDoc;
-
-       MSG_BEGIN();
-
-       bool ret = true;
-
-       if (IsValidSmilDocNo(nSmilDocNo)) {
-               xmlNodePtr pstParElement;
-               xmlNodePtr pstBodyElement;
-               xmlNodePtr pstParList;
-               char szBuf[MSG_STDSTR_SHORT] = {0, };
-
-               pstBodyElement = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"body");
-
-               if (NULL == pstBodyElement) {
-                       MSG_DEBUG("There is no <body> node. Can't create <par> node.");
-                       return false;
-               }
-               MSG_DEBUG("Body Element Name = %s", (char *)pstBodyElement->name);
-               /* Create "par"  node and insert it */
-               pstParElement = xmlNewNode(NULL, (xmlChar *)"par");
-
-               if (NULL == pstParElement) {
-                       MSG_DEBUG("Can't create <par> node. (from XmlParser) \n");
-                       return false;
-               }
-               MSG_DEBUG("Par Element Name = %s", (char *)pstParElement->name);
-
-               /* Add attributes to "par" */
-               if (pstSmilPage->nDur > 0) {
-                       snprintf(szBuf, MSG_STDSTR_SHORT, "%dms", pstSmilPage->nDur);
-                       xmlSetProp(pstParElement, (const xmlChar *)"dur", (const xmlChar *)szBuf);
-               }
-               /* Find the insertion point : right sibling of the last <par> node or first child of <body> */
-
-               pstParList = xmlGetLastChild(pstBodyElement);
-
-               if (pstParList) {
-                       ret = __MmsSmilInsertNode(pstBodyElement, pstParList, pstParElement);
-               } else {
-                       ret = __MmsInsertFirstChild(pstBodyElement, pstParElement);
-               }
-       } else {
-               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
-               return false;
-       }
-
-       return ret;
-}
-
-/**    @fn                     static bool MmsSmilAddRootLayout(HMmsSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout)
- *     @brief          Add Rootlayout to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      pstSmilRootLayout specifies RootLayout information. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddRootLayout(HMmsSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout)
-{
-       int nSmilDocNo = hSmilDoc;
-       xmlNodePtr pstRootLayout = NULL;
-       xmlNodePtr pstLayoutList = NULL;
-       xmlNodePtr pstRootLayoutList = NULL;
-       char szBuf[MSG_STDSTR_SHORT] = {0, };
-
-       MSG_BEGIN();
-
-       if (IsValidSmilDocNo(nSmilDocNo)) {
-               pstLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"layout");
-
-               if (NULL == pstLayoutList) {
-                       MSG_DEBUG("There is no <layout> node. Can't create <root-layout> node.");
-                       return false;
-               }
-               MSG_DEBUG("Layout Element Name = %s ", (char *)pstLayoutList->name);
-
-               pstRootLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"root-layout");
-
-               if (NULL != pstRootLayoutList) {
-                       MSG_DEBUG("MmsSmilAddRootLayout: There is <root-layout> node already");
-                       MSG_DEBUG("Root Layout Element Name = %s  type=%d\n", (char *)pstRootLayoutList->name);
-                       return false;
-               }
-               /* Create "root-layout" node and insert it */
-               pstRootLayout = xmlNewNode(NULL, (xmlChar *)"root-layout");
-               if (NULL == pstRootLayout) {
-                       MSG_DEBUG("Can't create <root-layout> node. (from XmlParser)");
-                       return false;
-               }
-               MSG_DEBUG("Root Layout Element Name = %s", (char *)pstRootLayout->name);
-
-               if (pstSmilRootLayout->bBgColor == true) {      // Replace value later
-                       xmlSetProp(pstRootLayout, (const xmlChar *)"backgroundColor", (const xmlChar *)__MmsSmilFindColorValue(pstSmilRootLayout->bgColor));
-               }
-
-               MSG_DEBUG(" Set Width");
-               if (true == pstSmilRootLayout->width.bUnitPercent) {
-                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRootLayout->width.value);
-                       xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)szBuf);
-               } else {
-                       if (pstSmilRootLayout->width.value > 0) {
-                               snprintf(szBuf, MSG_STDSTR_SHORT, "%d", pstSmilRootLayout->width.value);
-                               xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)szBuf);
-                       } else {
-                               xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)"100%");
-                       }
-               }
-               MSG_DEBUG(" Set Height");
-               if (true == pstSmilRootLayout->height.bUnitPercent) {
-                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRootLayout->height.value);
-                       xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)szBuf);
-               } else {
-                       if (pstSmilRootLayout->height.value > 0) {
-                               snprintf(szBuf, MSG_STDSTR_SHORT, "%d", pstSmilRootLayout->height.value);
-                               xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)szBuf);
-                       } else {
-                               xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)"100%");
-                       }
-               }
-               __MmsInsertFirstChild(pstLayoutList, pstRootLayout);
-
-               return true;
-       } else {
-               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
-               return false;
-       }
-
-}
-
-
-/**    @fn                     static bool MmsSmilAddRegion(HMmsSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion)
- *     @brief          Add Region to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      pstSmilRegion specifies Region information. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddRegion(HMmsSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion)
-{
-       int nSmilDocNo = hSmilDoc;
-
-       MSG_BEGIN();
-
-       if (IsValidSmilDocNo(nSmilDocNo)) {
-               int nRootWidth = 0;
-               int nRootHeight = 0;
-               xmlNodePtr pstRegion;
-               xmlNodePtr pstLayoutList;
-               xmlNodePtr pstRootLayoutList;
-               xmlAttrPtr pAttribute;
-               char szBuf[MSG_STDSTR_SHORT] = {0, };
-
-               pstLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"layout");
-               if (NULL == pstLayoutList) {
-                       MSG_DEBUG(" There is no <layout> node. Can't create <region> node");
-                       return false;
-               }
-               MSG_DEBUG("Layout Element Name = %s ", (char *)pstLayoutList->name);
-
-               /* Find the insertion point : right sibling of the last root-layout node or first child of pLayout */
-               pstRootLayoutList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"root-layout");
-
-               if (NULL == pstRootLayoutList) {
-                       MSG_DEBUG("There is no <root-layout> node. Can't create <root-layout> node.");
-                       return false;
-               } else {
-                       MSG_DEBUG("Root Layout Element Name = %s ", (char *)pstRootLayoutList->name);
-                       pAttribute =  pstRootLayoutList->properties;
-               }
-
-               if (NULL == pAttribute) {
-                       MSG_DEBUG("There is no Attribute in <root-layout> node.");
-                       return false;
-               }
-
-               xmlAttrPtr pstAttr = pAttribute;
-               for ( ; pstAttr; pstAttr = pstAttr->next) {
-                       int     attrType;
-                       MSG_DEBUG("AttributeType: (%s, %s) ", pstAttr->name, pstAttr->children->content);
-                       switch (attrType = MmsSmilGetAttrID((char *)pstAttr->name)) {
-                       case ATTRIBUTE_WIDTH:
-                               {
-                                       int bUnitPercent;
-
-                                       if (strchr((char *)pstAttr->children->content, '%'))
-                                               bUnitPercent = true;
-                                       else
-                                               bUnitPercent = false;
-
-                                       nRootWidth = atoi((char *)pstAttr->children->content);
-                               }
-                               break;
-
-                       case ATTRIBUTE_HEIGHT:
-                               {
-                                       int bUnitPercent;
-
-                                       if (strchr((char *)pstAttr->children->content, '%'))
-                                               bUnitPercent = true;
-                                       else
-                                               bUnitPercent = false;
-
-                                       nRootHeight = atoi((char *)pstAttr->children->content);
-                               }
-                               break;
-                       }
-               }
-
-               /* Create "region" node and insert it */
-               MSG_DEBUG("Create Region Node");
-               pstRegion = xmlNewNode(NULL, (xmlChar *)"region");
-               if (NULL == pstRegion) {
-                       MSG_DEBUG("Can't create <region> node. (from XmlParser)");
-                       return false;
-               }
-               /* Add attributes */
-               if (pstSmilRegion) {
-                       MSG_DEBUG(" [Set Attribute] : Region Id");
-                       if (strlen(pstSmilRegion->szID) > 0) {
-                               xmlSetProp(pstRegion, (const xmlChar *)"id", (const xmlChar *)pstSmilRegion->szID);
-                       }
-
-                       if (pstSmilRegion->bBgColor == true) {
-                               MSG_DEBUG(" [Set Attribute] : BkGrd Color");
-                               xmlSetProp(pstRegion, (const xmlChar *)"backgroundColor", (const xmlChar *)__MmsSmilFindColorValue(pstSmilRegion->bgColor));
-                       }
-
-                       MSG_DEBUG(" [Set Attribute] : Width");
-
-                       if (true == pstSmilRegion->width.bUnitPercent) {
-                               if (pstSmilRegion->width.value > 0) {
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->width.value);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"width", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->width = %d   \n", pstSmilRegion->width.value);
-                               }
-                       } else {
-                               // Note: nRootWidth should be in terms of value(pixel) not unitpercent(%)
-                               // Validation should be done before this.
-                               if (pstSmilRegion->width.value >= 0 &&
-                                       pstSmilRegion->width.value <= nRootWidth) {
-                                       int iWidth = (pstSmilRegion->width.value * 100) / nRootWidth;
-
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iWidth);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"width", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->width= %d  iWidth = %d \n", pstSmilRegion->width.value, iWidth);
-                               }
-                       }
-                       MSG_DEBUG(" [Set Attribute] : Height");
-                       if (true == pstSmilRegion->height.bUnitPercent) {
-                               if (pstSmilRegion->height.value > 0) {
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->height.value);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"height", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->height = %d   \n", pstSmilRegion->height.value);
-                               }
-                       } else {
-                               // Note: nRootHeight should be in terms of value(pixel) not unitpercent(%)
-                               // Validation should be done before this.
-                               if (pstSmilRegion->height.value >= 0 &&
-                                       pstSmilRegion->height.value <= nRootHeight) {
-                                       int iHeight = (pstSmilRegion->height.value * 100) / nRootHeight;
-
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iHeight);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"height", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->height = %d  iHeight = %d \n", pstSmilRegion->height.value, iHeight);
-                               }
-                       }
-                       MSG_DEBUG(" [Set Attribute] : Left");
-                       if (true == pstSmilRegion->nLeft.bUnitPercent) {
-                               if (pstSmilRegion->nLeft.value > 0) {
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->nLeft.value);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"left", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->left = %d   \n", pstSmilRegion->nLeft.value);
-                               }
-                       } else {
-                               // Note: nRootWidth should be in terms of value(pixel) not unitpercent(%)
-                               // Validation should be done before this.
-                               if (pstSmilRegion->nLeft.value >= 0) {
-                                       int iLeft = (pstSmilRegion->nLeft.value * 100) / nRootWidth;
-
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iLeft);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"left", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: SmilRegion->iLeft = %d       iLeft = %d \n", pstSmilRegion->nLeft.value, iLeft);
-                               }
-                       }
-                       MSG_DEBUG(" [Set Attribute] : Top");
-                       if (true == pstSmilRegion->nTop.bUnitPercent) {
-                               if (pstSmilRegion->nTop.value > 0) {
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->nTop.value);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"top", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->nTop= %d   \n", pstSmilRegion->nTop.value);
-                               }
-                       } else {
-                               // Note: nRootHeight should be in terms of value(pixel) not unitpercent(%)
-                               // Validation should be done before this.
-                               if (pstSmilRegion->nTop.value >= 0) {
-                                       int iTop = (pstSmilRegion->nTop.value * 100) / nRootHeight;
-
-                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iTop);
-                                       xmlSetProp(pstRegion, (const xmlChar *)"top", (const xmlChar *)szBuf);
-                                       MSG_DEBUG("MmsSmilAddRegion: pstSmilRegion->nTop= %d  iTop = %d \n", pstSmilRegion->nTop.value, iTop);
-                               }
-                       }
-                       MSG_DEBUG(" [Set Attribute] : Fit");
-                       //Fit Attribute
-                       if (MMSUI_IMAGE_REGION_FIT_MEET == pstSmilRegion->fit) {
-                               xmlSetProp(pstRegion, (const xmlChar *)"fit", (const xmlChar *)"meet");
-                       } else if (MMSUI_IMAGE_REGION_FIT_HIDDEN == pstSmilRegion->fit) {
-                               xmlSetProp(pstRegion, (const xmlChar *)"fit", (const xmlChar *)"hidden");
-                       }
-
-                       __MmsSmilInsertNode(pstLayoutList, pstRootLayoutList, pstRegion);
-
-               } else
-                       MSG_DEBUG("There is no attribute in <region> node\n");
-
-               MSG_END();
-               return true;
-       } else {
-               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)\n", nSmilDocNo);
-               return false;
-       }
-}
-
-/**    @fn                     static bool MmsSmilAddMedia( HMmsSmil hSmilDoc, int nPageNo, MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
- *     @brief          Add Media to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      nPageNo specifies page number to which media belongs. \n
- *     @param[in]      pstSmilMedia specifies Media information. \n
- *     @param[in]      pszContentID specifies Content ID of media. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddMedia( HMmsSmil hSmilDoc, int nPageNo, int nMediaIdx, MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
-{
-       int nSmilDocNo = hSmilDoc;
-
-       MSG_BEGIN();
-
-       if (NULL == pszContentID) {
-               MSG_DEBUG(" Content Id is NULL");
-               return false;
-       }
-       memset(pszContentID, 0, MMS_CONTENT_ID_LEN + 1);
-       if (IsValidSmilDocNo(nSmilDocNo)) {
-               int nIndex = 0;
-               xmlNode *pstMedia;
-               xmlNode *pstLastChild;
-               xmlNodePtr pstParList;
-               char *pszExt ;
-
-               pstParList = UtilxmlStringGetNodeList(__gpaMmsSmilDoc[nSmilDocNo]->pstRootNode, (char *)"par");
-               if (NULL == pstParList) {
-                       MSG_DEBUG("There is no <par> node. Can't create <media> node.");
-                       return false;
-               }
-               MSG_DEBUG("Par Element Name = %s ", (char *)pstParList->name);
-               for (nIndex = 0; (pstParList &&  nIndex < nPageNo); nIndex++) {
-                       pstParList = pstParList->next;
-               }
-               if (NULL == pstParList) {
-                       MSG_DEBUG("There is no such page node. Can't insert <media> node.");
-                       return false;
-               }
-               MSG_DEBUG("Par Element Name = %s ", (char *)pstParList->name);
-               /* Find insertion point and make a contentID */
-
-               pstLastChild = xmlGetLastChild(pstParList);
-
-               pszExt = strrchr(pstSmilMedia->szFileName, '.');
-               if (pszExt && !strrchr(pszExt, '/'))
-                       snprintf(pszContentID, MSG_MSG_ID_LEN+1, "%lu_%lu%s", (ULONG)nPageNo, (ULONG)nMediaIdx, pszExt);
-               else
-                       snprintf(pszContentID, MSG_MSG_ID_LEN+1, "%lu_%lu", (ULONG)nPageNo, (ULONG)nMediaIdx);
-
-               /* Create <media> node and insert set attribute */
-               MSG_DEBUG(" Create Media Node");
-               switch (pstSmilMedia->mediatype) {
-               case MMS_SMIL_MEDIA_TEXT:
-                       pstMedia = __MmsCreateTextNode(pstSmilMedia, pszContentID);
-                       break;
-               case MMS_SMIL_MEDIA_AUDIO:
-               case MMS_SMIL_MEDIA_VIDEO:
-               case MMS_SMIL_MEDIA_IMG:
-                       pstMedia = __MmsCreateMMNode(pstSmilMedia, pszContentID);
-                       break;
-               default:
-                       MSG_DEBUG("Invalid media type. Can't insert such-<media> node.");
-                       return false;
-               }
-
-               if (NULL == pstMedia) {
-                       MSG_DEBUG("Can't create <media> node. (from XmlParser) (media-type:%d)", pstSmilMedia->mediatype);
-                       return false;
-               }
-
-               /* Find the insertion point : the last child of <par> node */
-               if (pstLastChild)
-                       __MmsSmilInsertNode(pstParList, pstLastChild, pstMedia);
-               else
-                       __MmsInsertFirstChild(pstParList, pstMedia);
-
-               MSG_END();
-               return true;
-       } else {
-               MSG_DEBUG("MmsSmilAddMedia: Invalid SmilDoc(hSmilDoc:%d)\n", nSmilDocNo);
-               return false;
-       }
-}
-
-/**    @fn                     static xmlNode *__MmsCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
- *     @brief          Create Text Element. \n
- *     @param[in]      pstSmilMedia specifies Media information. \n
- *     @param[in]      pszContentID specifies Content ID of media. \n
- *     @retval         Text Element node               In case of Success. \n
- *     @retval         NULL                            In case of failure. \n
- */
-xmlNode *__MmsCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
-{
-       xmlNode *pstMedia = NULL;
-       xmlNode *pstParam = NULL;
-       char szBuf[MSG_STDSTR_SHORT] = {0, };
-       char szSizeBuf[MSG_STDSTR_SHORT] = {0, };
-
-       MSG_BEGIN();
-
-       pstMedia = xmlNewNode(NULL, (xmlChar *)"text");
-       if (NULL == pstMedia) {
-               MSG_DEBUG("Can't create <Text> node.");
-               return NULL;
-       }
-       MSG_DEBUG("Text Element Name = %s ", (char *)pstMedia->name);
-
-       /* Add attributes */
-       if (pstSmilMedia) {
-               MSG_DEBUG("[Set Attribute] Region Id ");
-               if (strlen(pstSmilMedia->regionId) > 0) {
-                       xmlSetProp(pstMedia, (const xmlChar *)"region", (const xmlChar *)pstSmilMedia->regionId);
-               }
-               MSG_DEBUG("[Set Attribute] Begin ");
-               if (pstSmilMedia->sMedia.sText.nBegin > 0) {
-                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sText.nBegin);
-                       xmlSetProp(pstMedia, (const xmlChar *)"begin", (const xmlChar *) szBuf);
-               }
-               MSG_DEBUG("[Set Attribute] Duration");
-               if (pstSmilMedia->sMedia.sText.nDurTime > 0) {
-                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sText.nDurTime);
-                       xmlSetProp(pstMedia, (const xmlChar *)"dur", (const xmlChar *)szBuf);
-               }
-               MSG_DEBUG("[Set Attribute] Alternate");
-               if (strlen(pstSmilMedia->szAlt) > 0) {
-                       snprintf (szBuf, sizeof(szBuf), "%s", pstSmilMedia->szAlt);
-                       xmlSetProp(pstMedia, (const xmlChar *)"alt", (const xmlChar *)szBuf);
-               }
-               MSG_DEBUG("[Set Attribute] Src");
-
-               char szFilePathWithCid[MMS_CONTENT_ID_LEN + 5]; // for "cid:"
-
-               snprintf (szFilePathWithCid, sizeof(szFilePathWithCid), "cid:%s", pszContentID);
-               _MmsSmilSetAttribute(pstMedia, (char *)"src", szFilePathWithCid);
-
-               MSG_DEBUG("[Set Attribute] Font Foreground Color");
-
-               if (pstSmilMedia->sMedia.sText.nColor!= SP_BLACK) {     // Chnage after getting exact values
-                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
-
-                       if (NULL == pstParam) {
-                               MSG_DEBUG("Cannot create <param> node");
-                               return false;
-                       }
-                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"foreground-color");
-                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)__MmsSmilFindColorValue(pstSmilMedia->sMedia.sText.nColor));
-                       __MmsInsertFirstChild(pstMedia, pstParam);
-               }
-
-               MSG_DEBUG("[Set Attribute] Font Background Color");
-
-               if (pstSmilMedia->sMedia.sText.nBgColor != SP_BLACK) {  // Chnage after getting exact values
-                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
-
-                       if (NULL == pstParam) {
-                               MSG_DEBUG("Cannot create <param> node");
-                               return false;
-                       }
-                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"background-color");
-                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)__MmsSmilFindColorValue(pstSmilMedia->sMedia.sText.nBgColor));
-                       __MmsInsertFirstChild(pstMedia, pstParam);
-               }
-
-               MSG_DEBUG("[Set Attribute] Size");
-               if (pstSmilMedia->sMedia.sText.nSize > 0) {
-                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
-                       if (NULL == pstParam) {
-                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
-                               return false;
-                       }
-
-                       if (pstSmilMedia->sMedia.sText.nSize  <= MMS_SMIL_FONT_SIZE_SMALL)
-                               strcpy(szSizeBuf, "small");
-                       else if ((pstSmilMedia->sMedia.sText.nSize  > MMS_SMIL_FONT_SIZE_SMALL) && (pstSmilMedia->sMedia.sText.nSize  < MMS_SMIL_FONT_SIZE_LARGE))
-                               strcpy(szSizeBuf, "normal");
-                       else
-                               strcpy(szSizeBuf, "large");
-
-                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textsize");
-                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
-                       __MmsInsertFirstChild(pstMedia, pstParam);
-               }
-
-               if (pstSmilMedia->sMedia.sText.bBold == true) {
-                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
-                       if (NULL == pstParam) {
-                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
-                               return false;
-                       }
-
-                       strcpy(szSizeBuf, "bold");
-
-                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
-                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
-                       __MmsInsertFirstChild(pstMedia, pstParam);
-               }
-
-               if (pstSmilMedia->sMedia.sText.bItalic == true) {
-                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
-                       if (NULL == pstParam) {
-                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
-                               return false;
-                       }
-
-                       strcpy(szSizeBuf, "italic");
-
-                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
-                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
-                       __MmsInsertFirstChild(pstMedia, pstParam);
-               }
-
-               if (pstSmilMedia->sMedia.sText.bUnderLine == true) {
-                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
-                       if (NULL == pstParam) {
-                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node \n");
-                               return false;
-                       }
-
-                       strcpy(szSizeBuf, "underline");
-
-                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
-                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
-                       __MmsInsertFirstChild(pstMedia, pstParam);
-               }
-       }
-
-       MSG_END();
-       return pstMedia;
-}
-
-/**    @fn                     static xmlNode *__MmsCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
- *     @brief          Create Image/Audio/Video Element. \n
- *     @param[in]      pstSmilMedia specifies Media information. \n
- *     @param[in]      pszContentID specifies Content ID of media. \n
- *     @retval         Image/Audio/Video Element node  In case of Success. \n
- *     @retval         NULL                                                    In case of failure. \n
- */
-xmlNode *__MmsCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
-{
-       xmlNode *pstMedia = NULL;
-       char szBuf[MSG_STDSTR_SHORT] = {0, };
-
-       MSG_BEGIN();
-
-       if (!pstSmilMedia)
-               return NULL;
-
-       switch (pstSmilMedia->mediatype) {
-       case MMS_SMIL_MEDIA_AUDIO:
-               pstMedia = xmlNewNode(NULL, (xmlChar *)"audio");
-               break;
-
-       case MMS_SMIL_MEDIA_VIDEO:
-               pstMedia = xmlNewNode(NULL, (xmlChar *)"video");
-               break;
-
-       case MMS_SMIL_MEDIA_IMG:
-               pstMedia = xmlNewNode(NULL, (xmlChar *)"img");
-               break;
-       default:
-               MSG_DEBUG("Invalid media type. Can't insert such-<media> node.");
-               return NULL;
-       }
-
-       if (pstMedia) {
-               char szFilePathWithCid[MMS_CONTENT_ID_LEN + 5];         // for "cid:"
-
-               MSG_DEBUG("[Set Attribute] Region Id ");
-               if (strlen(pstSmilMedia->regionId) > 0) {
-                       xmlSetProp(pstMedia, (const xmlChar *)"region", (const xmlChar *)pstSmilMedia->regionId);
-               }
-               MSG_DEBUG("[Set Attribute] Src ");
-               snprintf (szFilePathWithCid, sizeof(szFilePathWithCid), "cid:%s", pszContentID);
-               _MmsSmilSetAttribute(pstMedia, (char *)"src", szFilePathWithCid);
-
-               MSG_DEBUG("[Set Attribute] Begin ");
-               if (pstSmilMedia->sMedia.sAVI.nBegin > 0) {
-                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sAVI.nBegin);
-                       xmlSetProp(pstMedia, (const xmlChar *)"begin", (const xmlChar *)szBuf);
-               }
-               MSG_DEBUG("[Set Attribute] Duration ");
-               if (pstSmilMedia->sMedia.sAVI.nDurTime > 0) {
-                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sAVI.nDurTime);
-                       xmlSetProp(pstMedia, (const xmlChar *)"dur", (const xmlChar *)szBuf);
-               }
-               MSG_DEBUG("[Set Attribute] Alt ");
-               if (strlen(pstSmilMedia->szAlt) > 0) {
-                       snprintf (szBuf, sizeof(szBuf), "%s", pstSmilMedia->szAlt);
-                       xmlSetProp(pstMedia, (const xmlChar *)"alt", (const xmlChar *)szBuf);
-               }
-       } else {
-               MSG_DEBUG("There is no attribute in such-<media> node");
-       }
-
-       MSG_END();
-       return pstMedia;
-}
-
-/**    @fn                     static bool __MmsInsertFirstChild(xmlNode *pstParent, xmlNode *pstCurr)
- *     @brief          Inserts first child to parent node. \n
- *     @param[in]      pstParent specifies Parent node. \n
- *     @param[in]      pstCurr specifies Child node. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool __MmsInsertFirstChild(xmlNode *pstParent, xmlNode *pstCurr)
-{
-       bool bFlag = true;
-
-       MSG_BEGIN();
-
-        if (NULL == xmlAddChild(pstParent, pstCurr)) {
-               MSG_DEBUG("%s Node not added", pstCurr->name);
-               bFlag = false;
-        }
-
-        MSG_END();
-        return bFlag;
-}
-
-
-/**    @fn                     static bool __MmsSmilInsertNode(xmlNode *pstParent, xmlNode *pstLeftSibling, xmlNode *pstCurr)
- *     @brief          Inserts node. \n
- *     @param[in]      pstParent specifies Parent node. \n
- *     @param[in]      pstLeftSibling specifies Left Sibling node. \n
- *     @param[in]      pstCurr specifies Child node. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool __MmsSmilInsertNode(xmlNode *pstParent, xmlNode *pstLeftSibling, xmlNode *pstCurr)
-{
-       MSG_BEGIN();
-       bool bFlag = true;
-
-       if (pstLeftSibling) {
-               /* Parent Node is Unused */
-
-               while (pstLeftSibling->next !=NULL)
-                       pstLeftSibling = pstLeftSibling->next;
-
-                if (NULL == xmlAddNextSibling(pstLeftSibling, pstCurr)) {
-                       MSG_DEBUG("%s Node not added", pstCurr->name);
-                       bFlag = false;
-                }
-       } else {
-                if (NULL == xmlAddChild(pstParent, pstCurr)) {
-                        MSG_DEBUG("%s Node not added", pstCurr->name);
-                       bFlag = false;
-                }
-       }
-       MSG_END();
-       return bFlag;
-}
-
-
-bool __MmsGetRealFileName(MmsSmilMediaType mediaType, char *pszSrc, char *pszName, int msgID)
-{
-       MsgType partHeader;
-       int partCnt;
-       int i;
-
-       MSG_DEBUG("__MmsUiGetRealFileName: mediaType[%d]", mediaType);
-       MSG_DEBUG("__MmsUiGetRealFileName: pszSrc[%s]\n", pszSrc);
-
-       if (!pszName) {
-               MSG_DEBUG("__MmsUiGetRealFileName: pszName is null\n");
-               return false;
-       }
-
-       if (mediaType == MMS_SMIL_MEDIA_TEXT || mediaType == MMS_SMIL_MEDIA_INVALID) {
-               MSG_DEBUG("__MmsUiGetRealFileName: invalid mediaType(=%d)\n", mediaType);
-               return false;
-       }
-
-       partCnt = MmsGetMediaPartCount(msgID);
-
-       if (partCnt < 0) {
-               MSG_DEBUG("__MmsUiGetRealFileName: partCnt < 0, (=%d)\n", partCnt);
-               return false;
-       }
-
-       for (i = 0; i < partCnt; i++) {
-               MmsGetMediaPartHeader(i, &partHeader);
-
-               if (mediaType == MMS_SMIL_MEDIA_AUDIO ||
-                       mediaType == MMS_SMIL_MEDIA_VIDEO ||
-                       mediaType == MMS_SMIL_MEDIA_IMG) {
-                       if (!strcmp(partHeader.param.szFileName , pszSrc)) {
-                               // Found
-                               MSG_DEBUG("__MmsUiGetRealFileName: pszSrc[%s]\n", pszSrc);
-                               break;
-                       }
-               }
-       }
-
-       if (i == partCnt)
-               return false;
-
-       if (partHeader.param.szName[0] != '\0') {
-               int nameLen = strlen(partHeader.param.szName);
-
-               if (nameLen > MSG_FILENAME_LEN_MAX - 1) {
-                       ;//Need to check
-               } else {
-                       strcpy(pszName, partHeader.param.szName);
-               }
-
-               return true;
-       }
-       return false;
-}
-
-/**    @fn                     static void _MmsSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue)
- *     @brief          Sets Attribute. \n
- *     @param[in]      pNode specifies node. \n
- *     @param[in]      szField specifies attribute field. \n
- *     @param[in]      szValue specifies value of field \n
- */
-void _MmsSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue)
-{
-       MSG_BEGIN();
-
-       if (pNode && szField && strlen(szField)) {
-               if (szValue && strlen(szValue)) {
-                       xmlSetProp(pNode, (const xmlChar *)szField, (const xmlChar *)szValue);
-               } else {
-                       xmlSetProp(pNode, (const xmlChar *)szField, (const xmlChar *)"");
-               }
-       }
-
-       MSG_END();
-}
-
-/**    @fn                     static char *__MmsSmilFindColorValue(int nValue)
- *     @brief          Converts color to RGB. \n
- *     @param[in]      nValue specifies color value. \n
- *     @retval         RGB value. \n
- */
-char *__MmsSmilFindColorValue(int nValue)
-{
-       unsigned char red = (nValue & 0xFF0000) >> 16;
-       unsigned char green = (nValue & 0x00FF00) >> 8;
-       unsigned char blue = nValue & 0x0000FF;
-
-       MSG_BEGIN();
-
-       snprintf(gszColor,MMS_SMIL_COLOR_SIZE, "#%02x%02x%02x", red, green, blue);
-       MSG_DEBUG("__MmsSmilFindColorValue: gszColor %s \n", gszColor);
-
-       MSG_END();
-       return gszColor;
-}
-
-/**    @fn                     static xmlNodePtr UtilxmlStringGetNodeList(xmlNodePtr pstNode, char *pszValue)
- *     @brief          Get node based on pszValue. \n
- *     @param[in]      pNode specifies node. \n
- *     @param[in]      pszName specifies name field. \n
- *     @retval         RGB value. \n
- */
-xmlNodePtr UtilxmlStringGetNodeList(xmlNodePtr pstNode, char *pszName)
-{
-       MSG_BEGIN();
-
-       if ((NULL != pstNode) && (NULL != pszName)) {
-               xmlNodePtr pstTempNode;
-               xmlNodePtr pstReturnNode;
-
-               pstTempNode = pstNode;
-
-               for ( ; pstTempNode; pstTempNode = pstTempNode->next) {
-                       MSG_DEBUG("\n Node Name = %s[%p] children =%p \n", (char *)pstTempNode->name, pstTempNode, pstTempNode->children);
-                       MSG_DEBUG("\n Compare Parent Node = %s[%p] \n", (char *)pstTempNode->name, pstTempNode);
-                       if (0 == strcasecmp((char *)pstTempNode->name, pszName)) {
-                               return pstTempNode;
-                       }
-
-                       if (pstTempNode->children) {
-                               MSG_DEBUG("\n Enter Inside\n");
-                               pstReturnNode = UtilxmlStringGetNodeList(pstTempNode->children, pszName);
-                               if (NULL != pstReturnNode) {
-                                       return pstReturnNode;
-                               }
-                       }
-
-               }
-       }
-       return NULL;
-}
-
-void MmsSmilGetElementOnlyLayout(MMS_MESSAGE_DATA_S *pMmsMsg, xmlNode *a_node)
-{
-       MSG_BEGIN();
-
-       int elementType;
-       int attrType;
-       MMS_SMIL_ROOTLAYOUT rootlayout = {};
-       static bool cmd[ELEMENT_MAX] = {false, };
-       static MMS_SMIL_REGION *pRegion;
-       static MMS_PAGE_S *pPage;
-       static MMS_MEDIA_S *pMedia;
-       static MMS_SMIL_TRANSITION *pTransition;
-       static MMS_SMIL_META *pMeta;
-
-       xmlNode *cur_node = NULL;
-
-       for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
-               MSG_DEBUG("******* node, name: %s ***\n", cur_node->name);
-
-               if (cur_node->type == XML_ELEMENT_NODE) {
-                       // Get Smil Element =====================================================
-                       MSG_DEBUG("*** node type: Element, name: %s ***\n", cur_node->name);
-
-                       switch (elementType = MmsSmilGetElementID((char *)cur_node->name)) {
-                       case ELEMENT_ROOTLAYOUT:
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_ROOTLAYOUT] = true;
-                               break;
-
-                       case ELEMENT_REGION:
-                               pRegion = (MMS_SMIL_REGION *)calloc(1, sizeof(MMS_SMIL_REGION));
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_REGION] = true;
-                               break;
-
-                       case ELEMENT_TRANSITION:
-                               pTransition = (MMS_SMIL_TRANSITION *)calloc(1, sizeof(MMS_SMIL_TRANSITION));
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_TRANSITION] = true;
-                               break;
-
-                       case ELEMENT_META:
-                               pMeta = (MMS_SMIL_META *)calloc(1, sizeof(MMS_SMIL_META));
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_META] = true;
-                               break;
-
-                       case ELEMENT_PAR:
-                               pPage = (MMS_PAGE_S *)calloc(1, sizeof(MMS_PAGE_S));
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_PAR] = true;
-                               break;
-
-                       case ELEMENT_PARAM: // Need to check the original element type
-                               break;
-
-                       case ELEMENT_TEXT:
-                               pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
-                               pMedia->mediatype = MMS_SMIL_MEDIA_TEXT;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_TEXT] = true;
-                               break;
-
-                       case ELEMENT_IMG:
-                               pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
-                               pMedia->mediatype = MMS_SMIL_MEDIA_IMG;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_IMG] = true;
-                               break;
-
-                       case ELEMENT_AUDIO:
-                               pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
-                               pMedia->mediatype = MMS_SMIL_MEDIA_AUDIO;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_AUDIO] = true;
-                               break;
-
-                       case ELEMENT_VIDEO:
-                               pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
-                               pMedia->mediatype = MMS_SMIL_MEDIA_VIDEO;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_VIDEO] = true;
-                               break;
-
-                       case ELEMENT_REF:
-                               pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
-                               pMedia->mediatype = MMS_SMIL_MEDIA_IMG_OR_VIDEO;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_REF] = true;
-                               break;
-
-                       case ELEMENT_ANIMATE:
-                               pMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
-                               pMedia->mediatype = MMS_SMIL_MEDIA_ANIMATE;
-                               memset(cmd, 0, ELEMENT_MAX);
-                               cmd[ELEMENT_ANIMATE] = true;
-                               break;
-
-                       default:
-                               memset(cmd, 0, ELEMENT_MAX);
-                               break;
-                       }
-
-                       //Get Smil Attribute =====================================================
-                       xmlAttr *pAttr = cur_node->properties;
-                       SMIL_ATTRIBUTE_T paramType = ATTRIBUTE_UNKNOWN;
-
-                       for ( ; pAttr; pAttr = pAttr->next) {
-                               MSG_DEBUG("AttributeType: (%s, %s) ", pAttr->name, pAttr->children->content);
-                               switch (attrType = MmsSmilGetAttrID((char *)pAttr->name)) {
-                               case ATTRIBUTE_ID:
-                                       {
-                                               if (cmd[ELEMENT_REGION]) {
-                                                       strncpy(pRegion->szID, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
-                                               } else if (cmd[ELEMENT_TRANSITION]) {
-                                                       strncpy(pTransition->szID, (char *)pAttr->children->content, MAX_SMIL_TRANSITION_ID - 1);
-                                               } else if (cmd[ELEMENT_META]) {
-                                                       strncpy(pMeta->szID, (char *)pAttr->children->content, MAX_SMIL_META_ID - 1);
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_TOP:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->nTop.bUnitPercent = bUnitPercent;
-                                                       pRegion->nTop.value = value;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_LEFT:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->nLeft.bUnitPercent = bUnitPercent;
-                                                       pRegion->nLeft.value = value;
-                                               }
-                                       }
-                                       break;
-
-
-                               case ATTRIBUTE_WIDTH:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_ROOTLAYOUT]) {
-                                                       rootlayout.width.bUnitPercent = bUnitPercent;
-                                                       rootlayout.width.value = value;
-                                               } else if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->width.bUnitPercent = bUnitPercent;
-                                                       pRegion->width.value = value;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_HEIGHT:
-                                       {
-                                               int bUnitPercent;
-                                               int value;
-
-                                               if (strchr((char *)pAttr->children->content, '%'))
-                                                       bUnitPercent = true;
-                                               else
-                                                       bUnitPercent = false;
-
-                                               value = atoi((char *)pAttr->children->content);
-
-                                               if (cmd[ELEMENT_ROOTLAYOUT]) {
-                                                       rootlayout.height.bUnitPercent = bUnitPercent;
-                                                       rootlayout.height.value = value;
-                                               } else if (cmd[ELEMENT_REGION]) {
-                                                       pRegion->height.bUnitPercent = bUnitPercent;
-                                                       pRegion->height.value = value;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_FIT:
-                                       if (cmd[ELEMENT_REGION]) {
-                                               if (!strcmp((char *)pAttr->children->content, "meet")) {
-                                                       pRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
-                                               } else {
-                                                       pRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
-                                               }
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_BGCOLOR:
-                                       if (cmd[ELEMENT_ROOTLAYOUT]) {
-                                               rootlayout.bBgColor = true;
-                                               rootlayout.bgColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       } else if (cmd[ELEMENT_REGION]) {
-                                               pRegion->bBgColor = true;
-                                               pRegion->bgColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       } else if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nBgColor = MmsSmilGetColorValue(pAttr->children->content);
-
-                                       break;
-
-                               case ATTRIBUTE_DUR:
-                                       if (cmd[ELEMENT_PAR])
-                                               pPage->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
-                                       else if (cmd[ELEMENT_TRANSITION])
-                                               pTransition->nDur =  MmsSmilGetTime((char *)pAttr->children->content);
-                                       else if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nDurTime =  MmsSmilGetTime((char *)pAttr->children->content);
-
-#ifdef MMS_SMIL_ANIMATE
-                                       if (cmd[ELEMENT_ANIMATE])
-                                               pMedia->sMedia.sAVI.nDur = MmsSmilGetTime((char *)pAttr->children->content);
-#endif
-                                       break;
-
-                               case ATTRIBUTE_SRC:
-                               {
-                                       char *szSrc;
-                                       char szContentID[MSG_MSG_ID_LEN + 1] = {0,};
-                                       int cLen;
-
-                                       szSrc = MsgChangeHexString((char *)pAttr->children->content);
-                                       if (szSrc == NULL)
-                                               break;
-
-                                       snprintf(szContentID, sizeof(szContentID), "%s", szSrc);
-                                       free(szSrc);
-
-                                       cLen = strlen(szContentID);
-                                       if (!strncasecmp(szContentID, "cid:", 4)) {
-                                               strncpy(pMedia->szContentID, szContentID + 4, cLen - 4);
-                                               pMedia->szContentID[cLen - 4] = '\0';
-                                       } else {
-                                               strncpy(pMedia->szContentID, szContentID, cLen);
-                                               pMedia->szContentID[cLen] = '\0';
-                                       }
-                                       break;
-                               }
-                               case ATTRIBUTE_COLOR:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nColor = MmsSmilGetColorValue(pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_SIZE:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nSize = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_BOLD:
-                                       if (cmd[ELEMENT_TEXT]) {
-                                               pMedia->sMedia.sText.bBold = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_UNDERLINE:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.bUnderLine = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_ITALIC:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.bItalic = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_REVERSE:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.bReverse = MmsSmilGetFontAttrib((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_DIRECTION:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nDirection = MmsSmilGetFontDirection((char *)pAttr->children->content);
-                                       break;
-                               case ATTRIBUTE_REGION:
-                                       strncpy(pMedia->regionId, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
-                                       break;
-
-                               case ATTRIBUTE_TRANSIN:
-                                       if (cmd[ELEMENT_TEXT])
-                                               strncpy(pMedia->sMedia.sText.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
-                                       else
-                                               strncpy(pMedia->sMedia.sAVI.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
-                                       break;
-
-                               case ATTRIBUTE_TRANSOUT:
-                                       if (cmd[ELEMENT_TEXT])
-                                               strncpy(pMedia->sMedia.sText.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
-                                       else
-                                               strncpy(pMedia->sMedia.sAVI.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
-                                       break;
-
-                               case ATTRIBUTE_BEGIN:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nBegin = MmsSmilGetTime((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_END:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nEnd = MmsSmilGetTime((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_REPEAT_COUNT:
-                                       if (cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nRepeat = atoi((char *)pAttr->children->content);
-                                       else
-                                               pMedia->sMedia.sAVI.nRepeat = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_NAME:
-                                       if (!strcmp((char *)pAttr->children->content, "foreground-color") || !strcmp((char *)pAttr->children->content, "foregroundcolor"))
-                                               paramType = ATTRIBUTE_FGCOLOR;
-                                       else if (!strcmp((char *)pAttr->children->content, "background-color") || !strcmp((char *)pAttr->children->content, "backgroundcolor"))
-                                               paramType = ATTRIBUTE_BGCOLOR;
-                                       else if (!strcmp((char *)pAttr->children->content, "textsize"))
-                                               paramType = ATTRIBUTE_SIZE;
-                                       else if (!strcmp((char *)pAttr->children->content, "textattribute"))
-                                               paramType = ATTRIBUTE_TEXTFORMAT;
-
-                                       if (cmd[ELEMENT_META])
-                                               strncpy(pMeta->szName, (char *)pAttr->children->content, MAX_SMIL_META_NAME - 1);
-                                       break;
-
-                               case ATTRIBUTE_VALUE:
-                                       if (paramType == ATTRIBUTE_SIZE && cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nSize = MmsSmilGetFontSizeValue((char *)pAttr->children->content);
-                                       else if (paramType == ATTRIBUTE_FGCOLOR && cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nColor =  MmsSmilGetColorValue(pAttr->children->content);
-                                       else if (paramType == ATTRIBUTE_BGCOLOR && cmd[ELEMENT_TEXT])
-                                               pMedia->sMedia.sText.nBgColor =  MmsSmilGetColorValue(pAttr->children->content);
-                                       else if (paramType == ATTRIBUTE_TEXTFORMAT && cmd[ELEMENT_TEXT]) {
-                                               MmsSmilFontType fontType;
-
-                                               fontType = MmsSmilGetFontTypeValue((char *)pAttr->children->content);
-
-                                               if (fontType == MMS_SMIL_FONT_TYPE_BOLD)
-                                                       pMedia->sMedia.sText.bBold = true;
-                                               else
-                                                       pMedia->sMedia.sText.bBold = false;
-
-                                               if (fontType == MMS_SMIL_FONT_TYPE_ITALIC)
-                                                       pMedia->sMedia.sText.bItalic = true;
-                                               else
-                                                       pMedia->sMedia.sText.bItalic = false;
-
-                                               if (fontType == MMS_SMIL_FONT_TYPE_UNDERLINE)
-                                                       pMedia->sMedia.sText.bUnderLine = true;
-                                               else
-                                                       pMedia->sMedia.sText.bUnderLine = false;
-                                       }
-                                       break;
-
-                               case ATTRIBUTE_ALT:
-                                       strncpy(pMedia->szAlt, (char *)pAttr->children->content, MAX_SMIL_ALT_LEN - 1);
-                                       break;
-
-                               case ATTRIBUTE_TYPE:
-                                       pTransition->nType = (MmsSmilTransType)atoi((char *)pAttr->children->content);
-
-                                       switch (pTransition->nType) {
-                                       case MMS_SMIL_TRANS_SLIDEWIPE:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_FROM_LEFT;
-                                               break;
-                                       case MMS_SMIL_TRANS_BARWIPE:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_TOP_TO_BOTTOM;
-                                               break;
-                                       case MMS_SMIL_TRANS_BARNDOORWIPE:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_HORIZONTAL;
-                                               break;
-                                       default:
-                                               pTransition->nSubType = MMS_SMIL_TRANS_SUB_NONE;
-                                               break;
-                                       }
-
-                                       break;
-
-                               case ATTRIBUTE_SUBTYPE:
-                                       pTransition->nSubType = (MmsSmilTransSubType)atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_CONTENT:
-                                       strncpy(pMeta->szContent, (char *)pAttr->children->content, MAX_SMIL_META_CONTENT - 1);
-                                       break;
-#ifdef MMS_SMIL_ANIMATE
-                               case ATTRIBUTE_ATTRIBUTE_NAME:
-                                       strcpy(pMedia->sMedia.sAVI.nAttributeName, (char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_ATTRIBUTE_TYPE:
-                                       strcpy(pMedia->sMedia.sAVI.nAttributeType, (char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_TARGET_ELEMENT:
-                                       strcpy(pMedia->sMedia.sAVI.nTargetElement, (char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_FROM:
-                                       pMedia->sMedia.sAVI.nFrom = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_TO:
-                                       pMedia->sMedia.sAVI.nTo = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_BY:
-                                       pMedia->sMedia.sAVI.nBy = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_VALUES:
-                                       pMedia->sMedia.sAVI.nValues = atoi((char *)pAttr->children->content);
-                                       break;
-
-                               case ATTRIBUTE_CALCMODE:
-                                       strcpy(pMedia->sMedia.sAVI.nCalcMode, (char *)pAttr->children->content);
-                                       break;
-#endif
-                               default:
-                                       MSG_DEBUG("Undefined Attribute was found!!!!!");
-                               }
-                       }
-
-                       if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_REGION]) {
-                               // Insert a region to region list
-                               _MsgMmsAddRegion(pMmsMsg, pRegion);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_PAR]) {
-                               //Insert a page to page list
-                               _MsgMmsAddPage(pMmsMsg, pPage);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && (cmd[ELEMENT_TEXT] ||cmd[ELEMENT_IMG] ||cmd[ELEMENT_AUDIO] ||cmd[ELEMENT_VIDEO] ||cmd[ELEMENT_ANIMATE] || cmd[ELEMENT_REF])) {
-                               //Insert a media to media list
-                               _MsgMmsAddMedia(pPage, pMedia);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_ROOTLAYOUT]) {
-                               _MsgMmsSetRootLayout(pMmsMsg, &rootlayout);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_TRANSITION]) {
-                               //Insert a transition to transition list
-                               _MsgMmsAddTransition(pMmsMsg, pTransition);
-                       } else if (paramType == ATTRIBUTE_UNKNOWN && cmd[ELEMENT_META]) {
-                               //Insert a meta to meta list
-                               _MsgMmsAddMeta(pMmsMsg, pMeta);
-                       }
-
-                       paramType = ATTRIBUTE_UNKNOWN;
-               }
-
-               MmsSmilGetElementOnlyLayout(pMmsMsg, cur_node->children);
-       }
-
-       MSG_END();
-}
-
-bool MmsSmilParseSmilDocOnlyLayout(MMS_MESSAGE_DATA_S *pMmsMsg, char *pSmilDoc)
-{
-       xmlDocPtr doc;
-       xmlNodePtr cur;
-       MSG_DEBUG("%s", pSmilDoc);
-       doc = xmlParseMemory(pSmilDoc, strlen(pSmilDoc));
-
-       if (doc == NULL) {
-               MSG_DEBUG("Document not parsed successfully. \n");
-               return false;
-       }
-
-       cur = xmlDocGetRootElement(doc);
-
-       if (cur == NULL) {
-               MSG_DEBUG("empty document\n");
-               xmlFreeDoc(doc);
-               return false;
-       }
-
-       if (xmlStrcmp(cur->name, (const xmlChar *) "smil")) {
-               MSG_DEBUG("document of the wrong type, root node != smil");
-               xmlFreeDoc(doc);
-               return false;
-       }
-
-       MmsSmilGetElementOnlyLayout(pMmsMsg, cur);
-
-       xmlFreeDoc(doc);
-
-       return true;
-}
index a439b85..1e6d1b8 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdlib.h>
 #include "MsgUtilFile.h"
 #include "MsgMmsMessage.h"
 #include "MsgStorageTypes.h"
+#include "MsgSmil.h"
+#include "MsgSerialize.h"
+
 #include "MmsPluginDebug.h"
 #include "MmsPluginStorage.h"
 #include "MmsPluginMessage.h"
-#include "MmsPluginSmil.h"
 #include "MmsPluginDrm.h"
 #include "MmsPluginMIME.h"
+#include "MmsPluginTcs.h"
+#include "MmsPluginUtil.h"
+#include "MmsPluginComposer.h"
+#include "MmsPluginAppBase.h"
 
-#define MMS_FREE(obj)\
-       if (obj){\
-               free(obj);\
-               obj = NULL;\
-       }
-
-/*==================================================================================================
-                                     IMPLEMENTATION OF SmsPluginStorage - Member Functions
-==================================================================================================*/
 MmsPluginStorage *MmsPluginStorage::pInstance = NULL;
 
 
@@ -49,9 +46,7 @@ MmsPluginStorage::MmsPluginStorage()
 
 MmsPluginStorage::~MmsPluginStorage()
 {
-       if (dbHandle.disconnect() != MSG_SUCCESS) {
-               MSG_DEBUG("DB Disconnect Fail");
-       }
+
 }
 
 
@@ -82,7 +77,7 @@ void MmsPluginStorage::composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
 
        version = MmsPluginStorage::instance()->getMmsVersion(pMsgInfo->msgId);
 
-       snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d-Read-Rec.ind", pMsgInfo->msgId);
+       snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, "%s%d-Read-Rec.ind", MSG_DATA_PATH, pMsgInfo->msgId);
 
        if (version == 0x90)
                pMsgInfo->msgType.subType = MSG_READREPLY_MMS;
@@ -112,29 +107,27 @@ void MmsPluginStorage::composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
        MsgCloseFile(pFile);
 }
 
-
-msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, int attachCnt)
+msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_filepath)
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        // Add Message
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, %d, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsMsg->msgID, pMmsMsg->szTrID, pMmsMsg->szMsgID, pMmsMsg->szForwardMsgID, pMmsMsg->szContentLocation,
-                       pMsgInfo->msgData, pMmsMsg->mmsAttrib.version, pMmsMsg->mmsAttrib.dataType, pMmsMsg->mmsAttrib.date, pMmsMsg->mmsAttrib.bHideAddress,
+                       raw_filepath, pMmsMsg->mmsAttrib.version, pMmsMsg->mmsAttrib.dataType, pMmsMsg->mmsAttrib.date, pMmsMsg->mmsAttrib.bHideAddress,
                        pMmsMsg->mmsAttrib.bAskDeliveryReport, pMmsMsg->mmsAttrib.bReportAllowed, pMmsMsg->mmsAttrib.readReportAllowedType,
                        pMmsMsg->mmsAttrib.bAskReadReply, pMmsMsg->mmsAttrib.bRead, pMmsMsg->mmsAttrib.readReportSendStatus, pMmsMsg->mmsAttrib.bReadReportSent,
                        pMmsMsg->mmsAttrib.priority, pMmsMsg->mmsAttrib.bLeaveCopy, pMmsMsg->mmsAttrib.msgSize, pMmsMsg->mmsAttrib.msgClass,
-                       pMmsMsg->mmsAttrib.expiryTime.time,     pMmsMsg->mmsAttrib.bUseDeliveryCustomTime, pMmsMsg->mmsAttrib.deliveryTime.time, pMmsMsg->mmsAttrib.msgStatus);
+                       pMmsMsg->mmsAttrib.expiryTime.time,     0/*pMmsMsg->mmsAttrib.bUseDeliveryCustomTime*/, pMmsMsg->mmsAttrib.deliveryTime.time, pMmsMsg->mmsAttrib.msgStatus);
 
        MSG_DEBUG("\n!!!!!!!!! QUERY : %s\n", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_EXEC;
-
-       if (updateMmsAttachCount(pMmsMsg->msgID, attachCnt) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        MSG_END();
@@ -142,25 +135,26 @@ msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const MSG_MESSAGE_I
        return MSG_SUCCESS;
 }
 
-msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_filepath)
+#if 1 //old
+msg_error_t MmsPluginStorage::updateConfMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
-       // Add Message
+       MMS_RECV_DATA_S *pMmsRecvData = (MMS_RECV_DATA_S *)pMsgInfo->msgData;
+
+       MSG_DEBUG("###### pMsgInfo->msgData = %s #######", pMmsRecvData->retrievedFilePath);
+
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, %d, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);",
-                       MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsMsg->msgID, pMmsMsg->szTrID, pMmsMsg->szMsgID, pMmsMsg->szForwardMsgID, pMmsMsg->szContentLocation,
-                       raw_filepath, pMmsMsg->mmsAttrib.version, pMmsMsg->mmsAttrib.dataType, pMmsMsg->mmsAttrib.date, pMmsMsg->mmsAttrib.bHideAddress,
-                       pMmsMsg->mmsAttrib.bAskDeliveryReport, pMmsMsg->mmsAttrib.bReportAllowed, pMmsMsg->mmsAttrib.readReportAllowedType,
-                       pMmsMsg->mmsAttrib.bAskReadReply, pMmsMsg->mmsAttrib.bRead, pMmsMsg->mmsAttrib.readReportSendStatus, pMmsMsg->mmsAttrib.bReadReportSent,
-                       pMmsMsg->mmsAttrib.priority, pMmsMsg->mmsAttrib.bLeaveCopy, pMmsMsg->mmsAttrib.msgSize, pMmsMsg->mmsAttrib.msgClass,
-                       pMmsMsg->mmsAttrib.expiryTime.time,     pMmsMsg->mmsAttrib.bUseDeliveryCustomTime, pMmsMsg->mmsAttrib.deliveryTime.time, pMmsMsg->mmsAttrib.msgStatus);
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MESSAGE_ID = '%s', FILE_PATH = '%s' WHERE MSG_ID = %d;",
+                       MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsRecvData->szMsgID, pMmsRecvData->retrievedFilePath, pMsgInfo->msgId);
 
-       MSG_DEBUG("\n!!!!!!!!! QUERY : %s\n", sqlQuery);
+       MSG_DEBUG("SQLQuery = %s", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        MSG_END();
@@ -168,121 +162,98 @@ msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_fil
        return MSG_SUCCESS;
 }
 
-msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
+#else //new
+
+msg_error_t MmsPluginStorage::updateRetriveConf(msg_message_id_t msgId, MMS_DATA_S *pMmsData)
 {
        MSG_BEGIN();
 
-       msg_error_t     err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
-       MmsMsg mmsMsg;
-       MMS_MESSAGE_DATA_S mmsMsgData = {0,};
-       char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
-       char raw_filedir[MSG_FILENAME_LEN_MAX+1] = {0,};
-       bzero(&mmsMsg, sizeof(mmsMsg));
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ASK_DELIVERY_REPORT = %d, KEEP_COPY = %d, ASK_READ_REPLY = %d, EXPIRY_TIME = %d, CUSTOM_DELIVERY_TIME = %d, DELIVERY_TIME= %d, PRIORITY = %d \
-                       WHERE MSG_ID = %d;", MMS_PLUGIN_MESSAGE_TABLE_NAME, pSendOptInfo->bDeliverReq, pSendOptInfo->bKeepCopy, pSendOptInfo->option.mmsSendOptInfo.bReadReq,
-                       pSendOptInfo->option.mmsSendOptInfo.expiryTime.time, pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime, pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time,
-                       pSendOptInfo->option.mmsSendOptInfo.priority, pMsgInfo->msgId);
-
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_EXEC;
-
-       MSG_DEBUG("msg sub type = [%d]", pMsgInfo->msgType.subType);
-
-       if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
 
-               if (_MsgMmsDeserializeMessageData(&mmsMsgData, pFileData) == false) {
-                       MSG_DEBUG("Fail to Deserialize Message Data");
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message Compose Error");
-               }
-
-               if (MmsComposeSendReq(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData) != true) {
-                       MmsReleaseMmsMsg(&mmsMsg);
-                       MsgMmsReleaseMmsLists(&mmsMsgData);
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message MmsComposeSendReq Error");
-               }
-
-               //mms file
-               snprintf(raw_filepath, sizeof(raw_filepath), MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
-
-               //encode mms
-               if (MmsEncodeMmsMessage(&mmsMsg, raw_filepath) == false) {
-                       MSG_DEBUG("Fail to Encode Message");
-                       MmsReleaseMmsMsg(&mmsMsg);
-                       MsgMmsReleaseMmsLists(&mmsMsgData);
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message Encode Error");
-               }
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "UPDATE %s "
+                       "SET ASK_DELIVERY_REPORT = %d, ASK_READ_REPLY = %d, PRIORITY = %d, VERSION = %d, MESSAGE_ID = '%s' "
+                       "WHERE MSG_ID = %d;"
+                       , MMS_PLUGIN_MESSAGE_TABLE_NAME
+                       , pMmsData->header->bDeliveryReport
+                       , pMmsData->header->bReadReport
+                       , pMmsData->header->mmsPriority
+                       , pMmsData->header->mmsVersion
+                       , pMmsData->header->messageID
+                       , msgId);
 
-               //preview data
-               MmsPluginStorage::instance()->removePreviewInfo(pMsgInfo->msgId); //remove exist previnfo
+       MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-               err = MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_EXEC;
 
-               err = getMsgText(&mmsMsgData, pMsgInfo->msgText);
+       MSG_END();
 
-               if (mmsMsgData.attachCnt > 0) {
-                       if (updateMmsAttachCount(mmsMsg.msgID, mmsMsgData.attachCnt) != MSG_SUCCESS) {
-                               MSG_DEBUG("Fail to updateMmsAttachCount");
-                       }
-               }
+       return MSG_SUCCESS;
+}
 
-               snprintf(raw_filedir, sizeof(raw_filedir), MSG_DATA_PATH"%d.mms.dir", pMsgInfo->msgId);
-               MsgRmRf(raw_filedir);
-               rmdir(raw_filedir);
+msg_error_t MmsPluginStorage::updateConfMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
+       int err;
 
-               int size = 0;
+       char *pSerializedMms = NULL;
+       gsize pSerializedMmsSize = 0;
 
-               if (MsgGetFileSize(raw_filepath, &size) == false) {
-                       MmsReleaseMmsMsg(&mmsMsg);
-                       MsgMmsReleaseMmsLists(&mmsMsgData);
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message MsgGetFileSize Error");
-               }
+       char working_dir[MSG_FILENAME_LEN_MAX+1] = {0,};
+       MMS_DATA_S *pMmsData = NULL;
 
-               pMsgInfo->dataSize = size;
+       //pMsgInfo->msgData is Filepath of json
+       g_file_get_contents(pMsgInfo->msgData, &pSerializedMms, &pSerializedMmsSize, NULL);
 
-               MmsReadMsgBody(pMsgInfo->msgId, true, false, NULL);
+       if (MsgDeserializeMmsData(pSerializedMms, strlen(pSerializedMms), &pMmsData) != 0) {
+               MSG_DEBUG("Fail to Deserialize Message Data");
+               return MSG_ERR_NULL_MSGHANDLE;
        }
 
-       MmsReleaseMmsMsg(&mmsMsg);
-       MsgMmsReleaseMmsLists(&mmsMsgData);
+       updateRetriveConf(pMsgInfo->msgId, pMmsData);
 
-       MSG_END();
+       snprintf(working_dir, sizeof(working_dir), MSG_DATA_PATH"%d.mms.dir", pMsgInfo->msgId);
 
-       return err;
-}
+       MsgMmsSetMultipartListData(pMmsData);//app file -> data
 
+       MsgMmsSetMultipartListFilePath(working_dir, pMmsData);//data -> svc file
 
-msg_error_t MmsPluginStorage::updateConfMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
-{
-       MSG_BEGIN();
-
-       char sqlQuery[MAX_QUERY_LEN + 1];
-
-       MMS_RECV_DATA_S *pMmsRecvData = (MMS_RECV_DATA_S *)pMsgInfo->msgData;
-
-       MSG_DEBUG("###### pMsgInfo->msgData = %s #######", pMmsRecvData->retrievedFilePath);
+       MMS_MULTIPART_DATA_S *pSmilMultipart = pMmsData->smil;
+       if (pSmilMultipart) {
+               MmsPluginStorage::instance()->insertMultipart(pMsgInfo->msgId, pSmilMultipart);
+       }
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MESSAGE_ID = '%s', FILE_PATH = '%s' WHERE MSG_ID = %d;",
-                       MMS_PLUGIN_MESSAGE_TABLE_NAME, pMmsRecvData->szMsgID, pMmsRecvData->retrievedFilePath, pMsgInfo->msgId);
+       MMSList *multipart_list = pMmsData->multipartlist;
+       for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+               MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
 
-       MSG_DEBUG("SQLQuery = %s", sqlQuery);
+               MmsPluginStorage::instance()->insertMultipart(pMsgInfo->msgId, pMultipart);
+       }
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_EXEC;
+       {//make Preview info for APP
+               MmsPluginAppBase appBase(pMmsData);
+               appBase.makePreviewInfo(pMsgInfo->msgId, true, NULL);
+               appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
+       }
 
+       MsgMmsRelease(&pMmsData);
        MSG_END();
 
        return MSG_SUCCESS;
 }
-
+#endif
 
 msg_error_t MmsPluginStorage::updateMsgServerID(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -293,7 +264,7 @@ msg_error_t MmsPluginStorage::updateMsgServerID(MSG_MESSAGE_INFO_S *pMsgInfo, MS
 
        MSG_DEBUG("SQLQuery = %s", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        if (pSendOptInfo != NULL) {
@@ -304,36 +275,22 @@ msg_error_t MmsPluginStorage::updateMsgServerID(MSG_MESSAGE_INFO_S *pMsgInfo, MS
 
                MSG_DEBUG("SQLQuery = %s", sqlQuery);
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                        return MSG_ERR_DB_EXEC;
                }
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        MSG_END();
 
        return MSG_SUCCESS;
 }
 
-
-msg_error_t MmsPluginStorage::updateNetStatus(msg_message_id_t msgId, msg_network_status_t netStatus)
-{
-       char sqlQuery[MAX_QUERY_LEN + 1];
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d WHERE MSG_ID = %d;",
-                       MSGFW_MESSAGE_TABLE_NAME, netStatus, msgId);
-
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_EXEC;
-
-       return MSG_SUCCESS;
-}
-
 msg_error_t MmsPluginStorage::insertDeliveryReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -345,7 +302,7 @@ msg_error_t MmsPluginStorage::insertDeliveryReport(msg_message_id_t msgId, char
 
        MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -353,6 +310,8 @@ msg_error_t MmsPluginStorage::insertDeliveryReport(msg_message_id_t msgId, char
 
 msg_error_t MmsPluginStorage::insertReadReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -364,7 +323,7 @@ msg_error_t MmsPluginStorage::insertReadReport(msg_message_id_t msgId, char *add
 
        MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -374,6 +333,8 @@ msg_error_t MmsPluginStorage::updateMmsAttrib(msg_message_id_t msgId, MmsAttrib
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -388,7 +349,7 @@ msg_error_t MmsPluginStorage::updateMmsAttrib(msg_message_id_t msgId, MmsAttrib
 
        MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        MSG_END();
@@ -401,12 +362,14 @@ msg_error_t MmsPluginStorage::updateMmsAttachCount(msg_message_id_t msgId, int c
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ATTACHMENT_COUNT = %d WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, count, msgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("Fail to execute query [%s]", sqlQuery);
                return MSG_ERR_DB_EXEC;
        }
@@ -418,6 +381,8 @@ msg_error_t MmsPluginStorage::updateMmsAttachCount(msg_message_id_t msgId, int c
 
 void MmsPluginStorage::getMmsFromDB(msg_message_id_t msgId, MmsMsg *pMmsMsg)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -429,83 +394,47 @@ void MmsPluginStorage::getMmsFromDB(msg_message_id_t msgId, MmsMsg *pMmsMsg)
                        FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                MSG_DEBUG("MSG_ERR_DB_PREPARE");
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
                int i = 0;
-               pMmsMsg->mmsAttrib.version = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.dataType = (MmsDataType)dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.date = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.bHideAddress = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.bAskDeliveryReport = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.bReportAllowed = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.readReportAllowedType = (MmsRecvReadReportType)dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.bAskReadReply = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.bRead = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.bReadReportSent = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.priority = (MmsPriority)dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.msgSize = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.expiryTime.time = dbHandle.columnInt(i++);
+               pMmsMsg->mmsAttrib.version = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.dataType = (MmsDataType)dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.date = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.bHideAddress = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.bAskDeliveryReport = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.bReportAllowed = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.readReportAllowedType = (MmsRecvReadReportType)dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.bAskReadReply = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.bRead = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.bReadReportSent = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.priority = (MmsPriority)dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.msgSize = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.expiryTime.time = dbHandle->columnInt(i++);
                i++;//CUSTOM_DELIVERY_TIME
-               pMmsMsg->mmsAttrib.deliveryTime.time = dbHandle.columnInt(i++);
-               pMmsMsg->mmsAttrib.msgStatus = (msg_delivery_report_status_t)dbHandle.columnInt(i++);
-               snprintf(pMmsMsg->szMsgID, sizeof(pMmsMsg->szMsgID), "%s", dbHandle.columnText(i++));
-               snprintf(pMmsMsg->szTrID, sizeof(pMmsMsg->szTrID), "%s", dbHandle.columnText(i++));
-               snprintf(pMmsMsg->szContentLocation, sizeof(pMmsMsg->szContentLocation), "%s", dbHandle.columnText(i++));
-               snprintf(pMmsMsg->szFileName, sizeof(pMmsMsg->szFileName), "%s", dbHandle.columnText(i++));
+               pMmsMsg->mmsAttrib.deliveryTime.time = dbHandle->columnInt(i++);
+               pMmsMsg->mmsAttrib.msgStatus = (msg_delivery_report_status_t)dbHandle->columnInt(i++);
+               snprintf(pMmsMsg->szMsgID, sizeof(pMmsMsg->szMsgID), "%s", dbHandle->columnText(i++));
+               snprintf(pMmsMsg->szTrID, sizeof(pMmsMsg->szTrID), "%s", dbHandle->columnText(i++));
+               snprintf(pMmsMsg->szContentLocation, sizeof(pMmsMsg->szContentLocation), "%s", dbHandle->columnText(i++));
+               snprintf(pMmsMsg->szFileName, sizeof(pMmsMsg->szFileName), "%s", dbHandle->columnText(i++));
        }
 
 
-       dbHandle.finalizeQuery();
-}
-
-void MmsPluginStorage::getMmsAttrib(msg_message_id_t msgId, MmsMsg *pMmsMsg)
-{
-       char sqlQuery[MAX_QUERY_LEN + 1];
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VERSION, DATA_TYPE,  DATE, HIDE_ADDRESS, ASK_DELIVERY_REPORT, REPORT_ALLOWED, \
-                       READ_REPORT_ALLOWED_TYPE, ASK_READ_REPLY, READ, READ_REPORT_SEND_STATUS, READ_REPORT_SENT, PRIORITY, \
-                       MSG_SIZE, MSG_CLASS, EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME, MSG_STATUS FROM %s WHERE MSG_ID = %d;",
-                       MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
-
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
-               MSG_DEBUG("MSG_ERR_DB_PREPARE");
-
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pMmsMsg->mmsAttrib.version = dbHandle.columnInt(1);
-               pMmsMsg->mmsAttrib.dataType = (MmsDataType)dbHandle.columnInt(2);
-               pMmsMsg->mmsAttrib.date = dbHandle.columnInt(3);
-               pMmsMsg->mmsAttrib.bHideAddress = dbHandle.columnInt(4);
-               pMmsMsg->mmsAttrib.bAskDeliveryReport = dbHandle.columnInt(5);
-               pMmsMsg->mmsAttrib.bReportAllowed = dbHandle.columnInt(6);
-               pMmsMsg->mmsAttrib.readReportAllowedType = (MmsRecvReadReportType)dbHandle.columnInt(7);
-               pMmsMsg->mmsAttrib.bAskReadReply = dbHandle.columnInt(8);
-               pMmsMsg->mmsAttrib.bRead = dbHandle.columnInt(9);
-               pMmsMsg->mmsAttrib.readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle.columnInt(10);
-               pMmsMsg->mmsAttrib.bReadReportSent = dbHandle.columnInt(11);
-               pMmsMsg->mmsAttrib.priority = (MmsPriority)dbHandle.columnInt(12);
-               pMmsMsg->mmsAttrib.msgSize = dbHandle.columnInt(13);
-               pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)dbHandle.columnInt(14);
-               pMmsMsg->mmsAttrib.expiryTime.time = dbHandle.columnInt(15);
-               pMmsMsg->mmsAttrib.deliveryTime.time = dbHandle.columnInt(17);
-               pMmsMsg->mmsAttrib.msgStatus = (msg_delivery_report_status_t)dbHandle.columnInt(18);
-       }
-
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 }
 
-
 msg_error_t MmsPluginStorage::getMmsMessageId(msg_message_id_t selectedMsgId, MmsMsg *pMmsMsg)
 {
        msg_error_t err = MSG_SUCCESS;
 
        int rowCnt = 0;
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -513,23 +442,23 @@ msg_error_t MmsPluginStorage::getMmsMessageId(msg_message_id_t selectedMsgId, Mm
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MESSAGE_ID FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, selectedMsgId);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                MSG_DEBUG("[Error]Failed to Get Table");
                return MSG_ERR_DB_NORECORD;
        }
 
        if (rowCnt != 1) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                MSG_DEBUG("[Error] MSG_ERR_DB_NORECORD");
                return MSG_ERR_DB_NORECORD;
        }
 
-       dbHandle.getColumnToString(1, MMS_MSG_ID_LEN + 1, pMmsMsg->szMsgID);
+       dbHandle->getColumnToString(1, MMS_MSG_ID_LEN + 1, pMmsMsg->szMsgID);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return MSG_SUCCESS;
 }
@@ -542,6 +471,8 @@ int MmsPluginStorage::getMmsVersion(msg_message_id_t selectedMsgId)
 
        int     version = 0;
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -549,60 +480,32 @@ int MmsPluginStorage::getMmsVersion(msg_message_id_t selectedMsgId)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VERSION FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, selectedMsgId);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                MSG_DEBUG("[Error]Failed to Get Table");
                return version;
        }
 
        if (rowCnt != 1) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                MSG_DEBUG("[Error]MSG_ERR_DB_NORECORD");
                return version;
        }
 
-       version = dbHandle.getColumnToInt(1);
+       version = dbHandle->getColumnToInt(1);
 
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return version;
 }
 
-
-msg_error_t MmsPluginStorage::getContentLocation(MSG_MESSAGE_INFO_S *pMsgInfo)
-{
-       char sqlQuery[MAX_QUERY_LEN + 1];
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONTENTS_LOCATION FROM %s WHERE MSG_ID = %d;",
-                       MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsgInfo->msgId);
-
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               if (dbHandle.columnText(0) != NULL) {
-                       strncpy(pMsgInfo->msgData, (char *)dbHandle.columnText(0), (strlen((char *)dbHandle.columnText(0)) > MAX_MSG_DATA_LEN ? MAX_MSG_DATA_LEN : strlen((char *)dbHandle.columnText(0))));
-                       pMsgInfo->dataSize = strlen(pMsgInfo->msgData);
-               }
-       } else {
-               dbHandle.finalizeQuery();
-
-               return MSG_ERR_DB_STEP;
-       }
-
-       dbHandle.finalizeQuery();
-
-       return MSG_SUCCESS;
-}
-
-
 /* reject_msg_support */
 msg_error_t MmsPluginStorage::getTrID(MSG_MESSAGE_INFO_S *pMsgInfo,char *pszTrID,int nBufferLen)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -610,21 +513,21 @@ msg_error_t MmsPluginStorage::getTrID(MSG_MESSAGE_INFO_S *pMsgInfo,char *pszTrID
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT TRANSACTION_ID FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsgInfo->msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               if (dbHandle.columnText(0) != NULL) {
-                       strncpy(pszTrID, (char *)dbHandle.columnText(0), nBufferLen - 1);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               if (dbHandle->columnText(0) != NULL) {
+                       strncpy(pszTrID, (char *)dbHandle->columnText(0), nBufferLen - 1);
                        pszTrID[nBufferLen-1] = '\0';
                }
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
 
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -632,37 +535,48 @@ msg_error_t MmsPluginStorage::getTrID(MSG_MESSAGE_INFO_S *pMsgInfo,char *pszTrID
 
 msg_error_t MmsPluginStorage::getAddressInfo(msg_message_id_t msgId, MSG_ADDRESS_INFO_S *pAddrInfo)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
        // Add Address
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_TYPE, A.RECIPIENT_TYPE, A.CONTACT_ID, A.ADDRESS_VAL \
-                       FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.MSG_ID = %d;",
-                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, msgId);
-
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "A.ADDRESS_TYPE, "
+                       "A.RECIPIENT_TYPE, "
+                       "A.CONTACT_ID, "
+                       "A.ADDRESS_VAL "
+                       "FROM %s A, %s B "
+                       "WHERE A.CONV_ID = B.CONV_ID "
+                       "AND B.MSG_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                       msgId);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               pAddrInfo->addressType = dbHandle.columnInt(0);
-               pAddrInfo->recipientType = dbHandle.columnInt(1);
-               pAddrInfo->contactId = dbHandle.columnInt(2);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               pAddrInfo->addressType = dbHandle->columnInt(0);
+               pAddrInfo->recipientType = dbHandle->columnInt(1);
+               pAddrInfo->contactId = dbHandle->columnInt(2);
 
-               strncpy(pAddrInfo->addressVal, (char*)dbHandle.columnText(3), MAX_ADDRESS_VAL_LEN);
+               strncpy(pAddrInfo->addressVal, (char*)dbHandle->columnText(3), MAX_ADDRESS_VAL_LEN);
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
 
 
-msg_error_t MmsPluginStorage::getMmsRawFilePath(msg_message_id_t msgId, char *pFilepath)
+msg_error_t MmsPluginStorage::getMmsRawFilePath(msg_message_id_t msgId, char *pFilepath, size_t filePathLen)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -670,20 +584,20 @@ msg_error_t MmsPluginStorage::getMmsRawFilePath(msg_message_id_t msgId, char *pF
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               if (dbHandle.columnText(0) != NULL) {
-                       strcpy(pFilepath, (char *)dbHandle.columnText(0));
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               if (dbHandle->columnText(0) != NULL) {
+                       snprintf(pFilepath, filePathLen, "%s", (char *)dbHandle->columnText(0));
                }
        } else {
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
 
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return MSG_SUCCESS;
 }
@@ -695,6 +609,8 @@ int MmsPluginStorage::searchMsgId(char *toNumber, char *szMsgID)
 
        msg_folder_id_t folderId = MSG_SENTBOX_ID;
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
 
        MmsAddrUtilRemovePlmnString(toNumber);
@@ -707,96 +623,59 @@ int MmsPluginStorage::searchMsgId(char *toNumber, char *szMsgID)
 
        MSG_DEBUG("sqlQuery [%s]", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               msgId = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               msgId = dbHandle->columnInt(0);
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        return msgId;
 }
 
-
-msg_error_t MmsPluginStorage::setReadReportSendStatus(msg_message_id_t msgId, int readReportSendStatus)
-{
-       bool bReadReportSent = false;
-
-       if ((MmsRecvReadReportSendStatus)readReportSendStatus == MMS_RECEIVE_READ_REPORT_SENT)
-               bReadReportSent = true;
-       else
-               bReadReportSent = false;
-
-       char sqlQuery[MAX_QUERY_LEN + 1];
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET READ_REPORT_SEND_STATUS = %d, READ_REPORT_SENT = %d WHERE MSG_ID = %d;",
-                       MMS_PLUGIN_MESSAGE_TABLE_NAME, (MmsRecvReadReportSendStatus)readReportSendStatus, (int)bReadReportSent, msgId);
-
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_EXEC;
-
-       return MSG_SUCCESS;
-}
-
-
 msg_error_t MmsPluginStorage::getMsgText(MMS_MESSAGE_DATA_S *pMmsMsg, char *pMsgText)
 {
        MMS_PAGE_S *pPage = NULL;
        MMS_MEDIA_S *pMedia = NULL;
-       char *pMmsMsgText = NULL;
-       int textLen = 0;
-       bool bText = false;
 
        if (pMmsMsg == NULL)
                return MSG_ERR_NULL_POINTER;
 
        // Get the text data from the 1st slide.
-       for (int i = 0; i< pMmsMsg->pageCnt; ++i) {
-               pPage = _MsgMmsGetPage(pMmsMsg, i);
-
-               for (int j = 0; j < pPage->mediaCnt; ++j) {
-                       pMedia = _MsgMmsGetMedia(pPage, j);
-
-                       if (pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
-                               pMmsMsgText = MsgOpenAndReadMmsFile(pMedia->szFilePath, 0, -1, &textLen);
-                               if (pMmsMsgText)
-                                       strncpy(pMsgText, pMmsMsgText, MAX_MSG_TEXT_LEN);
-
-                               // for avoiding break character end of the string.
-                               if ((textLen >= MAX_MSG_TEXT_LEN) && pMsgText[MAX_MSG_TEXT_LEN - 1] >= 0x80) { // if it is multibyte chars by UTF8, it would be presendted by 1xxx xxxx
-                                       for (int k = 1; k < 5; k++) {
-                                               // the first byte of multi-byte chars of UTF8, should be larger than 1100 0000
-                                               // (two byte chars start with 110x xxxx, and three byte chars start with 1110 xxxx,
-                                               // four byte chars start with 1111 0xxx)
-                                               if ((pMsgText[MAX_MSG_TEXT_LEN - k] >= 0xC0)) {
-                                                       pMsgText[MAX_MSG_TEXT_LEN - k] = '\0';
-                                                       break;
-                                               }
-                                       }
-                               }
+       if (pMmsMsg->pageCnt > 0) {
+               pPage = _MsgMmsGetPage(pMmsMsg, 0);
+
+               if (pPage) {
+
+                       for (int j = 0; j < pPage->mediaCnt; ++j) {
+
+                               pMedia = _MsgMmsGetMedia(pPage, j);
 
-                               if (pMmsMsgText) {
-                                       free(pMmsMsgText);
-                                       pMmsMsgText = NULL;
+                               if (pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
+
+                                       MimeType mimeType = MIME_UNKNOWN;
+                                       MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
+
+                                       if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
+                                               MSG_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
+                                       } else {
+                                               strncpy(pMsgText, pMedia->szFilePath, MAX_MSG_TEXT_LEN);
+                                       }
+                                       break;
                                }
-                               bText = true;
-                               break;
                        }
                }
-
-               if (bText)
-                       break;
        }
 
        return MSG_SUCCESS;
 }
 
-msg_error_t MmsPluginStorage::insertPreviewInfo(int msgId, int type, char *value, int count)
+msg_error_t MmsPluginStorage::insertPreviewInfo(int msgId, int type, const char *value, int count)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -804,12 +683,12 @@ msg_error_t MmsPluginStorage::insertPreviewInfo(int msgId, int type, char *value
        snprintf(sqlQuery, sizeof(sqlQuery),
                        "INSERT INTO %s "
                        "(MSG_ID, TYPE, VALUE, COUNT)"
-                       "VALUES (%d, %d, '%s', %d);",
+                       "VALUES (%d, %d, \"%s\", %d);",
                        MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, type, value, count);
 
        MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -817,6 +696,8 @@ msg_error_t MmsPluginStorage::insertPreviewInfo(int msgId, int type, char *value
 
 msg_error_t MmsPluginStorage::removePreviewInfo(int msgId)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
        char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0,};
 
@@ -827,21 +708,21 @@ msg_error_t MmsPluginStorage::removePreviewInfo(int msgId)
                        "WHERE MSG_ID = %d AND (TYPE=%d OR TYPE=%d);",
                        MSGFW_MMS_PREVIEW_TABLE_NAME, msgId, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                return MSG_ERR_DB_PREPARE;
        }
 
-       while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
+       while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
 
                memset(filePath, 0x00, sizeof(filePath));
-               strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+               strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
                if (remove(filePath) == -1)
-                       MSG_DEBUG("Fail to delete file [%s]", filePath);
+                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                else
-                       MSG_DEBUG("Success to delete file [%s]", filePath);
+                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        //(MSG_ID INTEGER, TYPE INTEGER, INFO TEXT)
@@ -851,7 +732,7 @@ msg_error_t MmsPluginStorage::removePreviewInfo(int msgId)
 
        MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
        return MSG_SUCCESS;
@@ -859,6 +740,8 @@ msg_error_t MmsPluginStorage::removePreviewInfo(int msgId)
 
 msg_error_t MmsPluginStorage::deleteMmsMessage(int msgId)
 {
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN + 1];
        char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0,};
        char dirPath[MSG_FILEPATH_LEN_MAX + 1]= {0,};
@@ -866,25 +749,26 @@ msg_error_t MmsPluginStorage::deleteMmsMessage(int msgId)
        //remove DB Preview
        removePreviewInfo(msgId);
 
+       deleteMultipartList(msgId);
+
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                return MSG_ERR_DB_PREPARE;
        }
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               strncpy(filePath, (char *)dbHandle->columnText(0), MSG_FILEPATH_LEN_MAX);
 
                snprintf(dirPath, MSG_FILEPATH_LEN_MAX, "%s.dir", filePath);
 
                //delete pdu file
                if (remove(filePath) == -1)
-                       MSG_DEBUG("Fail to delete file [%s]", filePath);
+                       MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
                else
-                       MSG_DEBUG("Success to delete file [%s]", filePath);
+                       MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
 
                //delete multipart files
                MsgRmRf(dirPath);
@@ -894,12 +778,11 @@ msg_error_t MmsPluginStorage::deleteMmsMessage(int msgId)
 
        } else {
                MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
-               dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
 
        // Delete Data from MMS table
@@ -907,8 +790,7 @@ msg_error_t MmsPluginStorage::deleteMmsMessage(int msgId)
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                return MSG_ERR_DB_EXEC;
        }
 
@@ -917,284 +799,756 @@ msg_error_t MmsPluginStorage::deleteMmsMessage(int msgId)
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
                        MSGFW_REPORT_TABLE_NAME, msgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                return MSG_ERR_DB_EXEC;
        }
 
        return MSG_SUCCESS;
 }
 
-msg_error_t MmsPluginStorage::plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
+msg_error_t MmsPluginStorage::insertMultipart(msg_message_id_t msgId, MMS_MULTIPART_DATA_S *pMultipart)
 {
        MSG_BEGIN();
 
-       msg_error_t     err = MSG_SUCCESS;
-       MMS_MESSAGE_DATA_S tempMmsMsgData = {0,};
-       MMS_MESSAGE_DATA_S *pMmsMsg = &tempMmsMsgData;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       unsigned int nSize = 0;
+       char sqlQuery[MAX_QUERY_LEN + 1];
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       bzero(pMmsMsg, sizeof(MMS_MESSAGE_DATA_S));
-       pMmsMsg->regionCnt = 0;
-       pMmsMsg->pageCnt = 0;
-       pMmsMsg->attachCnt = 0;
-       pMmsMsg->transitionCnt = 0;
-       pMmsMsg->metaCnt = 0;
-       memset(pMmsMsg->szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
+       if (pMultipart == NULL) {
+               MSG_ERR("NULL parameter");
+               return MSG_ERR_INVALID_PARAMETER;
+       }
 
-       MmsMsg tempMmsMsg;
-       memset(&tempMmsMsg, 0x00, sizeof(MmsMsg));
+#if 0
+       //( MSG_ID INTEGER NOT NULL , SEQ INTEGER DEFAULT 0, CONTENT_TYPE TEXT,         NAME TEXT, CHARSET INTEGER,     CONTENT_ID TEXT, CONTENT_LOCATION TEXT, FILE_PATH TEXT, TEXT TEXT,);
+       if (pMultipart->type == MIME_APPLICATION_SMIL) {//Smil
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
+                               "(MSG_ID, SEQ, CONTENT_TYPE, NAME, CONTENT_ID, CONTENT_LOCATION, TEXT) "
+                               "VALUES (%d, -1, '%s', '%s', '%s', '%s' , '%s');",
+                               MSGFW_MMS_MULTIPART_TABLE_NAME, msgId, pMultipart->szContentType, pMultipart->szFileName, pMultipart->szContentID, pMultipart->szContentLocation, (char *)pMultipart->data);
+
+       } else if (MmsIsText(pMultipart->type)) {//Text
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
+                               "(MSG_ID, CONTENT_TYPE, NAME, CHARSET, CONTENT_ID, CONTENT_LOCATION, TEXT) "
+                               "VALUES (%d, '%s', '%s', %d, '%s', '%s' ,'%s');",
+                               MSGFW_MMS_MULTIPART_TABLE_NAME, msgId, pMultipart->szContentType, pMultipart->szFileName, pMultipart->char_set, pMultipart->szContentID, pMultipart->szContentLocation, (char *)pMultipart->data);
+       } else {
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
+                               "(MSG_ID, CONTENT_TYPE, NAME, CONTENT_ID, CONTENT_LOCATION, FILE_PATH) "
+                               "VALUES (%d, '%s', '%s', '%s', '%s' ,'%s');",
+                               MSGFW_MMS_MULTIPART_TABLE_NAME, msgId, pMultipart->szContentType, pMultipart->szFileName, pMultipart->szContentID, pMultipart->szContentLocation, (char *)pMultipart->szFilePath);
+       }
+#else
 
-       getMmsFromDB(pMsg->msgId, &tempMmsMsg);
+       if (pMultipart->type == MIME_APPLICATION_SMIL) {//Smil
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
+                                               "(MSG_ID, SEQ, CONTENT_TYPE, NAME, CONTENT_ID, CONTENT_LOCATION, FILE_PATH) "
+                                               "VALUES (%d, -1, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\");",
+                                               MSGFW_MMS_MULTIPART_TABLE_NAME, msgId, pMultipart->szContentType, pMultipart->szFileName, pMultipart->szContentID, pMultipart->szContentLocation, (char *)pMultipart->szFilePath);
 
-       snprintf(pMmsMsg->header.contentLocation, MSG_MSG_ID_LEN, "%s", tempMmsMsg.szContentLocation);
-       pMmsMsg->header.mmsVersion = tempMmsMsg.mmsAttrib.version;
-       pMmsMsg->header.messageClass = tempMmsMsg.mmsAttrib.msgClass;
-       pMmsMsg->header.mmsPriority = tempMmsMsg.mmsAttrib.priority;
-       snprintf(pMmsMsg->header.messageID, MSG_MSG_ID_LEN, "%s", tempMmsMsg.szMsgID);
-       snprintf(pMmsMsg->header.trID, MSG_MSG_ID_LEN, "%s", tempMmsMsg.szTrID);
+       } else {
+               const char *pszMimeType = NULL;
 
-       if (pSendOptInfo != NULL) {
+               if (strlen(pMultipart->szContentType) == 0) {
+                       MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMultipart->szFilePath, &pMultipart->type, &pszMimeType);
+                       snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pszMimeType);
+                       MSG_DEBUG("pMultipart->szContentType = %s", pMultipart->szContentType);
+               }
 
-               pSendOptInfo->bDeliverReq = tempMmsMsg.mmsAttrib.bAskDeliveryReport;
-               MSG_DEBUG("## delivery = %d ##", pSendOptInfo->bDeliverReq);
+               /* make tcs_bc_level & malware_allow value */
+               pMultipart->tcs_bc_level = -1;
+               //CID 41991: pMultipart->szFilePath is an array, hence checking for null is not required
+               if (strlen(pMultipart->szFilePath) > 0 && MsgAccessFile(pMultipart->szFilePath, F_OK) == true) {
+                       int bc_level = -1;
+                       int tcs_ret = MmsPluginTcsScanFile(pMultipart->szFilePath, &bc_level);
+                       if (tcs_ret == 0) {
+                               if (bc_level > -1) {
+                                       MSG_DEBUG("This content is malware, level = %d", bc_level);
+                                       pMultipart->tcs_bc_level = bc_level;
+                                       pMultipart->malware_allow = 0;
+                               }
+                       }
+               }
+
+               if (pMultipart->tcs_bc_level < 0 || pMultipart->malware_allow) {
+
+                       if (g_str_has_prefix(pMultipart->szContentType, "video")) {
+                               char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
+
+                               if (MmsMakeMultipartThumbnailInfo(pMultipart, thumbPath) == MSG_SUCCESS)
+                                       snprintf(pMultipart->szThumbFilePath, sizeof(pMultipart->szThumbFilePath), "%s", thumbPath);
+                       }
+               }
 
-               pSendOptInfo->bKeepCopy = tempMmsMsg.mmsAttrib.bLeaveCopy;
-               MSG_DEBUG("## bKeepCopy = %d ##", pSendOptInfo->bKeepCopy);
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s "
+                                               "(MSG_ID, CONTENT_TYPE, NAME, CONTENT_ID, CONTENT_LOCATION, FILE_PATH, TCS_LEVEL, MALWARE_ALLOW, THUMB_FILE_PATH) "
+                                               "VALUES (%d, \"%s\", \"%s\", \"%s\", \"%s\" ,\"%s\", '%d', '%d', \"%s\");",
+                                               MSGFW_MMS_MULTIPART_TABLE_NAME, msgId, pMultipart->szContentType, pMultipart->szFileName, pMultipart->szContentID, pMultipart->szContentLocation, (char *)pMultipart->szFilePath, pMultipart->tcs_bc_level, pMultipart->malware_allow, (char *)pMultipart->szThumbFilePath);
+       }
+#endif
+       MSG_DEBUG("QUERY : [%s]", sqlQuery);
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_EXEC;
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
 
-               pSendOptInfo->option.mmsSendOptInfo.bReadReq = tempMmsMsg.mmsAttrib.bAskReadReply;
-               MSG_DEBUG("## bReadReq = %d ##", pSendOptInfo->option.mmsSendOptInfo.bReadReq);
+msg_error_t MmsPluginStorage::updateMultipart(msg_message_id_t msgId, int allow_malware, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       MSG_BEGIN();
 
-               pSendOptInfo->option.mmsSendOptInfo.priority = tempMmsMsg.mmsAttrib.priority;
-               MSG_DEBUG("## priority = %d ##", pSendOptInfo->option.mmsSendOptInfo.priority);
+       MsgDbHandler *dbHandle = getDbHandle();
 
-               pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = tempMmsMsg.mmsAttrib.expiryTime.time;
-               MSG_DEBUG("## expiryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.expiryTime.time);
+       char sqlQuery[MAX_QUERY_LEN + 1];
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-               pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = tempMmsMsg.mmsAttrib.deliveryTime.time;
-               MSG_DEBUG("## deliveryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time);
+       if (pMultipart == NULL) {
+               MSG_ERR("NULL parameter");
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
-       switch(pMsg->msgType.subType) {
-               case MSG_SENDREQ_MMS:
-               case MSG_SENDCONF_MMS:
-               case MSG_RETRIEVE_MMS:
-               case MSG_RETRIEVE_AUTOCONF_MMS:
-               case MSG_RETRIEVE_MANUALCONF_MMS:
-               {
-                       if (MmsReadMsgBody(pMsg->msgId, true, false, NULL) == false) {
-                               MSG_DEBUG("Fail to MmsReadMsgBody");
-                               goto FREE_CATCH;
-                       }
+       if (pMultipart->type != MIME_APPLICATION_SMIL) {
+               /* make tcs_bc_level & malware_allow value */
+               pMultipart->malware_allow = allow_malware;
+
+               if (pMultipart->tcs_bc_level >= 0 || pMultipart->malware_allow) {
 
-                       //header value
-                       snprintf(pMmsMsg->header.szContentType, MSG_MSG_ID_LEN, "%s", MimeGetMimeStringFromMimeInt(mmsMsg.msgType.type));
-                       pMmsMsg->header.contentType = mmsMsg.msgType.type;
-                       pMmsMsg->header.messageType = mmsMsg.mmsAttrib.msgType;
+                       if (!strcasecmp(pMultipart->szContentType, "video")) {
+                               char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
 
-                       //body value
-                       if (MmsMakeMmsData(&mmsMsg, pMmsMsg) == false) {
-                               MSG_DEBUG("Fail to makeMmsMessageData");
-                               goto FREE_CATCH;
+                               if (MmsMakeMultipartThumbnailInfo(pMultipart, thumbPath) == MSG_SUCCESS)
+                                       snprintf(pMultipart->szThumbFilePath, sizeof(pMultipart->szThumbFilePath), "%s", thumbPath);
                        }
                }
-               break;
 
-               case MSG_NOTIFICATIONIND_MMS:
-                       pMmsMsg->header.messageType = MMS_MSGTYPE_NOTIFICATION_IND;
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MALWARE_ALLOW = %d, THUMB_FILE_PATH = '%s' WHERE MSG_ID = %d;",
+                       MSGFW_MMS_MULTIPART_TABLE_NAME, pMultipart->malware_allow, (char *)pMultipart->szThumbFilePath, msgId);
 
-               break;
-               default:
+               MSG_DEBUG("QUERY : [%s]", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
+                       return MSG_ERR_DB_EXEC;
 
-               break;
        }
 
 
+       MSG_END();
+       return MSG_SUCCESS;
+}
 
-       *pDestMsg = _MsgMmsSerializeMessageData(pMmsMsg, &nSize);
+msg_error_t MmsPluginStorage::deleteMultipartList(int msgId)
+{
+       MSG_BEGIN();
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       MsgMmsReleaseMmsLists(pMmsMsg);
+       char sqlQuery[MAX_QUERY_LEN + 1];
+       //char filePath[MSG_FILEPATH_LEN_MAX + 1] = {0,};
+       const char * filePath = NULL;
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
 
+       MSG_DEBUG("QUERY : [%s]", sqlQuery);
 
-       MmsMsg *pStoMmsMsg;
-       MmsPluginStorage::instance()->getMmsMessage(&pStoMmsMsg);
-       MmsInitHeader();
-       MmsUnregisterDecodeBuffer();
-#ifdef __SUPPORT_DRM__
-       MmsReleaseMsgDRMInfo(&pStoMmsMsg->msgType.drmInfo);
-#endif
-       MmsReleaseMsgBody(&pStoMmsMsg->msgBody, pStoMmsMsg->msgType.type);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               return MSG_ERR_DB_PREPARE;
+       }
 
-       pMsg->dataSize = nSize;
-       MSG_END();
+       while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
 
-       return err;
+               filePath = (const char *)dbHandle->columnText(0);
+               if (filePath) {
+                       if (remove(filePath) == -1)
+                               MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
+                       else
+                               MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
+               }
+
+       }
+
+       dbHandle->finalizeQuery();
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT THUMB_FILE_PATH FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               return MSG_ERR_DB_PREPARE;
+       }
+
+       while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+
+               filePath = (const char *)dbHandle->columnText(0);
+               if (filePath) {
+                       if (remove(filePath) == -1)
+                               MSG_SEC_DEBUG("Fail to delete file [%s]", filePath);
+                       else
+                               MSG_SEC_DEBUG("Success to delete file [%s]", filePath);
+               }
+
+       }
+
+       dbHandle->finalizeQuery();
+
+       // Delete Data from Multipart table
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
 
-FREE_CATCH:
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               return MSG_ERR_DB_EXEC;
+       }
 
-       MSG_DEBUG("MmsPlgUpdateMessage : Update MMS Message Failed");
        MSG_END();
-       {
-               MmsMsg *pMsg;
-               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-               MmsInitHeader();
-
-               MmsUnregisterDecodeBuffer();
-#ifdef __SUPPORT_DRM__
-               MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
-#endif
-               MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
+       return MSG_SUCCESS;
+}
+
+msg_error_t MmsPluginStorage::getMultipartList(msg_message_id_t msgId, MMSList **multipart_list)
+{
+       MSG_BEGIN();
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN + 1];
+       int rowCnt;
+       int index = 8;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT CONTENT_TYPE, NAME, FILE_PATH, CONTENT_ID, CONTENT_LOCATION, TCS_LEVEL, MALWARE_ALLOW, THUMB_FILE_PATH "
+                       "FROM %s WHERE MSG_ID=%d;",
+                       MSGFW_MMS_MULTIPART_TABLE_NAME, msgId);
+
+       msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_SUCCESS) {
+
+               for (int i = 0; i < rowCnt; i++) {
+
+                       MMS_MULTIPART_DATA_S *multipart = MsgMmsCreateMultipart();
+
+                       dbHandle->getColumnToString(index++, sizeof(multipart->szContentType), multipart->szContentType);
+
+                       dbHandle->getColumnToString(index++, sizeof(multipart->szFileName), multipart->szFileName);
+
+                       dbHandle->getColumnToString(index++, sizeof(multipart->szFilePath), multipart->szFilePath);
+
+                       dbHandle->getColumnToString(index++, sizeof(multipart->szContentID), multipart->szContentID);
+
+                       dbHandle->getColumnToString(index++, sizeof(multipart->szContentLocation), multipart->szContentLocation);
+
+                       multipart->tcs_bc_level = dbHandle->getColumnToInt(index++);
+
+                       multipart->malware_allow = dbHandle->getColumnToInt(index++);
+
+                       dbHandle->getColumnToString(index++, sizeof(multipart->szThumbFilePath), multipart->szThumbFilePath);
+
+                       multipart->type = MimeGetMimeIntFromMimeString(multipart->szContentType);
 
-               return MSG_ERR_STORAGE_ERROR;
+                       *multipart_list = g_list_append(*multipart_list, multipart);
+               }
        }
+
+       dbHandle->freeTable();
+
+       MSG_END();
+       return MSG_SUCCESS;
 }
 
-void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
+msg_error_t MmsPluginStorage::addMmsData(msg_message_id_t msgId, const char *raw_filepath, MMS_DATA_S *pMmsData)
 {
        MSG_BEGIN();
 
-       msg_error_t     err;
-       MmsMsg *pMmsMsg = NULL;
-       MMS_MESSAGE_DATA_S *pMmsMsgData = NULL;
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN + 1];
 
-       char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
+       MMS_HEADER_DATA_S *pHeader = pMmsData->header;
 
-       pMmsMsg = (MmsMsg *)calloc(1, sizeof(MmsMsg));
-       if (pMmsMsg == NULL) {
-               MSG_DEBUG("memory allocation error");
-               goto __CATCH;
+       if (pHeader == NULL) {
+               MSG_ERR("Header is NULL");
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
-       pMmsMsgData = (MMS_MESSAGE_DATA_S *)calloc(1, sizeof(MMS_MESSAGE_DATA_S));
-       if (pMmsMsgData == NULL) {
-               MSG_DEBUG("memory allocation error");
-               goto __CATCH;
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery)
+                       , "INSERT INTO %s "
+                       "(MSG_ID, TRANSACTION_ID, MESSAGE_ID, FWD_MESSAGE_ID, CONTENTS_LOCATION"
+                       ", FILE_PATH, VERSION, DATA_TYPE, DATE, HIDE_ADDRESS"
+                       ", ASK_DELIVERY_REPORT, REPORT_ALLOWED, READ_REPORT_ALLOWED_TYPE"
+                       ", ASK_READ_REPLY, READ, READ_REPORT_SEND_STATUS, READ_REPORT_SENT"
+                       ", PRIORITY, KEEP_COPY, MSG_SIZE, MSG_CLASS"
+                       ", EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME, MSG_STATUS) "
+                       "VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, %d, %ld, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);"
+                       , MMS_PLUGIN_MESSAGE_TABLE_NAME
+                       , msgId, pHeader->trID, pHeader->messageID, "", pHeader->contentLocation
+                       , raw_filepath, pHeader->mmsVersion, MMS_DATATYPE_NONE, pHeader->date, pHeader->bHideAddress
+                       , pHeader->bDeliveryReport, 0 /*pMmsMsg->mmsAttrib.bReportAllowed*/, 0/*pMmsMsg->mmsAttrib.readReportAllowedType*/
+                       , pHeader->bReadReport, 0 /*pMmsMsg->mmsAttrib.bRead*/, 0/*pMmsMsg->mmsAttrib.readReportSendStatus*/, 0 /*pMmsMsg->mmsAttrib.bReadReportSent*/
+                       , pHeader->mmsPriority, true/*pMmsMsg->mmsAttrib.bLeaveCopy*/,pHeader->messageSize, pHeader->messageClass
+                       , pHeader->expiry.time, 0, pHeader->delivery.time, pHeader->mmsStatus);
+
+       msg_error_t db_err = dbHandle->execQuery(sqlQuery);
+       if (db_err != MSG_SUCCESS) {
+               MSG_ERR("execute query fail [%s], err = [%d]", sqlQuery, db_err);
+               return MSG_ERR_DB_EXEC;
+       } else {
+               MSG_DEBUG("execute query success [%s]", sqlQuery);
        }
 
-       if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
+       MMS_MULTIPART_DATA_S *smil = pMmsData->smil;
+       if (smil) {
+               MSG_DEBUG("insert smil multipart to db");
+               smil->type = MIME_APPLICATION_SMIL;
+               this->insertMultipart(msgId, smil);
+       }
 
-               if (_MsgMmsDeserializeMessageData(pMmsMsgData, pFileData) == false) {
-                       MSG_DEBUG("Fail to Deserialize Message Data");
-                       goto __CATCH;
-               }
+       MMSList *multipart_list = pMmsData->multipartlist;
+       if (multipart_list) {
+               MSG_DEBUG("insert multipart to db");
 
-               if (MmsComposeSendReq(pMmsMsg, pMsgInfo, pSendOptInfo, pMmsMsgData) != true) {
-                       MSG_DEBUG("Fail to Compose Message");
-                       goto __CATCH;
+               for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+
+                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+
+                       if (pMultipart) {
+                               this->insertMultipart(msgId, pMultipart);
+                       }
                }
+       }
 
-               //mms file
-               snprintf(raw_filepath, sizeof(raw_filepath), MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
+       MSG_END();
 
-               //encode mms
-               if (MmsEncodeMmsMessage(pMmsMsg, raw_filepath) == false) {
-                       MSG_DEBUG("Fail to Encode Message");
-                       goto __CATCH;
+       return MSG_SUCCESS;
+}
+
+msg_error_t MmsPluginStorage::getMmsData(msg_message_id_t msgId, MMS_DATA_S *pMmsData)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN + 1];
+
+       MMS_HEADER_DATA_S *pHeader = pMmsData->header;
+
+       if (pHeader == NULL) {
+               MSG_ERR("Header is NULL");
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery)
+                       , "SELECT "
+                       "VERSION, DATA_TYPE,  DATE, HIDE_ADDRESS, ASK_DELIVERY_REPORT, REPORT_ALLOWED"
+                       ", READ_REPORT_ALLOWED_TYPE, ASK_READ_REPLY, READ, READ_REPORT_SEND_STATUS, READ_REPORT_SENT"
+                       ", PRIORITY,  MSG_SIZE, MSG_CLASS, EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME, MSG_STATUS"
+                       ", MESSAGE_ID, TRANSACTION_ID, CONTENTS_LOCATION, FILE_PATH "
+                       "FROM %s "
+                       "WHERE MSG_ID = %d;"
+                       , MMS_PLUGIN_MESSAGE_TABLE_NAME, msgId);
+
+       msg_error_t db_err = dbHandle->prepareQuery(sqlQuery);
+
+       if (db_err != MSG_SUCCESS) {
+               MSG_ERR("prepare query fail [%s], err = [%d]", sqlQuery, db_err);
+               dbHandle->finalizeQuery();
+               return MSG_ERR_PLUGIN_STORAGE;
+       }
+
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               int i = 0;
+               pHeader->mmsVersion = dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.dataType = (MmsDataType)dbHandle->columnInt(i++);
+               pHeader->date = dbHandle->columnInt(i++);
+               pHeader->bHideAddress = dbHandle->columnInt(i++);
+               pHeader->bDeliveryReport = dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.bReportAllowed = dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.readReportAllowedType = (MmsRecvReadReportType)dbHandle->columnInt(i++);
+               pHeader->bReadReport = dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.bRead = dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.readReportSendStatus = (MmsRecvReadReportSendStatus)dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.bReadReportSent = dbHandle->columnInt(i++);
+               pHeader->mmsPriority = (MmsPriority)dbHandle->columnInt(i++);
+               pHeader->messageSize = dbHandle->columnInt(i++);
+               pHeader->messageClass = (MmsMsgClass)dbHandle->columnInt(i++);
+               pHeader->expiry.time = dbHandle->columnInt(i++);
+               i++;//CUSTOM_DELIVERY_TIME
+               pHeader->delivery.time = dbHandle->columnInt(i++);
+               i++;//pMmsMsg->mmsAttrib.msgStatus = (msg_delivery_report_status_t)dbHandle->columnInt(i++);
+               snprintf(pHeader->messageID, sizeof(pHeader->messageID), "%s", dbHandle->columnText(i++));
+               snprintf(pHeader->trID, sizeof(pHeader->trID), "%s", dbHandle->columnText(i++));
+               snprintf(pHeader->contentLocation, sizeof(pHeader->contentLocation), "%s", dbHandle->columnText(i++));
+               i++;//snprintf(pMmsMsg->szFileName, sizeof(pMmsMsg->szFileName), "%s", dbHandle->columnText(i++));
+       }
+
+       dbHandle->finalizeQuery();
+
+
+       MMSList *pMultipartList = NULL;
+
+       if (this->getMultipartList(msgId, &pMultipartList) == MSG_SUCCESS) {
+
+               if (pMultipartList) {
+
+                       MMS_MULTIPART_DATA_S *smil_multipart = NULL;
+                       char *content_type = NULL;
+
+                       MsgMmsGetSmilMultipart(pMultipartList, &smil_multipart);
+
+                       if (smil_multipart) {
+                               pMmsData->smil = smil_multipart ;
+                               pMultipartList = g_list_remove(pMultipartList, smil_multipart);
+                               pHeader->contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
+
+                               if (MsgAccessFile(smil_multipart->szFilePath, F_OK)) {
+                                       gchar *contents = NULL;
+                                       gsize length = 0;
+
+                                       g_file_get_contents (smil_multipart->szFilePath, &contents, &length, NULL);
+
+                                       smil_multipart->pMultipartData = contents;
+                                       smil_multipart->nMultipartDataLen = length;
+
+                                       memset(smil_multipart->szFilePath, 0x00, sizeof(smil_multipart->szFilePath));
+                               }
+
+                       } else {
+                               pHeader->contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
+                       }
+
+                       content_type = MimeGetMimeStringFromMimeInt(pHeader->contentType);
+                       if (content_type) {
+                               snprintf(pHeader->szContentType, sizeof(pHeader->szContentType), "%s", content_type);
+                       }
+
+                       pMmsData->multipartlist = pMultipartList;
                }
+       }
+
+       MSG_END();
+       return MSG_SUCCESS;
+}
+
+msg_error_t MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pSerializedMms)
+{//send request or notification ind
+       MSG_BEGIN();
+
+       msg_error_t     err = MSG_SUCCESS;
+
+       MMS_DATA_S *pMmsData = NULL;
+
+       if (MsgDeserializeMmsData(pSerializedMms, strlen(pSerializedMms), &pMmsData) != 0) {
+               MSG_DEBUG("Fail to Deserialize Message Data");
+               goto __CATCH;
+       }
+
+       if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS || pMsgInfo->msgType.subType == MSG_SENDCONF_MMS) {
+               char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
+               char working_dir[MSG_FILENAME_LEN_MAX+1] = {0,};
+
+               //compose
+               MmsPluginComposer::instance()->composeSendReq(pMsgInfo, pSendOptInfo, pMmsData);
+
+               //encode
+               snprintf(working_dir, sizeof(working_dir), MSG_DATA_PATH"%d.mms.dir", pMsgInfo->msgId);
+
+               MsgMmsSetMultipartListData(pMmsData);//app file -> data
+
+               MsgMmsSetMultipartListFilePath(working_dir, pMmsData);//data -> svc file
+
+               snprintf(raw_filepath, sizeof(raw_filepath), "%s%d.mms", MSG_DATA_PATH, pMsgInfo->msgId);
+
+               MmsPluginEncoder::instance()->encodeMmsPdu(pMmsData, pMsgInfo->msgId, raw_filepath);
 
                //add to db
-               if (addMmsMsgToDB(pMmsMsg, raw_filepath) != MSG_SUCCESS) {
+               if (addMmsData(pMsgInfo->msgId, raw_filepath, pMmsData) != MSG_SUCCESS) {
                        MSG_DEBUG("Fail to add db message");
                        goto __CATCH;
                }
 
-               //preview data
-               err = MmsMakePreviewInfo(pMsgInfo->msgId, pMmsMsgData);
-               err = getMsgText(pMmsMsgData, pMsgInfo->msgText);
+               //set
+               if (MsgGetFileSize(raw_filepath, (int *)&pMsgInfo->dataSize) == false) {
+                       MSG_SEC_DEBUG("Fail to get mms file size [%s]", raw_filepath);
+                       goto __CATCH;
+               }
 
-               if (pMmsMsgData->attachCnt > 0) {
-                       if (updateMmsAttachCount(pMmsMsg->msgID, pMmsMsgData->attachCnt) != MSG_SUCCESS) {
-                               MSG_DEBUG("Fail to updateMmsAttachCount");
-                               goto __CATCH;
-                       }
+               {//make Preview info for APP
+                       MmsPluginAppBase appBase(pMmsData);
+                       appBase.makePreviewInfo(pMsgInfo->msgId, true, raw_filepath);
+                       appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
                }
 
-               if (MsgGetFileSize(raw_filepath, (int *)&pMsgInfo->dataSize) == false) {
-                       MSG_DEBUG("Fail to get mms file size [%s]", raw_filepath);
+       } else if (pMsgInfo->msgType.subType == MSG_RETRIEVE_MMS
+                       || pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS
+                       || pMsgInfo->msgType.subType ==MSG_RETRIEVE_MANUALCONF_MMS) {
+
+               char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
+               char working_dir[MSG_FILENAME_LEN_MAX+1] = {0,};
+
+               //compose
+               MmsPluginComposer::instance()->composeRetrieveConf(pMsgInfo, pSendOptInfo, pMmsData);
+
+               //encode
+               snprintf(working_dir, sizeof(working_dir), MSG_DATA_PATH"%d.mms.dir", pMsgInfo->msgId);
+
+               MsgMmsSetMultipartListData(pMmsData);//app file -> data
+
+               MsgMmsSetMultipartListFilePath(working_dir, pMmsData);//data -> svc file
+
+               snprintf(raw_filepath, sizeof(raw_filepath), "%s%d.mms", MSG_DATA_PATH, pMsgInfo->msgId);
+
+               MmsPluginEncoder::instance()->encodeMmsPdu(pMmsData, pMsgInfo->msgId, raw_filepath);
+
+               //add to db
+               if (addMmsData(pMsgInfo->msgId, raw_filepath, pMmsData) != MSG_SUCCESS) {
+                       MSG_DEBUG("Fail to add db message");
                        goto __CATCH;
                }
 
-               MmsReleaseMmsMsg(pMmsMsg);
-               MMS_FREE(pMmsMsg);
+               //set
+               if (MsgGetFileSize(raw_filepath, (int *)&pMsgInfo->dataSize) == false) {
+                       MSG_SEC_DEBUG("Fail to get mms file size [%s]", raw_filepath);
+                       goto __CATCH;
+               }
 
-               MsgMmsReleaseMmsLists(pMmsMsgData);
-               MMS_FREE(pMmsMsgData);
+               {//make Preview info for APP
+                       MmsPluginAppBase appBase(pMmsData);
+                       appBase.makePreviewInfo(pMsgInfo->msgId, true, raw_filepath);
+                       appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
+               }
 
        } else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
 
-               MmsComposeNotiMessage(pMmsMsg, pMsgInfo->msgId);
+               if (pMmsData->header == NULL || pMmsData->header->messageType != MMS_MSGTYPE_NOTIFICATION_IND) {
+                       goto __CATCH;
+               }
 
-               //add to db
-               if (addMmsMsgToDB(pMmsMsg, "") != MSG_SUCCESS) {
+               if (addMmsData(pMsgInfo->msgId, "", pMmsData) != MSG_SUCCESS) {
                        MSG_DEBUG("Fail to add db message");
                        goto __CATCH;
                }
 
-               MmsReleaseMmsMsg(pMmsMsg);
-               MMS_FREE(pMmsMsg);
-       } else if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS) {
+       } else {
+               MSG_DEBUG("Not support msg sub type [%d]", pMsgInfo->msgType.subType);
+               goto __CATCH;
+       }
+
+       MsgMmsRelease(&pMmsData);
+       MSG_END();
+       return MSG_SUCCESS;
 
-               MmsMsg *pMsg = NULL;
+__CATCH:
+       MsgMmsRelease(&pMmsData);
+       deleteMmsMessage(pMsgInfo->msgId);
 
-               if (!MmsReadMsgBody(pMsgInfo->msgId, true, true, pFileData))
-                       THROW(MsgException::MMS_PLG_ERROR, "_MmsReadMsgBody Error");
+       return err;
+}
 
-               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
+msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pSerializedMms)
+{
+       MSG_BEGIN();
 
-               if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS)
-                       pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
-               else
-                       pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
+       msg_error_t     err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
+       char sqlQuery[MAX_QUERY_LEN + 1];
 
-               {//preview data
-                       MMS_MESSAGE_DATA_S tempMmsMsgData = {0,};
-                       if (MmsMakeMmsData(pMsg, &tempMmsMsgData) == false) {
-                               MSG_DEBUG("Fail to makeMmsMessageData");
-                       } else {
-                               err = MmsMakePreviewInfo(pMsgInfo->msgId, &tempMmsMsgData);
-                               err = getMsgText(&tempMmsMsgData, pMsgInfo->msgText);
+       MMS_DATA_S *pMmsData = NULL;
+
+       if (MsgDeserializeMmsData(pSerializedMms, strlen(pSerializedMms), &pMmsData) != 0) {
+               MSG_DEBUG("Fail to Deserialize Message Data");
+               goto __CATCH;
+       }
+
+       MSG_DEBUG("msg sub type = [%d]", pMsgInfo->msgType.subType);
+
+       if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
+               char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
+               char working_dir[MSG_FILENAME_LEN_MAX+1] = {0,};
+
+               //compose
+               MmsPluginComposer::instance()->composeSendReq(pMsgInfo, pSendOptInfo, pMmsData);
+
+               //encode
+               snprintf(raw_filepath, sizeof(raw_filepath), "%s%d.mms", MSG_DATA_PATH, pMsgInfo->msgId);
+
+               MmsPluginEncoder::instance()->encodeMmsPdu(pMmsData, pMsgInfo->msgId, raw_filepath);
+
+               //add to db
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET ASK_DELIVERY_REPORT = %d, KEEP_COPY = %d, ASK_READ_REPLY = %d, EXPIRY_TIME = %d, CUSTOM_DELIVERY_TIME = %d, DELIVERY_TIME= %d, PRIORITY = %d \
+                               WHERE MSG_ID = %d;", MMS_PLUGIN_MESSAGE_TABLE_NAME, pSendOptInfo->bDeliverReq, pSendOptInfo->bKeepCopy, pSendOptInfo->option.mmsSendOptInfo.bReadReq,
+                               pSendOptInfo->option.mmsSendOptInfo.expiryTime.time, pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime, pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time,
+                               pSendOptInfo->option.mmsSendOptInfo.priority, pMsgInfo->msgId);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       //CID 41997: Releasing pMmsDta in case of failure
+                       MsgMmsRelease(&pMmsData);
+                       return MSG_ERR_DB_EXEC;
+               }
+
+               snprintf(working_dir, sizeof(working_dir), MSG_DATA_PATH"%d.mms.dir", pMsgInfo->msgId);
+
+               MsgMmsSetMultipartListData(pMmsData);//app file -> data
+
+               MmsPluginStorage::instance()->deleteMultipartList(pMsgInfo->msgId); //remove exist multipart
+
+               MsgMmsSetMultipartListFilePath(working_dir, pMmsData);//data -> svc file
+
+               {//add multipart list
+                       if (pMmsData->smil) {
+                               pMmsData->smil->type = MIME_APPLICATION_SMIL;
+                               insertMultipart(pMsgInfo->msgId, pMmsData->smil);
                        }
 
-                       if (tempMmsMsgData.attachCnt > 0) {
-                               if (updateMmsAttachCount(pMsg->msgID, tempMmsMsgData.attachCnt) != MSG_SUCCESS) {
-                                       MSG_DEBUG("Fail to updateMmsAttachCount");
-                                       goto __CATCH;
+                       MMSList *multipart_list = pMmsData->multipartlist;
+
+                       if (multipart_list) {
+                               for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+
+                                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+
+                                       if (pMultipart) {
+                                               insertMultipart(pMsgInfo->msgId, pMultipart);
+                                       }
                                }
                        }
+               }
+
+               //set
+               if (MsgGetFileSize(raw_filepath, (int *)&pMsgInfo->dataSize) == false) {
+                       MSG_SEC_DEBUG("Fail to get mms file size [%s]", raw_filepath);
+                       //CID 41997: Releasing pMmsDta in case of failure
+                       MsgMmsRelease(&pMmsData);
+                       goto __CATCH;
+               }
+
+               {//make Preview info for APP
+                       MmsPluginAppBase appBase(pMmsData);
+                       appBase.makePreviewInfo(pMsgInfo->msgId, true, raw_filepath);
+                       appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
+               }
+       }
+
+       MsgMmsRelease(&pMmsData);
+       MSG_END();
+
+       return err;
+
+__CATCH:
+       removePreviewInfo(pMsgInfo->msgId);
+
+       THROW(MsgException::MMS_PLG_ERROR, "MMS add Error");
+}
+
+msg_error_t MmsPluginStorage::getMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pSerializedMms)
+{
+       MSG_BEGIN();
+
+       msg_error_t     err = MSG_SUCCESS;
+
+       MMS_DATA_S *pMmsData = MsgMmsCreate();
+
+       if (pMmsData == NULL) {
+               MSG_ERR("MsgMmsCreate Fail");
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       MMS_HEADER_DATA_S *pHeader = MsgMmsCreateHeader();
+
+       if (pHeader == NULL) {
+               MsgMmsRelease(&pMmsData);
+               MSG_ERR("MsgMmsCreateHeader Fail");
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       pMmsData->header = pHeader;
+
+       switch(pMsg->msgType.subType) {
+               case MSG_SENDREQ_MMS:
+                       pHeader->messageType = MMS_MSGTYPE_SEND_REQ;
+                       break;
+               case MSG_SENDCONF_MMS:
+                       pHeader->messageType = MMS_MSGTYPE_SEND_CONF;
+                       break;
+               case MSG_RETRIEVE_MMS:
+                       pHeader->messageType = MMS_MSGTYPE_RETRIEVE_CONF;
+                       break;
+               case MSG_RETRIEVE_AUTOCONF_MMS:
+                       pHeader->messageType = MMS_MSGTYPE_RETRIEVE_CONF;
+                       break;
+               case MSG_RETRIEVE_MANUALCONF_MMS:
+                       pHeader->messageType = MMS_MSGTYPE_RETRIEVE_CONF;
+                       break;
+               case MSG_NOTIFICATIONIND_MMS:
+                       pHeader->messageType = MMS_MSGTYPE_NOTIFICATION_IND;
+                       break;
+               default:
+                       break;
+       }
 
-                       MsgMmsReleaseMmsLists(&tempMmsMsgData);
-               }//end preview data
+       err = getMmsData(pMsg->msgId, pMmsData); // get MmsData Info from DB
 
-               if (addMmsMsgToDB(pMsg, pFileData) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
+       if (err == MSG_SUCCESS) {
+
+               if (pSendOptInfo) {
+                       pSendOptInfo->bDeliverReq = pHeader->bDeliveryReport;
+                       pSendOptInfo->option.mmsSendOptInfo.bReadReq = pHeader->bReadReport;
+                       pSendOptInfo->option.mmsSendOptInfo.priority = pHeader->mmsPriority;
+                       pSendOptInfo->option.mmsSendOptInfo.expiryTime.type = pHeader->expiry.type;
+                       pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = pHeader->expiry.time;
+                       pSendOptInfo->option.mmsSendOptInfo.deliveryTime.type = pHeader->delivery.type;
+                       pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = pHeader->delivery.time;
+               }
 
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
+               //MsgMmsSetMultipartListData(pMmsData);
+               int mmsDataSize = MsgSerializeMms(pMmsData, pSerializedMms);
+               if (mmsDataSize > 0) {
+                       pMsg->dataSize = mmsDataSize;
+               } else {
+                       MSG_ERR("MsgSerializeMms fail");
                }
 
-               MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
        } else {
-               MSG_DEBUG("Not support msg sub type [%d]", pMsgInfo->msgType.subType);
-               goto __CATCH;
+               MSG_ERR("getMmsData fail, err = [%d]",  err);
        }
 
-       MmsReleaseMmsMsg(pMmsMsg);
-       MsgMmsReleaseMmsLists(pMmsMsgData);
-       MMS_FREE(pMmsMsg);
-       MMS_FREE(pMmsMsgData);
-
+       //Release pMmsData
+       MsgMmsRelease(&pMmsData);
        MSG_END();
-       return;
 
-__CATCH:
+       return err;
+}
 
-       removePreviewInfo(pMsgInfo->msgId);
+msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
 
-       MmsReleaseMmsMsg(pMmsMsg);
-       MsgMmsReleaseMmsLists(pMmsMsgData);
-       MMS_FREE(pMmsMsg);
-       MMS_FREE(pMmsMsgData);
+       //update multipart list
+       MMSList *multipart_list = NULL;
+       if (MmsPluginStorage::instance()->getMultipartList(pMsgInfo->msgId, &multipart_list) != MSG_SUCCESS)
+               return -1;
 
-       THROW(MsgException::MMS_PLG_ERROR, "MMS add Error");
+       for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+               MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+               MmsPluginStorage::instance()->updateMultipart(pMsgInfo->msgId, true, pMultipart);
+       }
+
+       //update preview
+       char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
+       MmsMsg mmsMsg;
+       memset(&mmsMsg, 0, sizeof(MmsMsg));
+       MmsPluginStorage::instance()->getMmsRawFilePath(pMsgInfo->msgId, szFullPath, sizeof(szFullPath));
+       MmsPluginDecoder::instance()->decodeMmsPdu(&mmsMsg, pMsgInfo->msgId, szFullPath);
+       {//make Preview info for APP
+               MmsPluginAppBase appBase(&mmsMsg);
+               appBase.makePreviewInfo(pMsgInfo->msgId, true, szFullPath);
+               appBase.getFirstPageTextFilePath(pMsgInfo->msgText, sizeof(pMsgInfo->msgText));
+       }
+       MmsReleaseMmsMsg(&mmsMsg);
+
+       MSG_END();
+       return 0;
 }
diff --git a/plugin/mms_plugin/MmsPluginTcs.cpp b/plugin/mms_plugin/MmsPluginTcs.cpp
new file mode 100755 (executable)
index 0000000..5a9ca7b
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include "TCSImpl.h"
+#include "TCSErrorCodes.h"
+#include "MmsPluginDebug.h"
+#include "MsgUtilFile.h"
+#include "MmsPluginTcs.h"
+
+int MmsPluginTcsScanFile(const char *filepath, int *bLevel)
+{
+       MSG_BEGIN();
+       TCSLIB_HANDLE hLib;
+       TCSScanResult result;
+       TCSDetected* pDetected;
+       int rtn, i;
+       int ret_b_level = -1;
+
+       if (MsgAccessFile(filepath, R_OK) == false) {
+               MSG_SEC_DEBUG("not exist source file [%s]", filepath);
+               return -1;
+       }
+
+       MSG_SEC_DEBUG("Scanning file name : %s\n", filepath);
+
+       hLib = TCSLibraryOpen();
+       if(hLib == INVALID_TCSLIB_HANDLE) {
+               MSG_DEBUG("TCSLibraryOpen error\n");
+               return -1;
+       }
+
+       rtn = TCSScanFile(hLib, filepath, TCS_DTYPE_UNKNOWN, TCS_SA_SCANONLY, 1, &result);
+       if(rtn == 0)
+       {
+               MSG_DEBUG("Detected malware number: %d\n", result.iNumDetected);
+               i = result.iNumDetected;
+               pDetected = result.pDList;
+               while(i && pDetected)
+               {
+                       int temp_b_level;
+                       int temp_s_class;
+                       MSG_SEC_DEBUG(" +-- Malware [%d] Name: %s\n", i, pDetected->pszName);
+                       MSG_DEBUG(" +-- Malware [%d] uAction: %u : 0x%04x\n", i, pDetected->uAction, pDetected->uAction);
+
+                       temp_b_level  = (pDetected->uAction & 0xFF00) >> 8;
+                       MSG_DEBUG(" +-- Malware [%d] Behavior level: %u\n", i, temp_b_level);
+
+                       if (ret_b_level == -1 || ret_b_level < temp_b_level) {
+                               ret_b_level = temp_b_level;
+                       }
+
+                       temp_s_class  = (pDetected->uAction & 0x00FF);
+                       MSG_DEBUG(" +-- Malware [%d] Severity class: %u\n", i, temp_s_class);
+
+                       pDetected = pDetected->pNext;
+                       i --;
+               }
+
+               result.pfFreeResult(&result);
+       } else {
+               MSG_DEBUG("TCSScanFile fail: err = %d\n", rtn);
+       }
+
+       TCSLibraryClose(hLib);
+
+       if (bLevel)
+               *bLevel = ret_b_level;
+
+       MSG_END();
+
+       return 0;
+}
index e5bfd07..58e1da4 100755 (executable)
@@ -1,18 +1,19 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
+
 #include <glib.h>
 #include "MmsPluginDebug.h"
 #include "MmsPluginMIME.h"
@@ -32,6 +33,7 @@ const char *MmsPluginTextConvertGetCharSet(int MIBEnum)
 
 bool MmsPluginTextConvert(const char *pToCodeSet, const char *pFromCodeset, const char *pSrc, int srcLen, char **ppDest, int *pDestLen)
 {
+       MSG_BEGIN();
        char *pDest = NULL;
        gsize bytes_read = 0;
        gsize bytes_written = 0;
@@ -49,29 +51,71 @@ bool MmsPluginTextConvert(const char *pToCodeSet, const char *pFromCodeset, cons
                goto __CATCH;
        }
 
+       if (strcasecmp("utf-16", pFromCodeset) == 0) {//check utf-8 str though utf-16
+
+               MSG_DEBUG("Codeset [%s] check utf-8 type", pFromCodeset);
+
+               if (((UINT8)pSrc[0] == 0xFF && (UINT8)pSrc[1] == 0xFE) || ((UINT8)pSrc[0] == 0xFE && (UINT8)pSrc[1] == 0xFF)) {
+
+                       char *pTemp = (char *)calloc(1, srcLen + 1);
+                       memcpy(pTemp, pSrc, srcLen);
+
+                       for (int i = 0; i < srcLen - 1; i++) {
+                               if ((UINT8)pTemp[i] == 0xFF && (UINT8)pTemp[i+1] == 0xFD) {
+                                       MSG_DEBUG("exist 0xFFFD convert to 0x5F5F");
+                                       pTemp[i] = 0x5F;
+                                       pTemp[i+1] = 0x5F;
+                               }
+                       }
+
+                       if (MmsIsUtf8String((unsigned char *)pTemp+2, srcLen-2) == true) {
+                               MSG_DEBUG("UTF-8 string");
+                               pDest = (char *)calloc(1, srcLen - 2 + 1);
+                               strncpy(pDest, pTemp + 2, srcLen - 2);
+                               bytes_written = srcLen - 2;
+
+                               if (pTemp) {
+                                       free(pTemp);
+                                       pTemp = NULL;
+                               }
+
+                               goto __RETURN;
+                       }
+
+                       if (pTemp) {
+                               free(pTemp);
+                               pTemp = NULL;
+                       }
+
+               }
+       }
+
        pDest = g_convert (pSrc, srcLen,
                        pToCodeSet, pFromCodeset,
               &bytes_read, &bytes_written,
               &error);
 
        if (error != NULL) {
-               printf("Error in g_convert, GError = %d:%s, pSrc = %s\n", error->code, error->message, pSrc);
+               MSG_DEBUG("Error in g_convert, GError = %d:%s, pSrc = %s\n", error->code, error->message, pSrc);
                goto __CATCH;
        }
 
        if (pDest == NULL || bytes_written == 0 || bytes_read == 0) {
-               printf("Error in g_convert, pDest = %s, bytes_written = %d, bytes_read = %d\n", pDest, bytes_written, bytes_read);
+               MSG_DEBUG("Error in g_convert, pDest = %s, bytes_written = %d, bytes_read = %d\n", pDest, bytes_written, bytes_read);
                goto __CATCH;
        }
 
+__RETURN:
        *ppDest = pDest;
        *pDestLen = bytes_written;
 
+       MSG_END();
        return true;
 
 __CATCH:
        if (pDest)
                g_free(pDest);
 
+       MSG_END();
        return false;
 }
index 510b301..16f020d 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -147,6 +147,11 @@ void MmsPluginTransport::submitRequest(const MSG_REQUEST_INFO_S *pReqInfo)
 
        MmsPluginUaManager::instance()->addMmsReqEntity(reqItem);
        MmsPluginUaManager::instance()->start();
+
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
 }
 
 void MmsPluginTransport::cancelRequest(msg_request_id_t reqId)
index 5ef83ef..b3dd8e8 100755 (executable)
@@ -1,26 +1,23 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
-#include <sys/utsname.h>
-
 #include "MsgException.h"
 #include "MsgUtilFile.h"
 #include "MsgGconfWrapper.h"
 
-
 #include "MmsPluginDebug.h"
 #include "MmsPluginUserAgent.h"
 #include "MmsPluginHttp.h"
@@ -198,8 +195,10 @@ MmsPluginUaManager *MmsPluginUaManager::pInstance = NULL;
 
 MmsPluginUaManager::MmsPluginUaManager()
 {
+       lock();
        running = false;
        mmsTranQ.clear();
+       unlock();
 }
 
 MmsPluginUaManager::~MmsPluginUaManager()
@@ -233,28 +232,34 @@ void MmsPluginUaManager::start()
 
 MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity)
 {
+       MSG_BEGIN();
+
        MMS_NET_ERROR_T ret = eMMS_UNKNOWN;
-       int retryCount = 0;
+       http_request_info_s request_info = {};
+       char *http_url = NULL;
+       const char *home_url = NULL;
+       const char *proxy_addr = NULL;
+       const char *interfaceName = NULL;
+       bool cm_ret;
 
-       MSG_DEBUG("request Submit:");
        PRINT_PDU_TYPE(qEntity->eMmsPduType);
-       PRINT_QUEUE_ENTITY(qEntity);
 
-       MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
+       PRINT_QUEUE_ENTITY(qEntity);
 
-       http_request_info_s request_info = {};
+       cm_ret = MmsPluginCmAgent::instance()->getProxyAddr(&proxy_addr);
+       if (cm_ret == false)
+               return eMMS_EXCEPTIONAL_ERROR;
 
-       char *http_url = NULL;
+       cm_ret = MmsPluginCmAgent::instance()->getInterfaceName(&interfaceName);
+       if (cm_ret == false)
+               return eMMS_EXCEPTIONAL_ERROR;
 
-       memset(&request_info, 0x00, sizeof(request_info));
 
-       const char *home_url = NULL;
-       const char *proxy_addr = NULL;
-       const char *interfaceName = NULL;
+       cm_ret = MmsPluginCmAgent::instance()->getHomeUrl(&home_url);
+       if (cm_ret == false)
+               return eMMS_EXCEPTIONAL_ERROR;
 
-       MmsPluginCmAgent::instance()->getProxyAddr(&proxy_addr);
-       MmsPluginCmAgent::instance()->getInterfaceName(&interfaceName);
-       MmsPluginCmAgent::instance()->getHomeUrl(&home_url);
+       memset(&request_info, 0x00, sizeof(request_info));
 
        if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) {
 
@@ -284,37 +289,30 @@ MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity)
                request_info.interface = interfaceName;
        }
 
+       MMS_HTTP_ERROR_E http_ret;
+       MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
+       http_ret = httpAgent->httpRequest(request_info);
 
-       while (retryCount < RETRY_MAX) {
-
-               ret = httpAgent->httpRequest(request_info);
-
-               // Process result
-               if (ret == MMS_HTTP_ERROR_NONE) {
-                       MSG_DEBUG("Submit request sent");
+       if (http_ret == MMS_HTTP_ERROR_NONE) {
+               MSG_DEBUG("Submit request sent");
 
-                       if (qEntity->pGetData) {
-                               free(qEntity->pGetData);
-                               qEntity->pGetData = NULL;
-                       }
-
-                       qEntity->pGetData = request_info.response_data;
-                       qEntity->getDataLen = request_info.response_data_len;
-
-                       break;
-               } else if (ret == eMMS_HTTP_ERROR_NETWORK) {
-                       retryCount++;
-                       MSG_DEBUG("HTTP sent timeout and try again: %d", retryCount);
-                       continue;
-               } else {
-                       MSG_DEBUG("Unexpected Error %d", ret);
-                       break;
+               if (qEntity->pGetData) {
+                       free(qEntity->pGetData);
+                       qEntity->pGetData = NULL;
                }
+
+               qEntity->pGetData = request_info.response_data;
+               qEntity->getDataLen = request_info.response_data_len;
+               ret = eMMS_SUCCESS;
+       } else {
+               MSG_DEBUG("Unexpected Error http_ret = [%d]", http_ret);
+               ret = eMMS_HTTP_ERROR_NETWORK;
        }
 
        if (http_url)
                free(http_url);
 
+       MSG_END();
        return ret;
 }
 
@@ -329,108 +327,54 @@ void MmsPluginUaManager::run()
 
        MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
 
-       int msgId;
-
        while (1) {
-               if (mmsTranQ.empty()) {
-                       lock();
+               lock();
+               while (mmsTranQ.empty()) {
                        wait();
-                       unlock();
                }
-
-
-               { // Check is it emulator or not.
-                       struct utsname buf;
-                       int ret = uname(&buf);
-
-                       if (ret == 0) {
-                               MSG_DEBUG("System runs on [%s].", buf.machine);
-                               //if (strncmp(buf.machine, "i686", 4) == 0) {
-                               if(strcasestr(buf.machine, "emulated")) {
-                                       MSG_DEBUG("Running on Emulator mode.");
-
-                                       int mmsResult = MsgSettingGetInt(VCONFKEY_TELEPHONY_MMS_SENT_STATUS);
-
-                                       MSG_DEBUG("MMS result has to be [%d]", mmsResult);
-
-                                       while (!mmsTranQ.empty()) {
-                                               MSG_DEBUG("###### mmsTranQ.size [%d]", mmsTranQ.size());
-
-                                               mmsTranQEntity reqEntity;
-                                               memset(&reqEntity, 0, sizeof(mmsTranQEntity));
-
-                                               mmsTranQ.front(&reqEntity);
-
-                                               if (mmsResult > 0) {
-                                                       // For MMS send fail.
-                                                       MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
-                                                       mmsTranQ.pop_front();
-                                               } else {
-                                                       // For MMS send success.
-                                                       MSG_DEBUG("conf received successfully");
-
-                                                       reqEntity.eMmsPduType = eMMS_SEND_CONF;
-
-                                                       try {
-                                                               MmsPluginEventHandler::instance()->handleMmsReceivedData(&reqEntity, NULL);
-                                                       } catch (MsgException& e) {
-                                                               MSG_FATAL("%s", e.what());
-                                                               break;
-                                                       } catch (exception& e) {
-                                                               MSG_FATAL("%s", e.what());
-                                                               break;
-                                                       }
-
-                                                       mmsTranQ.pop_front();
-                                               }
-                                       }
-
-                                       mmsTranQ.clear();
-                                       MutexLocker locker(mx);
-                                       running = false;
-
-                                       return;
-                               }
-                       }
-               }
-
+               unlock();
 
                // Request CM Open
                if (!(cmAgent->open())) {
-                       MSG_DEBUG("Cm Open Failed");
-
+                       MSG_FATAL("Cm Open Failed");
                        // delete all request from reqQEntities
                        goto CLEANUP;
                }
 
-               while (!mmsTranQ.empty()) {
+               bool transaction = true;
+               while (transaction) {
+                       lock();
+                       int qSize = mmsTranQ.size();
+                       unlock();
+                       if (qSize <= 0) {
+                               break;
+                       }
 
-                       MSG_DEBUG("###### mmsTranQ.size [%d]", mmsTranQ.size());
+                       MSG_DEBUG("###### mmsTranQ.size [%d]", qSize);
 
                        mmsTranQEntity reqEntity;
                        memset(&reqEntity, 0, sizeof(mmsTranQEntity));
 
+                       lock();
                        mmsTranQ.front(&reqEntity);
+                       unlock();
 
                        reqEntity.isCompleted = false;
 
                        PRINT_QUEUE_ENTITY(&reqEntity);
 
-                       if (reqEntity.eMmsPduType == eMMS_RETRIEVE_AUTO) {
-                               msgId = reqEntity.msgId;
-                               MmsPluginStorage::instance()->updateNetStatus(msgId, MSG_NETWORK_RETRIEVING);
-                       }
-
                        // MMS Transaction
                        MSG_DEBUG("\n\n ===================  MMS Transaction Start ========================");
 
                        do {
 
-                               if (submitHandler(&reqEntity) != MMS_HTTP_ERROR_NONE) {
+                               if (submitHandler(&reqEntity) != eMMS_SUCCESS) {
                                        MSG_DEBUG("Transaction Error: submit failed");
 
                                        MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
+                                       lock();
                                        mmsTranQ.pop_front();
+                                       unlock();
                                        //try to next mmsTranQ
                                        break;
                                }
@@ -440,13 +384,13 @@ void MmsPluginUaManager::run()
                                MSG_DEBUG("#### MMS PDU TYPE = %d ####", reqEntity.eMmsPduType);
 
                                if (reqEntity.eMmsPduType == eMMS_NOTIFYRESP_IND ||
-                                       reqEntity.eMmsPduType == eMMS_ACKNOWLEDGE_IND ||
-                                       reqEntity.eMmsPduType == eMMS_READREC_IND ||
-                                       reqEntity.eMmsPduType == eMMS_CANCEL_CONF) {
+                                               reqEntity.eMmsPduType == eMMS_ACKNOWLEDGE_IND ||
+                                               reqEntity.eMmsPduType == eMMS_READREC_IND ||
+                                               reqEntity.eMmsPduType == eMMS_CANCEL_CONF) {
                                        reqEntity.isCompleted = true;
-
+                                       lock();
                                        mmsTranQ.pop_front();
-
+                                       unlock();
                                        MSG_DEBUG("Transaction Completed");
                                        break;
                                } else {
@@ -455,9 +399,9 @@ void MmsPluginUaManager::run()
                                        updatePduType(&reqEntity);
                                        MSG_DEBUG("Waiting Conf");
                                }
-
+                               lock();
                                mmsTranQ.pop_front();
-
+                               unlock();
                                //////// Waiting Conf //////////////////////
                                MMS_NET_ERROR_T networkErr;
 
@@ -492,7 +436,6 @@ void MmsPluginUaManager::run()
                                        }
 
                                        MSG_DEBUG("conf received successfully");
-
                                        try {
                                                MmsPluginEventHandler::instance()->handleMmsReceivedData(&reqEntity, retrievedFilePath);
                                        } catch (MsgException& e) {
@@ -541,15 +484,17 @@ void MmsPluginUaManager::run()
                                                }
 
                                                reqEntity.pPostData = MsgOpenAndReadMmsFile(filepath, 0, -1, &reqEntity.postDataLen);
-
+                                               lock();
                                                mmsTranQ.push_front(reqEntity);
-
+                                               unlock();
                                                if (remove(filepath) != 0) {
                                                        MSG_DEBUG("Error removing file");
                                                }
 
                                                MSG_DEBUG("Submit Ind");
-                                       } else if (reqEntity.eMmsPduType == eMMS_RETRIEVE_MANUAL_CONF) {
+                                       }
+                                       else if (reqEntity.eMmsPduType == eMMS_RETRIEVE_MANUAL_CONF)
+                                       {
                                                /* saved msg trId should be checked  */
                                                // Send Acknowledge Ind
                                                char filepath[MAX_FULL_PATH_SIZE] = {0};
@@ -582,9 +527,9 @@ void MmsPluginUaManager::run()
                                                }
 
                                                reqEntity.pPostData = MsgOpenAndReadMmsFile(filepath, 0, -1, &reqEntity.postDataLen);
-
+                                               lock();
                                                mmsTranQ.push_front(reqEntity);
-
+                                               unlock();
                                                remove(filepath); // not ipc
 
                                                MSG_DEBUG("Submit Ack");
@@ -622,6 +567,8 @@ void MmsPluginUaManager::run()
 CLEANUP:
        MSG_DEBUG("CLEANUP");
 
+       //httpAgent->clearSession();
+       lock();
        while (!mmsTranQ.empty()) {
                MSG_DEBUG("clear mmsTranQ");
 
@@ -649,9 +596,9 @@ CLEANUP:
        }
 
        mmsTranQ.clear();
-       MutexLocker locker(mx);
        running = false;
-
+       unlock();
+       
        MSG_END();
 
        return;
@@ -659,28 +606,36 @@ CLEANUP:
 
 void MmsPluginUaManager::getMmsPduData(mmsTranQEntity *qEntity)
 {
+       lock();
        mmsTranQ.front(qEntity);
+       unlock();
 }
 
 void MmsPluginUaManager::addMmsReqEntity(mmsTranQEntity req)
 {
+       lock();
        if (mmsTranQ.checkExist(req, compare_func) == true) {
                MSG_DEBUG("request Already Exist, req_id = %d", req.msgId);
+               unlock();
                THROW(MsgException::REQ_EXIST_ERROR, "MMS request already exist");
        }
-
-       MSG_DEBUG("New MMS Tran Added");
        mmsTranQ.push_back(req);
-       lock();
        signal();
        unlock();
+
+       MSG_DEBUG("New MMS Tran Added");
 }
 
 bool MmsPluginUaManager::processReceivedData(int msgId, char *pRcvdBody, int rcvdBodyLen, char *retrievedFilePath)
 {
        MSG_BEGIN();
 
+       //CID 317909 : replacing MSG_FILENAME_LEN_MAX with MAX_FULL_PATH_SIZE as the latter is max length for internal file path
+       //                              and size of retrievedFilePath in calling function is same i.e. MAX_FULL_PATH_SIZE+1
+       //CID 358483 : Making fileName smaller causes buffer overflow in MsgCreateFileName function.
+       //                      So We will keep it 1024 as before but only copy 320 out of it which is the size of retrievedFilePath buffer.
        char fileName[MSG_FILENAME_LEN_MAX] = {0};
+       //char fileName[MAX_FULL_PATH_SIZE] = {0};
 
        MSG_DEBUG(":::%d :%s ", rcvdBodyLen, pRcvdBody);
 
@@ -690,27 +645,30 @@ bool MmsPluginUaManager::processReceivedData(int msgId, char *pRcvdBody, int rcv
        if (MsgCreateFileName(fileName) == false)
                return false;
 
-       snprintf(retrievedFilePath, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s", fileName);
+       //CID 317909 : replacing MSG_FILENAME_LEN_MAX with MAX_FULL_PATH_SIZE as the latter is max length for internal file path
+       //                              and size of retrievedFilePath in calling function is same i.e. MAX_FULL_PATH_SIZE+1
+       //snprintf(retrievedFilePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, fileName);
+       snprintf(retrievedFilePath, MAX_FULL_PATH_SIZE, "%s%s", MSG_DATA_PATH, fileName);
 
-       MSG_DEBUG("retrievedFilePaths [%s]", retrievedFilePath);
+       MSG_INFO("retrievedFilePaths [%s]", retrievedFilePath);
 
        // create temp file
        if (!MsgOpenCreateAndOverwriteFile(retrievedFilePath, (char *)pRcvdBody, rcvdBodyLen)) {
-               MSG_DEBUG( "_MmsUaInitMsgDecoder: creating temporary file failed(msgID=%d)\n", msgId);
+               MSG_ERR( "_MmsUaInitMsgDecoder: creating temporary file failed(msgID=%d)\n", msgId);
                return false;
        }
+#if 1 //
+       MmsMsg *pMsg;
 
-       if (MmsReadMsgBody(msgId, true, true, retrievedFilePath) == false) {
-               MSG_DEBUG("The MMS Message might include drm contents!!!");
-               goto ERR_MMS_UA_PROCESS_CONF;
-       }
+       MmsPluginStorage::instance()->getMmsMessage(&pMsg);
 
-       MSG_END();
+       memset(pMsg, 0, sizeof(MmsMsg));
 
-       return true;
+       MmsPluginDecoder::instance()->decodeMmsPdu(pMsg, msgId, retrievedFilePath);
+#else //
+       if (MmsReadMsgBody(msgId, true, true, retrievedFilePath) == false) {
+               MSG_INFO("The MMS Message might include drm contents!!!");
 
-ERR_MMS_UA_PROCESS_CONF:
-       {
                MmsMsg *pMsg;
                MmsPluginStorage::instance()->getMmsMessage(&pMsg);
 
@@ -718,13 +676,18 @@ ERR_MMS_UA_PROCESS_CONF:
                MmsInitHeader();
                MmsUnregisterDecodeBuffer();
 
-#ifdef __SUPPORT_DRM__
+
                MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
-#endif
                MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
 
+               MSG_END();
+
                return false;
        }
+#endif
+       MSG_END();
+
+       return true;
 }
 
 
index b20e952..ff12f4a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <mm_file.h>
 #include "MsgUtilFile.h"
 #include "MmsPluginDebug.h"
 #include "MmsPluginUtil.h"
+#include <string>
+using namespace std;
 
-
-bool makeImageThumbnail(char *srcPath, char *dstPath)
+bool MmsMakeImageThumbnail(char *srcPath, char *dstPath)
 {
        if (srcPath == NULL || dstPath == NULL) {
                MSG_DEBUG(MMS_DEBUG_STR_INVALID_PARAM" src = %p, dst = %p", srcPath, dstPath);
@@ -54,7 +55,7 @@ bool makeImageThumbnail(char *srcPath, char *dstPath)
        return true;
 }
 
-bool makeVideoThumbnail(char *srcPath, char *dstPath)
+bool MmsMakeVideoThumbnail(char *srcPath, char *dstPath)
 {
        MMHandleType content_attrs = (MMHandleType)NULL;
        char *err_attr_name = NULL;
@@ -80,7 +81,7 @@ bool makeVideoThumbnail(char *srcPath, char *dstPath)
 
        fileRet = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &trackCount, NULL);
        if (fileRet != 0) {
-               MSG_DEBUG("mm_file_get_attrs fails [%s]", err_attr_name);
+               MSG_SEC_DEBUG("mm_file_get_attrs fails [%s]", err_attr_name);
 
                if (err_attr_name) {
                        free(err_attr_name);
@@ -111,7 +112,7 @@ bool makeVideoThumbnail(char *srcPath, char *dstPath)
                                                                                                                                NULL);
 
        if (fileRet != 0) {
-               MSG_DEBUG("mm_file_get_attrs fails [%s]", err_attr_name);
+               MSG_SEC_DEBUG("mm_file_get_attrs fails [%s]", err_attr_name);
                if (err_attr_name) {
                        free(err_attr_name);
                        err_attr_name = NULL;
@@ -139,6 +140,7 @@ bool makeVideoThumbnail(char *srcPath, char *dstPath)
 
        if (MsgAccessFile(dstPath, F_OK) == false) {
                MSG_DEBUG("not exist result file [%s]", dstPath);
+               mm_file_destroy_content_attrs(content_attrs);
                return false;
        }
 
@@ -147,7 +149,41 @@ bool makeVideoThumbnail(char *srcPath, char *dstPath)
        return true;
 }
 
-bool MsgIsASCII(char *pszText)
+FILE *MmsFileOpen(char *pFileName)
+{
+       mode_t file_mode = (S_IRUSR | S_IWUSR);
+
+       if (!pFileName) {
+               MSG_DEBUG("pFileName NULL: %s", strerror(errno));
+               return NULL;
+       }
+
+       MSG_DEBUG("pFileName = %s", pFileName);
+
+       FILE *pFile = MsgOpenFile(pFileName, "wb+");
+
+       if (pFile == NULL) {
+               MSG_FATAL("File Open Error: %s", strerror(errno));
+               return NULL;
+       }
+
+       if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
+               MsgCloseFile(pFile);
+               MSG_DEBUG("File Read Error: %s", strerror(errno));
+               return NULL;
+       }
+
+       if (fchmod(fileno(pFile), file_mode) < 0) {
+               MsgCloseFile(pFile);
+               MSG_DEBUG("File chmod Error: %s", strerror(errno));
+               return NULL;
+       }
+
+       return pFile;
+}
+
+
+bool MmsIsAsciiString(const char *pszText)
 {
        if (pszText == NULL) {
                MSG_DEBUG(MMS_DEBUG_STR_INVALID_PARAM" pszText = %p", pszText);
@@ -171,256 +207,251 @@ bool MsgIsASCII(char *pszText)
        return true;
 }
 
-bool MsgReplaceNonAscii(char *szInText, char **szOutText, char replaceChar)
+void MmsRemoveLessGreaterChar(const char *szSrcID, char *szDest, int destSize)
 {
+       char szBuf[MSG_MSG_ID_LEN + 1] = {0, };
+       int cLen = strlen(szSrcID);
 
-       int nCount = 0;
-       int index = 0;
-       int cLen = 0;
-       char *pNew = NULL;
-
-       if (szInText == NULL || szOutText == NULL) {
-               MSG_DEBUG(MMS_DEBUG_STR_INVALID_PARAM" szInText = %p, szOutText = %p", szInText, szOutText);
-               return false;
+       if (cLen > 1 && szSrcID[0] == '<' && szSrcID[cLen - 1] == '>') {
+               strncpy(szBuf, &szSrcID[1], cLen - 2);
+               szBuf[cLen - 2] = '\0';
+       } else if (cLen > 1 && szSrcID[0] == '"' && szSrcID[cLen-1] == '"') {
+               strncpy(szBuf, &szSrcID[1], cLen - 2);
+               szBuf[cLen - 2] = '\0';
+       } else {
+               strncpy(szBuf, szSrcID, cLen);
+               szBuf[cLen] = '\0';
        }
-       cLen = strlen(szInText);
 
-       pNew = (char *)malloc(cLen + 1);
+       snprintf(szDest, destSize, "%s", szBuf);
+}
+
+bool MmsRemoveMarkup(const char *src, char *dst, int dstsize)
+{
+       const int M_IN = 1;
+       const int M_OUT = 0;
 
-       if (pNew == NULL)
+       int state = M_OUT;
+       const char *srcptr = NULL;
+       char *dstptr = NULL;
+
+       if (src == NULL || dst == NULL || dstsize == 0)
                return false;
 
-       memset(pNew, 0, cLen + 1);
+       dstptr = dst;
+       srcptr = src;
 
-       while (*(szInText+nCount) != '\0') {
-               if (0x0001 <= *(szInText+nCount) && *(szInText+nCount) <= 0x007F) {
-                       MSG_DEBUG("non ascii characters (1bytes). \n");
-                       pNew[index] = szInText[nCount];
-                       nCount += 1;
-                       index += 1;
-               } else {
-                       MSG_DEBUG("UTF-8 characters (2bytes). \n");
-                       pNew[index] = replaceChar;
-                       nCount += 1;
-                       index +=1;
+       while (*srcptr != '\0' && ((dstptr-dst) < dstsize)) {
+
+               if (*srcptr == '<') state = M_IN;
+               if (*srcptr == '>') state = M_OUT;
+
+               if (state == M_OUT && *srcptr != '<' && *srcptr != '>') {
+                       *dstptr = *srcptr;
+                       dstptr++;
                }
+
+               srcptr++;
+       }
+
+       if (((dstptr-dst) < dstsize)) {
+               *dstptr = '\0';
+       } else {
+               *(dst + dstsize -1) = '\0';
        }
 
-       *szOutText = pNew;
        return true;
 }
 
-bool MsgIsSpace(char *pszText)
+//change character ' ' to '_'
+bool MmsReplaceSpaceChar(char *pszText)
 {
        if (!pszText) {
-               MSG_DEBUG(MMS_DEBUG_STR_INVALID_PARAM);
                return false;
        }
 
-       if (strchr(pszText, ' ') == NULL) {
-               MSG_DEBUG("space is Not exist");
-               return false;
+       char *spaceCharPtr = strchr(pszText, ' ');
+
+       while (spaceCharPtr) {
+
+               *spaceCharPtr = '_';
+
+               spaceCharPtr = strchr(pszText, ' ');
        }
 
-       MSG_DEBUG("space exist");
        return true;
 }
 
-bool MsgReplaceSpecialChar(char *szInText, char **szOutText, char specialChar)
+char *MmsReplaceNonAsciiUtf8(const char *szSrc, char replaceChar)
 {
-       char *pszOutText = NULL;
-       char szBuf[10] = {0, };
-       char temp[5] = {0, };
-       int cLen = 0;
-       int i = 0;
-
-       if (!szInText || !szOutText) {
-               MSG_DEBUG(MMS_DEBUG_STR_INVALID_PARAM" szInText = %p, szOutText = %p", szInText, szOutText);
-               return false;
+       int offset = 0;
+       int srcLen = 0;
+       const unsigned char *ptr = NULL;
+       unsigned char b1, b2, b3, b4;
+       string str;
+
+       if (szSrc == NULL) {
+               return NULL;
        }
 
-       cLen = strlen(szInText);
+       srcLen = strlen(szSrc);
 
-       if (specialChar == ' ') {
-               if ((pszOutText = (char *)malloc(cLen + 1)) == NULL) {
-                       MSG_DEBUG("%d line. MemAlloc failed.\n", __LINE__);
-                       return false;
-               }
-               memset(pszOutText, 0, cLen + 1);
-
-               *szOutText = pszOutText;
+       if (srcLen == 0) {
+               return NULL;
        }
 
-       for (i = 0; i<cLen; i++) {
-               switch (specialChar) {
-               // changed space to '_'
-               case ' ':
-                       pszOutText[i] = (szInText[i] == specialChar) ? '_' : szInText[i];
-                       break;
-
-               default:
-                       if (szInText[i] != specialChar) {
-                               temp[0] = szInText[i];
-                               *szOutText = MsgStrAppend(*szOutText, temp);
-                               continue;
-                       } else {
-                               MsgConvertCharToHex(specialChar, szBuf);
-                               *szOutText = MsgStrAppend(*szOutText, (char *)"%");
-                               *szOutText = MsgStrAppend(*szOutText, szBuf);
-                       }
-                       break;
-               }
-       }
+       ptr = (const unsigned char*)szSrc;
 
-       MSG_DEBUG("output text : [%s]\n", pszOutText);
+       while(offset < srcLen && *(ptr) != '\0') {
 
-       return true;
-}
+               b1 = *(ptr);
 
-char *MsgStrAppend(char *szInputStr1, char *szInputStr2)
-{
-       char *szOutputStr = NULL;
+               if ((b1 & 0x80) == 0) { //1byte : 0xxx xxxx
+                       offset += 1;
+                       ptr += 1;
 
-       if (szInputStr1 == NULL) {
-               szOutputStr = MsgStrCopy(szInputStr2);
-       } else {
-               int length1 = 0;
-               int length2 = 0;
-               length1 = MsgStrlen(szInputStr1);
-               length2 = MsgStrlen(szInputStr2);
+                       str += b1;
+               } else  if ((b1 & 0xE0) == 0xC0) { //2byte : 110x xxxx
+                       offset += 2;
 
-               szOutputStr = (char *)malloc(length1 + length2 + 1);
+                       if (offset > srcLen)
+                               return NULL;
 
-               if (szOutputStr == NULL)
-                       goto __CATCH;
+                       b2 = *(ptr + 1);
 
-               memset(szOutputStr, 0, length1 + length2 + 1);
+                       if (b2 >= 0x80) { //10xx xxxx
+                               ptr += 2;
+                               str += replaceChar;
+                       } else {
+                               return NULL;
+                       }
 
-               strncpy(szOutputStr, szInputStr1, length1);
+               } else  if ((b1 & 0xF0) == 0xE0) { //3byte : 1110 xxxx
 
-               if (length2 > 0)
-                       strcat(szOutputStr, szInputStr2);
+                       offset += 3;
 
-               free(szInputStr1);
-               szInputStr1 = NULL;
-       }
+                       if (offset > srcLen)
+                               return NULL;
 
-       return szOutputStr;
+                       b2 = *(ptr + 1);
+                       b3 = *(ptr + 2);
 
-__CATCH:
-       return NULL;
-}
+                       if (b2 >= 0x80 && b3 >= 0x80) { //10xx xxxx
+                               ptr += 3;
+                               str += replaceChar;
+                       } else {
+                               return NULL;
+                       }
 
-char *MsgStrCopy(const char *string)
-{
-       char *pDst = NULL;
+               } else  if ((b1 & 0xF8) == 0xF0) { //4byte : 1111 xxxx
+
+                       offset += 4;
+
+                       if (offset > srcLen)
+                               return NULL;
 
-       if (string) {
-               pDst = (char *)malloc(1 + strlen(string));
-               if (pDst == NULL) {
-                       MSG_DEBUG("pDst MemAlloc Fail \n");
+                       b2 = *(ptr + 1);
+                       b3 = *(ptr + 2);
+                       b4 = *(ptr + 3);
+
+                       if (b2 >= 0x80 && b3 >= 0x80 && b4 >= 0x80) { //10xx xxxx
+                               ptr += 4;
+                               str += replaceChar;
+
+                       } else {
+                               return NULL;
+                       }
+               } else {
                        return NULL;
                }
+       }
 
-               memset(pDst, 0, strlen(string) + 1);
-
-               strcpy(pDst,string);
 
-               return pDst;
+       if (str.empty() == true) {
+               return NULL;
        }
 
-       return NULL;
+       MSG_DEBUG("str is UTF-8 [%s]", str.c_str());
+
+       return g_strdup(str.c_str());
 }
 
-char *MsgStrNCopy(const char *string, int length)
+bool MmsIsUtf8String(const unsigned char *szSrc, int nChar)
 {
-       char *pDst = NULL;
+       int offset = 0;
+       int srcLen = 0;
+       const unsigned char *ptr;
+       unsigned char b1, b2, b3, b4;
 
-       if (string) {
-               pDst = (char *)malloc(1 + length);
-               if (pDst == NULL) {
-                       MSG_DEBUG("pDst MemAlloc Fail \n");
-                       return NULL;
-               }
+       if (szSrc == NULL) {
+               return false;
+       }
 
-               memset(pDst, 0, length + 1);
-               strncpy(pDst,string, length);
+       srcLen = nChar;
 
-               return pDst;
+       if (srcLen == 0) {
+               return true;
        }
 
-       return NULL;
-}
+       ptr = (const unsigned char*)szSrc;
 
-int MsgStrlen(char * pStr)
-{
-       if (pStr == NULL)
-               return 0;
+       while(offset < srcLen && *(ptr) != '\0') {
 
-       return strlen(pStr);
-}
+               b1 = *(ptr);
 
-bool MsgConvertCharToHex(char pSrc, char *pDest)
-{
-       static unsigned char saucHex[] = "0123456789ABCDEF";
+               if ((b1 & 0x80) == 0) { //1byte : 0xxx xxxx
+                       offset += 1;
+                       ptr += 1;
+               } else  if ((b1 & 0xE0) == 0xC0) { //2byte : 110x xxxx
+                       offset += 2;
 
-       pDest[0] = saucHex[pSrc >> 4];
-       pDest[1] = saucHex[pSrc & 0xF];
-       pDest[2] = 0;
+                       if (offset > srcLen)
+                               return false;
 
-       return true;
-}
+                       b2 = *(ptr + 1);
 
+                       if (b2 >= 0x80) { //10xx xxxx
+                               ptr += 2;
+                       } else {
+                               return false;
+                       }
 
-FILE *MmsFileOpen(char *pFileName)
-{
-       int len;
-       mode_t file_mode = (S_IRUSR | S_IWUSR);
+               } else  if ((b1 & 0xF0) == 0xE0) { //3byte : 1110 xxxx
 
-       if (!pFileName) {
-               MSG_DEBUG("pFileName NULL: %s", strerror(errno));
-               return NULL;
-       }
+                       offset += 3;
 
-       MSG_DEBUG("pFileName = %s", pFileName);
+                       if (offset > srcLen)
+                               return false;
 
-       FILE *pFile = MsgOpenFile(pFileName, "wb+");
+                       b2 = *(ptr + 1);
+                       b3 = *(ptr + 2);
 
-       if (pFile == NULL) {
-               MSG_FATAL("File Open Error: %s", strerror(errno));
-               return NULL;
-       }
+                       if (b2 >= 0x80 && b3 >= 0x80) { //10xx xxxx
+                               ptr += 3;
+                       } else {
+                               return false;
+                       }
 
-       if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
-               MsgCloseFile(pFile);
-               MSG_DEBUG("File Read Error: %s", strerror(errno));
-               return NULL;
-       }
+               } else  if ((b1 & 0xF8) == 0xF0) { //4byte : 1111 xxxx
 
-       if (fchmod(fileno(pFile), file_mode) < 0) {
-               MsgCloseFile(pFile);
-               MSG_DEBUG("File chmod Error: %s", strerror(errno));
-               return NULL;
-       }
+                       offset += 4;
 
-       return pFile;
-}
+                       if (offset > srcLen)
+                               return false;
 
-void removeLessGreaterMark(const char *szSrcID, char *szDest, int destSize)
-{
-       char szBuf[MSG_MSG_ID_LEN + 1] = {0, };
-       int cLen = strlen(szSrcID);
+                       b2 = *(ptr + 1);
+                       b3 = *(ptr + 2);
+                       b4 = *(ptr + 3);
 
-       if (cLen > 1 && szSrcID[0] == '<' && szSrcID[cLen - 1] == '>') {
-               strncpy(szBuf, &szSrcID[1], cLen - 2);
-               szBuf[cLen - 2] = '\0';
-       } else if (cLen > 1 && szSrcID[0] == '"' && szSrcID[cLen-1] == '"') {
-               strncpy(szBuf, &szSrcID[1], cLen - 2);
-               szBuf[cLen - 2] = '\0';
-       } else {
-               strncpy(szBuf, szSrcID, cLen);
-               szBuf[cLen] = '\0';
-       }
+                       if (b2 >= 0x80 && b3 >= 0x80 && b4 >= 0x80) { //10xx xxxx
+                               ptr += 4;
+                       } else {
+                               return false;
+                       }
+               } else {
+                       return false;
+               }
+       }//while
 
-       snprintf(szDest, destSize, "%s", szBuf);
+       return true;
 }
diff --git a/plugin/mms_plugin/include/MmsPluginAppBase.h b/plugin/mms_plugin/include/MmsPluginAppBase.h
new file mode 100755 (executable)
index 0000000..f1e2c28
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MMS_PLUGIN_APPBASE_H
+#define MMS_PLUGIN_APPBASE_H
+
+#include "MmsPluginTypes.h"
+
+//Set Data for Message App
+class MmsPluginAppBase {
+public:
+       MmsPluginAppBase();
+       MmsPluginAppBase(MMS_DATA_S *pMsgData);
+       MmsPluginAppBase(MmsMsg *pMmsMsg);
+       ~MmsPluginAppBase();
+
+       void setMmsData(MMS_DATA_S *pMmsData);
+       void setMmsData(MmsMsg *pMmsMsg);
+
+       void makePreviewInfo(msg_message_id_t  msgId, bool allow_malware, const char *raw_filepath);
+
+       void getFirstPageTextFilePath(char *textBuf, int textBufSize);
+private:
+       MMS_MESSAGE_DATA_S mmsMsgData;
+};
+#endif //MMS_PLUGIN_APPBASE_H
diff --git a/plugin/mms_plugin/include/MmsPluginAvCodec.h b/plugin/mms_plugin/include/MmsPluginAvCodec.h
deleted file mode 100755 (executable)
index d655c76..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef MMS_PLUGIN_AVCODEC_H
-#define MMS_PLUGIN_AVCODEC_H
-
-#include "MmsPluginTypes.h"
-
-#define        FILEEXT_MAX     5
-
-typedef enum {
-       AV_CODEC_NONE                                           = 0x00000000,
-       AV_CODEC_AUDIO_REAL                                     = 0x00000001,
-       AV_CODEC_AUDIO_AMR                                      = 0x00000002,           // AMR
-       AV_CODEC_AUDIO_G723_1                           = 0x00000004,           // G723.1
-       AV_CODEC_AUDIO_MP3                                      = 0x00000008,           // MP3
-       AV_CODEC_AUDIO_AAC                                      = 0x00000010,           // AAC
-       AV_CODEC_AUDIO_MIDI                                     = 0x00000020,           // MIDI
-       AV_CODEC_AUDIO_MMF                                      = 0x00000040,           // MMF
-       AV_CODEC_AUDIO_MMF_PHRASE_L1            = 0x00000080,           // YAMAHA Phrase L1
-       AV_CODEC_AUDIO_ADPCM                            = 0x00000100,           // ADPCM
-       AV_CODEC_AUDIO_WAVE                                     = 0x00000200,           // WAVE
-       AV_CODEC_AUDIO_IMELODY                          = 0x00000400,           // IMELODY
-       AV_CODEC_AUDIO_DTMF_TONE                        = 0x00000800,           // DTMF
-       AV_CODEC_AUDIO_DTMF_TONE_ID                     = 0x00001000,
-       AV_CODEC_AUDIO_DTMF_TONE_FREQ           = 0x00002000,
-       AV_CODEC_AUDIO_DTMF_SOUND_ID            = 0x00004000,
-       AV_CODEC_AUDIO_DTMF_TONE_FLEX           = 0x00008000,           // DTMF
-       AV_CODEC_AUDIO_MPEG4                            = 0x00010000,           // MPEG4 audio
-       AV_CODEC_AUDIO_SPM                                      = 0x00020000,           // SPM(SP-MIDI)
-       AV_CODEC_AUDIO_PCM                                      = 0x00040000,
-       AV_CODEC_AUDIO_XMF                                      = 0x00080000,           // XMF
-       AV_CODEC_VIDEO_H263                                     = 0x00400000,           // H.26L
-       AV_CODEC_VIDEO_MPEG4                            = 0x02000000,           // MPEG4 video
-       AV_CODEC_VIDEO_AVI                                      = 0x04000000,           // MPEG4 video
-       AV_CODEC_VIDEO_MPEG1                            = 0x08000000,           // MPEG4 video
-       AV_CODEC_VIDEO_REAL                                     = 0x10000000,
-       AV_CODEC_VIDEO_PVX                                      = 0x20000000,            // for Fast Track .PVX type
-
-       AV_ENC_AUDIO_AMR                                        = AV_CODEC_AUDIO_AMR,           // AMR
-       AV_ENC_AUDIO_G723_1                                     = AV_CODEC_AUDIO_G723_1,        // G723.1
-       AV_ENC_AUDIO_MP3                                        = AV_CODEC_AUDIO_MP3,           // MP3
-       AV_ENC_AUDIO_AAC                                        = AV_CODEC_AUDIO_AAC,           // AAC
-       AV_ENC_AUDIO_ADPCM                                      = AV_CODEC_AUDIO_ADPCM,         // ADPCM
-       AV_ENC_AUDIO_WAVE                                       = AV_CODEC_AUDIO_WAVE,          // WAVE
-       AV_ENC_VIDEO_H263                                       = AV_CODEC_VIDEO_H263,          // H.263
-       AV_ENC_VIDEO_MPEG4                                      = AV_CODEC_VIDEO_MPEG4,         // MPEG4
-       AV_ENC_VIDEO_AVI                                        = AV_CODEC_VIDEO_AVI,           // AVI
-       AV_ENC_VIDEO_MPEG1                                      = AV_CODEC_VIDEO_MPEG1,         // MPEG1
-
-       AV_DEC_AUDIO_DTMF_TONE_FLEX                     = AV_CODEC_AUDIO_DTMF_TONE_FLEX,        // DTMF
-       AV_DEC_AUDIO_AMR                                        = AV_CODEC_AUDIO_AMR,           // AMR
-       AV_DEC_AUDIO_G723_1                                     = AV_CODEC_AUDIO_G723_1,        // G723.1
-       AV_DEC_AUDIO_MP3                                        = AV_CODEC_AUDIO_MP3,           // MP3
-       AV_DEC_AUDIO_AAC                                        = AV_CODEC_AUDIO_AAC,           // AAC
-       AV_DEC_AUDIO_MIDI                                       = AV_CODEC_AUDIO_MIDI,          // MIDI
-       AV_DEC_AUDIO_MMF                                        = AV_CODEC_AUDIO_MMF,           // MMF
-       AV_DEC_AUDIO_MMF_PHRASE_L1                      = AV_CODEC_AUDIO_MMF_PHRASE_L1,         // YAMAHA Phrase L1
-       AV_DEC_AUDIO_ADPCM                                      = AV_CODEC_AUDIO_ADPCM,         // ADPCM
-       AV_DEC_AUDIO_WAVE                                       = AV_CODEC_AUDIO_WAVE,          // WAVE
-       AV_DEC_AUDIO_IMELODY                            = AV_CODEC_AUDIO_IMELODY,               // IMELODY
-       AV_DEC_AUDIO_DTMF_TONE                          = AV_CODEC_AUDIO_DTMF_TONE,             // DTMF
-       AV_DEC_AUDIO_DTMF_TONE_ID                       = AV_CODEC_AUDIO_DTMF_TONE_ID,
-       AV_DEC_AUDIO_DTMF_TONE_FREQ                     = AV_CODEC_AUDIO_DTMF_TONE_FREQ,
-       AV_DEC_AUDIO_DTMF_SOUND_ID                      = AV_CODEC_AUDIO_DTMF_SOUND_ID,
-       AV_DEC_AUDIO_MPEG4                                      = AV_CODEC_AUDIO_MPEG4,         // MPEG4 audio
-       AV_DEC_AUDIO_SPM                                        = AV_CODEC_AUDIO_SPM,           // SPM(SP-MIDI)
-       AV_DEC_AUDIO_XMF                                        = AV_CODEC_AUDIO_XMF,           // XMF
-       AV_DEC_AUDIO_REAL                                       = AV_CODEC_AUDIO_REAL,          // MPEG4 video
-
-       AV_DEC_VIDEO_H263                                       = AV_CODEC_VIDEO_H263,          // H.26L
-       AV_DEC_VIDEO_MPEG4                                      = AV_CODEC_VIDEO_MPEG4,         // MPEG4 video
-       AV_DEC_VIDEO_AVI                                        = AV_CODEC_VIDEO_AVI,           // AVI
-       AV_DEC_VIDEO_MPEG1                                      = AV_CODEC_VIDEO_MPEG1,         // MPEG1
-
-       AV_DEC_VIDEO_REAL                                       = AV_CODEC_VIDEO_REAL,                  // REAL VIDEO DEC
-
-       AV_DEC_VIDEO_PVX                                        = AV_CODEC_VIDEO_PVX,                //for .PVX
-
-} AvCodecType;
-
-
-AvCodecType    AvGetFileCodecType(const char *szFileName);
-
-#endif //MMS_PLUGIN_AVCODEC_H
index 3733b04..0633099 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_CODEC_H
index 48c544f..4b5006b 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_CODEC_COMMON_H
 
 #include "MmsPluginCodecTypes.h"
 
+#define                MSG_CH_CR                                               '\r'
+#define                MSG_CH_LF                                               '\n'
+#define                MSG_CH_SP                                               ' '
+#define                MSG_CH_TAB                                              '\t'
+#define                MSG_CH_NULL                                             '\0'
+#define                MSG_CH_COLON                                    ':'
+#define                MSG_CH_SEMICOLON                                ';'
+#define                MSG_CH_UNDERLINE                                '_'
+#define                MSG_CH_COMMA                                    ','
+#define                MSG_CH_BASE64_LOWER                             'b'
+#define                MSG_CH_BASE64_UPPER                             'B'
+#define                MSG_CH_QPRINT_LOWER                             'Q'
+#define                MSG_CH_QPRINT_UPPER                             'q'
+
+#define                MSG_CH_QUESTION                                 '?'
+#define                MSG_CH_QUOT                                             '"'
+#define                MSG_CH_EQUAL                                    '='
+#define                MSG_CH_BRACKET_S                                '<'
+#define                MSG_CH_BRACKET_E                                '>'
+
+#define                MSG_STR_DEC_START                       "=?"
+#define                MSG_STR_DEC_END                         "?="
+#define                MSG_STR_CRLF                            "\r\n"
+#define                MSG_END_OF_HEADER                       "\r\n\r\n"
+#define                MSG_STR_DOUBLE_HYPEN            "--"
+#define                MSG_STR_BOUNDARY_DEL            "\r\n--"
+
+#define                MSG_MMS_CH_EMAIL_AT                     '@'
+
+/* character-set parameter value of content-type header field */
+enum {
+       MSG_CHARSET_US_ASCII,
+       MSG_CHARSET_UTF16,
+       MSG_CHARSET_USC2,
+       MSG_CHARSET_UTF8,
+       MSG_CHARSET_ISO_2022_KR,
+       MSG_CHARSET_KS_C_5601_1987,
+       MSG_CHARSET_EUC_KR,
+       MSG_CHARSET_ISO_2022_JP,
+       MSG_CHARSET_ISO_2022_JP_2,
+       MSG_CHARSET_ISO_8859_1,
+       MSG_CHARSET_ISO_8859_2,
+       MSG_CHARSET_ISO_8859_3,
+       MSG_CHARSET_ISO_8859_4,
+       MSG_CHARSET_ISO_8859_5,
+       MSG_CHARSET_ISO_8859_6,
+       MSG_CHARSET_ISO_8859_7,
+       MSG_CHARSET_ISO_8859_8,
+       MSG_CHARSET_ISO_8859_9,
+       MSG_CHARSET_ISO_8859_10,
+       MSG_CHARSET_ISO_8859_15,
+       MSG_CHARSET_Shift_JIS,
+       MSG_CHARSET_EUC_JP,
+       MSG_CHARSET_GB2312,
+       MSG_CHARSET_BIG5,
+       MSG_CHARSET_WIN1251,
+       MSG_CHARSET_KOI8_R,
+       MSG_CHARSET_KOI8_U,
+
+       MSG_CHARSET_NUM,
+       MSG_CHARSET_UNKNOWN
+};
+
+/* Content-Transfer-Encoding header field value */
+enum {
+       MSG_ENCODING_7BIT,
+       MSG_ENCODING_8BIT,
+       MSG_ENCODING_BINARY,
+       MSG_ENCODING_BASE64,
+       MSG_ENCODING_QUOTE_PRINTABLE,
+       MSG_ENCODING_NUM,
+       MSG_ENCODING_OTHER,
+};
+
+
+/* Content-Disposition header field value */
+enum {
+       MSG_DISPOSITION_FORMDATA,
+       MSG_DISPOSITION_ATTACHMENT,
+       MSG_DISPOSITION_INLINE,
+       MSG_DISPOSITION_NUM
+};
+
+/* MIME header field */
+enum {
+       MSG_FIELD_RETURN_PATH,
+       MSG_FIELD_MESSAGE_ID,
+       MSG_FIELD_FROM,
+       MSG_FIELD_TO,
+       MSG_FIELD_CC,
+       MSG_FIELD_SUBJECT,
+       MSG_FIELD_DATE,
+       MSG_FIELD_MIME_VERSION,
+       MSG_FIELD_CONTENT_TYPE,
+       MSG_FIELD_CONTENT_TRANSFER_ENCODING,
+       MSG_FIELD_CONTENT_DISPOSITION, //If start param is given in multipart/related, this field will be ignored
+       MSG_FIELD_CONTENT_ID,
+       MSG_FIELD_CONTENT_LOCATION,
+       MSG_FIELD_CONTENT_NAME,
+       MSG_FIELD_CONTENT_DESCRIPTION,
+       MSG_FIELD_CONTENT_VENDOR,
+       MSG_FIELD_RIGHT_ISSUER,
+
+       MSG_FIELD_RETURN_RECEIPT_TO,                    /* for Delivery confirm */
+       MSG_FIELD_DISPOSITION_NOTIFICATION_TO,  /* for Read confirm */
+
+       MSG_FILED_CONTENT_REPLACE_POS,
+       MSG_FILED_CONTENT_REPLACE_SIZE,
+       MSG_FILED_CONTENT_REPLACE_INDEX,
+
+       MSG_FIELD_DRM_CONVERTED,
+
+       MSG_FIELD_NUM,
+       MSG_FIELD_UNKNOWN,
+};
+
+/* MIME header field parameter */
+enum {
+       MSG_PARAM_CHARSET,
+       MSG_PARAM_NAME,
+       MSG_PARAM_FILENAME,
+       MSG_PARAM_TYPE,                 // only used as parameter of Content-Type: multipart/related
+       MSG_PARAM_START,                // Only if content-type is multipart/related
+       MSG_PARAM_START_INFO,   // Only if content-type is multipart/related
+       MSG_PARAM_BOUNDARY,
+       MSG_PARAM_REPORT_TYPE,  // only used as parameter of Content-Type: multipart/report; report-type=delivery-status;
+#ifdef FEATURE_JAVA_MMS
+       MSG_PARAM_APPLICATION_ID,
+       MSG_PARAM_REPLY_TO_APPLICATION_ID,
+#endif
+       MSG_PARAM_NUM,
+       MSG_PARAM_UNKNOWN,
+};
+
 const char *MmsGetTextByCode(MmsCode i, UINT16 code);
 const char *MmsGetTextValue(MmsCode i, int j);
 const char *MmsGetTextValuebyField(int field, int value);
@@ -30,7 +164,7 @@ void *MsgDecodeBase64(unsigned char *pSrc, unsigned long srcLen, unsigned long *
 bool MsgEncode2Base64(void *pSrc, unsigned long srcLen, unsigned long *len, unsigned char *ret);
 unsigned char *MsgDecodeQuotePrintable(unsigned char *pSrc, unsigned long srcLen, unsigned long *len);
 
-char *MsgDecodeText(char *pOri);
+char *MsgDecodeText(const char *pOri);
 
 const char *MmsDebugGetMimeType(MimeType mimeType);
 const char *MmsDebugGetMmsReport(MmsReport report);
@@ -47,14 +181,17 @@ bool MmsInitMsgType(MsgType *pMsgType);
 bool MmsInitMsgBody(MsgBody *pMsgBody);
 bool MmsInitMsgContentParam(MsgContentParam *pMsgContentParam);
 bool MmsInitMsgAttrib(MmsAttrib *pAttrib);
-
-#ifdef __SUPPORT_DRM__
 bool MmsInitMsgDRMInfo(MsgDRMInfo *pMsgDrmInfo);
-void MmsReleaseMsgDRMInfo(MsgDRMInfo *pDrmInfo);
-#endif//__SUPPORT_DRM__
 
 bool MmsReleaseMsgBody(MsgBody *pBody, int type);
 bool MmsReleaseMmsAttrib(MmsAttrib *pAttrib);
+void MmsReleaseMsgDRMInfo(MsgDRMInfo *pDrmInfo);
 void MmsReleaseMmsMsg(MmsMsg *pMmsMsg);
 
+bool MmsIsTextType(int type);
+bool MmsIsMultipart(int type);
+bool MmsIsVitemContent(int type, char *pszName);
+
+MsgMultipart *MmsAllocMultipart(void);
+bool MmsPrintMulitpart(MsgMultipart *pMultipart, int index);
 #endif //MMS_PLUGIN_CODEC_COMMON_H
index e34c300..d4b1566 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_CODEC_TYPE_H
@@ -75,10 +75,8 @@ typedef unsigned char                        UCHAR;
 typedef unsigned short                 MCHAR;
 typedef unsigned short                 USHORT;
 
-typedef struct _MsgAddress             MsgAddress;
-typedef struct _MsgBody                        MsgBody;
+typedef struct _MsgBody                MsgBody;
 typedef struct _MsgMultipart   MsgMultipart;
-typedef struct _MsgMessage             MsgMessage;
 
 typedef enum {
        MMS_CODE_BCC,
@@ -302,44 +300,6 @@ typedef enum {
 } MmsReplyChargeType;
 
 typedef enum {
-       MMS_STATUS_ERROR = -1,  // error return in Get method
-       MMS_STATUS_INITIAL = 0,
-       MMS_STATUS_REQUESTING = 1,
-       MMS_STATUS_SUCCESS = 2,
-       MMS_STATUS_FAIL = 3,
-       MMS_STATUS_NUM = 4,
-} MmsDataStatus;
-
-typedef enum {
-       MMS_EDIT_STYLE_THIS_PAGE = 0,
-       MMS_EDIT_STYLE_ALL_PAGE,
-} MmsEditStyleMode;
-
-typedef enum {
-       MMS_SPECIAL_MSG_TYPE_NONE = 0,
-       MMS_SPECIAL_MSG_TYPE_SYSTEM_TEMPLATE,   // system template .
-       MMS_SPECIAL_MSG_TYPE_VOICE_MESSAGE,             //voice message service
-
-       MMS_SPECIAL_MSG_TYPE_VDF_POSTCARD,              //postcard service, or Generic Postcard Service
-       MMS_SPECIAL_MSG_TYPE_POSTCARD_EXT1,     //Stickers Service
-       MMS_SPECIAL_MSG_TYPE_POSTCARD_EXT2,     //Photo 10x15
-       MMS_SPECIAL_MSG_TYPE_POSTCARD_EXT3,     //8 Photos
-       MMS_SPECIAL_MSG_TYPE_POSTCARD_EXT4,     // 4 Photos
-} MmsSpecialMsgType;
-
-typedef enum {
-       MMS_MM_CLASS_TEXT,
-       MMS_MM_CLASS_IMAGE_BASIC,
-       MMS_MM_CLASS_IMAGE_RICH,
-       MMS_MM_CLASS_VIDEO_BASIC,
-       MMS_MM_CLASS_VIDEO_RICH,
-       MMS_MM_CLASS_MEGAPIXEL,
-       MMS_MM_CLASS_CONTENT_BASIC,
-       MMS_MM_CLASS_CONTENT_RICH,
-       MMS_MM_CLASS_OTHER
-} MmsUiMmClass;
-
-typedef enum {
        MMS_MSGCLASS_ERROR = -1,        // error return in Get method
        MMS_MSGCLASS_PERSONAL = 0,      // default
        MMS_MSGCLASS_ADVERTISEMENT = 1,
@@ -389,7 +349,6 @@ typedef struct _MMS_ATTRIB_S {
        MmsPriority priority;
 
        MmsReplyCharge replyCharge;
-       bool bChargingMsgReplied;
 
        bool bHideAddress;
        bool bAskDeliveryReport;
@@ -397,31 +356,18 @@ typedef struct _MMS_ATTRIB_S {
        MmsRecvReadReportType readReportAllowedType;
 
        bool bAskReadReply;
-       bool bRead;
+       bool bRead;//FIXME : remove this value
 
        MmsRecvReadReportSendStatus readReportSendStatus;
 
        bool bReadReportSent;
 
        bool bLeaveCopy;
-       bool bUseExpiryCustomTime;              // for expiry custom time
-       bool bUseDeliveryCustomTime;    // for expiry custom time
-       MmsEditStyleMode editStyleMode;                 //editStyle on All Page
-
-       MmsSpecialMsgType specialMsgType;                       // instead of bPostcard
-
-#ifdef __SUPPORT_DRM__
-       MsgDrmType drmType;
-       int roWaitingTimerMax;          // DRM RO WAITING
-       char *pszDrmData;                       // DRM Data to draw mailbox icon
-#endif
 
        int msgSize;
        MmsMsgClass msgClass;
        MmsTimeStruct expiryTime;
-       MmsTimeStruct expiryCustomTime;
        MmsTimeStruct deliveryTime;
-       MmsTimeStruct deliveryCustomTime;
 
        //for ReadMsg, When Sending notifyResp.ind
        msg_delivery_report_status_t msgStatus;
@@ -432,7 +378,7 @@ typedef struct _MMS_ATTRIB_S {
        char szRetrieveText[MMS_LOCALE_RESP_TEXT_LEN + 1];
 
        MmsMsgMultiStatus *pMultiStatus;
-       bool bRetrieveNow;
+
 } MmsAttrib;
 
 typedef struct _MsgContentParam {
@@ -454,7 +400,6 @@ typedef struct _MsgContentParam {
        MsgParamReportType reportType; //only used as parameter of Content-Type: multipart/report; report-type=delivery-status;
 } MsgContentParam;
 
-#ifdef __SUPPORT_DRM__
 typedef struct _MsgDRMInfo {
        MsgDrmType drmType;
        MimeType contentType;
@@ -470,7 +415,6 @@ typedef struct _MsgDRMInfo {
        bool bNoRingTone;
        bool bNoScreen;
 } MsgDRMInfo;
-#endif
 
 typedef struct _MsgType {
        int offset;
@@ -478,49 +422,18 @@ typedef struct _MsgType {
        int contentSize;
        int section;
        int type;
-#ifdef __SUPPORT_DRM__
+
        MsgDRMInfo drmInfo;
-#endif
+
        int encoding;
        int disposition;
        char szContentID[MSG_MSG_ID_LEN + 1];
        char szContentLocation[MSG_MSG_ID_LEN + 1];
        char szOrgFilePath[MSG_FILEPATH_LEN_MAX];
 
-       char szContentRepPos[30];
-       char szContentRepSize[30];
-       char szContentRepIndex[8];
-#ifdef __SUPPORT_DRM__
-       int nDrmConvertedStatus;
-#endif
-
        MsgContentParam param;
 } MsgType;
 
-struct _MsgAddress {
-       int type;                                       //MSG_ADDR_TYPE_PHONE/EMAIL/IPV4/IPV6
-       int recipientType;                      // TO, CC, BCC
-       char szName[MSG_LOCALE_NAME_LEN + 1];
-       char szAddr[MSG_ADDR_LEN + 1];
-       MsgAddress *pNext;
-       bool bDoNotShow;                                // temporary clip
-
-       // sorting
-       ULONG uLastRecentTime;          // last recent time save item
-       ULONG uMostUseCount;                    // most use count item.
-       int index;                                      // index sorting..
-};
-
-typedef struct _MsgHeader {
-       MsgAddress *pFrom;
-       MsgAddress *pTo;
-       MsgAddress *pCC;
-       char szReturnPath[MSG_ADDR_LEN + 1];
-       char szDate[MSG_DATE_LEN];
-       char szSubject[MSG_LOCALE_SUBJ_LEN + 1];
-       char szMsgID[MSG_MSG_ID_LEN + 1];
-} MsgHeader;
-
 struct _MsgBody {
        int offset;
        int size;
@@ -530,9 +443,7 @@ struct _MsgBody {
 
        union {
                char *pText;
-               void *pBinary;
                MsgMultipart *pMultipart;
-               MsgMessage *pMessage;
        } body;
 };
 
@@ -542,12 +453,6 @@ struct _MsgMultipart {
        MsgMultipart *pNext;
 };
 
-struct _MsgMessage {
-       MsgHeader header;
-       MsgType type;
-       MsgBody *pBody;
-};
-
 typedef struct _MMS_MESSAGE_S {
        MmsAttrib mmsAttrib;
        msg_message_id_t msgID;
diff --git a/plugin/mms_plugin/include/MmsPluginComposer.h b/plugin/mms_plugin/include/MmsPluginComposer.h
new file mode 100755 (executable)
index 0000000..c354d28
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MMS_PLUGIN_COMPOSER_H
+#define MMS_PLUGIN_COMPOSER_H
+
+#include "MmsPluginTypes.h"
+#include "MmsPluginCodec.h"
+
+//make MMS_DATA_S for DB & Encoding
+class MmsPluginComposer {
+public:
+       static MmsPluginComposer *instance();
+
+       void composeNotiInd();
+       void composeDeliveryInd();
+       void composeReadOriInd();
+       void composeRetrieveConf(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_DATA_S *pMmsData){};
+
+       void composeSendReq(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_DATA_S *pMmsData);
+
+       void composeReadReport();
+       void composeAckInd();
+       void composeNotiRespInd();
+
+private:
+       static MmsPluginComposer *pInstance;
+
+       MmsPluginComposer();
+       ~MmsPluginComposer();
+
+};
+#endif //MMS_PLUGIN_COMPOSER_H
index eddbd69..f8402d1 100755 (executable)
@@ -1,42 +1,43 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_CONNMAN_H
 #define MMS_PLUGIN_CONNMAN_H
 
-#include <network-cm-intf.h>
-#include <network-pm-intf.h>
 #include "MsgMutex.h"
-#include <glib.h>
 #include "net_connection.h"
 
+typedef enum {
+       MSG_CM_ERR_NONE = 0,
+       MSG_CM_ERR_UNKNOWN,
+ } cm_error_e;
+
 class MmsPluginCmAgent
 {
 public:
        static MmsPluginCmAgent *instance();
 
-       /* open and close are occasionally called when transaction begins and ends */
        bool open();
        void close();
 
        bool getCmStatus() { return isCmOpened; }
 
-       void open_callback(connection_error_e result, void* user_data);
-       void close_callback(connection_error_e result, void* user_data);
-
+       void connection_profile_open_callback(connection_error_e result, void* user_data);
+       void connection_profile_close_callback(connection_error_e result, void* user_data);
+       void connection_profile_state_changed_cb(connection_profile_state_e state, void* user_data);
        bool getInterfaceName(const char **deviceName);
        bool getProxyAddr(const char **proxyAddr);
        bool getHomeUrl(const char **homeURL);
@@ -49,12 +50,12 @@ private:
        void lock() { mx.lock(); }
        void unlock() { mx.unlock(); }
        void signal() { cv.signal(); }
+
        void setCmStatus() { isCmOpened = true; }
        void resetCmStatus() { isCmOpened = false; }
 
-       bool isCmOpened;
-       bool isCmRegistered;
-
+       bool isCmOpened; //connection & profile connect
+       bool waitProfileOpen;
        char *home_url;
        char *interface_name;
        char *proxy_address;
index ce767c5..d77485e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_DEBUG_H
index 36eda58..ddd3b3e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_DECODE_H
@@ -33,11 +33,6 @@ typedef enum {
 } MsgPresentationFactor;
 
 typedef struct {
-       char *pData;
-       UINT32 length;
-} EncodedPData;
-
-typedef struct {
        MsgPresentationFactor factor;
        MsgMultipart *pPrevPart;
        MsgMultipart *pCurPresentation;
@@ -50,10 +45,6 @@ struct _MsgHeaderAddress {
 
 // for Decoding & Encoding
 typedef struct {
-       bool bActive;
-       char *pszOwner;
-       int msgID;              // if noti.ind, msgID is -1.
-
        MmsMsgType type;
        char szTrID[MMS_TR_ID_LEN+1];
        UINT8 version;
@@ -88,9 +79,7 @@ typedef struct {
        char szMsgID[MMS_MSG_ID_LEN + 1];
        UINT32 msgSize;
 
-#ifdef __SUPPORT_DRM__
        MsgDrmType drmType;
-#endif
 
        // dependent to Client implementation
        MsgType msgType;
@@ -113,19 +102,22 @@ char *MsgChangeHexString(char *pOrg);
 char *MsgResolveContentURI(char *szSrc);
 char *MsgRemoveQuoteFromFilename(char *pSrc);
 bool MsgIsMultipart(int type);
-bool MmsAddrUtilCompareAddr(char *pszAddr1, char *pszAddr2);
-bool MmsDataUpdateLastStatus(MmsMsg *pMsg);
 bool MmsAddrUtilRemovePlmnString(char *pszAddr);
-bool MsgGetTypeByFileName(int *type, char *szFileName);
+bool MmsAddrUtilCheckEmailAddress(char *pszAddr);
 bool MsgGetFileNameWithoutExtension(char *szOutputName, char *szName);
-int MmsGetMediaPartCount(msg_message_id_t msgId);
+bool MsgGetFileName(char *szFilePath, char *szFileName, int size);
 bool MmsGetMediaPartHeader(int index, MsgType *pHeader);
-bool MmsGetMsgAttrib(MmsMsgID msgID, MmsAttrib *pAttrib);
 
-#ifdef __SUPPORT_DRM__
-bool MsgCopyDrmInfo(MsgType *pPartType);
-bool MmsDrm2ConvertMsgBody(char *szOriginFilePath);
-bool MmsDrm2ReadMsgConvertedBody(MSG_MESSAGE_INFO_S *pMsg, bool bSavePartsAsTempFiles, bool bRetrieved, char *retrievedPath);
-#endif
+class MmsPluginDecoder {
+public:
+       static MmsPluginDecoder *instance();
 
+       void decodeMmsPdu(MmsMsg *pMmsMsg, msg_message_id_t msgID, const char *pduFilePath);
+private:
+       static MmsPluginDecoder *pInstance;
+
+       MmsPluginDecoder();
+       ~MmsPluginDecoder();
+
+};
 #endif //MMS_PLUGIN_DECODE_H
index e8563f2..f40112b 100755 (executable)
@@ -1,45 +1,24 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_DRM_H
 #define MMS_PLUGIN_DRM_H
 
-#include "MsgMmsTypes.h"
 #include "MmsPluginCodecTypes.h"
 
-#ifdef __SUPPORT_DRM__
-
-#define        MMS_DECODE_DRM_CONVERTED_TEMP_FILE MSG_DATA_PATH"Mms_Decode_Drm_Converted"
-#define        MMS_MIMETYPELENGTH 50
-
-typedef enum {
-       MMS_DRM2_CONVERT_NONE,
-       MMS_DRM2_CONVERT_NOT_FIXED,
-       MMS_DRM2_CONVERT_REQUIRED,
-       MMS_DRM2_CONVERT_FINISH
-} MmsDrm2ConvertState;
-
-MsgDrmType MsgGetDRMType(MsgType *pMsgType, MsgBody *pMsgBody);
-void MmsDrm2SetConvertState(MmsDrm2ConvertState newConvertState);
-MmsDrm2ConvertState MmsDrm2GetConvertState(void);
-bool MsgDRM2GetDRMInfo(char *szFilePath, MsgType *pMsgType);
-bool MsgDRMIsForwardLockType(MsgDrmType drmType);
-bool MsgChangeDrm2FileName(char *szFileName);
-bool MsgIsDCFFile(char *szFilePath);
-
-#endif //__SUPPORT_DRM__
+bool MmsPluginDrmGetInfo(const char *szFilePath, MsgType *pMsgType);
 
 #endif //MMS_PLUGIN_DRM_H
index 7817930..235b45b 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_ENCODE_H
@@ -34,4 +34,17 @@ bool MmsEncodeNotiRespInd(FILE *pFile, char *szTrID, msg_delivery_report_status_
 bool MmsEncodeReadReport10(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus);
 bool MmsEncodeReadReport11(FILE *pFile, MmsMsg *pMsg, msg_read_report_status_t mmsReadStatus);
 
+class MmsPluginEncoder {
+public:
+       static MmsPluginEncoder *instance();
+
+       void encodeMmsPdu(MMS_DATA_S *pMmsData, msg_message_id_t msgID, const char *pduFilePath);
+       void encodeMmsPdu(MmsMsg *pMmsMsg, msg_message_id_t msgID, const char *pduFilePath);
+private:
+       static MmsPluginEncoder *pInstance;
+
+       MmsPluginEncoder();
+       ~MmsPluginEncoder();
+
+};
 #endif //MMS_PLUGIN_ENCODE_H
index d38f0e1..2aa676b 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_EVENT_HANDLER_H
@@ -26,7 +26,6 @@ public:
        static MmsPluginEventHandler *instance();
 
        void registerListener(MSG_PLUGIN_LISTENER_S *pListener);
-       void handleSentStatus(int TapiReqId, msg_network_status_t NetStatus);
        void handleMmsReceivedData(mmsTranQEntity *pRequest, char *pRetrivedFilePath);
        void handleMmsError(mmsTranQEntity *pRequest);
 
index d090de6..7be2f8e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_HTTP_H
 #define MSG_MMS_HH_LANGUAGE         "zh-cn, en"
 #define MSG_MMS_HH_ENCODING         "deflate,gzip"
 
-#define MSG_MMS_HH_USER_AGENT          "Mozilla/5.0 (Linux; U; Tizen 1.0; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Mobile Tizen Browser/1.0"
-#define MSG_MMS_WAP_PROFILE         ""
+#define MSG_MMS_HH_USER_AGENT          "Mozilla/5.0 (Linux; Tizen 2.3) AppleWebKit/537.3 (KHTML, like Gecko) Version/2.2 Mobile Safari/537.3"
 
 typedef unsigned int MMS_HTTP_HEADER_FIELD_T;
 
 
-enum _MMS_HTTP_HEADER_FIELD_E {
+typedef enum _MMS_HTTP_HEADER_FIELD_E {
        MMS_HH_CONTENT_TYPE,
        MMS_HH_HOST,
        MMS_HH_ACCEPT,
@@ -41,8 +40,8 @@ enum _MMS_HTTP_HEADER_FIELD_E {
        MMS_HH_ACCEPT_LANGUAGE,
        MMS_HH_ACCEPT_ENCODING,
        MMS_HH_USER_AGENT,
-       MMS_HH_WAP_PROFILE
-};
+       MMS_HH_UA_PROFILE
+} MMS_HTTP_HEADER_FIELD_E;
 
 typedef enum _MMS_HTTP_TRANSACTION_TYPE_E {
        MMS_HTTP_TRANSACTION_TYPE_UNKNOWN = 0,
@@ -55,6 +54,7 @@ typedef enum _MMS_HTTP_ERROR_E {
        MMS_HTTP_ERROR_ABORT,
        MMS_HTTP_ERROR_TRANSACTION_TYPE,
        MMS_HTTP_ERROR_TRANSACTION,
+       MMS_HTTP_ERROR_SESSION,
 } MMS_HTTP_ERROR_E;
 
 typedef struct _http_session_info_s {
index 4627696..53550f3 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_INTERNAL_H
@@ -42,6 +42,7 @@ class MmsPluginInternal
                void processDeliveryInd(MSG_MESSAGE_INFO_S *pMsgInfo);
                void processReadOrgInd(MSG_MESSAGE_INFO_S *pMsgInfo);
                bool checkRejectNotiInd(int roamState, bool bReportAllowed, char *pSendFilePath);
+               bool checkFilterMmsBody(MMS_DATA_S *pMmsData);
                bool getMmsReport(MmsReport mmsReport);
                const char *getMmsDeliveryStatus(msg_delivery_report_status_t deliveryStatus);
                const char *getMmsReadStatus(msg_read_report_status_t readStatus);
index 35066cc..fe53ff8 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_MIME_H
 
 #include "MmsPluginTypes.h"
 
-#define                MSG_CH_CR                                               '\r'
-#define                MSG_CH_LF                                               '\n'
-#define                MSG_CH_SP                                               ' '
-#define                MSG_CH_TAB                                              '\t'
-#define                MSG_CH_NULL                                             '\0'
-#define                MSG_CH_COLON                                    ':'
-#define                MSG_CH_SEMICOLON                                ';'
-#define                MSG_CH_UNDERLINE                                '_'
-#define                MSG_CH_COMMA                                    ','
-#define                MSG_CH_BASE64_LOWER                             'b'
-#define                MSG_CH_BASE64_UPPER                             'B'
-#define                MSG_CH_QPRINT_LOWER                             'Q'
-#define                MSG_CH_QPRINT_UPPER                             'q'
-
-#define                MSG_CH_QUESTION                                 '?'
-#define                MSG_CH_QUOT                                             '"'
-#define                MSG_CH_EQUAL                                    '='
-#define                MSG_CH_BRACKET_S                                '<'
-#define                MSG_CH_BRACKET_E                                '>'
-
-#define                MSG_STR_DEC_START                       "=?"
-#define                MSG_STR_DEC_END                         "?="
-#define                MSG_STR_CRLF                            "\r\n"
-#define                MSG_END_OF_HEADER                       "\r\n\r\n"
-#define                MSG_STR_DOUBLE_HYPEN            "--"
-#define                MSG_STR_BOUNDARY_DEL            "\r\n--"
-
-#define                MSG_MMS_CH_EMAIL_AT                     '@'
-
-
-/* character-set parameter value of content-type header field */
-enum {
-       MSG_CHARSET_US_ASCII,                   //0
-       MSG_CHARSET_UTF16,
-       MSG_CHARSET_USC2,
-       MSG_CHARSET_UTF8,
-       /* MIME character-set value */
-
-       MSG_CHARSET_ISO_2022_KR,
-       MSG_CHARSET_KS_C_5601_1987,
-       MSG_CHARSET_EUC_KR,     // KS_C5861-1992
-       MSG_CHARSET_ISO_2022_JP,
-       MSG_CHARSET_ISO_2022_JP_2,
-       MSG_CHARSET_ISO_8859_1,                 //Latin1
-       MSG_CHARSET_ISO_8859_2,
-       MSG_CHARSET_ISO_8859_3,
-       MSG_CHARSET_ISO_8859_4,
-       MSG_CHARSET_ISO_8859_5,
-       MSG_CHARSET_ISO_8859_6,
-       MSG_CHARSET_ISO_8859_6_E,
-       MSG_CHARSET_ISO_8859_6_I,
-       MSG_CHARSET_ISO_8859_7,
-       MSG_CHARSET_ISO_8859_8,
-       MSG_CHARSET_ISO_8859_8_I,
-       MSG_CHARSET_ISO_8859_9,
-       MSG_CHARSET_ISO_8859_10,
-       MSG_CHARSET_ISO_8859_15,
-       MSG_CHARSET_Shift_JIS,
-       MSG_CHARSET_EUC_JP,
-       MSG_CHARSET_GB2312,
-       MSG_CHARSET_BIG5,
-       MSG_CHARSET_WIN1251,
-       MSG_CHARSET_WINDOW_1251,
-       MSG_CHARSET_WINDOWS_1251, // same: WIN1251, WINDOW-1251, WINDOWS-1251
-       MSG_CHARSET_KOI8_R,
-       MSG_CHARSET_KOI8_U,
-
-       MSG_CHARSET_NUM,
-       MSG_CHARSET_UNKNOWN
-};
-
-/* Content-Transfer-Encoding header field value */
-enum {
-       MSG_ENCODING_7BIT,
-       MSG_ENCODING_8BIT,
-       MSG_ENCODING_BINARY,
-       MSG_ENCODING_BASE64,
-       MSG_ENCODING_QUOTE_PRINTABLE,
-       MSG_ENCODING_NUM,
-       MSG_ENCODING_OTHER,
-};
-
-
-/* Content-Disposition header field value */
-enum {
-       MSG_DISPOSITION_FORMDATA,
-       MSG_DISPOSITION_ATTACHMENT,
-       MSG_DISPOSITION_INLINE,
-       MSG_DISPOSITION_NUM
-};
-
-#define                UNDEFINED_BINARY        0xFF
-#define                MSG_UNKNOWN_TYPE_STRING         "unknown"
+#define UNDEFINED_BINARY       0xFF
 
 typedef enum _MimeMainType {
+       MIME_MAINTYPE_UNKNOWN = -1,
        MIME_MAINTYPE_APPLICATION,
        MIME_MAINTYPE_AUDIO,
        MIME_MAINTYPE_IMAGE,
@@ -125,149 +34,20 @@ typedef enum _MimeMainType {
        MIME_MAINTYPE_ETC
 } MimeMainType;
 
-typedef enum _MimeAppType {
-       MIME_APPLICATION_NONE,
-
-       MIME_APPLICATION_CAMERA,
-       MIME_APPLICATION_VIDEORECORDER,
-
-       MIME_APPLICATION_IMAGEVIEWER,
-       MIME_APPLICATION_FLASHVIEWER,
-       MIME_APPLICATION_IMAGEEDITOR,
-       MIME_APPLICATION_THEMEVIEWER,
-
-       MIME_APPLICATION_SOUNDPLAYER,
-       MIME_APPLICATION_MEDIAPLAYER,
-       MIME_APPLICATION_VOICEMEMO,
-
-       MIME_APPLICATION_PICSELVIEWER,
-
-       MIME_APPLICATION_CONTACT,
-       MIME_APPLICATION_ORGANIZER,
-
-       MIME_APPLICATION_MAX
-} MimeAppType;
-
-
-typedef struct _MimeTable {
-       const char *szMIME;
-       const char *szExt;
-       bool bDownloadable;
-       MimeType mime;                  /* index of mime type */
-       MimeType contentType;   /* representative mime type */
-       MimeAppType appType;
-       MimeMainType mainType;
-       int binary;
-} MimeTable;
-
-typedef struct _ExtTable {
-       const char *szExt;
-       MimeType mimeType;
-} ExtTable;
-
-/* MIME string table ID */
-typedef enum {
-       MSG_ENCODING,
-       MSG_DISPOSITION,
-       MSG_FIELD,
-       MSG_PARAM,
-       MSG_TYPE,
-       MSG_CHARSET,
-       MSG_ADDR_TYPE,
-} MsgHeaderField;
-
-typedef enum {
-       MSG_ADDR_TYPE_ERROR = -1,               // error return in Get method
-       MSG_ADDR_TYPE_PHONE = 0,
-       MSG_ADDR_TYPE_EMAIL = 1,
-       MSG_ADDR_TYPE_IPV4  = 2,
-       MSG_ADDR_TYPE_IPV6  = 3,
-       MSG_ADDR_TYPE_ALIAS = 4,
-       MSG_ADDR_TYPE_NUM   = 5,
-} MsgAddrType;
-
-/* MIME header field */
-enum {
-       MSG_FIELD_RETURN_PATH,
-       MSG_FIELD_MESSAGE_ID,
-       MSG_FIELD_FROM,
-       MSG_FIELD_TO,
-       MSG_FIELD_CC,
-       MSG_FIELD_SUBJECT,
-       MSG_FIELD_DATE,
-       MSG_FIELD_MIME_VERSION,
-       MSG_FIELD_CONTENT_TYPE,
-       MSG_FIELD_CONTENT_TRANSFER_ENCODING,
-       MSG_FIELD_CONTENT_DISPOSITION, //If start param is given in multipart/related, this field will be ignored
-       MSG_FIELD_CONTENT_ID,
-       MSG_FIELD_CONTENT_LOCATION,
-       MSG_FIELD_CONTENT_NAME,
-       MSG_FIELD_CONTENT_DESCRIPTION,
-       MSG_FIELD_CONTENT_VENDOR,
-       MSG_FIELD_RIGHT_ISSUER,
-
-       MSG_FIELD_RETURN_RECEIPT_TO,                    /* for Delivery confirm */
-       MSG_FIELD_DISPOSITION_NOTIFICATION_TO,  /* for Read confirm */
-
-       MSG_FILED_CONTENT_REPLACE_POS,
-       MSG_FILED_CONTENT_REPLACE_SIZE,
-       MSG_FILED_CONTENT_REPLACE_INDEX,
-#ifdef __SUPPORT_DRM__
-       MSG_FIELD_DRM_CONVERTED,
-#endif
-       MSG_FIELD_NUM,
-       MSG_FIELD_UNKNOWN,
-};
-
-/* MIME header field parameter */
-enum {
-       MSG_PARAM_CHARSET,
-       MSG_PARAM_NAME,
-       MSG_PARAM_FILENAME,
-       MSG_PARAM_TYPE,                 // only used as parameter of Content-Type: multipart/related
-       MSG_PARAM_START,                // Only if content-type is multipart/related
-       MSG_PARAM_START_INFO,   // Only if content-type is multipart/related
-       MSG_PARAM_BOUNDARY,
-       MSG_PARAM_REPORT_TYPE,  // only used as parameter of Content-Type: multipart/report; report-type=delivery-status;
-#ifdef FEATURE_JAVA_MMS
-       MSG_PARAM_APPLICATION_ID,
-       MSG_PARAM_REPLY_TO_APPLICATION_ID,
-#endif
-       MSG_PARAM_NUM,
-       MSG_PARAM_UNKNOWN,
-};
-
-/********************          API definition           ************************/
-
-bool MimeIsDownloadableInt(MimeType mime);
-bool MimeIsDownloadableString(const char *szMime);
 char *MimeGetExtFromMimeInt(MimeType mime);
-char *MimeGetExtFromMimeString(const char *szMime);
-char *MimeGetMimeFromExtString(const char *szExt);
-MimeType MimeGetMimeFromExtInt(const char *szExt);
-MimeMainType MimeGetMainTypeInt(MimeType mime);
-MimeMainType MimeGetMainTypeString(const char *szMime);
-MimeType MimeGetMimeIntFromBi(int binCode);
-char *MimeGetMimeStringFromBi(int binCode);
-int MimeGetBinaryValueFromMimeInt(MimeType mime);
-int MimeGetBinaryValueFromMimeString(const char *szMime);
 
-// Append the functions on MimeAppType
-MimeAppType MimeGetAppTypeFromInt(MimeType mime);
-MimeAppType MimeGetAppTypeFromString(const char *szMime);
-MimeAppType MimeGetAppTypeFromExtString(const char *szExt);
+MimeMainType MimeGetMainTypeInt(MimeType mime);
 
-// Append the functions returning index and content type
+MimeType MimeGetMimeIntFromBi(int binCode);
 
-MimeType MimeGetContentTypeFromInt(MimeType mime);
-MimeType MimeGetContentTypeFromString(const char *szMime);
-MimeType MimeGetMimeTypeFromString(const char *szMime);
+int MimeGetBinaryValueFromMimeInt(MimeType mime);
 
 MimeType MimeGetMimeIntFromMimeString(char *szMimeStr);
+
 char *MimeGetMimeStringFromMimeInt(int mimeType);
 
-char *MsgGetString(MsgHeaderField tableId, int code);
-char *_MsgSkipWS3(char *s);
-int    _MsgGetCode(MsgHeaderField tableId, char *pStr);
+bool MmsGetMimeTypeFromExt(MimeMainType mainType, const char *pExt, MimeType *pMimeType, const char **ppszMimeType);
+
+bool MmsGetMimeTypeFromFileName(MimeMainType mainType, const char *pFileName, MimeType *pMimeType, const char **ppszMimeType);
 
 #endif // MMS_PLUGIN_MIME_H
index 0b0cf4c..527dff8 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_MAIN_H
@@ -40,7 +40,7 @@ msg_error_t MmsProcessReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO
 
 msg_error_t MmsUpdateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData);
 
-msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg);
+msg_error_t MmsGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg,  MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg);
 
 msg_error_t MmsUpdateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo);
 
index 5d0060c..a12ad04 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_MESSAGE_H
 #include "MmsPluginTypes.h"
 #include "MmsPluginCodec.h"
 
-MsgMultipart *MmsAllocMultipart(void);
-MsgMultipart *MmsMakeMultipart(MimeType mimeType, char *szTitleName, char *szOrgFilePath, char *szContentID, char *szContentLocation);
 
-bool MmsIsMultipart(int type);
-bool MmsIsText(int type);
-bool MmsIsVitemContent(int type, char *pszName);
-
-bool MmsComposeMessage(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMsgData, char *pFileData);
 void MmsComposeNotiMessage(MmsMsg *pMmsMsg, msg_message_id_t msgID);
+
 void MmsComposeReadReportMessage(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, msg_message_id_t selectedMsgId);
-bool MmsComposeSendReq(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMsgData);
 
+//int MmsUpdatePreviewData(MSG_MESSAGE_INFO_S *pMsgInfo);
+//
+//int MmsUpdateMultipartList(MSG_MESSAGE_INFO_S *pMsgInfo);
 
-bool MmsEncodeMmsMessage(MmsMsg *pMmsMsg, const char *raw_filepath);
+//void MmsPrintFileInfoForVLD(MMS_MESSAGE_DATA_S *pMmsMsg);
+//
+//bool MmsChangeFileNameToAscii(MMS_MESSAGE_DATA_S *pMsgData);
 
-bool MmsMakeMmsData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg);
+bool MmsConvertMsgData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg);
 
-bool MmsCheckAdditionalMedia(MMS_MESSAGE_DATA_S *pMsgData, MsgType *partHeader);
+bool MmsConvertMmsData(MmsMsg *pMsg, MMS_DATA_S *pMmsData);//temp func for supporting new mmsdata
 
-bool MmsRemovePims(MMS_MESSAGE_DATA_S *pMsgData);
+bool MmsConvertMmsMsg(MmsMsg *pMmsMsg, MMS_DATA_S *pMsgData);
 
-msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg);
+msg_error_t MmsMakeMultipartThumbnailInfo(MMS_MULTIPART_DATA_S *pMultipart, char *thumbnail_path);
 
-void MmsPrintFileInfoForVLD(MMS_MESSAGE_DATA_S *pMmsMsg);
-int MmsUpdatePreviewData(MSG_MESSAGE_INFO_S *pMsgInfo);
 #endif //MMS_PLUGIN_MESSAGE_H
diff --git a/plugin/mms_plugin/include/MmsPluginSMILValidate.h b/plugin/mms_plugin/include/MmsPluginSMILValidate.h
deleted file mode 100755 (executable)
index 66f45d9..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef MMS_PLUGIN_SMIL_VALIDATE_H
-#define MMS_PLUGIN_SMIL_VALIDATE_H
-
-#include "MsgMmsTypes.h"
-
-/**
- *     @brief  Represents the default values of SMIL root layout. \n
- */
-#define MSG_SMIL_ROOT_LAYOUT_WIDTH     (100)
-#define MSG_SMIL_ROOT_LAYOUT_HEIGHT    (100)
-#define MSG_SMIL_ROOT_LAYOUT_IN_PERCENT        (true)
-#define MSG_SMIL_ROOT_LAYOUT_BG_COLOR  "#FFFFFF"
-
-/**
- *     @brief  Represents the default values of SMIL Region \n
- */
-#define MSG_SMIL_DEFAULT_TXT_REG       "text"
-#define MSG_SMIL_DEFAULT_IMG_REG       "image"
-#define MSG_SMIL_DEFAULT_FULL_REG      "full"
-#define MSG_SMIL_REG_FIT_TYPE          "meet"
-#define MSG_SMIL_REG_BG_COLOR          "#FFFFFF"
-
-#define MSG_SMIL_FULL_REG_LEFT                         (0)
-#define MSG_SMIL_FULL_REG_TOP                          (0)
-#define MSG_SMIL_FULL_REG_WIDTH                                (100)
-#define MSG_SMIL_FULL_REG_HEIGHT                       (100)
-
-#define MSG_SMIL_FIRST_REG_LEFT                                (0)
-#define MSG_SMIL_FIRST_REG_TOP                         (0)
-#define MSG_SMIL_FIRST_REG_WIDTH                       (100)
-#define MSG_SMIL_FIRST_REG_HEIGHT                      (50)
-
-#define MSG_SMIL_SECOND_REG_LEFT                       (0)
-#define MSG_SMIL_SECOND_REG_TOP                                (50)
-#define MSG_SMIL_SECOND_REG_WIDTH                      (100)
-#define MSG_SMIL_SECOND_REG_HEIGHT                     (50)
-
-/**
- *     @brief  Represents the default values of SMIL Media \n
- */
-#define MSG_SMIL_REG_POSITION_IS_DEFAULT       (true)
-#define MSG_SMIL_TEXT_ON_TOP                           (true)
-
-
-/*==================================================================================================
- *                                     ENUMS
- *==================================================================================================*/
-
-/**
- *     @brief  Represents the values of an smil error code. \n
- *     Success code is zero, but all error codes SHOULD be negative and smaller than MSG_SMIL_ERR_BEGIN. \n
- */
-enum MSG_SMIL_ERR_E {
-       MSG_SMIL_SUCCESS = 0,
-       MSG_SMIL_ERR_UNKNOWN = -255,
-       MSG_SMIL_ERR_INVALID_ROOTLAYOUT,
-       MSG_SMIL_ERR_INVALID_REGION_INFO,
-       MSG_SMIL_ERR_SIMILAR_MEDIA_EXISTS,
-       MSG_SMIL_ERR_INVALID_SMIL_FILE_PATH,
-       MSG_SMIL_ERR_INVALID_PAGE_INFO,
-       MSG_SMIL_ERR_INVALID_PAGE_DUR,
-       MSG_SMIL_ERR_INVALID_PARAM,
-};
-
-/**    @fn             MSG_SMIL_ERR_E MsgMMSCreateSMIL(MMS_MESSAGE_DATA_S *pMsgData)
- *     @brief  Creates a SMIL buffer based on the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @param  pError is a pointer to a SMIL error type. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                Success in operation. \n
- *     @retval MSG_SMIL_ERR_UNKNOWN                            Encoding failed \n
- *     @retval MSG_SMIL_ERR_INVALID_ROOTLAYOUT         Invalid Root Layout \n
-  *    @retval MSG_SMIL_ERR_INVALID_REGION_INFO        Invalid Region \n
- *     @retval MSG_SMIL_ERR_SIMILAR_MEDIA_EXISTS       Duplicate media \n
- *     @retval MSG_SMIL_ERR_INVALID_SMIL_FILE_PATH     Invalid Smil Path \n
- *     @retval MSG_SMIL_ERR_INVALID_PAGE_INFO          Invalid Page Info \n
- *     @retval MSG_SMIL_ERR_INVALID_PAGE_DUR           Invalid Page Duration \n
- *     @retval MSG_SMIL_ERR_INVALID_PARAM                      Invalid Parameter \n
- */
-MSG_SMIL_ERR_E MsgMMSCreateSMIL(MMS_MESSAGE_DATA_S *pMsgData);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSValidateSMILRootLayout(MMS_MESSAGE_DATA_S *pMsgData)
- *     @brief  Validates the Root layout information present in the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_ROOTLAYOUT                 Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSValidateSMILRootLayout(MMS_MESSAGE_DATA_S *pMsgData);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSAddDefaultSMILRegions(MMS_MESSAGE_DATA_S *pMsgData)
- *     @brief  Adds the default Region information based on the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_ROOTLAYOUT                 Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSAddDefaultSMILRootLayout(MMS_MESSAGE_DATA_S *pMsgData);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSValidateSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bool *pbRegAdded)
- *     @brief  Validates the Region information present in the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_REGION_INFO                Failure in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_PAGE_INFO                  Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSValidateSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bool *pbRegAdded);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSAddDefaultFirstSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bool bTextReg)
- *     @brief  Adds the default first Region information when two regions are present in a page based on the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_REGION_INFO                Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSAddDefaultFirstSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bool bTextReg);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSAddDefaultSecondSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bool bTextReg)
- *     @brief  Adds the default second Region information when two regions are present in a page based on the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_REGION_INFO                Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSAddDefaultSecondSMILRegion(MMS_MESSAGE_DATA_S *pMsgData, bool bTextReg);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSAddDefaultFullSMILRegion(MMS_MESSAGE_DATA_S *pMsgData)
- *     @brief  Adds the default full Region information when only region is present in a page based on the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_REGION_INFO                Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSAddDefaultFullSMILRegion(MMS_MESSAGE_DATA_S *pMsgData);
-
-/**    @fn             MSG_SMIL_ERR_E _MsgMMSValidateSMILPage(MMS_MESSAGE_DATA_S *pMsgData, bool bRegAdded)
- *     @brief  Validates the Page information present in the Message handle.
- *     @param  pMsgData is Message handle. \n
- *     @return MSG_SMIL_ERR_E \n
- *     @retval MSG_SMIL_SUCCESS                                                Success in operation. \n
- *     @retval MSG_SMIL_ERR_INVALID_PAGE_INFO                  Failure in operation. \n
- *     @retval MSG_SMIL_ERR_SIMILAR_MEDIA_EXISTS               Same Kind of Media Exists in SMIL page. \n
- *     @retval MSG_SMIL_ERR_INVALID_REGION_INFO                Failure in operation. \n
- */
-MSG_SMIL_ERR_E _MsgMMSValidateSMILPage(MMS_MESSAGE_DATA_S *pMsgData, bool bRegAdded);
-
-#endif //MMS_PLUGIN_SMIL_ENCODE_H
diff --git a/plugin/mms_plugin/include/MmsPluginSmil.h b/plugin/mms_plugin/include/MmsPluginSmil.h
deleted file mode 100755 (executable)
index 23df37c..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef MMS_PLUGIN_SMIL_H
-#define MMS_PLUGIN_SMIL_H
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#include "MsgMmsTypes.h"
-#include "MmsPluginCodecTypes.h"
-
-typedef enum _SMIL_ELEMENT_T {
-       ELEMENT_SMIL,
-       ELEMENT_HEAD,
-       ELEMENT_LAYOUT,
-       ELEMENT_ROOTLAYOUT,
-       ELEMENT_REGION,
-       ELEMENT_TRANSITION,
-       ELEMENT_META,
-       ELEMENT_BODY,
-       ELEMENT_PAR,
-       ELEMENT_PARAM,
-       ELEMENT_TEXT,
-       ELEMENT_IMG,
-       ELEMENT_AUDIO,
-       ELEMENT_VIDEO,
-       ELEMENT_REF,
-       ELEMENT_ANIMATE,
-       ELEMENT_MAX,
-} SMIL_ELEMENT_T;
-
-typedef        int     HMmsSmil;                       // SmilDoc Handle
-
-#define MMS_SMIL_MAX_DOC       1
-#define MMS_SMIL_COLOR_SIZE    10
-#define INVALID_HOBJ   -1
-#define SP_NO_COLOR_SET        -1
-#define SP_BLACK       0
-
-/* Structures */
-/**
- *     @brief  Represents Smil Doc Information. \n
- */
-typedef struct _MmsSmilDoc {
-       xmlDocPtr pSmilDoc;
-       xmlNodePtr pstRootNode;
-} MmsSmilDoc;
-
-typedef enum _SMIL_ATTRIBUTE_T {
-       ATTRIBUTE_UNKNOWN = -1,
-       ATTRIBUTE_ID,
-       ATTRIBUTE_TOP,
-       ATTRIBUTE_LEFT,
-       ATTRIBUTE_WIDTH,
-       ATTRIBUTE_HEIGHT,
-       ATTRIBUTE_FIT,
-       ATTRIBUTE_BGCOLOR,
-       ATTRIBUTE_DUR,
-       ATTRIBUTE_SRC,
-       ATTRIBUTE_COLOR,
-       ATTRIBUTE_BOLD,
-       ATTRIBUTE_UNDERLINE,
-       ATTRIBUTE_ITALIC,
-       ATTRIBUTE_REVERSE,
-       ATTRIBUTE_DIRECTION,
-       ATTRIBUTE_SIZE,
-       ATTRIBUTE_FONT,
-       ATTRIBUTE_REGION,
-       ATTRIBUTE_NAME,
-       ATTRIBUTE_VALUE,
-       ATTRIBUTE_ALT,
-       ATTRIBUTE_TYPE,
-       ATTRIBUTE_SUBTYPE,
-       ATTRIBUTE_CONTENT,
-       ATTRIBUTE_FGCOLOR,
-       ATTRIBUTE_TEXTFORMAT,
-       ATTRIBUTE_TRANSIN,
-       ATTRIBUTE_TRANSOUT,
-       ATTRIBUTE_BEGIN,
-       ATTRIBUTE_END,
-       ATTRIBUTE_REPEAT_COUNT,
-} SMIL_ATTRIBUTE_T;
-
-char *MmsSmilGetPresentationData(msg_message_id_t msgId);
-bool MmsSmilParseSmilDoc(MMS_MESSAGE_DATA_S *pMmsMsg, char *pSmilDoc);
-void MmsSmilGetElement(MMS_MESSAGE_DATA_S *pMmsMsg, xmlNode *a_node);
-int MmsSmilGetColorValue(xmlChar *content);
-int MmsSmilGetTime(char *pValue);
-int MmsSmilAtoIHexa(char *pInput);
-#ifndef __SUPPORT_DRM__
-int MmsSmilGetMediaSrcForNormalMsg(char *szOutbuf, char *szInBuf, MsgMultipart *pPart);
-#else
-int MmsSmilGetMediaSrcForNormalMsg(char *szOutbuf, char *szInBuf, MsgMultipart *pPart, MMS_MEDIA_S *pMedia);
-#endif
-int MmsSmilGetElementID(char *pString);
-int MmsSmilGetAttrID(char *pString);
-bool MmsSmilGetFontAttrib(char *pString);
-MmsTextDirection MmsSmilGetFontDirection(char *pString);
-int MmsSmilGetFontSizeValue(char *pString);
-MmsSmilFontType MmsSmilGetFontTypeValue(char *pString);
-bool MmsSmilGetMediaFilePath(MMS_MEDIA_S *pMedia, char *pszTemp, int msgID);
-bool __MmsGetRealFileName(MmsSmilMediaType mediaType, char *pszSrc, char *pszName, int msgID);
-/**    @fn             bool MMSGenerateSmilBuffer(MMS_MESSAGE_DATA_S *pstMsgBody)
- *     @brief  Forms Smil Buffer using pstMsgBody. \n
- *     @param[in/out]  pstMsgBody is Message handle. \n
- *     @retval TRUE                            In case of Success. \n
- *     @retval FALSE                           In case of failure. \n
- */
-bool MMSGenerateSmilBuffer(MMS_MESSAGE_DATA_S *pstMsgBody);
-
-/**    @fn             HMmsSmil MmsSmilCreateEmptySmilDoc(void)
- *     @brief  Creates default Smil Doc based on input gszEmptyRawDoc. \n
- *     @retval Returns Smil Document number. \n
- */
-HMmsSmil MmsSmilCreateEmptySmilDoc(void);
-
- /**   @fn                     HMmsSmil MmsSmilCreateSmilDoc(char *pszRawData)
- *     @brief          Creates Smil Doc based on input pszRawData. \n
- *     @param[in]      pszRawData is smil buffer. \n
- *     @retval         Returns Smil Document number. \n
- */
-HMmsSmil MmsSmilCreateSmilDoc(char *pszRawData);
-
- /**   @fn                     BOOL MmsSmilDestroyDoc(HMmsSmil hSmilDoc)
- *     @brief          Destroys Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @retval TRUE                            In case of Success. \n
- *     @retval FALSE                           In case of failure. \n
- */
-bool MmsSmilDestroyDoc(HMmsSmil hSmilDoc);
-
-/**    @fn                     static bool IsValidSmilDocNo(int nSmilDocNo)
- *     @brief          Form Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @retval         Returns Smil Buffer     In case of success. \n
- *     @retval         Returns NULL                    In case of failure. \n
- */
-bool IsValidSmilDocNo(int nSmilDocNo);
-
-/**    @fn                     static char * MmsSmilGetRawData( HMmsSmil hSmilDoc )
- *     @brief          Form Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @retval         Returns Smil Buffer             In case of success. \n
- *     @retval         Returns NULL                    In case of failure. \n
- */
-char *MmsSmilGetRawData(HMmsSmil hSmilDoc);
-
-/**    @fn                     static bool MmsSmilAddPage(HMmsSmil hSmilDoc, MMS_PAGE_S *pstSmilPage)
- *     @brief          Add Page to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      pstSmilPage specifies page information. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddPage(HMmsSmil hSmilDoc, MMS_PAGE_S *pstSmilPage);
-
-/**    @fn                     static bool MmsSmilAddRootLayout(HMmsSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout)
- *     @brief          Add Rootlayout to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      pstSmilRootLayout specifies RootLayout information. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddRootLayout(HMmsSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout);
-
-/**    @fn                     static bool MmsSmilAddRegion(HMmsSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion)
- *     @brief          Add Region to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      pstSmilRegion specifies Region information. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddRegion(HMmsSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion);
-
-/**    @fn                     static bool MmsSmilAddMedia( HMmsSmil hSmilDoc, int nPageNo, MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
- *     @brief          Add Media to Smil Doc. \n
- *     @param[in]      hSmilDoc is smil doc number. \n
- *     @param[in]      nPageNo specifies page number to which media belongs. \n
- *     @param[in]      nMediaIdx specifies medi ID. \n
- *     @param[in]      pstSmilMedia specifies Media information. \n
- *     @param[in]      pszContentID specifies Content ID of media. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool MmsSmilAddMedia(HMmsSmil hSmilDoc, int nPageNo, int nMediaIdx, MMS_MEDIA_S *pstSmilMedia, char *pszContentID);
-
-/**    @fn                     static xmlNode *__MmsCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
- *     @brief          Create Text Element. \n
- *     @param[in]      pstSmilMedia specifies Media information. \n
- *     @param[in]      pszContentID specifies Content ID of media. \n
- *     @retval         Text Element node               In case of Success. \n
- *     @retval         NULL                            In case of failure. \n
- */
-xmlNode *__MmsCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID);
-
-/**    @fn                     static xmlNode *__MmsCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
- *     @brief          Create Image/Audio/Video Element. \n
- *     @param[in]      pstSmilMedia specifies Media information. \n
- *     @param[in]      pszContentID specifies Content ID of media. \n
- *     @retval         Image/Audio/Video Element node  In case of Success. \n
- *     @retval         NULL                                                    In case of failure. \n
- */
-xmlNode *__MmsCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID);
-
-/**    @fn                     static bool __MmsInsertFirstChild(xmlNode *pstParent, xmlNode *pstCurr)
- *     @brief          Inserts first child to parent node. \n
- *     @param[in]      pstParent specifies Parent node. \n
- *     @param[in]      pstCurr specifies Child node. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool __MmsInsertFirstChild(xmlNode *pParent, xmlNode *pNode);
-
-/**    @fn                     static bool __MmsSmilInsertNode(xmlNode *pstParent, xmlNode *pstLeftSibling, xmlNode *pstCurr)
- *     @brief          Inserts node. \n
- *     @param[in]      pstParent specifies Parent node. \n
- *     @param[in]      pstLeftSibling specifies Left Sibling node. \n
- *     @param[in]      pstCurr specifies Child node. \n
- *     @retval         TRUE                            In case of Success. \n
- *     @retval         FALSE                           In case of failure. \n
- */
-bool __MmsSmilInsertNode(xmlNode *pParent, xmlNode *pLeftSibling, xmlNode *pNode);
-
-/**    @fn                     static void _MmsSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue)
- *     @brief          Sets Attribute. \n
- *     @param[in]      pNode specifies node. \n
- *     @param[in]      szField specifies attribute field. \n
- *     @param[in]      szValue specifies value of field \n
- */
-void _MmsSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue);
-
-/**    @fn                     static char *__MmsSmilFindColorValue(int nValue)
- *     @brief          Converts color to RGB. \n
- *     @param[in]      nValue specifies color value. \n
- *     @retval         RGB value. \n
- */
-char *__MmsSmilFindColorValue(int nValue);
-
-/**    @fn                     static xmlNodePtr UtilxmlStringGetNodeList(xmlNodePtr pstNode, char *pszValue)
- *     @brief          Get node based on pszValue. \n
- *     @param[in]      pNode specifies node. \n
- *     @param[in]      pszName specifies name field. \n
- *     @retval         RGB value. \n
- */
-xmlNodePtr UtilxmlStringGetNodeList(xmlNodePtr pstNode, char *pszName);
-
-
-bool MmsSmilParseSmilDocOnlyLayout(MMS_MESSAGE_DATA_S *pMmsMsg, char *pSmilDoc);
-
-
-#endif//MMS_PLUGIN_SMIL_H
index bb4ad46..798e5af 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_STORAGE_H
@@ -28,53 +28,60 @@ public:
        MmsPluginStorage();
        ~MmsPluginStorage();
 
-       void addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData);
+       //MMS message operation
+       msg_error_t addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pSerializedMms);
+       msg_error_t getMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pSerializedMms);
+       msg_error_t updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pSerializedMms);
+       msg_error_t updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo);//malware allowed
+
+       msg_error_t deleteMmsMessage(int msgId);
+
+       //MMS message preview info
+       msg_error_t insertPreviewInfo(int msgId, int type, const char *value, int count = 0);
+       msg_error_t removePreviewInfo(int msgId);
+
+       //MMS message multipart list
+       msg_error_t insertMultipart(msg_message_id_t msgId, MMS_MULTIPART_DATA_S *pMultipart);
+       msg_error_t updateMultipart(msg_message_id_t msgId, int allow_malware, MMS_MULTIPART_DATA_S *pMultipart);
+       msg_error_t getMultipartList(msg_message_id_t msgId, MMSList **multipart_list);
+       msg_error_t deleteMultipartList(int msgId);
+
+       //MMS message report
+       msg_error_t insertDeliveryReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus);
+       msg_error_t insertReadReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus);
+
+       //etc
        void getMmsMessage(MmsMsg **pMmsMsg);
-       void getMmsAttrib(msg_message_id_t msgId, MmsMsg *pMmsMsg);
        msg_error_t getMmsMessageId(msg_message_id_t selectedMsgId, MmsMsg *pMmsMsg);
        void composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo);
 
        int searchMsgId(char *toNumber, char *szMsgID);
        int getMmsVersion(msg_message_id_t selectedMsgId);
 
-       msg_error_t updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData);
        msg_error_t updateConfMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
        msg_error_t updateMmsAttrib(msg_message_id_t msgId, MmsAttrib *attrib, MSG_SUB_TYPE_T msgSubType);
        msg_error_t updateMmsAttachCount(msg_message_id_t msgId, int count);
-       msg_error_t updateNetStatus(msg_message_id_t msgId, msg_network_status_t netStatus);
-
-       msg_error_t insertDeliveryReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus);
-       msg_error_t insertReadReport(msg_message_id_t msgId, char *address, MmsMsgMultiStatus *pStatus);
-       msg_error_t insertPreviewInfo(int msgId, int type, char *value, int count = 0);
 
-       msg_error_t removePreviewInfo(int msgId);
+       msg_error_t getMmsRawFilePath(msg_message_id_t msgId, char *pFilepath, size_t filePathLen);
 
-       msg_error_t setReadReportSendStatus(msg_message_id_t msgId, int readReportSendStatus);
-       msg_error_t plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg);
-       msg_error_t getContentLocation(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t getMmsRawFilePath(msg_message_id_t msgId, char *pFilepath);
+       msg_error_t getTrID(MSG_MESSAGE_INFO_S *pMsgInfo, char *pszTrID, int nBufferLen); /* reject_msg_support */
 
-       /* reject_msg_support */
-       msg_error_t getTrID(MSG_MESSAGE_INFO_S *pMsgInfo, char *pszTrID, int nBufferLen);
-       /* reject_msg_support */
        msg_error_t getAddressInfo(msg_message_id_t msgId, MSG_ADDRESS_INFO_S *pAddrInfo);
+
        msg_error_t updateMsgServerID(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo);
 
        msg_error_t getMsgText(MMS_MESSAGE_DATA_S *pMmsMsg, char *pMsgText);
 
-       msg_error_t deleteMmsMessage(int msgId);
-
+private:
        void getMmsFromDB(msg_message_id_t msgId, MmsMsg *pMmsMsg);
+       msg_error_t addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_filepath);
+       msg_error_t addMmsData(msg_message_id_t msgId, const char *raw_filepath, MMS_DATA_S *pMmsData);
+       msg_error_t getMmsData(msg_message_id_t msgId, MMS_DATA_S *pMmsData);
 
+       msg_error_t updateRetriveConf(msg_message_id_t msgId, MMS_DATA_S *pMmsData);
 
-
-private:
-       msg_error_t addMmsMsgToDB(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, int attachCnt = 0);
-       msg_error_t addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_filepath);
        static MmsPluginStorage *pInstance;
 
-       MsgDbHandler dbHandle;
-
        MmsMsg mmsMsg;
 };
 
diff --git a/plugin/mms_plugin/include/MmsPluginTcs.h b/plugin/mms_plugin/include/MmsPluginTcs.h
new file mode 100755 (executable)
index 0000000..449a000
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef MMS_PLUGIN_TCS_H
+#define MMS_PLUGIN_TCS_H
+
+//Scan content on file system.
+int MmsPluginTcsScanFile(const char *filepath, int *bLevel);
+
+#endif //MMS_PLUGIN_TCS_H
index 5e1e09d..50cf1d0 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_TEXT_CONVERT_H
index ff93af5..28cc34e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_TRANSPORT_H
@@ -31,10 +31,6 @@ class MmsPluginTransport
                MmsPluginTransport();
                ~MmsPluginTransport();
 
-               void submitProcess(mmsTranQEntity req);
-               MMS_NET_ERROR_T submitHandler(mmsTranQEntity *qEntity);
-               bool processReceivedData(int msgId, char *pRcvdBody, int rcvdBodyLen, char *retrievedFilePath);
-
                static MmsPluginTransport *pInstance;
 };
 
index 2703b72..f42a1f2 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_TYPES_H
 #define INOUT     /*! Pfrefix*/
 
 #define RETRY_MAX 1
-#define MAX_MMSC_URL_LEN       100
 #define HTTP_REQUEST_LEN   1024
-#define MAX_URL_LENGTH 1024
-#define MAX_IPV4_LENGTH 30
-
 
 typedef unsigned int MMS_NET_ERROR_T;
 typedef unsigned int MMS_PDU_TYPE_T;
 typedef unsigned char MMS_HTTP_CMD_TYPE_T;
-typedef unsigned int E_MMS_CONNECTION_MODE;
-typedef unsigned int E_MMS_NETWORK_ACCESS_POINT;
 
 enum _MMS_NET_ERROR_E {
        eMMS_SUCCESS = 0,
@@ -126,37 +120,5 @@ typedef struct _mmsTranQEntity {
        char *pGetData;
 } mmsTranQEntity;
 
-typedef struct  _MMSC_CONFIG_DATA_S {
-       char mmscUrl[MAX_URL_LENGTH + 1];                       /** if break, change it to NETPM_HOME_URL_LEN_MAX   */
-       char httpProxyIpAddr[MAX_IPV4_LENGTH + 1];      /**   HTTP Proxy's URL or IP address */
-
-       unsigned int proxyPortNo;       /** MMS HTTP proxy Port number  */
-       E_MMS_CONNECTION_MODE connectionMode;   /**   Values must be from ENUM list -\ref E_MMS_CONNECTION_MODE  */
-       E_MMS_NETWORK_ACCESS_POINT networkAccessPoint;  /**   Values must be from \ref E_MMS_NETWORK_ACCESS_POINT  */
-       unsigned int bAutoRetrieveFlag; /**  Value's shall be true or false */
-       unsigned int profileId;                 /** Profile is for CM Conn open*/
-} MMSC_CONFIG_DATA_S;
-
-typedef struct _MMS_PLUGIN_HTTP_DATA_S {
-       int profileId;
-       int profileCount;
-       int currentProfileId;
-       int sessionId;
-       int transactionId;
-       void *session;
-       void *sessionHeader;
-       MMSC_CONFIG_DATA_S mmscConfig;
-} MMS_PLUGIN_HTTP_DATA_S;
-
-typedef struct _MMS_PLUGIN_HTTP_CONTEXT_S {
-       char *recv_header_buf ;
-       int header_bufsize;
-       unsigned char *final_content_buf; // Final Concatenated Buffer
-       unsigned long ulContentLength;  // Content Leght Value received in HTTP OK Header
-       unsigned long bufOffset; /** < Incremented once received Content_receiving or Content_received Event */
-} MMS_PLUGIN_HTTP_CONTEXT_S;
-
-
-
 #endif //MMS_PLUGIN_TYPES_H
 
index f4f2b5b..3df0340 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_USERAGENT_H
@@ -53,7 +53,7 @@ class MmsPluginUaManager: public MsgThread
                // condition values
                bool running;           // flag for thread running
 
-               MsgThdSafeQ <mmsTranQEntity> mmsTranQ; // transaction q for mms plugin
+               MsgSimpleQ<mmsTranQEntity> mmsTranQ; // transaction q for mms plugin
 };
 
 #endif //MMS_PLUGIN_USERAGENT_H
index d0ff163..1e08034 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef MMS_PLUGIN_UTIL_H
 
 #include <stdio.h>
 
-bool makeImageThumbnail(char *srcPath, char *dstPath);
-bool makeVideoThumbnail(char *srcPath, char *dstPath);
-
-bool MsgIsASCII(char *pszText);
-bool MsgReplaceNonAscii(char *szInText, char **szOutText, char replaceChar);
-bool MsgIsSpace(char *pszText);
-bool MsgReplaceSpecialChar(char *szInText, char **szOutText, char specialChar);
-char *MsgStrAppend(char *szInputStr1, char *szInputStr2);
-char *MsgStrCopy(const char *string);
-char *MsgStrNCopy(const char *string, int length);
-int    MsgStrlen(char *pStr);
-bool MsgConvertCharToHex(char pSrc, char *pDest);
+//File Util
+bool MmsMakeImageThumbnail(char *srcPath, char *dstPath);
+
+bool MmsMakeVideoThumbnail(char *srcPath, char *dstPath);
+
 FILE *MmsFileOpen(char *pFileName);
-void removeLessGreaterMark(const char *szSrcID, char *szDest, int destSize);
+
+//Text Util
+bool MmsIsAsciiString(const char *szSrc);
+
+bool MmsIsUtf8String(const unsigned char *szSrc, int nChar);
+
+void MmsRemoveLessGreaterChar(const char *szSrc, char *szDest, int destSize);
+
+bool MmsRemoveMarkup(const char *szSrc, char *szDest, int dstsize);
+
+bool MmsReplaceSpaceChar(char *pszText);
+
+char *MmsReplaceNonAsciiUtf8(const char *szSrc, char replaceChar);
+
 #endif //MMS_PLUGIN_UTIL_H
index 09601e0..e99b5a0 100755 (executable)
@@ -30,17 +30,19 @@ SET(SMS-PLUGIN-SRCS
        ${CMAKE_SOURCE_DIR}/plugin/sms_plugin/SmsPluginUAManager.cpp
        ${CMAKE_SOURCE_DIR}/plugin/sms_plugin/SmsPluginCallback.cpp
        ${CMAKE_SOURCE_DIR}/plugin/sms_plugin/SmsPluginMain.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_plugin/SmsPluginDSHandler.cpp
 )
 
 INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/include/mapi
        ${CMAKE_SOURCE_DIR}/include/common
        ${CMAKE_SOURCE_DIR}/include/utils
+       ${CMAKE_SOURCE_DIR}/include/externals
        ${CMAKE_CURRENT_SOURCE_DIR}/include
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(sms_plugin_pkgs REQUIRED glib-2.0 tapi libxml-2.0 libwbxml2 drm-client dlog vconf dbus-glib-1)
+pkg_check_modules(sms_plugin_pkgs REQUIRED glib-2.0 tapi libxml-2.0 libwbxml2 dlog vconf dbus-glib-1 db-util)
 
 FOREACH(flag ${sms_plugin_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -53,7 +55,7 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${SMS-PLUGIN-LIB} SHARED ${SMS-PLUGIN-SRCS})
-TARGET_LINK_LIBRARIES(${SMS-PLUGIN-LIB} ${sms_plugin_pkgs_LDFLAGS} ${UTILS-LIB})
+TARGET_LINK_LIBRARIES(${SMS-PLUGIN-LIB} ${sms_plugin_pkgs_LDFLAGS} ${UTILS-LIB} ${EXTERNALS-LIB})
 
-INSTALL(TARGETS ${SMS-PLUGIN-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${SMS-PLUGIN-LIB} LIBRARY DESTINATION lib)
 
index 1ac2af8..8b28607 100755 (executable)
@@ -1,23 +1,24 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <glib.h>
 #include <pthread.h>
 
 #include "MsgDebug.h"
+#include "MsgCppTypes.h"
 #include "MsgException.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginCbMsgHandler.h"
 #include "SmsPluginSetting.h"
 #include "MsgGconfWrapper.h"
 #include "SmsPluginCallback.h"
+#include "SmsPluginDSHandler.h"
+
+extern bool isMemAvailable;
 
-extern struct tapi_handle *pTapiHandle;
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
@@ -44,7 +47,7 @@ void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, v
        try
        {
                // Call Event Handler
-               SmsPluginEventHandler::instance()->setDeviceStatus();
+               SmsPluginEventHandler::instance()->setDeviceStatus(handle);
        }
        catch (MsgException& e)
        {
@@ -54,26 +57,99 @@ void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, v
 
 }
 
+SMS_NETWORK_STATUS_T convertTapiRespToSmsPlugin(int result)
+{
+       SMS_NETWORK_STATUS_T sentStatus;
+
+       /* Convert TAPI status -> SMS network status */
+       switch ((TelSmsResponse_t)result) {
+               case TAPI_NETTEXT_SENDSMS_SUCCESS :
+                       sentStatus = SMS_NETWORK_SEND_SUCCESS;
+                       break;
+
+               case TAPI_NETTEXT_INVALID_MANDATORY_INFO :
+                       sentStatus = SMS_NETWORK_SEND_FAIL_MANDATORY_INFO_MISSING;
+                       break;
+
+               case TAPI_NETTEXT_DESTINAITION_OUTOFSERVICE :
+               case TAPI_NETTEXT_TEMPORARY_FAILURE :
+               case TAPI_NETTEXT_CONGESTION :
+               case TAPI_NETTEXT_RESOURCES_UNAVAILABLE :
+               case TAPI_NETTEXT_MESSAGE_NOT_COMPAT_PROTOCOL :
+                       sentStatus = SMS_NETWORK_SEND_FAIL_TEMPORARY;
+                       break;
+
+               case TAPI_NETTEXT_MESSAGE_TRANSFER_REJECTED :
+                       sentStatus = SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED;
+                       break;
+
+               case TAPI_NETTEXT_DEST_ADDRESS_FDN_RESTRICTED :
+               case TAPI_NETTEXT_SCADDRESS_FDN_RESTRICTED :
+                       sentStatus = SMS_NETWORK_SEND_FAIL_FDN_RESTRICED;
+                       break;
+
+               default :
+                       sentStatus = SMS_NETWORK_SEND_FAIL;
+                       break;
+       }
+       return sentStatus;
+}
 
 void TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_data)
 {
-       MSG_DEBUG("TapiEventSentStatus is called. : result = [%d]", result);
+       MSG_DEBUG("TapiEventSentStatus is called. : result = [0x%x]", result);
+
+       SMS_NETWORK_STATUS_T sentStatus;
+
+       TelSatMoSmCtrlIndData_t *moCtrlStatus = (TelSatMoSmCtrlIndData_t *)user_data;
+
+       sentStatus = convertTapiRespToSmsPlugin(result);
+
+       if (moCtrlStatus && sentStatus == SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED)
+       {
+               if (moCtrlStatus->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD)
+                       sentStatus = SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD;
+       }
+
+       MSG_DEBUG("SMS Network Status = [%d]", sentStatus);
+
+       if (sentStatus == SMS_NETWORK_SEND_FAIL_TEMPORARY ||
+                       sentStatus == SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD ||
+                       sentStatus == SMS_NETWORK_SEND_FAIL_FDN_RESTRICED) {
+               SmsPluginTransport::instance()->setNetStatus(sentStatus);
+               return;
+       }
 
+       if (sentStatus == SMS_NETWORK_SEND_FAIL)
+       {
+               int svc_type;
+               tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
+               if(svc_type < TAPI_NETWORK_SERVICE_TYPE_2G){
+                       sentStatus = SMS_NETWORK_SEND_PENDING;
+               }
+       }
+
+       /* Convert SMS status -> Messaging network status */
        msg_network_status_t netStatus;
 
-       // Convert TAPI status -> Messaging status
-       if ((TelSmsResponse_t)result == TAPI_NETTEXT_SENDSMS_SUCCESS)
+       if (sentStatus == SMS_NETWORK_SEND_SUCCESS) {
                netStatus = MSG_NETWORK_SEND_SUCCESS;
-       else
+       } else if (sentStatus == SMS_NETWORK_SENDING) {
+               netStatus = MSG_NETWORK_SENDING;
+       } else if (sentStatus == SMS_NETWORK_SEND_PENDING) {
+               netStatus = MSG_NETWORK_SEND_PENDING;
+       } else {
                netStatus = MSG_NETWORK_SEND_FAIL;
+       }
+
+       if (netStatus == MSG_NETWORK_SEND_FAIL)
+               MSG_INFO("sentStatus:[%d], tapi_result:[0x%x]", sentStatus, result);
 
        try
        {
-               // Call Event Handler
                SmsPluginEventHandler::instance()->handleSentStatus(netStatus);
 
-               // Call SAT Handler
-               SmsPluginSatHandler::instance()->ctrlSms(netStatus);
+               SmsPluginTransport::instance()->setNetStatus(sentStatus);
        }
        catch (MsgException& e)
        {
@@ -83,16 +159,48 @@ void TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_
 
 }
 
+void TapiEventSatSmsSentStatus(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventSatSmsSentStatus is called. : result = [%d]", result);
+
+       SMS_NETWORK_STATUS_T sentStatus;
+
+       sentStatus = convertTapiRespToSmsPlugin(result);
+
+       MSG_DEBUG("SMS Network Status = [%d]", sentStatus);
+
+       if (sentStatus == SMS_NETWORK_SEND_FAIL && result != TAPI_NETTEXT_DEVICE_FAILURE)
+       {
+               int svc_type;
+               tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
+               if (svc_type < TAPI_NETWORK_SERVICE_TYPE_2G){
+                       sentStatus = SMS_NETWORK_SEND_PENDING;
+               }
+       }
+
+       try
+       {
+               SmsPluginSatHandler::instance()->ctrlSms(handle, sentStatus);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
+}
 
 void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
 {
-       MSG_DEBUG("TapiEventMsgIncoming is called. noti_id [%s]", noti_id);
+       MSG_SEC_DEBUG("TapiEventMsgIncoming is called. noti_id [%s]", noti_id);
 
        if (data == NULL) {
                MSG_DEBUG("Error. evt->pData is NULL.");
                return;
        }
-
+#if 0
+       SmsPluginCbMsgHandler::instance()->handleCbMsg(handle, NULL);
+       return;
+#endif
        TelSmsDatapackageInfo_t* pDataPackage = (TelSmsDatapackageInfo_t*)data;
 
        SMS_TPDU_S tpdu;
@@ -115,7 +223,7 @@ void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, v
                MSG_DEBUG("tpdu.data.deliver.dcs.codingScheme : %d", tpdu.data.deliver.dcs.codingScheme);
                MSG_DEBUG("tpdu.data.deliver.dcs.codingGroup : %d", tpdu.data.deliver.dcs.codingGroup);
                MSG_DEBUG("tpdu.data.deliver.dcs.bIndActive : %d", tpdu.data.deliver.dcs.bIndActive);
-               MSG_DEBUG("tpdu.data.deliver.originAddress.address : %s", tpdu.data.deliver.originAddress.address);
+               MSG_SEC_DEBUG("tpdu.data.deliver.originAddress.address : %s", tpdu.data.deliver.originAddress.address);
                MSG_DEBUG("tpdu.data.deliver.timeStamp.time : %d/%d/%d %d:%d:%d ", tpdu.data.deliver.timeStamp.time.absolute.year, tpdu.data.deliver.timeStamp.time.absolute.month, tpdu.data.deliver.timeStamp.time.absolute.day,
                        tpdu.data.deliver.timeStamp.time.absolute.hour, tpdu.data.deliver.timeStamp.time.absolute.minute, tpdu.data.deliver.timeStamp.time.absolute.second);
                MSG_DEBUG("tpdu.data.deliver.userData.headerCnt : %d", tpdu.data.deliver.userData.headerCnt);
@@ -136,7 +244,7 @@ void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, v
                MSG_DEBUG("tpdu.data.statusRep.dcs.msgClass : %d", tpdu.data.statusRep.dcs.msgClass);
                MSG_DEBUG("tpdu.data.statusRep.dcs.codingScheme : %d", tpdu.data.statusRep.dcs.codingScheme);
                MSG_DEBUG("tpdu.data.statusRep.dcs.codingGroup : %d", tpdu.data.statusRep.dcs.codingGroup);
-               MSG_DEBUG("tpdu.data.statusRep.recipAddress.address : %s", tpdu.data.statusRep.recipAddress.address);
+               MSG_SEC_DEBUG("tpdu.data.statusRep.recipAddress.address : %s", tpdu.data.statusRep.recipAddress.address);
                MSG_DEBUG("tpdu.data.statusRep.timeStamp.time : %d/%d/%d %d:%d:%d ", tpdu.data.statusRep.timeStamp.time.absolute.year, tpdu.data.statusRep.timeStamp.time.absolute.month, tpdu.data.statusRep.timeStamp.time.absolute.day,
                        tpdu.data.statusRep.timeStamp.time.absolute.hour, tpdu.data.statusRep.timeStamp.time.absolute.minute, tpdu.data.statusRep.timeStamp.time.absolute.second);
                MSG_DEBUG("tpdu.data.statusRep.dischargeTime.time : %d/%d/%d %d:%d:%d ", tpdu.data.statusRep.dischargeTime.time.absolute.year, tpdu.data.statusRep.dischargeTime.time.absolute.month, tpdu.data.statusRep.dischargeTime.time.absolute.day,
@@ -159,16 +267,16 @@ void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, v
                        if (SmsPluginConcatHandler::instance()->IsConcatMsg(&(tpdu.data.deliver.userData)) == true ||
                                SmsPluginWapPushHandler::instance()->IsWapPushMsg(&(tpdu.data.deliver.userData)) == true)
                        {
-                               SmsPluginConcatHandler::instance()->handleConcatMsg(&tpdu); // Call Concat Msg Handler
+                               SmsPluginConcatHandler::instance()->handleConcatMsg(handle, &tpdu); // Call Concat Msg Handler
                        }
                        else
                        {
-                               SmsPluginEventHandler::instance()->handleMsgIncoming(&tpdu); // Call Event Handler
+                               SmsPluginEventHandler::instance()->handleMsgIncoming(handle, &tpdu); // Call Event Handler
                        }
                }
                else if (tpdu.tpduType == SMS_TPDU_STATUS_REP)
                {
-                       SmsPluginEventHandler::instance()->handleMsgIncoming(&tpdu); // Call Event Handler
+                       SmsPluginEventHandler::instance()->handleMsgIncoming(handle, &tpdu); // Call Event Handler
                }
        }
        catch (MsgException& e)
@@ -182,7 +290,7 @@ void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, v
 
 void TapiEventCbMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
 {
-       MSG_DEBUG("TapiEventCbMsgIncoming is called. noti_id [%s]", noti_id);
+       MSG_SEC_DEBUG("TapiEventCbMsgIncoming is called. noti_id [%s]", noti_id);
 
        if (data == NULL) {
                MSG_DEBUG("Error. evt->pData is NULL.");
@@ -193,7 +301,7 @@ void TapiEventCbMsgIncoming(TapiHandle *handle, const char *noti_id, void *data,
 
        try
        {
-               SmsPluginCbMsgHandler::instance()->handleCbMsg(pCbMsg);
+               SmsPluginCbMsgHandler::instance()->handleCbMsg(handle, pCbMsg);
        }
        catch (MsgException& e)
        {
@@ -206,7 +314,7 @@ void TapiEventCbMsgIncoming(TapiHandle *handle, const char *noti_id, void *data,
 
 void TapiEventEtwsMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
 {
-       MSG_DEBUG("TapiEventEtwsMsgIncoming is called. noti_id [%s]", noti_id);
+       MSG_SEC_DEBUG("TapiEventEtwsMsgIncoming is called. noti_id [%s]", noti_id);
 
        if (data == NULL) {
                MSG_DEBUG("Error. evt->pData is NULL.");
@@ -217,7 +325,7 @@ void TapiEventEtwsMsgIncoming(TapiHandle *handle, const char *noti_id, void *dat
 
        try
        {
-               SmsPluginCbMsgHandler::instance()->handleEtwsMsg(pEtwsMsg);
+               SmsPluginCbMsgHandler::instance()->handleEtwsMsg(handle, pEtwsMsg);
        }
        catch (MsgException& e)
        {
@@ -244,11 +352,11 @@ void TapiEventGetSimMsgCnt(TapiHandle *handle, int result, void *data, void *use
                MSG_DEBUG("Error. data is NULL.");
                MSG_SIM_COUNT_S simCnt;
                memset(&simCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
-               SmsPluginSimMsg::instance()->setSimMsgCntEvent(&simCnt);
+               SmsPluginSimMsg::instance()->setSimMsgCntEvent(handle, &simCnt);
                return;
        }
 
-       SmsPluginSimMsg::instance()->setSimMsgCntEvent((MSG_SIM_COUNT_S *)data);
+       SmsPluginSimMsg::instance()->setSimMsgCntEvent(handle, (MSG_SIM_COUNT_S *)data);
 
 }
 
@@ -261,12 +369,16 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
        {
                MSG_DEBUG("Error!! pEvent->Status [%d]", result);
 
-               SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+               SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
 
                return;
        }
 
+
        TelSmsData_t* pSmsTpdu = (TelSmsData_t*)data;
+       //SmsPluginSimMsg::instance()->deleteSimMessage((msg_sim_id_t)pSmsTpdu->SimIndex);
+
+       int *simIdList = (int *)user_data;
 
        // Reading TelSmsData_t
        MSG_DEBUG ("sim index %d", pSmsTpdu->SimIndex);
@@ -277,7 +389,7 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
        {
                MSG_DEBUG ("WARNING: tpdu_len > MAX_SMS_TPDU_SIZE [%d] bytes. setting to 0.", pSmsTpdu->SmsData.MsgLength);
 
-               SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+               SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
 
                return;
        }
@@ -301,7 +413,7 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
        {
                if (tpdu.data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && tpdu.data.deliver.pid == 0x11) {
                        MSG_DEBUG("Unsupported message!!");
-                       SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+                       SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
                        return;
                }
 
@@ -310,9 +422,15 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
                {
                        // Handler Concatenated Message
                        if (tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
-                               tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
-                       {
-                               SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+                               tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT) {
+                               SmsPluginConcatHandler::instance()->handleSimConcatMsg(handle, &tpdu, pSmsTpdu->SimIndex, bRead, simIdList);
+                               //SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+                               return;
+                       }
+
+                       if (tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
+                               MSG_DEBUG("Unsupported Special SMS!!");
+                               SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
                                return;
                        }
                }
@@ -321,10 +439,9 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
        {
                if (tpdu.data.submit.dcs.codingScheme == SMS_CHARSET_8BIT && tpdu.data.submit.pid == 0x11) {
                        MSG_DEBUG("Unsupported message!!");
-                       SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+                       SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
                        return;
                }
-
                MSG_DEBUG("headerCnt [%d]", tpdu.data.submit.userData.headerCnt);
 
                for (int i = 0; i < tpdu.data.submit.userData.headerCnt; i++)
@@ -333,7 +450,7 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
                        if (tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
                                tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
                        {
-                               SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
+                               SmsPluginConcatHandler::instance()->handleSimConcatMsg(handle, &tpdu, pSmsTpdu->SimIndex, bRead, simIdList);
                                return;
                        }
                }
@@ -343,23 +460,64 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
        MSG_MESSAGE_INFO_S msgInfo;
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
+       // set storage id
+       msgInfo.storageId = MSG_STORAGE_SIM;
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        SmsPluginEventHandler::instance()->convertTpduToMsginfo(&tpdu, &msgInfo);
 
-       // set Sim Message ID
-       msgInfo.msgId = pSmsTpdu->SimIndex;
+       msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       if (tpdu.tpduType == SMS_TPDU_DELIVER && tpdu.data.deliver.dcs.bMWI == true) {
+               if (tpdu.data.deliver.pid == 0x20 && tpdu.data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
+                       char keyName[MAX_VCONFKEY_NAME_LEN];
+                       char *voiceNumber = NULL;
+                       char *voiceAlphaId = NULL;
+
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
+                       voiceNumber = MsgSettingGetString(keyName);
+
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
+                       voiceAlphaId = MsgSettingGetString(keyName);
+
+                       memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
+                       memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
+
+                       if (voiceNumber) {
+                               snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
+                               free(voiceNumber);
+                               voiceNumber = NULL;
+                       }
+
+                       if (voiceAlphaId) {
+                               snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
+                               free(voiceAlphaId);
+                               voiceAlphaId = NULL;
+                       }
+
+                       memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
+                       snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "Voice message");
+               }
+       }
+       else if (tpdu.tpduType == SMS_TPDU_SUBMIT) {
+               msgInfo.displayTime =  time(NULL);
+       }
 
        // set read status
        msgInfo.bRead = bRead;
 
-       // set storage id
-       msgInfo.storageId = MSG_STORAGE_SIM;
-
+       simIdList[0] = pSmsTpdu->SimIndex + 1;
        /// Print MSG_MESSAGE_INFO_S
        MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
        MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
        MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
        MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
        MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
+       MSG_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
        MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
        MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
        MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
@@ -374,9 +532,11 @@ void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_d
                MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
        else
        MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
+       MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
        MSG_DEBUG("###############################################################");
 
-       SmsPluginSimMsg::instance()->setSimMsgEvent(&msgInfo, true); // Call Event Handler
+       SmsPluginSimMsg::instance()->setSimMsgEvent(handle, &msgInfo, true); // Call Event Handler
+
 
 }
 
@@ -392,13 +552,13 @@ void TapiEventSaveSimMsg(TapiHandle *handle, int result, void *data, void *user_
        else
                MSG_DEBUG("Data(SIM Msg ID) is NULL");
 
-       SmsPluginSimMsg::instance()->setSaveSimMsgEvent(simId, result);
+       SmsPluginSimMsg::instance()->setSaveSimMsgEvent(handle, simId, result);
 }
 
 
 void TapiEventSaveClass2Msg(TapiHandle *handle, int result, void *data, void *user_data)
 {
-       MSG_DEBUG("TapiEventSaveSimMsg is called. result [%d]", result);
+       MSG_DEBUG("TapiEventSaveClass2Msg is called. result [%d]", result);
 
        int simId = -1;
 
@@ -407,7 +567,27 @@ void TapiEventSaveClass2Msg(TapiHandle *handle, int result, void *data, void *us
        else
                MSG_DEBUG("Data(SIM Msg ID) is NULL");
 
-       SmsPluginSimMsg::instance()->setSaveClass2MsgEvent(simId, result);
+       MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)user_data;
+
+       SmsPluginSimMsg::instance()->setSaveClass2MsgEvent(handle, simId, result, pMsgInfo);
+
+       if(result == TAPI_NETTEXT_SENDSMS_SUCCESS)
+       {
+               SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)simId, true);
+       }
+       else
+       {
+               SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)0, false);
+       }
+
+       if (pMsgInfo) {
+               if (pMsgInfo->addressList) {
+                       delete[] pMsgInfo->addressList;
+                       pMsgInfo->addressList = NULL;
+               }
+               free(pMsgInfo);
+               pMsgInfo = NULL;
+       }
 }
 
 
@@ -415,18 +595,16 @@ void TapiEventDeleteSimMsg(TapiHandle *handle, int result, void *data, void *use
 {
        MSG_DEBUG("TapiEventDeleteSimMsg is called. result [%d]", result);
 
-       MSG_DEBUG("status : [%d]", (TelSmsCause_t)result);
-
        if (result != TAPI_API_SUCCESS || data == NULL)
        {
                MSG_DEBUG("Error. data is NULL.");
-               SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)0, false);
+               SmsPluginSimMsg::instance()->setDelSimEvent(-1, false);
                return;
        }
 
        int sim_id = *((int*)data);
 
-       SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)sim_id, true);
+       SmsPluginSimMsg::instance()->setDelSimEvent(sim_id, true);
 
 }
 
@@ -512,7 +690,7 @@ void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_da
        if (result != TAPI_API_SUCCESS || data == NULL)
        {
                MSG_DEBUG("Error. data is NULL.");
-               SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
+               SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
                return;
        }
 
@@ -530,7 +708,7 @@ void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_da
        {
                MSG_DEBUG("Wrong Alpha ID Length[%d]", alphaIdLen);
 
-               SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
+               SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
 
                return;
        }
@@ -542,13 +720,13 @@ void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_da
        if(addrLen > SMSC_ADDR_MAX)
        {
                MSG_DEBUG("addrLen is too long: %d", addrLen);
-               SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
+               SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
                return;
        }
        else if(addrLen < 2)
        {
                MSG_DEBUG("addrLen is too short: %d", addrLen);
-               SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
+               SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
                return;
        }
 
@@ -574,13 +752,13 @@ void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_da
                memset(smscData.smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
                paramCodec.decodeSMSC(smsParam->TpSvcCntrAddr.szDiallingNum, addrLen, smscData.smscAddr.ton, smscData.smscAddr.address);
 
-               MSG_DEBUG("SMSC Address : [%s]", smscData.smscAddr.address);
+               MSG_SEC_DEBUG("SMSC Address : [%s]", smscData.smscAddr.address);
 
                memset(smscData.name, 0x00, SMSC_NAME_MAX+1);
                memcpy(smscData.name, smsParam->szAlphaId, alphaIdLen);
                smscData.name[alphaIdLen] = '\0';
 
-               MSG_DEBUG("SMSC Name : [%s]", smscData.name);
+               MSG_SEC_DEBUG("SMSC Name : [%s]", smscData.name);
        }
        else
        {
@@ -592,7 +770,7 @@ void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_da
 //             memset(smscData.smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
 //             memset(smscData.name, 0x00, SMSC_NAME_MAX+1);
 
-               SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
+               SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
 
                return;
        }
@@ -660,12 +838,26 @@ void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_da
        }
        else
        {
+
                smscData.valPeriod = 0;
+
                MSG_DEBUG("Validity Period is not present");
        }
 
-       SmsPluginSetting::instance()->setParamEvent(&smscData, (int)smsParam->RecordIndex, true);
+       SmsPluginSetting::instance()->setParamEvent(handle, &smscData, (int)smsParam->RecordIndex, true);
+
+}
+
+
+void TapiEventSetSmscInfo(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventSetSmscInfo is called. result=[%d]", result);
 
+       if (result != TAPI_API_SUCCESS) {
+               SmsPluginSetting::instance()->setResultFromSim(false);
+       } else {
+               SmsPluginSetting::instance()->setResultFromSim(true);
+       }
 }
 
 
@@ -679,7 +871,7 @@ void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user
        {
                MSG_DEBUG("Error. data is NULL.");
 
-               SmsPluginSetting::instance()->setCbConfigEvent(NULL, false);
+               SmsPluginSetting::instance()->setCbConfigEvent(handle, NULL, false);
 
                return;
        }
@@ -700,10 +892,6 @@ void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user
                cbOpt.channelData.channelCnt = CB_CHANNEL_MAX;
        }
 
-       if (MsgSettingSetInt(CB_CHANNEL_COUNT, cbOpt.channelData.channelCnt) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", CB_CHANNEL_COUNT);
-       }
-
        MSG_DEBUG("Channel Count [%d]", cbOpt.channelData.channelCnt);
 
        for (int i = 0; i < cbOpt.channelData.channelCnt; i++)
@@ -716,7 +904,7 @@ void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user
                MSG_DEBUG("Channel FROM [%d], Channel TO [%d] ", cbOpt.channelData.channelInfo[i].from, cbOpt.channelData.channelInfo[i].to);
        }
 
-       SmsPluginSetting::instance()->setCbConfigEvent(&cbOpt, true);
+       SmsPluginSetting::instance()->setCbConfigEvent(handle, &cbOpt, true);
 }
 
 void TapiEventSetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data)
@@ -733,13 +921,34 @@ void TapiEventSetMailboxInfo(TapiHandle *handle, int result, void *data, void *u
 
 void TapiEventGetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data)
 {
-       MSG_DEBUG("TapiEventGetMailboxInfo is called.");
-
-       if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL)
-       {
-               MSG_DEBUG("Error. data is NULL.");
-               SmsPluginSetting::instance()->setMailboxInfoEvent(NULL, false);
-
+       MSG_DEBUG("TapiEventGetMailboxInfo is called. result=[%d]", result);
+
+       if (result == TAPI_API_SIM_SERVICE_IS_DISABLED) {
+               MSG_INFO("result is TAPI_API_SIM_SERVICE_IS_DISABLED");
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+               int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
+               char *voiceNum = NULL;
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
+               voiceNum = MsgSettingGetString(keyName);
+
+               if (voiceNum && strlen(voiceNum)) {
+                       MSG_DEBUG("Voice mailbox number exist in vconf");
+                       SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, true, false);
+                       free(voiceNum);
+                       voiceNum = NULL;
+                       return;
+               } else {
+                       SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, false, false);
+                       if (voiceNum) {
+                               free(voiceNum);
+                               voiceNum = NULL;
+                       }
+                       return;
+               }
+       } else if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL) {
+               MSG_ERR("Error. data is NULL.");
+               SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, false, true);
                return;
        }
 
@@ -747,7 +956,8 @@ void TapiEventGetMailboxInfo(TapiHandle *handle, int result, void *data, void *u
        SMS_SIM_MAILBOX_LIST_S mbList = {0,};
 
        if (list->count <= 0) {
-               SmsPluginSetting::instance()->setMailboxInfoEvent(NULL, true);
+               MSG_INFO("Mailbox list is empty");
+               SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, false, true);
                return;
        }
 
@@ -767,7 +977,7 @@ void TapiEventGetMailboxInfo(TapiHandle *handle, int result, void *data, void *u
                mbList.list[i].ext1_id = list->list[i].ext1_id;
        }
 
-       SmsPluginSetting::instance()->setMailboxInfoEvent(&mbList, true);
+       SmsPluginSetting::instance()->setMailboxInfoEvent(handle, &mbList, true, true);
 }
 
 void TapiEventSetMwiInfo(TapiHandle *handle, int result, void *data, void *user_data)
@@ -782,7 +992,7 @@ void TapiEventGetMwiInfo(TapiHandle *handle, int result, void *data, void *user_
        if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL)
        {
                MSG_DEBUG("Error. data is NULL.");
-               SmsPluginSetting::instance()->setMwiInfoEvent(NULL, false);
+               SmsPluginSetting::instance()->setMwiInfoEvent(handle, NULL, false);
 
                return;
        }
@@ -792,16 +1002,18 @@ void TapiEventGetMwiInfo(TapiHandle *handle, int result, void *data, void *user_
 
        memcpy(&simMwiInfo, MwiInfo, sizeof(SMS_SIM_MWI_INFO_S));
 
-       SmsPluginSetting::instance()->setMwiInfoEvent(&simMwiInfo, true);
+       SmsPluginSetting::instance()->setMwiInfoEvent(handle, &simMwiInfo, true);
 }
 
 void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *user_data)
 {
        MSG_DEBUG("TapiEventGetMsisdnInfo is called.");
 
-       if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL)
-       {
+       bool bRet = false;
+
+       if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL) {
                MSG_DEBUG("Error. data is NULL.");
+               SmsPluginSetting::instance()->setResultFromSim(bRet);
                return;
        }
 
@@ -809,14 +1021,85 @@ void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *us
 
        for (int i = 0; i < list->count; i++) {
                if (list->list[i].num[0] != '\0') {
-                       if (MsgSettingSetString(MSG_SIM_MSISDN, list->list[i].num) == MSG_SUCCESS)
-                               MSG_DEBUG("Get MSISDN from SIM : [%s]", list->list[i].num);
-                       else
-                               MSG_DEBUG("Getting MSISDN is failed!");
+                       char keyName[MAX_VCONFKEY_NAME_LEN];
+                       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
 
+                       if (MsgSettingSetString(keyName, list->list[i].num) == MSG_SUCCESS) {
+                               MSG_SEC_DEBUG("Get MSISDN from SIM : [%s]", list->list[i].num);
+                               bRet = true;
+                       } else {
+                               MSG_DEBUG("Getting MSISDN is failed!");
+                       }
                        break;
                }
        }
+
+       SmsPluginSetting::instance()->setResultFromSim(bRet);
+}
+
+void TapiEventGetSimServiceTable(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventGetSimServiceTable is called.");
+
+    TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
+    TelSimServiceTable_t *svct = (TelSimServiceTable_t *)data;
+
+       bool bRet = true;
+
+       if (access_rt != TAPI_SIM_ACCESS_SUCCESS || svct == NULL)
+       {
+               MSG_DEBUG("Error. data is NULL.");
+               SmsPluginSetting::instance()->setResultFromSim(false);
+               return;
+       }
+
+       msg_error_t err = MSG_SUCCESS;
+
+       char sstKey[128];
+       char moCtrlKey[128];
+
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       memset(sstKey, 0x00, sizeof(sstKey));
+       snprintf(sstKey, sizeof(sstKey), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
+
+       memset(moCtrlKey, 0x00, sizeof(moCtrlKey));
+       snprintf(moCtrlKey, sizeof(moCtrlKey), "%s/%d", MSG_SIM_MO_CONTROL, simIndex);
+
+       if (svct->sim_type == TAPI_SIM_CARD_TYPE_GSM) {
+               if (svct->table.sst.service[TAPI_SIM_SST_SMS] == 1) {
+                       err = MsgSettingSetBool(sstKey, true);
+               } else {
+                       err = MsgSettingSetBool(sstKey, false);
+               }
+
+               if (svct->table.sst.service[TAPI_SIM_SST_MO_SMS_CTRL_BY_SIM] == 1){
+                       err = MsgSettingSetBool(moCtrlKey, true);
+               } else {
+                       err = MsgSettingSetBool(moCtrlKey, false);
+               }
+       } else if (svct->sim_type == TAPI_SIM_CARD_TYPE_USIM) {
+               if (svct->table.sst.service[TAPI_SIM_UST_SMS] == 1) {
+                       err = MsgSettingSetBool(sstKey, true);
+               } else {
+                       err = MsgSettingSetBool(sstKey, false);
+               }
+
+               if (svct->table.sst.service[TAPI_SIM_UST_MO_SMS_CTRL] == 1){
+                       err = MsgSettingSetBool(moCtrlKey, true);
+               } else {
+                       err = MsgSettingSetBool(moCtrlKey, false);
+               }
+       } else {
+               MSG_DEBUG("Unknown SIM type value");
+       }
+
+       MSG_DEBUG("Setting result = [%d]", err);
+
+       SmsPluginSetting::instance()->setResultFromSim(bRet);
 }
 
 void TapiEventSatSmsRefresh(TapiHandle *handle, int result, void *data, void *user_data)
@@ -831,7 +1114,7 @@ void TapiEventSatSmsRefresh(TapiHandle *handle, int result, void *data, void *us
 
        try
        {
-               SmsPluginSatHandler::instance()->refreshSms(data);
+               SmsPluginSatHandler::instance()->refreshSms(handle, data);
        }
        catch (MsgException& e)
        {
@@ -854,7 +1137,7 @@ void TapiEventSatSendSms(TapiHandle *handle, const char *noti_id, void *data, vo
 
        try
        {
-               SmsPluginSatHandler::instance()->sendSms(data);
+               SmsPluginSatHandler::instance()->sendSms(handle, data);
        }
        catch (MsgException& e)
        {
@@ -865,11 +1148,11 @@ void TapiEventSatSendSms(TapiHandle *handle, const char *noti_id, void *data, vo
 }
 
 
-void TapiEventSatMoSmsCtrl(TapiHandle *handle, int result, void *data, void *user_data)
+void TapiEventSatMoSmsCtrl(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
 {
        MSG_DEBUG("TapiEventSatMoSmsCtrl is called.");
 
-       if (result != TAPI_API_SUCCESS || data == NULL)
+       if (data == NULL)
        {
                MSG_DEBUG("Error. data is NULL.");
                return;
@@ -877,7 +1160,7 @@ void TapiEventSatMoSmsCtrl(TapiHandle *handle, int result, void *data, void *use
 
        try
        {
-               SmsPluginSatHandler::instance()->ctrlSms(data);
+               SmsPluginSatHandler::instance()->ctrlSms(handle, data);
        }
        catch (MsgException& e)
        {
@@ -890,6 +1173,10 @@ void TapiEventSatMoSmsCtrl(TapiHandle *handle, int result, void *data, void *use
 void TapiEventMemoryStatus(TapiHandle *handle, int result, void *data, void *user_data)
 {
        MSG_DEBUG("Tapi result is [%d]", result);
+       if(result == TAPI_API_SUCCESS)
+       {
+               isMemAvailable = true;
+       }
 }
 
 void TapiEventSetMsgStatus(TapiHandle *handle, int result, void *data, void *user_data)
@@ -908,6 +1195,69 @@ void TapiEventSetMsgStatus(TapiHandle *handle, int result, void *data, void *use
        SmsPluginSimMsg::instance()->setSimEvent(sim_id, true);
 }
 
+
+void TapiEventGetMeImei(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_SEC_DEBUG("TapiEventGetMeImei is called. result [%d]", result);
+
+       if (result != TAPI_API_SUCCESS || data == NULL)
+       {
+               MSG_DEBUG("Error. data is NULL.");
+               SmsPluginSetting::instance()->setResultImei(false, NULL);
+               return;
+       }
+
+       char *tmpImei = (char *)data;
+
+       SmsPluginSetting::instance()->setResultImei(true, tmpImei);
+}
+
+
+void TapiEventSimStatusChange(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventSimStatusChange is called.");
+
+       if (data == NULL) {
+               MSG_DEBUG("Error. data is NULL.");
+               return;
+       }
+
+        int status = *(int *)data;
+
+        MSG_DEBUG("SIM Status [%d]", status);
+
+        if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
+                MSG_INFO("SIM Initialize by sim status change callback");
+                SmsPluginSetting::instance()->setSimChangeStatus(handle, false);
+        }
+}
+
+void TapiEventNetworkStatusChange(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventNetworkStatusChange is called.");
+
+       if (data == NULL) {
+               MSG_DEBUG("Error. data is NULL.");
+               return;
+       }
+
+       TelNetworkServiceType_t *type = (TelNetworkServiceType_t *)data;
+
+       MSG_INFO("network status type [%d], simIndex [%d]", *type, (int)user_data);
+
+       if(*type > TAPI_NETWORK_SERVICE_TYPE_SEARCH)
+       {
+               SmsPluginEventHandler::instance()->handleResendMessage(); // Call Event Handler
+       }
+}
+
+void TapiEventSimRefreshed(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventSimRefreshed is called.");
+
+       SmsPluginSetting::instance()->SimRefreshCb(handle);
+}
+
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginCallback - Member Functions
 ==================================================================================================*/
@@ -923,8 +1273,7 @@ SmsPluginCallback::SmsPluginCallback()
 
 SmsPluginCallback::~SmsPluginCallback()
 {
-       if (pInstance != NULL)
-       {
+       if (pInstance != NULL) {
                delete pInstance;
                pInstance = NULL;
        }
@@ -942,13 +1291,38 @@ SmsPluginCallback* SmsPluginCallback::instance()
 
 void SmsPluginCallback::registerEvent()
 {
-       tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_DEVICE_READY, TapiEventDeviceReady, NULL);
-       tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_INCOM_MSG, TapiEventMsgIncoming, NULL);
-       tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_CB_INCOM_MSG, TapiEventCbMsgIncoming, NULL);
-       tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_ETWS_INCOM_MSG, TapiEventEtwsMsgIncoming, NULL);
-//     tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_REFRESH, TapiEventSatSmsRefresh, NULL);
-       tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_SEND_SMS, TapiEventSatSendSms, NULL);
-//     tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_MO_SMS_CTRL, TapiEventSatMoSmsCtrl, NULL);
+       struct tapi_handle *pTapiHandle;
+
+       int count = SmsPluginDSHandler::instance()->getTelHandleCount();
+
+       for(int i =1; i <= count; ++i)
+       {
+               pTapiHandle = SmsPluginDSHandler::instance()->getTelHandle(i);
+               int simIndex = SmsPluginDSHandler::instance()->getSimIndex(pTapiHandle);
+
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_DEVICE_READY, TapiEventDeviceReady, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_DEVICE_READY);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_INCOM_MSG, TapiEventMsgIncoming, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_INCOM_MSG);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_CB_INCOM_MSG, TapiEventCbMsgIncoming, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_CB_INCOM_MSG);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_ETWS_INCOM_MSG, TapiEventEtwsMsgIncoming, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_ETWS_INCOM_MSG);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_SEND_SMS, TapiEventSatSendSms, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_SEND_SMS);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_MO_SM_CONTROL_RESULT, TapiEventSatMoSmsCtrl, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_MO_SM_CONTROL_RESULT);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SIM_STATUS, TapiEventSimStatusChange, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SIM_STATUS);
+               if (tel_register_noti_event(pTapiHandle, TAPI_PROP_NETWORK_SERVICE_TYPE, TapiEventNetworkStatusChange, (void*)simIndex) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_PROP_NETWORK_SERVICE_TYPE);
+               if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SIM_REFRESHED, TapiEventSimRefreshed, NULL) != TAPI_API_SUCCESS)
+                       MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SIM_REFRESHED);
+//             if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_REFRESH, TapiEventSatSmsRefresh, NULL) != TAPI_API_SUCCESS)
+//                     MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_REFRESH);
+//             if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_MO_SMS_CTRL, TapiEventSatMoSmsCtrl, NULL) != TAPI_API_SUCCESS)
+//                     MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_MO_SMS_CTRL);
+       }
 }
 
 
index 235a3f2..1619e7a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <time.h>
 #include "MsgException.h"
 #include "MsgGconfWrapper.h"
 #include "MsgUtilFile.h"
+#include "MsgUtilStorage.h"
 #include "SmsPluginUDCodec.h"
 #include "SmsPluginStorage.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginCbMsgHandler.h"
-
+#include "SmsPluginDSHandler.h"
 
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
@@ -54,12 +55,33 @@ SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::instance()
 }
 
 
-void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
+void SmsPluginCbMsgHandler::handleCbMsg(TapiHandle *handle, TelSmsCbMsg_t *pCbMsg)
 {
        MSG_BEGIN();
 
-       SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
+#if 0
+       char temp[1000]= {0x01, 0xa4, 0x1f, 0x51, 0x10, 0x11, 0x02, 0xea, 0x30, 0x30, 0xa8, 0x30, 0xea, 0x30, 0xa2, 0x30, 0xe1, 0x30, 0xfc, 0x30, 0xeb, 0x91, 0x4d, 0x4f, 0xe1, 0x30, 0xc6, 0x30, 0xb9, 0x30, 0xc8, 0x00, 0x0d, 0x00, 0x0a, 0x30, 0x53, 0x30, 0x8c, 0x30, 0x6f, 0x8a, 0x66, 0x9a, 0x13, 0x75, 0x28, 0x30, 0x6e, 0x30, 0xe1, 0x30, 0xc3, 0x30, 0xbb, 0x30, 0xfc, 0x30, 0xb8, 0x30, 0x67, 0x30, 0x59, 0x30, 0x02, 0x00, 0x0d, 0x00, 0x0a, 0xff, 0x08, 0x00, 0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33, 0x00, 0x2f, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2f, 0x00, 0x32, 0x52, 0xea, 0x30, 0x00, 0x37, 0x00, 0x20, 0x00, 0x31, 0x00, 0x35, 0x00, 0x3a, 0x00, 0x34, 0x00, 0x34, 0xff, 0x09, 0x00, 0x0d, 0x00, 0x0a, 0xff, 0x08, 0x30, 0xa8, 0x30, 0xea, 0x30, 0xa2, 0x5e, 0x02, 0xff, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22};
+       TelSmsEtwsMsg_t *pCbMsg = (TelSmsEtwsMsg_t *)calloc(1, sizeof(TelSmsEtwsMsg_t));
+       pCbMsg->Length = 173;
+       pCbMsg->EtwsMsgType = (TelSmsEtwsMsgType_t)2;
+       memcpy(pCbMsg->szMsgData, temp, pCbMsg->Length);
 
+       SMS_CB_NETWORK_TYPE_T type = pCbMsg->EtwsMsgType;
+       SMS_CBMSG_PAGE_S CbMsgPage = {0};
+
+       switch (type)
+       {
+               case SMS_CB_NETWORK_TYPE_2G_GSM :
+                       Decode2gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
+               break;
+
+               case SMS_CB_NETWORK_TYPE_3G_UMTS :
+                       Decode3gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
+               break;
+
+       }
+#else
+       SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
        SMS_CBMSG_PAGE_S CbMsgPage = {0};
 
        switch (type)
@@ -71,12 +93,15 @@ void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
                case SMS_CB_NETWORK_TYPE_3G_UMTS :
                        Decode3gCbMsg(pCbMsg, &CbMsgPage);
                break;
-       }
 
+       }
+#endif
        // Check CB Msg Options
        bool bJavaMsg = false;
 
-       if (!checkCbOpt(CbMsgPage, &bJavaMsg))
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       if (!checkCbOpt(CbMsgPage, &bJavaMsg, simIndex))
        {
                MSG_DEBUG("The CB Msg is not supported by option.");
                return;
@@ -88,6 +113,7 @@ void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
                CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
        }
 
+
        // Check CB Pages
        unsigned char pageCnt = checkCbPage(CbMsgPage);
 
@@ -95,19 +121,25 @@ void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
        {
                MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
 
-               SMS_CBMSG_S cbMsg = {};
-               MSG_MESSAGE_INFO_S msgInfo = {};
+               SMS_CBMSG_S cbMsg = {0,};
+               MSG_MESSAGE_INFO_S msgInfo;
+
+               /** initialize msgInfo */
+               memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+               msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
                // Make CB Msg Structure
                MakeCbMsg(CbMsgPage, &cbMsg);
 
                // Convert to MSG_MESSAGE_INFO_S
-               convertCbMsgToMsginfo(&cbMsg, &msgInfo);
+               convertCbMsgToMsginfo(&cbMsg, &msgInfo, simIndex);
 
                // Add CB Msg into DB
                msg_error_t err = MSG_SUCCESS;
 
-               err = SmsPluginStorage::instance()->addMessage(&msgInfo);
+               err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
 
                if (err == MSG_SUCCESS)
                {
@@ -123,7 +155,7 @@ void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
                        cbOutMsg.cbTextLen= convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), &cbMsg);
                        memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
                        memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
-                       err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg);
+                       err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo);
                        if (err != MSG_SUCCESS)
                        {
                                MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
@@ -131,32 +163,44 @@ void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
                }
                else
                {
-                       MSG_DEBUG("addMessage() Error !! [%d]", err);
+                       MSG_DEBUG("checkMessage() Error !! [%d]", err);
                }
 
+#if 0
+               // insert message-id to internal CB message table
+               SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
+               err = storageHandler->insertReceivedCBMessage(CbMsgPage);
+               if (err != MSG_SUCCESS)
+               {
+                       MSG_DEBUG("insertReceivedCBMessage() Error !! [%d]", err);
+               }
+#endif
                // Remove From List
                removeFromPageList(CbMsgPage);
+
+
        }
        MSG_END();
 }
 
 
-void SmsPluginCbMsgHandler::handleEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg)
+void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
 {
        MSG_BEGIN();
        msg_error_t err = MSG_SUCCESS;
-       SMS_ETWS_NETWORK_TYPE_T type = pEtwsMsg->EtwsMsgType;
+       TelSmsEtwsMsgType_t type = pEtwsMsg->EtwsMsgType;
        //MSG_MESSAGE_INFO_S msgInfo = {};
        SMS_ETWS_PRIMARY_S              etwsPn = {0, };
        MSG_CB_MSG_S                    cbOutMsg = {0, };
 
        if(type != TAPI_NETTEXT_ETWS_PRIMARY)
        {
-               MSG_DEBUG("The Etws Msg is not supported");
+               MSG_DEBUG("The Etws secondary Message");
+               handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
                return;
        }
        DecodeEtwsMsg(pEtwsMsg, &etwsPn);
-       //convertEtwsMsgToMsginfo(CbMsgPage, &msgInfo);
+       //convertEtwsMsgToMsginfo(CbMsgPage, &msgInfo, simIndex);
 
        cbOutMsg.type = MSG_ETWS_SMS;
        cbOutMsg.receivedTime = etwsPn.recvTime;
@@ -165,7 +209,7 @@ void SmsPluginCbMsgHandler::handleEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg)
        cbOutMsg.etwsWarningType = etwsPn.warningType;
        memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
 
-       err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg);
+       err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
        if (err != MSG_SUCCESS)
        {
                MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
@@ -177,15 +221,16 @@ void SmsPluginCbMsgHandler::handleEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg)
 
 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
 {
-       if (pCbMsg->Length > MAX_CBMSG_PAGE_SIZE)
-               THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbMsg->Length);
-
        unsigned char cbData[pCbMsg->Length+1];
 
+       MSG_DEBUG("CB msg length = [%d]", pCbMsg->Length);
        memset(cbData, 0x00, sizeof(cbData));
        memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
        cbData[pCbMsg->Length] = '\0';
 
+       for(int i=0; i <pCbMsg->Length; ++i)
+               MSG_DEBUG("Decode2gCbMsg [%2x]", cbData[i]);
+
        pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
 
        // Serial Number
@@ -196,14 +241,14 @@ void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_
 
        pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
 
-MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
+       MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
 
        pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
 
-MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
+       MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
 
        // DCS
-       decodeCbMsgDCS(cbData[4], (unsigned char*)cbData[6], &(pCbPage->pageHeader.dcs));
+       decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
 
        // Page Parameter
        pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
@@ -212,13 +257,13 @@ MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
        if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
                THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
 
-MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
+       MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
 
        // Convert Language Type
        convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
 
-MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
-MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
+       MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
+       MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
        // Get Receive Time
        pCbPage->pageHeader.recvTime = getRecvTime();
 
@@ -240,7 +285,10 @@ MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
                        if(pCbPage->pageHeader.dcs.iso639Lang[0])
                        {
                                unpackLen = unpackLen - 3;
-                               memcpy(pCbPage->pageData, &pageData[3], unpackLen);
+                               if (unpackLen > 0)
+                                       memcpy(pCbPage->pageData, &pageData[3], unpackLen);
+                               else
+                                       unpackLen = 0;
                        } else {
                                memcpy(pCbPage->pageData, &pageData, unpackLen);
                        }
@@ -269,7 +317,7 @@ MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
                break;
        }
 
-MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
+       MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
 }
 
 
@@ -316,20 +364,22 @@ void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PR
 
 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
 {
-       if (pCbMsg->Length > (MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM))
-               THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbMsg->Length);
-
-       char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
+       unsigned char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
 
+       MSG_DEBUG("CB msg length = [%d]", pCbMsg->Length);
        memset(cbData, 0x00, sizeof(cbData));
-       memcpy(cbData, pCbMsg->szMsgData, sizeof(pCbMsg->szMsgData));
+       //memcpy(cbData, pCbMsg->szMsgData, sizeof(pCbMsg->szMsgData));
+       memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
        cbData[pCbMsg->Length] = '\0';
 
+       for(int i=0; i <pCbMsg->Length; ++i)
+               MSG_DEBUG("Decode3gCbMsg [%2x]", cbData[i]);
+
        pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
 
        pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
 
-MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
+       MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
 
        // Serial Number
        pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
@@ -339,53 +389,99 @@ MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
 
        pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
 
-MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
+       MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
 
        // DCS
-       decodeCbMsgDCS(cbData[5], (unsigned char*)cbData[6], &(pCbPage->pageHeader.dcs));
+       decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
 
        // Convert Language Type
        convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
 
-MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
+       MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
 
        // Get Receive Time
        pCbPage->pageHeader.recvTime = getRecvTime();
+       pCbPage->pageHeader.totalPages = cbData[6];
+
+
 
-#if 0
        // Decode CB Data
-       int dataLen = pCbMsg->Length - 6;
+       int dataLen = 0;
+       int offset = 0;
 
        switch (pCbPage->pageHeader.dcs.codingScheme)
        {
                case SMS_CHARSET_7BIT :
                {
-                       dataLen = (dataLen*8) / 7;
+                       for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
+                       {
+                               char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
+                               dataLen = cbData[7+(i+1)*82 + i];
+                               memcpy(cbMessage, &cbData[7+(i*82)+ i], dataLen);
 
-                       if (pCbPage->pageLength > MAX_CBMSG_PAGE_SIZE)
-                               THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbPage->pageLength);
+                               dataLen = (dataLen*8) / 7;
 
-                       SmsPluginUDCodec udCodec;
-                       int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pCbPage->pageData);
-                       pCbPage->pageData[unpackLen] = '\0';
+                               if (dataLen > MAX_CBMSG_PAGE_SIZE)
+                                       THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
 
-                       pCbPage->pageLength = unpackLen;
+                               SmsPluginUDCodec udCodec;
+                               int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
+                               offset += unpackLen;
+                       }
+                       pCbPage->pageLength = offset;
                }
                break;
 
                case SMS_CHARSET_8BIT :
                case SMS_CHARSET_UCS2 :
                {
-                       pCbPage->pageLength = dataLen;
+#if 0
+                       char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
 
-                       memcpy(pCbPage->pageData, &cbData[6], pCbPage->pageLength);
-                       pCbPage->pageData[pCbPage->pageLength] = '\0';
+                       for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
+                       {
+                               dataLen = cbData[7+(i+1)*82 + i];
+                               memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
+                               offset += dataLen;
+                       }
+                       dataLen = offset;
+
+                       if(pCbPage->pageHeader.dcs.iso639Lang[0])
+                       {
+                               int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
+                               memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
+                               pCbPage->pageLength = tmpDataLen;
+                       } else {
+                               memcpy(pCbPage->pageData, cbMessage, dataLen);
+                               pCbPage->pageLength = dataLen;
+                       }
+#else
+                       char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
+
+                       for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
+                       {
+                               if(pCbPage->pageHeader.dcs.iso639Lang[0])
+                               {
+                                       dataLen = cbData[7+(i+1)*82 + i] - 2;
+                                       memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
+                                       offset += dataLen;
+                               } else {
+                                       dataLen = cbData[7+(i+1)*82 + i];
+                                       memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
+                                       offset += dataLen;
+                               }
+                       }
+                       dataLen = offset;
+                       memcpy(pCbPage->pageData, cbMessage, dataLen);
+                       pCbPage->pageLength = dataLen;
+#endif
                }
                break;
        }
+       pCbPage->pageHeader.totalPages = 1;
+
+       MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
 
-MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
-#endif
 }
 
 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields )
@@ -398,7 +494,58 @@ unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S
        return serialNum;
 }
 
-bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
+int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
+{
+       int ret = 0;
+
+       switch (message_id)
+       {
+               case 4370 :
+               case 4383 :
+                       ret = MSG_CMAS_PRESIDENTIAL;
+                       break;
+               case 4371 :
+               case 4372 :
+               case 4384 :
+               case 4385 :
+                       ret = MSG_CMAS_EXTREME;
+                       break;
+               case 4373 :
+               case 4374 :
+               case 4375 :
+               case 4376 :
+               case 4377 :
+               case 4378 :
+               case 4386 :
+               case 4387 :
+               case 4388 :
+               case 4389 :
+               case 4390 :
+               case 4391 :
+                       ret = MSG_CMAS_SEVERE;
+                       break;
+               case 4379 :
+               case 4392 :
+                       ret = MSG_CMAS_AMBER;
+                       break;
+               case 4380 :
+               case 4381 :
+               case 4393 :
+               case 4394 :
+                       ret = MSG_CMAS_TEST;
+                       break;
+               case 4382 :
+               case 4395 :
+                       ret = MSG_CMAS_OPERATOR_DEFINED;
+                       break;
+               default :
+                       break;
+       }
+
+       return ret;
+}
+
+bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
 {
        bool bReceive = false;
        MsgSettingGetBool(CB_RECEIVE, &bReceive);
@@ -410,11 +557,11 @@ bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
                return false;
        }
 
-       char keyName[128];
-
+#if 0
+       char keyname[128];
        // check Language
        memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
+       snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
 
        bool bAllLang = false;
        MsgSettingGetBool(keyName, &bAllLang);
@@ -424,7 +571,7 @@ bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
                MSG_DEBUG("ALL LANGUAGE = FALSE");
 
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
+               snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
 
                bool bLang = false;
 
@@ -436,28 +583,23 @@ bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
                        return false;
                }
        }
-
-       int MsgIdCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
+#endif
 
        bool bActivate = false;
        int MsgId_from = 0, MsgId_to = 0;
+       MSG_CB_CHANNEL_S cbChannelInfo = {0,};
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       for (int i = 0; i < MsgIdCnt; i++)
-       {
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
-
-               MsgSettingGetBool(keyName, &bActivate);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
-
-               MsgId_from = MsgSettingGetInt(keyName);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
+       err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
+       if (err != MSG_SUCCESS)
+               MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
 
-               MsgId_to = MsgSettingGetInt(keyName);
+       for (int i = 0; i < cbChannelInfo.channelCnt; i++)
+       {
+               bActivate = cbChannelInfo.channelInfo[i].bActivate;
+               MsgId_from = cbChannelInfo.channelInfo[i].from;
+               MsgId_to = cbChannelInfo.channelInfo[i].to;
 
                if (bActivate == true && CbPage.pageHeader.msgId >= MsgId_from && CbPage.pageHeader.msgId <= MsgId_to)
                {
@@ -469,14 +611,26 @@ bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
        return false;
 }
 
-
 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S CbPage)
 {
        unsigned char currPageCnt = 0;
 
        bool bFind = false;
 
-       if (CbPage.pageHeader.totalPages > 1)
+#if 0
+       msg_error_t err = MSG_SUCCESS;
+
+       SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
+       err = storageHandler->isReceivedCBMessage(CbPage);
+       // check existing message with cb internal table;
+       if(err != MSG_ERR_DB_NORECORD)
+       {
+               MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
+               return 0;
+       }
+#endif
+
+       if (CbPage.pageHeader.totalPages > 0)
        {
                for (unsigned int i = 0; i < pageList.size(); i++)
                {
@@ -500,11 +654,11 @@ unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S CbPage)
                                                        return 0;
                                                }
 
-                                               pair<unsigned char, string> newData(CbPage.pageHeader.page, CbPage.pageData);
+                                               pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage.pageHeader.page, CbPage);
                                                pageList[i].data.insert(newData);
 
                                                MSG_DEBUG("PAGE DATA : %s", CbPage.pageData);
-                                               MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.c_str());
+                                               MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
 
                                                pageList[i].pageCnt++;
                                                pageList[i].totalSize += CbPage.pageLength;
@@ -526,7 +680,7 @@ unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S CbPage)
 
        if (bFind == false || CbPage.pageHeader.totalPages == 1)
        {
-               addToPageLiat(CbPage);
+               addToPageList(CbPage);
                return 1;
        }
 
@@ -543,7 +697,7 @@ void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S CbPage, SMS_CBMSG_S *pCbM
        pCbMsg->recvTime = CbPage.pageHeader.recvTime;
 
        cbPageMap::iterator it;
-       string tmpStr ("");
+       int offset = 0;
 
        for (unsigned int i = 0; i < pageList.size(); i++)
        {
@@ -553,24 +707,29 @@ void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S CbPage, SMS_CBMSG_S *pCbM
 
                        if (pageList[i].msgId == CbPage.pageHeader.msgId)
                        {
+
                                for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++)
                                {
-                                       tmpStr += it->second;
+                                       memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
+                                       pCbMsg->msgLength += it->second.pageLength;
+                                       offset = pCbMsg->msgLength;
                                }
                        }
                }
        }
 
+#if 0
        pCbMsg->msgLength = tmpStr.size();
 
        memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
        pCbMsg->msgData[tmpStr.size()] = '\0';
 
        MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
+#endif
 }
 
 
-void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
+void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
 {
        pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
 
@@ -579,10 +738,17 @@ void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSA
        // Convert Type values
        pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
 
-       if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS)
-               pMsgInfo->msgType.subType = MSG_CB_SMS;
-       else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS)
+       if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
+               int cmas_class = CMAS_class(pCbMsg->msgId);
+
+               if (cmas_class == 0)
+                       pMsgInfo->msgType.subType = MSG_CB_SMS;
+               else
+                       pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
+       }
+       else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
                pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
+       }
 
        switch(pCbMsg->classType)
        {
@@ -613,12 +779,18 @@ void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSA
        // Temporary
        pMsgInfo->nAddressCnt = 1;
 
+       pMsgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
        pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
        pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
+       pMsgInfo->sim_idx = simIndex;
 
-       getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal);
+       //      TODO :: MSG ID should be used to get CB message type
+       getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
        MSG_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
 
+
        pMsgInfo->msgPort.valid = false;
        pMsgInfo->msgPort.dstPort = 0;
        pMsgInfo->msgPort.srcPort = 0;
@@ -631,6 +803,18 @@ void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSA
        char tmpBuf[bufSize];
        memset(tmpBuf, 0x00, sizeof(tmpBuf));
 
+       while (pCbMsg->msgLength > 0) {
+               if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
+                               pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
+                               pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
+                       pCbMsg->msgLength--;
+               }
+               else {
+                       break;
+               }
+       }
+       pCbMsg->msgData[pCbMsg->msgLength] = '\0';
+
        MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
 
        // Convert Data values
@@ -647,7 +831,7 @@ void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSA
                if (MsgCreateFileName(fileName) == false)
                        THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
 
-               MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
+               MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
                if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
                        THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
 
@@ -659,11 +843,13 @@ void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSA
 
                memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
                memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
+               pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
+               MSG_DEBUG("CB MSG %s", pMsgInfo->msgText);
        }
 }
 
 
-void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
+void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
 {
        pMsgInfo->msgId = (msg_message_id_t)EtwsMsg.pageHeader.msgId;
 
@@ -688,7 +874,7 @@ void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MS
        pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
        pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
 
-       getDisplayName(EtwsMsg.pageHeader.msgId, pMsgInfo->addressList[0].addressVal);
+       getDisplayName(EtwsMsg.pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
        MSG_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
 
        pMsgInfo->msgPort.valid = false;
@@ -709,6 +895,8 @@ int SmsPluginCbMsgHandler::convertTextToUtf8 (unsigned char* outBuf, int outBufS
        int     convertedTextSize = 0;
        MSG_LANG_INFO_S langInfo = {0,};
 
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
+
        if (!outBuf || !pCbMsg)
        {
                MSG_DEBUG ("invalid param.\n");
@@ -721,14 +909,14 @@ int SmsPluginCbMsgHandler::convertTextToUtf8 (unsigned char* outBuf, int outBufS
 
        // Convert Data values
        if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
-               convertedTextSize = textCvt.convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
+               convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
        else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
-               convertedTextSize = textCvt.convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
+               convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
 
        return convertedTextSize;
 }
 
-void SmsPluginCbMsgHandler::addToPageLiat(SMS_CBMSG_PAGE_S CbPage)
+void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S CbPage)
 {
        CB_PAGE_INFO_S tmpInfo;
 
@@ -741,11 +929,11 @@ void SmsPluginCbMsgHandler::addToPageLiat(SMS_CBMSG_PAGE_S CbPage)
        tmpInfo.pageCnt = 1;
        tmpInfo.totalSize = CbPage.pageLength;
 
-       pair<unsigned char, string> newData(CbPage.pageHeader.page, CbPage.pageData);
+       pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage.pageHeader.page, CbPage);
        tmpInfo.data.insert(newData);
 
        MSG_DEBUG("MSG DATA : %s", CbPage.pageData);
-       MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.c_str());
+       MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
 
        pageList.push_back(tmpInfo);
 }
@@ -802,13 +990,13 @@ void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned
                                pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
                                pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
                                pDcs->langType = SMS_CBMSG_LANG_ISO639;
-
-                               if (pMsgData != NULL)
+                               MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
+                               if (pMsgData[0] && pMsgData[1])
                                {
                                        pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
-                                       pDcs->iso639Lang[1] = (pMsgData[0] & 0x80) >> 7;
-                                       pDcs->iso639Lang[1] |= (pMsgData[1] & 0x3F) << 1;
-                                       pDcs->iso639Lang[2]  = 0x13; /* CR char in GSM 7-bit Alphabet */
+                                       pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
+                                       pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
+                                       pDcs->iso639Lang[2] = 0x13;  /* CR */
                                }
                                else
                                {
@@ -833,29 +1021,49 @@ void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned
                        if (dcsData & 0x10)
                                pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
 
-                       pDcs->codingScheme = (SMS_CODING_SCHEME_T)(dcsData & 0x0C);
+                       unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
+
+                       switch (tmpScheme) {
+                               case 0x00:
+                                       pDcs->codingScheme = SMS_CHARSET_7BIT;
+                                       break;
+                               case 0x01:
+                                       pDcs->codingScheme = SMS_CHARSET_8BIT;
+                                       break;
+                               case 0x02:
+                                       pDcs->codingScheme = SMS_CHARSET_UCS2;
+                                       break;
+                               default:
+                                       MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
+                                       break;
+                       }
                }
                break;
 
                case 0x09 :
                {
                        pDcs->bUDH = true;
+                       pDcs->classType = (MSG_CLASS_TYPE_T)((dcsData & 0x0C) >> 2);
+                       pDcs->codingScheme = (SMS_CODING_SCHEME_T)(dcsData & 0x03);
                }
                break;
 
-               case 0x14 :
+               case 0x0E :
                {
                        pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
                }
                break;
 
-               case 0x15 :
+               case 0x0F :
                {
                        pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
                        pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
                        pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
                }
                break;
+               default:
+                       MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
+               break;
        }
 }
 
@@ -917,45 +1125,38 @@ unsigned long SmsPluginCbMsgHandler::getRecvTime()
 }
 
 
-void SmsPluginCbMsgHandler::getDisplayName(unsigned short      MsgId, char *pDisplayName)
+void SmsPluginCbMsgHandler::getDisplayName(unsigned short      MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
 {
-       int MsgIdCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
+       MSG_CB_CHANNEL_S cbChannelInfo = {0,};
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       char from[128];
-       char to[128];
+       err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
+       MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
 
-       for (int i = 0; i < MsgIdCnt; i++)
+       for (int i = 0; i < cbChannelInfo.channelCnt; i++)
        {
-               memset(from, 0x00, sizeof(from));
-               sprintf(from, "%s/%d", CB_CHANNEL_ID_FROM, i);
-
-               memset(to, 0x00, sizeof(to));
-               sprintf(to, "%s/%d", CB_CHANNEL_ID_TO, i);
-
-               if (MsgId >= MsgSettingGetInt(from) && MsgId <= MsgSettingGetInt(to))
+               if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to)
                {
                        MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
 #if 0
-                       memset(keyName, 0x00, sizeof(keyName));
-                       sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
-
+                       char strTmp[CB_CHANNEL_NAME_MAX + 1];
                        memset(strTmp, 0x00, sizeof(strTmp));
 
-                       channelName = MsgSettingGetString(keyName);
-
-                       strncpy(strTmp, channelName, CB_CHANNEL_NAME_MAX);
-
-                       if (channelName) {
-                               free(channelName);
-                               channelName = NULL;
-                       }
+                       strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
 
                        if (strlen(strTmp) > 0)
-                               sprintf(pDisplayName, "[%s]", strTmp);
+                               snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
                        else
-                               sprintf(pDisplayName, "[%d]", MsgId);
+                               snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
 #else
-                       sprintf(pDisplayName, "[%d]", MsgId);
+
+       #ifdef MSG_NOTI_INTEGRATION
+                       snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
+       #else
+                       snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
+       #endif
+
 #endif
 
                        return;
index f98b548..28581bd 100755 (executable)
@@ -1,28 +1,32 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
 #include "MsgException.h"
 #include "MsgCppTypes.h"
 #include "MsgUtilFile.h"
+#include "MsgGconfWrapper.h"
+#include "MsgNotificationWrapper.h"
 #include "SmsPluginStorage.h"
 #include "SmsPluginTransport.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginWapPushHandler.h"
 #include "SmsPluginConcatHandler.h"
+#include "SmsPluginSimMsg.h"
+#include "SmsPluginDSHandler.h"
 
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginConcatHandler - Member Functions
@@ -72,7 +76,7 @@ bool SmsPluginConcatHandler::IsConcatMsg(SMS_USERDATA_S *pUserData)
 }
 
 
-void SmsPluginConcatHandler::handleConcatMsg(SMS_TPDU_S *pTpdu)
+void SmsPluginConcatHandler::handleConcatMsg(struct tapi_handle *handle, SMS_TPDU_S *pTpdu)
 {
        MSG_BEGIN();
 
@@ -86,6 +90,8 @@ void SmsPluginConcatHandler::handleConcatMsg(SMS_TPDU_S *pTpdu)
 
        SMS_CONCAT_MSG_S msg = {0};
 
+       msg.simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
        for (int i = 0; i < pTpdu->data.deliver.userData.headerCnt; i++) {
                if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT) {
                        msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat8bit.msgRef;
@@ -142,18 +148,55 @@ void SmsPluginConcatHandler::handleConcatMsg(SMS_TPDU_S *pTpdu)
 
                MSG_MESSAGE_INFO_S msgInfo = {0};
 
-               dataSize = makeConcatUserData(msg.msgRef, &pUserData);
+               msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+               msgInfo.sim_idx = msg.simIndex;
+
+               dataSize = makeConcatUserData(msg.msgRef, msg.simIndex, &pUserData);
 
                if (dataSize > 0) {
                        if (SmsPluginWapPushHandler::instance()->IsWapPushMsg(&(pTpdu->data.deliver.userData)) == true) {
                                SmsPluginWapPushHandler::instance()->copyDeliverData(&(pTpdu->data.deliver));
-                               SmsPluginWapPushHandler::instance()->handleWapPushMsg(pUserData, dataSize);
+                               msgInfo.msgType.mainType = MSG_SMS_TYPE;
+                               if (err == MSG_SUCCESS) {
+                                               SmsPluginWapPushHandler::instance()->handleWapPushMsg(pUserData, dataSize, msg.simIndex);
+                               }
                        } else {
                                convertConcatToMsginfo(&(pTpdu->data.deliver), pUserData, dataSize, &msgInfo);
 
+                               if (msgInfo.msgPort.valid == true) {
+                                       if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcalendar WAP push) **/
+                                               (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
+                                               memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
+                                               snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<<Content not supported>>");
+                                               msgInfo.dataSize = strlen(msgInfo.msgText);
+                                               msgInfo.msgPort.valid = false;
+                                       }
+                               }
+
                                if (msgInfo.msgPort.valid == false) {
                                        /** Add Concat Msg into DB */
-                                       err = SmsPluginStorage::instance()->addMessage(&msgInfo);
+
+                                       /* check Class2 Normal SMS is longer than SIM slot full size and send DeliveryReport SUCCESS because that Class2 msg cannot be saved on SIM
+                                        * It MUST be done before calling addClass2Message(thread) beause 10+ page message body ipc file is deleted after SmsPluginTransport::instance()->msgInfoToSubmitData() */
+                                       if (msgInfo.msgType.subType == MSG_NORMAL_SMS && msgInfo.msgType.classType == MSG_CLASS_2 &&
+                                               (SmsPluginSimMsg::instance()->checkSimMsgFull(msg.simIndex, segCnt) == true)) {
+                                               char keyName[MAX_VCONFKEY_NAME_LEN];
+                                               memset(keyName, 0x00, sizeof(keyName));
+                                               sprintf(keyName, "%s/%d", SIM_TOTAL_COUNT, msg.simIndex);
+                                               int totalCnt = MsgSettingGetInt(keyName);
+
+                                               if (segCnt > totalCnt) {
+                                                       //send DeliveryResport as MSG_SUCCESS and return when total sim storage cnt is less than segment cnt.
+                                                       MSG_INFO("SIM slot total count [%d] is less than total sement count of Class2 message [%d], send delivery report as SUCCESS and save it only PHONE", totalCnt, segCnt);
+
+                                                       SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
+
+                                                       MsgInsertTicker("Message is too large to store as a single message to SIM card.", SMS_MESSAGE_SIZE_OVER_SIM_SLOT_SIZE, false, 0);
+                                               }
+                                       } else {
+                                               err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+                                       }
                                }
 
                                if (err == MSG_SUCCESS) {
@@ -169,11 +212,181 @@ void SmsPluginConcatHandler::handleConcatMsg(SMS_TPDU_S *pTpdu)
                        }
                }
 
-               removeFromConcatList(msg.msgRef);
+               removeFromConcatList(msg.msgRef, msg.simIndex);
        }
 
        /** Send Deliver Report */
-       SmsPluginTransport::instance()->sendDeliverReport(err);
+       SmsPluginTransport::instance()->sendDeliverReport(handle, err);
+
+       MSG_END();
+}
+
+void SmsPluginConcatHandler::handleSimConcatMsg(struct tapi_handle *handle, SMS_TPDU_S *pTpdu, int msgId, int bRead, int *simIdList)
+{
+       MSG_BEGIN();
+
+       bool noneConcatTypeHeader = true;
+
+       if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
+               SMS_CONCAT_MSG_S msg = {0};
+
+               msg.simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+               for (int i = 0; i < pTpdu->data.deliver.userData.headerCnt; i++) {
+                       if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT) {
+                               msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat8bit.msgRef;
+                               msg.totalSeg = pTpdu->data.deliver.userData.header[i].udh.concat8bit.totalSeg;
+                               msg.seqNum = pTpdu->data.deliver.userData.header[i].udh.concat8bit.seqNum;
+                               msg.simId = msgId;
+                               memcpy(&(msg.timeStamp.time.absolute), &(pTpdu->data.deliver.timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
+                               memcpy(&(msg.originAddress), &(pTpdu->data.deliver.originAddress), sizeof(SMS_ADDRESS_S));
+                               memcpy(&(msg.dcs), &(pTpdu->data.deliver.dcs), sizeof(SMS_DCS_S));
+
+
+                               /**  check noneConcatTypeHeader */
+                               noneConcatTypeHeader = false;
+
+                               break;
+                       } else if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT) {
+                               msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat16bit.msgRef;
+                               msg.totalSeg = pTpdu->data.deliver.userData.header[i].udh.concat16bit.totalSeg;
+                               msg.seqNum = pTpdu->data.deliver.userData.header[i].udh.concat16bit.seqNum;
+                               msg.simId = msgId;
+                               memcpy(&(msg.timeStamp.time.absolute), &(pTpdu->data.deliver.timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
+                               memcpy(&(msg.originAddress), &(pTpdu->data.deliver.originAddress), sizeof(SMS_ADDRESS_S));
+                               memcpy(&(msg.dcs), &(pTpdu->data.deliver.dcs), sizeof(SMS_DCS_S));
+
+                               /**  check noneConcatTypeHeader */
+                               noneConcatTypeHeader = false;
+
+                               break;
+                       }
+               }
+
+               unsigned char segCnt = checkConcatMsg(&msg, &(pTpdu->data.deliver.userData));
+               MSG_DEBUG("segCnt [%d]", segCnt);
+               MSG_DEBUG("msg.totalSeg [%d]", msg.totalSeg);
+
+               if ((segCnt == msg.totalSeg) || noneConcatTypeHeader) {
+                       MSG_DEBUG("RECEIVED LAST CONCAT : %d", segCnt);
+
+                       int dataSize = 0;
+                       char* pUserData = NULL;
+                       AutoPtr<char> dataBuf(&pUserData);
+
+                       MSG_MESSAGE_INFO_S msgInfo = {0};
+
+                       msgInfo.addressList = NULL;
+                       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+                       msgInfo.sim_idx = msg.simIndex;
+
+                       dataSize = makeConcatUserData(msg.msgRef, msg.simIndex, &pUserData);
+
+                       if (dataSize > 0) {
+
+                               convertConcatToMsginfo(&(pTpdu->data.deliver), pUserData, dataSize, &msgInfo);
+                               // set Sim Message ID
+                               msgInfo.msgId = msgId;
+
+                               // set read status
+                               msgInfo.bRead = bRead;
+                               // set storage id
+                               msgInfo.storageId = MSG_STORAGE_SIM;
+                       }
+                       for (int index = concatList.size(); index >= 0 ; index--) {
+                               if (concatList[index].msgRef == msg.msgRef && concatList[index].simIndex == msg.simIndex) {
+                                       memcpy(simIdList, concatList[index].simIdList, sizeof(int) * MAX_SIM_SMS_NUM);
+                                       for (int i = 0; i < 255; ++i)
+                                       {
+                                               MSG_DEBUG("sim id [%d]", simIdList[i]);
+                                       }
+                                       break;
+                               }
+                       }
+                       removeFromConcatList(msg.msgRef, msg.simIndex);
+                       SmsPluginSimMsg::instance()->setSimMsgEvent(handle, &msgInfo, true); // Call Event Handler
+                       return;
+               }
+               SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false); // Call Event Handler
+       } else {
+               SMS_CONCAT_MSG_S msg = {0};
+
+               msg.simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+               for (int i = 0; i < pTpdu->data.submit.userData.headerCnt; i++) {
+                       if (pTpdu->data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT) {
+                               msg.msgRef = (unsigned short)pTpdu->data.submit.userData.header[i].udh.concat8bit.msgRef;
+                               msg.totalSeg = pTpdu->data.submit.userData.header[i].udh.concat8bit.totalSeg;
+                               msg.seqNum = pTpdu->data.submit.userData.header[i].udh.concat8bit.seqNum;
+                               msg.simId = msgId;
+                               memcpy(&(msg.originAddress), &(pTpdu->data.submit.destAddress), sizeof(SMS_ADDRESS_S));
+                               memcpy(&(msg.dcs), &(pTpdu->data.submit.dcs), sizeof(SMS_DCS_S));
+
+
+                               /**  check noneConcatTypeHeader */
+                               noneConcatTypeHeader = false;
+
+                               break;
+                       } else if (pTpdu->data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT) {
+                               msg.msgRef = (unsigned short)pTpdu->data.submit.userData.header[i].udh.concat16bit.msgRef;
+                               msg.totalSeg = pTpdu->data.submit.userData.header[i].udh.concat16bit.totalSeg;
+                               msg.seqNum = pTpdu->data.submit.userData.header[i].udh.concat16bit.seqNum;
+                               msg.simId = msgId;
+                               memcpy(&(msg.originAddress), &(pTpdu->data.submit.destAddress), sizeof(SMS_ADDRESS_S));
+                               memcpy(&(msg.dcs), &(pTpdu->data.submit.dcs), sizeof(SMS_DCS_S));
+
+                               /**  check noneConcatTypeHeader */
+                               noneConcatTypeHeader = false;
+
+                               break;
+                       }
+               }
+
+               unsigned char segCnt = checkConcatMsg(&msg, &(pTpdu->data.submit.userData));
+
+               MSG_DEBUG("segCnt [%d]", segCnt);
+               MSG_DEBUG("msg.totalSeg [%d]", msg.totalSeg);
+
+               if ((segCnt == msg.totalSeg) || noneConcatTypeHeader) {
+                       MSG_DEBUG("RECEIVED LAST CONCAT : %d", segCnt);
+
+                       int dataSize = 0;
+                       char* pUserData = NULL;
+                       AutoPtr<char> dataBuf(&pUserData);
+
+                       MSG_MESSAGE_INFO_S msgInfo = {0};
+
+                       msgInfo.addressList = NULL;
+                       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+                       msgInfo.sim_idx = msg.simIndex;
+
+                       dataSize = makeConcatUserData(msg.msgRef, msg.simIndex, &pUserData);
+
+                       if (dataSize > 0) {
+                               convertConcatToMsginfo(&(pTpdu->data.submit), pUserData, dataSize, &msgInfo);
+
+                               // set Sim Message ID
+                               msgInfo.msgId = msgId;
+                               // set read status
+                               msgInfo.bRead = bRead;
+
+                               msgInfo.msgType.subType = MSG_CONCAT_SIM_SMS;
+
+                               // set storage id
+                               msgInfo.storageId = MSG_STORAGE_SIM;
+                       }
+                       for (int index = concatList.size(); index >= 0 ; index--) {
+                               if (concatList[index].msgRef == msg.msgRef && concatList[index].simIndex == msg.simIndex) {
+                                       memcpy(simIdList, concatList[index].simIdList, sizeof(int) * MAX_SIM_SMS_NUM);
+                                       break;
+                               }
+                       }
+                       SmsPluginSimMsg::instance()->setSimMsgEvent(handle, &msgInfo, true); // Call Event Handler
+                       removeFromConcatList(msg.msgRef, msg.simIndex);
+                       return;
+               }
+               SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false); // Call Event Handler
+       }
 
        MSG_END();
 }
@@ -398,12 +611,11 @@ unsigned char SmsPluginConcatHandler::checkConcatMsg(SMS_CONCAT_MSG_S *pConcatMs
        bool bFind = false;
 
        for (unsigned int i = 0; i < concatList.size(); i++) {
-               if (concatList[i].msgRef == pConcatMsg->msgRef) {
+               if (concatList[i].msgRef == pConcatMsg->msgRef && concatList[i].simIndex == pConcatMsg->simIndex) {
                        if (concatList[i].data.count(pConcatMsg->seqNum) != 0) {
                                MSG_DEBUG("The Sequence Number already exists [%d]", pConcatMsg->seqNum);
                                return 0;
                        }
-
                        CONCAT_DATA_S concatData = {0};
 
                        memcpy(concatData.data, pUserData->data, pUserData->length);
@@ -411,13 +623,13 @@ unsigned char SmsPluginConcatHandler::checkConcatMsg(SMS_CONCAT_MSG_S *pConcatMs
 
                        pair<unsigned char, CONCAT_DATA_S> newData(pConcatMsg->seqNum, concatData);
                        concatList[i].data.insert(newData);
+                       concatList[i].simIdList[concatList[i].segCnt] = pConcatMsg->simId + 1;
 
                        MSG_DEBUG("MSG DATA : %s", pUserData->data);
                        MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
 
                        concatList[i].segCnt++;
                        concatList[i].totalSize += pUserData->length;
-
                        currSegCnt = concatList[i].segCnt;
 
                        bFind = true;
@@ -429,16 +641,20 @@ unsigned char SmsPluginConcatHandler::checkConcatMsg(SMS_CONCAT_MSG_S *pConcatMs
        /** New Concat Msg */
        if (bFind == false) {
                SMS_CONCAT_INFO_S tmpInfo;
-
+               memset(tmpInfo.simIdList, 0x00, sizeof(int) * MAX_SIM_SMS_NUM);
                tmpInfo.msgRef = pConcatMsg->msgRef;
                tmpInfo.totalSeg = pConcatMsg->totalSeg;
                tmpInfo.segCnt = 1;
+               tmpInfo.simIdList[0] = pConcatMsg->simId + 1;
+               tmpInfo.simIndex = pConcatMsg->simIndex;
+               tmpInfo.bRead = false;
 
                memcpy(&(tmpInfo.timeStamp.time.absolute), &(pConcatMsg->timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
                memcpy(&(tmpInfo.originAddress), &(pConcatMsg->originAddress), sizeof(SMS_ADDRESS_S));
                memcpy(&(tmpInfo.dcs), &(pConcatMsg->dcs), sizeof(SMS_DCS_S));
 
                tmpInfo.totalSize = pUserData->length;
+               tmpInfo.display_time = time(NULL);
 
                CONCAT_DATA_S concatData = {0};
 
@@ -460,14 +676,14 @@ unsigned char SmsPluginConcatHandler::checkConcatMsg(SMS_CONCAT_MSG_S *pConcatMs
 }
 
 
-int SmsPluginConcatHandler::makeConcatUserData(unsigned short MsgRef, char **ppTotalData)
+int SmsPluginConcatHandler::makeConcatUserData(unsigned short MsgRef, int simIndex, char **ppTotalData)
 {
        concatDataMap::iterator it;
 
        int totalSize = 0, offset = 0;
 
        for (unsigned int i = 0; i < concatList.size(); i++) {
-               if (concatList[i].msgRef == MsgRef) {
+               if (concatList[i].msgRef == MsgRef && concatList[i].simIndex == simIndex) {
                        totalSize = concatList[i].totalSize;
 
                        if (totalSize <= 0) {
@@ -494,7 +710,7 @@ void SmsPluginConcatHandler::convertConcatToMsginfo(const SMS_DELIVER_S *pTpdu,
 {
        /** Convert Type  values */
        pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
-       pMsgInfo->msgType.subType = MSG_NORMAL_SMS;
+       pMsgInfo->msgType.subType = SmsPluginEventHandler::instance()->convertMsgSubType(pTpdu->pid);
 
        /** set folder id */
        pMsgInfo->folderId = MSG_INBOX_ID;
@@ -587,6 +803,9 @@ void SmsPluginConcatHandler::convertConcatToMsginfo(const SMS_DELIVER_S *pTpdu,
        pMsgInfo->displayTime = rawtime;
 
        /** Convert Address values */
+       pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
        pMsgInfo->nAddressCnt = 1;
        pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
        strncpy(pMsgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
@@ -615,6 +834,7 @@ void SmsPluginConcatHandler::convertConcatToMsginfo(const SMS_DELIVER_S *pTpdu,
        memset(tmpBuf, 0x00, sizeof(tmpBuf));
 
        /** Convert Data values */
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
        if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
                MSG_LANG_INFO_S langInfo = {0,};
 
@@ -622,14 +842,14 @@ void SmsPluginConcatHandler::convertConcatToMsginfo(const SMS_DELIVER_S *pTpdu,
                langInfo.bLockingShift = false;
 
                pMsgInfo->encodeType = MSG_ENCODE_GSM7BIT;
-               pMsgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize, &langInfo);
+               pMsgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize, &langInfo);
        } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
                pMsgInfo->encodeType = MSG_ENCODE_8BIT;
                memcpy(tmpBuf, pUserData, DataSize);
                pMsgInfo->dataSize = DataSize;
        } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
                pMsgInfo->encodeType = MSG_ENCODE_UCS2;
-               pMsgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize);
+               pMsgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize);
        }
 
        MSG_DEBUG("Data Size [%d]", pMsgInfo->dataSize);
@@ -656,7 +876,7 @@ printf("\n");
                if (MsgCreateFileName(fileName) == false)
                        THROW(MsgException::FILE_ERROR, "########  MsgCreateFileName Fail !!! #######");
 
-               MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
+               MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
                if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
                        THROW(MsgException::FILE_ERROR, "########  MsgWriteIpcFile Fail !!! #######");
 
@@ -670,6 +890,123 @@ printf("\n");
 }
 
 
+void SmsPluginConcatHandler::convertConcatToMsginfo(const SMS_SUBMIT_S *pTpdu, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       /** Convert Type  values */
+       pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
+       pMsgInfo->msgType.subType = SmsPluginEventHandler::instance()->convertMsgSubType(pTpdu->pid);
+
+       /** set folder id */
+       pMsgInfo->folderId = MSG_INBOX_ID;
+
+       /** set storage id */
+       pMsgInfo->storageId = MSG_STORAGE_PHONE;
+
+       switch(pTpdu->dcs.msgClass)
+       {
+               case SMS_MSG_CLASS_0:
+                       pMsgInfo->msgType.classType = MSG_CLASS_0;
+                       break;
+               case SMS_MSG_CLASS_1:
+                       pMsgInfo->msgType.classType = MSG_CLASS_1;
+                       break;
+               case SMS_MSG_CLASS_2:
+                       pMsgInfo->msgType.classType = MSG_CLASS_2;
+                       break;
+               case SMS_MSG_CLASS_3:
+                       pMsgInfo->msgType.classType = MSG_CLASS_3;
+                       break;
+               default:
+                       pMsgInfo->msgType.classType = MSG_CLASS_NONE;
+                       break;
+       }
+
+       pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
+       pMsgInfo->bRead = false;
+       pMsgInfo->bProtected = false;
+       pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
+       pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
+
+
+       time_t rawtime = time(NULL);
+       pMsgInfo->displayTime = rawtime;
+
+       /** Convert Address values */
+       pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+       pMsgInfo->nAddressCnt = 1;
+       pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
+       strncpy(pMsgInfo->addressList[0].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
+
+       pMsgInfo->msgPort.valid = false;
+       pMsgInfo->msgPort.dstPort = 0;
+       pMsgInfo->msgPort.srcPort = 0;
+
+       for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
+               /** Convert UDH values - Port Number */
+               if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
+                       pMsgInfo->msgPort.valid = true;
+                       pMsgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
+                       pMsgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
+               } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
+                       pMsgInfo->msgPort.valid = true;
+                       pMsgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
+                       pMsgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
+               }
+       }
+
+       //int bufSize = (MAX_MSG_DATA_LEN*MAX_SEGMENT_NUM) + 1;
+       int bufSize = (DataSize*4) + 1; // For UTF8
+
+       char tmpBuf[bufSize];
+       memset(tmpBuf, 0x00, sizeof(tmpBuf));
+
+       /** Convert Data values */
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
+       if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
+               MSG_LANG_INFO_S langInfo = {0,};
+
+               langInfo.bSingleShift = false;
+               langInfo.bLockingShift = false;
+
+               pMsgInfo->encodeType = MSG_ENCODE_GSM7BIT;
+               pMsgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize, &langInfo);
+       } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
+               pMsgInfo->encodeType = MSG_ENCODE_8BIT;
+               memcpy(tmpBuf, pUserData, DataSize);
+               pMsgInfo->dataSize = DataSize;
+       } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
+               pMsgInfo->encodeType = MSG_ENCODE_UCS2;
+               pMsgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize);
+       }
+
+       MSG_DEBUG("Data Size [%d]", pMsgInfo->dataSize);
+       MSG_DEBUG("Data [%s]", tmpBuf);
+
+       if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
+               pMsgInfo->bTextSms = false;
+
+               /** Save Message Data into File */
+               char fileName[MSG_FILENAME_LEN_MAX+1];
+               memset(fileName, 0x00, sizeof(fileName));
+
+               if (MsgCreateFileName(fileName) == false)
+                       THROW(MsgException::FILE_ERROR, "########  MsgCreateFileName Fail !!! #######");
+
+               MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
+               if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
+                       THROW(MsgException::FILE_ERROR, "########  MsgWriteIpcFile Fail !!! #######");
+
+               strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
+       } else {
+               pMsgInfo->bTextSms = true;
+
+               memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
+               memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
+       }
+}
+
 #ifdef CONCAT_SIM_MSG_OPERATION
 void SmsPluginConcatHandler::convertSimMsgToMsginfo(const SMS_CONCAT_MSG_S *pConcatMsg, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo)
 {
@@ -834,15 +1171,15 @@ void SmsPluginConcatHandler::convertSimMsgToMsginfo(const SMS_CONCAT_MSG_S *pCon
        memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
        strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
 
-       MSG_DEBUG("Save Message Data into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
+       MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
 }
 #endif
 
 
-void SmsPluginConcatHandler::removeFromConcatList(unsigned short MsgRef)
+void SmsPluginConcatHandler::removeFromConcatList(unsigned short MsgRef, int simIndex)
 {
-       for (int index = concatList.size(); index >= 0 ; index--) {
-               if (concatList[index].msgRef == MsgRef) {
+       for (int index = concatList.size()-1; index >= 0 ; index--) {
+               if (concatList[index].msgRef == MsgRef && concatList[index].simIndex == simIndex) {
                        MSG_DEBUG("remove concatlist of the index [%d]", index);
                        concatList.erase(concatList.begin()+index);
                        break;
diff --git a/plugin/sms_plugin/SmsPluginDSHandler.cpp b/plugin/sms_plugin/SmsPluginDSHandler.cpp
new file mode 100755 (executable)
index 0000000..1a4bba5
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include <errno.h>
+#include "MsgDebug.h"
+#include "MsgException.h"
+#include "SmsPluginDSHandler.h"
+#include "MsgGconfWrapper.h"
+
+extern "C"
+{
+       #include <tapi_common.h>
+       #include <TelNetwork.h>
+       #include <ITapiNetwork.h>
+}
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
+==================================================================================================*/
+SmsPluginDSHandler* SmsPluginDSHandler::pInstance = NULL;
+
+
+SmsPluginDSHandler::SmsPluginDSHandler()
+{
+}
+
+
+SmsPluginDSHandler::~SmsPluginDSHandler()
+{
+}
+
+
+SmsPluginDSHandler* SmsPluginDSHandler::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginDSHandler();
+
+       return pInstance;
+}
+
+int SmsPluginDSHandler::initTelHandle()
+{
+       int cnt = 0;
+       cp_list = tel_get_cp_name_list();
+
+       if (!cp_list) {
+               MSG_FATAL("tel_get_cp_name_list returns null");
+               goto FINISH;
+       }
+
+       while(cp_list[cnt] && cnt < MAX_TELEPHONY_HANDLE_CNT)
+       {
+               MSG_SEC_INFO("cp_list[%d]:[%s]", cnt, cp_list[cnt]);
+               handle_list.handle[cnt]= tel_init(cp_list[cnt]);
+               cnt++;
+       }
+
+FINISH:
+       handle_list.count = cnt;
+       return cnt;
+}
+
+void SmsPluginDSHandler::deinitTelHandle()
+{
+       int ret = 0;
+
+       for (int i = 0; i < handle_list.count; i++)
+       {
+               ret = tel_deinit(handle_list.handle[i]);
+               MSG_DEBUG("tel_deinit ret=[%d]", ret);
+               handle_list.handle[i] = NULL;
+       }
+
+       handle_list.count = 0;
+       cp_list = NULL;
+
+       return;
+}
+
+struct tapi_handle *SmsPluginDSHandler::getTelHandle(int sim_idx)
+{
+       if (sim_idx > 0 && sim_idx < MAX_TELEPHONY_HANDLE_CNT)
+               return handle_list.handle[sim_idx-1];
+       else {
+               int SIM_Status = 0;
+               SIM_Status = MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT);
+               if (SIM_Status == 1) {
+                       return handle_list.handle[0];
+               }
+
+               SIM_Status = MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT2);
+               if (SIM_Status == 1) {
+                       return handle_list.handle[1];
+               }
+       }
+
+       return handle_list.handle[handle_list.count - 1];
+}
+
+int SmsPluginDSHandler::getSimIndex(struct tapi_handle *handle)
+{
+       for(int index=0; index < handle_list.count; ++index)
+       {
+               if(handle_list.handle[index] == handle)
+                       return index+1;
+       }
+       return 0;
+}
+
+
+void SmsPluginDSHandler::getDefaultNetworkSimId(int *simId)
+{
+       TelNetworkDefaultDataSubs_t defaultSimId;
+
+       int tapi_ret = TAPI_API_SUCCESS;
+
+       if (handle_list.count == 1) {
+               *simId = 1;
+               return;
+       }
+
+       tapi_ret = tel_get_network_default_data_subscription(handle_list.handle[0], &defaultSimId);
+
+       MSG_INFO("Default network subscription = [SIM %d]", (int)defaultSimId+1);
+
+       if (tapi_ret != TAPI_API_SUCCESS) {
+               *simId = 0;
+               THROW(MsgException::SMS_PLG_ERROR, "########  tel_get_network_default_data_subscription Fail !!! return : %d #######", tapi_ret);
+       } else {
+               *simId = (int)defaultSimId + 1;
+       }
+}
+
+
+int SmsPluginDSHandler::getTelHandleCount()
+{
+       return handle_list.count;
+}
+
+int SmsPluginDSHandler::getActiveSimCount()
+{
+       int active_count = 0;
+       int sim_status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
+
+       sim_status = MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT);
+       MSG_DEBUG("sim1 status : %d", sim_status);
+       if (sim_status == VCONFKEY_TELEPHONY_SIM_INSERTED)
+               active_count++;
+
+       sim_status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
+       sim_status = MsgSettingGetInt(VCONFKEY_TELEPHONY_SIM_SLOT2);
+
+       MSG_DEBUG("sim2 status : %d", sim_status);
+       if (sim_status == VCONFKEY_TELEPHONY_SIM_INSERTED)
+               active_count++;
+
+       MSG_DEBUG("active sim count : %d", active_count);
+
+       return active_count;
+}
index b9675d6..9305674 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include<time.h>
 
 #include "MsgDebug.h"
 #include "MsgUtilFile.h"
+#include "MsgCppTypes.h"
+#include "MsgContact.h"
 #include "MsgGconfWrapper.h"
+#include "MsgNotificationWrapper.h"
+#include "MsgDevicedWrapper.h"
 #include "SmsPluginTransport.h"
 #include "SmsPluginSimMsg.h"
 #include "SmsPluginStorage.h"
 #include "SmsPluginSetting.h"
 #include "SmsPluginConcatHandler.h"
 #include "SmsPluginEventHandler.h"
+#include "SmsPluginDSHandler.h"
 
 
 /*==================================================================================================
@@ -43,6 +48,9 @@ SmsPluginEventHandler::SmsPluginEventHandler()
 
        pSimCnt = NULL;
        devStatus = false;
+       bUdhMwiMethod = false;
+       udhMwiCnt = 0;
+       devHandle = NULL;
 }
 
 
@@ -71,13 +79,27 @@ void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
 {
        MSG_DEBUG("NetStatus[%d]", NetStatus);
 
-       SmsPluginTransport::instance()->setNetStatus(NetStatus);
+       if (sentInfo.reqInfo.msgInfo.msgType.subType == MSG_UNSAVED_SMS) {
+               MSG_SEC_INFO("Delete sim change alert msg. NetStatus:%d", NetStatus);
+               SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
+               return;
+       }
 
        if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
                /** Update Msg Status */
-               if (sentInfo.reqInfo.msgInfo.msgPort.valid == false){
-                       SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus);
+               if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
+//                     SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus);
+
                        sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
+
+                       if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
+                               MSG_DEBUG("Add phone log");
+                               MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
+                               sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID; // It should be set after adding phone log.
+                       } else {
+                               sentInfo.reqInfo.msgInfo.bRead = false;
+                       }
+
                        callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
                }
 
@@ -85,7 +107,7 @@ void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
                MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
                /** Check sending options */
                if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
-                       SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
+//                     SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
                        callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
                }
 
@@ -103,38 +125,115 @@ void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
 }
 
 
-void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
+void SmsPluginEventHandler::handleMsgIncoming(struct tapi_handle *handle, SMS_TPDU_S *pTpdu)
 {
+
        /** Make MSG_MESSAGE_INFO_S */
        MSG_MESSAGE_INFO_S msgInfo;
 
        /** initialize msgInfo */
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
-       /** check unsupported message */
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+
        if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
+               /** check unsupported message */
                if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
                        MSG_DEBUG("Unsupported message!!");
-                       SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
+                       SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
                        return;
                }
        }
 
-       /** check discard & indicator inactive message **/
-       if (pTpdu->data.deliver.dcs.bMWI == true &&
-                       pTpdu->data.deliver.dcs.bIndActive == false &&
-                       pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD) {
-               MSG_DEBUG("Discard and no-indication message!!");
-               SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
-               return;
-       }
+       bUdhMwiMethod = false;
+       udhMwiCnt = 0;
+
+       if(pTpdu->data.deliver.dcs.msgClass == SMS_MSG_CLASS_2)
+               msgInfo.storageId = MSG_STORAGE_UNKNOWN;
+       else
+               msgInfo.storageId = MSG_STORAGE_PHONE;
+
+       msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
 
        /** convert to msgInfo */
        convertTpduToMsginfo(pTpdu, &msgInfo);
 
+       if (msgInfo.msgPort.valid == true) {
+               if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcard WAP push) **/
+                       (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
+                       memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
+                       snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<Unsupported message>");
+                       msgInfo.dataSize = strlen(msgInfo.msgText);
+                       msgInfo.msgPort.valid = false;
+               }
+       }
+
+       if (bUdhMwiMethod == false) {
+               /** check MWI and set info to SIM for DCS & Address method */
+               if (pTpdu->tpduType == SMS_TPDU_DELIVER && pTpdu->data.deliver.dcs.bMWI == true) {
+                       MSG_DEBUG("MWI message - DCS method");
+
+                       if (pTpdu->data.deliver.dcs.bIndActive == false) {
+                               SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
+                               SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
+                               return;
+                       } else {
+                               SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 1);
+
+                               /* For address method */
+                               if (pTpdu->data.deliver.pid == 0x20 && pTpdu->data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
+                                       MSG_DEBUG("MWI message - Address method");
+                                       char *voiceNumber = NULL;
+                                       char *voiceAlphaId = NULL;
+                                       char keyName[MAX_VCONFKEY_NAME_LEN];
+
+                                       memset(keyName, 0x00, sizeof(keyName));
+                                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
+                                       voiceNumber = MsgSettingGetString(keyName);
+
+                                       memset(keyName, 0x00, sizeof(keyName));
+                                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
+                                       voiceAlphaId = MsgSettingGetString(keyName);
+
+                                       memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
+                                       memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
+
+                                       if (voiceNumber) {
+                                               snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
+                                               free(voiceNumber);
+                                               voiceNumber = NULL;
+                                       }
+
+                                       if (voiceAlphaId) {
+                                               snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
+                                               free(voiceAlphaId);
+                                               voiceAlphaId = NULL;
+                                       }
+
+                                       memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
+                                       snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
+
+                               }
+                       }
+
+                       if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD)
+                               msgInfo.bStore = false;
+               }
+       } else {
+               MSG_DEBUG("MWI message - UDH method");
+               if (udhMwiCnt <= 0) {
+                       MSG_DEBUG("MWI count is 0");
+                       SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
+                       SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
+                       return;
+               }
+       }
+
        /** Short Message Type 0 - Just Send Deliver Report */
        if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
-               SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
+               SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
                return;
        }
 
@@ -143,10 +242,12 @@ void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
        MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
        MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
        MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
+       MSG_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
        MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
        MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
        MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
        MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
+       MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
        MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
        MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
        MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
@@ -155,6 +256,7 @@ void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
        MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
        MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
        MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
+       MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
 
        if (msgInfo.bTextSms == true) {
                MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
@@ -168,10 +270,15 @@ void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
 
        if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
                /** Status Report Message */
-               err = listener.pfMsgIncomingCb(&msgInfo);
+               err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
+
+               if (err == MSG_SUCCESS)
+                       err = listener.pfMsgIncomingCb(&msgInfo);
+               else
+                       MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
 
                /** Handling of Fail Case ?? */
-               SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
+               SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
        } else { /** SMS Deliver */
                /** Class 2 Msg */
                if (msgInfo.msgType.classType == MSG_CLASS_2) {
@@ -181,12 +288,21 @@ void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
                        }
                }
 
+               /** Add message to DB */
                if (msgInfo.msgPort.valid == false) {
-                       err = SmsPluginStorage::instance()->addMessage(&msgInfo);
+                       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
                }
 
                /** Callback to MSG FW */
-               if (msgInfo.msgType.classType != MSG_CLASS_2) {
+               if (msgInfo.msgType.classType == MSG_CLASS_2) {
+                       if (((msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS) && (msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) &&
+                                       (msgInfo.bStore == false)) {
+                               if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
+                                       MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
+
+                               SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
+                       }
+               } else {
                        if (err == MSG_SUCCESS) {
                                MSG_DEBUG("callback to msg fw");
                                err = listener.pfMsgIncomingCb(&msgInfo);
@@ -200,14 +316,17 @@ void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
 
                        /** Send Deliver Report */
                        if (msgInfo.msgType.classType == MSG_CLASS_0)
-                               SmsPluginTransport::instance()->sendClass0DeliverReport(err);
+                               SmsPluginTransport::instance()->sendClass0DeliverReport(handle, err);
                        else
-                               SmsPluginTransport::instance()->sendDeliverReport(err);
+                               SmsPluginTransport::instance()->sendDeliverReport(handle, err);
                }
 
                // Tizen Validation System
                char *msisdn = NULL;
-               msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, msgInfo.sim_idx);
+               msisdn = MsgSettingGetString(keyName);
 
                MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s",  msgInfo.msgId, \
                                                                                                                                msgInfo.addressList[0].addressVal, \
@@ -215,6 +334,11 @@ void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
                                                                                                                                (err == MSG_SUCCESS)?"Success":"Fail");
 
                MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
+
+               if (msisdn) {
+                       free(msisdn);
+                       msisdn = NULL;
+               }
        }
 }
 
@@ -225,7 +349,7 @@ void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPush
        memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
 
        /** set PUSH data */
-       memcpy(&pushData.pushHeader, pPushHeader, strlen(pPushHeader));
+       memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
 
        pushData.pushBodyLen = pushBodyLen;
        memcpy(pushData.pushBody, pPushBody, pushBodyLen);
@@ -238,7 +362,13 @@ void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPush
 }
 
 
-void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen)
+void SmsPluginEventHandler::handleResendMessage(void)
+{
+       listener.pfResendMessageCb();
+}
+
+
+void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen,int simIndex)
 {
        MSG_SYNCML_MESSAGE_DATA_S syncMLData;
 
@@ -247,6 +377,8 @@ void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t ms
        /** set syncML data */
        syncMLData.syncmlType = msgType;
 
+       syncMLData.simIndex = simIndex;
+
        syncMLData.pushBodyLen = PushBodyLen;
        memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
 
@@ -265,7 +397,7 @@ void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushB
        memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
 
        /** set LBA data */
-       memcpy(&lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
+       memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
 
        lBSData.pushBodyLen = pushBodyLen;
        memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
@@ -274,7 +406,6 @@ void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushB
        listener.pfLBSMsgIncomingCb(&lBSData);
 }
 
-
 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
@@ -289,14 +420,14 @@ msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgI
        return err;
 }
 
-msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg)
+msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
 
        msg_error_t err = MSG_SUCCESS;
 
        /** Callback to MSG FW */
-       err = listener.pfCBMsgIncomingCb(pCbMsg);
+       err = listener.pfCBMsgIncomingCb(pCbMsg, pMsgInfo);
 
        MSG_END();
 
@@ -322,7 +453,6 @@ msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type
 
 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
 {
-       memset(msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
        switch(pTpdu->tpduType)
        {
@@ -348,7 +478,7 @@ void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu
        msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
 
        /** set folder id (temporary) */
-       msgInfo->folderId = MSG_OUTBOX_ID;
+       msgInfo->folderId = MSG_SENTBOX_ID;
 
        switch(pTpdu->dcs.msgClass)
        {
@@ -366,13 +496,14 @@ void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu
                        break;
                default:
                        msgInfo->msgType.classType = MSG_CLASS_NONE;
+                       break;
        }
 
        msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
        msgInfo->bRead = false;
        msgInfo->bProtected = false;
        msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
-       msgInfo->direction = MSG_DIRECTION_TYPE_MT;
+       msgInfo->direction = MSG_DIRECTION_TYPE_MO;
        msgInfo->bTextSms = true;
 
        memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
@@ -386,6 +517,10 @@ void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu
 
        /** Convert Address values */
        msgInfo->nAddressCnt = 1;
+
+       msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
        msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
        strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
 
@@ -397,15 +532,16 @@ void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu
        }
 
        /** Convert Data values */
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
        if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
                MSG_LANG_INFO_S langInfo = {0,};
 
                langInfo.bSingleShift = false;
                langInfo.bLockingShift = false;
 
-               msgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
+               msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
        } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
-               msgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
+               msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
        }
 }
 
@@ -421,7 +557,65 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
        /** set folder id (temporary) */
        msgInfo->folderId = MSG_INBOX_ID;
 
-       msgInfo->storageId = MSG_STORAGE_PHONE;
+       time_t rawtime = 0;
+       if(msgInfo->storageId == MSG_STORAGE_SIM)
+       {
+       /*** Comment below lines to save local UTC time..... (it could be used later.)
+       ***/
+               if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
+
+                       MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
+                       MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
+                       MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
+                       MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
+                       MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
+                       MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
+                       MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
+
+                       char displayTime[32];
+                       struct tm * timeTM;
+
+                       struct tm timeinfo;
+                       memset(&timeinfo, 0x00, sizeof(tm));
+
+                       timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
+                       timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
+                       timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
+                       timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
+                       timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
+                       timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
+                       timeinfo.tm_isdst = 0;
+
+                       rawtime = mktime(&timeinfo);
+
+                       MSG_DEBUG("tzname[0] [%s]", tzname[0]);
+                       MSG_DEBUG("tzname[1] [%s]", tzname[1]);
+                       MSG_DEBUG("timezone [%d]", timezone);
+                       MSG_DEBUG("daylight [%d]", daylight);
+
+                       memset(displayTime, 0x00, sizeof(displayTime));
+                       strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
+                       MSG_DEBUG("displayTime [%s]", displayTime);
+
+                       rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
+
+                       timeTM = localtime(&rawtime);
+                       memset(displayTime, 0x00, sizeof(displayTime));
+                       strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
+                       MSG_DEBUG("displayTime [%s]", displayTime);
+
+                       rawtime -= timezone;
+
+                       timeTM = localtime(&rawtime);
+                       memset(displayTime, 0x00, sizeof(displayTime));
+                       strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
+                       MSG_DEBUG("displayTime [%s]", displayTime);
+               }
+       }
+       else
+               rawtime = time(NULL);
+
+       msgInfo->displayTime = rawtime;
 
        switch(pTpdu->dcs.msgClass)
        {
@@ -444,7 +638,16 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
        }
 
        if (pTpdu->dcs.bMWI) {
-               msgInfo->msgType.subType = (pTpdu->dcs.indType + MSG_MWI_VOICE_SMS);
+               if (pTpdu->dcs.indType == SMS_VOICE_INDICATOR)
+                       msgInfo->msgType.subType = MSG_MWI_VOICE_SMS;
+               else if (pTpdu->dcs.indType == SMS_VOICE2_INDICATOR)
+                       msgInfo->msgType.subType = MSG_MWI_VOICE2_SMS;
+               else if (pTpdu->dcs.indType == SMS_FAX_INDICATOR)
+                       msgInfo->msgType.subType = MSG_MWI_FAX_SMS;
+               else if (pTpdu->dcs.indType == SMS_EMAIL_INDICATOR)
+                       msgInfo->msgType.subType = MSG_MWI_EMAIL_SMS;
+               else if (pTpdu->dcs.indType == SMS_OTHER_INDICATOR)
+                       msgInfo->msgType.subType = MSG_MWI_OTHER_SMS;
        }
 
        msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
@@ -456,66 +659,12 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
 
        memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
 
-       time_t rawtime = time(NULL);
-
-/*** Comment below lines to save local UTC time..... (it could be used later.)
-
-       if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
-
-               MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
-               MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
-               MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
-               MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
-               MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
-               MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
-               MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
-
-               char displayTime[32];
-               struct tm * timeTM;
-
-               struct tm timeinfo;
-               memset(&timeinfo, 0x00, sizeof(tm));
-
-               timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
-               timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
-               timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
-               timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
-               timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
-               timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
-               timeinfo.tm_isdst = 0;
-
-               rawtime = mktime(&timeinfo);
-
-               MSG_DEBUG("tzname[0] [%s]", tzname[0]);
-               MSG_DEBUG("tzname[1] [%s]", tzname[1]);
-               MSG_DEBUG("timezone [%d]", timezone);
-               MSG_DEBUG("daylight [%d]", daylight);
-
-               memset(displayTime, 0x00, sizeof(displayTime));
-               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
-               MSG_DEBUG("displayTime [%s]", displayTime);
-
-               rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
-
-               timeTM = localtime(&rawtime);
-               memset(displayTime, 0x00, sizeof(displayTime));
-               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
-               MSG_DEBUG("displayTime [%s]", displayTime);
-
-               rawtime -= timezone;
-
-               timeTM = localtime(&rawtime);
-               memset(displayTime, 0x00, sizeof(displayTime));
-               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
-               MSG_DEBUG("displayTime [%s]", displayTime);
-       }
-
-***/
-
-       msgInfo->displayTime = rawtime;
-
        /** Convert Address values */
        msgInfo->nAddressCnt = 1;
+
+       msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
        msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
        strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
 
@@ -537,25 +686,29 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
                        msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
                        msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
 
+                       bUdhMwiMethod = true;
+
                        if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
                                msgInfo->bStore = false;
 
-                       MSG_DEBUG("Message waiting number : [%d]", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
-                       SmsPluginSetting::instance()->setMwiInfo(msgInfo->msgType.subType, pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
+                       udhMwiCnt = pTpdu->userData.header[i].udh.specialInd.waitMsgNum;
+                       MSG_DEBUG("Message waiting number : [%d]", udhMwiCnt);
+
+                       SmsPluginSetting::instance()->setMwiInfo(msgInfo->sim_idx, msgInfo->msgType.subType, udhMwiCnt);
 
-                       if (pTpdu->userData.length == 0) {
+                       if (udhMwiCnt > 0 && (msgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
                                switch (msgInfo->msgType.subType) {
                                case MSG_MWI_VOICE_SMS :
-                                       sprintf(msgInfo->msgText, "%d new voice message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
+                                       snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d", udhMwiCnt);
                                        break;
                                case MSG_MWI_FAX_SMS :
-                                       sprintf(msgInfo->msgText, "%d new fax message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
+                                       snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new fax message", udhMwiCnt);
                                        break;
                                case MSG_MWI_EMAIL_SMS :
-                                       sprintf(msgInfo->msgText, "%d new email message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
+                                       snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new email message", udhMwiCnt);
                                        break;
                                default :
-                                       sprintf(msgInfo->msgText, "%d new special message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
+                                       snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new special message", udhMwiCnt);
                                        break;
                                }
                                msgInfo->dataSize = strlen(msgInfo->msgText);
@@ -563,6 +716,10 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
                        }
                } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
                        strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
+               } else if (pTpdu->userData.header[i].udhType >= SMS_UDH_EMS_FIRST && pTpdu->userData.header[i].udhType <= SMS_UDH_EMS_LAST) {
+                       snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "Unsupported Message");
+                       msgInfo->dataSize = strlen(msgInfo->msgText);
+                       return;
                }
        }
 
@@ -595,6 +752,7 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
        }
 
        /** Convert Data values */
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
        if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
                MSG_LANG_INFO_S langInfo = {0,};
 
@@ -612,17 +770,17 @@ void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTp
                }
 
                msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
-               msgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
+               msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
        } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
                msgInfo->encodeType = MSG_ENCODE_8BIT;
                memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
                msgInfo->dataSize = pTpdu->userData.length;
        } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
                msgInfo->encodeType = MSG_ENCODE_UCS2;
-               msgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
+               msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
        } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
                msgInfo->encodeType = MSG_ENCODE_8BIT;
-               msgInfo->dataSize = textCvt.convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
+               msgInfo->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
                return;
        }
 
@@ -640,7 +798,9 @@ void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPOR
        msgInfo->folderId = MSG_INBOX_ID;
 
        /** set storage id */
-       msgInfo->storageId = MSG_STORAGE_PHONE;
+       if (msgInfo->storageId == MSG_STORAGE_UNKNOWN) {
+               msgInfo->storageId = MSG_STORAGE_PHONE;
+       }
 
        switch(pTpdu->dcs.msgClass)
        {
@@ -663,9 +823,20 @@ void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPOR
 
        MSG_DEBUG("delivery status : [%d]", pTpdu->status);
 
-       if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS) {
+       if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS)
+       {
                msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
-       } else {
+       }
+       else if(pTpdu->status == SMS_STATUS_TRY_REQUEST_PENDING)
+       {
+               msgInfo->networkStatus = MSG_NETWORK_DELIVER_PENDING;
+       }
+       else if(pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED)
+       {
+               msgInfo->networkStatus = MSG_NETWORK_DELIVER_EXPIRED;
+       }
+       else
+       {
                msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
        }
 
@@ -737,6 +908,10 @@ void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPOR
 
        /** Convert Address values */
        msgInfo->nAddressCnt = 1;
+
+       msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
        msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
        strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
 
@@ -761,13 +936,13 @@ void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPOR
        msgInfo->dataSize = 0;
 
        if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
-               strncpy(msgInfo->msgText, "Message delivered.", MAX_MSG_TEXT_LEN);
+               strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MESSAGE_DELIVERED", MAX_MSG_TEXT_LEN);
                msgInfo->dataSize = strlen(msgInfo->msgText);
        } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
-               strncpy(msgInfo->msgText, "Message delivery rejected.", MAX_MSG_TEXT_LEN);
+               strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MMSDELIVERYMSGREJECTED", MAX_MSG_TEXT_LEN);
                msgInfo->dataSize = strlen(msgInfo->msgText);
        } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
-               strncpy(msgInfo->msgText, "Message delivery expired.", MAX_MSG_TEXT_LEN);
+               strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MESSAGE_HAS_EXPIRED", MAX_MSG_TEXT_LEN);
                msgInfo->dataSize = strlen(msgInfo->msgText);
        } else {
                strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
@@ -815,27 +990,59 @@ void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
 }
 
 
-void SmsPluginEventHandler::setDeviceStatus()
+void SmsPluginEventHandler::setDeviceStatus(struct tapi_handle *handle)
 {
-       mx.lock();
-       devStatus = true;
-       cv.signal();
-       mx.unlock();
+    if (handle == devHandle) {
+       mx.lock();
+       devStatus = true;
+       cv.signal();
+       mx.unlock();
+    }
 }
 
 
-bool SmsPluginEventHandler::getDeviceStatus()
+bool SmsPluginEventHandler::getDeviceStatus(struct tapi_handle *handle)
 {
        int ret = 0;
 
        mx.lock();
-
-       ret = cv.timedwait(mx.pMutex(), 16);
+       devHandle = handle;
+       ret = cv.timedwait(mx.pMutex(), 25);
 
        if (ret == ETIMEDOUT) {
                MSG_DEBUG("WARNING: DEVICE STATUS TIME-OUT");
                devStatus = false;
        }
+       devHandle = NULL;
        mx.unlock();
        return devStatus;
 }
+
+
+msg_error_t SmsPluginEventHandler::handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Callback to MSG FW */
+       err = listener.pfSimMsgIncomingCb(pMsgInfo, simIdList, retMsgId, listSize);
+
+       MSG_END();
+
+       return err;
+}
+
+msg_error_t SmsPluginEventHandler::updateIMSI(int sim_idx)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Callback to MSG FW */
+       err = listener.pfSimInitImsiCb(sim_idx);
+
+       MSG_END();
+
+       return err;
+}
index 59bce3a..c6074d4 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
@@ -29,6 +29,8 @@
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginUAManager.h"
 #include "SmsPluginMain.h"
+#include "SmsPluginDSHandler.h"
+#include <dbus/dbus-glib.h>
 
 extern "C"
 {
@@ -39,7 +41,12 @@ extern "C"
        #include <ITapiNetText.h>
 }
 
-struct tapi_handle *pTapiHandle = NULL;
+#define BUS_NAME "org.tizen.system.deviced"
+#define PATH_NAME "/Org/Tizen/System/DeviceD/Lowmem"
+#define INTERFACE_NAME BUS_NAME".lowmem"
+#define MEMBER_NAME "Full"
+
+bool isMemAvailable = true;
 
 Mutex mx;
 CndVar cv;
@@ -47,21 +54,6 @@ CndVar cv;
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
-static void MsgTapiInitCB(keynode_t *key, void* data)
-{
-       MSG_DEBUG("MsgTapiInitCB is called.");
-
-       bool bTelRdy = false;
-       bTelRdy = vconf_keynode_get_bool(key);
-
-       MSG_DEBUG("bTelRdy [%d]", bTelRdy);
-
-       if (bTelRdy) {
-               mx.lock();
-               cv.signal();
-               mx.unlock();
-       }
-}
 
 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
 {
@@ -75,19 +67,15 @@ msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
                pPluginHandle->pfInitialize = SmsPlgInitialize;
                pPluginHandle->pfFinalize = SmsPlgFinalize;
                pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
-               pPluginHandle->pfCheckSimStatus = SmsPlgCheckSimStatus;
-               pPluginHandle->pfCheckDeviceStatus = SmsPlgCheckDeviceStatus;
                pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
-               pPluginHandle->pfInitSimMessage = SmsPlgInitSimMessage;
                pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
                pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
                pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
                pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
-               pPluginHandle->pfInitConfigData = SmsPlgInitConfigData;
                pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
                pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
-
-               pPluginHandle->pfRestoreMsg = NULL;
+               pPluginHandle->pfAddMessage = SmsPlgAddMessage;
+               pPluginHandle->pfGetDefaultNetworkSimId = SmsPlgGetDefaultNetworkSimId;
 
                MSG_DEBUG("SMS plugin: create handler OK");
                MSG_DEBUG ("SMS plugin %p", pPluginHandle);
@@ -115,71 +103,50 @@ msg_error_t SmsPlgInitialize()
 {
        MSG_BEGIN();
 
-       MSG_DEBUG("set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND.");
-       if (MsgSettingSetInt(MSG_SIM_CHANGED, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
-               MSG_DEBUG("MsgSettingSetInt is failed!!");
-
        bool bReady = false;
-       MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady);
-       MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady);
 
-       int ret = 0;
+       for (int i = 0; i < 100; i++) {
+               MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady);
+               MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady ? 1 : 0);
 
-       if(!bReady) {
-               MsgSettingRegVconfCBCommon(VCONFKEY_TELEPHONY_READY, MsgTapiInitCB);
-               mx.lock();
-               ret = cv.timedwait(mx.pMutex(), 90);
-               mx.unlock();
-       }
+               if(bReady)
+                       break;
 
-       try
-       {
-               if (ret != ETIMEDOUT) {
-                       pTapiHandle = tel_init(NULL);
-                       SmsPluginCallback::instance()->registerEvent();
-               } else {
-                       MSG_DEBUG("MsgTapiInitCB is time out.");
-               }
-       }
-       catch (MsgException& e)
-       {
-               MSG_FATAL("%s", e.what());
-               return MSG_ERR_PLUGIN_REGEVENT;
+               sleep(1);
        }
-       catch (exception& e)
-       {
-               MSG_FATAL("%s", e.what());
-               return MSG_ERR_PLUGIN_REGEVENT;
-       }
-
-       MSG_END();
 
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t SmsPlgFinalize()
-{
-       MSG_BEGIN();
-
-       if (!pTapiHandle)
+       if (!bReady) {
+               MSG_DEBUG("Fail to wait telephony init complete.");
                return MSG_ERR_PLUGIN_TAPIINIT;
+       }
 
-       SmsPluginCallback::instance()->deRegisterEvent();
+       int simCnt = 0;
+       char keyName[MAX_VCONFKEY_NAME_LEN];
 
-       tel_deinit(pTapiHandle);
+       SmsPluginDSHandler::instance()->initTelHandle();
+       simCnt = SmsPluginDSHandler::instance()->getTelHandleCount();
 
-       MSG_END();
+       MSG_DEBUG("simCnt [%d]", simCnt);
 
-       return MSG_SUCCESS;
-}
+       for (int i = 1; i <= simCnt; i++) {
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, i);
+               MSG_DEBUG("set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND.");
+               if (MsgSettingSetInt(keyName, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgSettingSetInt is failed!!");
+       }
 
+       SmsPluginCallback::instance()->registerEvent();
 
-msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
-{
-       MSG_BEGIN();
+       for(int i=1; i <= simCnt; ++i)
+       {
+               struct tapi_handle *handle;
+               handle = SmsPluginDSHandler::instance()->getTelHandle(i);
+               SmsPluginSetting::instance()->setSimChangeStatus(handle, true);
+       }
 
-       SmsPluginEventHandler::instance()->registerListener(pListener);
+       // set resource monitor
+       MsgResourceMonitorInit();
 
        MSG_END();
 
@@ -187,102 +154,13 @@ msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
 }
 
 
-msg_error_t SmsPlgCheckSimStatus(MSG_SIM_STATUS_T *pStatus)
+msg_error_t SmsPlgFinalize()
 {
        MSG_BEGIN();
 
-       if (!pTapiHandle)
-               return MSG_ERR_PLUGIN_TAPIINIT;
-
-       int tryNum = 0, tapiRet = TAPI_API_SUCCESS;
-
-       TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
-       int cardChanged = 0;
-
-       // initialize pStatus.
-       *pStatus = MSG_SIM_STATUS_NOT_FOUND;
-
-       // Check SIM Status
-       while (1)
-       {
-               if (tryNum > 30) return MSG_ERR_PLUGIN_TAPIINIT;
-
-               tapiRet = tel_get_sim_init_info(pTapiHandle, &status, &cardChanged);
-
-               if (tapiRet == TAPI_API_SUCCESS) {
-                       if (status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED || status == TAPI_SIM_STATUS_SIM_PUK_REQUIRED) {
-                               MSG_DEBUG("PIN or PUK is required [%d]", status);
-
-                               sleep(3);
-
-                               continue;
-                       }
-
-                       if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
-                               MSG_DEBUG("SIM status is OK [%d]", status);
-
-                               MSG_DEBUG("SIM Changed [%d]", cardChanged);
-
-                               if (cardChanged == 1)
-                                       *pStatus = MSG_SIM_STATUS_CHANGED;
-                               else
-                                       *pStatus = MSG_SIM_STATUS_NORMAL;
-
-                               break;
-                       } else if (status == TAPI_SIM_STATUS_CARD_NOT_PRESENT) {
-                               MSG_DEBUG("SIM is not present [%d]", status);
-                               break;
-                       } else {
-                               MSG_DEBUG("SIM status is not OK [%d]", status);
-                               tryNum++;
-
-                               sleep(3);
-                       }
-               } else if (tapiRet == TAPI_API_SIM_NOT_FOUND) {
-                       MSG_DEBUG("tel_get_sim_init_info() result is TAPI_API_SIM_NOT_FOUND");
-                       break;
-               } else {
-                       MSG_DEBUG("tel_get_sim_init_info() result is unknown!!!!!!!!!! [%d]", tapiRet);
-                       tryNum++;
-
-                       sleep(3);
-               }
-       }
-
-
-       char imsi[7];
-       memset(imsi, 0x00, sizeof(imsi));
-
-       // Get IMSI
-       if (*pStatus != MSG_SIM_STATUS_NOT_FOUND)
-       {
-               // Get IMSI
-               TelSimImsiInfo_t imsiInfo;
-               memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
-
-               tapiRet = tel_get_sim_imsi(pTapiHandle, &imsiInfo);
-
-               if (tapiRet == TAPI_API_SUCCESS)
-               {
-                       MSG_DEBUG("tel_get_sim_imsi() Success - MCC [%s], MNC [%s]", imsiInfo.szMcc, imsiInfo.szMnc);
-
-                       sprintf(imsi, "%03d%03d", atoi(imsiInfo.szMcc), atoi(imsiInfo.szMnc));
-
-                       MSG_DEBUG("IMSI [%d]", atoi(imsi));
-               }
-               else
-               {
-                       MSG_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
-
-                       MsgSettingSetBool(MSG_NATIONAL_SIM, false);
-               }
-       }
-       else
-       {
-               MsgSettingSetBool(MSG_NATIONAL_SIM, false);
-       }
+       SmsPluginCallback::instance()->deRegisterEvent();
 
-       MsgSettingSetString(MSG_SIM_IMSI, imsi);
+       SmsPluginDSHandler::instance()->deinitTelHandle();
 
        MSG_END();
 
@@ -290,36 +168,13 @@ msg_error_t SmsPlgCheckSimStatus(MSG_SIM_STATUS_T *pStatus)
 }
 
 
-msg_error_t SmsPlgCheckDeviceStatus()
+msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
 {
        MSG_BEGIN();
 
-       if (!pTapiHandle)
-               return MSG_ERR_PLUGIN_TAPIINIT;
-
-       int status = 0, tapiRet = TAPI_API_SUCCESS;
-
-       tapiRet = tel_check_sms_device_status(pTapiHandle, &status);
-
-       if (tapiRet != TAPI_API_SUCCESS) {
-               MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
-               return MSG_ERR_PLUGIN_TAPI_FAILED;
-       }
-
-       if (status == 1) {
-               MSG_DEBUG("Device Is Ready");
-               return MSG_SUCCESS;
-       } else if (status == 0) {
-               MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
+       SmsPluginEventHandler::instance()->registerListener(pListener);
 
-               if (SmsPluginEventHandler::instance()->getDeviceStatus() == true) {
-                       MSG_DEBUG("Device Is Ready");
-                       return MSG_SUCCESS;
-               } else {
-                       MSG_DEBUG("Device Is Not Ready.");
-                       return MSG_ERR_PLUGIN_TAPI_FAILED;
-               }
-       }
+       MSG_END();
 
        return MSG_SUCCESS;
 }
@@ -332,11 +187,19 @@ msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
        // Add Submit SMS into DB
        if (pReqInfo->msgInfo.msgId == 0) {
                if (pReqInfo->msgInfo.msgPort.valid == false) {
-                       err = SmsPluginStorage::instance()->addMessage(&(pReqInfo->msgInfo));
+                       err = SmsPluginStorage::instance()->checkMessage(&(pReqInfo->msgInfo));
+
                        if (err != MSG_SUCCESS) {
-                               MSG_DEBUG("########  addMessage Fail !!");
+                               MSG_DEBUG("########  checkMessage Fail !! [err=%d]", err);
                                return MSG_ERR_PLUGIN_STORAGE;
                        }
+
+                       err = SmsPluginStorage::instance()->addSmsMessage(&(pReqInfo->msgInfo));
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("########  addSmsMessage Fail !! [err=%d]", err);
+                               return MSG_ERR_PLUGIN_STORAGE;
+                       }
+
                        if (SmsPluginStorage::instance()->addSmsSendOption(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo)) != MSG_SUCCESS) {
                                MSG_DEBUG("########  addSmsSendOption Fail !!");
                                return MSG_ERR_PLUGIN_STORAGE;
@@ -345,7 +208,9 @@ msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
        }
 
        // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, pReqInfo->msgInfo.sim_idx);
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
 
        if (simStatus == MSG_SIM_STATUS_NOT_FOUND)
        {
@@ -379,19 +244,24 @@ msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
 }
 
 
-msg_error_t SmsPlgInitSimMessage()
+msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
 {
        // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, pMsgInfo->sim_idx);
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
 
        if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                MSG_DEBUG("SIM is not present..");
                return MSG_ERR_NO_SIM;
        }
 
+       msg_error_t err = MSG_SUCCESS;
+
        try
        {
-               SmsPluginSimMsg::instance()->initSimMessage();
+               err = SmsPluginSimMsg::instance()->saveSimMessage(pMsgInfo, pSimIdList);
        }
        catch (MsgException& e)
        {
@@ -404,32 +274,16 @@ msg_error_t SmsPlgInitSimMessage()
                return MSG_ERR_PLUGIN_STORAGE;
        }
 
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
-{
-       // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
-
-       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
-               MSG_DEBUG("SIM is not present..");
-               return MSG_ERR_NO_SIM;
-       }
-
-       msg_error_t err = MSG_SUCCESS;
-
-       err = SmsPluginSimMsg::instance()->saveSimMessage(pMsgInfo, pSimIdList);
-
        return err;
 }
 
 
-msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
+msg_error_t SmsPlgDeleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
 {
        // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN]={0,};
+       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, sim_idx);
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
 
        if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                MSG_DEBUG("SIM is not present..");
@@ -438,7 +292,7 @@ msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
 
        try
        {
-               SmsPluginSimMsg::instance()->deleteSimMessage(SimMsgId);
+               SmsPluginSimMsg::instance()->deleteSimMessage(sim_idx, SimMsgId);
        }
        catch (MsgException& e)
        {
@@ -455,10 +309,12 @@ msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
 }
 
 
-msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
+msg_error_t SmsPlgSetReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
 {
        // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN]={0,};
+       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, sim_idx);
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
 
        if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                MSG_DEBUG("SIM is not present..");
@@ -467,7 +323,7 @@ msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
 
        try
        {
-               SmsPluginSimMsg::instance()->setReadStatus(SimMsgId);
+               SmsPluginSimMsg::instance()->setReadStatus(sim_idx, SimMsgId);
        }
        catch (MsgException& e)
        {
@@ -484,10 +340,14 @@ msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
 }
 
 
-msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
+msg_error_t SmsPlgSetMemoryStatus(msg_sim_slot_id_t simIndex, msg_error_t Error)
 {
        // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
+       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
 
        if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
                MSG_DEBUG("SIM is not present..");
@@ -504,7 +364,9 @@ msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
 
        MSG_DEBUG("Set Status : [%d]", status);
 
-       tapiRet = tel_set_sms_memory_status(pTapiHandle, status, TapiEventMemoryStatus, NULL);
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
+
+       tapiRet = tel_set_sms_memory_status(handle, status, TapiEventMemoryStatus, NULL);
 
        if (tapiRet == TAPI_API_SUCCESS)
        {
@@ -519,19 +381,32 @@ msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
 }
 
 
-msg_error_t SmsPlgInitConfigData(MSG_SIM_STATUS_T SimStatus)
+msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
 {
-       // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
-
-       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
-               MSG_DEBUG("SIM is not present..");
-               return MSG_ERR_NO_SIM;
+       try
+       {
+               SmsPluginSetting::instance()->setConfigData(pSetting);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_PLUGIN_SETTING;
+       }
+       catch (exception& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return MSG_ERR_PLUGIN_SETTING;
        }
 
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
+{
        try
        {
-               SmsPluginSetting::instance()->initConfigData(SimStatus);
+               SmsPluginSetting::instance()->getConfigData(pSetting);
        }
        catch (MsgException& e)
        {
@@ -548,19 +423,15 @@ msg_error_t SmsPlgInitConfigData(MSG_SIM_STATUS_T SimStatus)
 }
 
 
-msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
+msg_error_t SmsPlgAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo,  MSG_SENDINGOPT_INFO_S* pSendOptInfo, char* pFileData)
 {
-       // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
-
-       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
-               MSG_DEBUG("SIM is not present..");
-               return MSG_ERR_NO_SIM;
-       }
 
+       int *simIdList = (int*)pFileData;
        try
        {
-               SmsPluginSetting::instance()->setConfigData(pSetting);
+               SmsPluginStorage::instance()->addSmsSendOption(pMsgInfo, pSendOptInfo);
+               if (simIdList)
+                       SmsPluginStorage::instance()->addSimMessage(pMsgInfo, simIdList);
        }
        catch (MsgException& e)
        {
@@ -577,19 +448,12 @@ msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
 }
 
 
-msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
+msg_error_t SmsPlgGetDefaultNetworkSimId(int *simId)
 {
-       // Check SIM is present or not
-       MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
-
-       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
-               MSG_DEBUG("SIM is not present..");
-               return MSG_ERR_NO_SIM;
-       }
 
        try
        {
-               SmsPluginSetting::instance()->getConfigData(pSetting);
+               SmsPluginDSHandler::instance()->getDefaultNetworkSimId(simId);
        }
        catch (MsgException& e)
        {
@@ -605,3 +469,50 @@ msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
        return MSG_SUCCESS;
 }
 
+
+static void on_change_received(DBusGProxy *proxy, const gint memStatus, gpointer userData)
+{
+       MSG_BEGIN();
+
+       if(memStatus == 0)
+       {
+               int sim_count = SmsPluginDSHandler::instance()->getTelHandleCount();
+
+               for (int i = 0; i < sim_count; i++) {
+                       SmsPlgSetMemoryStatus(i, MSG_SUCCESS);
+               }
+       }
+       MSG_END();
+}
+
+int MsgResourceMonitorInit(void)
+{
+       MSG_BEGIN();
+       int err = MSG_SUCCESS;
+
+       DBusGConnection *connection;
+       DBusGProxy *remote_object;
+       GError *error = NULL;
+
+       connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+       if(connection == NULL)
+       {
+               MSG_DEBUG("Couldn't connect to bus");
+               err = MSG_ERR_UNKNOWN;
+               return err;
+       }
+
+       remote_object = dbus_g_proxy_new_for_name(connection, BUS_NAME, PATH_NAME, INTERFACE_NAME);
+       if(!remote_object)
+       {
+               MSG_DEBUG("dbus_request_name error");
+               err = MSG_ERR_UNKNOWN;
+               return err;
+       }
+
+       dbus_g_proxy_add_signal(remote_object, MEMBER_NAME, G_TYPE_INT, G_TYPE_INVALID);
+       dbus_g_proxy_connect_signal(remote_object, MEMBER_NAME, G_CALLBACK(on_change_received), NULL, NULL);
+
+       MSG_END();
+       return err;
+}
index e5c62ef..a1badbd 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -261,7 +261,7 @@ int SmsPluginParamCodec::encodeSMSC(const SMS_ADDRESS_S *pAddress, unsigned char
 int SmsPluginParamCodec::decodeAddress(const unsigned char *pTpdu, SMS_ADDRESS_S *pAddress)
 {
        int offset = 0, addrLen = 0, bcdLen = 0;
-       MsgTextConvert textCvt;
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
        memset(pAddress->address, 0x00, sizeof(pAddress->address));
 
        addrLen = (int)pTpdu[offset++];
@@ -284,22 +284,23 @@ MSG_DEBUG("npi [%d]", pAddress->npi);
                char* tmpAddress = new char[MAX_ADDRESS_LEN];
                int tmplength = 0;
 
-               tmplength = SmsPluginUDCodec::unpack7bitChar(&(pTpdu[offset]), bcdLen, 0, tmpAddress);
+               tmplength = SmsPluginUDCodec::unpack7bitChar(&(pTpdu[offset]), (addrLen*4 )/7, 0, tmpAddress);
 
                MSG_LANG_INFO_S langInfo = {0,};
 
                langInfo.bSingleShift = false;
                langInfo.bLockingShift = false;
 
-               textCvt.convertGSM7bitToUTF8((unsigned char*)pAddress->address, MAX_ADDRESS_LEN, (unsigned char*)tmpAddress, tmplength, &langInfo);
+               textCvt->convertGSM7bitToUTF8((unsigned char*)pAddress->address, MAX_ADDRESS_LEN, (unsigned char*)tmpAddress, tmplength, &langInfo);
 
                if (tmpAddress)
                        delete[] tmpAddress;
        }
        else if (pAddress->ton == SMS_TON_INTERNATIONAL)
        {
-               (pAddress->address)[0] = '+';
                convertBcdToDigit(&(pTpdu[offset]), bcdLen, &((pAddress->address)[1]));
+               if (pAddress->address[1] != '\0')
+                       pAddress->address[0] = '+';
        }
        else
        {
@@ -527,3 +528,25 @@ int SmsPluginParamCodec::convertBcdToDigit(const unsigned char *pBcd, int BcdLen
        return offset;
 }
 
+bool SmsPluginParamCodec::checkCphsVmiMsg(const unsigned char *pTpdu, int *setType, int *indType)
+{
+       bool ret = false;
+
+       int offset = 0;
+       int addrLen = 0;
+
+       addrLen = (int)pTpdu[offset++];
+
+       if (addrLen == 0x04 && pTpdu[offset++] == 0xD0) {
+               if (pTpdu[offset] == 0x11 || pTpdu[offset] == 0x10) {
+                       MSG_DEBUG("####### VMI msg ######");
+                       *setType = (int)(pTpdu[offset] & 0x01); // 0 : clear, 1 : set
+
+                       *indType = (int)(pTpdu[offset+1] & 0x01); // 0 : indicator 1, 1 : indicator 2
+
+                       ret = true;
+               }
+       }
+
+       return ret;
+}
index 3233684..bed98d6 100755 (executable)
@@ -1,30 +1,35 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
+#include <errno.h>
 #include "MsgDebug.h"
 #include "MsgCppTypes.h"
 #include "MsgException.h"
 #include "MsgGconfWrapper.h"
+#include "MsgNotificationWrapper.h"
+#include "MsgUtilStorage.h"
 #include "SmsPluginParamCodec.h"
 #include "SmsPluginUDCodec.h"
+#include "SmsPluginTpduCodec.h"
 #include "SmsPluginSetting.h"
 #include "SmsPluginTransport.h"
 #include "SmsPluginCallback.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginSatHandler.h"
+#include "SmsPluginDSHandler.h"
 
 extern "C"
 {
@@ -35,7 +40,6 @@ extern "C"
        #include <ITapiSat.h>
 }
 
-extern struct tapi_handle *pTapiHandle;
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
 ==================================================================================================*/
@@ -46,7 +50,6 @@ SmsPluginSatHandler::SmsPluginSatHandler()
 {
        commandId = 0;
 
-       bSendSms = false;
        bInitSim = false;
        bSMSPChanged = false;
        bCBMIChanged = false;
@@ -68,7 +71,7 @@ SmsPluginSatHandler* SmsPluginSatHandler::instance()
 }
 
 
-void SmsPluginSatHandler::refreshSms(void *pData)
+void SmsPluginSatHandler::refreshSms(struct tapi_handle *handle, void *pData)
 {
        /*
        TelSatRefreshInd_t* pRefreshData = (TelSatRefreshInd_t*)pData;
@@ -135,12 +138,10 @@ void SmsPluginSatHandler::refreshSms(void *pData)
 }
 
 
-void SmsPluginSatHandler::sendSms(void *pData)
+void SmsPluginSatHandler::sendSms(struct tapi_handle *handle, void *pData)
 {
        TelSatSendSmsIndSmsData_t* pSmsData = (TelSatSendSmsIndSmsData_t*)pData;
 
-       bSendSms = true;
-
        commandId = pSmsData->commandId;
 
        MSG_DEBUG("commandId [%d]", commandId);
@@ -156,9 +157,16 @@ void SmsPluginSatHandler::sendSms(void *pData)
        // Modify Parameters, Pack User Data
        tpduLen = handleSatTpdu(tpdu, pSmsData->smsTpdu.dataLen, pSmsData->bIsPackingRequired);
 
-       if (tpduLen <= 0 || tpduLen > MAX_TPDU_DATA_LEN)
-       {
-               sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
+       if (tpduLen <= 0) {
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
+               return;
+       } //else if (tpduLen > MAX_TPDU_DATA_LEN) {
+       else if (tpduLen > MAX_SAT_TPDU_LEN) {  //CID 358478: replacing check against MAX_TPDU_DATA_LEN (255) with check
+                                                                                       //                      against MAX_SAT_TPDU_LEN (175).
+                                                                                       //                      as mentioned above "The TPDU Maximum Length at SAT side is 175".
+                                                                                       //                      Earlier MAX_TPDU_DATA_LEN was increased from 165 to 255 which creates confusion for prevent tool.
+                                                                                       //                      Prevent tool thinks that it can take value of 255 and cause buffer overflow during memcpy below.
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
                return;
        }
 
@@ -169,31 +177,32 @@ void SmsPluginSatHandler::sendSms(void *pData)
        memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData));
        memcpy((void*)pkgInfo.szData, tpdu, tpduLen);
 
-       pkgInfo.szData[tpduLen - 1] = '\0';
+       pkgInfo.szData[tpduLen] = '\0';
        pkgInfo.MsgLength = tpduLen;
 
        // Set SMSC Address
-       SMS_ADDRESS_S smsc;
+       SMS_ADDRESS_S smsc = {0,};
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
 
        if (pSmsData->address.diallingNumberLen > 0)
        {
                smsc.ton = pSmsData->address.ton;
                smsc.npi = pSmsData->address.npi;
-               memcpy(smsc.address, pSmsData->address.diallingNumber, pSmsData->address.diallingNumberLen);
-               smsc.address[pSmsData->address.diallingNumberLen] = '\0';
+               snprintf(smsc.address, sizeof(smsc.address), "%s", pSmsData->address.diallingNumber);
 
-               MSG_DEBUG("SCA TON[%d], NPI[%d], LEN[%d], ADDR[%s]", smsc.ton, smsc.npi, strlen(smsc.address), smsc.address);
+               MSG_SEC_DEBUG("SCA TON[%d], NPI[%d], LEN[%d], ADDR[%s]", smsc.ton, smsc.npi, strlen(smsc.address), smsc.address);
        }
        else
        {
                // Set SMSC Options
-               SmsPluginTransport::instance()->setSmscOptions(&smsc);
+               SmsPluginTransport::instance()->setSmscOptions(simIndex, &smsc);
        }
 
        unsigned char smscAddr[MAX_SMSC_LEN];
-       memset(smscAddr, 0x00, sizeof(smscAddr));
+       int smscLen = 0;
 
-       int smscLen = SmsPluginParamCodec::encodeSMSC(&smsc, smscAddr);
+       memset(smscAddr, 0x00, sizeof(smscAddr));
+       smscLen = SmsPluginParamCodec::encodeSMSC(&smsc, smscAddr);
 
        if (smscLen <= 0) return;
 
@@ -205,24 +214,45 @@ void SmsPluginSatHandler::sendSms(void *pData)
        int tapiRet = TAPI_API_SUCCESS;
 
        // Send SMS
-       tapiRet = tel_send_sms(pTapiHandle, &pkgInfo, 0, TapiEventSentStatus, NULL);
+       tapiRet = tel_send_sms(handle, &pkgInfo, 0, TapiEventSatSmsSentStatus, NULL);
 
        if (tapiRet == TAPI_API_SUCCESS)
        {
                MSG_DEBUG("########  TelTapiSmsSend Success !!! return : %d #######", tapiRet);
+
        }
        else
        {
                MSG_DEBUG("########  TelTapiSmsSend Fail !!! return : %d #######", tapiRet);
-               sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
        }
 }
 
 
-void SmsPluginSatHandler::ctrlSms(void *pData)
+void SmsPluginSatHandler::ctrlSms(struct tapi_handle *handle, void *pData)
 {
+       if (!pData) {
+               MSG_DEBUG("pData is NULL");
+               return;
+       }
+
        TelSatMoSmCtrlIndData_t* pCtrlData = (TelSatMoSmCtrlIndData_t*)pData;
 
+#if 0 // sangkoo 13.11.28
+       if (bSendSmsbySat == true) {// Send SMS By SAT
+               MSG_DEBUG("Event Noti for sending message by SAT : result = [%d]", pCtrlData->moSmsCtrlResult);
+       } else { // Send SMS By APP
+               SmsPluginTransport::instance()->setMoCtrlStatus(pCtrlData);
+       }
+#else
+       if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED) {
+               MsgInsertTicker("Sending message failed : blocked by call control", NULL, true, 0);
+       }
+#endif
+
+       return;
+
+#if 0
        if (bSendSms == true) // Send SMS By SAT
        {
                if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED)
@@ -258,29 +288,38 @@ void SmsPluginSatHandler::ctrlSms(void *pData)
                // Call Event Handler
                SmsPluginEventHandler::instance()->handleSentStatus(netStatus);
        }
+#endif
 }
 
 
-void SmsPluginSatHandler::ctrlSms(msg_network_status_t netStatus)
+void SmsPluginSatHandler::ctrlSms(struct tapi_handle *handle, SMS_NETWORK_STATUS_T smsStatus)
 {
-       if (bSendSms == true) // Send SMS By SAT
-       {
-               if (netStatus == MSG_NETWORK_SEND_SUCCESS)
-               {
-                       MSG_DEBUG("Sending SMS by SAT is OK");
-
-                       sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
-               }
-               else if (netStatus == MSG_NETWORK_SEND_FAIL)
-               {
-                       MSG_DEBUG("Sending SMS by SAT is failed");
+       MSG_DEBUG("SMS network status = [%d]", smsStatus);
+
+       if (smsStatus == SMS_NETWORK_SEND_SUCCESS) {
+               MSG_DEBUG("Sending SMS by SAT is OK");
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
+       } else if (smsStatus == SMS_NETWORK_SEND_FAIL) {
+               MSG_ERR("Sending SMS by SAT is failed");
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SMS_RP_ERROR);
+       } else if (smsStatus == SMS_NETWORK_SEND_FAIL_MANDATORY_INFO_MISSING){
+               MSG_ERR("Sending SMS by SAT is failed, but result is 'success'");
+               //sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_ERROR_REQUIRED_VALUES_ARE_MISSING);
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
+       } else if (smsStatus == SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED){
+               MSG_ERR("Sending SMS is failed by MO control");
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_INTRCTN_WITH_CC_OR_SMS_CTRL_PRMNT_PRBLM);
+       } else { /*Default case*/
+               MSG_ERR("Sending SMS by SAT is failed");
+               sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SMS_RP_ERROR);
+       }
 
-                       sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SMS_RP_ERROR);
-               }
+       if (smsStatus != SMS_NETWORK_SEND_SUCCESS) {
+               MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL, true, 0);
        }
 }
 
-
+#if 0
 void SmsPluginSatHandler::finishSimMsgInit(msg_error_t Err)
 {
        // SAT Handler is initializing SIM now
@@ -351,11 +390,11 @@ void      SmsPluginSatHandler::initSMSCList()
                MSG_DEBUG("pid[%d]", settingData.option.smscList.smscData[i].pid);
 //             MSG_DEBUG("dcs[%d]", settingData.option.smscList.smscData[i].dcs);
                MSG_DEBUG("val_period[%d]", settingData.option.smscList.smscData[i].valPeriod);
-               MSG_DEBUG("name[%s]", settingData.option.smscList.smscData[i].name);
+               MSG_SEC_DEBUG("name[%s]", settingData.option.smscList.smscData[i].name);
 
                MSG_DEBUG("ton[%d]", settingData.option.smscList.smscData[i].smscAddr.ton);
                MSG_DEBUG("npi[%d]", settingData.option.smscList.smscData[i].smscAddr.npi);
-               MSG_DEBUG("address[%s]", settingData.option.smscList.smscData[i].smscAddr.address);
+               MSG_SEC_DEBUG("address[%s]", settingData.option.smscList.smscData[i].smscAddr.address);
        }
 
        if (MsgSettingSetInt(SMSC_SELECTED, settingData.option.smscList.selected) != MSG_SUCCESS)
@@ -370,51 +409,51 @@ void      SmsPluginSatHandler::initSMSCList()
                return;
        }
 
-       char keyName[128];
+       char keyName[MAX_VCONFKEY_NAME_LEN];
        msg_error_t err = MSG_SUCCESS;
 
        for (int i = 0; i < settingData.option.smscList.totalCnt; i++)
        {
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_PID, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_PID, i);
 
                if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].pid)) != MSG_SUCCESS)
                        break;
 
 #if 0
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_DCS, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_DCS, i);
 
                if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].dcs)) != MSG_SUCCESS)
                        break;
 #endif
 
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_VAL_PERIOD, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_VAL_PERIOD, i);
 
                if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].valPeriod)) != MSG_SUCCESS)
                        break;
 
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_NAME, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_NAME, i);
 
                if ((err = MsgSettingSetString(keyName, settingData.option.smscList.smscData[i].name)) != MSG_SUCCESS)
                        break;
 
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_TON, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_TON, i);
 
                if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].smscAddr.ton)) != MSG_SUCCESS)
                        break;
 
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_NPI, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_NPI, i);
 
                if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].smscAddr.npi)) != MSG_SUCCESS)
                        break;
 
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_ADDRESS, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_ADDRESS, i);
 
                if ((err = MsgSettingSetString(keyName, settingData.option.smscList.smscData[i].smscAddr.address)) != MSG_SUCCESS)
                        break;
@@ -431,6 +470,9 @@ void        SmsPluginSatHandler::initCBConfig()
 {
        MSG_SETTING_S settingData;
 
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
+
        settingData.type = MSG_CBMSG_OPT;
 
        // Get Data From SIM
@@ -448,48 +490,15 @@ void      SmsPluginSatHandler::initCBConfig()
                return;
        }
 
-       if (MsgSettingSetInt(CB_CHANNEL_COUNT, settingData.option.cbMsgOpt.channelData.channelCnt) != MSG_SUCCESS)
-       {
-               THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_CHANNEL_COUNT);
-               return;
-       }
-
-       char keyName[128];
-       msg_error_t err = MSG_SUCCESS;
-
-       for (int i = 0; i < settingData.option.cbMsgOpt.channelData.channelCnt; i++)
-       {
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
-
-               if ((err = MsgSettingSetBool(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].bActivate)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
-
-               if ((err = MsgSettingSetInt(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].from)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
-
-               if ((err = MsgSettingSetInt(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].to)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
-
-               if ((err = MsgSettingSetString(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].name)) != MSG_SUCCESS)
-                       break;
-       }
+       err = MsgStoAddCBChannelInfo(dbHandle, &(settingData.option.cbMsgOpt.channelData), settingData.option.cbMsgOpt.simIndex);
+       MSG_DEBUG("MsgStoAddCBChannelInfo : err=[%d]", err);
 
        if (err != MSG_SUCCESS)
        {
-               THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", keyName);
+               THROW(MsgException::SMS_PLG_ERROR, "Error to set config data");
        }
 }
-
+#endif
 
 int SmsPluginSatHandler::handleSatTpdu(unsigned char *pTpdu, unsigned char TpduLen, int bIsPackingRequired)
 {
@@ -582,9 +591,10 @@ MSG_DEBUG("user data : [%s]", userData.data);
 }
 
 
-void SmsPluginSatHandler::sendResult(SMS_SAT_CMD_TYPE_T CmdType, int ResultType)
+void SmsPluginSatHandler::sendResult(struct tapi_handle *handle, SMS_SAT_CMD_TYPE_T CmdType, int ResultType)
 {
        TelSatAppsRetInfo_t satRetInfo;
+       memset(&satRetInfo, 0, sizeof(TelSatAppsRetInfo_t));
 
        satRetInfo.commandId = commandId;
 
@@ -606,7 +616,7 @@ void SmsPluginSatHandler::sendResult(SMS_SAT_CMD_TYPE_T CmdType, int ResultType)
 
        int tapiRet = TAPI_API_SUCCESS;
 
-       tapiRet = tel_send_sat_app_exec_result(pTapiHandle, &satRetInfo);
+       tapiRet = tel_send_sat_app_exec_result(handle, &satRetInfo);
 
        if (tapiRet == TAPI_API_SUCCESS)
        {
@@ -617,9 +627,7 @@ void SmsPluginSatHandler::sendResult(SMS_SAT_CMD_TYPE_T CmdType, int ResultType)
                MSG_DEBUG("TelTapiSatSendAppExecutionResult() FAIL [%d]", tapiRet);
        }
 
-       bSendSms = false;
        bInitSim = false;
        bSMSPChanged = false;
        bCBMIChanged = false;
 }
-
index 77542c2..efa3890 100755 (executable)
@@ -1,31 +1,40 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
+#include <pthread.h>
 
 #include "MsgDebug.h"
+#include "MsgCppTypes.h"
 #include "MsgException.h"
 #include "MsgGconfWrapper.h"
 #include "MsgNotificationWrapper.h"
 #include "MsgSoundPlayer.h"
+#include "MsgContact.h"
+#include "MsgUtilStorage.h"
+#include "MsgTextConvert.h"
+#include "MsgDevicedWrapper.h"
 
 #include "SmsPluginParamCodec.h"
 #include "SmsPluginCallback.h"
+#include "SmsPluginEventHandler.h"
+#include "SmsPluginSimMsg.h"
+#include "SmsPluginMain.h"
 #include "SmsPluginSetting.h"
-
+#include "SmsPluginDSHandler.h"
 
 extern "C"
 {
@@ -34,12 +43,16 @@ extern "C"
        #include <TapiUtility.h>
        #include <ITapiNetText.h>
        #include <ITapiSim.h>
+       #include <ITapiModem.h>
 }
 
-extern struct tapi_handle *pTapiHandle;
+/*==================================================================================================
+                                  INTERNAL FUNCTION
+==================================================================================================*/
+
 
 /*==================================================================================================
-                                     IMPLEMENTATION OF SmsPluginSetting - Member Functions
+                   IMPLEMENTATION OF SmsPluginSetting - Member Functions
 ==================================================================================================*/
 SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
 
@@ -47,13 +60,20 @@ SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
 SmsPluginSetting::SmsPluginSetting()
 {
        // Initialize member variables
-       memset(&smscData, 0x00, sizeof(MSG_SMSC_DATA_S));
-       memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
-       memset(&simMailboxList, 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
+       for (int i = 0; i <= MAX_TELEPHONY_HANDLE_CNT; i++) {
+               memset(&smscList[i], 0x00, sizeof(MSG_SMSC_LIST_S));
+               memset(&smscData[i], 0x00, sizeof(MSG_SMSC_DATA_S));
+               memset(&cbOpt[i], 0x00, sizeof(MSG_CBMSG_OPT_S));
+               memset(&simMailboxList[i], 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
+               memset(&simMwiInfo[i], 0x00, sizeof(SMS_SIM_MWI_INFO_S));
+               simStatus[i] = MSG_SIM_STATUS_NOT_FOUND;
+       }
+       memset(&meImei, 0x00, sizeof(meImei));
 
        bTapiResult = false;
        paramCnt = 0;
        selectedParam = 0;
+       bMbdnEnable = true;
 }
 
 
@@ -73,26 +93,132 @@ SmsPluginSetting* SmsPluginSetting::instance()
 }
 
 
-void SmsPluginSetting::initConfigData(MSG_SIM_STATUS_T SimStatus)
+void* SmsPluginSetting::initSimInfo(void *data)
+{
+       static Mutex mm;
+       MutexLocker lock(mm);
+
+       SmsPluginSetting::instance()->processInitSimInfo(data);
+
+       return NULL;
+}
+
+void* SmsPluginSetting::processInitSimInfo(void *data)
+{
+       MSG_BEGIN();
+
+       //Handle sim info initialization separately
+       struct tapi_handle *handle = (struct tapi_handle *)data;
+       instance()->updateSimStatus(handle);
+
+       MSG_END();
+       return NULL;
+}
+
+
+void SmsPluginSetting::updateSimStatus(struct tapi_handle *handle)
+{
+       MSG_BEGIN();
+
+       if (!handle) {
+               MSG_DEBUG("handle is NULL.");
+               return;
+       }
+
+       int status = 0;
+       int tapiRet = TAPI_API_SUCCESS;
+
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       // Get IMSI
+       char imsi[17];
+       memset(imsi, 0x00, sizeof(imsi));
+
+       TelSimImsiInfo_t imsiInfo;
+       memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
+
+       tapiRet = tel_get_sim_imsi(handle, &imsiInfo);
+
+       if (tapiRet == TAPI_API_SUCCESS) {
+               MSG_SEC_DEBUG("tel_get_sim_imsi() Success - MCC [%s], MNC [%s], MSIN [%s]", imsiInfo.szMcc, imsiInfo.szMnc, imsiInfo.szMsin);
+
+               snprintf(imsi, sizeof(imsi), "%03d%03d%s", atoi(imsiInfo.szMcc), atoi(imsiInfo.szMnc), imsiInfo.szMsin);
+               MSG_SEC_DEBUG("IMSI [%s]", imsi);
+       } else {
+               MSG_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
+               snprintf(keyName, sizeof(keyName), "%s/%d", MSG_NATIONAL_SIM, simIndex);
+               MsgSettingSetBool(keyName, false);
+       }
+
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_IMSI, simIndex);
+       MsgSettingSetString(keyName, imsi);
+       tapiRet = tel_check_sms_device_status(handle, &status);
+
+       if (tapiRet != TAPI_API_SUCCESS) {
+               MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
+               return;
+       }
+
+       if (status == 1) {
+               MSG_DEBUG("Device Is Ready");
+       } else if (status == 0) {
+               MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
+
+               if (SmsPluginEventHandler::instance()->getDeviceStatus(handle) == true) {
+                       MSG_DEBUG("Device Is Ready");
+               } else {
+                       MSG_DEBUG("Device Is Not Ready.");
+                       return;
+               }
+       }
+
+       // init config data.
+       initConfigData(handle);
+
+       try
+       {
+               // init sim messages.
+               SmsPluginSimMsg::instance()->initSimMessage(handle);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
+
+
+       MSG_END();
+
+       return;
+}
+
+
+void SmsPluginSetting::initConfigData(struct tapi_handle *handle)
 {
        MSG_BEGIN();
 
        msg_error_t     err = MSG_SUCCESS;
 
+       int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
+       /*==================== SMSC setting ====================*/
        // Init SMS Parameter
        int paramCnt = 0;
        int failCnt = 0;
 
-       paramCnt = getParamCount();
+       paramCnt = getParamCount(handle);
 
-       MSG_DEBUG("Parameter Count [%d]", paramCnt);
+       MSG_INFO("Parameter Count [%d]", paramCnt);
 
        MSG_SMSC_DATA_S tmpSmscData = {};
-       MSG_SMSC_LIST_S tmpSmscList = {};
+       MSG_SMSC_LIST_S tmpSmscList = {0,};
 
        for (int index = 0; index < paramCnt; index++)
        {
-               if (getParam(index, &tmpSmscData) == false) {
+               memset(&tmpSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
+               if (getParam(handle, index, &tmpSmscData) == false) {
                        failCnt++;
                        continue;
                }
@@ -101,75 +227,123 @@ void SmsPluginSetting::initConfigData(MSG_SIM_STATUS_T SimStatus)
 
                MSG_DEBUG("pid[%d]", tmpSmscList.smscData[index].pid);
                MSG_DEBUG("val_period[%d]", tmpSmscList.smscData[index].valPeriod);
-               MSG_DEBUG("name[%s]", tmpSmscList.smscData[index].name);
+               MSG_SEC_DEBUG("name[%s]", tmpSmscList.smscData[index].name);
 
                MSG_DEBUG("ton[%d]", tmpSmscList.smscData[index].smscAddr.ton);
                MSG_DEBUG("npi[%d]", tmpSmscList.smscData[index].smscAddr.npi);
-               MSG_DEBUG("address[%s]", tmpSmscList.smscData[index].smscAddr.address);
+               MSG_SEC_DEBUG("address[%s]", tmpSmscList.smscData[index].smscAddr.address);
        }
 
        tmpSmscList.totalCnt = (paramCnt - failCnt);
+       tmpSmscList.simIndex = sim_idx;
+
 //     below is commented to be the first smsc is selected.
 //     tmpSmscList.selected = selectedParam;
 
        if (paramCnt > 0) {
-               err = addSMSCList(&tmpSmscList);
-
-               if (err == MSG_SUCCESS) {
-                       MSG_DEBUG("########  Add SMSC List Success !!! #######");
-               } else {
-                       MSG_DEBUG("########  Add SMSC List Fail !!! return : %d #######", err);
-               }
+               MSG_DEBUG("########  Add SMSC ist #######");
+               addSMSCList(&tmpSmscList);
        }
 
-       // Init CB Config
-       if (SimStatus == MSG_SIM_STATUS_CHANGED) {
-               MSG_DEBUG("simStatus == MSG_SIM_STATUS_CHANGED");
+       /*==================== CB configuration ====================*/
+       if (simStatus[sim_idx] != MSG_SIM_STATUS_NOT_FOUND)
+       {
+               MSG_DEBUG("simStatus == [%d]", simStatus[sim_idx]);
 
-               MSG_CBMSG_OPT_S cbMsgOpt = {};
+               MSG_CBMSG_OPT_S cbMsgOpt = {0,};
+               cbMsgOpt.simIndex = sim_idx;
 
                if (getCbConfig(&cbMsgOpt) == true) {
+                       cbMsgOpt.simIndex = sim_idx;
                        err = addCbOpt(&cbMsgOpt);
 
                        if (err == MSG_SUCCESS) {
                                MSG_DEBUG("########  Add CB Option Success !!! #######");
+                               MSG_SETTING_S cbSetting;
+                               getCbOpt(&cbSetting, sim_idx);
+                               setCbConfig(&(cbSetting.option.cbMsgOpt));
                        } else {
                                MSG_DEBUG("########  Add CB Option Fail !!! return : %d #######", err);
                        }
+               } else {
+                       MSG_DEBUG("########  getCbConfig Fail !!! #######");
+
+#if 0
+                       // CSC doesn't support CB Info any longer
+                       if (MsgCscGetCBInfo(&cbMsgOpt) == true) {
+                               err = addCbOpt(&cbMsgOpt);
+
+                               if (err == MSG_SUCCESS) {
+                                       MSG_DEBUG("########  Add CB Option From CSC Success !!! #######");
+                               } else {
+                                       MSG_DEBUG("########  Add CB Option from CSC Fail !!! return : %d #######", err);
+                               }
+                       } else {
+                               MSG_DEBUG("########  MsgCscGetCBInfo Fail !!! #######");
+                       }
+#endif
                }
-       } else if (SimStatus == MSG_SIM_STATUS_NORMAL) {
-               MSG_DEBUG("simStatus == MSG_SIM_STATUS_NORMAL");
 
-               // Set CB Data into SIM in case of same SIM
-               MSG_SETTING_S cbSetting;
-               cbSetting.type = MSG_CBMSG_OPT;
+               /*==================== Default Voice mail Setting ====================*/
+               if (simStatus[sim_idx] == MSG_SIM_STATUS_CHANGED) {
+                       char keyName[MAX_VCONFKEY_NAME_LEN];
 
-               getCbOpt(&cbSetting);
+                       MSG_DEBUG("=================SIM CHANGED===================");
 
-               setCbConfig(&(cbSetting.option.cbMsgOpt));
-       }
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
+                       if (MsgSettingSetString(keyName, VOICEMAIL_DEFAULT_NUMBER) != MSG_SUCCESS)
+                               MSG_DEBUG("MsgSettingSetString is failed!!");
 
-       if (SimStatus != MSG_SIM_STATUS_NOT_FOUND)
-       {
-               MSG_VOICEMAIL_OPT_S tmpVoiceMail;
-               memset(&tmpVoiceMail, 0x00, sizeof(MSG_VOICEMAIL_OPT_S));
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, sim_idx);
+                       if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS)
+                               MSG_DEBUG("MsgSettingSetInt is failed!!");
 
-               if (getVoiceMailInfo(&tmpVoiceMail) == true) {
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, sim_idx);
+                       if (MsgSettingSetString(keyName, VOICEMAIL_DEFAULT_ALPHA_ID) != MSG_SUCCESS)
+                               MSG_DEBUG("MsgSettingSetString is failed!!");
+
+                       MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_1);
+                       MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_2);
+               }
+
+
+               /*==================== Voice mail information update ====================*/
+               if (getVoiceMailInfo(handle) == true) {
                        MSG_DEBUG("########  getVoiceMailInfo Success !!! #######");
                } else {
-                       MSG_DEBUG("########  getVoiceMailInfo Fail !!! #######");
+                       MSG_WARN("########  getVoiceMailInfo Fail !!! #######");
                }
 
-               if (getMwiInfo() == true) {
+               /*==================== Voice mail count update ====================*/
+               if (getMwiInfo(handle) == true) {
                        MSG_DEBUG("########  getMwiInfo Success !!! #######");
                } else {
-                       MSG_DEBUG("########  getMwiInfo Fail !!! #######");
+                       MSG_WARN("########  getMwiInfo Fail !!! #######");
+
+                       // Get MWI from vconf and insert notification
+                       int mwiCnt = 0;
+                       char keyName[MAX_VCONFKEY_NAME_LEN];
+                       memset(keyName, 0x00, sizeof(keyName));
+                       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, sim_idx);
+                       if ((mwiCnt = MsgSettingGetInt(keyName)) > 0)
+                               deliverVoiceMsgNoti(sim_idx, mwiCnt);
                }
 
-               if (getMsisdnInfo() == true) {
+               /*==================== MSISDN update ====================*/
+               if (getMsisdnInfo(handle) == true) {
                        MSG_DEBUG("########  getMsisdnInfo Success !!! #######");
                } else {
-                       MSG_DEBUG("########  getMsisdnInfo Fail !!! #######");
+                       MSG_WARN("########  getMsisdnInfo Fail !!! #######");
+               }
+
+               /*==================== SST(SIM Service Table) update ====================*/
+               if (getSimServiceTable(handle) == true) {
+                       MSG_DEBUG("########  getSimServiceTable Success !!! #######");
+               } else {
+                       MSG_WARN("########  getSimServiceTable Fail !!! #######");
                }
        }
 
@@ -177,6 +351,28 @@ void SmsPluginSetting::initConfigData(MSG_SIM_STATUS_T SimStatus)
 }
 
 
+void SmsPluginSetting::SimRefreshCb(struct tapi_handle *handle)
+{
+       pthread_t thd;
+
+       if(pthread_create(&thd, NULL, &init_config_data, handle) < 0) {
+               MSG_DEBUG("pthread_create() error");
+       }
+
+       pthread_detach(thd);
+
+}
+
+
+void* SmsPluginSetting::init_config_data(void *data)
+{
+       struct tapi_handle *handle = (struct tapi_handle *)data;
+
+       instance()->initConfigData(handle);
+       return NULL;
+}
+
+
 void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
 {
        MSG_DEBUG("Setting Type : [%d]", pSetting->type);
@@ -190,6 +386,8 @@ void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
 #endif
                case MSG_SMSC_LIST :
                        setParamList(&pSetting->option.smscList);
+                       addSMSCList((MSG_SMSC_LIST_S *)(&pSetting->option.smscList));
+//                     setSmscInfo(&pSetting->option.smscList);
                        break;
                case MSG_CBMSG_OPT :
                        setCbConfig(&pSetting->option.cbMsgOpt);
@@ -211,7 +409,8 @@ void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
        switch (pSetting->type)
        {
                case MSG_SMSC_LIST :
-                       getParamList(&pSetting->option.smscList);
+//                     getParamList(&pSetting->option.smscList);
+                       getSmscListInfo(pSetting->option.smscList.simIndex, &(pSetting->option.smscList));
                break;
 
                case MSG_CBMSG_OPT :
@@ -225,10 +424,13 @@ void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
 }
 
 
-msg_error_t SmsPluginSetting::addSMSCList(MSG_SMSC_LIST_S *pSmscList)
+void SmsPluginSetting::addSMSCList(MSG_SMSC_LIST_S *pSmscList)
 {
-       msg_error_t err = MSG_SUCCESS;
+       MSG_BEGIN();
 
+       int sim_index = -1;
+
+       MSG_DEBUG("SIM index[%d]", pSmscList->simIndex);
        MSG_DEBUG("total_count[%d]", pSmscList->totalCnt);
        MSG_DEBUG("selected index[%d]", pSmscList->selected);
 
@@ -236,75 +438,60 @@ msg_error_t SmsPluginSetting::addSMSCList(MSG_SMSC_LIST_S *pSmscList)
        {
                MSG_DEBUG("pid[%d]", pSmscList->smscData[i].pid);
                MSG_DEBUG("val_period[%d]", pSmscList->smscData[i].valPeriod);
-               MSG_DEBUG("name[%s]", pSmscList->smscData[i].name);
+               MSG_SEC_DEBUG("name[%s]", pSmscList->smscData[i].name);
 
                MSG_DEBUG("ton[%d]", pSmscList->smscData[i].smscAddr.ton);
                MSG_DEBUG("npi[%d]", pSmscList->smscData[i].smscAddr.npi);
-               MSG_DEBUG("address[%s]", pSmscList->smscData[i].smscAddr.address);
+               MSG_SEC_DEBUG("address[%s]", pSmscList->smscData[i].smscAddr.address);
        }
 
-       char keyName[128];
+       sim_index = pSmscList->simIndex;
 
-       if (MsgSettingSetInt(SMSC_TOTAL_COUNT, pSmscList->totalCnt) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", SMSC_TOTAL_COUNT);
-               return MSG_ERR_SET_SETTING;
-       }
-
-       if (MsgSettingSetInt(SMSC_SELECTED, pSmscList->selected) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", SMSC_SELECTED);
-               return MSG_ERR_SET_SETTING;
-       }
+       smscList[sim_index].simIndex = pSmscList->simIndex;
+       smscList[sim_index].totalCnt = pSmscList->totalCnt;
+       smscList[sim_index].selected = pSmscList->selected;
 
        for (int i = 0; i < pSmscList->totalCnt; i++) {
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_PID, i);
 
-               if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].pid)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_VAL_PERIOD, i);
-
-               if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].valPeriod)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_NAME, i);
+               smscList[sim_index].smscData[i].pid = pSmscList->smscData[i].pid;
+               smscList[sim_index].smscData[i].valPeriod = pSmscList->smscData[i].valPeriod;
 
-               if ((err = MsgSettingSetString(keyName, pSmscList->smscData[i].name)) != MSG_SUCCESS)
-                       break;
+               memset(smscList[sim_index].smscData[i].name, 0x00, SMSC_NAME_MAX+1);
+               memcpy(smscList[sim_index].smscData[i].name, pSmscList->smscData[i].name, SMSC_NAME_MAX);
 
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_TON, i);
+               memset(smscList[sim_index].smscData[i].smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
+               memcpy(smscList[sim_index].smscData[i].smscAddr.address, pSmscList->smscData[i].smscAddr.address, SMSC_ADDR_MAX);
 
                if (pSmscList->smscData[i].smscAddr.address[0] == '+')
-                       pSmscList->smscData[i].smscAddr.ton = MSG_TON_INTERNATIONAL;
+                       smscList[sim_index].smscData[i].smscAddr.ton = MSG_TON_INTERNATIONAL;
                else
-                       pSmscList->smscData[i].smscAddr.ton = MSG_TON_NATIONAL;
-
-               if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].smscAddr.ton)) != MSG_SUCCESS)
-                       break;
+                       smscList[sim_index].smscData[i].smscAddr.ton = MSG_TON_NATIONAL;
 
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_NPI, i);
-
-               pSmscList->smscData[i].smscAddr.npi = MSG_NPI_ISDN; // app cannot set this value
+               smscList[sim_index].smscData[i].smscAddr.npi = MSG_NPI_ISDN; // app cannot set this value
+       }
 
-               if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].smscAddr.npi)) != MSG_SUCCESS)
-                       break;
+       MSG_END();
+}
 
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", SMSC_ADDRESS, i);
 
-               if ((err = MsgSettingSetString(keyName, pSmscList->smscData[i].smscAddr.address)) != MSG_SUCCESS)
-                       break;
+void SmsPluginSetting::getSmscListInfo(int simIndex, MSG_SMSC_LIST_S *pSmscList)
+{
+       if (pSmscList == NULL) {
+               MSG_DEBUG("pSmscList is NULL!");
+               return;
        }
 
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", keyName);
+       if (simIndex <= 0) {
+               struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
+               simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
        }
 
-       return err;
+       if (simIndex == -1)
+               memset(pSmscList, 0x00, sizeof(MSG_SMSC_LIST_S));
+       else
+               memcpy(pSmscList, &smscList[simIndex], sizeof(MSG_SMSC_LIST_S));
+
+       return;
 }
 
 
@@ -321,99 +508,62 @@ msg_error_t SmsPluginSetting::addCbOpt(MSG_CBMSG_OPT_S *pCbOpt)
                MSG_DEBUG("Channel FROM [%d], Channel TO [%d]", pCbOpt->channelData.channelInfo[i].from, pCbOpt->channelData.channelInfo[i].to);
        }
 
+#if 0
        // Set Setting Data into Vconf
        if (MsgSettingSetBool(CB_RECEIVE, pCbOpt->bReceive) != MSG_SUCCESS) {
                MSG_DEBUG("Error to set config data [%s]", CB_RECEIVE);
                return MSG_ERR_SET_SETTING;
        }
+#endif
 
-       if (MsgSettingSetInt(CB_MAX_SIM_COUNT, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", CB_MAX_SIM_COUNT);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, pCbOpt->simIndex);
+       if (MsgSettingSetInt(keyName, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
+               MSG_DEBUG("Error to set config data [%s]", keyName);
                return MSG_ERR_SET_SETTING;
        }
 
-       if (MsgSettingSetInt(CB_CHANNEL_COUNT, pCbOpt->channelData.channelCnt) != MSG_SUCCESS) {
-               MSG_DEBUG("Error to set config data [%s]", CB_CHANNEL_COUNT);
+#if 0
+       MsgDbHandler *dbHandle = getDbHandle();
+       err = MsgStoAddCBChannelInfo(dbHandle, &pCbOpt->channelData);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("MsgStoGetCBChannelInfo is failed [%d]", err);
                return MSG_ERR_SET_SETTING;
        }
-
-       char keyName[128];
-
-       for (int i = 0; i < pCbOpt->channelData.channelCnt; i++) {
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
-
-               if ((err = MsgSettingSetBool(keyName, pCbOpt->channelData.channelInfo[i].bActivate)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
-
-               if ((err = MsgSettingSetInt(keyName, pCbOpt->channelData.channelInfo[i].from)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
-
-               if ((err = MsgSettingSetInt(keyName, pCbOpt->channelData.channelInfo[i].to)) != MSG_SUCCESS)
-                       break;
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
-
-               if ((err = MsgSettingSetString(keyName, pCbOpt->channelData.channelInfo[i].name)) != MSG_SUCCESS)
-                       break;
-       }
+#endif
 
        return err;
 }
 
 
-void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting)
+void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting, int simIndex)
 {
-       char keyName[128];
-       char *tmpValue = NULL;
-
-       memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
-
-       MsgSettingGetBool(CB_RECEIVE, &pSetting->option.cbMsgOpt.bReceive);
-
-       pSetting->option.cbMsgOpt.maxSimCnt = MsgSettingGetInt(CB_MAX_SIM_COUNT);
-
-       pSetting->option.cbMsgOpt.channelData.channelCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
-
-       for (int i = 0; i < pSetting->option.cbMsgOpt.channelData.channelCnt; i++) {
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
 
-               MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.channelData.channelInfo[i].bActivate);
-
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
-
-               pSetting->option.cbMsgOpt.channelData.channelInfo[i].from = MsgSettingGetInt(keyName);
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler *dbHandle = getDbHandle();
 
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
+       memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
 
-               pSetting->option.cbMsgOpt.channelData.channelInfo[i].to = MsgSettingGetInt(keyName);
+       pSetting->type = MSG_CBMSG_OPT;
+       pSetting->option.cbMsgOpt.simIndex = simIndex;
 
-               memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
+//     memset(keyName, 0x00, sizeof(keyName));
+//     snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
+       MsgSettingGetBool(CB_RECEIVE, &pSetting->option.cbMsgOpt.bReceive);
 
-               tmpValue = MsgSettingGetString(keyName);
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
+       pSetting->option.cbMsgOpt.maxSimCnt = MsgSettingGetInt(keyName);
 
-               if (tmpValue != NULL)
-               {
-                       strncpy(pSetting->option.cbMsgOpt.channelData.channelInfo[i].name, tmpValue, CB_CHANNEL_NAME_MAX);
-                       free(tmpValue);
-                       tmpValue = NULL;
-               }
-       }
+       err = MsgStoGetCBChannelInfo(dbHandle, &pSetting->option.cbMsgOpt.channelData, simIndex);
+       if (err != MSG_SUCCESS)
+               MSG_ERR("MsgStoGetCBChannelInfo : err=[%d]", err);
 
        for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++) {
                memset(keyName, 0x00, sizeof(keyName));
-               sprintf(keyName, "%s/%d", CB_LANGUAGE, i);
+               snprintf(keyName, sizeof(keyName), "%s/%d", CB_LANGUAGE, i);
 
                MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bLanguage[i]);
        }
@@ -425,72 +575,78 @@ void SmsPluginSetting::setParamList(const MSG_SMSC_LIST_S *pSMSCList)
 {
        MSG_BEGIN();
 
+       MutexLocker lock(mx);
+
        TelSmsParams_t smsParam = {0};
 
        int ret = TAPI_API_SUCCESS;
 
-       for (int index = 0; index < pSMSCList->totalCnt; index++) {
-               /*Setting the SMSP Record index value*/
-               smsParam.RecordIndex = (unsigned char)index;
+       int index = pSMSCList->index;
+       MSG_DEBUG("SMSC Index to be set in SIM = %d", index);
 
-               /*Setting the SMSP Record Length value = 28 + alphaId_len*/
-               smsParam.RecordLen = 28 + strlen(pSMSCList->smscData[index].name);
+       /*Setting the SMSP Record index value*/
+       smsParam.RecordIndex = (unsigned char)index;
 
-               /*Setting the SMSP Alpha ID value*/
-               smsParam.AlphaIdLen = strlen(pSMSCList->smscData[index].name);
-               MSG_DEBUG("AlphaIdLen = %ld", smsParam.AlphaIdLen);
+       /*Setting the SMSP Record Length value = 28 + alphaId_len*/
+       smsParam.RecordLen = 28 + strlen(pSMSCList->smscData[index].name);
 
-               if (smsParam.AlphaIdLen > 0 &&  smsParam.AlphaIdLen <= SMSC_NAME_MAX) {
-                       memcpy(smsParam.szAlphaId, pSMSCList->smscData[index].name, smsParam.AlphaIdLen);
-                       smsParam.szAlphaId[smsParam.AlphaIdLen] = '\0';
-                       MSG_DEBUG("szAlphaId = %s", smsParam.szAlphaId);
-               }
+       /*Setting the SMSP Alpha ID value*/
+       smsParam.AlphaIdLen = strlen(pSMSCList->smscData[index].name);
+       MSG_DEBUG("AlphaIdLen = %ld", smsParam.AlphaIdLen);
+
+       if (smsParam.AlphaIdLen > 0 &&  smsParam.AlphaIdLen <= SMSC_NAME_MAX) {
+               memcpy(smsParam.szAlphaId, pSMSCList->smscData[index].name, smsParam.AlphaIdLen);
+               smsParam.szAlphaId[smsParam.AlphaIdLen] = '\0';
+               MSG_DEBUG("szAlphaId = %s", smsParam.szAlphaId);
+       }
 
-               smsParam.ParamIndicator = 0x00;
+       smsParam.ParamIndicator = 0x00;
 
-               if (strlen(pSMSCList->smscData[index].smscAddr.address) > 0) {
-                       smsParam.ParamIndicator |= 0x02 ;  //enable 2nd Bit
-                       MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
+       if (strlen(pSMSCList->smscData[index].smscAddr.address) > 0) {
+               smsParam.ParamIndicator |= 0x02 ;  //enable 2nd Bit
+               MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
 
-                       if (pSMSCList->smscData[index].smscAddr.address[0] == '+')
-                               smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_INTERNATIONAL;
-                       else
-                               smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_NATIONAL;
+               if (pSMSCList->smscData[index].smscAddr.address[0] == '+')
+                       smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_INTERNATIONAL;
+               else
+                       smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_NATIONAL;
 
-                       smsParam.TpSvcCntrAddr.Npi = TAPI_SIM_NPI_ISDN_TEL; // app cannot set this value
+               smsParam.TpSvcCntrAddr.Npi = TAPI_SIM_NPI_ISDN_TEL; // app cannot set this value
 
-                       MSG_DEBUG("SMSC TON = [%d] NPI = [%d]", smsParam.TpSvcCntrAddr.Ton, smsParam.TpSvcCntrAddr.Npi);
+               MSG_DEBUG("SMSC TON = [%d] NPI = [%d]", smsParam.TpSvcCntrAddr.Ton, smsParam.TpSvcCntrAddr.Npi);
 
-                       MSG_DEBUG("address = %s", pSMSCList->smscData[index].smscAddr.address);
+               MSG_SEC_DEBUG("address = %s", pSMSCList->smscData[index].smscAddr.address);
 
-                       smsParam.TpSvcCntrAddr.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSMSCList->smscData[index].smscAddr.address, smsParam.TpSvcCntrAddr.szDiallingNum);
-               } else {
-                       MSG_DEBUG("SMSC Addr is not present");
-               }
+               smsParam.TpSvcCntrAddr.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSMSCList->smscData[index].smscAddr.address, smsParam.TpSvcCntrAddr.szDiallingNum);
+       } else {
+               MSG_DEBUG("SMSC Addr is not present");
+       }
 
-               /*Setting the PID value*/
-               smsParam.ParamIndicator |= 0x04 ;  //enable 3nd Bit
-               MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
+       /*Setting the PID value*/
+       smsParam.ParamIndicator |= 0x04 ;  //enable 3nd Bit
+       MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
 
-               smsParam.TpProtocolId = (unsigned short)convertPid(pSMSCList->smscData[index].pid);
+       smsParam.TpProtocolId = (unsigned short)convertPid(pSMSCList->smscData[index].pid);
 
-               /*Setting the ValidityPeriod value*/
-               smsParam.ParamIndicator |= 0x10 ;  //enable 5nd Bit
-               MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
+       /*Setting the ValidityPeriod value*/
+       smsParam.ParamIndicator |= 0x10 ;  //enable 5nd Bit
+       MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
 
-               smsParam.TpValidityPeriod = (unsigned short)pSMSCList->smscData[index].valPeriod;
+       smsParam.TpValidityPeriod = (unsigned short)pSMSCList->smscData[index].valPeriod;
 
-               smsParam.ParamIndicator = ~(smsParam.ParamIndicator);
-               MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
+       smsParam.ParamIndicator = ~(smsParam.ParamIndicator);
+       MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
 
-               ret = tel_set_sms_parameters(pTapiHandle, (const TelSmsParams_t*)&smsParam, TapiEventSetConfigData, NULL);
+       /* Get TAPI handle */
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(pSMSCList->simIndex);
 
-               if (ret != TAPI_API_SUCCESS)
-                       THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Error. [%d]", ret);
+       ret = tel_set_sms_parameters(handle, (const TelSmsParams_t*)&smsParam, TapiEventSetConfigData, NULL);
 
-               if (!getResultFromSim())
-                       THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Result Error.");
-       }
+       if (ret != TAPI_API_SUCCESS)
+               THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Error. [%d]", ret);
+
+       if (!getResultFromSim())
+               THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Result Error.");
 
        MSG_END();
 }
@@ -502,7 +658,9 @@ void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
 
        int paramCnt = 0;
 
-       paramCnt = getParamCount();
+       MSG_SEC_DEBUG("SIM index [%d]", pSMSCList->simIndex);
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(pSMSCList->simIndex);
+       paramCnt = getParamCount(handle);
 
        MSG_DEBUG("Parameter Count [%d]", paramCnt);
 
@@ -511,7 +669,7 @@ void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
        MSG_SMSC_DATA_S tmpSmscData = {};
 
        for (int index = 0; index < paramCnt; index++) {
-               ret = tel_get_sms_parameters(pTapiHandle, index, TapiEventGetParam, NULL);
+               ret = tel_get_sms_parameters(handle, index, TapiEventGetParam, NULL);
 
                if (ret == TAPI_API_SUCCESS) {
                        MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
@@ -519,21 +677,21 @@ void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
                        THROW(MsgException::SMS_PLG_ERROR, "######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
                }
 
-               if (getParamEvent(&tmpSmscData) == true) {
+               if (getParamEvent(handle, &tmpSmscData) == true) {
                        MSG_DEBUG("######## Get Parameter was Successful !!! #######");
-               } else {
-                       THROW(MsgException::SMS_PLG_ERROR, "######## Get Parameter was Failed !!! #######");
-               }
 
-               memcpy(&(pSMSCList->smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
+                       memcpy(&(pSMSCList->smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
 
-               MSG_DEBUG("pid[%d]", pSMSCList->smscData[index].pid);
-               MSG_DEBUG("val_period[%d]", pSMSCList->smscData[index].valPeriod);
-               MSG_DEBUG("name[%s]", pSMSCList->smscData[index].name);
+                       MSG_DEBUG("pid[%d]", pSMSCList->smscData[index].pid);
+                       MSG_DEBUG("val_period[%d]", pSMSCList->smscData[index].valPeriod);
+                       MSG_SEC_DEBUG("name[%s]", pSMSCList->smscData[index].name);
 
-               MSG_DEBUG("ton[%d]", pSMSCList->smscData[index].smscAddr.ton);
-               MSG_DEBUG("npi[%d]", pSMSCList->smscData[index].smscAddr.npi);
-               MSG_DEBUG("address[%s]", pSMSCList->smscData[index].smscAddr.address);
+                       MSG_DEBUG("ton[%d]", pSMSCList->smscData[index].smscAddr.ton);
+                       MSG_DEBUG("npi[%d]", pSMSCList->smscData[index].smscAddr.npi);
+                       MSG_SEC_DEBUG("address[%s]", pSMSCList->smscData[index].smscAddr.address);
+               } else {
+                       MSG_DEBUG("######## Get Parameter was Failed !!! #######");
+               }
        }
 
        pSMSCList->totalCnt = paramCnt;
@@ -545,11 +703,11 @@ void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
 }
 
 
-int SmsPluginSetting::getParamCount()
+int SmsPluginSetting::getParamCount(struct tapi_handle *handle)
 {
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_get_sms_parameter_count(pTapiHandle, TapiEventGetParamCnt, NULL);
+       ret = tel_get_sms_parameter_count(handle, TapiEventGetParamCnt, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_get_sms_parameter_count() Success !!! #######");
@@ -561,23 +719,23 @@ int SmsPluginSetting::getParamCount()
 }
 
 
-bool SmsPluginSetting::getParam(int Index, MSG_SMSC_DATA_S *pSmscData)
+bool SmsPluginSetting::getParam(struct tapi_handle *handle, int Index, MSG_SMSC_DATA_S *pSmscData)
 {
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_get_sms_parameters(pTapiHandle, Index, TapiEventGetParam, NULL);
+       ret = tel_get_sms_parameters(handle, Index, TapiEventGetParam, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
        } else {
-               MSG_DEBUG("######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
+               MSG_ERR("######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
                return false;
        }
 
-       if (getParamEvent(pSmscData) == true) {
+       if (getParamEvent(handle, pSmscData) == true) {
                MSG_DEBUG("######## Get Parameter was Successful !!! #######");
        } else {
-               MSG_DEBUG("######## Get Parameter was Failed !!! #######");
+               MSG_ERR("######## Get Parameter was Failed !!! #######");
                return false;
        }
 
@@ -585,40 +743,172 @@ bool SmsPluginSetting::getParam(int Index, MSG_SMSC_DATA_S *pSmscData)
 }
 
 
-bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
+void SmsPluginSetting::setSmscInfo(const MSG_SMSC_LIST_S *pSmscList)
 {
+       MSG_BEGIN();
+
+       MutexLocker lock(mx);
+
        int ret = TAPI_API_SUCCESS;
 
-       TelSmsCbConfig_t cbConfig = {};
+       struct tapi_handle *handle = NULL;
 
-       cbConfig.CBEnabled = (int)pCbOpt->bReceive;
-       cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
-       cbConfig.MsgIdMaxCount = pCbOpt->maxSimCnt;
-       cbConfig.MsgIdRangeCount = pCbOpt->channelData.channelCnt;
+       handle = SmsPluginDSHandler::instance()->getTelHandle(pSmscList->simIndex);
 
-       for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
-               cbConfig.MsgIDs[i].Net3gpp.Selected = (unsigned short)pCbOpt->channelData.channelInfo[i].bActivate;
-               cbConfig.MsgIDs[i].Net3gpp.FromMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].from;
-               cbConfig.MsgIDs[i].Net3gpp.ToMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].to;
+       int select_id = pSmscList->selected;
+       const MSG_SMSC_DATA_S *pSmscData = (const MSG_SMSC_DATA_S *)&(pSmscList->smscData[select_id]);
 
-               MSG_DEBUG("FROM: %d, TO: %d", cbConfig.MsgIDs[i].Net3gpp.FromMsgId, cbConfig.MsgIDs[i].Net3gpp.ToMsgId);
-       }
-       MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);
+       MSG_DEBUG("Select SMSC id = [%d]", select_id);
 
-       ret = tel_set_sms_cb_config(pTapiHandle, &cbConfig, TapiEventSetConfigData, NULL);
+       TelSmsAddressInfo_t sca;
+       memset(&sca, 0x00, sizeof(TelSmsAddressInfo_t));
 
-       if (ret == TAPI_API_SUCCESS) {
-               MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
+       if (strlen(pSmscData->smscAddr.address) > 0) {
+
+               if (pSmscData->smscAddr.address[0] == '+')
+                       sca.Ton = TAPI_SIM_TON_INTERNATIONAL;
+               else
+                       sca.Ton = TAPI_SIM_TON_NATIONAL;
+
+               sca.Npi = TAPI_SIM_NPI_ISDN_TEL; // app cannot set this value
+
+               MSG_SEC_DEBUG("SMSC TON = [%d], NPI = [%d], Address = [%s]", sca.Ton, sca.Npi, pSmscData->smscAddr.address);
+
+               sca.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSmscData->smscAddr.address, sca.szDiallingNum);
        } else {
-               MSG_DEBUG("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
-               return false;
+               MSG_DEBUG("SMSC Addr is not present");
        }
 
-       if (getResultFromSim() == true) {
-               MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
+       ret = tel_set_sms_sca(handle, (const TelSmsAddressInfo_t *)&sca, 0, TapiEventSetSmscInfo, NULL);
+
+       if (ret != TAPI_API_SUCCESS)
+               THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_sca() Error. [%d]", ret);
+
+       if (!getResultFromSim())
+               THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_sca() Result Error.");
+
+       MSG_END();
+}
+
+
+bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
+{
+       struct tapi_handle *handle = NULL;
+       int simCnt = SmsPluginDSHandler::instance()->getTelHandleCount();
+
+       TelSmsCbConfig_t cbConfig = {};
+
+       int cbEnabled = 0;
+       int ret = TAPI_API_SUCCESS;
+
+       if(pCbOpt->bReceive==true)
+               cbEnabled = 2;// Need to get a Enumeration from TAPI, currently it is not available
+
+       MSG_DEBUG("simIndex:%d, cbEnabled:%d", pCbOpt->simIndex, cbEnabled);
+
+       if (pCbOpt->simIndex == 0) {
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+               memset(keyName, 0x00, sizeof(keyName));
+               MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NOT_FOUND;
+
+               for (int i = 1; i <= simCnt; i++) {
+                       MutexLocker lock(mx);
+
+                       //if (i == pCbOpt->simIndex)
+                       //      continue;
+                       memset(keyName, 0x00, sizeof(keyName));
+                       sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, i);
+                       simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(keyName);
+
+                       if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
+                               MSG_DEBUG("SIM %d is not present..", i);
+                               continue;
+                       }
+
+                       handle = SmsPluginDSHandler::instance()->getTelHandle(i);
+                       memset(&cbConfig, 0x00, sizeof(TelSmsCbConfig_t));
+
+                       MSG_SETTING_S cbSetting;
+                       getCbOpt(&cbSetting, i);
+
+                       cbConfig.CBEnabled = cbEnabled;
+                       cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
+
+                       /*cbConfig.CBEnabled = (int)pCbOpt->bReceive;
+                       cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
+                       cbConfig.MsgIdMaxCount = cbSetting.option.cbMsgOpt.maxSimCnt;
+                       cbConfig.MsgIdRangeCount = cbSetting.option.cbMsgOpt.channelData.channelCnt;
+
+                       for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
+                               cbConfig.MsgIDs[i].Net3gpp.Selected = (unsigned short)cbSetting.option.cbMsgOpt.channelData.channelInfo[i].bActivate;
+                               cbConfig.MsgIDs[i].Net3gpp.FromMsgId = (unsigned short)cbSetting.option.cbMsgOpt.channelData.channelInfo[i].from;
+                               cbConfig.MsgIDs[i].Net3gpp.ToMsgId = (unsigned short)cbSetting.option.cbMsgOpt.channelData.channelInfo[i].to;
+                       }*/
+
+                       ret = tel_set_sms_cb_config(handle, &cbConfig, TapiEventSetConfigData, NULL);
+
+                       if (ret == TAPI_API_SUCCESS) {
+                               MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
+                       } else {
+                               MSG_ERR("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
+                               return false;
+                       }
+
+                       if (getResultFromSim() == true) {
+                               MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
+                       } else {
+                               MSG_ERR("######## Set Cb Config was Failed !!! #######");
+                               return false;
+                       }
+
+                       msg_error_t err = MSG_SUCCESS;
+                       MsgDbHandler *dbHandle = getDbHandle();
+                       err = MsgStoAddCBChannelInfo(dbHandle, const_cast<MSG_CB_CHANNEL_S*>(&pCbOpt->channelData),i);
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgStoAddCBChannelInfo is failed [%d]", err);
+                               return MSG_ERR_SET_SETTING;
+                       }
+               }
+
+               MSG_DEBUG("SIM Index = [0], Set CB Receive is done");
+               return true;
        } else {
-               MSG_DEBUG("######## Set Cb Config was Failed !!! #######");
-               return false;
+               MutexLocker lock(mx);
+
+               handle = SmsPluginDSHandler::instance()->getTelHandle(pCbOpt->simIndex);
+
+               memset(&cbConfig, 0x00, sizeof(TelSmsCbConfig_t));
+               cbConfig.CBEnabled = cbEnabled;
+               cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
+       /*      cbConfig.CBEnabled = (int)pCbOpt->bReceive;
+               cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
+               cbConfig.MsgIdMaxCount = pCbOpt->maxSimCnt;
+               cbConfig.MsgIdRangeCount = pCbOpt->channelData.channelCnt;
+
+               for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
+                       cbConfig.MsgIDs[i].Net3gpp.Selected = (unsigned short)pCbOpt->channelData.channelInfo[i].bActivate;
+                       cbConfig.MsgIDs[i].Net3gpp.FromMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].from;
+                       cbConfig.MsgIDs[i].Net3gpp.ToMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].to;
+
+                       MSG_DEBUG("FROM: %d, TO: %d", cbConfig.MsgIDs[i].Net3gpp.FromMsgId, cbConfig.MsgIDs[i].Net3gpp.ToMsgId);
+               }
+               MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);*/
+
+               ret = tel_set_sms_cb_config(handle, &cbConfig, TapiEventSetConfigData, NULL);
+
+               if (ret == TAPI_API_SUCCESS) {
+                       MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
+               } else {
+                       MSG_ERR("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
+                       return false;
+               }
+
+               if (getResultFromSim() == true) {
+                       MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
+               } else {
+                       MSG_ERR("######## Set Cb Config was Failed !!! #######");
+                       return false;
+               }
        }
 
        return true;
@@ -629,59 +919,105 @@ bool SmsPluginSetting::getCbConfig(MSG_CBMSG_OPT_S *pCbOpt)
 {
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_get_sms_cb_config(pTapiHandle, TapiEventGetCBConfig, NULL);
+       struct tapi_handle *handle = NULL;
+
+       if (pCbOpt->simIndex == 0) {
+               MSG_DEBUG("SIM Index for getCBConfig = 0, CANNOT get cbconfig from SIM 0");
+               return false;
+       }
+
+       handle = SmsPluginDSHandler::instance()->getTelHandle(pCbOpt->simIndex);
+
+       ret = tel_get_sms_cb_config(handle, TapiEventGetCBConfig, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_get_sms_cb_config() Success !!! #######");
        } else {
-               MSG_DEBUG("######## tel_get_sms_cb_config() Fail !!! return : %d #######", ret);
+               MSG_ERR("######## tel_get_sms_cb_config() Fail !!! return : %d #######", ret);
                return false;
        }
 
        if (getCbConfigEvent(pCbOpt) == true) {
                MSG_DEBUG("######## Get Cb Config was Successful !!! #######");
        } else {
-               MSG_DEBUG("######## Get Cb Config was Failed !!! #######");
+               MSG_ERR("######## Get Cb Config was Failed !!! #######");
                return false;
        }
 
        return true;
 }
 
+
 void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
 {
+       MutexLocker lock(mx);
+
        int ret = TAPI_API_SUCCESS;
 
+       if (bMbdnEnable == false) {
+               MSG_DEBUG("MBDN service is disable.");
+               return;
+       }
+
        TelSimMailBoxNumber_t mailboxInfo = {0,};
+       bool bExistVoicetype = false;
+       int i = 0;
+       int simIndex = pVoiceOpt->simIndex;
 
-       for (int i = 0; i < simMailboxList.count; i++) {
-               if (simMailboxList.list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
-                       memset(&simMailboxList.list[i].num, 0x00, sizeof(simMailboxList.list[i].num));
-                       snprintf(simMailboxList.list[i].num, sizeof(simMailboxList.list[i].num), "%s", pVoiceOpt->mailNumber);
-                       MSG_DEBUG("Mailbox number config [%s]", simMailboxList.list[i].num);
-
-                       mailboxInfo.b_cphs = simMailboxList.list[i].b_cphs;
-                       mailboxInfo.alpha_id_max_len = simMailboxList.list[i].alpha_id_max_len;
-                       mailboxInfo.mb_type = (TelSimMailboxType_t)simMailboxList.list[i].mb_type;
-                       mailboxInfo.profile_num = simMailboxList.list[i].profile_num;
-                       mailboxInfo.rec_index = simMailboxList.list[i].rec_index;
-                       mailboxInfo.ton = (TelSimTypeOfNum_t)simMailboxList.list[i].ton;
-                       mailboxInfo.npi = (TelSimNumberingPlanIdentity_t)simMailboxList.list[i].npi;
-                       snprintf(mailboxInfo.alpha_id, sizeof(mailboxInfo.alpha_id), "%s", simMailboxList.list[i].alpha_id);
-                       snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", simMailboxList.list[i].num);
-                       mailboxInfo.cc_id = simMailboxList.list[i].cc_id;
-                       mailboxInfo.ext1_id = simMailboxList.list[i].ext1_id;
+       if (simMailboxList[simIndex].count <= 0) { /* Not available */
+               THROW(MsgException::SMS_PLG_ERROR, "########  Set mailbox info Failed !!!#######");
+               return;
+       }
 
+       for (i = 0; i < simMailboxList[simIndex].count; i++) {
+               if (simMailboxList[simIndex].list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
+                       bExistVoicetype = true;
                        break;
                }
        }
 
-       ret = tel_set_sim_mailbox_info(pTapiHandle, &mailboxInfo, TapiEventSetMailboxInfo, NULL);
+       if (bExistVoicetype == false) {
+               /* There is no mailbox information for voicemail type on SIM. */
+               for (i = 0; i < simMailboxList[simIndex].count; i++) {
+                       if (simMailboxList[simIndex].list[i].mb_type < TAPI_SIM_MAILBOX_VOICE || simMailboxList[simIndex].list[i].mb_type > TAPI_SIM_MAILBOX_OTHER) {
+                               simMailboxList[simIndex].list[i].mb_type = TAPI_SIM_MAILBOX_VOICE;
+                               break;
+                       }
+               }
+       }
+
+       memset(&simMailboxList[simIndex].list[i].num, 0x00, sizeof(simMailboxList[simIndex].list[i].num));
+       snprintf(simMailboxList[simIndex].list[i].num, sizeof(simMailboxList[simIndex].list[i].num), "%s", pVoiceOpt->mailNumber);
+       MSG_DEBUG("Mailbox number config [%s]", simMailboxList[simIndex].list[i].num);
+
+       mailboxInfo.b_cphs = simMailboxList[simIndex].list[i].b_cphs;
+       mailboxInfo.alpha_id_max_len = simMailboxList[simIndex].list[i].alpha_id_max_len;
+       mailboxInfo.mb_type = (TelSimMailboxType_t)simMailboxList[simIndex].list[i].mb_type;
+       mailboxInfo.profile_num = simMailboxList[simIndex].list[i].profile_num;
+       mailboxInfo.rec_index = simMailboxList[simIndex].list[i].rec_index;
+       mailboxInfo.ton = (TelSimTypeOfNum_t)simMailboxList[simIndex].list[i].ton;
+       mailboxInfo.npi = (TelSimNumberingPlanIdentity_t)simMailboxList[simIndex].list[i].npi;
+       snprintf(mailboxInfo.alpha_id, sizeof(mailboxInfo.alpha_id), "%s", simMailboxList[simIndex].list[i].alpha_id);
+
+       if (simMailboxList[simIndex].list[i].num[0] == '+') {
+               snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", &(simMailboxList[simIndex].list[i].num[1]));
+               mailboxInfo.ton = TAPI_SIM_TON_INTERNATIONAL;
+       } else {
+               snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", simMailboxList[simIndex].list[i].num);
+       }
+       MSG_DEBUG("Mailbox number to save sim [%s]", mailboxInfo.num);
+
+       mailboxInfo.cc_id = simMailboxList[simIndex].list[i].cc_id;
+       mailboxInfo.ext1_id = simMailboxList[simIndex].list[i].ext1_id;
+
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
+
+       ret = tel_set_sim_mailbox_info(handle, &mailboxInfo, TapiEventSetMailboxInfo, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_set_sim_mailbox_info() Success !!! #######");
        } else {
-               MSG_DEBUG("######## tel_set_sim_mailbox_info() Fail !!! return : %d #######", ret);
+               MSG_ERR("######## tel_set_sim_mailbox_info() Fail !!! return : %d #######", ret);
        }
 
        if (getResultFromSim() == true) {
@@ -693,74 +1029,143 @@ void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
        return;
 }
 
-bool SmsPluginSetting::getVoiceMailInfo(MSG_VOICEMAIL_OPT_S *pVoiceOpt)
+
+bool SmsPluginSetting::getVoiceMailInfo(struct tapi_handle *handle)
 {
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_get_sim_mailbox_info(pTapiHandle, TapiEventGetMailboxInfo, NULL);
+       ret = tel_get_sim_mailbox_info(handle, TapiEventGetMailboxInfo, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_get_sim_mailbox_info() Success !!! #######");
        } else {
-               MSG_DEBUG("######## tel_get_sim_mailbox_info() Fail !!! return : %d #######", ret);
+               MSG_ERR("######## tel_get_sim_mailbox_info() Fail !!! return : %d #######", ret);
                return false;
        }
 
-       if (getMailboxInfoEvent(pVoiceOpt) == true) {
-               MSG_DEBUG("######## Get MWI info was Successful !!! #######");
+       if (getMailboxInfoEvent() == true) {
+               MSG_DEBUG("######## Get mailbox info was Successful !!! #######");
        } else {
-               MSG_DEBUG("######## Get MWI info was Failed !!! #######");
+               MSG_ERR("######## Get mailbox info was Failed !!! #######");
                return false;
        }
 
        return true;
 }
 
-void SmsPluginSetting::setMwiInfo(MSG_SUB_TYPE_T type, int count)
+
+void SmsPluginSetting::getMeImei(char *pImei)
 {
-       if (type < MSG_MWI_VOICE_SMS || type > MSG_MWI_OTHER_SMS) {
-               MSG_DEBUG("Invalid parameter");
+       int ret = TAPI_API_SUCCESS;
+
+       struct tapi_handle *handle = NULL;
+       handle = SmsPluginDSHandler::instance()->getTelHandle(1);
+
+       if (handle == NULL) {
+               MSG_DEBUG("Tapi Handle is NULL!");
                return;
        }
 
-       int ret = TAPI_API_SUCCESS;
+       ret = tel_get_misc_me_imei(handle, TapiEventGetMeImei, NULL);
+
+       if (ret == TAPI_API_SUCCESS) {
+               MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Success !!! #######");
+
+               if (getResultImei(pImei) == true) {
+                       MSG_SEC_DEBUG("######## Get ME IMEI was Successful !!! #######");
+               } else {
+                       MSG_SEC_DEBUG("######## Get ME IMEI was Failed !!! #######");
+               }
+       } else {
+               MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Fail !!! return : %d #######", ret);
+       }
+}
 
+
+void SmsPluginSetting::setMwiInfo(int simIndex, MSG_SUB_TYPE_T type, int count)
+{
+       MSG_DEBUG("SET MWI INFO, type=[%d]", type);
+       MSG_DEBUG("SET MWI INFO, count=[%d]", count);
+
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, simIndex);
+
+       if (MsgSettingSetInt(keyName, count) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingSetInt is failed!!");
+
+       if(count <= 0) {
+               if (type == MSG_MWI_VOICE_SMS)
+                       MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_1);
+               else if (type == MSG_MWI_VOICE2_SMS)
+                       MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_2);
+       }
+
+       if (bMbdnEnable == false) {
+               MSG_DEBUG("MBDN service is disable.");
+               return;
+       }
+
+       int ret = TAPI_API_SUCCESS;
        TelSimMessageWaitingReq_t mwReq = {0,};
 
-       if (simMwiInfo.b_cphs) {
+       MSG_DEBUG("SET MWI INFO, CPHS? [%s]", simMwiInfo[simIndex].b_cphs?"Yes":"No");
+
+       if (simMwiInfo[simIndex].b_cphs) {
                if (type == MSG_MWI_VOICE_SMS)
-                       simMwiInfo.cphs_mwi.b_voice1 = true;
+                       simMwiInfo[simIndex].cphs_mwi.b_voice1 = (count > 0 ? 1:0);
+               else if (type == MSG_MWI_VOICE2_SMS)
+                       simMwiInfo[simIndex].cphs_mwi.b_voice2 = (count > 0 ? 1:0);
                else if (type == MSG_MWI_FAX_SMS)
-                       simMwiInfo.cphs_mwi.b_fax = true;
-               else
+                       simMwiInfo[simIndex].cphs_mwi.b_fax = (count > 0 ? 1:0);
+               else {
                        MSG_DEBUG("There is no type [%d] in CPHS.", type);
+                       return;
+               }
+
+               mwReq.mw_data_u.cphs_mw.b_voice1 = simMwiInfo[simIndex].cphs_mwi.b_voice1;
+               mwReq.mw_data_u.cphs_mw.b_voice2 = simMwiInfo[simIndex].cphs_mwi.b_voice2;
+               mwReq.mw_data_u.cphs_mw.b_fax = simMwiInfo[simIndex].cphs_mwi.b_fax;
+               mwReq.mw_data_u.cphs_mw.b_data = simMwiInfo[simIndex].cphs_mwi.b_data;
+
+               MSG_DEBUG("MWI voice 1 = [%d]", mwReq.mw_data_u.cphs_mw.b_voice1);
+               MSG_DEBUG("MWI voice 2 = [%d]", mwReq.mw_data_u.cphs_mw.b_voice2);
+               MSG_DEBUG("MWI fax = [%d]", mwReq.mw_data_u.cphs_mw.b_fax);
+               MSG_DEBUG("MWI data = [%d]", mwReq.mw_data_u.cphs_mw.b_data);
 
-               mwReq.mw_data_u.cphs_mw.b_voice1 = simMwiInfo.cphs_mwi.b_voice1;
-               mwReq.mw_data_u.cphs_mw.b_voice2 = simMwiInfo.cphs_mwi.b_voice2;
-               mwReq.mw_data_u.cphs_mw.b_fax = simMwiInfo.cphs_mwi.b_fax;
-               mwReq.mw_data_u.cphs_mw.b_data = simMwiInfo.cphs_mwi.b_data;
        } else {
                if (type == MSG_MWI_VOICE_SMS)
-                       simMwiInfo.mwi_list.mw_info[0].voice_count = count;
+                       simMwiInfo[simIndex].mwi_list.mw_info[0].voice_count = count;
                else if (type == MSG_MWI_FAX_SMS)
-                       simMwiInfo.mwi_list.mw_info[0].fax_count = count;
+                       simMwiInfo[simIndex].mwi_list.mw_info[0].fax_count = count;
                else if (type == MSG_MWI_EMAIL_SMS)
-                       simMwiInfo.mwi_list.mw_info[0].email_count = count;
+                       simMwiInfo[simIndex].mwi_list.mw_info[0].email_count = count;
                else // MSG_MWI_OTHER_SMS
-                       simMwiInfo.mwi_list.mw_info[0].other_count = count;
-
-               mwReq.mw_data_u.mw.rec_index = simMwiInfo.mwi_list.mw_info[0].rec_index;
-               mwReq.mw_data_u.mw.indicator_status = simMwiInfo.mwi_list.mw_info[0].indicator_status;
-               mwReq.mw_data_u.mw.voice_count = simMwiInfo.mwi_list.mw_info[0].voice_count;
-               mwReq.mw_data_u.mw.fax_count = simMwiInfo.mwi_list.mw_info[0].fax_count;
-               mwReq.mw_data_u.mw.email_count = simMwiInfo.mwi_list.mw_info[0].email_count;
-               mwReq.mw_data_u.mw.other_count = simMwiInfo.mwi_list.mw_info[0].other_count;
-               mwReq.mw_data_u.mw.video_count = simMwiInfo.mwi_list.mw_info[0].video_count;
+                       simMwiInfo[simIndex].mwi_list.mw_info[0].other_count = count;
+
+               mwReq.mw_data_u.mw.rec_index = simMwiInfo[simIndex].mwi_list.mw_info[0].rec_index;
+               mwReq.mw_data_u.mw.indicator_status = simMwiInfo[simIndex].mwi_list.mw_info[0].indicator_status;
+               mwReq.mw_data_u.mw.voice_count = simMwiInfo[simIndex].mwi_list.mw_info[0].voice_count;
+               mwReq.mw_data_u.mw.fax_count = simMwiInfo[simIndex].mwi_list.mw_info[0].fax_count;
+               mwReq.mw_data_u.mw.email_count = simMwiInfo[simIndex].mwi_list.mw_info[0].email_count;
+               mwReq.mw_data_u.mw.other_count = simMwiInfo[simIndex].mwi_list.mw_info[0].other_count;
+               mwReq.mw_data_u.mw.video_count = simMwiInfo[simIndex].mwi_list.mw_info[0].video_count;
+
+               MSG_DEBUG("MWI record index = [%d]", mwReq.mw_data_u.mw.rec_index);
+               MSG_DEBUG("MWI ind status = [%d]", mwReq.mw_data_u.mw.indicator_status);
+               MSG_DEBUG("MWI voice = [%d]", mwReq.mw_data_u.mw.voice_count);
+               MSG_DEBUG("MWI fax = [%d]", mwReq.mw_data_u.mw.fax_count);
+               MSG_DEBUG("MWI email = [%d]", mwReq.mw_data_u.mw.email_count);
+               MSG_DEBUG("MWI other = [%d]", mwReq.mw_data_u.mw.other_count);
+               MSG_DEBUG("MWI video = [%d]", mwReq.mw_data_u.mw.video_count);
        }
 
-       mwReq.b_cphs = simMwiInfo.b_cphs;
+       mwReq.b_cphs = simMwiInfo[simIndex].b_cphs;
 
-       ret = tel_set_sim_messagewaiting_info(pTapiHandle, &mwReq, TapiEventSetMwiInfo, NULL);
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
+
+       ret = tel_set_sim_messagewaiting_info(handle, &mwReq, TapiEventSetMwiInfo, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Success !!! #######");
@@ -772,11 +1177,13 @@ void SmsPluginSetting::setMwiInfo(MSG_SUB_TYPE_T type, int count)
 }
 
 
-bool SmsPluginSetting::getMwiInfo(void)
+bool SmsPluginSetting::getMwiInfo(struct tapi_handle *handle)
 {
+       MutexLocker lock(mx);
+
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_get_sim_messagewaiting_info(pTapiHandle, TapiEventGetMwiInfo, NULL);
+       ret = tel_get_sim_messagewaiting_info(handle, TapiEventGetMwiInfo, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
                MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Success !!! #######");
@@ -796,22 +1203,55 @@ bool SmsPluginSetting::getMwiInfo(void)
 }
 
 
-bool SmsPluginSetting::getMsisdnInfo(void)
+bool SmsPluginSetting::getMsisdnInfo(struct tapi_handle *handle)
 {
+       MutexLocker lock(mx);
+
        int ret = TAPI_API_SUCCESS;
-       bool result = true;
 
-       ret = tel_get_sim_msisdn(pTapiHandle, TapiEventGetMsisdnInfo, NULL);
+       ret = tel_get_sim_msisdn(handle, TapiEventGetMsisdnInfo, NULL);
 
        if (ret == TAPI_API_SUCCESS) {
-               result = true;
                MSG_DEBUG("######## tel_get_sim_msisdn() Success !!! #######");
        } else {
-               result = false;
                MSG_DEBUG("######## tel_get_sim_msisdn() Fail !!! return : %d #######", ret);
+               return false;
+       }
+
+       if (getResultFromSim() == true) {
+               MSG_DEBUG("######## Get Sim msisdn was Successful !!! #######");
+       } else {
+               MSG_DEBUG("######## Get Sim msisdn was Failed !!! #######");
+               return false;
+       }
+
+       return true;
+}
+
+
+bool SmsPluginSetting::getSimServiceTable(struct tapi_handle *handle)
+{
+       MutexLocker lock(mx);
+
+       int ret = TAPI_API_SUCCESS;
+
+       ret = tel_get_sim_service_table(handle, TapiEventGetSimServiceTable, NULL);
+
+       if (ret == TAPI_API_SUCCESS) {
+               MSG_DEBUG("######## tel_get_sim_service_table() Success !!! #######");
+       } else {
+               MSG_DEBUG("######## tel_get_sim_service_table() Fail !!! return : %d #######", ret);
+               return false;
        }
 
-       return result;
+       if (getResultFromSim() == true) {
+               MSG_DEBUG("######## Get SST info was Successful !!! #######");
+       } else {
+               MSG_DEBUG("######## Get SST info was Failed !!! #######");
+               return false;
+       }
+
+       return true;
 }
 
 
@@ -833,7 +1273,7 @@ int SmsPluginSetting::getParamCntEvent()
 
        mx.lock();
 
-       ret = cv.timedwait(mx.pMutex(), 10);
+       ret = cv.timedwait(mx.pMutex(), 25);
 
        mx.unlock();
 
@@ -846,20 +1286,22 @@ int SmsPluginSetting::getParamCntEvent()
 }
 
 
-void SmsPluginSetting::setParamEvent(const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess)
+void SmsPluginSetting::setParamEvent(struct tapi_handle *handle, const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess)
 {
        mx.lock();
 
        bTapiResult = bSuccess;
 
-       memset(&smscData, 0x00, sizeof(MSG_SMSC_DATA_S));
+       int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       memset(&smscData[sim_idx], 0x00, sizeof(MSG_SMSC_DATA_S));
 
        if (bTapiResult == true) {
                MSG_DEBUG("Success to get parameter data");
 
                selectedParam = RecordIdx;
 
-               memcpy(&smscData, pSmscData, sizeof(MSG_SMSC_DATA_S));
+               memcpy(&smscData[sim_idx], pSmscData, sizeof(MSG_SMSC_DATA_S));
        }
 
        cv.signal();
@@ -868,14 +1310,14 @@ void SmsPluginSetting::setParamEvent(const MSG_SMSC_DATA_S *pSmscData, int Recor
 }
 
 
-bool SmsPluginSetting::getParamEvent(MSG_SMSC_DATA_S *pSmscData)
+bool SmsPluginSetting::getParamEvent(struct tapi_handle *handle, MSG_SMSC_DATA_S *pSmscData)
 {
        int ret = 0;
 
        mx.lock();
 
        bTapiResult = false;
-       ret = cv.timedwait(mx.pMutex(), 10);
+       ret = cv.timedwait(mx.pMutex(), 25);
 
        mx.unlock();
 
@@ -887,25 +1329,27 @@ bool SmsPluginSetting::getParamEvent(MSG_SMSC_DATA_S *pSmscData)
        memset(pSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
 
        if (bTapiResult == true) {
-               memcpy(pSmscData, &smscData, sizeof(MSG_SMSC_DATA_S));
+               int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
+               memcpy(pSmscData, &smscData[index], sizeof(MSG_SMSC_DATA_S));
        }
 
        return bTapiResult;
 }
 
 
-void SmsPluginSetting::setCbConfigEvent(const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
+void SmsPluginSetting::setCbConfigEvent(struct tapi_handle *handle, const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
 {
        mx.lock();
 
        bTapiResult = bSuccess;
 
-       memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+       memset(&cbOpt[simIndex], 0x00, sizeof(MSG_CBMSG_OPT_S));
 
        if (bTapiResult == true) {
                MSG_DEBUG("Success to get cb config data");
 
-               memcpy(&cbOpt, pCbOpt, sizeof(MSG_CBMSG_OPT_S));
+               memcpy(&cbOpt[simIndex], pCbOpt, sizeof(MSG_CBMSG_OPT_S));
        }
 
        cv.signal();
@@ -921,7 +1365,7 @@ bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
        mx.lock();
 
        bTapiResult = false;
-       ret = cv.timedwait(mx.pMutex(), 10);
+       ret = cv.timedwait(mx.pMutex(), 25);
 
        mx.unlock();
 
@@ -930,51 +1374,102 @@ bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
                return false;
        }
 
+       int simIndex = pCbOpt->simIndex;
+
        memset(pCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
 
        if (bTapiResult == true) {
-               memcpy(pCbOpt, &cbOpt, sizeof(MSG_CBMSG_OPT_S));
+               memcpy(pCbOpt, &cbOpt[simIndex], sizeof(MSG_CBMSG_OPT_S));
        }
 
        return bTapiResult;
 }
 
 
-void SmsPluginSetting::setMailboxInfoEvent(SMS_SIM_MAILBOX_LIST_S *pMailboxList, bool bSuccess)
+void SmsPluginSetting::setMailboxInfoEvent(struct tapi_handle *handle, SMS_SIM_MAILBOX_LIST_S *pMailboxList, bool bSuccess, bool bMbdn)
 {
        mx.lock();
 
        bTapiResult = bSuccess;
 
-       memset(&simMailboxList, 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
+       bMbdnEnable = bMbdn;
+
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       memset(&simMailboxList[simIndex], 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
 
        if (bTapiResult == true) {
                int i = 0;
+               bool bExistMailboxType = false;
+               char keyName[MAX_VCONFKEY_NAME_LEN];
 
                if (pMailboxList && pMailboxList->count > 0) {
-                       memcpy(&simMailboxList, pMailboxList, sizeof(SMS_SIM_MAILBOX_LIST_S));
+                       memcpy(&simMailboxList[simIndex], pMailboxList, sizeof(SMS_SIM_MAILBOX_LIST_S));
 
                        /* Temp :: Save voicemail number with VOICE1 line number */
                        for (i = 0; i < pMailboxList->count ; i++) {
-                               MSG_DEBUG("Mailbox list[%d] type=[%d] address = [%s]", i, pMailboxList->list[i].mb_type, pMailboxList->list[i].num);
+                               MSG_SEC_DEBUG("Mailbox list[%d] type=[%d]", i, pMailboxList->list[i].mb_type);
+
                                if (pMailboxList->list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
-                                       char mailNumber[MAX_PHONE_NUMBER_LEN+1];
-                                       memset(mailNumber, 0x00 , sizeof(mailNumber));
-                                       if (simMailboxList.list[i].ton == MSG_TON_INTERNATIONAL && simMailboxList.list[i].num[0] != '+') {
-                                               snprintf(mailNumber, MAX_PHONE_NUMBER_LEN, "+%s", simMailboxList.list[i].num);
-                                               MSG_DEBUG("MSG_TON_INTERNATIONAL [%s]", mailNumber);
-                                       } else {
-                                               snprintf(mailNumber, MAX_PHONE_NUMBER_LEN, "%s", simMailboxList.list[i].num);
-                                               MSG_DEBUG("[%s]", mailNumber);
-                                       }
+                                       bExistMailboxType = true;
+                                       break;
+                               }
+                       }
 
-                                       if (mailNumber[0] != '\0') {
-                                               if (MsgSettingSetString(VOICEMAIL_NUMBER, mailNumber) != MSG_SUCCESS)
-                                                       MSG_DEBUG("MsgSettingSetString is failed!!");
+                       if (bExistMailboxType == false) {
+                               MSG_DEBUG("There is no voice mailbox type.");
+                               for (i = 0; i < simMailboxList[simIndex].count; i++) {
+                                       if (pMailboxList->list[i].mb_type < TAPI_SIM_MAILBOX_VOICE || pMailboxList->list[i].mb_type > TAPI_SIM_MAILBOX_OTHER) {
+                                               pMailboxList->list[i].mb_type = TAPI_SIM_MAILBOX_VOICE;
+                                               break;
                                        }
-                                       break;
                                }
                        }
+
+                       char mailNumber[MAX_PHONE_NUMBER_LEN+1];
+                       memset(mailNumber, 0x00 , sizeof(mailNumber));
+
+                       MSG_SEC_DEBUG("Mailbox list[%d] ton=[%d], address=[%s], alpha_id=[%s]", \
+                                       i, simMailboxList[simIndex].list[i].ton, simMailboxList[simIndex].list[i].num, \
+                                       simMailboxList[simIndex].list[i].alpha_id);
+
+                       if (simMailboxList[simIndex].list[i].ton == MSG_TON_INTERNATIONAL && simMailboxList[simIndex].list[i].num[0] != '+') {
+                               snprintf(mailNumber, MAX_PHONE_NUMBER_LEN, "+%s", simMailboxList[simIndex].list[i].num);
+                               MSG_DEBUG("MSG_TON_INTERNATIONAL [%s]", mailNumber);
+                       } else {
+                               snprintf(mailNumber, MAX_PHONE_NUMBER_LEN, "%s", simMailboxList[simIndex].list[i].num);
+                               MSG_DEBUG("[%s]", mailNumber);
+                       }
+
+                       if (mailNumber[0] != '\0') {
+                               memset(keyName, 0x00, sizeof(keyName));
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
+                               if (MsgSettingSetString(keyName, mailNumber) != MSG_SUCCESS)
+                                       MSG_DEBUG("MsgSettingSetString is failed!!");
+                       }
+
+                       if (simMailboxList[simIndex].list[i].alpha_id[0] != '\0') {
+                               char unpackAlphaId[MAX_SIM_XDN_ALPHA_ID_LEN+8];
+                               int tmpLen = 0;
+                               MSG_LANG_INFO_S langInfo = {0,};
+
+                               memset(unpackAlphaId, 0x00, sizeof(unpackAlphaId));
+
+                               langInfo.bSingleShift = false;
+                               langInfo.bLockingShift = false;
+
+                               tmpLen = strlen(simMailboxList[simIndex].list[i].alpha_id);
+
+                               MsgTextConvert *textCvt = MsgTextConvert::instance();
+                               textCvt->convertGSM7bitToUTF8((unsigned char*)unpackAlphaId, sizeof(unpackAlphaId), (unsigned char*)simMailboxList[simIndex].list[i].alpha_id, tmpLen, &langInfo);
+
+                               MSG_DEBUG("UTF8 ALPHA_ID = [%s]", unpackAlphaId);
+
+                               memset(keyName, 0x00, sizeof(keyName));
+                               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, simIndex);
+                               if (MsgSettingSetString(keyName, unpackAlphaId) != MSG_SUCCESS)
+                                       MSG_DEBUG("MsgSettingSetString is failed!!");
+                       }
                }
        }
 
@@ -983,14 +1478,14 @@ void SmsPluginSetting::setMailboxInfoEvent(SMS_SIM_MAILBOX_LIST_S *pMailboxList,
        mx.unlock();
 }
 
-bool SmsPluginSetting::getMailboxInfoEvent(MSG_VOICEMAIL_OPT_S *pVoiceOpt)
+bool SmsPluginSetting::getMailboxInfoEvent()
 {
        int ret = 0;
 
        mx.lock();
 
        bTapiResult = false;
-       ret = cv.timedwait(mx.pMutex(), 10);
+       ret = cv.timedwait(mx.pMutex(), 25);
 
        mx.unlock();
 
@@ -999,80 +1494,65 @@ bool SmsPluginSetting::getMailboxInfoEvent(MSG_VOICEMAIL_OPT_S *pVoiceOpt)
                return false;
        }
 
-       memset(pVoiceOpt, 0x00, sizeof(MSG_VOICEMAIL_OPT_S));
-
-       if (bTapiResult == true) {
-               for(int i = 0; i < simMailboxList.count; i++) {
-                       if (simMailboxList.list[i].mb_type == MSG_SIM_MAILBOX_VOICE) {
-                               if (simMailboxList.list[i].ton == MSG_TON_INTERNATIONAL && simMailboxList.list[i].num[0] != '+') {
-                                       snprintf(pVoiceOpt->mailNumber, sizeof(pVoiceOpt->mailNumber), "+%s", simMailboxList.list[i].num);
-                               } else {
-                                       snprintf(pVoiceOpt->mailNumber, sizeof(pVoiceOpt->mailNumber), "%s", simMailboxList.list[i].num);
-                               }
-
-                               break;
-                       }
-               }
-       }
-
        return bTapiResult;
 }
 
-void SmsPluginSetting::setMwiInfoEvent(SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess)
+void SmsPluginSetting::setMwiInfoEvent(struct tapi_handle *handle, SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess)
 {
+       MSG_BEGIN();
+
        mx.lock();
 
        bTapiResult = bSuccess;
 
-       memset(&simMwiInfo, 0x00, sizeof(SMS_SIM_MWI_INFO_S));
+       int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       memset(&simMwiInfo[index], 0x00, sizeof(SMS_SIM_MWI_INFO_S));
 
        if (bTapiResult == true) {
-               int mwi_cnt = 0;
-               int index = 0;
+               int mwiCnt = 0;
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+
+               memcpy(&simMwiInfo[index], pMwiInfo, sizeof(SMS_SIM_MWI_INFO_S));
 
-               memcpy(&simMwiInfo, pMwiInfo, sizeof(SMS_SIM_MWI_INFO_S));
+               /* Save MW count with VOICE line1 number */
+               if (simMwiInfo[index].b_cphs == true) {
+                       mwiCnt = simMwiInfo[index].cphs_mwi.b_voice1;
+               } else {
+                       mwiCnt = simMwiInfo[index].mwi_list.mw_info[0].voice_count; // Normal case
+               }
+               // TODO :: Add operation for voice mail of line 2
 
-               /* Save MW count with VOICE line number */
-               for(int i = 0; i < simMailboxList.count; i++) {
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, index);
+               if (MsgSettingSetInt(keyName, mwiCnt) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgSettingSetInt is failed!!");
 
-                       if (simMailboxList.list[i].mb_type == MSG_SIM_MAILBOX_VOICE) {
+               MSG_DEBUG("MWI count = [%d]", mwiCnt);
 
-                               index = simMailboxList.list[i].profile_num - 1;
-                               if (index < 0) {
-                                       MSG_DEBUG("SIM profile number is invalid.");
-                                       break;
-                               }
+               if (mwiCnt > 0) {
+                       deliverVoiceMsgNoti(index, mwiCnt);
+               }
+       }
 
-                               MSG_DEBUG("SIM MWI profile number=[%d], index=[%d]", simMailboxList.list[i].profile_num, index);
+       cv.signal();
 
-                               if (simMwiInfo.b_cphs == false) { // Normal case
-                                       mwi_cnt = simMwiInfo.mwi_list.mw_info[index].voice_count;
-                               } else { // CPHS case
-                                       /* For CPHS case, mwi_cnt value is boolean */
-                                       mwi_cnt = simMwiInfo.cphs_mwi.b_voice1;
-                               }
+       mx.unlock();
 
-                               if (MsgSettingSetInt(VOICEMAIL_COUNT, mwi_cnt) != MSG_SUCCESS)
-                                       MSG_DEBUG("MsgSettingSetInt is failed!!");
+       MSG_END();
+}
 
-                               if (mwi_cnt > 0) {
-                                       MSG_MESSAGE_INFO_S msgInfo = {0,};
 
-                                       msgInfo.displayTime = time(NULL);
-                                       snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), \
-                                                       "%s", simMailboxList.list[i].num);
-                                       memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
-                                       msgInfo.msgType.mainType = MSG_SMS_TYPE;
-                                       msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
+void SmsPluginSetting::setResultImei(bool bResult, char *pImei)
+{
+       mx.lock();
 
-                                       snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new voice message", mwi_cnt);
+       bTapiResult = bResult;
 
-                                       MsgSoundPlayStart(false);
-                                       MsgInsertNoti(&msgInfo);
-                               }
-                               break;
-                       }
-               }
+       memset(&meImei, 0x00, sizeof(meImei));
+
+       if (bTapiResult == true && pImei) {
+               snprintf(meImei, sizeof(meImei), "%s", pImei);
        }
 
        cv.signal();
@@ -1080,6 +1560,30 @@ void SmsPluginSetting::setMwiInfoEvent(SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSucce
        mx.unlock();
 }
 
+
+bool SmsPluginSetting::getResultImei(char *pImei)
+{
+       int ret = 0;
+
+       mx.lock();
+
+       ret = cv.timedwait(mx.pMutex(), 25);
+
+       mx.unlock();
+
+       if (ret == ETIMEDOUT) {
+               MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
+               return false;
+       }
+
+       if (bTapiResult == true && pImei) {
+               snprintf(pImei, sizeof(meImei), "%s", meImei);
+       }
+
+       return bTapiResult;
+}
+
+
 void SmsPluginSetting::setResultFromSim(bool bResult)
 {
        mx.lock();
@@ -1096,11 +1600,13 @@ bool SmsPluginSetting::getResultFromSim()
 {
        int ret = 0;
 
-       mx.lock();
+       MSG_DEBUG("getResultFromSim() is called .");
 
-       ret = cv.timedwait(mx.pMutex(), 10);
+       //mx.lock(); //  Caller of this function MUST acquire the mutex before calling the TAPI API
 
-       mx.unlock();
+       ret = cv.timedwait(mx.pMutex(), 25);
+
+       //mx.unlock();
 
        if (ret == ETIMEDOUT) {
                MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
@@ -1143,3 +1649,109 @@ SMS_PID_T SmsPluginSetting::convertPid(MSG_SMS_PID_T pid)
        return retPid;
 }
 
+
+void SmsPluginSetting::deliverVoiceMsgNoti(int simIndex, int mwiCnt)
+{
+       MSG_BEGIN();
+
+       MSG_MESSAGE_INFO_S msgInfo = {0,};
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+       msgInfo.addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(msgInfo.addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+       msgInfo.nAddressCnt = 1;
+
+       msgInfo.displayTime = time(NULL);
+
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       char *voiceNum = NULL;
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
+       voiceNum = MsgSettingGetString(keyName);
+
+       if (voiceNum) {
+               snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal),
+                               "%s", voiceNum);
+               free(voiceNum);
+               voiceNum = NULL;
+       }
+       memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
+       msgInfo.msgType.mainType = MSG_SMS_TYPE;
+       msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
+
+#if 0
+       if (simMwiInfo.b_cphs == false) { // Normal case
+               snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new voice message", mwiCnt);
+       } else {
+               snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
+       }
+#else
+       snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", mwiCnt);
+#endif
+
+#if 0
+       if (SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo) != MSG_SUCCESS)
+               MSG_DEBUG("callbackIncoming is failed.");
+#else
+       MsgInsertNotification(&msgInfo);
+       MsgChangePmState();
+#endif
+
+       MSG_END();
+}
+
+
+void SmsPluginSetting::setSimChangeStatus(struct tapi_handle *handle, bool bInitializing)
+{
+       MSG_BEGIN();
+
+       int tapiRet = TAPI_API_SUCCESS;
+       TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
+
+       int cardChanged = 0;
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       pthread_t thd;
+       char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+
+       tapiRet = tel_get_sim_init_info(handle, &status, &cardChanged);
+       MSG_INFO("Tapi Ret=[%d], SIM index [%d], SIM status [%d], CardChanged [%d]", tapiRet, simIndex, status, cardChanged);
+
+       if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
+               if (simStatus[simIndex] == MSG_SIM_STATUS_NOT_FOUND) {
+                       if (cardChanged == 1) {
+                               sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, simIndex);
+                               MsgSettingSetInt(keyName, MSG_SIM_STATUS_CHANGED);
+                               simStatus[simIndex] = MSG_SIM_STATUS_CHANGED;
+                       } else {
+                               sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, simIndex);
+                               MsgSettingSetInt(keyName, MSG_SIM_STATUS_NORMAL);
+                               simStatus[simIndex] = MSG_SIM_STATUS_NORMAL;
+                       }
+//                     tel_handle_list.push_back(handle);
+                       // Modified to call initSimInfo for SIM separately
+                       MSG_DEBUG("calling initSimInfo");
+                       if(pthread_create(&thd, NULL, &initSimInfo, handle) < 0) {
+                               MSG_DEBUG("pthread_create() error");
+                       }
+                       pthread_detach(thd);
+
+               } else {
+                       MSG_DEBUG("SIM init was already done!");
+               }
+       } else {
+               MSG_DEBUG("It doesn't initialize yet!!");
+               sprintf(keyName, "%s/%d", MSG_SIM_CHANGED, simIndex);
+               MSG_DEBUG("Set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND");
+               if (MsgSettingSetInt(keyName, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
+                       MSG_DEBUG("Fail to set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND");
+
+               simStatus[simIndex] = MSG_SIM_STATUS_NOT_FOUND;
+
+       }
+
+       MSG_END();
+}
index 3f6fec8..8eda214 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
 #include "SmsPluginStorage.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginCallback.h"
+#include "MsgUtilStorage.h"
+#include "MsgNotificationWrapper.h"
+
 #include "SmsPluginSimMsg.h"
+#include "SmsPluginDSHandler.h"
 
-extern struct tapi_handle *pTapiHandle;
 
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginSimMsg - Member Functions
@@ -40,6 +43,7 @@ SmsPluginSimMsg::SmsPluginSimMsg()
 {
        // Initialize member variables
        simMsgId = 0;
+       delSimMsgId = -1;
        usedCnt = 0;
        totalCnt = 0;
        bTapiResult = false;
@@ -63,179 +67,291 @@ SmsPluginSimMsg* SmsPluginSimMsg::instance()
 }
 
 
-void SmsPluginSimMsg::initSimMessage()
+void SmsPluginSimMsg::initSimMessage(struct tapi_handle *handle)
 {
        MSG_BEGIN();
 
+       char keyName[MAX_VCONFKEY_NAME_LEN] = {0,};
+       int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
+       sprintf(keyName, "%s/%d", SIM_USED_COUNT, sim_idx);
+       // Set SIM count of vconf to 0
+       if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS) {
+               MSG_DEBUG("Error to set config data [%s]", keyName);
+       }
+       memset(keyName, 0, sizeof(keyName));
+       sprintf(keyName, "%s/%d", SIM_TOTAL_COUNT, sim_idx);
+
+       if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS) {
+               MSG_DEBUG("Error to set config data [%s]", keyName);
+       }
+
        MSG_SIM_COUNT_S tmpMsgCnt;
        memset(&tmpMsgCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
-
-       getSimMsgCount(&tmpMsgCnt);
+       getSimMsgCount(handle, &tmpMsgCnt);
 
        MSG_MESSAGE_INFO_S tmpMsgInfo;
-       memset(&tmpMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+       int simIdList[MAX_SIM_SMS_NUM];
+       int unreadSimMsg = 0;
 
        for (int i = 0; i < tmpMsgCnt.usedCount; i++)
        {
+               memset(&tmpMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+               memset(simIdList, 0, sizeof(int) * MAX_SIM_SMS_NUM);
+
                // Get SIM Msg
-               if (getSimMsg(tmpMsgCnt.indexList[i], &tmpMsgInfo) == false)
+               if (getSimMsg(handle, tmpMsgCnt.indexList[i], &tmpMsgInfo, simIdList) == false)
                        continue;
 
-               if (SmsPluginStorage::instance()->addSimMessage(&tmpMsgInfo) != MSG_SUCCESS)
-               {
-                       MSG_DEBUG("Fail to addSimMessage()");
+               if (tmpMsgInfo.bRead == false)
+                       unreadSimMsg++;
+
+               if (SmsPluginEventHandler::instance()->handleSimMsg(&tmpMsgInfo, simIdList, NULL, MAX_SIM_SMS_NUM) < 0) {
+                       MSG_DEBUG("Fail to handleSimMsg()");
+               }
+
+               if (tmpMsgInfo.addressList) {
+                       free(tmpMsgInfo.addressList);
+                       tmpMsgInfo.addressList = NULL;
                }
        }
 
+       MSG_DEBUG("Unread SIM message count = [%d]", unreadSimMsg);
+#ifndef MSG_NOTI_INTEGRATION
+       if (unreadSimMsg > 0) {
+               MsgRefreshNotification(MSG_NOTI_TYPE_SIM, true, false);
+       }
+#endif
+
+       if (SmsPluginEventHandler::instance()->updateIMSI(sim_idx) != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to handleSimMsg()");
+       }
+
        MSG_END();
 }
 
 
 msg_error_t SmsPluginSimMsg::saveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
 {
+       bool bSimSst = true;
+
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(pMsgInfo->sim_idx);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, pMsgInfo->sim_idx);
+       if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingGetBool [%s] failed", keyName);
+               /* No return, default value is true. */
+
+       if (bSimSst == false)
+               return MSG_ERR_STORE_RESTRICT;
+
        // Reset Out Parameter
        pSimIdList->count = 0;
 
        SMS_TPDU_S tpdu;
        memset(&tpdu, 0x00, sizeof(SMS_TPDU_S));
-
-       tpdu.tpduType = SMS_TPDU_DELIVER;
-
-       // Set SMS TPDU Options
-       setSmsOptions(&(tpdu.data.deliver));
-
-       // Set TimeStamp
-       convertTimeStamp(pMsgInfo, &(tpdu.data.deliver));
-
-       // Set SMSC Options
-       SMS_ADDRESS_S smsc;
-       memset(&smsc, 0x00, sizeof(SMS_ADDRESS_S));
-       SmsPluginTransport::instance()->setSmscOptions(&smsc);
-
-       // Make SMS_SUBMIT_DATA_S from MSG_REQUEST_INFO_S
-       SMS_SUBMIT_DATA_S submitData;
-       memset(&submitData, 0x00, sizeof(SMS_SUBMIT_DATA_S));
-       SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), 0);
-
-       // Check sim message full.
-       if (checkSimMsgFull(submitData.segCount) == true)
+       if(pMsgInfo->direction == MSG_DIRECTION_TYPE_MO)
        {
-               MSG_DEBUG("SIM storage is full.");
-
-               return MSG_ERR_SIM_STORAGE_FULL;
+               tpdu.tpduType = SMS_TPDU_SUBMIT;
+               tpdu.data.submit.dcs.msgClass = SMS_MSG_CLASS_NONE;
+               //SmsPluginTransport::instance()->setSmsSendOptions(&(tpdu.data.submit));
+               tpdu.data.submit.vpf = SMS_VPF_NOT_PRESENT;
+       }
+       else
+       {
+               tpdu.tpduType = SMS_TPDU_DELIVER;
+               setSmsOptions(&(tpdu.data.deliver));
+               // Set TimeStamp
+               convertTimeStamp(pMsgInfo, &(tpdu.data.deliver));
        }
 
-       tpdu.data.deliver.userData.headerCnt = 0;
+       for(int i=0; i <pMsgInfo->nAddressCnt; ++i)
+       {
+               SMS_SUBMIT_DATA_S submitData;
+               memset(&submitData, 0x00, sizeof(SMS_SUBMIT_DATA_S));
+               int bufLen = 0;
+               char buf[MAX_TPDU_DATA_LEN];
 
-       if (submitData.segCount > 1)
-               tpdu.data.deliver.bHeaderInd = true;
+               if(pMsgInfo->direction == MSG_DIRECTION_TYPE_MO) // SUBMIT MSG
+               {
+                       SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.submit.dcs.codingScheme), i);
 
-       int bufLen = 0;
+                       int addLen = strlen(submitData.destAddress.address);
 
-       char buf[MAX_TPDU_DATA_LEN];
+                       tpdu.data.submit.destAddress.ton = submitData.destAddress.ton;
+                       tpdu.data.submit.destAddress.npi = submitData.destAddress.npi;
 
-       int addLen = strlen(submitData.destAddress.address);
+                       if (addLen < MAX_ADDRESS_LEN) {
+                               memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, addLen);
+                               tpdu.data.submit.destAddress.address[addLen] = '\0';
+                       } else {
+                               memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN);
+                               tpdu.data.submit.destAddress.address[MAX_ADDRESS_LEN] = '\0';
+                       }
 
-       tpdu.data.deliver.originAddress.ton = submitData.destAddress.ton;
-       tpdu.data.deliver.originAddress.npi = submitData.destAddress.npi;
+               } else { // DELIVER MSG
+                       SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), i);
 
-       memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, addLen);
-       tpdu.data.deliver.originAddress.address[addLen] = '\0';
+                       int addLen = strlen(submitData.destAddress.address);
 
-       for (unsigned int segCnt = 0; segCnt < submitData.segCount; segCnt++)
-       {
-               tpdu.data.deliver.userData.length = submitData.userData[segCnt].length;
-               memcpy(tpdu.data.deliver.userData.data, submitData.userData[segCnt].data, submitData.userData[segCnt].length);
+                       tpdu.data.deliver.originAddress.ton = submitData.destAddress.ton;
+                       tpdu.data.deliver.originAddress.npi = submitData.destAddress.npi;
 
-               memset(buf, 0x00, sizeof(buf));
+                       if (addLen < MAX_ADDRESS_LEN) {
+                               memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, addLen);
+                               tpdu.data.deliver.originAddress.address[addLen] = '\0';
+                       } else {
+                               memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN);
+                               tpdu.data.deliver.originAddress.address[MAX_ADDRESS_LEN] = '\0';
+                       }
+               }
 
-               // Encode SMS-DELIVER TPDU
-               bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
+               // Check sim message full.
+               if (checkSimMsgFull(pMsgInfo->sim_idx, submitData.segCount) == true)
+               {
+                       MSG_DEBUG("SIM storage is full.");
+                       MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);
 
-               // Make Telephony Structure
-               TelSmsData_t simSmsData;
-               memset((void*)&simSmsData, 0x00, sizeof(simSmsData));
+                       return MSG_ERR_SIM_STORAGE_FULL;
+               }
 
-               // Set TPDU data
-               memcpy((void*)simSmsData.SmsData.szData, buf, bufLen);
+               if(submitData.segCount > 1)
+               {
+                       if(pMsgInfo->direction == MSG_DIRECTION_TYPE_MO){ // SUBMIT MSG
+                               tpdu.data.submit.bHeaderInd = true;
+                       } else {
+                               tpdu.data.deliver.bHeaderInd = true;
+                       }
 
-               simSmsData.SmsData.szData[bufLen] = 0;
-               simSmsData.SmsData.MsgLength = bufLen;
+               }
 
-#ifdef MSG_FOR_DEBUG
-               MSG_DEBUG("Sim Message.");
-               for (int j = 0; j < simSmsData.SmsData.MsgLength; j++)
+               for (unsigned int segCnt = 0; segCnt < submitData.segCount; segCnt++)
                {
-                       MSG_DEBUG("[%02x]", simSmsData.SmsData.szData[j]);
-               }
-#endif
+                       if(pMsgInfo->direction == MSG_DIRECTION_TYPE_MO){
+                               memcpy(&(tpdu.data.submit.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S));
+                       } else {
+                               memcpy(&(tpdu.data.deliver.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S));
+                       }
 
-               MSG_DEBUG("Read Status [%d]", pMsgInfo->bRead);
+                       memset(buf, 0x00, sizeof(buf));
+
+                       // Encode SMS-DELIVER TPDU
+                       bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
+
+                       // Make Telephony Structure
+                       TelSmsData_t simSmsData;
+                       memset((void*)&simSmsData, 0x00, sizeof(simSmsData));
+
+                       // Set TPDU data
+                       memcpy((void*)simSmsData.SmsData.szData, buf, bufLen);
+
+                       simSmsData.SmsData.szData[bufLen] = 0;
+                       simSmsData.SmsData.MsgLength = bufLen;
+
+                       if(pMsgInfo->direction == MSG_DIRECTION_TYPE_MT) { // MT messages
+                               if (pMsgInfo->bRead == true)
+                                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_READ;
+                               else
+                                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
+                       } else { // MO messages
+                               if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS)
+                                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_SENT;
+                               else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_SUCCESS)
+                                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_DELIVERED;
+                               else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_FAIL)
+                                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_DELIVERY_UNCONFIRMED;
+                               else
+                                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNSENT;
+                       }
 
-               if (pMsgInfo->bRead == true)
-                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_READ;
-               else
-                       simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
+                       // Save SMS in SIM
+                       int ret = 0;
 
-               // Save SMS in SIM
-               int ret = 0;
+                       ret = tel_write_sms_in_sim(handle, &simSmsData, TapiEventSaveSimMsg, NULL);
 
-               ret = tel_write_sms_in_sim(pTapiHandle, &simSmsData, TapiEventSaveSimMsg, NULL);
+                       if (ret == TAPI_API_SUCCESS)
+                       {
+                               MSG_DEBUG("########  tel_write_sms_in_sim Success !!!#######");
+                       }
+                       else
+                       {
+                               MSG_DEBUG("########  tel_write_sms_in_sim Fail !!! return : [%d] #######", ret);
 
-               if (ret == TAPI_API_SUCCESS)
-               {
-                       MSG_DEBUG("########  tel_write_sms_in_sim Success !!!#######");
-               }
-               else
-               {
-                       MSG_DEBUG("########  tel_write_sms_in_sim Fail !!! return : [%d] #######", ret);
+                               return MSG_ERR_PLUGIN_STORAGE;
+                       }
 
-                       return MSG_ERR_PLUGIN_STORAGE;
-               }
+                       msg_sim_id_t SimId = 0;
 
-               msg_sim_id_t SimId = 0;
+                       bool bResult = false;
 
-               bool bResult = false;
+                       bResult = getSimEvent(&SimId);
 
-               bResult = getSimEvent(&SimId);
+                       int usedCnt = 0;
 
-               int usedCnt = 0;
+                       if (bResult == true)
+                       {
+                               MSG_DEBUG("########  Saving Msg was Successful !!! SIM ID : [%d] #######", SimId);
 
-               if (bResult == true)
-               {
-                       MSG_DEBUG("########  Saving Msg was Successful !!! SIM ID : [%d] #######", SimId);
+                               char keyName[MAX_VCONFKEY_NAME_LEN];
+                               memset(keyName, 0x00, sizeof(keyName));
+                               sprintf(keyName, "%s/%d", SIM_USED_COUNT, pMsgInfo->sim_idx);
+                               usedCnt = MsgSettingGetInt(keyName);
 
-                       usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
+                               usedCnt++;
 
-                       usedCnt++;
+                               if (MsgSettingSetInt(keyName, usedCnt) != MSG_SUCCESS)
+                               {
+                                       MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
+                               }
 
-                       if (MsgSettingSetInt(SIM_USED_COUNT, usedCnt) != MSG_SUCCESS)
-                       {
-                               MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
+                               pSimIdList->simId[pSimIdList->count] = SimId;
+                               pSimIdList->count++;
                        }
+                       else
+                       {
+                               MSG_DEBUG("########  Saving Msg was Failed !!! SIM ID : [%d] #######", SimId);
 
-                       pSimIdList->simId[pSimIdList->count] = SimId;
-                       pSimIdList->count++;
-               }
-               else
-               {
-                       MSG_DEBUG("########  Saving Msg was Failed !!! SIM ID : [%d] #######", SimId);
-
-                       return MSG_ERR_PLUGIN_STORAGE;
+                               return MSG_ERR_PLUGIN_STORAGE;
+                       }
                }
        }
-
        return MSG_SUCCESS;
 }
 
 
 msg_error_t SmsPluginSimMsg::saveClass2Message(const MSG_MESSAGE_INFO_S *pMsgInfo)
 {
+
+       msg_error_t err = MSG_SUCCESS;
+       bool bSimSst = true;
+       int tapiRet = TAPI_API_SUCCESS;
+       int simId = -1;
+       int replaceSimId = -1;
+       int replaceMsgId = 0;
+
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(pMsgInfo->sim_idx);
+
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, pMsgInfo->sim_idx);
+       if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingGetBool [%s] failed", keyName);
+       /* No return, default value is true. */
+
+       if (bSimSst == false)
+       {
+               SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
+               return MSG_SUCCESS;
+       }
+
        // Reset Flag
        SMS_TPDU_S tpdu;
 
        tpdu.tpduType = SMS_TPDU_DELIVER;
 
+       convertTimeStamp(pMsgInfo, &(tpdu.data.deliver));
+
        // Set SMS TPDU Options
        setSmsOptions(&(tpdu.data.deliver));
 
@@ -243,14 +359,40 @@ msg_error_t SmsPluginSimMsg::saveClass2Message(const MSG_MESSAGE_INFO_S *pMsgInf
        SMS_SUBMIT_DATA_S submitData;
        SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), 0);
 
-       // Check sim message full.
-       if (checkSimMsgFull(submitData.segCount) == true)
-       {
-               MSG_DEBUG("SIM storage is full.");
 
-               SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_SIM_STORAGE_FULL);
+       if (pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS && pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS) {
+               err = SmsPluginStorage::instance()->getReplaceSimMsg(pMsgInfo, &replaceMsgId, &replaceSimId);
+               MSG_DEBUG("getReplaceSimMsg(): err=[%d], Replace Sim Id = [%d], Replace message id = [%d]", err, replaceSimId, replaceMsgId);
+               if (replaceMsgId < 0)
+                       replaceMsgId = 0;
+       }
+
+       // Check SIM ID
+       if (replaceSimId < 0) { // Normal message type
+               // Check sim message full.
+               if (checkSimMsgFull(pMsgInfo->sim_idx, submitData.segCount) == true)
+               {
+                       MSG_DEBUG("SIM storage is full.");
+
+                       SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_ERR_SIM_STORAGE_FULL);
+
+                       return MSG_ERR_SIM_STORAGE_FULL;
+               }
+       } else { // Replace message type
+               tapiRet = tel_delete_sms_in_sim(handle, replaceSimId, TapiEventDeleteSimMsg, NULL);
+
+               if (tapiRet == TAPI_API_SUCCESS) {
+                       MSG_DEBUG("########  tel_delete_sms_in_sim Success !!! #######");
+
+                       simId = -1;
+                       if(getDelSimEvent(&simId) == true) {
+                               err = SmsPluginStorage::instance()->deleteSimMessage(pMsgInfo->sim_idx, replaceSimId);
+                       }
+                       MSG_DEBUG("tel_delete_sms_in_sim() : Err=[%d], Replace Sim Id=[%d], Result Sim id=[%d]", err, replaceSimId, simId);
 
-               return MSG_ERR_SIM_STORAGE_FULL;
+               } else {
+                       MSG_DEBUG("########  tel_delete_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
+               }
        }
 
        // Create TelSmsData_t data
@@ -263,36 +405,41 @@ msg_error_t SmsPluginSimMsg::saveClass2Message(const MSG_MESSAGE_INFO_S *pMsgInf
        // Set message status
        simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
 
-       // Save Class 2 Msg in SIM
-       int tapiRet = TAPI_API_SUCCESS;
+       MSG_MESSAGE_INFO_S *tmpSimMsgInfo = (MSG_MESSAGE_INFO_S *)calloc(1, sizeof(MSG_MESSAGE_INFO_S));
+       memcpy(tmpSimMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
 
-       tapiRet = tel_write_sms_in_sim(pTapiHandle, &simSmsData, TapiEventSaveClass2Msg, NULL);
+       tmpSimMsgInfo->msgId = replaceMsgId;
 
-       if (tapiRet == TAPI_API_SUCCESS)
-       {
-               memset(&simMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
-               memcpy(&simMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+       tmpSimMsgInfo->addressList = NULL;
+       tmpSimMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memcpy(&tmpSimMsgInfo->addressList[0], &pMsgInfo->addressList[0], sizeof(MSG_ADDRESS_INFO_S));
+
+       tapiRet = tel_write_sms_in_sim(handle, &simSmsData, TapiEventSaveClass2Msg, tmpSimMsgInfo);
 
+       if (tapiRet == TAPI_API_SUCCESS) {
                MSG_DEBUG("########  tel_write_sms_in_sim Success !!! #######");
-       }
-       else
-       {
+       } else {
                MSG_DEBUG("########  tel_write_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
 
-               SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_STORAGE_ERROR);
+               SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_ERR_STORAGE_ERROR);
 
                return MSG_ERR_PLUGIN_STORAGE;
        }
 
+       msg_sim_id_t retSimId;
+       if(!getSimEvent(&retSimId))
+               return MSG_ERR_PLUGIN_STORAGE;
+
        return MSG_SUCCESS;
 }
 
 
-void SmsPluginSimMsg::deleteSimMessage(msg_sim_id_t SimMsgId)
+void SmsPluginSimMsg::deleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
 {
        int tapiRet = TAPI_API_SUCCESS;
 
-       tapiRet = tel_delete_sms_in_sim(pTapiHandle, (int)SimMsgId, TapiEventDeleteSimMsg, NULL);
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(sim_idx);
+       tapiRet = tel_delete_sms_in_sim(handle, (int)SimMsgId, TapiEventDeleteSimMsg, NULL);
 
        if (tapiRet == TAPI_API_SUCCESS)
        {
@@ -303,23 +450,27 @@ void SmsPluginSimMsg::deleteSimMessage(msg_sim_id_t SimMsgId)
                THROW(MsgException::SMS_PLG_ERROR, "########  tel_delete_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
        }
 
-       msg_sim_id_t SimId = 0;
+       int SimId = 0;
        bool bResult = false;
 
-       bResult = getSimEvent(&SimId);
+       bResult = getDelSimEvent(&SimId);
 
        int usedCnt = 0, totalCnt = 0;
 
        if (bResult == true)
        {
                MSG_DEBUG("########  Deleting Msg was Successful !!! SIM ID : [%d] #######", SimId);
-
-               usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
-               totalCnt = MsgSettingGetInt(SIM_TOTAL_COUNT);
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+               memset(keyName, 0x00, sizeof(keyName));
+               sprintf(keyName, "%s/%d", SIM_USED_COUNT, sim_idx);
+               usedCnt = MsgSettingGetInt(keyName);
+               memset(keyName, 0x00, sizeof(keyName));
+               sprintf(keyName, "%s/%d", SIM_TOTAL_COUNT, sim_idx);
+               totalCnt = MsgSettingGetInt(keyName);
 
                if (usedCnt == totalCnt)
                {
-                       tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, NULL, NULL);
+                       tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, NULL, NULL);
 
                        if (tapiRet == TAPI_API_SUCCESS)
                        {
@@ -333,9 +484,12 @@ void SmsPluginSimMsg::deleteSimMessage(msg_sim_id_t SimMsgId)
 
                usedCnt--;
 
-               if (MsgSettingSetInt(SIM_USED_COUNT, usedCnt) != MSG_SUCCESS)
+               memset(keyName, 0x00, sizeof(keyName));
+               sprintf(keyName, "%s/%d", SIM_USED_COUNT, sim_idx);
+
+               if (MsgSettingSetInt(keyName, usedCnt) != MSG_SUCCESS)
                {
-                       MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
+                       MSG_DEBUG("Error to set config data [%s]", keyName);
                }
        }
        else
@@ -345,12 +499,17 @@ void SmsPluginSimMsg::deleteSimMessage(msg_sim_id_t SimMsgId)
 }
 
 
-bool SmsPluginSimMsg::checkSimMsgFull(unsigned int SegCnt)
+bool SmsPluginSimMsg::checkSimMsgFull(msg_sim_slot_id_t sim_idx, unsigned int SegCnt)
 {
        int usedCnt = 0, totalCnt = 0;
 
-       usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
-       totalCnt = MsgSettingGetInt(SIM_TOTAL_COUNT);
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       sprintf(keyName, "%s/%d", SIM_USED_COUNT, sim_idx);
+       usedCnt = MsgSettingGetInt(keyName);
+       memset(keyName, 0x00, sizeof(keyName));
+       sprintf(keyName, "%s/%d", SIM_TOTAL_COUNT, sim_idx);
+       totalCnt = MsgSettingGetInt(keyName);
 
        MSG_DEBUG("Segment Count [%d]", SegCnt);
        MSG_DEBUG("usedCnt [%d], totalCnt [%d]", usedCnt, totalCnt);
@@ -362,13 +521,14 @@ bool SmsPluginSimMsg::checkSimMsgFull(unsigned int SegCnt)
 }
 
 
-void SmsPluginSimMsg::setReadStatus(msg_sim_id_t SimMsgId)
+void SmsPluginSimMsg::setReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
 {
        MSG_DEBUG("Sim Message ID [%d]", SimMsgId);
 
        int ret = TAPI_API_SUCCESS;
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(sim_idx);
 
-       ret = tel_set_sms_message_status(pTapiHandle, (int)SimMsgId, TAPI_NETTEXT_STATUS_READ, TapiEventSetMsgStatus, (void *)&SimMsgId);
+       ret = tel_set_sms_message_status(handle, (int)SimMsgId, TAPI_NETTEXT_STATUS_READ, TapiEventSetMsgStatus, (void *)&SimMsgId);
 
        if (ret == TAPI_API_SUCCESS)
        {
@@ -395,11 +555,11 @@ void SmsPluginSimMsg::setReadStatus(msg_sim_id_t SimMsgId)
 }
 
 
-void SmsPluginSimMsg::getSimMsgCount(MSG_SIM_COUNT_S *pSimMsgCnt)
+void SmsPluginSimMsg::getSimMsgCount(struct tapi_handle *handle, MSG_SIM_COUNT_S *pSimMsgCnt)
 {
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_get_sms_count(pTapiHandle, TapiEventGetSimMsgCnt, NULL);
+       ret = tel_get_sms_count(handle, TapiEventGetSimMsgCnt, NULL);
 
        if (ret == TAPI_API_SUCCESS)
        {
@@ -410,7 +570,7 @@ void SmsPluginSimMsg::getSimMsgCount(MSG_SIM_COUNT_S *pSimMsgCnt)
                THROW(MsgException::SMS_PLG_ERROR, "########  tel_get_sms_count() Fail !!! return : %d #######", ret);
        }
 
-       if (getSimMsgCntEvent(pSimMsgCnt) == true)
+       if (getSimMsgCntEvent(handle, pSimMsgCnt) == true)
        {
                MSG_DEBUG("######## Get Sim Msg Count was Successful !!! #######");
        }
@@ -421,11 +581,11 @@ void SmsPluginSimMsg::getSimMsgCount(MSG_SIM_COUNT_S *pSimMsgCnt)
 }
 
 
-bool SmsPluginSimMsg::getSimMsg(msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S *pMsgInfo)
+bool SmsPluginSimMsg::getSimMsg(struct tapi_handle *handle, msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList)
 {
        int ret = TAPI_API_SUCCESS;
 
-       ret = tel_read_sms_in_sim(pTapiHandle, SimMsgId, TapiEventGetSimMsg, NULL);
+       ret = tel_read_sms_in_sim(handle, SimMsgId, TapiEventGetSimMsg, simIdList);
 
        if (ret == TAPI_API_SUCCESS)
        {
@@ -437,7 +597,7 @@ bool SmsPluginSimMsg::getSimMsg(msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S *pMsgI
                return false;
        }
 
-       if (getSimMsgEvent(pMsgInfo) == true)
+       if (getSimMsgEvent(handle, pMsgInfo) == true)
        {
                MSG_DEBUG("######## Get Sim Msg was Successful !!! #######");
        }
@@ -481,7 +641,8 @@ void SmsPluginSimMsg::convertTimeStamp(const MSG_MESSAGE_INFO_S* pMsgInfo, SMS_D
 
        // encode absolute time
        struct tm timeinfo = {0,};
-       gmtime_r(&pMsgInfo->displayTime, &timeinfo);
+       tzset();
+       localtime_r(&pMsgInfo->displayTime, &timeinfo);
 
        pDeliver->timeStamp.time.absolute.year = timeinfo.tm_year - 100;
        MSG_DEBUG("pDeliver->timeStamp.time.absolute.year is %d",pDeliver->timeStamp.time.absolute.year);
@@ -508,23 +669,29 @@ void SmsPluginSimMsg::convertTimeStamp(const MSG_MESSAGE_INFO_S* pMsgInfo, SMS_D
 }
 
 
-void SmsPluginSimMsg::setSimMsgCntEvent(const MSG_SIM_COUNT_S *pSimMsgCnt)
+void SmsPluginSimMsg::setSimMsgCntEvent(struct tapi_handle *handle, const MSG_SIM_COUNT_S *pSimMsgCnt)
 {
        mx.lock();
 
        MSG_DEBUG("Sim Message Count is %d.", pSimMsgCnt->usedCount);
 
+       int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
+       char keyName[MAX_VCONFKEY_NAME_LEN]= {0,};
+
        for (int i=0; i < pSimMsgCnt->usedCount; i++)
        {
                MSG_DEBUG("Sim Message Index is %d.", pSimMsgCnt->indexList[i]);
        }
 
-       if (MsgSettingSetInt(SIM_USED_COUNT, pSimMsgCnt->usedCount) != MSG_SUCCESS)
+       sprintf(keyName, "%s/%d", SIM_USED_COUNT, sim_idx);
+       if (MsgSettingSetInt(keyName, pSimMsgCnt->usedCount) != MSG_SUCCESS)
        {
                MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
        }
 
-       if (MsgSettingSetInt(SIM_TOTAL_COUNT, (int)pSimMsgCnt->totalCount) != MSG_SUCCESS)
+       memset(keyName, 0, sizeof(keyName));
+       sprintf(keyName, "%s/%d", SIM_TOTAL_COUNT, sim_idx);
+       if (MsgSettingSetInt(keyName, (int)pSimMsgCnt->totalCount) != MSG_SUCCESS)
        {
                MSG_DEBUG("Error to set config data [%s]", SIM_TOTAL_COUNT);
        }
@@ -538,7 +705,7 @@ void SmsPluginSimMsg::setSimMsgCntEvent(const MSG_SIM_COUNT_S *pSimMsgCnt)
 }
 
 
-bool SmsPluginSimMsg::getSimMsgCntEvent(MSG_SIM_COUNT_S *pSimMsgCnt)
+bool SmsPluginSimMsg::getSimMsgCntEvent(struct tapi_handle *handle, MSG_SIM_COUNT_S *pSimMsgCnt)
 {
        int ret = 0;
 
@@ -559,19 +726,22 @@ bool SmsPluginSimMsg::getSimMsgCntEvent(MSG_SIM_COUNT_S *pSimMsgCnt)
        return true;
 }
 
-void SmsPluginSimMsg::setSimMsgEvent(const MSG_MESSAGE_INFO_S *pMsgInfo, bool bSuccess)
+void SmsPluginSimMsg::setSimMsgEvent(struct tapi_handle *handle, const MSG_MESSAGE_INFO_S *pMsgInfo, bool bSuccess)
 {
        mx.lock();
 
        bTapiResult = bSuccess;
 
        memset(&simMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+       memset(&simAddrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
 
        if (bTapiResult  == true)
        {
                MSG_DEBUG("Success to get sim msg - Id : [%d]", pMsgInfo->msgId);
 
                memcpy(&simMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+               simMsgInfo.addressList = &simAddrInfo;
+               memcpy(&simAddrInfo,pMsgInfo->addressList, sizeof(MSG_ADDRESS_INFO_S));
        }
 
        cv.signal();
@@ -580,7 +750,7 @@ void SmsPluginSimMsg::setSimMsgEvent(const MSG_MESSAGE_INFO_S *pMsgInfo, bool bS
 }
 
 
-bool SmsPluginSimMsg::getSimMsgEvent(MSG_MESSAGE_INFO_S *pMsgInfo)
+bool SmsPluginSimMsg::getSimMsgEvent(struct tapi_handle *handle, MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        int ret = 0;
 
@@ -602,20 +772,25 @@ bool SmsPluginSimMsg::getSimMsgEvent(MSG_MESSAGE_INFO_S *pMsgInfo)
        if (bTapiResult == true)
        {
                memcpy(pMsgInfo, &simMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+               pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)calloc(1, sizeof(MSG_ADDRESS_INFO_S));
+               memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+               memcpy(pMsgInfo->addressList, simMsgInfo.addressList, sizeof(MSG_ADDRESS_INFO_S));
+               pMsgInfo->sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
        }
 
+
        return bTapiResult;
 }
 
 
-void SmsPluginSimMsg::setSaveSimMsgEvent(int simMsgId, int result)
+void SmsPluginSimMsg::setSaveSimMsgEvent(struct tapi_handle *handle, int simId, int result)
 {
        msg_error_t err = MSG_SUCCESS;
 
        mx.lock();
 
        if (result != TAPI_NETTEXT_SENDSMS_SUCCESS) {
-               if (result == TAPI_NETTEXT_ROUTING_NOT_AVAILABLE)
+               if (result == TAPI_NETTEXT_ROUTING_NOT_AVAILABLE || result == TAPI_NETTEXT_SIM_FULL)
                        err = MSG_ERR_SIM_STORAGE_FULL;
                else
                        err = MSG_ERR_UNKNOWN;
@@ -626,58 +801,95 @@ void SmsPluginSimMsg::setSaveSimMsgEvent(int simMsgId, int result)
        else
                bTapiResult = false;
 
+       simMsgId = simId;
+
        cv.signal();
 
        mx.unlock();
 
-       // Send Deliver Report
-       SmsPluginTransport::instance()->sendDeliverReport(err);
+       int tapiRet = TAPI_API_SUCCESS;
 
+       if (err == MSG_SUCCESS) {
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, TapiEventMemoryStatus, NULL);
+       } else if (err == MSG_ERR_SIM_STORAGE_FULL) {
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
+       } else {
+               return;
+       }
+
+       if (tapiRet == TAPI_API_SUCCESS) {
+               MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! #######");
+       } else {
+               MSG_DEBUG("########  tel_set_sms_memory_status() Failed !!! return : [%d] #######", tapiRet);
+       }
 }
 
 
-void SmsPluginSimMsg::setSaveClass2MsgEvent(int simMsgId, int result)
+void SmsPluginSimMsg::setSaveClass2MsgEvent(struct tapi_handle *handle, int simId, int result, MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        msg_error_t err = MSG_SUCCESS;
+//     int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
 
-       if (result == TAPI_NETTEXT_SENDSMS_SUCCESS && simMsgId >= 0) {
+       if (result == TAPI_NETTEXT_SENDSMS_SUCCESS && simId >= 0 && pMsgInfo) {
 
-               simMsgInfo.msgId = simMsgId;
+               int simIdList[MAX_SIM_SMS_NUM];
+               bool isNewSimMsg = true;
+               memset(simIdList, 0, sizeof(int) * MAX_SIM_SMS_NUM);
+               simIdList[0] = simId + 1;
 
-               err = SmsPluginStorage::instance()->addSimMessage(&simMsgInfo);
+               if (pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS && pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS) {
+                       if (pMsgInfo->msgId > 0) {
+                               isNewSimMsg = false;
+                       }
+               }
 
-               if (err == MSG_SUCCESS)
-               {
-                       MSG_DEBUG("addSimMessage() Success !!");
+               msg_message_id_t saved_msg_id = 0;
+               SmsPluginEventHandler::instance()->handleSimMsg(pMsgInfo, simIdList, &saved_msg_id, MAX_SIM_SMS_NUM);
 
-                       // Callback
-                       err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&simMsgInfo);
+               MSG_DEBUG("Saved message ID = [%d]", saved_msg_id);
 
-                       if (err != MSG_SUCCESS)
-                       {
-                               MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
-                       }
+#ifndef MSG_NOTI_INTEGRATION
+               if (saved_msg_id > 0)
+                       pMsgInfo->msgId = saved_msg_id;
+#else
+               pMsgInfo->msgId = 0;
+#endif
 
-                       usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
+               err = SmsPluginEventHandler::instance()->callbackMsgIncoming(pMsgInfo);
 
+               if (err != MSG_SUCCESS)
+               {
+                       MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
+               }
+
+               if (isNewSimMsg == true) {
+                       char keyName[MAX_VCONFKEY_NAME_LEN];
+                       sprintf(keyName, "%s/%d", SIM_USED_COUNT, pMsgInfo->sim_idx);
+                       usedCnt = MsgSettingGetInt(keyName);
                        usedCnt++;
 
-                       if (MsgSettingSetInt(SIM_USED_COUNT, usedCnt) != MSG_SUCCESS)
+                       if (MsgSettingSetInt(keyName, usedCnt) != MSG_SUCCESS)
                        {
                                MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
                        }
-               } else  {
-                       MSG_DEBUG("addMessage() Error !! [%d]", err);
                }
+
        } else {
+#if 0
                        if (result == TAPI_NETTEXT_ROUTING_NOT_AVAILABLE)
                                err = MSG_ERR_SIM_STORAGE_FULL;
                        else
                                err = MSG_ERR_UNKNOWN;
+#else
+                       if (result == TAPI_NETTEXT_SIM_FULL)
+                               err = MSG_ERR_SIM_STORAGE_FULL;
+                       else
+                               err = MSG_ERR_UNKNOWN;
+#endif
        }
 
        // Send Deliver Report
-       SmsPluginTransport::instance()->sendDeliverReport(err);
+       SmsPluginTransport::instance()->sendDeliverReport(handle, err);
 }
 
 
@@ -718,6 +930,46 @@ bool SmsPluginSimMsg::getSimEvent(msg_sim_id_t *pSimId)
        return bTapiResult;
 }
 
+
+void SmsPluginSimMsg::setDelSimEvent(int SimId, bool bResult)
+{
+       mx.lock();
+
+       delSimMsgId = SimId;
+       bTapiResult = bResult;
+
+       cv.signal();
+
+       mx.unlock();
+}
+
+
+bool SmsPluginSimMsg::getDelSimEvent(int *pSimId)
+{
+       int ret = 0;
+
+       mx.lock();
+
+       delSimMsgId = -1;
+       bTapiResult = false;
+       ret = cv.timedwait(mx.pMutex(), 10);
+
+       mx.unlock();
+
+       if (ret == ETIMEDOUT)
+       {
+               MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
+               return false;
+       }
+
+       *pSimId = delSimMsgId;
+
+       MSG_DEBUG("Returned delSimMsgId is %d.", delSimMsgId);
+
+       return bTapiResult;
+}
+
+
 void SmsPluginSimMsg::setSmsData(const char *sca, const char *szData, int msgLength)
 {
        MSG_DEBUG("Set SMS data(class2 message)");
index 94ab0ff..461c279 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
@@ -22,6 +22,7 @@
 #include "MsgContact.h"
 #include "MsgUtilFile.h"
 #include "MsgUtilStorage.h"
+#include "MsgUtilFunction.h"
 #include "MsgGconfWrapper.h"
 #include "MsgNotificationWrapper.h"
 #include "SmsPluginMain.h"
@@ -38,7 +39,7 @@ SmsPluginStorage* SmsPluginStorage::pInstance = NULL;
 SmsPluginStorage::SmsPluginStorage()
 {
 /*** No need to connect DB anymore.
-       if (dbHandle.connect() != MSG_SUCCESS) {
+       if (dbHandle->connect() != MSG_SUCCESS) {
                MSG_DEBUG("DB Connect Fail");
        }
 ***/
@@ -47,9 +48,7 @@ SmsPluginStorage::SmsPluginStorage()
 
 SmsPluginStorage::~SmsPluginStorage()
 {
-       if (dbHandle.disconnect() != MSG_SUCCESS) {
-               MSG_DEBUG("DB Disconnect Fail");
-       }
+
 }
 
 
@@ -64,13 +63,157 @@ SmsPluginStorage* SmsPluginStorage::instance()
 }
 
 
+msg_error_t SmsPluginStorage::insertMsgRef(MSG_MESSAGE_INFO_S *pMsg, unsigned char msgRef, int index)
+{
+       MSG_BEGIN();
+
+       time_t curTime = time(NULL);
+
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       char *normalNum = NULL;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       normalNum = msg_normalize_number(pMsg->addressList[index].addressVal);
+
+       MSG_SEC_DEBUG("Insert MsgID=[%d], Address=[%s], MsgRef=[%d], Time=[%d]", \
+                       pMsg->msgId, normalNum, (int)msgRef, (int)curTime);
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %s, %d, 0, -1, %d);",
+                       MSGFW_SMS_REPORT_TABLE_NAME, pMsg->msgId, normalNum, (int)msgRef, (int)curTime);
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgExecQuery() : [%s]", sqlQuery);
+               return MSG_ERR_DB_EXEC;
+       }
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+
+}
+
+
+msg_error_t SmsPluginStorage::updateMsgDeliverStatus(MSG_MESSAGE_INFO_S *pMsgInfo, unsigned char msgRef)
+{
+       MSG_BEGIN();
+
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       msg_message_id_t msgId = 0;
+       int rowCnt = 0;
+       char *normalNum = NULL;
+
+       normalNum = msg_normalize_number(pMsgInfo->addressList[0].addressVal);
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE ADDRESS_VAL = %s AND MSG_REF > 0 ORDER BY TIME ASC;",
+                       MSGFW_SMS_REPORT_TABLE_NAME, normalNum);
+       MSG_DEBUG("[SQL Query] %s", sqlQuery);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
+
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
+               msgId = dbHandle->columnInt(0);
+
+       dbHandle->finalizeQuery();
+
+       pMsgInfo->msgId = msgId;
+
+       /** Update Status - MSG_MESSAGE_TABLE */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE MSG_ID = %d AND MSG_REF > 0;",
+                       MSGFW_SMS_REPORT_TABLE_NAME, msgId);
+
+       if (dbHandle->getTable(sqlQuery, &rowCnt) != MSG_SUCCESS) {
+               dbHandle->freeTable();
+               return MSG_ERR_DB_GETTABLE;
+       }
+
+       dbHandle->freeTable();
+
+       MSG_DEBUG("Selected row count = [%d]", rowCnt);
+
+       if (rowCnt == 1 && pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_SUCCESS) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d WHERE MSG_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME, (int)pMsgInfo->networkStatus, msgId);
+               MSG_DEBUG("[SQL Query] %s", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("Query Failed : [%s]", sqlQuery);
+                       return MSG_ERR_DB_EXEC;
+               }
+       }
+
+       /** Update Status - MSG_REPORT_TABLE */
+       if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_SUCCESS) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
+                               MSGFW_SMS_REPORT_TABLE_NAME, 1, (int)pMsgInfo->displayTime, msgId, normalNum);
+               MSG_DEBUG("[SQL Query] %s", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("Query Failed : [%s]", sqlQuery);
+                       return MSG_ERR_DB_EXEC;
+               }
+       } else if(pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_EXPIRED) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
+                               MSGFW_SMS_REPORT_TABLE_NAME, 0, (int)pMsgInfo->displayTime, msgId, normalNum);
+               MSG_DEBUG("[SQL Query] %s", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("Query Failed : [%s]", sqlQuery);
+                       return MSG_ERR_DB_EXEC;
+               }
+       } else if(pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_PENDING) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
+                               MSGFW_SMS_REPORT_TABLE_NAME, 3, (int)pMsgInfo->displayTime, msgId, normalNum);
+               MSG_DEBUG("[SQL Query] %s", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("Query Failed : [%s]", sqlQuery);
+                       return MSG_ERR_DB_EXEC;
+               }
+       } else if(pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_FAIL) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, STATUS = %d, TIME = %d WHERE MSG_ID = %d and ADDRESS_VAL = '%s';",
+                               MSGFW_SMS_REPORT_TABLE_NAME, 8, (int)pMsgInfo->displayTime, msgId, normalNum);
+               MSG_DEBUG("[SQL Query] %s", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("Query Failed : [%s]", sqlQuery);
+                       return MSG_ERR_DB_EXEC;
+               }
+       }
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
 msg_error_t SmsPluginStorage::updateSentMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_network_status_t status)
 {
        MSG_BEGIN();
 
+       if (!pMsgInfo || (pMsgInfo && pMsgInfo->msgId <= 0)) {
+               MSG_DEBUG("Invalid message id");
+               return MSG_ERR_INVALID_MESSAGE_ID;
+       }
+
 /***  Comment below line to not save the time value after sent status (it could be used later.)
        time_t curTime = time(NULL);
 ***/
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -82,11 +225,11 @@ msg_error_t SmsPluginStorage::updateSentMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_ne
                snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d, FOLDER_ID = %d WHERE MSG_ID = %d;",
                                        MSGFW_MESSAGE_TABLE_NAME, status, MSG_SENTBOX_ID, pMsgInfo->msgId);
        } else {
-               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d WHERE MSG_ID = %d;",
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d, READ_STATUS = 0 WHERE MSG_ID = %d;",
                                        MSGFW_MESSAGE_TABLE_NAME, status, pMsgInfo->msgId);
        }
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("MsgExecQuery() : [%s]", sqlQuery);
                return MSG_ERR_DB_EXEC;
        }
@@ -96,7 +239,6 @@ msg_error_t SmsPluginStorage::updateSentMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_ne
                MsgAddPhoneLog(pMsgInfo);
        }
 
-
        MSG_END();
 
        return MSG_SUCCESS;
@@ -107,6 +249,8 @@ msg_error_t SmsPluginStorage::updateMsgRef(msg_message_id_t MsgId, unsigned char
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -114,7 +258,7 @@ msg_error_t SmsPluginStorage::updateMsgRef(msg_message_id_t MsgId, unsigned char
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = %d WHERE MSG_ID = %d;",
                                MSGFW_REPORT_TABLE_NAME, (int)MsgRef, MsgId);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("Query Failed : [%s]", sqlQuery);
                return MSG_ERR_DB_EXEC;
        }
@@ -136,6 +280,8 @@ msg_error_t SmsPluginStorage::updateStatusReport(unsigned char MsgRef, msg_deliv
 
        MSG_DEBUG("tmpMsgRef : %d", tmpMsgRef);
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
        /** Get Msg Id for Quickpanel Noti */
@@ -145,20 +291,20 @@ msg_error_t SmsPluginStorage::updateStatusReport(unsigned char MsgRef, msg_deliv
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MSG_REF = %d;",
                                        MSGFW_REPORT_TABLE_NAME, (int)tmpMsgRef);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW)
-               msgId = dbHandle.columnInt(0);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW)
+               msgId = dbHandle->columnInt(0);
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
        /** Update Status */
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, DELIVERY_REPORT_STATUS = %d, DELIVERY_REPORT_TIME = %lu WHERE MSG_REF = %d;",
                                        MSGFW_REPORT_TABLE_NAME, Status, DeliveryTime, (int)tmpMsgRef);
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("Query Failed : [%s]", sqlQuery);
                return MSG_ERR_DB_EXEC;
        }
@@ -166,7 +312,7 @@ msg_error_t SmsPluginStorage::updateStatusReport(unsigned char MsgRef, msg_deliv
        /** Insert Quickpanel Noti */
        msg_error_t ret = MSG_SUCCESS;
 
-       ret = MsgInsertSmsNotiToQuickpanel(&dbHandle, msgId, Status);
+       ret = MsgInsertSmsNotiToQuickpanel(dbHandle, msgId, Status);
 
        if (ret != MSG_SUCCESS) {
                MSG_DEBUG("MsgInsertSmsNotiToQuickpanel() Failed : [%d]", ret);
@@ -179,61 +325,40 @@ msg_error_t SmsPluginStorage::updateStatusReport(unsigned char MsgRef, msg_deliv
 }
 #endif
 
-msg_error_t SmsPluginStorage::addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo)
+msg_error_t SmsPluginStorage::addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo, int *simIdList)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       msg_message_id_t msgId = 0;
-       msg_thread_id_t convId = 0;
        unsigned int simId = 0;
+       MsgDbHandler *dbHandle = getDbHandle();
 
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       dbHandle.beginTrans();
+//     dbHandle->beginTrans();
 
-       err = MsgStoAddAddress(&dbHandle, pSimMsgInfo, &convId);
+# if 0
+       msg_message_id_t msgId = 0;
+       msg_thread_id_t convId = 0;
+
+       err = MsgStoAddAddress(dbHandle, pSimMsgInfo, &convId);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return err;
        }
 
        pSimMsgInfo->threadId = convId;
 
-       err = dbHandle.getRowId(MSGFW_MESSAGE_TABLE_NAME, &msgId);
+       err = dbHandle->getRowId(MSGFW_MESSAGE_TABLE_NAME, &msgId);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return err;
        }
 
-       simId = pSimMsgInfo->msgId;
+       //simId = pSimMsgInfo->msgId;
        pSimMsgInfo->msgId = msgId;
 
-       SMS_CONCAT_SIM_MSG_S concatSimMsg = {0};
-
-       /** Get Data from Concat SIM Msg */
-       if (pSimMsgInfo->msgType.subType == MSG_CONCAT_SIM_SMS && pSimMsgInfo->bTextSms == false) {
-
-               int fileSize = 0;
-
-               char* pFileData = NULL;
-               AutoPtr<char> buf(&pFileData);
-
-               if (MsgOpenAndReadFile(pSimMsgInfo->msgData, &pFileData, &fileSize) == false) {
-                       dbHandle.endTrans(false);
-                       return MSG_ERR_STORAGE_ERROR;
-               }
-
-
-               memcpy(&concatSimMsg, (SMS_CONCAT_SIM_MSG_S*)pFileData, fileSize);
-
-               /** Delete temporary file */
-               MsgDeleteFile(pSimMsgInfo->msgData); /** ipc */
-
-               MSG_DEBUG("SIM ID [%d], MSG DATA [%s]", concatSimMsg.simIdCnt, concatSimMsg.msgData);
-       }
-
        /**  Add Message */
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
@@ -245,68 +370,99 @@ msg_error_t SmsPluginStorage::addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo)
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_PREPARE;
        }
 
-       dbHandle.bindText(pSimMsgInfo->subject, 1);
+       dbHandle->bindText(pSimMsgInfo->subject, 1);
 
-       if (pSimMsgInfo->msgType.subType == MSG_CONCAT_SIM_SMS && pSimMsgInfo->bTextSms == false)
-               dbHandle.bindText(concatSimMsg.msgData, 2);
-       else
-               dbHandle.bindText(pSimMsgInfo->msgText, 2);
+       dbHandle->bindText(pSimMsgInfo->msgText, 2);
 
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.endTrans(false);
+       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
+#endif
+       if(simIdList) {
+               MSG_DEBUG("simIdList exist.");
+               for(int i=0; i < MAX_SIM_SMS_NUM; ++i)
+               {
+                       if(simIdList[i]) {
+                               simId = simIdList[i] - 1;
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
+                                               MSGFW_SIM_MSG_TABLE_NAME, simId, pSimMsgInfo->msgId);
+
+                               MSG_DEBUG("QUERY : %s", sqlQuery);
+
+                               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+//                                     dbHandle->endTrans(false);
+                                       return MSG_ERR_DB_EXEC;
+                               }
+                       } else
+                               break;
+               }
+       }
+
+//     dbHandle->endTrans(true);
 
-       /** Insert to Sim table */
-       if (pSimMsgInfo->msgType.subType == MSG_CONCAT_SIM_SMS && pSimMsgInfo->bTextSms == false) {
+       return err;
 
-               MSG_DEBUG("sim count : %d", concatSimMsg.simIdCnt);
+}
 
-               for (unsigned int i = 0; i < concatSimMsg.simIdCnt; i++) {
-                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
-                                       MSGFW_SIM_MSG_TABLE_NAME, msgId, concatSimMsg.simIdList[i]);
 
-                       MSG_DEBUG("QUERY : %s", sqlQuery);
+msg_error_t SmsPluginStorage::insertSimMessage(int simId, int msgId)
+{
+       MSG_BEGIN();
 
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
-                               return MSG_ERR_DB_EXEC;
-                       }
-               }
-       } else {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
-                               MSGFW_SIM_MSG_TABLE_NAME, msgId, simId);
+       MsgDbHandler *dbHandle = getDbHandle();
 
-               MSG_DEBUG("QUERY : %s", sqlQuery);
+       char sqlQuery[MAX_QUERY_LEN+1];
 
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       return MSG_ERR_DB_EXEC;
-               }
+       dbHandle->beginTrans();
+
+       /** Insert Message into msg_sim table */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);", MSGFW_SIM_MSG_TABLE_NAME, simId, msgId);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
        }
 
-       /**  Update conversation table. */
-       if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_STORAGE_ERROR;
+       dbHandle->endTrans(true);
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPluginStorage::deleteSimMessage(int sim_idx, int simId)
+{
+       MSG_BEGIN();
+
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       dbHandle->beginTrans();
+
+       /** Delete Message from msg_sim table */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_ID = %d AND SIM_SLOT_ID = %d;", MSGFW_SIM_MSG_TABLE_NAME, simId, sim_idx);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
-       return err;
+       return MSG_SUCCESS;
 }
 
 
-msg_error_t SmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+msg_error_t SmsPluginStorage::checkMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
 
@@ -318,74 +474,58 @@ msg_error_t SmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
        if (err != MSG_SUCCESS) {
                if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
                        pMsgInfo->folderId = 0;
-                       if (addSmsMessage(pMsgInfo) != MSG_SUCCESS) {
-                               MSG_DEBUG("addSmsMessage is failed!");
-                       }
+                       err = MSG_SUCCESS;
+               }
+               else if(pMsgInfo->msgType.classType == MSG_CLASS_2 &&
+                               (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS)) {
+                       err = addClass2Message(pMsgInfo);
+               }
+               else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS){
+                       err = MSG_SUCCESS;
                }
                return err;
        }
 
-       if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS) {
+       /**  Amend message information for type **/
+       if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS \
+                       || pMsgInfo->msgType.subType == MSG_UNSAVED_SMS) {
 
-               MSG_DEBUG("Add Normal SMS");
+               MSG_DEBUG("Normal SMS");
 
                if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
-                       err = SmsPluginSimMsg::instance()->saveClass2Message(pMsgInfo);
-
-                       if (err == MSG_SUCCESS) {
-                               MSG_DEBUG("Success to saveSimMessage.");
-                       } else {
-                               MSG_DEBUG("Fail to saveSimMessage : [%d]", err);
-                       }
-               } else {
+                       err = addClass2Message(pMsgInfo);
+               } else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
                        /** Class 0 Msg should be saved in hidden folder */
-                       if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
-                               pMsgInfo->folderId = 0;
-                       }
-
-                       /**  Add into DB */
-                       err = addSmsMessage(pMsgInfo);
+                       pMsgInfo->folderId = 0;
                }
 
-       } else if ((pMsgInfo->msgType.subType == MSG_CB_SMS) || (pMsgInfo->msgType.subType == MSG_JAVACB_SMS)) {
-               /** check add message option */
-               bool bSave = false;
-               MsgSettingGetBool(CB_SAVE, &bSave);
-               if(bSave) {
-                       MSG_DEBUG("Add CB Message");
-                       err = addCbMessage(pMsgInfo);
-               }
        } else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
-               MSG_DEBUG("Add Replace SM Type [%d]", pMsgInfo->msgType.subType-3);
-               err = addReplaceTypeMsg(pMsgInfo);
+               MSG_DEBUG("Replace SM Type [%d]", pMsgInfo->msgType.subType-3);
+
+               if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
+                       err = addClass2Message(pMsgInfo);
+               } else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
+                       /** Class 0 Msg should be saved in hidden folder */
+                       pMsgInfo->folderId = 0;
+                       pMsgInfo->msgType.subType = MSG_NORMAL_SMS;
+               }
+
        } else if ((pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS) && (pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
                if (pMsgInfo->bStore == true) {
-                       MSG_DEBUG("Add MWI Message");
-                       err = addSmsMessage(pMsgInfo);
-               }
-       } else if ((pMsgInfo->msgType.subType == MSG_WAP_SI_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_CO_SMS)) {
-               MSG_DEBUG("Add WAP Push Message");
-               switch (pMsgInfo->msgType.subType)
-               {
-                       case MSG_WAP_SI_SMS:
-                       {
-                               // save push message information
-                               err = addWAPMessage(pMsgInfo);
-                       }
-                       break;
+                       MSG_DEBUG("MWI Message");
 
-                       case MSG_WAP_CO_SMS:
-                       {
-                               err = handleCOWAPMessage(pMsgInfo);
+                       if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
+                               err = addClass2Message(pMsgInfo);
                        }
-                       break;
                }
+       } else {
+               MSG_DEBUG("No matching type [%d]", pMsgInfo->msgType.subType);
        }
 
        if (err == MSG_SUCCESS) {
-               MSG_DEBUG("Success to add message !!");
+               MSG_DEBUG("Success to check message !!");
        } else {
-               MSG_DEBUG("fail to add message !! : [%d]", err);
+               MSG_DEBUG("fail to check message !! : [%d]", err);
        }
 
        return err;
@@ -399,14 +539,16 @@ msg_error_t SmsPluginStorage::addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
        unsigned int rowId = 0;
        msg_thread_id_t convId = 0;
 
-       dbHandle.beginTrans();
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       dbHandle->beginTrans();
 
        if (pMsgInfo->nAddressCnt > 0) {
 
-               err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
+               err = MsgStoAddAddress(dbHandle, pMsgInfo, &convId);
 
                if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+                       dbHandle->endTrans(false);
                        return err;
                }
 
@@ -414,154 +556,29 @@ msg_error_t SmsPluginStorage::addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
        }
 
        /**  Add Message Table */
-       rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
+       rowId = MsgStoAddMessageTable(dbHandle, pMsgInfo);
 
        if (rowId <= 0) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_ROW;
        }
 
        /** Update conversation table */
-       err = MsgStoUpdateConversation(&dbHandle, convId);
+       err = MsgStoUpdateConversation(dbHandle, convId);
 
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+               dbHandle->endTrans(false);
                return err;
        }
 
-       dbHandle.endTrans(true);
-
-       pMsgInfo->msgId = (msg_message_id_t)rowId;
-
-       MSG_END();
-
-       return MSG_SUCCESS;
-}
-
-msg_error_t SmsPluginStorage::addSmsSendOption(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
-{
-       MSG_BEGIN();
-
-       msg_error_t err = MSG_SUCCESS;
-
-       if (pSendOptInfo->bSetting == false) {
-               MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq);
-               MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath);
-
-               if (pSendOptInfo->bDeliverReq || pSendOptInfo->option.smsSendOptInfo.bReplyPath) {
-                       pSendOptInfo->bSetting = true;
-                       MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy);
-               }
-       }
-
-       if (pSendOptInfo->bSetting == true) {
-               char sqlQuery[MAX_QUERY_LEN+1];
-
-               dbHandle.beginTrans();
-
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d);",
-                               MSGFW_SMS_SENDOPT_TABLE_NAME, pMsg->msgId, pSendOptInfo->bDeliverReq,
-                               pSendOptInfo->bKeepCopy, pSendOptInfo->option.smsSendOptInfo.bReplyPath);
-
-               MSG_DEBUG("Query = [%s]", sqlQuery);
-
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       err = MSG_ERR_DB_EXEC;
-               } else {
-                       dbHandle.endTrans(true);
-               }
-       }
-
-       MSG_END();
-
-       return err;
-}
-
-
-msg_error_t SmsPluginStorage::updateSmsMessage(MSG_MESSAGE_INFO_S *pMsg)
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       msg_thread_id_t convId = 0;
-
-       dbHandle.beginTrans();
-
-       if (pMsg->nAddressCnt > 0) {
-
-               err = MsgStoAddAddress(&dbHandle, pMsg, &convId);
-
-               if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       return err;
-               }
-       }
-
-       int fileSize = 0;
-
-       char* pFileData = NULL;
-       AutoPtr<char> buf(&pFileData);
-
-       /**  Get File Data */
-       if (pMsg->bTextSms == false) {
-               if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
-                       dbHandle.endTrans(false);
-                       return MSG_ERR_STORAGE_ERROR;
-               }
-       }
-
-       /**  Update Message */
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
-                       DISPLAY_TIME = %lu, DATA_SIZE = %d, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
-                       BACKUP = %d, SUBJECT = ?, MSG_DATA = ?, THUMB_PATH = ?, MSG_TEXT = ? WHERE MSG_ID = %d;",
-                               MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
-                               pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
-
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_DB_EXEC;
-       }
-
-       dbHandle.bindText(pMsg->subject, 1);
-
-       dbHandle.bindText(pMsg->msgData, 2);
-
-       dbHandle.bindText(pMsg->thumbPath, 3);
-
-       if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
-               dbHandle.bindText(pFileData, 4);
-       else
-               dbHandle.bindText(pMsg->msgText, 4);
-
-       MSG_DEBUG("%s", sqlQuery);
-
-       if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_DB_EXEC;
-       }
-
-       dbHandle.finalizeQuery();
-
-       err = MsgStoUpdateConversation(&dbHandle, convId);
-
+       err = dbHandle->endTrans(true);
        if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_STORAGE_ERROR;
+               return err;
        }
 
-       err = MsgStoClearConversationTable(&dbHandle);
-
-       if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_STORAGE_ERROR;
-       }
+       pMsgInfo->msgId = (msg_message_id_t)rowId;
 
-       dbHandle.endTrans(true);
+       MSG_END();
 
        return MSG_SUCCESS;
 }
@@ -571,45 +588,49 @@ msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
 {
        MSG_BEGIN();
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
         /**  Get SUB_TYPE, STORAGE_ID */
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, ADDRESS_ID \
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, CONV_ID, SIM_INDEX \
                        FROM %s WHERE MSG_ID = %d;",
                        MSGFW_MESSAGE_TABLE_NAME, msgId);
 
-       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
 
        MSG_MESSAGE_TYPE_S msgType;
        msg_folder_id_t folderId;
 
        msg_thread_id_t convId;
+       msg_sim_slot_id_t simIndex;
 
-       if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-               msgType.mainType = dbHandle.columnInt(0);
-               msgType.subType = dbHandle.columnInt(1);
-               folderId = dbHandle.columnInt(2);
-               convId = dbHandle.columnInt(3);
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               msgType.mainType = dbHandle->columnInt(0);
+               msgType.subType = dbHandle->columnInt(1);
+               folderId = dbHandle->columnInt(2);
+               convId = dbHandle->columnInt(3);
+               simIndex = dbHandle->columnInt(4);
 
                MSG_DEBUG("Main Type:[%d] SubType:[%d] FolderId:[%d] ConversationId:[%d]", msgType.mainType, msgType.subType, folderId, convId);
        } else {
                MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
-               dbHandle.finalizeQuery();
+               dbHandle->finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.finalizeQuery();
+       dbHandle->finalizeQuery();
 
-       dbHandle.beginTrans();
+       dbHandle->beginTrans();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
 
        /**  Delete SMS Send Option */
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
@@ -618,8 +639,8 @@ msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
                snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_CB_MSG_TABLE_NAME, msgId);
 
                /** Delete Push Message from push table */
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
        } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
@@ -627,8 +648,8 @@ msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
                snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_PUSH_MSG_TABLE_NAME, msgId);
 
                /**  Delete Push Message from push table */
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
        } else if (msgType.subType == MSG_SYNCML_CP) {
@@ -636,479 +657,228 @@ msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
                snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
 
                /**  Delete SyncML Message from syncML table */
-               if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_EXEC;
                }
        }
 
+       /** Delete Message from msg table */
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
        snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
+       }
 
-       /** Delete Message from msg table */
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       /** Delete Message from msg_report table */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SMS_REPORT_TABLE_NAME, msgId);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
+       }
+
+       /** Delete Message from msg_sim table */
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SIM_MSG_TABLE_NAME, msgId);
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
        /**  Clear Conversation table */
-       if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (MsgStoClearConversationTable(dbHandle) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
        /**  Update conversation table.*/
-       if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
+       if (MsgStoUpdateConversation(dbHandle, convId) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
        if (folderId == MSG_INBOX_ID) {
                msgType.classType = MSG_CLASS_NONE;
 
                /**  Set memory status in SIM */
-               if (MsgStoCheckMsgCntFull(&dbHandle, &msgType, folderId) == MSG_SUCCESS) {
+               if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId, simIndex) == MSG_SUCCESS) {
                        MSG_DEBUG("Set Memory Status");
-                       SmsPlgSetMemoryStatus(MSG_SUCCESS);
+                       SmsPlgSetMemoryStatus(simIndex, MSG_SUCCESS);
                }
        }
 
-       int smsCnt = 0, mmsCnt = 0;
-
-       smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
-       mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
-
-       MsgSettingHandleNewMsg(smsCnt, mmsCnt);
-       MsgRefreshNoti(false);
+       MsgRefreshAllNotification(true, false, false);
 
        return MSG_SUCCESS;
 }
 
 
-msg_error_t SmsPluginStorage::addCbMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+msg_error_t SmsPluginStorage::addClass2Message(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
-       msg_error_t err = MSG_SUCCESS;
-
-       unsigned int rowId = 0;
-       msg_thread_id_t convId = 0;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       dbHandle.beginTrans();
-
-       if (pMsgInfo->nAddressCnt > 0) {
-               err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
+       MSG_BEGIN();
 
-               if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       return err;
-               }
+       msg_error_t err = MSG_SUCCESS;
+       pthread_t thd;
+       memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
+       memset(&addrInfo, 0, sizeof(MSG_ADDRESS_INFO_S));
+       memcpy(&msgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
+       memcpy(&addrInfo, pMsgInfo->addressList, sizeof(MSG_ADDRESS_INFO_S));
+       msgInfo.addressList = &addrInfo;
+
+       if(pthread_create(&thd, NULL, &class2_thread, (void *)&msgInfo) < 0)
+       {
+               MSG_DEBUG("pthread_create() error");
 
-               pMsgInfo->threadId = convId;
        }
+       //pthread_join(thd, (void **)&err);
+       pthread_detach(thd);
 
-       /**  Add Message Table */
-       rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
+#if 0
+       err = SmsPluginSimMsg::instance()->saveClass2Message(pMsgInfo);
 
-       if (rowId <= 0) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_DB_ROW;
+
+       if (err == MSG_SUCCESS) {
+               MSG_DEBUG("Success to saveClass2Message.");
+       } else {
+               MSG_DEBUG("Fail to saveClass2Message : [%d]", err);
        }
+#endif
 
-       /**  Get CB Msg ID */
-       unsigned short cbMsgId = (unsigned short)pMsgInfo->msgId;
+       MSG_END();
 
-       /** Add CB Msg in MSG_CBMSG_TABLE */
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       return err;
+}
 
-       sprintf(sqlQuery, "INSERT INTO %s VALUES (%d, %d);",
-                       MSGFW_CB_MSG_TABLE_NAME, rowId, cbMsgId);
+void* SmsPluginStorage::class2_thread(void *data)
+{
+       MSG_BEGIN();
 
-       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_DB_EXEC;
-       }
+       msg_error_t err = MSG_SUCCESS;
+       MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)data;
 
-       /**  Update conversation table. */
-       if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_STORAGE_ERROR;
+       err = SmsPluginSimMsg::instance()->saveClass2Message(pMsgInfo);
+       if (err == MSG_SUCCESS) {
+               MSG_DEBUG("Success to saveClass2Message.");
+       } else {
+               MSG_DEBUG("Fail to saveClass2Message : [%d]", err);
        }
 
-       dbHandle.endTrans(true);
-
-       /** Assign Msg ID */
-       pMsgInfo->msgId = (msg_message_id_t)rowId;
-
-       return err;
+       MSG_END();
+       return (void *)err;
 }
 
 
-msg_error_t SmsPluginStorage::addReplaceTypeMsg(MSG_MESSAGE_INFO_S *pMsgInfo)
+msg_error_t SmsPluginStorage::getReplaceSimMsg(const MSG_MESSAGE_INFO_S *pMsg, int *pMsgId, int *pSimId)
 {
-       msg_error_t err = MSG_SUCCESS;
+       MSG_BEGIN();
 
-       char sqlQuery[MAX_QUERY_LEN+1];
+       MsgDbHandler *dbHandle = getDbHandle();
 
-       unsigned int retCnt = 0;
+       char sqlQuery[MAX_QUERY_LEN+1];
        msg_thread_id_t convId = 0;
+       msg_message_id_t msgId = 0;
 
-       /** Check if new address or not */
-       if (MsgExistAddress(&dbHandle, pMsgInfo, &convId) == true) {
+       dbHandle->beginTrans();
+
+       if (MsgExistAddress(dbHandle, pMsg, &convId) == true) {
                MSG_DEBUG("Address Info. exists [%d]", convId);
 
-               /**  Find Replace Type Msg : Same Replace Type, Same Origin Address */
+               /**  Find Replace Type Msg : Same Replace Type, Same Origin Address, Same Storage ID */
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*), MSG_ID FROM %s WHERE SUB_TYPE = %d AND CONV_ID = %d;",
-                               MSGFW_MESSAGE_TABLE_NAME, pMsgInfo->msgType.subType, convId);
-
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s \
+                                                       WHERE CONV_ID = %d AND SUB_TYPE = %d AND STORAGE_ID = %d \
+                                                       ORDER BY DISPLAY_TIME ASC;",
+                               MSGFW_MESSAGE_TABLE_NAME, (int)convId, pMsg->msgType.subType, MSG_STORAGE_SIM);
+
+               MSG_DEBUG("Query=[%s]", sqlQuery);
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_PREPARE;
+               }
 
-               if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-                       retCnt = dbHandle.columnInt(0);
-                       pMsgInfo->msgId = dbHandle.columnInt(1);
+               if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       *pMsgId = dbHandle->columnInt(0);
                } else {
-                       dbHandle.finalizeQuery();
+                       dbHandle->finalizeQuery();
+                       dbHandle->endTrans(false);
                        return MSG_ERR_DB_STEP;
                }
 
-               dbHandle.finalizeQuery();
-       }
+               dbHandle->finalizeQuery();
 
-       /** Update New Replace Type Msg */
-       if (retCnt == 0) { /** Insert New Replace Type Msg */
-               MSG_DEBUG("Insert Replace Type Msg");
-               err = addSmsMessage(pMsgInfo);
        } else {
-               MSG_DEBUG("Update Replace Type Msg");
-               err = updateSmsMessage(pMsgInfo);
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_NORECORD;
        }
 
-       return err;
-}
-
-
-msg_error_t SmsPluginStorage::addWAPMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       MSG_PUSH_MESSAGE_S pushMsg = {};
-
-       char sqlQuery[MAX_QUERY_LEN+1];
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       int fileSize = 0;
-
-       char* pFileData = NULL;
-       AutoPtr<char> buf(&pFileData);
-
-       if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false)
-               return MSG_ERR_STORAGE_ERROR;
-
-       MSG_DEBUG("fileSize : %d", fileSize);
-
-       memcpy(&pushMsg, pFileData, fileSize);
-
-       /** Delete temporary file */
-       MsgDeleteFile(pMsgInfo->msgData);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT SIM_ID FROM %s \
+                       WHERE MSG_ID = %d;",
+                       MSGFW_SIM_MSG_TABLE_NAME, *pMsgId);
 
-       /** check pPushMsg data */
-
-       MSG_DEBUG("check pushMsg data");
-       MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
-       MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
-       MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
-       MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
-       MSG_DEBUG("pushMsg.id : [%s]", pushMsg.id);
-       MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
-       MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
-
-       bool bProceed = true;
-
-       /**  check validation of contents */
-       if (checkPushMsgValidation(&pushMsg, &bProceed) != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to check Push Message validation.");
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_PREPARE;
        }
 
-       /**  if validation check value is false */
-       /** return and drop message. */
-       if (bProceed == false)
-               return MSG_ERR_INVALID_MESSAGE;
-
-#if 0
-       /**  update subject */
-       int len = strlen(pushMsg.contents);
-
-       if (len > MAX_SUBJECT_LEN) {
-               memcpy(pMsgInfo->subject, pushMsg.contents, MAX_SUBJECT_LEN);
-               pMsgInfo->subject[MAX_SUBJECT_LEN] = '\0';
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               *pSimId = dbHandle->columnInt(0);
        } else {
-               strncpy(pMsgInfo->subject, pushMsg.contents, MAX_SUBJECT_LEN);
-       }
-#endif
-
-       /**  Update Msg Text - remove */
-       strncpy(pMsgInfo->msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
-
-       if (pushMsg.contents[0] != '\0') {
-               strncat(pMsgInfo->msgText, " ", MAX_MSG_TEXT_LEN - strlen(pMsgInfo->msgText));
-               strncat(pMsgInfo->msgText, pushMsg.contents, MAX_MSG_TEXT_LEN - strlen(pMsgInfo->msgText));
-       }
-
-       pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
-
-       pMsgInfo->bTextSms = true;
-       pMsgInfo->folderId = MSG_INBOX_ID;
-       pMsgInfo->storageId = MSG_STORAGE_PHONE;
-
-       msg_thread_id_t convId = 0;
-
-       dbHandle.beginTrans();
-
-       if (pMsgInfo->nAddressCnt > 0) {
-
-               err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
-
-               if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       return err;
-               }
-
-               pMsgInfo->threadId = convId;
-       }
-
-       /**  get last row count for Message id */
-       unsigned int rowId = 0;
-
-       /** Add Message Table */
-       rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
-
-       if (rowId <= 0) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_DB_ROW;
-       }
-
-       /**  add msg_push_table */
-       snprintf (sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %lu, %lu, ?, ?, ?)",
-                       MSGFW_PUSH_MSG_TABLE_NAME, pMsgInfo->msgId, pushMsg.action, pushMsg.created, pushMsg.expires);
-
-       if ((err = dbHandle.prepareQuery(sqlQuery)) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return err;
+               dbHandle->finalizeQuery();
+               dbHandle->endTrans(false);
+               return MSG_ERR_DB_STEP;
        }
 
-       dbHandle.bindText(pushMsg.id, 1);
+       MSG_DEBUG("Replace Msg Id=[%d], Sim Id=[%d]", *pMsgId, *pSimId);
 
-       dbHandle.bindText(pushMsg.href, 2);
-
-       dbHandle.bindText(pushMsg.contents, 3);
-
-       if ((err = dbHandle.stepQuery()) != MSG_ERR_DB_DONE) {
-               dbHandle.endTrans(false);
-               return err;
-       }
-
-       /** Update conversation table. */
-       if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return MSG_ERR_STORAGE_ERROR;
-       }
+       dbHandle->finalizeQuery();
 
-       dbHandle.endTrans(true);
+       dbHandle->endTrans(true);
 
-       pMsgInfo->msgId = (msg_message_id_t)rowId;
+       MSG_END();
 
-       return MSG_SUCCESS;
+       return msgId;
 }
 
-
-msg_error_t SmsPluginStorage::handleCOWAPMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+msg_error_t SmsPluginStorage::addSmsSendOption(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
 {
-       msg_error_t err = MSG_SUCCESS;
-
-       char href[MAX_PUSH_CACHEOP_MAX_URL_LEN+1];
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       int fileSize = 0;
-
-       char* pFileData = NULL;
-       AutoPtr<char> buf(&pFileData);
-
-       if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false)
-               return MSG_ERR_STORAGE_ERROR;
-
-       MSG_PUSH_CACHEOP_S *pPushMsg;
-
-       pPushMsg = (MSG_PUSH_CACHEOP_S*)pFileData;
-
-       for (int i = 0; i < pPushMsg->invalObjectCnt; i++) {
-
-               int msgid = -1;
-
-               memset(href, 0x00, sizeof(href));
-               strncpy(href, &(pPushMsg->invalObjectUrl[i][0]), MAX_PUSH_CACHEOP_MAX_URL_LEN);
-
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf (sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE HREF LIKE '%%%s%%';", MSGFW_PUSH_MSG_TABLE_NAME, href);
-
-               dbHandle.beginTrans();
-
-               err = dbHandle.prepareQuery(sqlQuery);
-
-               if ((dbHandle.stepQuery() == MSG_ERR_DB_ROW) && err == MSG_SUCCESS) {
-
-                       msgid = dbHandle.getColumnToInt(1);
-
-                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID= %d;", MSGFW_PUSH_MSG_TABLE_NAME, msgid);
-
-                       /** Delete Message from Push table */
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
-
-                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgid);
-
-                       /** Delete Message from msg table */
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
-
-                       /** Update all Address */
-                       if (updateAllAddress() != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
+       MSG_BEGIN();
 
-                       /** Clear Conversation table */
-                       if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
-               }
+       msg_error_t err = MSG_SUCCESS;
 
-               dbHandle.finalizeQuery();
+       if (pSendOptInfo->bSetting == false) {
+               MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, &pSendOptInfo->bDeliverReq);
+               MsgSettingGetBool(SMS_SEND_REPLY_PATH, &pSendOptInfo->option.smsSendOptInfo.bReplyPath);
 
-               dbHandle.endTrans(true);
+//             if (pSendOptInfo->bDeliverReq || pSendOptInfo->option.smsSendOptInfo.bReplyPath) {
+//                     pSendOptInfo->bSetting = true;
+                       MsgSettingGetBool(MSG_KEEP_COPY, &pSendOptInfo->bKeepCopy);
+//             }
        }
 
-       for (int i = 0; i < pPushMsg->invalServiceCnt; i++) {
+//     if (pSendOptInfo->bSetting == true) {
+               MsgDbHandler *dbHandle = getDbHandle();
 
-               int msgid = -1;
-
-               memset(href, 0x00, sizeof(href));
-               strncpy(href, &(pPushMsg->invalObjectUrl[i][0]), MAX_PUSH_CACHEOP_MAX_URL_LEN);
+               char sqlQuery[MAX_QUERY_LEN+1];
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE HREF LIKE '%%%s%%'", MSGFW_PUSH_MSG_TABLE_NAME, href);
-
-               dbHandle.beginTrans();
-
-               err = dbHandle.prepareQuery(sqlQuery);
-
-               if ((dbHandle.stepQuery() == MSG_ERR_DB_ROW) && err == MSG_SUCCESS) {
-
-                       msgid = dbHandle.getColumnToInt(1);
-
-                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       sprintf(sqlQuery, "DELETE FROM %s WHERE MSG_ID='%d'", MSGFW_PUSH_MSG_TABLE_NAME, msgid);
-
-                       /** Delete Message from Push table */
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
-
-                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgid);
-
-                       /** Delete Message from msg table */
-                       if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d);",
+                               MSGFW_SMS_SENDOPT_TABLE_NAME, pMsg->msgId, pSendOptInfo->bDeliverReq,
+                               pSendOptInfo->bKeepCopy, pSendOptInfo->option.smsSendOptInfo.bReplyPath, pMsg->encodeType);
 
-                       /**  Update all Address */
-                       if (updateAllAddress() != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
+               MSG_DEBUG("Query = [%s]", sqlQuery);
 
-                       /** Clear Address table */
-                       if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
-                               dbHandle.finalizeQuery();
-                               dbHandle.endTrans(false);
-                               continue;
-                       }
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       err = MSG_ERR_DB_EXEC;
                }
+//     }
 
-               dbHandle.finalizeQuery();
-
-               dbHandle.endTrans(true);
-       }
-
-       /** delete temporary file */
-       MsgDeleteFile(pMsgInfo->msgData);
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t SmsPluginStorage::checkPushMsgValidation(MSG_PUSH_MESSAGE_S *pPushMsg, bool *pbProceed)
-{
-       msg_error_t err = MSG_SUCCESS;
-
-       unsigned long oldExpireTime = 0;
-       int rowCnt = 0;
-
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       /**  is push message is expired?? */
-       if (pPushMsg->received > pPushMsg->expires) {
-               MSG_DEBUG("Push Message is expired.");
-               pbProceed = false;
-               return err;
-       }
-
-
-       if (pPushMsg->action == MSG_PUSH_SL_ACTION_EXECUTE_LOW) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXPIRES FROM %s WHERE ID = '%s' AND ACTION = %d",
-                               MSGFW_PUSH_MSG_TABLE_NAME, pPushMsg->id, pPushMsg->action);
-       } else {
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXPIRES FROM %s WHERE ID = '%s'",
-                               MSGFW_PUSH_MSG_TABLE_NAME, pPushMsg->id);
-       }
-
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
-
-       if (rowCnt < 1) {
-               dbHandle.freeTable();
-               return MSG_SUCCESS;
-       }
-
-       oldExpireTime = dbHandle.getColumnToInt(1);
-
-       dbHandle.freeTable();
-
-       if (pPushMsg->created < oldExpireTime) {
-               MSG_DEBUG("Push Message is expired.");
-               pbProceed = false;
-               return err;
-       }
+       MSG_END();
 
        return err;
 }
@@ -1118,7 +888,9 @@ msg_error_t SmsPluginStorage::checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       err = MsgStoCheckMsgCntFull(&dbHandle, &(pMsgInfo->msgType), pMsgInfo->folderId);
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       err = MsgStoCheckMsgCntFull(dbHandle, &(pMsgInfo->msgType), pMsgInfo->folderId, pMsgInfo->sim_idx);
 
        if (err != MSG_SUCCESS) {
 
@@ -1133,7 +905,7 @@ msg_error_t SmsPluginStorage::checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
                                msg_message_id_t msgId;
 
                                /** Find the oldest message's msgId */
-                               err = MsgStoGetOldestMessage(&dbHandle, pMsgInfo, &msgId);
+                               err = MsgStoGetOldestMessage(dbHandle, pMsgInfo, &msgId);
 
                                if (err != MSG_SUCCESS)
                                        return err;
@@ -1150,68 +922,90 @@ msg_error_t SmsPluginStorage::checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
 }
 
 
-msg_error_t SmsPluginStorage::updateAllAddress()
+#if 0
+
+msg_error_t SmsPluginStorage::isReceivedCBMessage(SMS_CBMSG_PAGE_S CbPage)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       int rowCnt = 0, index = 1;
-       char sqlQuery[MAX_QUERY_LEN+1];
+       int rowCnt = 0;
+
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       char sqlQuery[MAX_QUERY_LEN+1] = {0, };
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_ID FROM %s", MSGFW_ADDRESS_TABLE_NAME);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT * FROM %s WHERE GEO_SCOPE = %d AND MSG_CODE = %d AND MESSAGE_ID = %d AND UPDATE_NUM = %d",
+                       MSGFW_RECEIVED_CB_MSG_TABLE_NAME, CbPage.pageHeader.serialNum.geoScope,
+                       CbPage.pageHeader.serialNum.msgCode,CbPage.pageHeader.msgId, CbPage.pageHeader.serialNum.updateNum);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
+       MSG_DEBUG("rowCnt: %d", rowCnt);
 
-       if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-               return MSG_SUCCESS;
-       } else if ( err != MSG_SUCCESS) {
-               dbHandle.freeTable();
-               return err;
-       }
+       dbHandle->freeTable();
+       return err;
+}
 
+msg_error_t SmsPluginStorage::insertReceivedCBMessage(SMS_CBMSG_PAGE_S CbPage)
+{
 
-       for (int i = 0; i < rowCnt; i++) {
+       msg_error_t err = MSG_SUCCESS;
+
+       unsigned int rowId = 0;
 
-               err = MsgStoUpdateConversation(&dbHandle, index++);
+       MsgDbHandler *dbHandle = getDbHandle();
 
-               if (err != MSG_SUCCESS)
-                       break;
-       }
+       char sqlQuery[MAX_QUERY_LEN+1];
 
-       dbHandle.freeTable();
+       err = dbHandle->getRowId(MSGFW_RECEIVED_CB_MSG_TABLE_NAME, &rowId);
+
+       if (err != MSG_SUCCESS)
+               return err;
+
+       // Add Folder
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d);",
+                       MSGFW_RECEIVED_CB_MSG_TABLE_NAME, rowId, CbPage.pageHeader.serialNum.geoScope,
+                       CbPage.pageHeader.serialNum.msgCode,CbPage.pageHeader.msgId, CbPage.pageHeader.serialNum.updateNum);
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_EXEC;
+
+       return MSG_SUCCESS;
 
-       return err;
 }
 
+#endif
 
-msg_error_t SmsPluginStorage::getRegisteredPushEvent(char* pPushHeader, int *count, char *application_id, char *contentType)
+msg_error_t SmsPluginStorage::getRegisteredPushEvent(char* pPushHeader, int *count, char *application_id, int app_id_len, char *content_type, int content_type_len)
 {
        msg_error_t err = MSG_SUCCESS;
 
        int rowCnt = 0, index = 3;
 
+       MsgDbHandler *dbHandle = getDbHandle();
+
        char sqlQuery[MAX_QUERY_LEN+1] = {0, };
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONTENT_TYPE, APP_ID, APPCODE FROM %s", MSGFW_PUSH_CONFIG_TABLE_NAME);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       err = dbHandle->getTable(sqlQuery, &rowCnt);
        MSG_DEBUG("rowCnt: %d", rowCnt);
 
        if (err == MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return MSG_SUCCESS;
        }
        else if ( err != MSG_SUCCESS) {
-               dbHandle.freeTable();
+               dbHandle->freeTable();
                return err;
        }
 
-       char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN + 1];
-       char app_id[MAX_WAPPUSH_ID_LEN + 1];
+       char contentType[MAX_WAPPUSH_CONTENT_TYPE_LEN + 1] = {0,};
+       char appId[MAX_WAPPUSH_ID_LEN + 1] = {0,};
        int appcode = 0, default_appcode = 0;
        bool found = false;
        char *_content_type = NULL, *_app_id = NULL;
@@ -1219,26 +1013,26 @@ msg_error_t SmsPluginStorage::getRegisteredPushEvent(char* pPushHeader, int *cou
 
 
        for (int i = 0; i < rowCnt; i++) {
-               memset(content_type, 0, MAX_WAPPUSH_CONTENT_TYPE_LEN);
-               memset(app_id, 0, MAX_WAPPUSH_ID_LEN);
+               memset(contentType, 0, MAX_WAPPUSH_CONTENT_TYPE_LEN);
+               memset(appId, 0, MAX_WAPPUSH_ID_LEN);
 
-               dbHandle.getColumnToString(index++, MAX_WAPPUSH_CONTENT_TYPE_LEN + 1, content_type);
-               dbHandle.getColumnToString(index++, MAX_WAPPUSH_ID_LEN + 1, app_id);
-               appcode = dbHandle.getColumnToInt(index++);
+               dbHandle->getColumnToString(index++, MAX_WAPPUSH_CONTENT_TYPE_LEN + 1, contentType);
+               dbHandle->getColumnToString(index++, MAX_WAPPUSH_ID_LEN + 1, appId);
+               appcode = dbHandle->getColumnToInt(index++);
 
                //MSG_DEBUG("content_type: %s, app_id: %s", content_type, app_id);
-               _content_type = strcasestr(pPushHeader, content_type);
+               _content_type = strcasestr(pPushHeader, contentType);
                if(_content_type) {
-                       _app_id = strcasestr(pPushHeader, app_id);
+                       _app_id = strcasestr(pPushHeader, appId);
                        if(appcode)
                                default_appcode = appcode;
 
                        if(_app_id) {
                                PUSH_APPLICATION_INFO_S pInfo = {0, };
                                pInfo.appcode = appcode;
-                               MSG_DEBUG("appcode: %d, app_id: %s", pInfo.appcode, app_id);
-                               strcpy(application_id, app_id);
-                               strcpy(contentType, content_type);
+                               MSG_SEC_DEBUG("appcode: %d, app_id: %s", pInfo.appcode, appId);
+                               snprintf(application_id, app_id_len, "%s", appId);
+                               snprintf(content_type, content_type_len, "%s", contentType);
                                pushAppInfoList.push_back(pInfo);
                                (*count)++;
                                found = true;
@@ -1246,17 +1040,18 @@ msg_error_t SmsPluginStorage::getRegisteredPushEvent(char* pPushHeader, int *cou
                }
        }
 
-       if(!found)
+       if(!found && default_appcode != SMS_WAP_APPLICATION_LBS)
        {
                // perform default action.
                PUSH_APPLICATION_INFO_S pInfo = {0, };
                pInfo.appcode = default_appcode;
-               strcpy(application_id, app_id);
-               strcpy(contentType, content_type);
+               memset(appId, 0, MAX_WAPPUSH_ID_LEN + 1);
+               snprintf(application_id, app_id_len, "%s", appId);
+               snprintf(content_type, content_type_len, "%s", contentType);
                pushAppInfoList.push_back(pInfo);
                *count = 1;
        }
-       dbHandle.freeTable();
+       dbHandle->freeTable();
 
        return err;
 }
index 24353cd..2b17797 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -116,7 +116,7 @@ int SmsPluginTpduCodec::encodeSubmit(const SMS_SUBMIT_S *pSubmit, char *pTpdu)
        pTpdu[offset] = 0x01;
 
        //TP-RD
-       if(pSubmit->bRejectDup == false)
+       if(pSubmit->bRejectDup == true)
                pTpdu[offset] |= 0x04;
 
        //TP-VPF
@@ -195,6 +195,15 @@ MSG_DEBUG("encodeSize : %d", encodeSize);
 
        offset += encodeSize;
 
+#if 0
+       printf("\n\n[encodeSubmit] pTpdu data.\n");
+       for (int i = 0; i < offset; i++)
+       {
+               printf(" [%02x]", pTpdu[i]);
+       }
+       printf("\n\n");
+#endif
+
        return offset;
 }
 
@@ -276,8 +285,10 @@ int SmsPluginTpduCodec::encodeDeliverReport(const SMS_DELIVER_REPORT_S *pDeliver
        offset++;
 
        // TP-FCS
-       if (pDeliverRep->reportType == SMS_REPORT_NEGATIVE)
+       if (pDeliverRep->reportType == SMS_REPORT_NEGATIVE) {
                pTpdu[offset++] = pDeliverRep->failCause;
+               MSG_DEBUG("Delivery report : fail cause = [%02x]", pDeliverRep->failCause);
+       }
 
        // TP-PI
        pTpdu[offset++] = pDeliverRep->paramInd;
@@ -468,7 +479,7 @@ int SmsPluginTpduCodec::decodeSubmit(const unsigned char *pTpdu, int TpduLen, SM
 
 int SmsPluginTpduCodec::decodeDeliver(const unsigned char *pTpdu, int TpduLen, SMS_DELIVER_S *pDeliver)
 {
-       int offset = 0, udLen = 0;
+       int offset = 0, udLen = 0, tmpOffset = 0;
 
 
        char tpduTmp[(TpduLen*2)+1];
@@ -477,7 +488,7 @@ int SmsPluginTpduCodec::decodeDeliver(const unsigned char *pTpdu, int TpduLen, S
                snprintf(tpduTmp+(i*2), sizeof(tpduTmp)-(i*2), "%02X", pTpdu[i]);
        }
        MSG_DEBUG("Deliver TPDU.");
-       MSG_DEBUG("[%s]", tpduTmp);
+       MSG_INFO("[%s]", tpduTmp);
 
 
        // TP-MMS
@@ -506,6 +517,8 @@ int SmsPluginTpduCodec::decodeDeliver(const unsigned char *pTpdu, int TpduLen, S
 
        offset++;
 
+       tmpOffset = offset;
+#if 1
        // TP-OA
        offset += SmsPluginParamCodec::decodeAddress(&pTpdu[offset], &(pDeliver->originAddress));
 
@@ -515,6 +528,65 @@ int SmsPluginTpduCodec::decodeDeliver(const unsigned char *pTpdu, int TpduLen, S
        // TP-DCS
        offset += SmsPluginParamCodec::decodeDCS(&pTpdu[offset], &(pDeliver->dcs));
 
+       // Support KSC5601 :: Coding group bits == 0x84
+       if (pTpdu[offset-1] == 0x84) {
+               pDeliver->dcs.codingScheme = SMS_CHARSET_EUCKR;
+       }
+
+#else
+       //For alphanumeric address test
+
+       offset += SmsPluginParamCodec::decodeAddress(&pTpdu[offset], &(pDeliver->originAddress));
+
+       char* address = new char[15];
+       address[0] = 0x04;
+       address[1] = 0xd0;
+       address[2] = 0x11;
+       address[3] = 0x00;
+       address[4] = 0x20;
+       address[5] = 0xF2;
+       address[6] = 0x01;
+       address[7] = 0x01;
+       address[8] = 0x11;
+       address[9] = 0x61;
+       address[10] = 0x40;
+       address[11] = 0x82;
+       address[12] = 0x2b;
+       address[13] = 0x01;
+       address[14] = 0x20;
+
+       SmsPluginParamCodec::decodeAddress((unsigned char*)address, &(pDeliver->originAddress));
+
+       pDeliver->pid = 0x20;
+       offset++;
+       offset += SmsPluginParamCodec::decodeDCS((unsigned char*)address, &(pDeliver->dcs));
+       // end test
+#endif
+
+       if (pDeliver->pid == 0x20 && pDeliver->originAddress.ton == SMS_TON_ALPHANUMERIC) {
+               int setType = -1;
+               int indType = -1;
+
+               bool bVmi = SmsPluginParamCodec::checkCphsVmiMsg(&pTpdu[tmpOffset], &setType, &indType);
+
+               MSG_DEBUG("bVmi = [%d], setType=[%d], indType=[%d]", bVmi, setType, indType);
+
+               if (bVmi) {
+                       pDeliver->dcs.bMWI = true;
+
+                       if (setType == 0) {
+                               pDeliver->dcs.bIndActive = false;
+                       } else {
+                               pDeliver->dcs.bIndActive = true;
+                       }
+
+                       if (indType == 0)
+                               pDeliver->dcs.indType = SMS_VOICE_INDICATOR;
+                       else if (indType == 1)
+                               pDeliver->dcs.indType = SMS_VOICE2_INDICATOR;
+               }
+       }
+
        // TP-SCTS
        offset += SmsPluginParamCodec::decodeTime(&pTpdu[offset], &(pDeliver->timeStamp));
 
index cad9cc8..d16ad19 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
 #include "MsgGconfWrapper.h"
 #include "MsgUtilFile.h"
 #include "MsgNotificationWrapper.h"
+#include "MsgUtilStorage.h"
+
 #include "SmsPluginParamCodec.h"
 #include "SmsPluginTpduCodec.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginStorage.h"
 #include "SmsPluginCallback.h"
 #include "SmsPluginTransport.h"
+#include "SmsPluginDSHandler.h"
+#include "SmsPluginSetting.h"
 
 extern "C"
 {
@@ -36,7 +40,7 @@ extern "C"
 }
 
 
-extern struct tapi_handle *pTapiHandle;
+extern bool isMemAvailable;
 
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginTransport - Member Functions
@@ -49,6 +53,7 @@ SmsPluginTransport::SmsPluginTransport()
        msgRef          = 0x00;
        msgRef8bit      = 0x00;
        msgRef16bit     = 0x0000;
+       memset(&curMoCtrlData, 0x00, sizeof(curMoCtrlData));
 }
 
 
@@ -75,48 +80,48 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
 
        tpdu.tpduType = SMS_TPDU_SUBMIT;
 
-       // Set SMS Send Options - Setting
-       setSmsSendOptions(&(tpdu.data.submit));
+       // Get SMS Send Options - Setting
+       getSmsSendOption(&(tpdu.data.submit));
 
        // Set SMS Send Options - Each Message
-       if (pReqInfo->sendOptInfo.bSetting == true)
-       {
-               tpdu.data.submit.bStatusReport = pReqInfo->sendOptInfo.bDeliverReq;
-               tpdu.data.submit.bReplyPath = pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath;
-       }
+       setSmsSendOption(pReqInfo, &tpdu);
 
-       // Set Coding Scheme for apps that use port number
-       if (pReqInfo->msgInfo.msgPort.valid == true)
-       {
-               tpdu.data.submit.dcs.codingScheme = (SMS_CODING_SCHEME_T)pReqInfo->msgInfo.encodeType;
-
-               MSG_DEBUG("DCS is changed by application : [%d]", tpdu.data.submit.dcs.codingScheme);
-       }
-
-#ifdef MSG_SMS_REPORT
-       // Update Msg Ref into Report Table
-       if (tpdu.data.submit.bStatusReport == true)
-       {
-               MSG_DEBUG("Update Msg Ref [%d] in Report Table", tpdu.data.submit.msgRef);
+       // Set coding scheme
+       setSmsDcsOption(pReqInfo, &tpdu);
 
-               SmsPluginStorage::instance()->updateMsgRef(pReqInfo->msgInfo.msgId, tpdu.data.submit.msgRef);
-       }
-#endif
+       // Set SMS report request
+       setSmsReportOption(pReqInfo, &tpdu);
 
        // Set SMSC Options
        SMS_ADDRESS_S smsc;
-       setSmscOptions(&smsc);
-       int i = 0;
-       int j = 0;
+       setSmscOptions(pReqInfo->msgInfo.sim_idx, &smsc);
+
+       // Get TAPI handle
+       struct tapi_handle *handle = SmsPluginDSHandler::instance()->getTelHandle(pReqInfo->msgInfo.sim_idx);
 
+       // Get address informations.
+       MsgDbHandler *dbHandle = getDbHandle();
+       MsgStoGetAddressByMsgId(dbHandle, pReqInfo->msgInfo.msgId, 0, &pReqInfo->msgInfo.nAddressCnt, &pReqInfo->msgInfo.addressList);
        MSG_DEBUG("pReqInfo->msgInfo.nAddressCnt [%d]", pReqInfo->msgInfo.nAddressCnt);
 
-       for (i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++)
+       // Get MSISDN
+       char *msisdn = NULL;
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, pReqInfo->msgInfo.sim_idx);
+       msisdn = MsgSettingGetString(keyName);
+
+       for (int i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++)
        {
                // Make SMS_SUBMIT_DATA_S from MSG_REQUEST_INFO_S
                SMS_SUBMIT_DATA_S submitData = {{0},};
                msgInfoToSubmitData(&(pReqInfo->msgInfo), &submitData, &(tpdu.data.submit.dcs.codingScheme), i);
 
+               // Insert message reference into db
+               if (tpdu.data.submit.bStatusReport == true) {
+                       SmsPluginStorage::instance()->insertMsgRef(&(pReqInfo->msgInfo), tpdu.data.submit.msgRef, i);
+               }
+
                // Encode SMSC Address
                unsigned char smscAddr[MAX_SMSC_LEN];
                memset(smscAddr, 0x00, sizeof(smscAddr));
@@ -125,12 +130,12 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
 
                if (smscLen <= 0) {
                        MSG_DEBUG("smscLen <= 0");
-                       return;
+                       goto _RETURN_FUNC;
                }
 
                char smscAddrTmp[(smscLen*2)+1];
                memset(smscAddrTmp, 0x00, sizeof(smscAddrTmp));
-               for (j = 0; j < smscLen; j++) {
+               for (int j = 0; j < smscLen; j++) {
                        snprintf(smscAddrTmp+(j*2), sizeof(smscAddrTmp)-(j*2), "%02X", smscAddr[j]);
                }
                MSG_DEBUG("pSCAInfo [%s]", smscAddrTmp);
@@ -154,7 +159,7 @@ void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo)
 
 MSG_DEBUG("ton [%d]", tpdu.data.submit.destAddress.ton);
 MSG_DEBUG("npi [%d]", tpdu.data.submit.destAddress.npi);
-MSG_DEBUG("address [%s]", tpdu.data.submit.destAddress.address);
+MSG_SEC_DEBUG("address [%s]", tpdu.data.submit.destAddress.address);
 
                bool bStatusReport = false;
 
@@ -176,87 +181,143 @@ MSG_DEBUG("address [%s]", tpdu.data.submit.destAddress.address);
                        memset(&(tpdu.data.submit.userData), 0x00, sizeof(SMS_USERDATA_S));
                        memcpy(&(tpdu.data.submit.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S));
 
-                       // Encode SMS-SUBMIT TPDU
-                       memset(buf, 0x00, sizeof(buf));
+                       SMS_NETWORK_STATUS_T retStatus = SMS_NETWORK_SENDING;
 
-                       bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
+                       bool bMoreMsg = false;
 
-                       // Make Telephony Structure
-                       TelSmsDatapackageInfo_t pkgInfo;
+                       int retMoCtrlStatus = TAPI_SAT_CALL_CTRL_R_ALLOWED_NO_MOD;
+                       bool bRetryByMoCtrl = false;
+                       bool bSatMoCtrl = false;
 
-                       // Set TPDU data
-                       memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData));
-                       memcpy((void*)pkgInfo.szData, buf, bufLen);
 
-                       pkgInfo.szData[bufLen] = 0;
-                       pkgInfo.MsgLength = bufLen;
+                       for(int cnt = 0; cnt < MAX_SMS_SEND_RETRY; ++cnt)
+                       {
 
-                       // Set SMSC data
-                       memset(pkgInfo.Sca, 0x00, sizeof(pkgInfo.Sca));
-                       memcpy((void*)pkgInfo.Sca, smscAddr, smscLen);
-                       pkgInfo.Sca[smscLen] = '\0';
+                               // Encode SMS-SUBMIT TPDU
+                               memset(buf, 0x00, sizeof(buf));
 
+                               if(cnt > 0)
+                                       tpdu.data.submit.bRejectDup = true;
 
-                       char pkgInfoTmp[(pkgInfo.MsgLength*2)+1];
-                       memset(pkgInfoTmp, 0x00, sizeof(pkgInfoTmp));
-                       for (j = 0; j < pkgInfo.MsgLength; j++) {
-                               snprintf(pkgInfoTmp+(j*2), sizeof(pkgInfoTmp)-(j*2), "%02X", pkgInfo.szData[j]);
-                       }
-                       MSG_DEBUG("Submit Request TPDU.");
-                       MSG_DEBUG("[%s]", pkgInfoTmp);
+                               bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
 
-                       SMS_SENT_INFO_S sentInfo;
-                       memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
+                               // Make Telephony Structure
+                               TelSmsDatapackageInfo_t pkgInfo;
 
-                       bool bMoreMsg = FALSE;
+                               // Set TPDU data
+                               memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData));
+                               memcpy((void*)pkgInfo.szData, buf, bufLen);
 
-                       memcpy(&(sentInfo.reqInfo), pReqInfo, sizeof(SMS_REQUEST_INFO_S));
+                               pkgInfo.szData[bufLen] = 0;
+                               pkgInfo.MsgLength = bufLen;
 
-                       if ((segCnt+1) == submitData.segCount && (i+1)==pReqInfo->msgInfo.nAddressCnt)
-                       {
-                               sentInfo.bLast = true;
+                               // Set SMSC data
+                               memset(pkgInfo.Sca, 0x00, sizeof(pkgInfo.Sca));
+                               memcpy((void*)pkgInfo.Sca, smscAddr, smscLen);
+                               pkgInfo.Sca[smscLen] = '\0';
+
+
+                               char pkgInfoTmp[(pkgInfo.MsgLength*2)+1];
+                               memset(pkgInfoTmp, 0x00, sizeof(pkgInfoTmp));
+                               for (int j = 0; j < pkgInfo.MsgLength; j++) {
+                                       snprintf(pkgInfoTmp+(j*2), sizeof(pkgInfoTmp)-(j*2), "%02X", pkgInfo.szData[j]);
+                               }
+                               MSG_INFO("Submit Request TPDU.");
+                               MSG_INFO("[%s]", pkgInfoTmp);
+
+                               SMS_SENT_INFO_S sentInfo;
+                               memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
 
                                bMoreMsg = FALSE;
-                       }
-                       else
-                       {
-                               sentInfo.bLast = false;
 
-                               bMoreMsg = TRUE;
-                       }
+                               memcpy(&(sentInfo.reqInfo), pReqInfo, sizeof(SMS_REQUEST_INFO_S));
 
-                       SmsPluginEventHandler::instance()->SetSentInfo(&sentInfo);
+                               if ((segCnt+1) == submitData.segCount && (i+1)==pReqInfo->msgInfo.nAddressCnt)
+                               {
+                                       sentInfo.bLast = true;
+                                       bMoreMsg = FALSE;
+                               }
+                               else
+                               {
+                                       sentInfo.bLast = false;
+                                       bMoreMsg = TRUE;
+                               }
 
-                       curStatus = MSG_NETWORK_SENDING;
+                               SmsPluginEventHandler::instance()->SetSentInfo(&sentInfo);
 
-                       // Send SMS
-                       int tapiRet = TAPI_API_SUCCESS;
+                               curStatus = SMS_NETWORK_SENDING;
 
-                       tapiRet = tel_send_sms(pTapiHandle, &pkgInfo, bMoreMsg, TapiEventSentStatus, NULL);
+                               // Send SMS
+                               int tapiRet = TAPI_API_SUCCESS;
 
-                       if (tapiRet == TAPI_API_SUCCESS)
-                       {
-                               MSG_DEBUG("########  tel_send_sms Success !!! return : [%d] #######", tapiRet);
-                       }
-                       else
-                       {
-                               SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
+                               tapiRet = tel_send_sms(handle, &pkgInfo, bMoreMsg, TapiEventSentStatus, (void *)&curMoCtrlData);
 
-                               THROW(MsgException::SMS_PLG_ERROR, "########  tel_send_sms Fail !!! return : [%d] #######", tapiRet);
-                       }
+                               if (tapiRet == TAPI_API_SUCCESS)
+                               {
+                                       MSG_DEBUG("########  tel_send_sms Success !!! return : [%d] #######", tapiRet);
+
+                                       memset(keyName, 0x00, sizeof(keyName));
+                                       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MO_CONTROL, pReqInfo->msgInfo.sim_idx);
+                                       if (MsgSettingGetBool(keyName, &bSatMoCtrl) != MSG_SUCCESS)
+                                               MSG_DEBUG("MsgSettingGetBool [%s] failed", keyName);
+
+                                       if (bSatMoCtrl) {
+                                               // Get SAT MO SM control
+                                               retMoCtrlStatus = getMoCtrlStatus();
+                                               MSG_DEBUG("retMoCtrlStatus  = [%d]", retMoCtrlStatus);
+
+                                               if (retMoCtrlStatus == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD) {
+
+                                                       if (bRetryByMoCtrl == false) {
+                                                               bRetryByMoCtrl = true;
+
+                                                               // Modify Address with control data
+                                                               memset(smsc.address, 0x00, sizeof(smsc.address));
+                                                               memcpy(smsc.address, curMoCtrlData.rpDestAddr.string, sizeof(smsc.address)-1);
+
+                                                               memset(smscAddr, 0x00, sizeof(smscAddr));
+                                                               smscLen = SmsPluginParamCodec::encodeSMSC(&smsc, smscAddr);
+
+                                                               MSG_SEC_DEBUG("SMSC address=[%s], Encoded length=[%d]", smsc.address, smscLen);
+
+                                                               if (curMoCtrlData.tpDestAddr.stringLen < MAX_ADDRESS_LEN) {
+                                                                       memcpy(tpdu.data.submit.destAddress.address, curMoCtrlData.tpDestAddr.string, curMoCtrlData.tpDestAddr.stringLen);
+                                                                       tpdu.data.submit.destAddress.address[curMoCtrlData.tpDestAddr.stringLen] = '\0';
+                                                               } else {
+                                                                       memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN);
+                                                                       tpdu.data.submit.destAddress.address[MAX_ADDRESS_LEN] = '\0';
+                                                               }
+                                                       } else {
+                                                               curMoCtrlData.moSmsCtrlResult = TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED;
+                                                       }
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
+
+                                       if (msisdn) {
+                                               free(msisdn);
+                                               msisdn = NULL;
+                                       }
+                                       THROW(MsgException::SMS_PLG_ERROR, "########  tel_send_sms Fail !!! return : [%d] #######", tapiRet);
+                               }
 
-                       // Tizen Validation System
-                       char *msisdn = NULL;
-                       msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
+                               // Tizen Validation System
+                               MSG_SMS_VLD_INFO("%d, SMS Send Start, %s->%s, %s",  pReqInfo->msgInfo.msgId, \
+                                                                                                                                                       (msisdn == NULL)?"ME":msisdn, \
+                                                                                                                                                       pReqInfo->msgInfo.addressList[0].addressVal, \
+                                                                                                                                                       (tapiRet == TAPI_API_SUCCESS)?"Success":"Fail");
 
-                       MSG_SMS_VLD_INFO("%d, SMS Send Start, %s->%s, %s",  pReqInfo->msgInfo.msgId, \
-                                                                                                                                               (msisdn == NULL)?"ME":msisdn, \
-                                                                                                                                               pReqInfo->msgInfo.addressList[0].addressVal, \
-                                                                                                                                               (tapiRet == TAPI_API_SUCCESS)?"Success":"Fail");
+                               MSG_SMS_VLD_TXT("%d, [%s]", pReqInfo->msgInfo.msgId, pReqInfo->msgInfo.msgText);
 
-                       MSG_SMS_VLD_TXT("%d, [%s]", pReqInfo->msgInfo.msgId, pReqInfo->msgInfo.msgText);
+                               retStatus = getNetStatus();
 
-                       msg_network_status_t retStatus = getNetStatus();
+                               if(retStatus != SMS_NETWORK_SEND_FAIL_TEMPORARY && retStatus != SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD)
+                                       break;
+
+                       }
 
        #ifdef MSG_SMS_REPORT
                        if (err == MSG_SUCCESS && tmpInfo.msgInfo.msgPort.valid == false)
@@ -274,35 +335,67 @@ MSG_DEBUG("address [%s]", tpdu.data.submit.destAddress.address);
                        MSG_SMS_VLD_INFO("%d, SMS Send End, %s->%s, %s",  pReqInfo->msgInfo.msgId, \
                                                                                                                                        (msisdn == NULL)?"ME":msisdn, \
                                                                                                                                        pReqInfo->msgInfo.addressList[0].addressVal, \
-                                                                                                                                       (retStatus == MSG_NETWORK_SEND_SUCCESS)?"Success":"Fail");
-
+                                                                                                                                       (retStatus == SMS_NETWORK_SEND_SUCCESS)?"Success":"Fail");
 
-                       if (retStatus == MSG_NETWORK_SEND_SUCCESS)
+                       if (retStatus == SMS_NETWORK_SEND_SUCCESS)
                        {
-                               if (bMoreMsg == false) {
-                                       MsgInsertTicker("SMS is sent", SMS_MESSAGE_SENT);
+                               if (pReqInfo->msgInfo.msgType.subType == MSG_UNSAVED_SMS) {
+                                       MSG_DEBUG("msg type=[%d]", pReqInfo->msgInfo.msgType.subType);
+                                       goto _RETURN_FUNC;
+                               }
+
+                               bool bTTS = false;
+
+                               if (MsgSettingGetBool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &bTTS) != MSG_SUCCESS) {
+                                       MSG_DEBUG("MsgSettingGetBool is failed.");
+                               }
+
+                               if (bTTS) {
+                                       if (bMoreMsg == false) {
+                                               MsgInsertTicker("SMS is sent", SMS_MESSAGE_SENT, false, 0);
+                                       }
+                                       MSG_DEBUG("########  Msg Sent was Successful !!! #######");
                                }
-                               MSG_DEBUG("########  Msg Sent was Successful !!! return : [%d] #######", retStatus);
                        }
                        else
                        {
-                               //MsgInsertTicker("Sending SMS is failed", NULL);
-                               MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL);
+                               if (retStatus == SMS_NETWORK_SEND_FAIL_TIMEOUT || retStatus == SMS_NETWORK_SEND_FAIL_FDN_RESTRICED)
+                                       SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
 
-                               SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
+                               if (pReqInfo->msgInfo.msgType.subType == MSG_UNSAVED_SMS) {
+                                       MSG_DEBUG("msg type=[%d]", pReqInfo->msgInfo.msgType.subType);
+                                       goto _RETURN_FUNC;
+                               }
 
+                               if (retStatus == SMS_NETWORK_SEND_FAIL_FDN_RESTRICED) {
+                                       MsgInsertTicker("Unable to send the message while Fixed dialling mode is enabled", SMS_FDN_RESTRICTED, true, 0);
+                               } else {
+                                       MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL, true, pReqInfo->msgInfo.msgId);
+                               }
+
+                               if (msisdn) {
+                                       free(msisdn);
+                                       msisdn = NULL;
+                               }
                                THROW(MsgException::SMS_PLG_ERROR, "########  Msg Sent was Failed !!! return : [%d] #######", retStatus);
                        }
 
                        if (tpdu.data.submit.userData.headerCnt > 0) tpdu.data.submit.userData.headerCnt--;
+
                }
        }
 
+_RETURN_FUNC :
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
        MSG_END();
+       return;
 }
 
 
-void SmsPluginTransport::sendDeliverReport(msg_error_t err)
+void SmsPluginTransport::sendDeliverReport(struct tapi_handle *handle, msg_error_t err)
 {
        MSG_BEGIN();
 
@@ -314,29 +407,37 @@ void SmsPluginTransport::sendDeliverReport(msg_error_t err)
 
        int tapiRet = TAPI_API_SUCCESS;
 
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
        if (err == MSG_SUCCESS)
        {
                tpdu.data.deliverRep.reportType = SMS_REPORT_POSITIVE;
                response = TAPI_NETTEXT_SENDSMS_SUCCESS;
 
-               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, TapiEventMemoryStatus, NULL);
-
-               if (tapiRet == TAPI_API_SUCCESS)
+               if(isMemAvailable == false)
                {
-                       MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! #######");
-               }
-               else
-               {
-                       MSG_DEBUG("########  tel_set_sms_memory_status() Failed !!! return : [%d] #######", tapiRet);
+                       tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, TapiEventMemoryStatus, NULL);
+
+                       if (tapiRet == TAPI_API_SUCCESS)
+                       {
+                               MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! #######");
+                       }
+                       else
+                       {
+                               MSG_DEBUG("########  tel_set_sms_memory_status() Failed !!! return : [%d] #######", tapiRet);
+                       }
                }
        }
        else if (err == MSG_ERR_SIM_STORAGE_FULL)
        {
                tpdu.data.deliverRep.reportType = SMS_REPORT_NEGATIVE;
-               tpdu.data.deliverRep.failCause = SMS_FC_MSG_CAPA_EXCEEDED;
+               tpdu.data.deliverRep.failCause = SMS_FC_SIM_STORAGE_FULL;
+
                response = TAPI_NETTEXT_SIM_FULL;
+               MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);
 
-               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
+#if 0
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
 
                if (tapiRet == TAPI_API_SUCCESS)
                {
@@ -346,14 +447,15 @@ void SmsPluginTransport::sendDeliverReport(msg_error_t err)
                {
                        MSG_DEBUG("########  tel_set_sms_memory_status() Failed !!! return : [%d] #######", tapiRet);
                }
+#endif
        }
        else if (err == MSG_ERR_MESSAGE_COUNT_FULL)
        {
                tpdu.data.deliverRep.reportType = SMS_REPORT_NEGATIVE;
                tpdu.data.deliverRep.failCause = SMS_FC_MSG_CAPA_EXCEEDED;
                response = TAPI_NETTEXT_ME_FULL;
-
-               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
+               MsgInsertTicker("Not enough memory. Delete some items.", SMS_MESSAGE_MEMORY_FULL, true, 0);
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
 
                if (tapiRet == TAPI_API_SUCCESS)
                {
@@ -412,7 +514,7 @@ void SmsPluginTransport::sendDeliverReport(msg_error_t err)
        SMS_ADDRESS_S smsc;
 
        // Set SMSC Options
-       setSmscOptions(&smsc);
+       setSmscOptions(simIndex, &smsc);
 
        // Encode SMSC Address
        unsigned char smscAddr[MAX_SMSC_LEN];
@@ -428,7 +530,7 @@ void SmsPluginTransport::sendDeliverReport(msg_error_t err)
        pkgInfo.Sca[smscLen] = '\0';
 
        // Send Deliver Report
-       tapiRet = tel_send_sms_deliver_report(pTapiHandle, &pkgInfo, response, TapiEventDeliveryReportCNF, NULL);
+       tapiRet = tel_send_sms_deliver_report(handle, &pkgInfo, response, TapiEventDeliveryReportCNF, NULL);
 
        if (tapiRet == TAPI_API_SUCCESS)
        {
@@ -442,7 +544,7 @@ void SmsPluginTransport::sendDeliverReport(msg_error_t err)
        MSG_END();
 }
 
-void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
+void SmsPluginTransport::sendClass0DeliverReport(struct tapi_handle *handle, msg_error_t err)
 {
        MSG_BEGIN();
 
@@ -454,12 +556,14 @@ void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
 
        int tapiRet = TAPI_API_SUCCESS;
 
+       int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
+
        if (err == MSG_SUCCESS)
        {
                tpdu.data.deliverRep.reportType = SMS_REPORT_POSITIVE;
                response = TAPI_NETTEXT_SENDSMS_SUCCESS;
 
-               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, TapiEventMemoryStatus, NULL);
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, TapiEventMemoryStatus, NULL);
 
                if (tapiRet == TAPI_API_SUCCESS)
                {
@@ -475,7 +579,7 @@ void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
                tpdu.data.deliverRep.reportType = SMS_REPORT_POSITIVE;
                response = TAPI_NETTEXT_SENDSMS_SUCCESS;
 
-               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
 
                if (tapiRet == TAPI_API_SUCCESS)
                {
@@ -491,7 +595,7 @@ void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
                tpdu.data.deliverRep.reportType = SMS_REPORT_POSITIVE;
                response = TAPI_NETTEXT_SENDSMS_SUCCESS;
 
-               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
+               tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
 
                if (tapiRet == TAPI_API_SUCCESS)
                {
@@ -539,7 +643,7 @@ void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
        SMS_ADDRESS_S smsc;
 
        // Set SMSC Options
-       setSmscOptions(&smsc);
+       setSmscOptions(simIndex, &smsc);
 
        // Encode SMSC Address
        unsigned char smscAddr[MAX_SMSC_LEN];
@@ -555,7 +659,7 @@ void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
        pkgInfo.Sca[smscLen] = '\0';
 
        // Send Deliver Report
-       tapiRet = tel_send_sms_deliver_report(pTapiHandle, &pkgInfo, response, TapiEventDeliveryReportCNF, NULL);
+       tapiRet = tel_send_sms_deliver_report(handle, &pkgInfo, response, TapiEventDeliveryReportCNF, NULL);
 
        if (tapiRet == TAPI_API_SUCCESS)
        {
@@ -571,7 +675,7 @@ void SmsPluginTransport::sendClass0DeliverReport(msg_error_t err)
 
 
 
-void SmsPluginTransport::setSmsSendOptions(SMS_SUBMIT_S *pSubmit)
+void SmsPluginTransport::getSmsSendOption(SMS_SUBMIT_S *pSubmit)
 {
        // Set SMS Send Options
        pSubmit->bRejectDup = false;
@@ -592,76 +696,109 @@ void SmsPluginTransport::setSmsSendOptions(SMS_SUBMIT_S *pSubmit)
 
        int selectIdx = MsgSettingGetInt(SMSC_SELECTED);
 
-       char keyName[128];
+       char keyName[MAX_VCONFKEY_NAME_LEN];
 
        memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_PID, selectIdx);
+       snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_PID, selectIdx);
        MSG_SMS_PID_T pid = (MSG_SMS_PID_T)MsgSettingGetInt(keyName);
 
        pSubmit->pid = convertPid(pid);
        MSG_DEBUG("PID : %d", pSubmit->pid);
 
        memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_VAL_PERIOD, selectIdx);
+       snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_VAL_PERIOD, selectIdx);
        int valPeriod = MsgSettingGetInt(keyName);
 
+       pSubmit->vpf = SMS_VPF_NOT_PRESENT; // default value
+
        MSG_DEBUG("valPeriod : %d", valPeriod);
+       MSG_DEBUG("vpf : %d", pSubmit->vpf);
+}
 
-       if (valPeriod == 0)
-       {
-               pSubmit->vpf = SMS_VPF_NOT_PRESENT;
+
+void SmsPluginTransport::setSmsSendOption(SMS_REQUEST_INFO_S *pReqInfo, SMS_TPDU_S* pSmsTpdu)
+{
+       if (!pReqInfo || !pSmsTpdu) {
+               MSG_DEBUG("Input param is NULL");
+               return;
        }
-       else
+
+       if (pReqInfo->sendOptInfo.bSetting == true)
        {
-               pSubmit->vpf = SMS_VPF_RELATIVE;
-               pSubmit->validityPeriod.format = SMS_TIME_RELATIVE;
-               pSubmit->validityPeriod.time.relative.time = valPeriod;
+               pSmsTpdu->data.submit.bStatusReport = pReqInfo->sendOptInfo.bDeliverReq;
+               pSmsTpdu->data.submit.bReplyPath = pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath;
        }
 }
 
 
-void SmsPluginTransport::setSmscOptions(SMS_ADDRESS_S *pSmsc)
+void SmsPluginTransport::setSmsDcsOption(SMS_REQUEST_INFO_S *pReqInfo, SMS_TPDU_S* pSmsTpdu)
 {
-       // Set SMSC Options
-       int selectIdx = MsgSettingGetInt(SMSC_SELECTED);
-
-       char keyName[128];
+       if (!pReqInfo || !pSmsTpdu) {
+               MSG_DEBUG("Input param is NULL");
+               return;
+       }
 
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_ADDRESS, selectIdx);
+       if (pReqInfo->msgInfo.msgPort.valid == true) {
+               // Set Coding Scheme for apps that use port number
+               pSmsTpdu->data.submit.dcs.codingScheme = (SMS_CODING_SCHEME_T)pReqInfo->msgInfo.encodeType;
+               MSG_DEBUG("DCS is changed by application : [%d]", pSmsTpdu->data.submit.dcs.codingScheme);
+       } else {
+               // Change coding scheme if it is set coding scheme by apps
+               if (pSmsTpdu->data.submit.dcs.codingScheme == SMS_CHARSET_7BIT && pReqInfo->msgInfo.encodeType != MSG_ENCODE_GSM7BIT) {
+                       pSmsTpdu->data.submit.dcs.codingScheme = (SMS_CODING_SCHEME_T)pReqInfo->msgInfo.encodeType;
+                       MSG_DEBUG("DCS is changed by application : [%d]", pSmsTpdu->data.submit.dcs.codingScheme);
+               }
+       }
+}
 
-       char* tmpValue = NULL;
 
-       tmpValue = MsgSettingGetString(keyName);
+void SmsPluginTransport::setSmsReportOption(SMS_REQUEST_INFO_S *pReqInfo, SMS_TPDU_S* pSmsTpdu)
+{
+       if (!pReqInfo || !pSmsTpdu) {
+               MSG_DEBUG("Input param is NULL");
+               return;
+       }
 
-       if (tmpValue != NULL)
+#ifdef MSG_SMS_REPORT
+       // Update Msg Ref into Report Table
+       if (pSmsTpdu->data.submit.bStatusReport == true)
        {
-               memset(pSmsc->address, 0x00, sizeof(pSmsc->address));
-               strncpy(pSmsc->address, tmpValue, MAX_ADDRESS_LEN);
+               MSG_DEBUG("Update Msg Ref [%d] in Report Table", pSmsTpdu->data.submit.msgRef);
 
-               MSG_DEBUG("address : %s", pSmsc->address);
+               SmsPluginStorage::instance()->updateMsgRef(pReqInfo->msgInfo.msgId, pSmsTpdu->data.submit.msgRef);
        }
-       else
-       {
-               strncpy(pSmsc->address, "+8210911111", MAX_ADDRESS_LEN);
+#endif
+
+       // Set Message Reference
+       if (pSmsTpdu->data.submit.bStatusReport == true) {
+               pSmsTpdu->data.submit.msgRef = (pReqInfo->msgInfo.msgId % 256);
        }
+}
 
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_TON, selectIdx);
-       pSmsc->ton = (SMS_TON_T)MsgSettingGetInt(keyName);
 
-       MSG_DEBUG("ton : %d", pSmsc->ton);
+void SmsPluginTransport::setSmscOptions(int simIndex, SMS_ADDRESS_S *pSmsc)
+{
+       // Set SMSC Options
+       MSG_SMSC_LIST_S smscList = {0,};
+       SmsPluginSetting::instance()->getSmscListInfo(simIndex, &smscList);
 
-       memset(keyName, 0x00, sizeof(keyName));
-       sprintf(keyName, "%s/%d", SMSC_NPI, selectIdx);
-       pSmsc->npi = (SMS_NPI_T)MsgSettingGetInt(keyName);
+       int selectIdx = smscList.selected;
 
-       MSG_DEBUG("npi : %d", pSmsc->npi);
+       if (selectIdx < SMSC_LIST_MAX) {
+               if (smscList.smscData[selectIdx].smscAddr.address[0] != '\0') {
+                       memset(pSmsc->address, 0x00, sizeof(pSmsc->address));
+                       strncpy(pSmsc->address, smscList.smscData[selectIdx].smscAddr.address, MAX_ADDRESS_LEN);
 
-       if (tmpValue != NULL)
-       {
-               free(tmpValue);
-               tmpValue = NULL;
+                       MSG_SEC_DEBUG("address : %s", pSmsc->address);
+               } else {
+                       memset(pSmsc->address, 0x00, MAX_ADDRESS_LEN);
+               }
+
+               pSmsc->ton = (SMS_TON_T)smscList.smscData[selectIdx].smscAddr.ton;
+               MSG_DEBUG("ton : %d", pSmsc->ton);
+
+               pSmsc->npi = (SMS_NPI_T)smscList.smscData[selectIdx].smscAddr.npi;
+               MSG_DEBUG("npi : %d", pSmsc->npi);
        }
 }
 
@@ -677,13 +814,15 @@ void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo,
 
        MSG_DEBUG("ton [%d]", pData->destAddress.ton);
        MSG_DEBUG("npi [%d]", pData->destAddress.npi);
-       MSG_DEBUG("address [%s]", pData->destAddress.address);
+       MSG_SEC_DEBUG("address [%s]", pData->destAddress.address);
 
        int decodeLen = 0, bufSize = (MAX_GSM_7BIT_DATA_LEN*MAX_SEGMENT_NUM) + 1;       // SMS_CHARSET_7BIT
 
        unsigned char decodeData[bufSize];
        memset(decodeData, 0x00, sizeof(decodeData));
 
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
+
        msg_encode_type_t encodeType = MSG_ENCODE_GSM7BIT;
 
        MSG_LANGUAGE_ID_T langId = MSG_LANG_ID_RESERVED;
@@ -695,7 +834,7 @@ void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo,
        {
                if (*pCharType == SMS_CHARSET_7BIT)
                {
-                       decodeLen = textCvt.convertUTF8ToGSM7bit(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize, &langId, &bAbnormal);
+                       decodeLen = textCvt->convertUTF8ToGSM7bit(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize, &langId, &bAbnormal);
                }
                else if (*pCharType == SMS_CHARSET_8BIT)
                {
@@ -704,11 +843,11 @@ void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo,
                }
                else if (*pCharType == SMS_CHARSET_UCS2)
                {
-                       decodeLen = textCvt.convertUTF8ToUCS2(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize);
+                       decodeLen = textCvt->convertUTF8ToUCS2(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize);
                }
                else if (*pCharType == SMS_CHARSET_AUTO)
                {
-                       decodeLen = textCvt.convertUTF8ToAuto(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize, &encodeType);
+                       decodeLen = textCvt->convertUTF8ToAuto(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize, &langId, &encodeType);
                        *pCharType = encodeType;
                }
        }
@@ -727,7 +866,7 @@ void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo,
 
                if (*pCharType == SMS_CHARSET_7BIT)
                {
-                       decodeLen = textCvt.convertUTF8ToGSM7bit(decodeData, bufSize, (unsigned char*)pFileData, fileSize, &langId, &bAbnormal);
+                       decodeLen = textCvt->convertUTF8ToGSM7bit(decodeData, bufSize, (unsigned char*)pFileData, fileSize, &langId, &bAbnormal);
                }
                else if (*pCharType == SMS_CHARSET_8BIT)
                {
@@ -736,11 +875,11 @@ void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo,
                }
                else if (*pCharType == SMS_CHARSET_UCS2)
                {
-                       decodeLen = textCvt.convertUTF8ToUCS2(decodeData, bufSize, (unsigned char*)pFileData, fileSize);
+                       decodeLen = textCvt->convertUTF8ToUCS2(decodeData, bufSize, (unsigned char*)pFileData, fileSize);
                }
                else if (*pCharType == SMS_CHARSET_AUTO)
                {
-                       decodeLen = textCvt.convertUTF8ToAuto(decodeData, bufSize, (unsigned char*)pFileData, fileSize, &encodeType);
+                       decodeLen = textCvt->convertUTF8ToAuto(decodeData, bufSize, (unsigned char*)pFileData, fileSize, &langId, &encodeType);
                        *pCharType = encodeType;
                }
 
@@ -752,7 +891,7 @@ void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo,
 MSG_DEBUG("decode length : [%d]", decodeLen);
 MSG_DEBUG("character type : [%d]", *pCharType);
 MSG_DEBUG("Language Identifier : [%d]", langId);
-MSG_DEBUG("reply address : [%s]", pMsgInfo->replyAddress);
+MSG_SEC_DEBUG("reply address : [%s]", pMsgInfo->replyAddress);
 
        int addrLen = 0;
 
@@ -935,22 +1074,22 @@ void SmsPluginTransport::setConcatHeader(SMS_UDH_S *pSrcHeader, SMS_UDH_S *pDstH
 }
 
 
-void SmsPluginTransport::setNetStatus(msg_network_status_t netStatus)
+void SmsPluginTransport::setNetStatus(SMS_NETWORK_STATUS_T sentStatus)
 {
        mx.lock();
-       curStatus = netStatus;
+       curStatus = sentStatus;
        cv.signal();
        mx.unlock();
 }
 
 
-msg_network_status_t SmsPluginTransport::getNetStatus()
+SMS_NETWORK_STATUS_T SmsPluginTransport::getNetStatus()
 {
        mx.lock();
 
        int ret = 0;
 
-       if (curStatus == MSG_NETWORK_SENDING)
+       if (curStatus == SMS_NETWORK_SENDING)
                ret = cv.timedwait(mx.pMutex(), 125);
 
        mx.unlock();
@@ -958,13 +1097,48 @@ msg_network_status_t SmsPluginTransport::getNetStatus()
        if (ret == ETIMEDOUT)
        {
                MSG_DEBUG("WARNING: SENT STATUS TIME-OUT");
-               curStatus = MSG_NETWORK_SEND_TIMEOUT;
+               curStatus = SMS_NETWORK_SEND_FAIL_TIMEOUT;
        }
 
        return curStatus;
 }
 
 
+void SmsPluginTransport::setMoCtrlStatus(TelSatMoSmCtrlIndData_t *moCtrlData)
+{
+       mx.lock();
+
+       if (moCtrlData) {
+               memset(&curMoCtrlData, 0x00, sizeof(TelSatMoSmCtrlIndData_t));
+               memcpy(&curMoCtrlData, moCtrlData, sizeof(TelSatMoSmCtrlIndData_t));
+               MSG_DEBUG("MO Control Data is set by Tapi Event Noti");
+       }
+
+       cv.signal();
+       mx.unlock();
+}
+
+
+int SmsPluginTransport::getMoCtrlStatus()
+{
+       mx.lock();
+
+       int ret = 0;
+
+       ret = cv.timedwait(mx.pMutex(), 10);
+
+       mx.unlock();
+
+       if (ret == ETIMEDOUT)
+       {
+               MSG_DEBUG("WARNING: SENT STATUS TIME-OUT");
+               return -1;
+       }
+
+       return (curMoCtrlData.moSmsCtrlResult);
+}
+
+
 unsigned char SmsPluginTransport::getMsgRef()
 {
        return msgRef++;
index d07b611..b5b0892 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -55,11 +55,16 @@ void SmsPluginUAManager::run()
 {
        while (1)
        {
-               if (smsTranQ.empty())
-                       cv.wait(mx.pMutex());
-
+               lock();
+               while (smsTranQ.empty()) {
+                       wait();
+               }
                SMS_REQUEST_INFO_S request;
                smsTranQ.front(&request);
+               unlock();
+
+               request.msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&request.msgInfo.addressList);
 
                try
                {
@@ -69,18 +74,23 @@ void SmsPluginUAManager::run()
                {
                        MSG_FATAL("%s", e.what());
 
+                       lock();
                        smsTranQ.pop_front();
+                       unlock();
                        continue;
                }
                catch (exception& e)
                {
                        MSG_FATAL("%s", e.what());
-
+                       lock();
                        smsTranQ.pop_front();
+                       unlock();
                        continue;
                }
 
+               lock();
                smsTranQ.pop_front();
+               unlock();
        }
 }
 
@@ -90,7 +100,12 @@ void SmsPluginUAManager::addReqEntity(SMS_REQUEST_INFO_S *request)
        SMS_REQUEST_INFO_S reqTmp = {0,};
 
        memcpy(&reqTmp, request, sizeof(SMS_REQUEST_INFO_S));
+
+       lock();
+
        smsTranQ.push_back(reqTmp);
        cv.signal();
+
+       unlock();
 }
 
index af06b28..2b821be 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -157,6 +157,15 @@ MSG_DEBUG("dataLen [%d]", pUserData->length);
 MSG_DEBUG("packSize [%d]", packSize);
 MSG_DEBUG("encodeLen [%d]", encodeLen);
 
+#if 0
+printf("\n\n[encodeGSMData] userData data.\n");
+for (int j = 0; j < encodeLen; j++)
+{
+       printf(" [%02x]", pEncodeData[j]);
+}
+printf("\n\n");
+#endif
+
        return encodeLen;
 }
 
@@ -239,6 +248,15 @@ MSG_DEBUG("dataLen [%d]", pUserData->length);
 
        encodeLen = offset + pUserData->length;
 
+#if 0
+printf("\n\n[encodeUCS2Data] userData data.\n");
+for (int j = 0; j < encodeLen; j++)
+{
+       printf(" [%02x]", pEncodeData[j]);
+}
+printf("\n\n");
+#endif
+
        return encodeLen;
 }
 
@@ -576,6 +594,11 @@ int SmsPluginUDCodec::encodeHeader(const SMS_UDH_S header, char *pEncodeHeader)
 
                        addrLen = SmsPluginParamCodec::encodeAddress(&(header.udh.alternateAddress), &encodedAddr);
 
+//MSG_DEBUG("addrLen : %d", addrLen);
+
+//for (int i = 0; i < addrLen; i++)
+//     MSG_DEBUG("header.udh.alternateAddress.address : [%02x]", encodedAddr[i]);
+
                        // IEDL
                        pEncodeHeader[offset++] = addrLen;
 
@@ -709,7 +732,7 @@ MSG_DEBUG("Decoding special sms udh.");
 
                        offset += SmsPluginParamCodec::decodeAddress(&pTpdu[offset], &(pHeader->udh.alternateAddress));
 
-MSG_DEBUG("alternate reply address [%s]", pHeader->udh.alternateAddress.address);
+                       MSG_SEC_DEBUG("alternate reply address [%s]", pHeader->udh.alternateAddress.address);
                }
                break;
 
@@ -774,11 +797,11 @@ int SmsPluginUDCodec::pack7bitChar(const unsigned char *pUserData, int dataLen,
                        pPackData[dstIdx] = pUserData[srcIdx];
 
 //MSG_DEBUG("pPackData [%02x]", pPackData[dstIdx]);
-                       if (srcIdx >= dataLen) break;
-
                        shift = 7;
                        srcIdx++;
                        dstIdx++;
+
+                       if (srcIdx >= dataLen) break;
                }
 
                if (shift > 1)
index 3596afa..f204c7f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
 #include "SmsPluginEventHandler.h"
 #include "SmsPluginWapPushHandler.h"
 
-
-#include <drm_client.h>
+#include <glib.h>
 #include <dbus/dbus-glib.h>
+#if MSG_DRM_SUPPORT
+#include <drm_client.h>
+#endif
 
 static unsigned short wapPushPortList [] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
 
@@ -613,7 +615,21 @@ const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] =
        { (char*)"x-wap-application:syncml.dm", 0x07 },
        { (char*)"x-wap-application:drm.ua", 0x08 },
        { (char*)"x-wap-application:emn.ua", 0x09 },
+       { (char*)"x-oma-application:ulp.ua ", 0x10 },
+       { (char*)"x-oma-docomo:open.ctl", 0x9055 },
        { (char*)"x-oma-docomo:xmd.mail.ua", 0x905C },
+       { (char*)"x-oma-docomo:xmd.storage.ua", 0x905F },
+       { (char*)"x-oma-docomo:xmd.lcsapp.ua", 0x9060 },
+       { (char*)"x-oma-docomo:xmd.info.ua", 0x9061 },
+       { (char*)"x-oma-docomo:xmd.agent.ua", 0x9062 },
+       { (char*)"x-oma-docomo:xmd.sab.ua", 0x9063 },
+       { (char*)"x-oma-docomo:xmd.am.ua", 0x9064 },
+       { (char*)"x-oma-docomo:xmd.emdm.ua", 0x906B },
+       { (char*)"x-oma-docomo:xmd.lac.ua", 0x906C },
+       { (char*)"x-oma-docomo:xmd.osv.ua", 0x906D },
+       { (char*)"x-oma-docomo:xmd.dcs.ua", 0x906E },
+       { (char*)"x-oma-docomo:xmd.wipe.ua", 0x906F },
+       { (char*)"x-oma-docomo:xmd.vdapp.ua ", 0x9070 },
 };
 
 
@@ -792,7 +808,7 @@ void SmsPluginWapPushHandler::copyDeliverData(SMS_DELIVER_S *pDeliver)
 
        strncpy(tmpAddress.address, pDeliver->originAddress.address, MAX_ADDRESS_LEN);
 
-       MSG_DEBUG("Address [%s]", tmpAddress.address);
+       MSG_SEC_DEBUG("Address [%s]", tmpAddress.address);
 
        tmpTimeStamp.format = pDeliver->timeStamp.format;
 
@@ -808,7 +824,7 @@ void SmsPluginWapPushHandler::copyDeliverData(SMS_DELIVER_S *pDeliver)
 }
 
 
-void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize)
+void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize, int simIndex)
 {
        MSG_BEGIN();
 
@@ -923,7 +939,7 @@ void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSi
                return;
        }
 
-       handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen);
+       handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen, simIndex);
 
        MSG_END();
 }
@@ -1098,8 +1114,8 @@ static void launchProcessByAppcode(int appcode)
                                        g_error_free(error);
                                        MSG_END();
                                }
-                               dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadmagent",
-                                                                      "/com/samsung/omadmagent", "com.samsung.omadmagent");
+                               dbus_proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.omadmagent",
+                                                                      "/org/tizen/omadmagent", "org.tizen.omadmagent");
                                MSG_DEBUG("dbus_proxy %x", dbus_proxy);
                                dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
                                g_object_unref(dbus_proxy);
@@ -1116,8 +1132,8 @@ static void launchProcessByAppcode(int appcode)
                                        g_error_free(error);
                                        MSG_END();
                                }
-                               dbus_proxy = dbus_g_proxy_new_for_name(connection, "com.samsung.omadsagent",
-                                                                                "/com/samsung/omadsagent", "com.samsung.omadsagent");
+                               dbus_proxy = dbus_g_proxy_new_for_name(connection, "org.tizen.omadsagent",
+                                                                                "/org/tizen/omadsagent", "org.tizen.omadsagent");
                                MSG_DEBUG("dbus_proxy %x", dbus_proxy);
                                dbus_g_proxy_call(dbus_proxy, "Hello_Agent", &error, G_TYPE_INVALID, G_TYPE_INVALID);
                                g_object_unref(dbus_proxy);
@@ -1132,7 +1148,7 @@ static void launchProcessByAppcode(int appcode)
 }
 
 
-void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
+void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen, int simIndex)
 {
        MSG_BEGIN();
 
@@ -1147,7 +1163,7 @@ void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPu
        char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN] = {0,};
        SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
 
-       err = storageHandler->getRegisteredPushEvent(pPushHeader, &pushEvt_cnt, app_id, content_type);
+       err = storageHandler->getRegisteredPushEvent(pPushHeader, &pushEvt_cnt, app_id, sizeof(app_id), content_type, sizeof(content_type));
        MSG_DEBUG("pushEvt_cnt: %d", pushEvt_cnt);
        if(err != MSG_SUCCESS) {
                MSG_DEBUG("Fail to get registered push event");
@@ -1168,83 +1184,90 @@ void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPu
                        return;
                }
 
+#ifdef FEATURE_MMS_DISABLE
+               if(appcode == SMS_WAP_APPLICATION_MMS_UA){
+                       MSG_DEBUG("Drop MMS Notification for DOCOMO");
+                       return;
+               }
+
+#endif
                launchProcessByAppcode(appcode);
 
                switch (appcode) {
                case SMS_WAP_APPLICATION_MMS_UA:
                        MSG_DEBUG("Received MMS Notification");
-                       handleMMSNotification(pPushBody, PushBodyLen);
+                       handleMMSNotification(pPushBody, PushBodyLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_SI:
                        MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
-                       handleSIMessage(pPushBody, PushBodyLen, true);
+                       handleSIMessage(pPushBody, PushBodyLen, true, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_SIC:
                        MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
-                       handleSIMessage(pPushBody, PushBodyLen, false);
+                       handleSIMessage(pPushBody, PushBodyLen, false, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_SL:
                        MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
-                       handleSLMessage(pPushBody, PushBodyLen, true);
+                       handleSLMessage(pPushBody, PushBodyLen, true, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_SLC:
                        MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
-                       handleSLMessage(pPushBody, PushBodyLen, false);
+                       handleSLMessage(pPushBody, PushBodyLen, false, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_CO:
                        MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
-                       handleCOMessage(pPushBody, PushBodyLen, true);
+                       handleCOMessage(pPushBody, PushBodyLen, true, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_COC:
                        MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
-                       handleCOMessage(pPushBody, PushBodyLen, false);
+                       handleCOMessage(pPushBody, PushBodyLen, false, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
                        MSG_DEBUG("Received DM BOOTSTRAP");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
                        MSG_DEBUG("Received DM BOOTSTRAP");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
                        MSG_DEBUG("Received Provisioning");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
                        MSG_DEBUG("Received Provisioning");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
                case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
                        MSG_DEBUG("Received Provisioning");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
                        MSG_DEBUG("Received DM Notification");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
                        MSG_DEBUG("Received DS Notification");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
                        MSG_DEBUG("Received DS Notification");
-                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
                        break;
 
                case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
@@ -1263,14 +1286,14 @@ void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPu
                        MSG_DEBUG("Received DRM V2");
                        // TODO: DRM V2
                        break;
-#if 0
+
                case SMS_WAP_APPLICATION_PUSH_EMAIL:
                case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
                case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
                        MSG_DEBUG("Received Email");
                        // TODO: Email
                        break;
-#endif
+
 
                case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
                        MSG_DEBUG("Received IMPS CIR");
@@ -1299,7 +1322,7 @@ void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPu
 }
 #endif
 
-void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen)
+void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen, int simIndex)
 {
        MSG_BEGIN();
 
@@ -1317,13 +1340,18 @@ void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int P
        MSG_MESSAGE_INFO_S msgInfo;
        memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        createMsgInfo(&msgInfo);
 
        /** Convert Type values */
        msgInfo.msgType.mainType = MSG_MMS_TYPE;
        msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
+       msgInfo.msgType.classType = MSG_CLASS_NONE;
        msgInfo.storageId = MSG_STORAGE_PHONE;
        msgInfo.dataSize = PushBodyLen;
+       msgInfo.sim_idx = simIndex;
 
        if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
                msgInfo.bTextSms = false;
@@ -1349,7 +1377,7 @@ void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int P
        msg_error_t err = MSG_SUCCESS;
 
        /** Add MMS Noti Msg into DB */
-       err = SmsPluginStorage::instance()->addMessage(&msgInfo);
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
 
        if (err == MSG_SUCCESS) {
                /**  Callback */
@@ -1359,13 +1387,13 @@ void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int P
                        MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
                }
        } else {
-               MSG_DEBUG("addMessage() Error !! [%d]", err);
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
        }
 
        MSG_END();
 }
 
-void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText)
+void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
 {
        MSG_BEGIN();
 
@@ -1401,7 +1429,7 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
 
        while (indNode != NULL) {
                if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
-                       MSG_DEBUG("indNode->name = %s\n", indNode->name);
+                       MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
                        break;
                }
 
@@ -1430,7 +1458,7 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
        }
 
        if (tmpXmlChar != NULL)
-               strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
+               strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
 
        tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
 
@@ -1481,6 +1509,10 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
 
        /**  Pack Message Info Structure */
        MSG_MESSAGE_INFO_S msgInfo;
+       memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
        createMsgInfo(&msgInfo);
 
@@ -1491,6 +1523,8 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
        msgInfo.msgType.subType = MSG_WAP_SI_SMS;
 
        msgInfo.dataSize = sizeof(pushMsg);
+       msgInfo.sim_idx = simIndex;
+       getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
 
        xmlFree(xmlDoc);
        xmlFree(tmpXmlChar);
@@ -1498,7 +1532,7 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
        msg_error_t err = MSG_SUCCESS;
 
        /** Add WAP Push Msg into DB */
-       err = SmsPluginStorage::instance()->addMessage(&msgInfo);
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
 
        if (err == MSG_SUCCESS) {
                /** Callback */
@@ -1508,7 +1542,7 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
                        MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
                }
        } else {
-               MSG_DEBUG("addMessage() Error !! [%d]", err);
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
        }
 
        MSG_END();
@@ -1517,7 +1551,7 @@ void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen,
 }
 
 
-void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText)
+void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
 {
        MSG_BEGIN();
 
@@ -1550,14 +1584,14 @@ void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen,
                xmlFreeDoc(xmlDoc);
                return;
        } else {
-               MSG_DEBUG("Not an empty Document and topNode->name = %s \n",topNode->name );
+               MSG_SEC_DEBUG("Not an empty Document and topNode->name = %s \n",topNode->name );
        }
 
        indNode = topNode;
 
        while (indNode != NULL) {
                if (!xmlStrcmp(indNode->name, (const xmlChar*) "sl")) {
-                       MSG_DEBUG("indNode->name = %s\n",indNode->name);
+                       MSG_SEC_DEBUG("indNode->name = %s\n",indNode->name);
                        break;
                }
 
@@ -1592,7 +1626,7 @@ void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen,
        MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
        MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
        MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
-       MSG_DEBUG("pushMsg.id : [%s]", pushMsg.id);
+       MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
        MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
        MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
 
@@ -1608,6 +1642,10 @@ void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen,
 
        /** Pack Message Info Structure */
        MSG_MESSAGE_INFO_S msgInfo;
+       memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
        createMsgInfo(&msgInfo);
 
@@ -1621,14 +1659,25 @@ void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen,
        strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
 
        msgInfo.dataSize = sizeof(pushMsg);
+       msgInfo.sim_idx = simIndex;
+       getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
 
        MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
 
-       /** Callback to MSG FW */
-       err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
+       /** Add WAP Push Msg into DB */
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+
+       if(err == MSG_SUCCESS)
+       {
+
+               /** Callback to MSG FW */
+               err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
 
-       if (err != MSG_SUCCESS)
-               MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
+               if (err != MSG_SUCCESS)
+                       MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
+       } else {
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
+       }
 
        xmlFree(xmlDoc);
        xmlFree(tmpXmlChar);
@@ -1638,7 +1687,7 @@ void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen,
        return;
 }
 
-void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText)
+void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
 {
        MSG_PUSH_CACHEOP_S cacheOp;
 
@@ -1676,7 +1725,7 @@ void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen,
 
                xmlChar* tmpUrl = NULL;
                if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_OBJ)) {
-                       MSG_DEBUG("indNode->name = %s\n", indNode->name);
+                       MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
 
                        tmpUrl = xmlGetProp(indNode, (xmlChar*) SMS_PUSH_XML_CO_URI);
 
@@ -1688,7 +1737,7 @@ void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen,
                                MSG_DEBUG("NO href value from the xmlDoc\n");
                        }
                } else if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_SVC)) {
-                       MSG_DEBUG("indNode->name = %s\n",indNode->name);
+                       MSG_SEC_DEBUG("indNode->name = %s\n",indNode->name);
                        tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
 
                        if (tmpUrl != NULL) {
@@ -1721,6 +1770,10 @@ void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen,
 
        /**  Pack Message Info Structure */
        MSG_MESSAGE_INFO_S msgInfo;
+       memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
        createMsgInfo(&msgInfo);
 
@@ -1731,11 +1784,12 @@ void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen,
        msgInfo.msgType.subType = MSG_WAP_CO_SMS;
 
        msgInfo.dataSize = sizeof(cacheOp);
+       msgInfo.sim_idx = simIndex;
 
        msg_error_t err = MSG_SUCCESS;
 
        /** Add WAP Push Msg into DB */
-       err = SmsPluginStorage::instance()->addMessage(&msgInfo);
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
 
        if (err == MSG_SUCCESS) {
                /** Callback */
@@ -1745,7 +1799,7 @@ void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen,
                        MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
                }
        } else {
-               MSG_DEBUG("addMessage() Error !! [%d]", err);
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
        }
 
        xmlFree(xmlDoc);
@@ -1756,6 +1810,7 @@ void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen,
 
 void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
 {
+#if MSG_DRM_SUPPORT
        int drmRt = DRM_RETURN_SUCCESS;
        char* cid = NULL;
        AutoPtr<char> buf(&cid);
@@ -1781,7 +1836,7 @@ void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
        } else {
                MSG_DEBUG("Fail to regist DRM to drm-service.");
        }
-
+#endif
        return;
 }
 
@@ -1861,6 +1916,10 @@ void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
 
        /**  Convert Address values */
        pMsgInfo->nAddressCnt = 1;
+
+       pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+       memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
        pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
        strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.address, MAX_ADDRESS_VAL_LEN);
 
@@ -1879,7 +1938,7 @@ void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBod
 
 
        if (isText) {
-               *pXmlDoc = xmlParseMemory(pPushBody, strlen(pPushBody));
+               *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
        } else {
                WB_UTINY*       xmldata = NULL;
                WBXMLConvWBXML2XML *conv = NULL;
@@ -1900,7 +1959,7 @@ void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBod
 
                MSG_DEBUG("xmldata : \n%s\n", xmldata);
 
-               *pXmlDoc = xmlParseMemory((char*)xmldata, strlen((char*)xmldata));
+               *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
        }
 
 }
@@ -1916,7 +1975,7 @@ unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
        memset(&timeStruct, 0x00, sizeof(struct tm));
 
        /** check pDate */
-       if (strlen(pDate)<20)
+       if (AcStrlen(pDate)<20)
                return 0;
 
        MSG_DEBUG("pDate [%s]", pDate);
@@ -1984,27 +2043,27 @@ msg_push_action_t SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pActio
        }
 
        /** compare  with signal-none. */
-       comp = strcmp( "signal-none", pAction );
+       comp = g_strcmp0( "signal-none", pAction );
        if (comp == 0)
                return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
 
        /** compare  with signal-low. */
-       comp = strcmp( "signal-low", pAction );
+       comp = g_strcmp0( "signal-low", pAction );
        if (comp == 0)
                return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
 
        /**  compare  with signal-medium. */
-       comp = strcmp( "signal-medium", pAction );
+       comp = g_strcmp0( "signal-medium", pAction );
        if (comp == 0)
                return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
 
        /**  compare  with signal-high. */
-       comp = strcmp( "signal-high", pAction );
+       comp = g_strcmp0( "signal-high", pAction );
        if (comp == 0)
                return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
 
        /**  compare  with delete. */
-       comp = strcmp( "delete", pAction );
+       comp = g_strcmp0( "delete", pAction );
        if (comp == 0)
                return MSG_PUSH_SI_ACTION_DELETE;
 
@@ -2023,17 +2082,17 @@ msg_push_action_t SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pActio
        }
 
        /**  compare pSrcStr with execute-low. */
-       comp = strcmp( "execute-low", pAction );
+       comp = g_strcmp0( "execute-low", pAction );
        if (comp == 0)
                return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
 
        /**  compare pSrcStr with execute-high. */
-       comp = strcmp( "execute-high", pAction );
+       comp = g_strcmp0( "execute-high", pAction );
        if (comp == 0)
                return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
 
        /** compare pSrcStr with cache. */
-       comp = strcmp( "cache", pAction );
+       comp = g_strcmp0( "cache", pAction );
        if (comp == 0)
                return MSG_PUSH_SL_ACTION_CACHE;
 
@@ -2148,13 +2207,17 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
        /* Is it reacehd end of header? */
        while (iEncodedHeader < encodedHeaderLen) {
                /* Get memory for single header */
-               temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
                if (temper == NULL) {
-                       MSG_DEBUG("temper Memory allocation is failed.\n" );
-                       return;
-               }
+                       temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
 
-               memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
+                       if (temper == NULL) {
+                               MSG_DEBUG("temper Memory allocation is failed.\n" );
+                               return;
+                       }
+                       memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
+               } else {
+                       memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
+               }
 
                /* this section presents header code page shifting procedure
                   This part can be implemented by future request.
@@ -2353,6 +2416,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                unsigned long  i = 0;
                                                                /* encoded content type length body */
                                                                unsigned long  tempLen;
+                                                               MSG_DEBUG("fieldValueLen: %d", fieldValueLen);
 
                                                                /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
                                                                if (0 == fieldValueLen) {
@@ -2365,8 +2429,8 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                        MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n" );
                                                                }
 
-                                                               if ((fieldValue[0] < 0x20 ) || (fieldValue[0] > 0x80 )) {
-                                                                       if (fieldValue[0] > 0x80) {
+                                                               if ((fieldValue[0] < 0x20 ) || (fieldValue[0] >= 0x80 )) {
+                                                                       if (fieldValue[0] >= 0x80) {
                                                                                tempLen = 1;
                                                                        } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /** 06 05 02 03 0A AF 89 */
                                                                                fieldValue[3] = fieldValue[2];
@@ -2400,7 +2464,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                        } else {
                                                                                contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
 
-                                                                               while ((wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspUnregisteredContentsTypeCount)) i++;
+                                                                               while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode)) i++;
 
                                                                                /** If there is a Content-Type assigned, */
                                                                                if (i < wspUnregisteredContentsTypeCount)
@@ -2514,7 +2578,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                        if((unsigned int)integerValue == wspHeaderApplId[i].parameterCode)
                                                                        {
                                                                                snprintf((char*)temp, 64, "%s", wspHeaderApplId[i].parameterToken);
-                                                                               strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1);
+                                                                               strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
                                                                                break;
                                                                        }
                                                                }
@@ -2523,7 +2587,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                /* Accept-Application */
                                                case 0x32 :
                                                        if (0x80 == fieldValue[0]) {
-                                                               strncat( (char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
+                                                               strncat( (char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1 );
                                                        } else {
 
                                                                unsigned char temp[16];
@@ -2533,7 +2597,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                 else
                                                                */
                                                                sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ));
-                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1);
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
                                                        }
                                                        break;
 
@@ -2555,21 +2619,21 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                char* decodedString = NULL;
                                                                AutoPtr<char> decodedStringbuf(&decodedString);
                                                                wspHeaderDecodeDateValue( fieldValueLen, fieldValue, &decodedString);
-                                                               strncat( (char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
+                                                               strncat( (char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1 );
                                                        }
                                                        break;
 
                                                /* connection */
                                                case 0x09 :
                                                        if (fieldValue[0] == 0x80 )
-                                                               strncat( (char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
+                                                               strncat( (char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1 );
                                                        break;
                                                /* accept-ranges */
                                                case 0x04 :
                                                        if (fieldValue[0] == 0x80 )
-                                                               strncat( (char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
+                                                               strncat( (char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1 );
                                                        if (fieldValue[0] == 0x81 )
-                                                               strncat( (char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
+                                                               strncat( (char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1 );
                                                        break;
                                                /* content-md5 */
                                                case 0x0f :
@@ -2628,7 +2692,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                iField = AcStrlen( (char*)authScheme ) + 1;
                                                                strncpy( (char*)realmValue, (char*)(fieldValue + iField ), WSP_STANDARD_STR_LEN_MAX-1);
                                                                iField = iField + AcStrlen( (char*)realmValue ) + 1;
-                                                               sprintf( (char*)addedString, "%s %s", authScheme, realmValue );
+                                                               snprintf( (char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue );
                                                                wspHeaderCopyDecodedString( addedString, &currentLength, &temper );
 
                                                                if (iField < fieldValueLen) {
@@ -2765,14 +2829,14 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                /* warning */
                                                case 0x2c :
                                                        {
-
                                                                unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
 
                                                                if (fieldValue[0] < 0x20 )
                                                                        iField = fieldValue[0];
                                                                else
                                                                        iField = 1;
-                                                               sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, iField ));
+
+                                                               snprintf( (char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, iField ));
                                                                strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
                                                                if (iField < fieldValueLen) {
                                                                        unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
@@ -2780,8 +2844,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                                        strncpy( (char*)agent, (char*)(fieldValue + iField ),WSP_STANDARD_STR_LEN_MAX-1);
                                                                        iField = iField + AcStrlen((char*)agent ) + 1;
                                                                        strncpy((char*)text, (char*)(fieldValue + iField ),WSP_STANDARD_STR_LEN_MAX-1);
-
-                                                                       sprintf( (char*)temp, " %s %s", agent, text );
+                                                                       snprintf( (char*)temp, sizeof(temp), " %s %s", agent, text );
                                                                        wspHeaderCopyDecodedString( temp, &currentLength, &temper );
                                                                }
                                                        }
@@ -2815,7 +2878,7 @@ void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, un
                                                        {
                                                                unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
 
-                                                               sprintf( (char*)temp, "%lX", wspHeaderDecodeInteger(fieldValue ));
+                                                               snprintf( (char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue ));
                                                                temp[2] = temp[1];
                                                                temp[1] = (unsigned char)0x30;
                                                                temp[3] = '\0';
@@ -3193,24 +3256,24 @@ void SmsPluginWapPushHandler::wspHeaderDecodeDateValue( unsigned long length, un
        {
                        /* UNIX asciitime function */
                case UNIX_DATE_TYPE :
-                       sprintf( (char*)decodedString, "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData->tm_wday], wspMonth[pTMData->tm_mon],
+                       snprintf( (char*)decodedString, sizeof(decodedString), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData->tm_wday], wspMonth[pTMData->tm_mon],
                                           pTMData->tm_mday, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec, pTMData->tm_year + 1900 );
                        break;
                case RFC1123_DATE_TYPE :
-                       sprintf( (char*)decodedString, "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData->tm_wday], pTMData->tm_mday,
+                       snprintf( (char*)decodedString, sizeof(decodedString), "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData->tm_wday], pTMData->tm_mday,
                                           wspMonth[pTMData->tm_mon], pTMData->tm_year + 1900, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec );
                        break;
                case RFC850_DATE_TYPE :
                        /* Have some Y2K Problems */
                        /* In RFC 850, date is represented like 11-May-99. So Y2K problem always can be occured. So remainer (year divided by 100) is used.                     */
-                       sprintf( (char*)decodedString, "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData->tm_wday], pTMData->tm_mday,
+                       snprintf( (char*)decodedString, sizeof(decodedString), "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData->tm_wday], pTMData->tm_mday,
                                           wspMonth[pTMData->tm_mon], pTMData->tm_year % CENTURY, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec );
 
                        break;
        }
 #endif
        /**UNIX_DATE_TYPE : */
-       sprintf( (char*)*pDecodedString, "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData->tm_wday], wspMonth[pTMData->tm_mon],
+       snprintf( (char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData->tm_wday], wspMonth[pTMData->tm_mon],
                                                                                        pTMData->tm_mday, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec, pTMData->tm_year + 1900 );
 
        return;
@@ -3248,6 +3311,7 @@ void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, u
        unsigned char  userId[WSP_STANDARD_STR_LEN_MAX];
        unsigned char  passWd[WSP_STANDARD_STR_LEN_MAX];
        unsigned long iField = 0;
+       char authStr[256];
 
        *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
 
@@ -3258,11 +3322,15 @@ void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, u
 
        /* skip 'basic' code */
        iField++;
-       sscanf((char*)(fieldValue + iField), "%s", userId );
+       memset(authStr, 0x00, sizeof(authStr));
+       snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
+       sscanf((char*)(fieldValue + iField), authStr, userId );
        iField = iField + AcStrlen( (char*)userId ) + 1;
-       sscanf( (char*)(fieldValue + iField), "%s", passWd );
+       memset(authStr, 0x00, sizeof(authStr));
+       snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(passWd));
+       sscanf( (char*)(fieldValue + iField), authStr, passWd );
        iField = iField + AcStrlen( (char*)userId ) + 1;
-       sprintf( (char*)*pDecodedString, "basic %s/%s", userId, passWd );
+       snprintf( (char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd );
 
        return;
 }
@@ -3272,6 +3340,7 @@ void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueL
 {
        unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
        unsigned long iField = 0;
+       char authStr[256];
 
        *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
 
@@ -3282,10 +3351,12 @@ void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueL
 
        /* skip 'basic' code */
        iField++;
-       sscanf( (char*)(fieldValue + iField), "%s", userId );
+       memset(authStr, 0x00, sizeof(authStr));
+       snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
+       sscanf( (char*)(fieldValue + iField), authStr, userId );
        iField = iField + AcStrlen( (char*)userId ) + 1;
 
-       sprintf( (char*)*pDecodedString, "basic realm=\"%s\"", userId );
+       snprintf( (char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId );
 
        return;
 }
@@ -3337,14 +3408,14 @@ void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldVa
                        case 0x03 :
                                /* min-fresh */
                        case 0x04 :
-                               sprintf( (char*)paramString, "%u", (unsigned int)wspHeaderDecodeInteger( fieldValue + 1));
+                               snprintf( (char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger( fieldValue + 1));
                                break;
 
                        default :
                                break;
 
                }
-               sprintf((char*)*pCacheString, "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString );
+               snprintf((char*)*pCacheString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString );
        } else {
                /* cache extentions */
                /* In case of come directive of doesn't specified string style */
@@ -3359,7 +3430,7 @@ void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldVa
                        if (fieldValue[stringLen+ 1] > 0x7f) {
                                int untyped = (int)wspHeaderDecodeIntegerByLength( fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1 ));
 
-                               sprintf( szString, "%d", untyped );
+                               snprintf( szString, sizeof(szString), "%d", untyped );
                                strncat( (char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1 );
                                strncat( (char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1 );
                        } else {
@@ -3373,3 +3444,10 @@ void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldVa
 
        return;
 }
+
+void SmsPluginWapPushHandler::getDisplayName(MSG_SUB_TYPE_T subType,char* displayName)
+{
+       if(subType == MSG_WAP_SL_SMS || subType == MSG_WAP_SI_SMS)
+               snprintf(displayName, MAX_ADDRESS_VAL_LEN + 1, "Push message");
+       return;
+}
index 7e3013f..1634292 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_CALLBACK_H
@@ -28,8 +28,10 @@ extern "C"
 {
        #include <tapi_common.h>
        #include <TelSms.h>
+       #include <TelSim.h>
        #include <TapiUtility.h>
        #include <ITapiNetText.h>
+       #include <ITapiNetwork.h>
 }
 
 /*==================================================================================================
@@ -38,6 +40,7 @@ extern "C"
 void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
 
 void TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_data);
+void TapiEventSatSmsSentStatus(TapiHandle *handle, int result, void *data, void *user_data);
 void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
 void TapiEventCbMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
 void TapiEventEtwsMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
@@ -51,6 +54,8 @@ void TapiEventDeleteSimMsg(TapiHandle *handle, int result, void *data, void *use
 
 void TapiEventSetConfigData(TapiHandle *handle, int result, void *data, void *user_data);
 
+void TapiEventSetSmscInfo(TapiHandle *handle, int result, void *data, void *user_data);
+
 void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user_data);
 
 void TapiEventSetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data);
@@ -61,6 +66,8 @@ void TapiEventGetMwiInfo(TapiHandle *handle, int result, void *data, void *user_
 
 void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *user_data);
 
+void TapiEventGetSimServiceTable(TapiHandle *handle, int result, void *data, void *user_data);
+
 void TapiEventGetParamCnt(TapiHandle *handle, int result, void *data, void *user_data);
 void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_data);
 
@@ -70,11 +77,19 @@ void TapiEventSatMoSmsCtrl(TapiHandle *handle, int result, void *data, void *use
 
 void TapiEventSimFileInfo(TapiHandle *handle, int result, void *data, void *user_data);
 void TapiEventSimReadFile(TapiHandle *handle, int result, void *data, void *user_data);
-
 void TapiEventMemoryStatus(TapiHandle *handle, int result, void *data, void *user_data);
 
 void TapiEventSetMsgStatus(TapiHandle *handle, int result, void *data, void *user_data);
 
+void TapiEventGetMeImei(TapiHandle *handle, int result, void *data, void *user_data);
+
+void TapiEventSimStatusChange(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
+
+void TapiEventNetworkStatusChange(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
+
+void TapiEventSimRefreshed(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
+
+SMS_NETWORK_STATUS_T convertTapiRespToSmsPlugin(int result);
 
 /*==================================================================================================
                                      CLASS DEFINITIONS
index 226e778..ae04ee5 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_CBMSG_HANDLER_H
@@ -40,7 +40,7 @@ extern "C"
 /*==================================================================================================
                                          VARIABLES
 ==================================================================================================*/
-typedef map<unsigned char, string> cbPageMap;
+typedef map<unsigned char, SMS_CBMSG_PAGE_S> cbPageMap;
 
 
 typedef struct _CB_PAGE_INFO_S
@@ -65,8 +65,8 @@ class SmsPluginCbMsgHandler
 public:
        static SmsPluginCbMsgHandler* instance();
 
-       void handleCbMsg(TelSmsCbMsg_t *pCbMsg);
-       void handleEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg);
+       void handleCbMsg(TapiHandle *handle, TelSmsCbMsg_t *pCbMsg);
+       void handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg);
 
 private:
        SmsPluginCbMsgHandler();
@@ -78,24 +78,24 @@ private:
        void Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage);
        void DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn);
        unsigned short encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields );
+       int CMAS_class(unsigned short message_id);
 
-       bool checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg);
+       bool checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex);
        unsigned char checkCbPage(SMS_CBMSG_PAGE_S CbPage);
        void MakeCbMsg(SMS_CBMSG_PAGE_S CbPage, SMS_CBMSG_S *pCbMsg);
-       void convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo);
-       void convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo);
+       void convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex);
+       void convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex);
        int convertTextToUtf8 (unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg);
-       void addToPageLiat(SMS_CBMSG_PAGE_S CbPage);
+       void addToPageList(SMS_CBMSG_PAGE_S CbPage);
        void removeFromPageList(SMS_CBMSG_PAGE_S CbPage);
 
        void decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs);
        void convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType);
        unsigned long getRecvTime();
-       void getDisplayName(unsigned short      MsgId, char *pDisplayName);
+       void getDisplayName(unsigned short      MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex);
 
        vector<CB_PAGE_INFO_S> pageList;
 
-       MsgTextConvert textCvt;
 };
 
 #endif //SMS_PLUGIN_CBMSG_HANDLER_H
index ef4e5aa..fa3552a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_CONCAT_HANDLER_H
@@ -54,6 +54,8 @@ typedef struct _SMS_CONCAT_MSG_S
        SMS_ADDRESS_S   originAddress;
        SMS_DCS_S               dcs;
        bool                            bRead;
+       int                             simId;
+       int                     simIndex;
 } SMS_CONCAT_MSG_S;
 
 typedef struct _SMS_CONCAT_INFO_S
@@ -69,6 +71,9 @@ typedef struct _SMS_CONCAT_INFO_S
 
        unsigned int            totalSize;
        concatDataMap   data;
+       int     simIdList[MAX_SIM_SMS_NUM];
+       unsigned int    display_time;
+       int                             simIndex;
 } SMS_CONCAT_INFO_S;
 
 typedef struct _SMS_SIM_ID_S
@@ -87,7 +92,8 @@ public:
        static SmsPluginConcatHandler* instance();
 
        bool IsConcatMsg(SMS_USERDATA_S *pUserData);
-       void handleConcatMsg(SMS_TPDU_S *pTpdu);
+       void handleConcatMsg(struct tapi_handle *handle, SMS_TPDU_S *pTpdu);
+       void handleSimConcatMsg(struct tapi_handle *handle, SMS_TPDU_S *pTpdu, int msgId, int bRead, int *simIdList);
 //     void handleConcatMsg(SMS_TPDU_S *pTpdu, msg_sim_id_t SimMsgId, bool bRead);
 
 //     void handleBrokenMsg();
@@ -99,12 +105,13 @@ private:
        static SmsPluginConcatHandler* pInstance;
 
        unsigned char checkConcatMsg(SMS_CONCAT_MSG_S *pConcatMsg, SMS_USERDATA_S *pUserData);
-       int makeConcatUserData(unsigned short MsgRef, char **ppTotalData);
+       int makeConcatUserData(unsigned short MsgRef, int simIndex, char **ppTotalData);
 
        void convertConcatToMsginfo(const SMS_DELIVER_S *pTpdu, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo);
+       void convertConcatToMsginfo(const SMS_SUBMIT_S *pTpdu, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo);
 //     void convertSimMsgToMsginfo(const SMS_CONCAT_MSG_S *pConcatMsg, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo);
 
-       void removeFromConcatList(unsigned short MsgRef);
+       void removeFromConcatList(unsigned short MsgRef, int simIndex);
 
 //     void addToSimIdList(unsigned short MsgRef, msg_sim_id_t SimMsgId);
 //     void removeFromSimIdList(unsigned short MsgRef);
@@ -112,7 +119,6 @@ private:
        vector<SMS_CONCAT_INFO_S> concatList;
 //     vector<SMS_SIM_ID_S> simIdList;
 
-       MsgTextConvert textCvt;
 };
 
 #endif //SMS_PLUGIN_CONCAT_HANDLER_H
diff --git a/plugin/sms_plugin/include/SmsPluginDSHandler.h b/plugin/sms_plugin/include/SmsPluginDSHandler.h
new file mode 100755 (executable)
index 0000000..508aff3
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#ifndef SMS_PLUGIN_DS_HANDLER_H
+#define SMS_PLUGIN_DS_HANDLER_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "SmsPluginTypes.h"
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginDSHandler
+{
+public:
+       static SmsPluginDSHandler* instance();
+       int initTelHandle();
+       void deinitTelHandle();
+       struct tapi_handle *getTelHandle(int sim_idx);
+       int getTelHandleCount();
+       int getActiveSimCount();
+       int getSimIndex(struct tapi_handle *handle);
+       void getDefaultNetworkSimId(int *simId);
+
+       bool checkSimChangeStatus(struct tapi_handle *handle);
+       bool checkSimIMSIStatus(struct tapi_handle *handle);
+
+private:
+       static SmsPluginDSHandler* pInstance;
+       SmsPluginDSHandler();
+       virtual ~SmsPluginDSHandler();
+       char **cp_list;
+       SMS_TELEPHONY_HANDLE_LIST_S handle_list;
+};
+
+#endif //SMS_PLUGIN_DS_HANDLER_H
+
index 43b603c..43f532e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_EVENT_HANDLER_H
@@ -37,23 +37,28 @@ public:
 
        void registerListener(MSG_PLUGIN_LISTENER_S *pListener);
        void handleSentStatus(msg_network_status_t NetStatus);
-       void handleMsgIncoming(SMS_TPDU_S *pTpdu);
-       void handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen);
+       void handleMsgIncoming(struct tapi_handle *handle, SMS_TPDU_S *pTpdu);
+       void handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen,int simIndex);
        void handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen);
        void handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *app_id, char *content_type);
+       void handleResendMessage(void);
 
        msg_error_t callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg);
+       msg_error_t callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo);
        msg_error_t callbackInitSimBySat();
        msg_error_t callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo);
+       msg_error_t handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize);
+       msg_error_t updateIMSI(int sim_idx);
 
        void SetSentInfo(SMS_SENT_INFO_S *pSentInfo);
 
-       void setDeviceStatus();
-       bool getDeviceStatus();
+       void setDeviceStatus(struct tapi_handle *handle);
+       bool getDeviceStatus(struct tapi_handle *handle);
 
        void convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo); // temp
 
+       MSG_SUB_TYPE_T convertMsgSubType(SMS_PID_T pid);
+
 private:
        SmsPluginEventHandler();
        virtual ~SmsPluginEventHandler();
@@ -61,7 +66,6 @@ private:
        void convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo);
        void convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo);
        void convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo);
-       MSG_SUB_TYPE_T convertMsgSubType(SMS_PID_T pid);
 
        static SmsPluginEventHandler* pInstance;
 
@@ -70,11 +74,12 @@ private:
        SMS_SENT_INFO_S sentInfo;
 
        bool devStatus;
+       bool bUdhMwiMethod;
+       int udhMwiCnt;
 
        Mutex mx;
        CndVar cv;
-
-       MsgTextConvert textCvt;
+       struct tapi_handle *devHandle;
 };
 
 #endif //SMS_PLUGIN_EVENT_HANDLER_H
index be884c3..f96b6c5 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_MAIN_H
@@ -40,32 +40,30 @@ msg_error_t SmsPlgFinalize();
 
 msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener);
 
-msg_error_t SmsPlgCheckSimStatus(MSG_SIM_STATUS_T *pStatus);
-
-msg_error_t SmsPlgCheckDeviceStatus();
-
 msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo);
 
-msg_error_t SmsPlgInitSimMessage();
-
 msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList);
 
-msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId);
+msg_error_t SmsPlgDeleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
 
 msg_error_t SmsPlgGetSimMessage(msg_sim_id_t SimMsgId);
 
 msg_error_t SmsPlgGetSimMessageCount();
 
-msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId);
-
-msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error);
+msg_error_t SmsPlgSetReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
 
-msg_error_t SmsPlgInitConfigData(MSG_SIM_STATUS_T SimStatus);
+msg_error_t SmsPlgSetMemoryStatus(msg_sim_slot_id_t simIndex, msg_error_t Error);
 
 msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting);
 
 msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting);
 
+msg_error_t SmsPlgAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo,  MSG_SENDINGOPT_INFO_S* pSendOptInfo, char* pFileData);
+
+msg_error_t SmsPlgGetDefaultNetworkSimId(int *simId);
+
+int MsgResourceMonitorInit(void);
+
 #ifdef __cplusplus
 }
 #endif
index 1e929a4..0795823 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_PARAMCODEC_H
@@ -44,6 +44,8 @@ public:
        static int decodeDCS(const unsigned char *pTpdu, SMS_DCS_S *pDCS);
        static void decodeSMSC(unsigned char* pAddress, int AddrLen, MSG_SMS_TON_T ton, char *pDecodeAddr);
 
+       static bool checkCphsVmiMsg(const unsigned char *pTpdu, int *setType, int *indType);
+
 private:
        static int convertDigitToBcd(char *pDigit, int DigitLen, unsigned char *pBcd);
        static int convertBcdToDigit(const unsigned char *pBcd, int BcdLen, char *pDigit);
index a00fd26..e6a640f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_SAT_HANDLER_H
                                          INCLUDE FILES
 ==================================================================================================*/
 #include "SmsPluginTypes.h"
+#include "MsgMutex.h"
+
+extern "C"
+{
+       #include <TelSat.h>
+}
 
 /*==================================================================================================
                                      CLASS DEFINITIONS
@@ -31,10 +37,10 @@ class SmsPluginSatHandler
 public:
        static SmsPluginSatHandler* instance();
 
-       void refreshSms(void *pData);
-       void sendSms(void *pData);
-       void ctrlSms(void *pData);
-       void ctrlSms(msg_network_status_t netStatus);
+       void refreshSms(struct tapi_handle *handle, void *pData);
+       void sendSms(struct tapi_handle *handle, void *pData);
+       void ctrlSms(struct tapi_handle *handle, void *pData);
+       void ctrlSms(struct tapi_handle *handle, SMS_NETWORK_STATUS_T netStatus);
 
        void finishSimMsgInit(msg_error_t Err);
 
@@ -49,16 +55,18 @@ private:
 
        int handleSatTpdu(unsigned char *pTpdu, unsigned char TpduLen, int bIsPackingRequired);
 
-       void sendResult(SMS_SAT_CMD_TYPE_T CmdType, int ResultType);
+       void sendResult(struct tapi_handle *handle, SMS_SAT_CMD_TYPE_T CmdType, int ResultType);
 
        static SmsPluginSatHandler* pInstance;
 
        int commandId;
 
-       bool bSendSms;
        bool bInitSim;
        bool bSMSPChanged;
        bool bCBMIChanged;
+
+       Mutex mx;
+       CndVar cv;
 };
 
 #endif //SMS_PLUGIN_SAT_HANDLER_H
index 82a8cec..38c1f1e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_SETTING_H
 ==================================================================================================*/
 #include "MsgMutex.h"
 #include "MsgSettingTypes.h"
+#include <list>
 
+extern "C"
+{
+       #include <tapi_common.h>
+}
 
 /*==================================================================================================
                                      CLASS DEFINITIONS
@@ -33,64 +38,88 @@ class SmsPluginSetting
 public:
        static SmsPluginSetting* instance();
 
-       void initConfigData(MSG_SIM_STATUS_T SimStatus);
-
        void setConfigData(const MSG_SETTING_S *pSetting);
        void getConfigData(MSG_SETTING_S *pSetting);
+       void getMeImei(char *pImei);
 
        void setParamCntEvent(int ParamCnt);
-       void setParamEvent(const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess);
-       void setCbConfigEvent(const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess);
-       void setMailboxInfoEvent(SMS_SIM_MAILBOX_LIST_S *pVoiceOpt, bool bSuccess);
-       void setMwiInfo(MSG_SUB_TYPE_T type, int count);
-       void setMwiInfoEvent(SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess);
+       void setParamEvent(struct tapi_handle *handle, const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess);
+       void setCbConfigEvent(struct tapi_handle *handle, const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess);
+       void setMailboxInfoEvent(struct tapi_handle *handle, SMS_SIM_MAILBOX_LIST_S *pVoiceOpt, bool bSuccess, bool bMbdn);
+       void setMwiInfo(int simIndex, MSG_SUB_TYPE_T type, int count);
+       void setMwiInfoEvent(struct tapi_handle *handle, SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess);
        void setResultFromSim(bool bResult);
+       void setResultImei(bool bResult, char *pImei);
+
+       void setSmscInfo(const MSG_SMSC_LIST_S *pSmscList);
+
+       void setSimChangeStatus(struct tapi_handle *handle, bool bInitializing);
+       void getSmscListInfo(int simIndex, MSG_SMSC_LIST_S *pSmscList);
+       void SimRefreshCb(struct tapi_handle *handle);
 
 private:
        SmsPluginSetting();
        ~SmsPluginSetting();
 
-       msg_error_t addSMSCList(MSG_SMSC_LIST_S *pSmscList);
+       void updateSimStatus(struct tapi_handle *handle);
+
+       void initConfigData(struct tapi_handle *handle);
+       static void* init_config_data(void *data);
+       static void* initSimInfo(void *data);
+       void* processInitSimInfo(void *data);
+
+       void addSMSCList(MSG_SMSC_LIST_S *pSmscList);
 
        msg_error_t addCbOpt(MSG_CBMSG_OPT_S *pCbOpt);
-       void getCbOpt(MSG_SETTING_S *pSetting);
+       void getCbOpt(MSG_SETTING_S *pSetting, int simIndex);
 
        void setParamList(const MSG_SMSC_LIST_S *pSMSCList);
        void getParamList(MSG_SMSC_LIST_S *pSMSCList);
 
-       int getParamCount();
-       bool getParam(int Index, MSG_SMSC_DATA_S *pSmscData);
+       int getParamCount(struct tapi_handle *handle);
+       bool getParam(struct tapi_handle *handle, int Index, MSG_SMSC_DATA_S *pSmscData);
 
        bool setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt);
        bool getCbConfig(MSG_CBMSG_OPT_S *pCbOpt);
 
        void setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt);
-       bool getVoiceMailInfo(MSG_VOICEMAIL_OPT_S *pVoiceOpt);
-       bool getMwiInfo(void);
-       bool getMsisdnInfo(void);
+       bool getVoiceMailInfo(struct tapi_handle *handle);
+
+       bool getMwiInfo(struct tapi_handle *handle);
+       bool getMsisdnInfo(struct tapi_handle *handle);
+       bool getSimServiceTable(struct tapi_handle *handle);
+       bool getResultImei(char *pImei);
 
        int getParamCntEvent();
-       bool getParamEvent(MSG_SMSC_DATA_S *pSmscData);
+       bool getParamEvent(struct tapi_handle *handle, MSG_SMSC_DATA_S *pSmscData);
        bool getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt);
 
-       bool getMailboxInfoEvent(MSG_VOICEMAIL_OPT_S *pVoiceOpt);
+       bool getMailboxInfoEvent();
 
        bool getResultFromSim();
 
        SMS_PID_T convertPid(MSG_SMS_PID_T pid);
+       void deliverVoiceMsgNoti(int simIndex, int mwiCnt);
 
        static SmsPluginSetting* pInstance;
-
-       MSG_SMSC_DATA_S         smscData;
-       MSG_CBMSG_OPT_S         cbOpt;
-
-       /* Message Waiting Indicator */
-       SMS_SIM_MAILBOX_LIST_S  simMailboxList;
-       SMS_SIM_MWI_INFO_S      simMwiInfo;
-
-       bool            bTapiResult;
+       std::list<TapiHandle *> tel_handle_list;
+
+       /* Setting values for keeping in setting instance */
+       MSG_SMSC_LIST_S         smscList[MAX_TELEPHONY_HANDLE_CNT+1];
+       MSG_SIM_STATUS_T        simStatus[MAX_TELEPHONY_HANDLE_CNT+1];
+       MSG_SMSC_DATA_S         smscData[MAX_TELEPHONY_HANDLE_CNT+1];
+       SMS_SIM_MAILBOX_LIST_S  simMailboxList[MAX_TELEPHONY_HANDLE_CNT+1];
+       SMS_SIM_MWI_INFO_S      simMwiInfo[MAX_TELEPHONY_HANDLE_CNT+1];
+       MSG_CBMSG_OPT_S cbOpt[MAX_TELEPHONY_HANDLE_CNT+1];
+
+       /* Local values for getting from SIM(TAPI) */
+       bool    bTapiResult;
        int             paramCnt;
        int             selectedParam;
+       int     selectedSimIndex;
+       char    meImei[MAX_ME_IMEI_LEN + 1];
+
+       bool    bMbdnEnable;
 
        Mutex mx;
        CndVar cv;
index 2161c45..73b1a3d 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_SIMMSG_H
@@ -43,19 +43,21 @@ class SmsPluginSimMsg
 public:
        static SmsPluginSimMsg* instance();
 
-       void initSimMessage();
+       void initSimMessage(struct tapi_handle *handle);
        msg_error_t saveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList);
        msg_error_t saveClass2Message(const MSG_MESSAGE_INFO_S *pMsgInfo);
-       void deleteSimMessage(msg_sim_id_t SimMsgId);
+       void deleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
        void getSimMessageList(MSG_SIM_MSG_INFO_LIST_S **ppSimMsgList);
-       void setReadStatus(msg_sim_id_t SimMsgId);
-       bool checkSimMsgFull(unsigned int SegCnt);
+       void setReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId);
+       bool checkSimMsgFull(msg_sim_slot_id_t sim_idx, unsigned int SegCnt);
 
-       void setSimMsgCntEvent(const MSG_SIM_COUNT_S *pSimMsgCnt);
-       void setSimMsgEvent(const MSG_MESSAGE_INFO_S *pMsgInfo, bool bSuccess);
-       void setSaveSimMsgEvent(int simMsgId, int result);
-       void setSaveClass2MsgEvent(int simMsgId, int result);
+       void setSimMsgCntEvent(struct tapi_handle *handle, const MSG_SIM_COUNT_S *pSimMsgCnt);
+       void setSimMsgEvent(struct tapi_handle *handle, const MSG_MESSAGE_INFO_S *pMsgInfo, bool bSuccess);
+       void setSaveSimMsgEvent(struct tapi_handle *handle, int simId, int result);
+       void setSaveClass2MsgEvent(struct tapi_handle *handle, int simId, int result, MSG_MESSAGE_INFO_S *data);
        void setSimEvent(msg_sim_id_t SimId, bool bResult);
+       void setUpdateSimEvent(int SimId, bool bResult);
+       void setDelSimEvent(int SimId, bool bResult);
 
        void setSmsData(const char *sca, const char *szData, int msgLength);
 
@@ -63,26 +65,31 @@ private:
        SmsPluginSimMsg();
        ~SmsPluginSimMsg();
 
-       void getSimMsgCount(MSG_SIM_COUNT_S *pSimMsgCnt);
-       bool getSimMsg(msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S* pMsgInfo);
+       void getSimMsgCount(struct tapi_handle *handle, MSG_SIM_COUNT_S *pSimMsgCnt);
+       bool getSimMsg(struct tapi_handle *handle, msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S* pMsgInfo, int *simIdList);
 
        void setSmsOptions(SMS_DELIVER_S *pDeliver);
        void convertTimeStamp(const MSG_MESSAGE_INFO_S* pMsgInfo, SMS_DELIVER_S *pDeliver);
 
-       bool getSimMsgCntEvent(MSG_SIM_COUNT_S *pSimMsgCnt);
-       bool getSimMsgEvent(MSG_MESSAGE_INFO_S *pMsgInfo);
+       bool getSimMsgCntEvent(struct tapi_handle *handle, MSG_SIM_COUNT_S *pSimMsgCnt);
+       bool getSimMsgEvent(struct tapi_handle *handle, MSG_MESSAGE_INFO_S *pMsgInfo);
        bool getSimEvent(msg_sim_id_t *pSimId);
+       bool getUpdateSimEvent();
+       bool getDelSimEvent(int *pSimId);
+
 
        static SmsPluginSimMsg* pInstance;
 
        msg_sim_id_t                            simMsgId;
+       int                             delSimMsgId;
 
        MSG_SIM_COUNT_S                 simMsgCnt;
 
        MSG_MESSAGE_INFO_S              simMsgInfo;
+       MSG_ADDRESS_INFO_S              simAddrInfo;
 
-       unsigned int                            usedCnt;
-       unsigned int                            totalCnt;
+       int                                     usedCnt;
+       int                                     totalCnt;
 
        bool                                            bTapiResult;
 
index 44d830f..0506e8f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_STORAGE_H
@@ -45,38 +45,44 @@ class SmsPluginStorage
 public:
        static SmsPluginStorage* instance();
 
+       msg_error_t insertMsgRef(MSG_MESSAGE_INFO_S *pMsg, unsigned char msgRef, int index);
+       msg_error_t updateMsgDeliverStatus(MSG_MESSAGE_INFO_S *pMsgInfo, unsigned char msgRef);
+
        msg_error_t updateSentMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_network_status_t Status);
+//     msg_error_t updateMsgRef(msg_message_id_t MsgId, unsigned char MsgRef);
+//     msg_error_t updateStatusReport(unsigned char MsgRef, msg_delivery_report_status_t Status, time_t DeliveryTime);
 
-       msg_error_t addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo);
+       msg_error_t addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo, int *simIdList);
+       msg_error_t insertSimMessage(int simId, int msgId);
+       msg_error_t deleteSimMessage(int sim_idx, int simId);
 
-       msg_error_t addMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
+       msg_error_t checkMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
        msg_error_t addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
-
+       msg_error_t deleteSmsMessage(msg_message_id_t msgId);
+#if 0
+       msg_error_t isReceivedCBMessage(SMS_CBMSG_PAGE_S CbPage);
+       msg_error_t insertReceivedCBMessage(SMS_CBMSG_PAGE_S CbPage);
+#endif
        msg_error_t addSmsSendOption(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo);
 
-       msg_error_t deleteSmsMessage(msg_message_id_t MsgId);
+       msg_error_t getReplaceSimMsg(const MSG_MESSAGE_INFO_S *pMsg, int *pMsgId, int *pSimId);
 
-       msg_error_t getRegisteredPushEvent(char* pPushHeader, int *count, char *app_id, char *content_type);
+       msg_error_t checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo);
+       msg_error_t getRegisteredPushEvent(char* pPushHeader, int *count, char *app_id, int app_id_len, char *content_type, int content_type_len);
        msg_error_t getnthPushEvent(int index, int *appcode);
        msg_error_t releasePushEvent();
 private:
        SmsPluginStorage();
        ~SmsPluginStorage();
 
-       msg_error_t updateSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
-
-       msg_error_t addCbMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t addReplaceTypeMsg(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t addWAPMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t handleCOWAPMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t checkPushMsgValidation(MSG_PUSH_MESSAGE_S *pPushMsg, bool *pbProceed);
-
-       msg_error_t checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo);
-       msg_error_t updateAllAddress();
+       msg_error_t addClass2Message(MSG_MESSAGE_INFO_S *pMsgInfo);
 
        static SmsPluginStorage* pInstance;
+       static void* class2_thread(void *data);
+
+       MSG_MESSAGE_INFO_S msgInfo;
+       MSG_ADDRESS_INFO_S addrInfo;
 
-       MsgDbHandler dbHandle;
        std::list<PUSH_APPLICATION_INFO_S> pushAppInfoList;
 //     unsigned char tmpMsgRef;
 };
index 051f935..597a91d 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_TPDU_CODEC_H
index a43dfb8..124bcef 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_TRANSPORT_H
 #include "SmsPluginTypes.h"
 #include "MsgInternalTypes.h"
 
+extern "C"
+{
+       #include <TelSat.h>
+}
+
 /*==================================================================================================
                                      CLASS DEFINITIONS
 ==================================================================================================*/
@@ -37,17 +42,19 @@ public:
        static SmsPluginTransport* instance();
 
        void submitRequest(SMS_REQUEST_INFO_S *pReqInfo);
-       void sendDeliverReport(msg_error_t err);
-       void sendClass0DeliverReport(msg_error_t err);
+       void sendDeliverReport(struct tapi_handle *handle, msg_error_t err);
+       void sendClass0DeliverReport(struct tapi_handle *handle, msg_error_t err);
 
-       void setSmsSendOptions(SMS_SUBMIT_S *pSubmit);
-       void setSmscOptions(SMS_ADDRESS_S *pSmsc);
+       void setSmscOptions(int simIndex, SMS_ADDRESS_S *pSmsc);
 
        void msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SUBMIT_DATA_S *pData, SMS_CODING_SCHEME_T *pCharType, int addrIndex);
        void setConcatHeader(SMS_UDH_S *pSrcHeader, SMS_UDH_S *pDstHeader);
 
-       void setNetStatus(msg_network_status_t netStatus);
-       msg_network_status_t getNetStatus();
+       void setNetStatus(SMS_NETWORK_STATUS_T sentStatus);
+       SMS_NETWORK_STATUS_T getNetStatus();
+
+       void setMoCtrlStatus(TelSatMoSmCtrlIndData_t *moCtrlData);
+       int getMoCtrlStatus();
 
        unsigned char getMsgRef();
 
@@ -55,6 +62,11 @@ private:
        SmsPluginTransport();
        ~SmsPluginTransport();
 
+       void getSmsSendOption(SMS_SUBMIT_S *pSubmit);
+       void setSmsSendOption(SMS_REQUEST_INFO_S *pReqInfo, SMS_TPDU_S* pSmsTpdu);
+       void setSmsDcsOption(SMS_REQUEST_INFO_S *pReqInfo, SMS_TPDU_S* pSmsTpdu);
+       void setSmsReportOption(SMS_REQUEST_INFO_S *pReqInfo, SMS_TPDU_S* pSmsTpdu);
+
        int getSegmentSize(SMS_CODING_SCHEME_T CodingScheme, int DataLen, bool bPortNum, MSG_LANGUAGE_ID_T LangId, int ReplyAddrLen);
        SMS_PID_T convertPid(MSG_SMS_PID_T pid);
 
@@ -65,12 +77,11 @@ private:
        unsigned char           msgRef8bit;
        unsigned short  msgRef16bit;
 
-       msg_network_status_t curStatus;
+       SMS_NETWORK_STATUS_T curStatus;
+       TelSatMoSmCtrlIndData_t curMoCtrlData;
 
        Mutex mx;
        CndVar cv;
-
-       MsgTextConvert textCvt;
 };
 
 #endif //SMS_PLUGIN_TRANSPORT_H
index 34370cd..01fdfbc 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_TYPES_H
 #define MAX_USER_DATA_LEN                      160
 #define MAX_GSM_7BIT_DATA_LEN          160
 #define MAX_UCS2_DATA_LEN                      140
-#define MAX_TPDU_DATA_LEN                      165
+//#define MAX_TPDU_DATA_LEN                    165
+//CID 321400: Making MAX_TPDU_DATA_LEN same as TAPI_NETTEXT_SMDATA_SIZE_MAX of TelSms.h to prevent any buffer overflow
+#define MAX_TPDU_DATA_LEN                      255
+#define MAX_SMS_SEND_RETRY                     4
 #define MAX_SMSC_LEN                           20
 #define MAX_ADD_PARAM_LEN                      12
 #define MAX_ABS_TIME_PARAM_LEN         7
 #define MAX_REL_TIME_PARAM_LEN         1
 #define MAX_UD_HEADER_NUM                      7
 #define MAX_SAT_TPDU_LEN                       175
-#define MAX_CBMSG_PAGE_SIZE            93
+#define MAX_CBMSG_PAGE_SIZE            1252
 #define MAX_ETWS_SIZE                  56
 #define MAX_CBMSG_PAGE_NUM             15
 #define MAX_SIM_SMS_NUM                        255
-#define MAX_SIM_XDN_ALPHA_ID_LEN       30
+#define MAX_SIM_IMSI_NUM               20
 #define MAX_SIM_MSP_CNT                        2
+#define MAX_TELEPHONY_HANDLE_CNT       3
 
 #define SMS_PUSH_XML_HREF_TAG          "href"
 #define SMS_PUSH_XML_SI_ID_TAG         "si-id"
                                          TYPES
 ==================================================================================================*/
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_TPDU_TYPE_T;
+typedef unsigned char SMS_TPDU_TYPE_T;         /* _SMS_TPDU_TYPE_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_VPF_T;
+typedef unsigned char SMS_VPF_T;               /* _SMS_VPF_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_TON_T;
+typedef unsigned char SMS_TON_T;               /* _SMS_TON_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_NPI_T;
+typedef unsigned char SMS_NPI_T;               /* _SMS_NPI_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_PID_T;
-
-
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_MSG_CLASS_T;
+typedef unsigned char SMS_PID_T;               /* _SMS_PID_E */
 
+typedef unsigned char SMS_MSG_CLASS_T;         /* _SMS_MSG_CLASS_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_CODING_SCHEME_T;
+typedef unsigned char SMS_CODING_SCHEME_T;     /* _SMS_CODING_SCHEME_E */
 
+typedef unsigned char SMS_CODING_GROUP_T;      /* _SMS_CODING_GROUP_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_CODING_GROUP_T;
+typedef unsigned char SMS_INDICATOR_TYPE_T;    /* _SMS_INDICATOR_TYPE_E */
 
+typedef unsigned char SMS_TIME_FORMAT_T;       /* _SMS_TIME_FORMAT_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_INDICATOR_TYPE_T;
+typedef unsigned char SMS_FAIL_CAUSE_T;                /* _SMS_FAIL_CAUSE_E */
 
+typedef unsigned char SMS_STATUS_T;            /* _SMS_STATUS_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_TIME_FORMAT_T;
+typedef unsigned char SMS_REF_NUMBER_T;                /* _SMS_REF_NUMBER_E */
 
+typedef unsigned char SMS_REPORT_TYPE_T;       /* _SMS_REPORT_TYPE_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_FAIL_CAUSE_T;
+typedef unsigned char SMS_UDH_TYPE_T;          /* _SMS_UDH_TYPE_E */
 
+typedef unsigned char SMS_WAP_APP_CODE_T;      /* _SMS_WAP_APP_CODE_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_STATUS_T;
+typedef unsigned char SMS_CB_NETWORK_TYPE_T;   /* _SMS_CB_NETWORK_TYPE_E */
 
+typedef unsigned char SMS_CBMSG_TYPE_T;                /* _SMS_CBMSG_TYPE_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_REF_NUMBER_T;
+typedef unsigned char SMS_CBMSG_LANG_TYPE_T;   /* _SMS_CBMSG_LANG_TYPE_E */
 
+typedef unsigned char SMS_CBMSG_CODING_GROUP_T;        /* _SMS_CBMSG_CODING_GROUP_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_REPORT_TYPE_T;
+typedef unsigned char SMS_SAT_CMD_TYPE_T;      /* _SMS_SAT_CMD_TYPE_E */
 
+typedef unsigned short SMS_SIM_EFILE_NAME_T;   /* _SMS_SIM_EFILE_NAME_E */
 
-/**
-\brief Represents TPDU Type.
-*/
-typedef unsigned char SMS_UDH_TYPE_T;
+typedef unsigned char SMS_SIM_MAILBOX_TYPE_T;  /* _SMS_SIM_MAILBOX_TYPE_E */
 
-
-/**
-\brief Represents WAP Push App Code.
-*/
-typedef unsigned char SMS_WAP_APP_CODE_T;
-
-
-typedef unsigned char SMS_CB_NETWORK_TYPE_T;
-
-
-typedef unsigned char SMS_CBMSG_TYPE_T;
-
-
-typedef unsigned char SMS_CBMSG_LANG_TYPE_T;
-
-
-typedef unsigned char SMS_CBMSG_CODING_GROUP_T;
-
-
-typedef unsigned char SMS_SAT_CMD_TYPE_T;
-
-
-typedef unsigned short SMS_SIM_EFILE_NAME_T;
-
-
-typedef unsigned char SMS_ETWS_NETWORK_TYPE_T;
-
-/**
-\brief Represents SIM mailbox type. See enum _SMS_SIM_MAILBOX_TYPE_E
-*/
-typedef unsigned char SMS_SIM_MAILBOX_TYPE_T;
+typedef unsigned char SMS_NETWORK_STATUS_T;    /* _SMS_NETWORK_STATUS_E */
 
 /*==================================================================================================
                                     ENUMS
@@ -294,6 +229,7 @@ enum _SMS_CODING_GROUP_E
 enum _SMS_INDICATOR_TYPE_E
 {
        SMS_VOICE_INDICATOR = 0,
+       SMS_VOICE2_INDICATOR, // Only for CPSH
        SMS_FAX_INDICATOR,
        SMS_EMAIL_INDICATOR,
        SMS_OTHER_INDICATOR,
@@ -337,6 +273,7 @@ enum _SMS_STATUS_E
        SMS_STATUS_TRY_NO_RESPONSE = 0x22,
        SMS_STATUS_TRY_SERVICE_REJECTED = 0x23,
        SMS_STATUS_TRY_QOS_NOT_AVAILABLE = 0x24,
+       SMS_STATUS_TRY_REQUEST_PENDING = 0x30,
 
        SMS_STATUS_PERM_REMOTE_ERROR = 0x40,
        SMS_STATUS_PERM_IMCOMPATIBLE_DEST = 0x41,
@@ -383,6 +320,8 @@ enum _SMS_UDH_TYPE_E
        SMS_UDH_SRC_IND = 0x07,
        SMS_UDH_CONCAT_16BIT = 0x08,
        SMS_UDH_WCMP = 0x09,
+       SMS_UDH_EMS_FIRST = 0x0a,
+       SMS_UDH_EMS_LAST = 0x1f,
        SMS_UDH_ALTERNATE_REPLY_ADDRESS = 0x22,
        SMS_UDH_SINGLE_SHIFT = 0x24,
        SMS_UDH_LOCKING_SHIFT = 0x25,
@@ -548,12 +487,26 @@ enum _SMS_SIM_EFILE_NAME_E
 
 
 enum _SMS_SIM_MAILBOX_TYPE_E {
-       MSG_SIM_MAILBOX_VOICE = 0x01,
-       MSG_SIM_MAILBOX_VOICE2 = 0x02,
-       MSG_SIM_MAILBOX_FAX = 0x03,
-       MSG_SIM_MAILBOX_DATA = 0x04,
-       MSG_SIM_MAILBOX_EMAIL = 0x05,
-       MSG_SIM_MAILBOX_OTHER = 0x06,
+       SMS_SIM_MAILBOX_VOICE = 0x01,
+       SMS_SIM_MAILBOX_VOICE2 = 0x02,
+       SMS_SIM_MAILBOX_FAX = 0x03,
+       SMS_SIM_MAILBOX_DATA = 0x04,
+       SMS_SIM_MAILBOX_EMAIL = 0x05,
+       SMS_SIM_MAILBOX_OTHER = 0x06,
+};
+
+
+enum _SMS_NETWORK_STATUS_E {
+       SMS_NETWORK_SEND_SUCCESS = 0x00,
+       SMS_NETWORK_SENDING,
+       SMS_NETWORK_SEND_FAIL,
+       SMS_NETWORK_SEND_FAIL_TIMEOUT,
+       SMS_NETWORK_SEND_FAIL_MANDATORY_INFO_MISSING,
+       SMS_NETWORK_SEND_FAIL_TEMPORARY,
+       SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD,
+       SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED,
+       SMS_NETWORK_SEND_FAIL_FDN_RESTRICED,
+       SMS_NETWORK_SEND_PENDING,
 };
 
 
@@ -825,7 +778,7 @@ typedef struct _SMS_CBMSG_PAGE_S
        SMS_CBMSG_TYPE_T                        cbMsgType;                                                      /*CBS Msg or SCHEDULE Msg or CBS41 Msg */
        SMS_CBMSG_HEADER_S                      pageHeader;                                                     /**< CB Message Header */
        int                                                     pageLength;                                                     /**< message string length */
-       char                                                    pageData[MAX_CBMSG_PAGE_SIZE+1];                /**< user data */
+       char                                                    pageData[MAX_CBMSG_PAGE_SIZE*8/7+1];            /**< user data */
 } SMS_CBMSG_PAGE_S;
 
 
@@ -837,7 +790,7 @@ typedef struct _SMS_CBMSG_S
        SMS_CODING_SCHEME_T             codingScheme;                                           /**< How to encode a message. */
        time_t                                          recvTime;                                                       /**< Msg Recv Time */
        int                                                     msgLength;                                                      /**< message string length */
-       char                                                    msgData[MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM+1];              /**< user data */
+       char                                                    msgData[MAX_CBMSG_PAGE_SIZE*8/7*MAX_CBMSG_PAGE_NUM+1];          /**< user data */
 } SMS_CBMSG_S;
 
 typedef struct _SMS_ETWS_PRIMARY_S
@@ -992,6 +945,15 @@ typedef struct {
 } SMS_SIM_MWI_INFO_S;
 
 /**
+ *     @brief  Represents SIM MSISDN Information
+ */
+typedef struct {
+       char    simMsisdn[MAX_SIM_MSISDN_LEN + 1];
+       int     sim_index;
+} SMS_SIM_MSISDN_INFO_S;
+
+
+/**
  *     @brief  Represents Message Data Information from Telephony.
  */
 typedef struct {
@@ -1000,5 +962,13 @@ typedef struct {
        unsigned char szData[MAX_TPDU_DATA_LEN + 1]; /**< SMS TPDU message */
 } SMS_DATA_INFO_S;
 
-#endif //SMS_PLUGIN_TYPES_H
 
+/**
+ *     @brief  Represents Telephony Handle from Telephony.
+ */
+typedef struct {
+       int count;
+       struct tapi_handle *handle[MAX_TELEPHONY_HANDLE_CNT]; //max is 3
+} SMS_TELEPHONY_HANDLE_LIST_S;
+
+#endif //SMS_PLUGIN_TYPES_H
index 48b6eed..a23e2d2 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_UA_MANAGER_H
@@ -42,6 +42,10 @@ public:
 private:
        SmsPluginUAManager();
        ~SmsPluginUAManager();
+       void lock()     { mx.lock(); };
+       void unlock()   { mx.unlock(); };
+       void wait()     { cv.wait(mx.pMutex()); };
+       void signal()   { cv.signal(); };
 
        virtual void run();
 
@@ -49,7 +53,7 @@ private:
 
        bool bRunning;
 
-       MsgThdSafeQ <SMS_REQUEST_INFO_S> smsTranQ;
+       MsgSimpleQ <SMS_REQUEST_INFO_S> smsTranQ;
 
        Mutex mx;
        CndVar cv;
index 39903e3..c109210 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_UDCODEC_H
index ae234ca..f47b46e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef SMS_PLUGIN_WAPPUSH_HANDLER_H
@@ -38,7 +38,6 @@
 #define WSP_CODE_BUFFER_LEFT_LEN_MAX   1024
 #define WSP_CODE_BUFFER_RIGHT_LEN_MAX  2048
 
-#define  MemFree(x)  {if(x != NULL) free(x);x=NULL;}
 #define  AcStrlen(x) ((x==NULL)?0:strlen(x))
 #define MIN(a,b)  (((a)  <  (b)) ? (a)  :  (b))
 
@@ -55,8 +54,8 @@ public:
        bool IsWapPushMsg(SMS_USERDATA_S *pUserData);
 
        void copyDeliverData(SMS_DELIVER_S *pDeliver);
-       void handleWapPushMsg(const char *pUserData, int DataSize);
-       void handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen);
+       void handleWapPushMsg(const char *pUserData, int DataSize, int simIndex);
+       void handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen, int simIndex);
 
 private:
        SmsPluginWapPushHandler();
@@ -66,13 +65,14 @@ private:
 
        SMS_WAP_APP_CODE_T getAppCode(const char *pPushHeader);
 
-       void handleMMSNotification(const char *pPushBody, int PushBodyLen);
-       void handleSIMessage(char* pPushBody, int PushBodyLen, bool isText);
-       void handleSLMessage(char* pPushBody, int PushBodyLen, bool isText);
-       void handleCOMessage(char* pPushBody, int PushBodyLen, bool isText);
+       void handleMMSNotification(const char *pPushBody, int PushBodyLen, int simIndex);
+       void handleSIMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex);
+       void handleSLMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex);
+       void handleCOMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex);
        void handleDrmVer1(char* pPushBody, int PushBodyLen);
        void getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText);
        void createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo);
+       void getDisplayName(MSG_SUB_TYPE_T subType, char* displayName);
        unsigned long convertXmlCharToSec(char* pDate);
        msg_push_action_t convertSIActionStrToEnum(char* pAction);
        msg_push_action_t convertSLActionStrToEnum(char* pAction);
index 0c3d397..5b864b2 100755 (executable)
@@ -26,13 +26,12 @@ SET(TRANS-PROXY-SRCS
 INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/include/mapi
        ${CMAKE_SOURCE_DIR}/include/common
-       ${CMAKE_SOURCE_DIR}/include/framework
        ${CMAKE_SOURCE_DIR}/include/utils
        ${CMAKE_SOURCE_DIR}/include/proxy
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(trans_proxy_pkgs REQUIRED glib-2.0 dlog vconf security-server)
+pkg_check_modules(trans_proxy_pkgs REQUIRED glib-2.0 dlog vconf security-server db-util)
 
 FOREACH(flag ${trans_proxy_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -45,7 +44,7 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_LIBRARY(${TRANS-PROXY-LIB} SHARED ${TRANS-PROXY-SRCS})
-TARGET_LINK_LIBRARIES(${TRANS-PROXY-LIB} ${trans_proxy_pkgs_LDFLAGS} ${UTILS-LIB} ${FW-HANDLER-LIB})
+TARGET_LINK_LIBRARIES(${TRANS-PROXY-LIB} ${trans_proxy_pkgs_LDFLAGS} ${UTILS-LIB})
 
-INSTALL(TARGETS ${TRANS-PROXY-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${TRANS-PROXY-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 
index 4edba0b..c89e0e9 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
 #include "MsgDebug.h"
 #include "MsgCppTypes.h"
 #include "MsgException.h"
+#include "MsgContact.h"
 #include "MsgUtilFile.h"
 #include "MsgGconfWrapper.h"
 #include "MsgProxyListener.h"
 #include "MsgHandle.h"
+#include "MsgSqliteWrapper.h"
 
 /*==================================================================================================
                                      IMPLEMENTATION OF MsgHandle - Control Member Functions
@@ -74,6 +76,7 @@ void MsgHandle::openHandle()
 
        // Open Socket IPC
        connectSocket();
+//     getDbHandle(); /* register db handler */
 }
 
 
@@ -90,6 +93,12 @@ void MsgHandle::closeHandle(MsgHandle* pHandle)
        // Close Socket IPC
        disconnectSocket();
 
+       // Close Contact Service
+       if (MsgCloseContactSvc() != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to close contact service.");
+       }
+       removeDbHandle(); /* unregister db handler */
+
        MSG_END();
 }
 
@@ -119,13 +128,25 @@ void MsgHandle::write(const char *pCmdData, int cmdSize, char **ppEvent)
        if (ret < 0)
                THROW(MsgException::IPC_ERROR, "IPC write error");
 
-       // Receive Result from MSG FW
-       read(ppEvent);
+       char *tmpEvent = NULL;
 
-       if (*ppEvent == NULL) {
-               THROW(MsgException::INVALID_RESULT, "event is NULL");
-       }
+       while(1)
+       {
+               // Receive Result from MSG FW
+               read(&tmpEvent);
 
+               if(tmpEvent == NULL) {
+                       MSG_DEBUG("Event Data is NULL!!");
+                       break;
+               }
+
+               if(!CheckEventData(tmpEvent)) {
+                       delete [] tmpEvent;
+               } else {
+                       *ppEvent = tmpEvent;
+                       break;
+               }
+       }
 }
 
 
@@ -153,17 +174,16 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_I
        pDest->msgType.classType= pSrc->classType;
        pDest->storageId = pSrc->storageId;
 
-       msg_struct_list_s *addr_info_s = pSrc->addr_list;
-
-       if (addr_info_s) {
+       if (g_list_length(pSrc->addressList) > 0) {
                msg_struct_s *addr_info = NULL;
                MSG_ADDRESS_INFO_S *address = NULL;
 
-               pDest->nAddressCnt = addr_info_s->nCount;
+               pDest->nAddressCnt = g_list_length(pSrc->addressList);
+               pDest->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pDest->nAddressCnt];
+               memset(pDest->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pDest->nAddressCnt);
 
-               for (int i = 0; i < addr_info_s->nCount; i++)
-               {
-                       addr_info = (msg_struct_s *)addr_info_s->msg_struct_info[i];
+               for (int i = 0; i < pDest->nAddressCnt; i++) {
+                       addr_info = (msg_struct_s *)g_list_nth_data(pSrc->addressList,(guint)i);
                        address = (MSG_ADDRESS_INFO_S *)addr_info->data;
 
                        pDest->addressList[i].addressType = address->addressType;
@@ -171,7 +191,31 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_I
                        pDest->addressList[i].contactId = address->contactId;
                        strncpy(pDest->addressList[i].addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
                        strncpy(pDest->addressList[i].displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
-                       pDest->addressList[i].displayName[MAX_DISPLAY_NAME_LEN] = '\0';
+               }
+       } else {
+
+               msg_struct_list_s *addr_info_s = pSrc->addr_list;
+
+               if (addr_info_s && (addr_info_s->nCount > 0)) {
+                       msg_struct_s *addr_info = NULL;
+                       MSG_ADDRESS_INFO_S *address = NULL;
+
+                       pDest->nAddressCnt = addr_info_s->nCount;
+
+                       pDest->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * addr_info_s->nCount];
+                       memset(pDest->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * addr_info_s->nCount);
+
+                       for (int i = 0; i < addr_info_s->nCount; i++) {
+                               addr_info = (msg_struct_s *)addr_info_s->msg_struct_info[i];
+
+                               address = (MSG_ADDRESS_INFO_S *)addr_info->data;
+
+                               pDest->addressList[i].addressType = address->addressType;
+                               pDest->addressList[i].recipientType = address->recipientType;
+                               pDest->addressList[i].contactId = address->contactId;
+                               strncpy(pDest->addressList[i].addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
+                               strncpy(pDest->addressList[i].displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
        }
 
@@ -198,38 +242,45 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_I
        MSG_DEBUG("nSize = %d",  pSrc->dataSize);
 
        if (pSrc->mainType == MSG_SMS_TYPE){
-               pDest->bTextSms = true;
-               pDest->dataSize = pSrc->dataSize;
+               if (pSrc->pData != NULL) {
+                       pDest->bTextSms = true;
+                       pDest->dataSize = pSrc->dataSize;
 
-               memset(pDest->msgText, 0x00, sizeof(pDest->msgText));
+                       memset(pDest->msgText, 0x00, sizeof(pDest->msgText));
 
-               if (pSrc->dataSize > MAX_MSG_TEXT_LEN) {
-                       // Save Message Data into File
-                       char fileName[MSG_FILENAME_LEN_MAX+1];
-                       memset(fileName, 0x00, sizeof(fileName));
+                       if (pSrc->dataSize > MAX_MSG_TEXT_LEN) {
+                               // Save Message Data into File
+                               char fileName[MSG_FILENAME_LEN_MAX+1];
+                               memset(fileName, 0x00, sizeof(fileName));
 
-                       if(MsgCreateFileName(fileName) == false)
-                               THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
+                               if(MsgCreateFileName(fileName) == false)
+                                       THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
 
-                       MSG_DEBUG("Save pSrc->pData into file : size[%d] name[%s]", pDest->dataSize, fileName);
+                               MSG_SEC_DEBUG("Save pSrc->pData into file : size[%d] name[%s]", pDest->dataSize, fileName);
 
-                       if (MsgWriteIpcFile(fileName, (char*)pSrc->pData, pSrc->dataSize) == false)
-                               THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
+                               if (MsgWriteIpcFile(fileName, (char*)pSrc->pData, pSrc->dataSize) == false)
+                                       THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
 
-                       memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
-                       strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
+                               memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
+                               strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
+
+                               pDest->bTextSms = false;
 
-                       pDest->bTextSms = false;
+                       } else {
+                               if (pDest->encodeType == MSG_ENCODE_8BIT)
+                                       memcpy(pDest->msgText, pSrc->pData, pSrc->dataSize);
+                               else
+                                       strncpy(pDest->msgText, (char*)pSrc->pData, pSrc->dataSize);
+                       }
 
+                       MSG_DEBUG("pData = %s", pSrc->pData);
                } else {
-                       if (pDest->encodeType == MSG_ENCODE_8BIT)
-                               memcpy(pDest->msgText, pSrc->pData, pSrc->dataSize);
-                       else
-                               strncpy(pDest->msgText, (char*)pSrc->pData, pSrc->dataSize);
+                       MSG_DEBUG("pSrc->pData is NULL.");
+                       pDest->bTextSms = true;
+                       pDest->dataSize = 0;
                }
 
-               MSG_DEBUG("pData = %s",  pSrc->pData);
-               MSG_DEBUG("msgText = %s",  pDest->msgText);
+               MSG_DEBUG("msgText = %s", pDest->msgText);
        } else if (pSrc->mainType == MSG_MMS_TYPE) {
 
                pDest->bTextSms = false;
@@ -258,7 +309,7 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_I
                                strncpy(pFileNameExt,"JAVA", MSG_FILENAME_LEN_MAX);
                        }
 
-                       MSG_DEBUG("Save Message Data into file : size[%d] name[%s]", pSrc->mmsDataSize, fileName);
+                       MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]", pSrc->mmsDataSize, fileName);
                        if (MsgWriteIpcFile(fileName, (char*)pSrc->pMmsData, pSrc->mmsDataSize) == false)
                                THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
 
@@ -275,6 +326,8 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_I
                }
        }
 
+       pDest->sim_idx = pSrc->simIndex;
+
        MSG_END();
 }
 
@@ -301,6 +354,7 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HID
        pDest->bBackup = pSrc->bBackup;
        pDest->priority = pSrc->priority;
        pDest->direction = pSrc->direction;
+       pDest->simIndex = pSrc->sim_idx;
 
        // Set Port Info.
        pDest->bPortValid = pSrc->msgPort.valid;
@@ -313,13 +367,14 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HID
        if(pSrc->thumbPath[0] != '\0')
                strncpy(pDest->thumbPath, pSrc->thumbPath, MSG_FILEPATH_LEN_MAX);
 
-       pDest->addr_list->nCount = pSrc->nAddressCnt;
+       int maxCnt = (pSrc->nAddressCnt > 10)? MAX_TO_ADDRESS_CNT: pSrc->nAddressCnt;
+
+       pDest->addr_list->nCount = maxCnt;
 
        msg_struct_s *addr_info_s = NULL;
        MSG_ADDRESS_INFO_S *addr_info = NULL;
 
-       for (int i = 0; i < pDest->addr_list->nCount; i++)
-       {
+       for (int i = 0; i < maxCnt; i++) {
                addr_info_s = (msg_struct_s *)pDest->addr_list->msg_struct_info[i];
                addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
 
@@ -331,6 +386,26 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HID
                addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
        }
 
+       for (int i = 0; i < pSrc->nAddressCnt; i++) {
+               addr_info_s = new msg_struct_s;
+               memset(addr_info_s, 0x00, sizeof(msg_struct_s));
+
+               addr_info_s->type = MSG_STRUCT_ADDRESS_INFO;
+               addr_info_s->data = new MSG_ADDRESS_INFO_S;
+               memset(addr_info_s->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+               addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
+
+               addr_info->addressType = pSrc->addressList[i].addressType;
+               addr_info->recipientType = pSrc->addressList[i].recipientType;
+               addr_info->contactId = pSrc->addressList[i].contactId;
+               strncpy(addr_info->addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
+               strncpy(addr_info->displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
+               addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
+
+               pDest->addressList = g_list_append(pDest->addressList, addr_info_s);
+       }
+
 
        if (pSrc->bTextSms == false) {
                int fileSize = 0;
@@ -341,34 +416,32 @@ void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HID
                pDest->dataSize = pSrc->dataSize;
 
                // Get Message Data from File
-               if (pSrc->networkStatus != MSG_NETWORK_RETRIEVE_FAIL) {
-
-                       if (MsgOpenAndReadFile(pSrc->msgData, &pFileData, &fileSize) == false)
-                               THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error");
+               if (MsgOpenAndReadFile(pSrc->msgData, &pFileData, &fileSize) == false)
+                       THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error");
 
-                       if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
-                               if (pDest->encodeType == MSG_ENCODE_8BIT) {
-                                       pDest->pData = (void*)new char[fileSize];
-                                       memset(pDest->pData, 0x00, fileSize);
-                                       memcpy(pDest->pData, pFileData, fileSize);
-                               } else {
-                                       pDest->pData = (void*)new char[fileSize+1];
-                                       memset(pDest->pData, 0x00, fileSize+1);
-                                       strncpy((char*)pDest->pData, pFileData, fileSize);
-                               }
+               if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
+                       if (pDest->encodeType == MSG_ENCODE_8BIT) {
+                               pDest->pData = (void*)new char[fileSize];
+                               memset(pDest->pData, 0x00, fileSize);
+                               memcpy(pDest->pData, pFileData, fileSize);
                        } else {
-                               if (pSrc->msgText[0] != '\0') {
-                                       pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
-                                       memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
-                                       strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
-                               }
-                               pDest->mmsDataSize = fileSize;
-                               pDest->pMmsData = (void*)new char[fileSize];
-                               memset(pDest->pMmsData, 0x00, fileSize);
-                               memcpy(pDest->pMmsData, pFileData, fileSize);
-                               MSG_DEBUG("Get Message Data from file : size[%d] name[%s]", pDest->mmsDataSize, pSrc->msgData);
+                               pDest->pData = (void*)new char[fileSize+1];
+                               memset(pDest->pData, 0x00, fileSize+1);
+                               strncpy((char*)pDest->pData, pFileData, fileSize);
                        }
+               } else {
+                       if (pSrc->msgText[0] != '\0') {
+                               pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
+                               memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
+                               strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
+                       }
+                       pDest->mmsDataSize = fileSize;
+                       pDest->pMmsData = (void*)new char[fileSize];
+                       memset(pDest->pMmsData, 0x00, fileSize);
+                       memcpy(pDest->pMmsData, pFileData, fileSize);
+                       MSG_SEC_DEBUG("Get Message Data from file : size[%d] name[%s]", pDest->mmsDataSize, pSrc->msgData);
                }
+
        } else {
                pDest->dataSize = pSrc->dataSize;
 
@@ -550,10 +623,10 @@ bool MsgHandle::CheckEventData(char *pEventData)
        case MSG_EVENT_PLG_INCOMING_MMS_CONF :
        case MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND :
        case MSG_EVENT_PLG_INCOMING_LBS_MSG_IND :
-       case MSG_EVENT_SYNCML_OPERATION :
        case MSG_EVENT_PLG_STORAGE_CHANGE_IND :
        case MSG_EVENT_PLG_INCOMING_CB_MSG_IND :
        case MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND :
+       case MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND :
                return false;
                break;
        default :
index 7f8d497..903ef5c 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
index a710998..2553a87 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -42,7 +42,7 @@ msg_error_t MsgHandle::getSMSCOption(msg_struct_t msg_struct)
        MSG_NULL_CHECK(smsc_opt->data);
 
        // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T) + sizeof(msg_sim_slot_id_t);
 
        char cmdBuf[cmdSize];
        bzero(cmdBuf, cmdSize);
@@ -60,6 +60,12 @@ msg_error_t MsgHandle::getSMSCOption(msg_struct_t msg_struct)
        // Copy Command Data
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &opt_type, sizeof(MSG_OPTION_TYPE_T));
 
+       msg_sim_slot_id_t simIndex = ((MSG_SMSC_LIST_HIDDEN_S *)smsc_opt->data)->simIndex;
+       if (simIndex <= 0) {
+               THROW(MsgException::INVALID_PARAM, "Invalid SIM Index");
+       }
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), &simIndex, sizeof(msg_sim_slot_id_t));
+
        // Send Command to Messaging FW
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
@@ -85,6 +91,8 @@ msg_error_t MsgHandle::getSMSCOption(msg_struct_t msg_struct)
 
                pTmp->selected = smsc_list_tmp.selected;
                pTmp->smsc_list->nCount = smsc_list_tmp.totalCnt;
+               pTmp->index = smsc_list_tmp.selected;
+               pTmp->simIndex = smsc_list_tmp.simIndex;
 
                msg_struct_s *pStructTmp = NULL;
 
@@ -120,6 +128,15 @@ msg_error_t MsgHandle::setSMSCOption(msg_struct_t msg_struct)
 
        smsc_list_tmp.totalCnt = pTmpList->smsc_list->nCount;
        smsc_list_tmp.selected = pTmpList->selected;
+       smsc_list_tmp.index = pTmpList->index;
+       smsc_list_tmp.simIndex = pTmpList->simIndex;
+
+       if (smsc_list_tmp.totalCnt > SMSC_LIST_MAX) {
+               MSG_ERR("SMSC count is invaild value[Max:%d, Input:%d]", SMSC_LIST_MAX, smsc_list_tmp.totalCnt);
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       MSG_DEBUG("SMSC totalcnt:%d selected:%d, index:%d ", smsc_list_tmp.totalCnt, smsc_list_tmp.selected, smsc_list_tmp.index);
 
        msg_struct_s *pStructTmp = NULL;
 
@@ -167,7 +184,7 @@ msg_error_t MsgHandle::getCBOption(msg_struct_t msg_struct)
        MSG_NULL_CHECK(cb_opt->data);
 
        // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T) + sizeof(msg_sim_slot_id_t);
 
        char cmdBuf[cmdSize];
        bzero(cmdBuf, cmdSize);
@@ -185,6 +202,9 @@ msg_error_t MsgHandle::getCBOption(msg_struct_t msg_struct)
        // Copy Command Data
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &opt_type, sizeof(MSG_OPTION_TYPE_T));
 
+       msg_sim_slot_id_t simIndex = ((MSG_CBMSG_OPT_HIDDEN_S*)cb_opt->data)->simIndex;
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), &simIndex, sizeof(msg_sim_slot_id_t));
+
        // Send Command to Messaging FW
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
@@ -207,6 +227,7 @@ msg_error_t MsgHandle::getCBOption(msg_struct_t msg_struct)
                MSG_CBMSG_OPT_HIDDEN_S *pTmp = (MSG_CBMSG_OPT_HIDDEN_S *)cb_opt->data;
                pTmp->bReceive = cb_opt_tmp.bReceive;
                pTmp->maxSimCnt = cb_opt_tmp.maxSimCnt;
+               pTmp->simIndex = cb_opt_tmp.simIndex;
 
                for (i = 0; i < CB_LANG_TYPE_MAX; i++)
                        pTmp->bLanguage[i] = cb_opt_tmp.bLanguage[i];
@@ -252,6 +273,7 @@ msg_error_t MsgHandle::setCBOption(msg_struct_t msg_struct)
 
        cb_opt_tmp.bReceive = cb_msg_opt->bReceive;
        cb_opt_tmp.maxSimCnt = cb_msg_opt->maxSimCnt;
+       cb_opt_tmp.simIndex = cb_msg_opt->simIndex;
        for (int i = 0; i < CB_LANG_TYPE_MAX; i++)
                cb_opt_tmp.bLanguage[i] = cb_msg_opt->bLanguage[i];
 
@@ -665,7 +687,7 @@ msg_error_t MsgHandle::getVoiceMsgOpt(msg_struct_t msg_struct)
        MSG_NULL_CHECK(voice_opt->data);
 
        // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T) + sizeof(msg_sim_slot_id_t);
 
        char cmdBuf[cmdSize];
        bzero(cmdBuf, cmdSize);
@@ -683,6 +705,12 @@ msg_error_t MsgHandle::getVoiceMsgOpt(msg_struct_t msg_struct)
        // Copy Command Data
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &opt_type, sizeof(MSG_OPTION_TYPE_T));
 
+       msg_sim_slot_id_t simIndex = ((MSG_VOICEMAIL_OPT_S *)voice_opt->data)->simIndex;
+       if (simIndex <= 0) {
+               THROW(MsgException::INVALID_PARAM, "Invalid SIM Index : [index=%d]", simIndex);
+       }
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_OPTION_TYPE_T)), &simIndex, sizeof(msg_sim_slot_id_t));
+
        // Send Command to Messaging FW
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
index c6213dd..c6fcc8e 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -22,8 +22,6 @@
 #include "MsgProxyListener.h"
 #include "MsgHandle.h"
 
-#include "MsgStorageHandler.h"
-
 #include "MsgVMessage.h"
 /*==================================================================================================
                                      IMPLEMENTATION OF MsgHandle - Storage Member Functions
@@ -33,6 +31,9 @@ int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pS
        MSG_MESSAGE_INFO_S msgInfo = {0,};
        MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
        convertMsgStruct(pMsg, &msgInfo);
 
@@ -46,7 +47,11 @@ int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pS
        convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
 
        // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
+
+       int cmdSize = sizeof(MSG_CMD_S) + dataSize;
 
        char cmdBuf[cmdSize];
        bzero(cmdBuf, cmdSize);
@@ -59,8 +64,7 @@ int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pS
        memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
 
        // Copy Command Data
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
@@ -71,12 +75,16 @@ int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pS
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_ADD_MSG)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if (pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        msg_message_id_t msgId = 0;
 
@@ -89,14 +97,22 @@ int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pS
 
 msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
 {
-       MSG_MESSAGE_INFO_S msgInfo = {0, };
+       MSG_MESSAGE_INFO_S msgInfo;
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
 
        // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
        msg_struct_s *msg = (msg_struct_s *)pSyncMLMsg->msg;
        convertMsgStruct((MSG_MESSAGE_HIDDEN_S *)msg->data, &msgInfo);
 
        // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + sizeof(MSG_MESSAGE_INFO_S);
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
+
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + dataSize;
 
        char cmdBuf[cmdSize];
        bzero(cmdBuf, cmdSize);
@@ -111,7 +127,7 @@ msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
        // Copy Command Data
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), encodedData, dataSize);
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
@@ -123,11 +139,21 @@ msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
+       msg_message_id_t msgId = 0;
+
+       // Decode Return Data
+       MsgDecodeMsgId(pEvent->data, &msgId);
+
+       ((MSG_MESSAGE_HIDDEN_S *)msg->data)->msgId = msgId;
+
        return pEvent->result;
 }
 
@@ -137,10 +163,13 @@ msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG
        MSG_MESSAGE_INFO_S msgInfo = {0, };
        MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
        convertMsgStruct(pMsg, &msgInfo);
 
-       if(pSendOpt != NULL) {
+       if (pSendOpt != NULL) {
                MSG_MESSAGE_TYPE_S msgType = {0,};
 
                msgType.mainType = pMsg->mainType;
@@ -151,7 +180,11 @@ msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG
        }
 
        // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
+
+       int cmdSize = sizeof(MSG_CMD_S) + dataSize;
 
        char cmdBuf[cmdSize];
        bzero(cmdBuf, cmdSize);
@@ -164,19 +197,20 @@ msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG
        memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
 
        // Copy Command Data
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_UPDATE_MSG)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -209,12 +243,14 @@ msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_UPDATE_READ)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -224,6 +260,45 @@ msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
 }
 
 
+msg_error_t MsgHandle::setConversationToRead(msg_thread_id_t ThreadId)
+{
+       // Allocate Memory to Command Data
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+       MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
+
+       // Copy Cookie
+       memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
+
+       // Copy Command Data
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
+
+       // Send Command to Messaging FW
+       char* pEventData = NULL;
+       AutoPtr<char> eventBuf(&pEventData);
+
+       write((char*)pCmd, cmdSize, &pEventData);
+
+       // Get Return Data
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
+
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
+       if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
+       {
+               THROW(MsgException::INVALID_RESULT, "Event Data Error");
+       }
+
+       return pEvent->result;
+}
+
+
 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
 {
        // Allocate Memory to Command Data
@@ -247,12 +322,14 @@ msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProte
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -284,12 +361,14 @@ msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_DELETE_MSG)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -322,12 +401,14 @@ msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -362,12 +443,14 @@ msg_error_t MsgHandle::deleteMessagesByList(msg_id_list_s *pMsgIdList)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_DELETE_MESSAGE_BY_LIST) {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
@@ -399,12 +482,14 @@ msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -437,12 +522,14 @@ msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -474,18 +561,21 @@ msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_COUNT_MSG)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MsgDecodeCountInfo(pEvent->data, pCountInfo);
@@ -521,12 +611,16 @@ msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *p
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
@@ -564,12 +658,16 @@ msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAd
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
@@ -606,23 +704,29 @@ msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
-       if (pEvent->eventType != MSG_EVENT_GET_MSG)
-       {
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
+       if (pEvent->eventType != MSG_EVENT_GET_MSG) {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS)
+       if (pEvent->result != MSG_SUCCESS)
                return pEvent->result;
 
        // Decode Return Data
        MSG_MESSAGE_INFO_S msgInfo;
        MSG_SENDINGOPT_INFO_S sendOptInfo;
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
 
        // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S
        convertMsgStruct(&msgInfo, pMsg);
 
-       if(pSendOpt != NULL) {
+       if (pSendOpt != NULL) {
                MSG_MESSAGE_TYPE_S msgType = {0,};
 
                msgType.mainType = pMsg->mainType;
@@ -647,13 +751,13 @@ msg_error_t MsgHandle::getFolderViewList(msg_folder_id_t FolderId, const MSG_SOR
 {
        msg_error_t err = MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
-
-       if (err != MSG_SUCCESS)
-       {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
-               return err;
-       }
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS)
+//     {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
 
        err = MsgStoGetFolderViewList(FolderId, (MSG_SORT_RULE_S *)pSortRule, pMsgFolderViewList);
 
@@ -663,7 +767,7 @@ msg_error_t MsgHandle::getFolderViewList(msg_folder_id_t FolderId, const MSG_SOR
                return err;
        }
 
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
@@ -691,12 +795,14 @@ msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -728,18 +834,20 @@ msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       return pEvent->result;;
+       return pEvent->result;
 }
 
 
@@ -765,12 +873,14 @@ msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -804,12 +914,16 @@ msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MsgDecodeFolderList(pEvent->data, pFolderList);
@@ -822,23 +936,61 @@ msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_s
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS)
+//     {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
+
+       err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
 
        if (err != MSG_SUCCESS)
        {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
+               MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
                return err;
        }
 
-       err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
+//     MsgStoDisconnectDB();
 
-       if (err != MSG_SUCCESS)
+#if 0
+       // Allocate Memory to Command Data
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+       MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
+
+       // Copy Command Data
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
+
+       // Send Command to Messaging FW
+       char* pEventData = NULL;
+       AutoPtr<char> eventBuf(&pEventData);
+
+       write((char*)pCmd, cmdSize, &pEventData);
+
+       // Get Return Data
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
+
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
+       if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST)
        {
-               MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
-               return err;
+               THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       MsgStoDisconnectDB();
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
+
+       // Decode Return Data
+       MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
+#endif
 
        return err;
 }
@@ -849,9 +1001,9 @@ msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVE
 
        msg_error_t err =  MSG_SUCCESS;
 
-       MsgStoConnectDB();
+//     MsgStoConnectDB();
        err = MsgStoGetConversationViewItem(MsgId, pConv);
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
@@ -862,47 +1014,13 @@ msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_str
 
        msg_error_t err =  MSG_SUCCESS;
 
-       MsgStoConnectDB();
+//     MsgStoConnectDB();
        err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
-       if(err != MSG_SUCCESS)
+       if (err != MSG_SUCCESS)
                return err;
 
-
-// Update Read Status for the Thead ID
-#if 1
-       // Allocate Memory to Command Data
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
-
-       char cmdBuf[cmdSize];
-       bzero(cmdBuf, cmdSize);
-       MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
-
-       // Set Command Parameters
-       pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
-
-       // Copy Cookie
-       memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
-
-       // Copy Command Data
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
-
-       // Send Command to Messaging FW
-       char* pEventData = NULL;
-       AutoPtr<char> eventBuf(&pEventData);
-
-       write((char*)pCmd, cmdSize, &pEventData);
-
-       // Get Return Data
-       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
-
-       if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
-       {
-               THROW(MsgException::INVALID_RESULT, "Event Data Error");
-       }
-#endif
-
        MSG_END();
 
        return err;
@@ -932,18 +1050,21 @@ msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool in
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        return MSG_SUCCESS;
 }
@@ -976,17 +1097,26 @@ msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MSG_MESSAGE_INFO_S msgInfo;
 
-       memcpy(&msgInfo, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(MSG_MESSAGE_INFO_S));
+       memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+       MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
 
        // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
        convertMsgStruct(&msgInfo, pMsg);
@@ -1026,6 +1156,9 @@ msg_error_t MsgHandle::resetDatabase()
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_RESET_DB)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -1054,18 +1187,21 @@ msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MsgDecodeMemSize(pEvent->data, memsize);
@@ -1115,12 +1251,16 @@ msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        return MSG_SUCCESS;
 }
@@ -1156,18 +1296,21 @@ msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        return MSG_SUCCESS;
 }
@@ -1177,13 +1320,13 @@ msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
-
-       if (err != MSG_SUCCESS)
-       {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
-               return err;
-       }
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS)
+//     {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
 
        err = MsgStoSearchMessage(pSearchString, pThreadViewList);
 
@@ -1193,31 +1336,32 @@ msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_
                return err;
        }
 
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
 
-
-msg_error_t MsgHandle::searchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList)
+msg_error_t MsgHandle::searchByTag(const int tagType, msg_struct_list_s *pThreadViewList)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
-
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
-               return err;
-       }
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS)
+//     {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
 
-       err = MsgStoSearchMessage(pSearchCon, offset, limit, pMsgList);
+       err = MsgStoSearchByTag(tagType, pThreadViewList);
 
-       if (err != MSG_SUCCESS) {
+       if (err != MSG_SUCCESS)
+       {
                MSG_DEBUG("MsgStoSearchMessage() Error!!");
                return err;
        }
 
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
@@ -1227,13 +1371,13 @@ msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
-
-       if (err != MSG_SUCCESS)
-       {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
-               return err;
-       }
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS)
+//     {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
 
        err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
 
@@ -1243,7 +1387,7 @@ msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *
                return err;
        }
 
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
@@ -1256,15 +1400,15 @@ msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageC
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if (remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
@@ -1278,13 +1422,11 @@ msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageC
        // Copy Cookie
        memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
 
-       int listenerFd = clientFd;
+       MSG_DEBUG("remote fd %d", remoteFd);
 
-       MSG_DEBUG("remote fd %d", listenerFd);
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
 
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
-
-       MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
+       MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
@@ -1295,6 +1437,9 @@ msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageC
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
        {
                THROW(MsgException::INVALID_PARAM, "Event Data Error");
@@ -1312,6 +1457,9 @@ msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_
        bzero(cmdBuf, cmdSize);
        MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
 
+       report_list->nCount = 0;
+       report_list->msg_struct_info = NULL;
+
        // Set Command Parameters
        pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
 
@@ -1325,18 +1473,21 @@ msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
-
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MsgDecodeReportStatus(pEvent->data, report_list);
@@ -1349,13 +1500,13 @@ msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
-
-       if (err != MSG_SUCCESS)
-       {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
-               return err;
-       }
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS)
+//     {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
 
        err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
 
@@ -1365,7 +1516,7 @@ msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct
                return err;
        }
 
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
@@ -1397,18 +1548,72 @@ msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_th
        char* pEventData = NULL;
        AutoPtr<char> eventBuf(&pEventData);
 
+       write((char*)pCmd, cmdSize, &pEventData);
+
+       // Get Return Data
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
+
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
+       if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
+       {
+               THROW(MsgException::INVALID_RESULT, "Event Data Error");
+       }
+
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
+
+       // Decode Return Data
+       MsgDecodeThreadId(pEvent->data, pThreadId);
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
+{
+       int addrCnt = (int)g_list_length((GList *)msg_address_list);
+
+       // Allocate Memory to Command Data
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+       MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
+
+       // Copy Cookie
+       memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
+
+       // Copy Command Data
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
+       int addSize = sizeof(MSG_ADDRESS_INFO_S);
+       for(int i=0; i<addrCnt; i++) {
+               memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(addrCnt)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(g_list_nth_data((GList *)msg_address_list,(guint)i)))->data, sizeof(MSG_ADDRESS_INFO_S));
+       }
+
+       // Send Command to Messaging FW
+       char* pEventData = NULL;
+       AutoPtr<char> eventBuf(&pEventData);
 
        write((char*)pCmd, cmdSize, &pEventData);
 
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS) return pEvent->result;
+       if (pEvent->result != MSG_SUCCESS)
+               return pEvent->result;
 
        // Decode Return Data
        MsgDecodeThreadId(pEvent->data, pThreadId);
@@ -1444,6 +1649,9 @@ msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pT
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -1456,25 +1664,25 @@ msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pT
 }
 
 
-msg_error_t MsgHandle::getMessageList(msg_folder_id_t folderId, msg_thread_id_t threadId, msg_message_type_t msgType, msg_storage_id_t storageId, msg_struct_list_s *pMsgList)
+msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
 {
        msg_error_t err =  MSG_SUCCESS;
 
-       err = MsgStoConnectDB();
-
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("MsgStoConnectDB() Error!!");
-               return err;
-       }
+//     err = MsgStoConnectDB();
+//
+//     if (err != MSG_SUCCESS) {
+//             MSG_DEBUG("MsgStoConnectDB() Error!!");
+//             return err;
+//     }
 
-       err = MsgStoGetMessageList(folderId, threadId, msgType, storageId, pMsgList);
+       err = MsgStoGetMessageList(pListCond, pMsgList);
 
        if (err != MSG_SUCCESS) {
-               MSG_DEBUG("MsgStoSearchMessage() Error!!");
+               MSG_DEBUG("MsgStoGetMessageList() Error!!");
                return err;
        }
 
-       MsgStoDisconnectDB();
+//     MsgStoDisconnectDB();
 
        return err;
 }
@@ -1507,6 +1715,9 @@ int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -1543,6 +1754,9 @@ int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -1579,6 +1793,9 @@ int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
@@ -1615,18 +1832,24 @@ msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
        // Get Return Data
        MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
 
+       if (pEvent == NULL)
+               THROW(MsgException::INVALID_RESULT, "Event is NULL");
+
        if (pEvent->eventType != MSG_EVENT_GET_MSG)
        {
                THROW(MsgException::INVALID_RESULT, "Event Data Error");
        }
 
-       if(pEvent->result != MSG_SUCCESS)
+       if (pEvent->result != MSG_SUCCESS)
                return pEvent->result;
 
        // Decode Return Data
        MSG_MESSAGE_INFO_S msgInfo = {0,};
        MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
 
+       msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
        MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
 
        //Convert MSG_MESSAGE_INFO_S to
index 405076a..bfd1404 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <time.h>
 #include "MsgDebug.h"
 #include "MsgCppTypes.h"
 #include "MsgException.h"
+#include "MsgUtilFunction.h"
 #include "MsgProxyListener.h"
 #include "MsgHandle.h"
 
 
-#define MAX_ADDRESS_LEN                        21 // including '+'
-
 /*==================================================================================================
                                      IMPLEMENTATION OF MsgHandle - Transport Member Functions
 ==================================================================================================*/
@@ -44,15 +43,27 @@ msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
        MSG_REQUEST_INFO_S reqInfo = {0};
        char trId[MMS_TR_ID_LEN+1] = {0};
 
+       reqInfo.msgInfo.addressList = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&reqInfo.msgInfo.addressList);
+
        msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
 
        MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
 
+       if (reqmsg->simIndex <= 0) {
+               MSG_DEBUG("Wrong SIM Index [%d]", reqmsg->simIndex);
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
        if (reqmsg->subType != MSG_SENDREQ_JAVA_MMS) {
                // In case MMS read report, get address value later.
                if(reqmsg->subType != MSG_READREPLY_MMS) {
-                       if ((reqmsg->addr_list->nCount == 0) || (reqmsg->addr_list->nCount > MAX_TO_ADDRESS_CNT)) {
-                               MSG_DEBUG("Recipient address count error [%d]", reqmsg->addr_list->nCount );
+                       if (reqmsg->addr_list && (reqmsg->addr_list->nCount > 0) && (reqmsg->addr_list->nCount <= MAX_TO_ADDRESS_CNT)) {
+                               MSG_DEBUG("Recipient address count [%d]", reqmsg->addr_list->nCount );
+                       } else if (g_list_length(reqmsg->addressList) > 0) {
+                               MSG_DEBUG("Recipient address count [%d]", g_list_length(reqmsg->addressList) );
+                       } else {
+                               MSG_DEBUG("Address count is invalid.");
                                return MSG_ERR_INVALID_MESSAGE;
                        }
                }
@@ -67,7 +78,7 @@ msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
                }
 
                reqmsg->bRead = false;
-               reqmsg->bProtected = false;
+               //reqmsg->bProtected = false;
                reqmsg->priority = MSG_MESSAGE_PRIORITY_NORMAL;
                reqmsg->direction = MSG_DIRECTION_TYPE_MO;
                reqmsg->storageId = MSG_STORAGE_PHONE;
@@ -83,30 +94,22 @@ msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
                //in case of JAVA MMS msg, parse mms transaction id from pMmsData
                reqmsg->networkStatus = MSG_NETWORK_SENDING;
                strncpy(trId, (char*)reqmsg->pMmsData+3,MMS_TR_ID_LEN);
-               MSG_DEBUG("JavaMMS transaction Id:%s ",trId);
+               MSG_SEC_DEBUG("JavaMMS transaction Id:%s ",trId);
        }
 
        // Convert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
        convertMsgStruct(reqmsg, &(reqInfo.msgInfo));
 
-       /* Check address validation */
-       if (reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE) {
-               for(int i=0; i<reqmsg->addr_list->nCount; i++) {
-                               if (reqInfo.msgInfo.addressList[i].addressVal[0] == '+' && strlen(reqInfo.msgInfo.addressList[i].addressVal)>MAX_ADDRESS_LEN) {
-                                       return MSG_ERR_INVALID_PARAMETER;
-                               } else if (strlen(reqInfo.msgInfo.addressList[i].addressVal)>(MAX_ADDRESS_LEN-1)) {
-                                       return MSG_ERR_INVALID_PARAMETER;
-                               }
-               }
-       }
-
        MSG_MESSAGE_TYPE_S msgType = {0,};
 
        msgType.mainType = reqmsg->mainType;
        msgType.subType = reqmsg->subType;
        msgType.classType = reqmsg->classType;
 
-       convertSendOptStruct((const MSG_SENDINGOPT_S *)pReq->sendOpt, &(reqInfo.sendOptInfo), msgType);
+       msg_struct_s *send_opt_s = (msg_struct_s *)pReq->sendOpt;
+       MSG_SENDINGOPT_S *send_opt = (MSG_SENDINGOPT_S *)send_opt_s->data;
+
+       convertSendOptStruct((const MSG_SENDINGOPT_S *)send_opt, &(reqInfo.sendOptInfo), msgType);
 
        reqInfo.reqId = 0;
 
@@ -115,14 +118,14 @@ msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
 
        chInfo.listenerFd = MsgProxyListener::instance()->getRemoteFd();
 
-#ifdef __x86_64__
-       chInfo.handleAddr = (uint64_t) this;
-#else
        chInfo.handleAddr = (unsigned int) this;
-#endif
 
        /* Allocate Memory to Command Data */
-       int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_REQUEST_INFO_S) + sizeof(MSG_PROXY_INFO_S);
+       char* encodedData = NULL;
+       AutoPtr<char> buf(&encodedData);
+       int dataSize = MsgEncodeMsgInfo(&reqInfo.msgInfo, &reqInfo.sendOptInfo, &encodedData);
+
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t) + dataSize + sizeof(MSG_PROXY_INFO_S);
 
        // In case of JAVA MMS msg, add trId
        if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
@@ -140,12 +143,13 @@ msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
        memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
 
        // Copy Command Data
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo, sizeof(MSG_REQUEST_INFO_S));
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), &chInfo, sizeof(MSG_PROXY_INFO_S));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo.reqId, sizeof(msg_request_id_t));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), &chInfo, sizeof(MSG_PROXY_INFO_S));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), encodedData, dataSize);
 
        // In case of JAVA MMS msg, add trId
        if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
-               memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)+sizeof(MSG_PROXY_INFO_S)), &trId, sizeof(trId));
+               memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)+dataSize), &trId, sizeof(trId));
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
@@ -216,15 +220,15 @@ msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged,
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
@@ -238,13 +242,11 @@ msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged,
        // Copy Cookie
        memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
 
-       int listenerFd = clientFd;
-
-       MSG_DEBUG("remote fd %d", listenerFd);
+       MSG_DEBUG("remote fd %d", remoteFd);
 
-       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
 
-       MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
+       MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
@@ -271,15 +273,15 @@ msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming,
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
@@ -297,7 +299,7 @@ msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming,
 
        MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd;
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_SMS_TYPE;
        cmdParam.port = port;
 
@@ -331,15 +333,15 @@ msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb on
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
@@ -357,7 +359,7 @@ msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb on
 
        MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd;
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_MMS_TYPE;
 
        if (pAppId)
@@ -393,15 +395,15 @@ msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyn
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
@@ -419,7 +421,7 @@ msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyn
 
        MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd;
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_SMS_TYPE;
 
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
@@ -451,15 +453,15 @@ msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgInc
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
@@ -475,7 +477,7 @@ msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgInc
 
        MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd;
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_SMS_TYPE;
 
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
@@ -508,15 +510,15 @@ msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operatio
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
@@ -534,7 +536,7 @@ msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operatio
 
        MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd;
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_SMS_TYPE;
 
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
@@ -566,15 +568,15 @@ msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsg
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
-               return MSG_SUCCESS;
+       if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
 
        // Allocate Memory to Command Data
        int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
@@ -592,7 +594,7 @@ msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsg
 
        MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd;
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_SMS_TYPE;
 
        if (pAppId)
@@ -627,14 +629,14 @@ msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, boo
 
        MsgProxyListener* eventListener = MsgProxyListener::instance();
 
-       eventListener->start();
+       eventListener->start(this);
 
-       int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
 
-       if (clientFd < 0)
-               return MSG_ERR_TRANSPORT_ERROR;
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
 
-       if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false) // callback was already registered, just return SUCCESS
+       if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false)
                return MSG_SUCCESS;
 
        // Allocate Memory to Command Data
@@ -653,13 +655,13 @@ msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, boo
 
        MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
 
-       cmdParam.listenerFd = clientFd; // fd that is reserved to the "listener thread" by msgfw daemon
+       cmdParam.listenerFd = remoteFd;
        cmdParam.msgType = MSG_SMS_TYPE;
        cmdParam.bsave = bSave;
 
        memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
 
-       MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
+       MSG_DEBUG("reg new msg [%s], fd: %d, bSave: %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.bsave);
 
        // Send Command to Messaging FW
        char* pEventData = NULL;
@@ -680,6 +682,59 @@ msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, boo
 }
 
 
+msg_error_t MsgHandle::regReportMessageCallback(msg_report_msg_incoming_cb onReportMsgCB, void *pUserParam)
+{
+       if (!onReportMsgCB)
+               THROW(MsgException::INVALID_PARAM, "onReportMsgCB is null");
+
+       MsgProxyListener* eventListener = MsgProxyListener::instance();
+
+       eventListener->start(this);
+
+       int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
+
+       if(remoteFd == -1 )
+               return MSG_ERR_INVALID_MSGHANDLE;
+
+       if (eventListener->regReportMsgIncomingCB(this, onReportMsgCB, pUserParam) == false)
+               return MSG_ERR_INVALID_PARAMETER;
+
+       // Allocate Memory to Command Data
+       int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+       MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_REG_REPORT_MSG_INCOMING_CB;
+
+       // Copy Cookie
+       memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
+
+       MSG_DEBUG("remote fd %d", remoteFd);
+
+       memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
+
+       MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
+
+       // Send Command to Messaging FW
+       char* pEventData = NULL;
+       AutoPtr<char> eventBuf(&pEventData);
+
+       write((char*)pCmd, cmdSize, &pEventData);
+
+       // Get Return Data
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
+
+       if (pEvent->eventType != MSG_EVENT_REG_REPORT_MSG_INCOMING_CB)
+       {
+               THROW(MsgException::INVALID_PARAM, "Event Data Error");
+       }
+
+       return pEvent->result;
+}
+
+
 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
 {
        if( msgId < 1)
index d6f106c..e6d8ed2 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <errno.h>
 #include "MsgDebug.h"
 #include "MsgCppTypes.h"
 #include "MsgException.h"
+#include "MsgUtilFunction.h"
 #include "MsgUtilFile.h"
 #include "MsgProxyListener.h"
 #include "MsgGconfWrapper.h"
 
+void MsgServerRestartCb(keynode_t *key, void* data)
+{
+       bool bReady = false;
+       MSG_DEBUG("Message Service Running State Changed");
+       // server is currently booting and service is not available until the end of booting
+       MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady);
+       MSG_INFO("Message Service Running State Changed bReady:(%d)", bReady);
+
+       //bReady false indicates that server has restarted. Hence the proxylistener needs to be reset
+       if (bReady == false) {
+               MSG_DEBUG("Message Service Is Restarted. Resetting ProxyListener");
+               MsgProxyListener::instance()->resetProxyListener();
+       }
+}
 
 gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
 {
        MSG_BEGIN();
+#if 0
+       if ((G_IO_ERR & condition) || (G_IO_HUP & condition) || (G_IO_NVAL & condition))
+       {
+               MSG_DEBUG("IO condition Error!!! [%d]", condition);
 
+               MsgProxyListener::instance()->stop();
+               return FALSE;
+       }
+#endif
        if (G_IO_ERR & condition)
        {
-               MSG_DEBUG("IO Error!!! [%d]", condition);
+               MSG_ERR("IO Error!!! [%d]", condition);
 
                MsgProxyListener::instance()->stop();
                return FALSE;
@@ -38,7 +61,7 @@ gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
 
        if (G_IO_HUP & condition)
        {
-               MSG_DEBUG("socket fd Error!!! [%d]", condition);
+               MSG_ERR("socket fd Error!!! [%d]", condition);
 
                MsgProxyListener::instance()->stop();
                return FALSE;
@@ -46,7 +69,7 @@ gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
 
        if (G_IO_NVAL & condition)
        {
-               MSG_DEBUG("Invaild socket Error!!! [%d]", condition);
+               MSG_ERR("Invaild socket Error!!! [%d]", condition);
 
                MsgProxyListener::instance()->stop();
                return FALSE;
@@ -64,7 +87,7 @@ gboolean readSocket(GIOChannel *source, GIOCondition condition, gpointer data)
        }
        else if (n == 0)
        {
-               MSG_DEBUG("Server closed connection");
+               MSG_WARN("Server closed connection");
                MsgProxyListener::instance()->stop();
                if (buf)
                {
@@ -103,6 +126,8 @@ MsgProxyListener::MsgProxyListener() : running(0)
        newMMSConfMessageCBList.clear();
        newSyncMLMessageCBList.clear();
        newLBSMessageCBList.clear();
+       openHandleSet.clear();
+       MsgSettingRegVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
 }
 
 
@@ -113,6 +138,8 @@ MsgProxyListener::~MsgProxyListener()
        newMMSConfMessageCBList.clear();
        newSyncMLMessageCBList.clear();
        newLBSMessageCBList.clear();
+       openHandleSet.clear();
+       MsgSettingRemoveVconfCBCommon(VCONFKEY_MSG_SERVER_READY, MsgServerRestartCb);
 }
 
 
@@ -121,21 +148,25 @@ MsgProxyListener* MsgProxyListener::instance()
        static Mutex mm;
        MutexLocker lock(mm);
 
-       if (!pInstance)
+       if (!pInstance) {
                pInstance = new MsgProxyListener();
+       }
 
        return pInstance;
 }
 
 
-void MsgProxyListener::start()
+void MsgProxyListener::start(MsgHandle* pMsgHandle)
 {
+       MutexLocker lock(mx);
+
+       handle_set::iterator it = openHandleSet.find(pMsgHandle);
+       if (it == openHandleSet.end())
+               openHandleSet.insert(pMsgHandle);
        if (running == 0)
        {
-               mx.lock();
                cliSock.connect(MSG_SOCKET_PATH);
                cv.signal(); // wake up the waiting thread
-               mx.unlock();
 
                int fd = cliSock.fd();
 
@@ -189,12 +220,8 @@ bool MsgProxyListener::regSentStatusEventCB(MsgHandle* pMsgHandle, msg_sent_stat
 
        for (; it != sentStatusCBList.end(); it++)
        {
-               if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus)
-               {
+               if (it->hAddr == pMsgHandle && it->pfSentStatusCB == pfSentStatus) {
                        MSG_DEBUG("msg_sent_status_cb() callback : [%p] is already registered!!!", pfSentStatus);
-
-                       it->userParam = pUserParam;
-
                        return false;
                }
        }
@@ -215,12 +242,8 @@ bool MsgProxyListener::regMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_sms_
 
        for (; it != newMessageCBList.end(); it++)
        {
-               if (it->port == port && it->pfIncomingCB == pfNewMessage)
-               {
+               if (it->hAddr == pMsgHandle && it->port == port && it->pfIncomingCB == pfNewMessage) {
                        MSG_DEBUG("msg_sms_incoming_cb() callback : Port Number [%d] is already registered!!!", port);
-
-                       it->userParam = pUserParam;
-
                        return false;
                }
        }
@@ -241,21 +264,13 @@ bool MsgProxyListener::regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, m
 
        for (; it != newMMSConfMessageCBList.end(); it++)
        {
-               if (it->pfMMSConfIncomingCB == pfNewMMSConfMessage)
-               {
+               if (it->hAddr == pMsgHandle && it->pfMMSConfIncomingCB == pfNewMMSConfMessage) {
 
-                       if(pAppId == NULL)
-                       {
+                       if(pAppId == NULL) {
                                MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback is already registered!!!");
-
                                return false;
-                       }
-                       else if(!strncmp(it->appId, pAppId, MAX_MMS_JAVA_APPID_LEN))
-                       {
+                       } else if(!strncmp(it->appId, pAppId, MAX_MMS_JAVA_APPID_LEN)) {
                                MSG_DEBUG("msg_mms_conf_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
-
-                               it->userParam = pUserParam;
-
                                return false;
                        }
                }
@@ -280,21 +295,13 @@ bool MsgProxyListener::regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_
 
        for (; it != newPushMessageCBList.end(); it++)
        {
-               if (it->pfPushIncomingCB == pfNewPushMessage)
-               {
+               if (it->hAddr == pMsgHandle && it->pfPushIncomingCB == pfNewPushMessage) {
 
-                       if(pAppId == NULL)
-                       {
+                       if(pAppId == NULL) {
                                MSG_DEBUG("msg_push_msg_incoming_cb() callback is already registered!!!");
-
                                return false;
-                       }
-                       else if(!strncmp(it->appId, pAppId, MAX_WAPPUSH_ID_LEN))
-                       {
+                       } else if(!strncmp(it->appId, pAppId, MAX_WAPPUSH_ID_LEN)) {
                                MSG_DEBUG("msg_push_msg_incoming_cb() callback : AppId [%s] is already registered!!!", pAppId);
-
-                               it->userParam = pUserParam;
-
                                return false;
                        }
                }
@@ -318,13 +325,10 @@ bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_cb
 
        for (; it != newCBMessageCBList.end(); it++)
        {
-               if (it->pfCBIncomingCB == pfNewCBMessage)
-               {
+               if (it->hAddr == pMsgHandle && it->pfCBIncomingCB == pfNewCBMessage) {
                        MSG_DEBUG("msg_CB_incoming_cb() callback : [%p] is already registered!!!", pfNewCBMessage);
-
-                       it->bsave = bSave;
-                       it->userParam = pUserParam;
-
+                        it->bsave = bSave;
+                        it->userParam = pUserParam;
                        return false;
                }
        }
@@ -336,6 +340,30 @@ bool MsgProxyListener::regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_cb
        return true;
 }
 
+
+bool MsgProxyListener::regReportMsgIncomingCB(MsgHandle* pMsgHandle, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam)
+{
+       MutexLocker lock(mx);
+
+       std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it = reportMessageCBList.begin();
+
+       for (; it != reportMessageCBList.end(); it++)
+       {
+               if (it->hAddr == pMsgHandle && it->pfReportMsgIncomingCB == pfReportMessage) {
+                       MSG_DEBUG("msg_report_msg_incoming_cb() callback : [%p] is already registered!!!", pfReportMessage);
+                        it->userParam = pUserParam;
+                       return false;
+               }
+       }
+
+       MSG_REPORT_INCOMING_CB_ITEM_S incomingCB = {pMsgHandle, pfReportMessage, pUserParam};
+
+       reportMessageCBList.push_back(incomingCB);
+
+       return true;
+}
+
+
 bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam)
 {
        MutexLocker lock(mx);
@@ -344,12 +372,8 @@ bool MsgProxyListener::regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, ms
 
        for (; it != newSyncMLMessageCBList.end(); it++)
        {
-               if (it->pfSyncMLIncomingCB == pfNewSyncMLMessage)
-               {
+               if (it->hAddr == pMsgHandle && it->pfSyncMLIncomingCB == pfNewSyncMLMessage) {
                        MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewSyncMLMessage);
-
-                       it->userParam = pUserParam;
-
                        return false;
                }
        }
@@ -370,12 +394,8 @@ bool MsgProxyListener::regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_l
 
        for (; it != newLBSMessageCBList.end(); it++)
        {
-               if (it->pfLBSMsgIncoming == pfNewLBSMsgIncoming)
-               {
+               if (it->hAddr == pMsgHandle && it->pfLBSMsgIncoming == pfNewLBSMsgIncoming) {
                        MSG_DEBUG("msg_lbs_msg_incoming_cb() callback : [%p] is already registered!!!", pfNewLBSMsgIncoming);
-
-                       it->userParam = pUserParam;
-
                        return false;
                }
        }
@@ -396,12 +416,8 @@ bool MsgProxyListener::regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, m
 
        for (; it != operationSyncMLMessageCBList.end(); it++)
        {
-               if (it->pfSyncMLOperationCB == pfSyncMLMessageOperation)
-               {
+               if (it->hAddr == pMsgHandle && it->pfSyncMLOperationCB == pfSyncMLMessageOperation) {
                        MSG_DEBUG("msg_syncml_msg_incoming_cb() callback : [%p] is already registered!!!", pfSyncMLMessageOperation);
-
-                       it->userParam = pUserParam;
-
                        return false;
                }
        }
@@ -422,12 +438,8 @@ bool MsgProxyListener::regStorageChangeEventCB(MsgHandle* pMsgHandle, msg_storag
 
        for (; it != storageChangeCBList.end(); it++)
        {
-               if (it->pfStorageChangeCB == pfStorageChangeOperation)
-               {
+               if (it->hAddr == pMsgHandle && it->pfStorageChangeCB == pfStorageChangeOperation) {
                        MSG_DEBUG("msg_storage_change_cb() callback : [%p] is already registered!!!", pfStorageChangeOperation);
-
-                       it->userParam = pUserParam;
-
                        return false;
                }
        }
@@ -444,139 +456,159 @@ void MsgProxyListener::clearListOfClosedHandle(MsgHandle* pMsgHandle)
 {
        MSG_BEGIN();
 
+       MutexLocker lock(mx);
+
        // sent status CB list
        std::list<MSG_SENT_STATUS_CB_ITEM_S>::iterator it = sentStatusCBList.begin();
 
-       for (; it != sentStatusCBList.end(); it++)
+       for (; it != sentStatusCBList.end(); )
        {
                if (it->hAddr == pMsgHandle)
                {
-                       sentStatusCBList.erase(it);
-                       it = sentStatusCBList.begin();
+                       sentStatusCBList.erase(it++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it;
        }
 
        // new message CB list
        std::list<MSG_INCOMING_CB_ITEM_S>::iterator it2 = newMessageCBList.begin();
 
-       for (; it2 != newMessageCBList.end(); it2++)
+       for (; it2 != newMessageCBList.end(); )
        {
                if (it2->hAddr == pMsgHandle)
                {
-                       newMessageCBList.erase(it2);
-                       it2 = newMessageCBList.begin();
+                       newMessageCBList.erase(it2++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it2;
        }
 
        // MMS conf Message CB list
        std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S>::iterator it3 = newMMSConfMessageCBList.begin();
 
-       for (; it3 != newMMSConfMessageCBList.end(); it3++)
+       for (; it3 != newMMSConfMessageCBList.end(); )
        {
                if (it3->hAddr == pMsgHandle)
                {
-                       newMMSConfMessageCBList.erase(it3);
-                       it3 = newMMSConfMessageCBList.begin();
+                       newMMSConfMessageCBList.erase(it3++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it3;
        }
 
        // SyncML Message CB list
        std::list<MSG_SYNCML_INCOMING_CB_ITEM_S>::iterator it4 = newSyncMLMessageCBList.begin();
 
-       for (; it4 != newSyncMLMessageCBList.end(); it4++)
+       for (; it4 != newSyncMLMessageCBList.end(); )
        {
                if (it4->hAddr == pMsgHandle)
                {
-                       newSyncMLMessageCBList.erase(it4);
-                       it4 = newSyncMLMessageCBList.begin();
+                       newSyncMLMessageCBList.erase(it4++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it4;
        }
 
        // LBS Message CB list
        std::list<MSG_LBS_INCOMING_CB_ITEM_S>::iterator it5 = newLBSMessageCBList.begin();
 
-       for (; it5 != newLBSMessageCBList.end(); it5++)
+       for (; it5 != newLBSMessageCBList.end(); )
        {
                if (it5->hAddr == pMsgHandle)
                {
-                       newLBSMessageCBList.erase(it5);
-                       it5 = newLBSMessageCBList.begin();
+                       newLBSMessageCBList.erase(it5++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it5;
        }
 
        // Push Message CB list
        std::list<MSG_PUSH_INCOMING_CB_ITEM_S>::iterator it6 = newPushMessageCBList.begin();
 
-       for (; it6 != newPushMessageCBList.end(); it6++)
+       for (; it6 != newPushMessageCBList.end(); )
        {
                if (it6->hAddr == pMsgHandle)
                {
-                       newPushMessageCBList.erase(it6);
-                       it6 = newPushMessageCBList.begin();
+                       newPushMessageCBList.erase(it6++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it6;
 
        }
 
        // CB Message CB list
        std::list<MSG_CB_INCOMING_CB_ITEM_S>::iterator it7 = newCBMessageCBList.begin();
 
-       bool bSave = false;
-       for (; it7 != newCBMessageCBList.end(); it7++)
+       for (; it7 != newCBMessageCBList.end(); )
        {
 
                if (it7->hAddr == pMsgHandle)
                {
 
-                       newCBMessageCBList.erase(it7);
-                       it7 = newCBMessageCBList.begin();
+                       newCBMessageCBList.erase(it7++);
 
                        //Stop client Listener
                        stop();
                }
                else
                {
-                       if(it7->bsave == true)
-                               bSave = true;
+                       ++it7;
                }
        }
 
-       if(!bSave)
-               if(MsgSettingSetBool(CB_SAVE, bSave) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgSettingSetBool FAIL: CB_SAVE");
 
        // Storage change Message CB list
        std::list<MSG_STORAGE_CHANGE_CB_ITEM_S>::iterator it8 = storageChangeCBList.begin();
 
-       for (; it8 != storageChangeCBList.end(); it8++)
+       for (; it8 != storageChangeCBList.end(); )
        {
                if (it8->hAddr == pMsgHandle)
                {
-                       storageChangeCBList.erase(it8);
-                       it8 = storageChangeCBList.begin();
+                       storageChangeCBList.erase(it8++);
 
                        //Stop client Listener
                        stop();
                }
+               else
+                       ++it8;
+       }
+
+
+       // Report message incoming CB list
+       std::list<MSG_REPORT_INCOMING_CB_ITEM_S>::iterator it9 = reportMessageCBList.begin();
+       for (; it9 != reportMessageCBList.end(); )
+       {
+               if (it9->hAddr == pMsgHandle)
+               {
+                       reportMessageCBList.erase(it9++);
+
+                       //Stop client Listener
+                       stop();
+               }
+               else
+                       ++it9;
        }
 
+
        MSG_END();
 }
 
@@ -618,8 +650,15 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
        }
        else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MSG_IND )
        {
-               MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)pMsgEvent->data;
-               int portKey = (pMsgInfo->msgPort.valid)? pMsgInfo->msgPort.dstPort: 0;
+               MSG_MESSAGE_INFO_S msgInfo;
+               memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+               msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+               MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
+
+               int portKey = (msgInfo.msgPort.valid)? msgInfo.msgPort.dstPort: 0;
 
                mx.lock();
 
@@ -642,7 +681,6 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
                {
                        MsgHandle* pHandle = it->hAddr;
 
-                       MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)pMsgEvent->data;
                        MSG_MESSAGE_HIDDEN_S msgHidden = {0,};
 
                        msgHidden.pData = NULL;
@@ -668,7 +706,12 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
 
                        msgHidden.addr_list = addr_list;
 
-                       pHandle->convertMsgStruct(pMsgInfo, &msgHidden);
+                       try {
+                               pHandle->convertMsgStruct(&msgInfo, &msgHidden);
+                       }
+                       catch (MsgException& e) {
+                               MSG_FATAL("%s", e.what());
+                       }
 
                        msg_struct_s msg = {0,};
                        msg.type = MSG_STRUCT_MESSAGE_INFO;
@@ -706,8 +749,16 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
        }
        else if ( pMsgEvent->eventType == MSG_EVENT_PLG_INCOMING_MMS_CONF )
        {
-               MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)pMsgEvent->data;
-               MMS_RECV_DATA_S* pMmsRecvData = ( MMS_RECV_DATA_S*)pMsgInfo->msgData;
+               MSG_MESSAGE_INFO_S msgInfo;
+               memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
+
+               msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+               MsgDecodeMsgInfo((char *)pMsgEvent->data, &msgInfo);
+
+
+               MMS_RECV_DATA_S* pMmsRecvData = ( MMS_RECV_DATA_S*)msgInfo.msgData;
 
                char* appIdKey = (pMmsRecvData->msgAppId.valid)? pMmsRecvData->msgAppId.appId: NULL;
 
@@ -738,8 +789,8 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
 
                strncpy(tempFileName, pMmsRecvData->retrievedFilePath, MSG_FILENAME_LEN_MAX);
 
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN+1);
-               memcpy(pMsgInfo->msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
+               memset(msgInfo.msgData, 0, MAX_MSG_DATA_LEN+1);
+               memcpy(msgInfo.msgData, tempFileName + strlen(MSG_DATA_PATH), MAX_MSG_DATA_LEN);
 
                it = matchList.begin();
 
@@ -747,7 +798,6 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
                {
                        MsgHandle* pHandle = it->hAddr;
 
-                       MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)pMsgEvent->data;
                        MSG_MESSAGE_HIDDEN_S msgHidden = {0,};
 
                        msgHidden.pData = NULL;
@@ -773,7 +823,12 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
 
                        msgHidden.addr_list = addr_list;
 
-                       pHandle->convertMsgStruct(pMsgInfo, &msgHidden);
+                       try {
+                               pHandle->convertMsgStruct(&msgInfo, &msgHidden);
+                       }
+                       catch (MsgException& e) {
+                               MSG_FATAL("%s", e.what());
+                       }
 
                        msg_struct_s msg = {0,};
                        msg.type = MSG_STRUCT_MESSAGE_INFO;
@@ -810,7 +865,7 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
                        if(appIdKey)
                        {
                                MSG_DEBUG("delete received JAVA MMS message:%s from native storage",tempFileName);
-                               pHandle->deleteMessage(pMsgInfo->msgId);
+                               pHandle->deleteMessage(msgInfo.msgId);
                        }
                }
        }
@@ -832,7 +887,7 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
 
                        void* param = it->userParam;
 
-                       pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, param);
+                       pfunc((msg_handle_t)pHandle, pSyncMLData->syncmlType, pSyncMLData->pushBody, pSyncMLData->pushBodyLen, pSyncMLData->wspHeader, pSyncMLData->wspHeaderLen, pSyncMLData->simIndex , param);
                }
 
                mx.unlock();
@@ -963,7 +1018,42 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
 
                        void* param = it->userParam;
 
-                       pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
+                       if(!strncmp(it->appId, pPushData->pushAppId, MAX_WAPPUSH_ID_LEN))
+                               pfunc((msg_handle_t)pHandle, pPushData->pushHeader, pPushData->pushBody, pPushData->pushBodyLen, param);
+               }
+
+               mx.unlock();
+       }
+
+       else if (pMsgEvent->eventType == MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND)
+       {
+               msg_report_type_t reportType;
+               msg_message_id_t msgId;
+               int addr_len;
+               char *addr_val;
+
+               // Decode event data
+               memcpy(&reportType, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(msg_report_type_t));
+               memcpy(&msgId, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)), sizeof(msg_message_id_t));
+               memcpy(&addr_len, (void*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)+sizeof(msg_message_id_t)), sizeof(int));
+               addr_val = (char*)((char*)pMsgEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)+sizeof(msg_report_type_t)+sizeof(msg_message_id_t)+sizeof(int));
+               addr_val[addr_len] = '\0';
+
+               MSG_DEBUG("reportType [%d], msgId [%d], Address Length [%d], Address Value [%s]", reportType, msgId, addr_len, addr_val);
+
+               mx.lock();
+
+               MsgReportMessageCBList::iterator it = reportMessageCBList.begin();
+
+               for( ; it != reportMessageCBList.end() ; it++)
+               {
+                       MsgHandle* pHandle = it->hAddr;
+
+                       msg_report_msg_incoming_cb pfunc = it->pfReportMsgIncomingCB;
+
+                       void* param = it->userParam;
+
+                       pfunc((msg_handle_t)pHandle, reportType, msgId, addr_len, addr_val, param);
                }
 
                mx.unlock();
@@ -975,10 +1065,35 @@ void MsgProxyListener::handleEvent(const MSG_EVENT_S* pMsgEvent)
 
 int  MsgProxyListener::getRemoteFd()
 {
-       int tmpFd = cliSock.getRemoteFd();
+       MSG_BEGIN();
+       //MutexLocker lock(mx);
+
+       int tmpFd = -1;
+       int ret = mx.timedlock();
+
+       if (ret != 0) {
+               MSG_DEBUG("mx.timedlock fail [%d]", ret);
+               return tmpFd;
+       }
+
+       tmpFd = cliSock.getRemoteFd();
 
        MSG_DEBUG("listener fd [%d]", tmpFd);
 
+       if( tmpFd == -1 ) {
+               ret = cv.timedwait(mx.pMutex(),1);
+       }
+
+       if (ret == ETIMEDOUT) {
+               MSG_DEBUG("get listener fd TIME-OUT");
+               return tmpFd;
+       }
+
+       tmpFd = cliSock.getRemoteFd();
+       mx.unlock();
+
+       MSG_END();
+
        return tmpFd;
 }
 
@@ -988,6 +1103,19 @@ int MsgProxyListener::readFromSocket(char** buf, unsigned int* len)
        return cliSock.read(buf, len);
 }
 
+void MsgProxyListener::resetProxyListener()
+{
+       MSG_BEGIN();
+       MutexLocker lock(mx);
+       handle_set::iterator it = openHandleSet.begin();
+       for (; it != openHandleSet.end(); it++) {
+               MsgHandle *handle = (MsgHandle *)*it;
+               clearListOfClosedHandle(handle);
+       }
+       openHandleSet.clear();
+       MSG_END();
+}
+
 #ifdef CHECK_SENT_STATUS_CALLBACK
 int MsgProxyListener::getSentStatusCbCnt()
 {
diff --git a/sysinfo-message.emul.xml b/sysinfo-message.emul.xml
deleted file mode 100755 (executable)
index e26ebf0..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0"?>
-<sys-info>
-       <default>
-               <key id="mms-support" string="true"/>
-               <key id="cbs-support" string="false"/>
-       </default>
-</sys-info>
index cf2905f..ff95ea7 100755 (executable)
@@ -22,29 +22,28 @@ SET(UTILS-SRCS
        ${CMAKE_SOURCE_DIR}/utils/MsgIpcSocket.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgUtilFile.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgSqliteWrapper.cpp
-       ${CMAKE_SOURCE_DIR}/utils/MsgSoundPlayer.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgUtilStorage.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgGconfWrapper.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgContact.cpp
-       ${CMAKE_SOURCE_DIR}/utils/MsgNotificationWrapper.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgVMessage.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgMemory.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgMmsMessage.cpp
-       ${CMAKE_SOURCE_DIR}/utils/MsgSpamFilter.cpp
        ${CMAKE_SOURCE_DIR}/utils/MsgDrmWrapper.cpp
+       ${CMAKE_SOURCE_DIR}/utils/MsgJsonParser.cpp
+       ${CMAKE_SOURCE_DIR}/utils/MsgSerialize.cpp
+       ${CMAKE_SOURCE_DIR}/utils/MsgSmil.cpp
 )
 
 INCLUDE_DIRECTORIES(
-    ${CMAKE_SOURCE_DIR}/include/mapi
+       ${CMAKE_SOURCE_DIR}/include/mapi
        ${CMAKE_SOURCE_DIR}/include/common
        ${CMAKE_SOURCE_DIR}/include/framework
-       ${CMAKE_SOURCE_DIR}/include/msg_helper
        ${CMAKE_SOURCE_DIR}/include/utils
        ${CMAKE_SOURCE_DIR}/vobject-engine/include
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(utils_pkgs REQUIRED glib-2.0 vconf db-util contacts-service2 dlog pmapi mm-session alarm-service notification drm-client appsvc)
+pkg_check_modules(utils_pkgs REQUIRED glib-2.0 vconf db-util contacts-service2 dlog libxml-2.0 storage json-glib-1.0)
 
 FOREACH(flag ${utils_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -52,7 +51,6 @@ ENDFOREACH(flag)
 
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DFEATURE_JAVA_MMS")
-ADD_DEFINITIONS("-D__SUPPORT_DRM__")
 
 SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
@@ -61,5 +59,5 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 ADD_LIBRARY(${UTILS-LIB} SHARED ${UTILS-SRCS})
 TARGET_LINK_LIBRARIES(${UTILS-LIB} ${utils_pkgs_LDFLAGS} rt ${VOBJECT-LIB})
 
-INSTALL(TARGETS ${UTILS-LIB} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${UTILS-LIB} DESTINATION lib COMPONENT RuntimeLibraries)
 
index 56518f5..1b14b61 100755 (executable)
@@ -1,30 +1,31 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
-extern "C"
-{
-       #include <contacts.h>
-}
+#include <ctype.h>
 
 #include "MsgDebug.h"
-#include "MsgIpcSocket.h"
 #include "MsgUtilStorage.h"
+#include "MsgUtilFile.h"
 #include "MsgGconfWrapper.h"
 #include "MsgContact.h"
 
+extern "C"
+{
+       #include <contacts.h>
+}
 
 /*==================================================================================================
                                      VARIABLES
@@ -34,50 +35,212 @@ __thread bool isContactSvcConnected = false;
 MsgDbHandler ContactDbHandle;
 
 MsgContactChangeCB cbFunction = NULL;
-/*==================================================================================================
-                                     FUNCTION IMPLEMENTATION
-==================================================================================================*/
-static void MsgContactSvcCallback(const char *view_uri, void *user_data)
-{
-       MSG_DEBUG("Contact Data is Changed!!!");
-
-       // establish connection to msgfw daemon
-       MsgIpcClientSocket client;
-       client.connect(MSG_SOCKET_PATH);
-
-       // composing command
-       int cmdSize = sizeof(MSG_CMD_S); // cmd type
 
-       char cmdBuf[cmdSize];
-       bzero(cmdBuf, cmdSize);
+#define CONTACT_CALLBACK_USER_DATA                             "contact"
+#define ADDRESSBOOK_CALLBACK_USER_DATA "addressbook"
 
-       MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
+// phonenumber minimum match digit.
+#define PHONENUMBER_MIN_MATCH_DIGIT VCONFKEY_CONTACTS_SVC_PHONENUMBER_MIN_MATCH_DIGIT
+#define DEFAULT_MIN_MATCH_DIGIT 8
 
-       // Set Command Parameters
-       pCmd->cmdType = MSG_CMD_CONTACT_SYNC;
+static int phonenumberMinMatchDigit = -1;
 
-       memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
+/*==================================================================================================
+                                     INTERNAL FUNCTION IMPLEMENTATION
+==================================================================================================*/
+int countryCodeLength(const char *src)
+{
+       int ret = 0;
+       switch (src[ret++]-'0')
+       {
+       case 1:
+       case 7:
+               break;
+       case 2:
+               switch (src[ret++]-'0')
+               {
+               case 0:
+               case 7:
+                       break;
+               case 1:
+               case 2:
+               case 3:
+               case 4:
+               case 5:
+               case 6:
+               case 8:
+               case 9:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 3:
+               switch (src[ret++]-'0')
+               {
+               case 0:
+               case 1:
+               case 2:
+               case 3:
+               case 4:
+               case 6:
+               case 9:
+                       break;
+               case 5:
+               case 7:
+               case 8:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 4:
+               switch (src[ret++]-'0')
+               {
+               case 0:
+               case 1:
+               case 3:
+               case 4:
+               case 5:
+               case 6:
+               case 7:
+               case 8:
+               case 9:
+                       break;
+               case 2:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 5:
+               switch (src[ret++]-'0')
+               {
+               case 1:
+               case 2:
+               case 3:
+               case 4:
+               case 5:
+               case 6:
+               case 7:
+               case 8:
+                       break;
+               case 0:
+               case 9:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 6:
+               switch (src[ret++]-'0')
+               {
+               case 0:
+               case 1:
+               case 2:
+               case 3:
+               case 4:
+               case 5:
+               case 6:
+                       break;
+               case 7:
+               case 8:
+               case 9:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 8:
+               switch (src[ret++]-'0')
+               {
+               case 1:
+               case 2:
+               case 4:
+               case 6:
+                       break;
+               case 0:
+               case 3:
+               case 5:
+               case 7:
+               case 8:
+               case 9:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 9:
+               switch (src[ret++]-'0')
+               {
+               case 0:
+               case 1:
+               case 2:
+               case 3:
+               case 4:
+               case 5:
+               case 8:
+                       break;
+               case 6:
+               case 7:
+               case 9:
+                       ret += 1;
+                       break;
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               }
+               break;
+       case 0:
+       default:
+               MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+               return 0;
+       }
 
-       // Send Command to Transaction Manager
-       client.write(cmdBuf, cmdSize);
+       return ret;
+}
 
-       // Receive result from Transaction Manager
-       char *temp = NULL;
-       AutoPtr<char> wrap(&temp);
-       unsigned int len;
-       client.read(&temp, &len);
 
-       // close connection to msgfw daemon
-       client.close();
+void normalizeNumber(const char *orig, char* dest, unsigned int destSize)
+{
+       unsigned int pos = 0;
+       for (unsigned int i=0; (orig[i] && i<destSize); i++) {
+               if (isdigit(orig[i]) || (orig[i] == '+')) {
+                       dest[pos++] = orig[i];
+               }
+       }
 }
 
 
+//static void MsgContactSvcCallback(const char *view_uri, void *user_data)
+//{
+//     MSG_DEBUG("MsgContactSvcCallback is called.");
+//     if (!strcmp(CONTACT_CALLBACK_USER_DATA, (const char*)user_data)) {
+//             MSG_DEBUG("Contact Data is Changed!!!");
+//             MsgSyncContact();
+//     } else if (!strcmp(ADDRESSBOOK_CALLBACK_USER_DATA, (const char*)user_data)) {
+//             MSG_DEBUG("Address Book Data is Changed!!!");
+//             MsgSyncAddressbook();
+//     }
+//
+//     if (ContactDbHandle.disconnect() != MSG_SUCCESS)
+//             MSG_DEBUG("DB Disconnect Fail");
+//}
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
 msg_error_t MsgOpenContactSvc()
 {
        int errCode = CONTACTS_ERROR_NONE;
 
        if (!isContactSvcConnected) {
-               errCode = contacts_connect2();
+               errCode = contacts_connect();
 
                if (errCode == CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("Connect to Contact Service Success");
@@ -100,10 +263,11 @@ msg_error_t MsgCloseContactSvc()
        int errCode = CONTACTS_ERROR_NONE;
 
        if (isContactSvcConnected) {
-               errCode = contacts_disconnect2();
+               errCode = contacts_disconnect();
 
                if (errCode == CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("Disconnect to Contact Service Success");
+                       isContactSvcConnected = false;
                } else {
                        MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
                        return MSG_ERR_DB_DISCONNECT;
@@ -116,15 +280,25 @@ msg_error_t MsgCloseContactSvc()
 
 msg_error_t MsgInitContactSvc(MsgContactChangeCB cb)
 {
-       msg_error_t err = MSG_SUCCESS;
+//     msg_error_t err = MSG_SUCCESS;
+//     unsigned int retryCnt = 10;
+
+       if (cb != NULL)
+               cbFunction = cb;
 
-       unsigned int retryCnt = 100;
+       phonenumberMinMatchDigit = MsgSettingGetInt(PHONENUMBER_MIN_MATCH_DIGIT);
+       MSG_DEBUG("phonenumberMinMatchDigit [%d]", phonenumberMinMatchDigit);
 
+       if (phonenumberMinMatchDigit < 1) {
+               phonenumberMinMatchDigit = DEFAULT_MIN_MATCH_DIGIT;
+       }
+
+#if 0
        do {
                if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
                        retryCnt--;
                        MSG_DEBUG("MsgOpenContactSvc fail. Retry count left [%d]", retryCnt);
-                       usleep(500 * 1000);
+                       usleep(100 * 1000);
                }
        } while (err != MSG_SUCCESS && retryCnt > 0);
 
@@ -133,18 +307,31 @@ msg_error_t MsgInitContactSvc(MsgContactChangeCB cb)
                return MSG_ERR_UNKNOWN;
        }
 
+       // Sync contact first.
+       MsgSyncAddressbook();
+//     MsgSyncContact();
+
        int errCode = CONTACTS_ERROR_NONE;
 
-       if (cb != NULL)
-               cbFunction = cb;
+       // Register callback function
+       errCode = contacts_db_add_changed_cb(_contacts_contact._uri, MsgContactSvcCallback, (void *)CONTACT_CALLBACK_USER_DATA);
+
+       if (errCode == CONTACTS_ERROR_NONE)
+               MSG_DEBUG("Register Contact Service Callback [_contacts_contact]");
+       else
+               MSG_DEBUG("Fail to Register Contact Service Callback [_contacts_contact] [%d]", errCode);
 
        // Register callback function
-       errCode = contacts_db_add_changed_cb(_contacts_contact._uri, MsgContactSvcCallback, NULL);
+       errCode = contacts_db_add_changed_cb(_contacts_address_book._uri, MsgContactSvcCallback, (void *)ADDRESSBOOK_CALLBACK_USER_DATA);
 
        if (errCode == CONTACTS_ERROR_NONE)
-               MSG_DEBUG("Register Contact Service Callback");
+               MSG_DEBUG("Register Contact Service Callback [_contacts_address_book]");
        else
-               MSG_DEBUG("Fail to Register Contact Service Callback [%d]", errCode);
+               MSG_DEBUG("Fail to Register Contact Service Callback [_contacts_address_book] [%d]", errCode);
+
+       if (ContactDbHandle.disconnect() != MSG_SUCCESS)
+                       MSG_DEBUG("DB Disconnect Fail");
+#endif
 
        return MSG_SUCCESS;
 }
@@ -166,18 +353,18 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                return MSG_ERR_UNKNOWN;
        }
 
-       MSG_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
+       MSG_SEC_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
 
        memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
 
        if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
                MSG_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
-               return MSG_SUCCESS;
+               return MSG_ERR_UNKNOWN;
        }
 
        int ret = 0;
        int index = 0;
-       unsigned int count = 0;
+       int count = 0;
        contacts_query_h query = NULL;
        contacts_filter_h filter = NULL;
        contacts_list_h contacts = NULL;
@@ -186,7 +373,7 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                ret = contacts_query_create(_contacts_contact_number._uri, &query);
                ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
 
-               ret = contacts_filter_add_str(filter, _contacts_contact_number.number, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
+               ret = contacts_filter_add_str(filter, _contacts_contact_number.number_filter, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
 
        } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
                ret = contacts_query_create(_contacts_contact_email._uri, &query);
@@ -196,7 +383,7 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
 
        } else {
                MSG_DEBUG("Invalid pAddrInfo->addressType.");
-               return MSG_SUCCESS;
+               return MSG_ERR_UNKNOWN;
        }
 
        ret = contacts_query_set_filter(query, filter);
@@ -206,7 +393,7 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                contacts_query_destroy(query);
                contacts_filter_destroy(filter);
                contacts_list_destroy(contacts, true);
-               return MSG_SUCCESS;
+               return MSG_ERR_UNKNOWN;
        }
 
        ret = contacts_list_get_count(contacts, &count);
@@ -231,22 +418,21 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       return MSG_SUCCESS;
+                       return MSG_ERR_UNKNOWN;
                }
 
                ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       return MSG_SUCCESS;
+                       return MSG_ERR_UNKNOWN;
                }
 
                ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       contacts_record_destroy(contact, true);
-                       return MSG_SUCCESS;
+                       return MSG_ERR_UNKNOWN;
                }
        } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
                contacts_record_h email = NULL;
@@ -255,27 +441,27 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       return MSG_SUCCESS;
+                       return MSG_ERR_UNKNOWN;
                }
 
                ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       return MSG_SUCCESS;
+                       return MSG_ERR_UNKNOWN;
                }
 
                ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       contacts_record_destroy(contact, true);
-                       return MSG_SUCCESS;
+                       return MSG_ERR_UNKNOWN;
                }
        }
 
        contacts_list_destroy(contacts, true);
 
+#if 0
        // Name Info
        contacts_record_h name = NULL;
 
@@ -283,58 +469,156 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
        } else {
-               char* strFirstName = NULL;
-               ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
+               char* strName = NULL;
+               ret = contacts_record_get_str_p(name, _contacts_name.first, &strName);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(pContactInfo->firstName, strName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
 
-               char* strLastName = NULL;
-               ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
+               ret = contacts_record_get_str_p(name, _contacts_name.last, &strName);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(pContactInfo->lastName, strName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
 
-               char* strDisplayName = NULL;
-               ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &strDisplayName);
+               ret = contacts_record_get_str_p(name, _contacts_name.addition, &strName);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(pContactInfo->middleName, strName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
 
-               if (strFirstName != NULL)
-                       strncpy(pContactInfo->firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
-
-               if (strLastName != NULL)
-                       strncpy(pContactInfo->lastName, strLastName, MAX_DISPLAY_NAME_LEN);
+               ret = contacts_record_get_str_p(name, _contacts_name.prefix, &strName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(pContactInfo->prefix, strName, MAX_DISPLAY_NAME_LEN);
+                       }
+               }
 
-               if (strDisplayName != NULL)
-                       strncpy(pContactInfo->displayName, strDisplayName, MAX_DISPLAY_NAME_LEN);
+               ret = contacts_record_get_str_p(name, _contacts_name.suffix, &strName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(pContactInfo->suffix, strName, MAX_DISPLAY_NAME_LEN);
+                       }
+               }
        }
-
-       MSG_DEBUG("pContactInfo->firstName : [%s], pContactInfo->lastName : [%s]", pContactInfo->firstName, pContactInfo->lastName);
-       MSG_DEBUG("pContactInfo->displayName : [%s]", pContactInfo->displayName);
+#endif
 
        ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
                contacts_record_destroy(contact, true);
-               return MSG_SUCCESS;
+               return MSG_ERR_UNKNOWN;
        }
 
        MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
 
+       ret = contacts_record_get_int(contact, _contacts_contact.address_book_id, (int*)&pContactInfo->addrbookId);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
+               contacts_record_destroy(contact, true);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       MSG_DEBUG("Address Book ID [%d]", pContactInfo->addrbookId);
+
        char* strImagePath = NULL;
        ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return MSG_SUCCESS;
        }
-
-       if (strImagePath != NULL)
+       if (strImagePath != NULL) {
                strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
+               MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
+       }
+
+       char* alerttonePath = NULL;
+       ret = contacts_record_get_str_p(contact, _contacts_contact.message_alert, &alerttonePath);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+       }
+
+       if (MsgAccessFile(alerttonePath, F_OK) == false) {
+               alerttonePath = NULL;
+       }
+
+       if (alerttonePath != NULL) {
+               MSG_DEBUG("alert tone Path [%s]", alerttonePath);
+               strncpy(pContactInfo->alerttonePath , alerttonePath, MSG_FILEPATH_LEN_MAX);
+       } else {
+               MSG_DEBUG("alert tone Path for this contact is default");
+               count = 0;
+               ret = contacts_record_get_child_record_count(contact, _contacts_contact.group_relation, &count);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
+               }
+
+               contacts_record_h group_relation_record;
+
+               for (int i = 0; i < count; i++) {
+                       int group_id = 0;
+                       contacts_record_get_child_record_at_p(contact, _contacts_contact.group_relation, i, &group_relation_record);
+                       contacts_record_get_int(group_relation_record, _contacts_group_relation.group_id, &group_id);
+
+                       contacts_record_h group_record;
+                       contacts_db_get_record(_contacts_group._uri, group_id, &group_record);
+
+                       MSG_DEBUG("Group ID = [%d]", group_id);
+
+                       char *group_ringtone_path;
+                       ret = contacts_record_get_str_p(group_record, _contacts_group.message_alert, &group_ringtone_path);
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
+                       } else {
+                               if (group_ringtone_path) {
+                                       MSG_DEBUG("Msg alert_tone is change to [%s] as contact group", group_ringtone_path);
+                                       memset(pContactInfo->alerttonePath, 0x00, sizeof(pContactInfo->alerttonePath));
+                                       snprintf(pContactInfo->alerttonePath, sizeof(pContactInfo->alerttonePath), "%s", group_ringtone_path);
+                                       contacts_record_destroy(group_record, true);
+                                       break;
+                               }
+                       }
+                       contacts_record_destroy(group_record, true);
+               }
+       }
+
+       char* vibrationPath = NULL;
+       ret = contacts_record_get_str_p(contact, _contacts_contact.vibration, &vibrationPath);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+       }
+       if (vibrationPath != NULL) {
+               MSG_DEBUG("vibration Path [%s]", vibrationPath);
+               strncpy(pContactInfo->vibrationPath , vibrationPath, MSG_FILEPATH_LEN_MAX);
+       }
 
-       MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
+       char* displayName = NULL;
+       ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &displayName);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+       }
+       if (displayName != NULL) {
+               MSG_DEBUG("displayName [%s]", displayName);
+               strncpy(pContactInfo->firstName , displayName, MAX_DISPLAY_NAME_LEN);
+       }
 
        contacts_record_destroy(contact, true);
 
@@ -344,10 +628,178 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
 }
 
 
+msg_error_t MsgGetContactSearchList(const char *pSearchVal, MSG_ADDRESS_INFO_S **pAddrInfo, int *count)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+#if 1
+       *count = 0;
+
+
+       if (pSearchVal == NULL) {
+               MSG_DEBUG("pSearchVal is NULL.");
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       if (pAddrInfo == NULL) {
+               MSG_DEBUG("pAddrInfo is NULL.");
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgOpenContactSvc fail.");
+               return err;
+       }
+
+       if (!isContactSvcConnected) {
+               MSG_DEBUG("Contact Service Not Opened.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+       MSG_SEC_DEBUG("pSearchVal [%s]", pSearchVal);
+
+
+       int ret = 0;
+       unsigned int index = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h personNumbers = NULL;
+
+       ret = contacts_query_create(_contacts_person_number._uri, &query);
+       ret = contacts_filter_create(_contacts_person_number._uri, &filter);
+
+       ret = contacts_filter_add_str(filter, _contacts_person_number.display_name, CONTACTS_MATCH_CONTAINS, pSearchVal);
+
+       ret = contacts_query_set_filter(query, filter);
+
+       ret = contacts_db_get_records_with_query(query, 0, 0, &personNumbers);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
+               contacts_query_destroy(query);
+               contacts_filter_destroy(filter);
+               contacts_list_destroy(personNumbers, true);
+               return MSG_ERR_UNKNOWN;
+       }
+
+       ret = contacts_list_get_count(personNumbers, count);
+       if (*count == 0 || ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("No Serach Data from Contact Service.");
+               *count = 0;
+               contacts_query_destroy(query);
+               contacts_filter_destroy(filter);
+               contacts_list_destroy(personNumbers, true);
+               return MSG_SUCCESS;
+       }
+
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+
+       MSG_DEBUG(" *count [%d]", *count);
+
+       *pAddrInfo = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * (*count)];
+       memset(*pAddrInfo, 0x00, (sizeof(MSG_ADDRESS_INFO_S) * (*count)));
+
+       contacts_record_h personNumber = NULL;
+
+       while (CONTACTS_ERROR_NONE == contacts_list_get_current_record_p(personNumbers, &personNumber)) {
+               char* normalizedNumber = NULL;
+               ret = contacts_record_get_str(personNumber, _contacts_person_number.normalized_number, &normalizedNumber);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
+               }
+               else if (normalizedNumber) {
+                       MSG_DEBUG("normalizedNumber [%s]", normalizedNumber);
+                       strncpy((*pAddrInfo)[index].addressVal, normalizedNumber, MAX_ADDRESS_VAL_LEN);
+               }
+
+               contacts_list_next(personNumbers);
+               index++;
+       }
+
+       contacts_list_destroy(personNumbers, true);
+#else
+       char normalizedList[1392][MAX_ADDRESS_VAL_LEN] = {"2526",  "46219",  "26519",  "6348",  "553",  "18338",  "97638",  "7592",  "2864",  "43915",  "40315",  "38690",  "3733",  "3458468",  "9997749",  "4259",  "374933",  "28711",  "95911",  "+8217337371517",  "+8264031191305",  "+8267404687926",  "+8273855995243",  "57215",  "65215",  "42116",  "28816",  "34216",  "44716",  "47812",  "65013",  "+8250098295075",  "+8274904233875",  "59011",  "84011",  "39317",  "92917",  "+8239949736984",  "+8229194495802",  "75216",  "14016",  "+8221481345276",  "+8216051855922",  "31117",  "43217",  "87918",  "62719",  "82415",  "17715",  "+8229405745",  "+8290415739",  "9584",  "7282",  "95519",  "36619",  "+823090649743",  "+82925579776",  "63012",  "71412",  "87217",  "20817",  "75419",  "44619",  "79419",  "27619",  "14012",  "63311",  "+8276033840",  "+8243243723",  "+8292360488413",  "+8255869510999",  "5462191",  "1314166",  "+82793045968",  "+82495134965",  "8316950",  "1209398",  "80111",  "96911",  "92120",  "69420",  "65818",  "69918",  "12301",  "29223",  "+8227044567780",  "26911",  "11011",  "23011",  "+82996462414",  "+821680532094",  "15411",  "27011",  "94916",  "57216",  "54719",  "25719",  "+8290240454",  "+8224503765",  "7796644",  "8915677",  "25617",  "17817",  "+8249088354",  "+8237361881",  "57319",  "82219",  "5508614",  "6887937",  "+82980906028",  "+8271024245",  "406141",  "31829",  "39514",  "87714",  "+8248476782",  "+8278819385",  "+827981191814",  "+823914017278",  "18915",  "43215",  "61716",  "88916",  "+8255191142137",  "+8244630854869",  "26418",  "60517",  "68717",  "54117",  "+8299123956",  "+8260637614",  "9401290",  "8022740",  "82511",  "86311",  "31711",  "89012",  "90715",  "91315",  "17012",  "61712",  "11811",  "50911",  "32817",  "69519",  "64415",  "77415",  "46837",  "35538",  "87513",  "50613",  "93117",  "94816",  "+822291427810",  "+829324638361",  "19016",  "81416",  "+8211909528",  "+8288990196",  "69514",  "40414",  "+8289849075",  "+82278537842",  "48815",  "81416",  "+8298262306792",  "+821880316127",  "16517",  "28917",  "96338",  "92439",  "+8217452702608",  "+8286509354634",  "+823684370979",  "+823691413448",  "14817",  "71817",  "+821230827018",  "+821609314661",  "+82787483813",  "+82917742541",  "98315",  "69915",  "64713",  "88713",  "23711",  "55911",  "+8268861590119",  "+8231709783226",  "99017",  "94217",  "18017",  "13217",  "82520",  "62920",  "+826492467497",  "+82646061417",  "+824218558925",  "+823119176486",  "81314",  "76714",  "4989314",  "2058683",  "14911",  "71711",  "14512",  "97812",  "+8219703855",  "+8293486876",  "81719",  "94419",  "+822546447866",  "+828708383609",  "52511",  "75211",  "+821120535186",  "+828782686796",  "9638",  "5429",  "36719",  "47119",  "+829785315464",  "64678",  "+821012345678",  "44314",  "43815",  "+8213068686114",  "+8280153344165",  "+8299708736",  "+8246172926",  "48517",  "94617",  "+82755102394",  "+82587757352",  "68185",  "96776",  "3029937",  "2463011",  "+8274651118",  "+82601523118",  "+82216338893",  "+82949043956",  "+8273120998277",  "+8219252992008",  "89213",  "62613",  "18211",  "15911",  "63015",  "59715",  "71014",  "25315",  "97317",  "65217",  "74517",  "56117",  "+829194948040",  "+824775034145",  "+82886209811",  "+8260978479",  "790289",  "618573",  "+8266462133",  "+8299329105",  "32117",  "24417",  "+824359919984",  "+8270978755155",  "90638",  "35976",  "86716",  "56816",  "17012",  "59213",  "4779261",  "3329267",  "34316",  "10616",  "+821573398266",  "+821268628353",  "58918",  "89518",  "62860",  "36887",  "83012",  "26212",  "81339",  "13639",  "+8274564498",  "+8216567105",  "13816",  "63016",  "12818",  "41718",  "443",  "7859",  "83013",  "22813",  "+826084710076",  "+821195963402",  "6021263",  "3536442",  "26013",  "39814",  "59812",  "23712",  "+8292050953236",  "+8268131788252",  "70411",  "62011",  "55914",  "52214",  "+8233459642",  "+8248429503",  "1617",  "9383",  "+8269920795614",  "+8228322701094",  "+8261961963",  "+8219396290",  "97295",  "22229",  "78515",  "74415",  "86816",  "92116",  "61213",  "41116",  "+8276112995",  "+8296535172",  "53118",  "78018",  "+824940,6#*",  "17215",  "91615",  "+82954768368",  "+822108381957",  "+8210655403",  "+8255894435",  "44214",  "23214",  "62120",  "38220",  "20670",  "74340",  "41014",  "86714",  "90712",  "86912",  "11315",  "57614",  "275183",  "889838",  "72314",  "77114",  "19316",  "67116",  "8049644",  "7483031",  "27314",  "44814",  "+82126938495",  "+82466585402",  "22912",  "31412",  "90014",  "50614",  "21111",  "44911",  "+82645605129",  "+82395235329",  "60820",  "11420",  "49800",  "63739",  "20344",  "50501",  "978463",  "471273",  "+82319091138",  "+82308506062",  "88418",  "59318",  "+82501623815",  "+82416693717",  "+82451451008",  "+82848638081",  "97317",  "82017",  "71611",  "84711",  "88018",  "93718",  "79716",  "55017",  "+82605623719",  "+82812525004",  "73739",  "86939",  "49018",  "40818",  "+8219532423",  "+8236915149",  "66414",  "58816",  "+822524147489",  "+828469059109",  "52311",  "41211",  "58613",  "42413",  "5801280",  "7379393",  "49711",  "90411",  "93011",  "81711",  "72213",  "58013",  "69213",  "78413",  "58811",  "64311",  "+822972330864",  "+8284941313343",  "9082712",  "1558090",  "19012",  "85912",  "613949",  "635601",  "86911",  "32011",  "687851",  "866074",  "75839",  "97139",  "+8233304124",  "1071221",  "17116",  "56416",  "93615",  "75915",  "91817",  "75115",  "80915",  "535953",  "+82013980358",  "+828101279518",  "18057",  "93097",  "41411",  "24011",  "99111",  "85712",  "+8258718200",  "+8238686794",  "+8264757584634",  "+8276816413423",  "+82447656628",  "+8251787518",  "13918",  "82018",  "+82722717863",  "+82817629417",  "133125",  "835403",  "+8219374168592",  "+8279699853952",  "50500",  "61042",  "+82147126972",  "+825473959852",  "72518",  "26518",  "55519",  "94119",  "3225486",  "8482265",  "+82306864676",  "+491751873129",  "+491703316378",  "+4916090154364",  "+4917025802580",  "+823535325335",  "+8284867562929",  "+8261591944741",  "58018",  "65618",  "50017",  "63115",  "89614",  "46015",  "48217",  "20016",  "+8286878337676",  "+828742402419",  "84318",  "96918",  "+8271990882",  "82436967",  "33711",  "64011",  "18411",  "62411",  "6994949",  "4048476",  "63012",  "21013",  "29213",  "78160",  "+82565819428",  "+82198013777",  "42317",  "27617",  "30814",  "51214",  "28111",  "86411",  "79813",  "32413",  "843155",  "381028",  "92315",  "96415",  "65318",  "26418",  "51118",  "86218",  "+8279187903",  "+8286876672",  "47612",  "5796",  "+8279564684616",  "+8231235212122",  "518414",  "76649",  "53434",  "1106",  "27619",  "53019",  "39719",  "89519",  "+82278386060906727",  "24339",  "97938",  "21112",  "24012",  "96614",  "47914",  "59917",  "64717",  "53319",  "99919",  "89417",  "74217",  "99716",  "58415",  "89913",  "26213",  "921",  "9810",  "+823936355066",  "+825612279752",  "84012",  "74212",  "27114",  "57714",  "+823732495824",  "+827362335718",  "19817",  "55817",  "0525800",  "+821234561237",  "82911",  "11811",  "30513",  "97614",  "+8210158861",  "+8243734461",  "18011",  "52911",  "+8294355593",  "+8295601967",  "9823598",  "8150063",  "41012",  "38812",  "80317",  "80817",  "642953",  "874829",  "+8279330559195",  "+8268242833982",  "71318",  "54718",  "10511",  "58511",  "+82704156709",  "+826564840488",  "+827331959376",  "+824194242050",  "42918",  "12018",  "12113",  "87613",  "+82102321541",  "+823396244622",  "+82508855751",  "+823135715107",  "+828073751118",  "202849",  "4220030",  "+8248010940",  "+8225408845",  "80516",  "26916",  "38318",  "28486",  "80316",  "96716",  "67113",  "72913",  "+824963986503",  "+8284643338215",  "94111",  "67711",  "97816",  "57616",  "36813",  "89513",  "382463",  "136401",  "+823412789347",  "+827464191528",  "625645",  "86914",  "4403892",  "3879982",  "84919",  "81019",  "1330191",  "+8277397895",  "93519",  "42619",  "84207",  "143262",  "+8239266358243",  "+8214958435006",  "96439",  "19139",  "678675",  "251374",  "+82264804094",  "+8289228529",  "6523710",  "4397914",  "410391",  "947372",  "499201",  "652852",  "427025",  "816093",  "55919",  "73519",  "+828392923031",  "+823114620220",  "70615",  "98015",  "16605",  "58763",  "58799",  "57790",  "78813",  "73913",  "41118",  "41818",  "2764484",  "8729071",  "46217",  "75317",  "81611",  "92911",  "4397",  "8371",  "29515",  "37015",  "83919",  "52219",  "3072",  "632356",  "+82251287038",  "+82997882416",  "96019",  "34419",  "38311",  "62911",  "8013",  "7627",  "53513",  "51614",  "88115",  "31714",  "16011",  "48411",  "30411",  "69411",  "+826495959595",  "10639",  "19539",  "+82352361770",  "+82702376062",  "88216",  "81216",  "72912",  "40312",  "+8250088294681",  "+821868849568",  "18616",  "50614",  "72416",  "19416",  "59991",  "70687",  "45313",  "19513",  "93917",  "34317",  "84214",  "88914",  "+8231825904",  "+8216082601",  "33714",  "87914",  "35219",  "72618",  "41917",  "20117",  "+82126150423",  "+821646082839",  "6255246",  "7760569",  "91016",  "11017",  "11017",  "19517",  "94620",  "80585",  "20611",  "98611",  "15713",  "55813",  "52912",  "62312",  "88442",  "17545",  "46038",  "86138",  "52839",  "85239",  "124005",  "905122",  "17017",  "62217",  "36815",  "71515",  "995946",  "38677",  "48917",  "50617",  "+8292281309109",  "+8289089750928",  "42519",  "66119",  "3073",  "397755",  "86112",  "28413",  "+8233267996",  "+8247851978",  "680148",  "9627970",  "+8266991919",  "+826219568413",  "+821257934291",  "26211",  "60311",  "10014",  "80413",  "33215",  "65915",  "8394",  "8035",  "26513",  "78413",  "45214",  "15713",  "30312",  "18512",  "54116",  "42616",  "+8286083723565",  "+8252775127436",  "24914",  "19514",  "2821873",  "3862845",  "77514",  "53014",  "65211",  "63611",  "18511",  "36811",  "32013",  "90613",  "+8276813393017",  "+8249751161459",  "72814",  "61215",  "8905",  "57622",  "62618",  "97118",  "38988",  "41462",  "+8264570842963",  "+8286362179818",  "99113",  "88013",  "50219",  "68119",  "+8232327452113",  "+8286615550113",  "27914",  "82214",  "68014",  "96014",  "9299480",  "2412859",  "92638",  "90538",  "22988",  "33313",  "82213",  "+82215862255",  "+82215862255",  "+82215862255",  "23612",  "35512",  "66912",  "77512",  "4092487",  "3070423",  "5122487",  "1811089",  "2206",  "3616",  "23519",  "20619",  "3006889",  "7347356",  "+822157465370",  "+82609525051",  "26515",  "54715",  "67913",  "41914",  "+82242259220",  "+82705118973",  "74014",  "33614",  "50839",  "11738",  "+8230914801552",  "22411",  "+82765551905",  "+82313328497",  "25918",  "83118",  "77418",  "84218",  "+82239238003",  "+82241166546",  "22611",  "46311",  "40016",  "30316",  "97787",  "98278",  "16318",  "89018",  "10613",  "24812",  "64514",  "78514",  "41111",  "13211",  "7617",  "3338",  "22514",  "94414",  "15339",  "84638",  "82519",  "10518",  "85019",  "59319",  "4500542",  "6895170",  "7372656",  "2108413",  "61815",  "22215",  "17815",  "72915",  "10816",  "41116",  "5219886",  "316473",  "467974",  "997194",  "22915",  "86615",  "+826005480227",  "+82980095651",  "+8287157132045",  "+8263555310243",  "+8269451512043",  "+8285094219125",  "+82554662624",  "+823742842858",  "69412",  "63111",  "487357",  "349084",  "88719",  "61219",  "55815",  "95415",  "14817",  "90117",  "79218",  "81218",  "51838",  "11438",  "73314",  "60314",  "832002",  "265937",  "57813",  "32014",  "53116",  "34116",  "+823163543300",  "+826615634432",  "22412",  "70212",  "+823982981110",  "+821836194724",  "84213",  "94813",  "59118",  "55918",  "+82424347979790909",  "73814",  "17914",  "61339",  "28139",  "792947",  "552063",  "+824940458674",  "+8275123745874",  "16114",  "57214",  "+82228956179",  "+82714924797",  "95916",  "67816",  "72718",  "23717",  "90314",  "19214",  "401125",  "177325",  "+8277176129674",  "+8242446349456",  "38339",  "92039",  "+8242983800477",  "+8227804537889",  "90349",  "1142",  "98539",  "70939",  "+82643125754",  "+821000100010",  "+8227890219",  "+8233622994",  "+823394681779",  "+822366263047",  "48013",  "25513",  "29613",  "64013",  "65217",  "58517",  "13114",  "55314",  "70719",  "81819",  "36517",  "63718",  "15617",  "73517",  "68815",  "58615",  "41214",  "25015",  "66415",  "52815",  "81011",  "19011",  "56611",  "61911",  "83317",  "34417",  "25814",  "30814",  "871231",  "743466",  "+8298831238",  "+8292336456",  "45818",  "32218",  "81218",  "22718",  "63218",  "62618",  "6891984",  "7274853",  "63416",  "85916",  "41612",  "78012",  "71215",  "92715",  "81916",  "18016",  "81714",  "34714",  "54113",  "51413",  "72217",  "89317",  "99517",  "30717",  "+8283972194",  "+8244403522",  "20618",  "65317",  "59417",  "10917",  "47619",  "91819",  "+8216148408599",  "+8293348404188",  "+82923142257",  "+82201176551",  "99311",  "+8276672221870",  "98946",  "32414",  "36314",  "20112",  "13112",  "89415",  "94315",  "6753655",  "+8271756114",  "+8280682245",  "59013",  "42514",  "3104",  "78705",  "+82188662976",  "8454865",  "29093",  "27857",  "41112",  "12812",  "+827708708544",  "33617",  "42417",  "78716",  "77015",  "32613",  "72114",  "54738",  "30938",  "7242032",  "2778225",  "58514",  "99214",  "84139",  "63239",  "+823882970360",  "+829593642287",  "61618",  "44118",  "+82161166681",  "+82810033445",  "94917",  "98617",  "78217",  "14817",  "27839",  "77139",  "31716",  "39516",  "+8210943772052",  "+8218010145648",  "89415",  "29315",  "23118",  "16918",  "+82235622927",  "+82957837490",  "24112",  "42112",  "3877652",  "3190845",  "94214",  "80015",  "2693981",  "1867151",  "30014",  "43413",  "+8246244402619",  "+8223163735604",  "+82610366759",  "+827048390282",  "+82610646026",  "+82401918875",  "78416",  "54016",  "1227074",  "7610416",  "522272",  "491843",  "+825451885859",  "23938",  "15337",  "54018",  "62819",  "287588",  "631048",  "31513",  "71013",  "9737",  "9677",  "+8261237434",  "+8222832625",  "+8220431882236",  "+8253992281968",  "6566",  "8310",  "82816",  "58916",  "83639",  "53139",  "34417",  "79917",  "57915",  "37815",  "80911",  "16011",  "53318",  "45418",  "+8294725927",  "2327769",  "21911",  "30811",  "+8210307121256",  "+8273178947962",  "93115",  "59515",  "49116",  "50315",  "24617",  "35618",  "71318",  "60019",  "12018",  "44718",  "42511",  "41411",  "33713",  "40014",  "65585",  "12967",  "14218",  "58517",  "+8287859187415",  "28311",  "85711",  "25611",  "28119",  "26519",  "78712",  "55613",  "+828744212301",  "+827728245377",  "+82602684073",  "+82860298866",  "40218",  "29218",  "64411",  "66311",  "+82742951586",  "+82585962739",  "74415",  "85214",  "1127682",  "587462",  "+82850393276",  "+82143588960",  "+82396473380",  "+82680777089",  "34712",  "79112",  "62045",  "49743",  "79014",  "13514",  "+8294592988",  "+8224995466",  "1093",  "146",  "12419",  "67319",  "32712",  "58212",  "33513",  "44013",  "+824150530901",  "+827659676651",  "65719",  "19419",  "67238",  "90736",  "92918",  "98318",  "86216",  "24116",  "11019",  "19619",  "49013",  "33913",  "92817",  "96917",  "+821000000000",  "+821054047458",  "+82105047458",  "97414",  "+8230014341",  "74117",  "98217",  "16475",  "51915",  "42613",  "80013",  "73918",  "97118",  "15811",  "73811",  "99139",  "70139",  "+821439293211",  "+828744241563",  "+82592923190",  "+82830855621",  "682125",  "6443941",  "78411",  "75211",  "14111",  "62711",  "+826542656447",  "+823336769531",  "+821234659761",  "+8251576749728",  "+8232841134072",  "60213",  "78413",  "36918",  "10318",  "67414",  "63714",  "48211",  "30311",  "39211",  "96311",  "31511",  "+826382086537",  "96339",  "52439",  "89318",  "98717",  "39212",  "15412",  "9790359",  "3848535",  "35712",  "37113",  "84511",  "+8259242216735",  "+8264929642288",  "+8267222577921",  "63615",  "30815",  "54612",  "40912",  "12615",  "61915",  "35117",  "80318",  "6539021",  "9946143",  "13613",  "49513",  "+8288419848044",  "+8232812490102",  "+826659440175",  "+821160526084",  "73612",  "33412",  "6453543",  "1593756",  "11848",  "63501",  "32017",  "31215",  "+82949965539",  "+82612457814",  "85039",  "81039",  "66019",  "67919",  "+82895483248",  "12717",  "52218",  "3319034",  "2179238",  "82815",  "83515",  "47614",  "16514",  "+82806764686",  "+491712522526",  "38617",  "83518",  "33618",  "59718",  "81916",  "40518",  "77313",  "36113",  "+82332725725",  "+828935590619",  "+8280454585163",  "+8292685199367",  "+8293610960741",  "+827490677427",  "+8244709456",  "+82775047180",  "+82173648543",  "+82835746455",  "7949362",  "6187513",  "48118",  "48518",  "13819",  "56519",  "+82173285605",  "+82106501217",  "22014",  "78414",  "31511",  "22911",  "8468938",  "6401338",  "+821012345678", };
+       *count = 1392;
+       *pAddrInfo = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * (*count)];
+       memset(*pAddrInfo, 0x00, (sizeof(MSG_ADDRESS_INFO_S) * (*count)));
+
+       for(unsigned int i = 0; i < *count; ++i){
+               strncpy((*pAddrInfo)[i].addressVal, normalizedList[i], MAX_ADDRESS_VAL_LEN);
+               MSG_DEBUG("normalizedNumber [%s]",(*pAddrInfo)[i].addressVal);
+       }
+
+#endif
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgSyncAddressbook()
+{
+       int ret = -1;
+       int changed_count = 0;
+
+       contacts_list_h addrbookListHnd = NULL;
+
+       ret = contacts_db_get_all_records(_contacts_address_book._uri, 0, 0, &addrbookListHnd);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_db_get_all_records() Error [%d]", ret);
+               contacts_list_destroy(addrbookListHnd, true);
+               return;
+       }
+
+       ret = contacts_list_get_count(addrbookListHnd, &changed_count);
+
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_list_get_count() Error [%d]", ret);
+               contacts_list_destroy(addrbookListHnd, true);
+               return;
+       }
+
+       if (changed_count>0) {
+               int addrbookList[changed_count];
+
+               for (int i = 0; i < changed_count; i++) {
+                       contacts_record_h addrbook = NULL;
+                       int addrbookId = 0;
+
+                       ret = contacts_list_get_current_record_p(addrbookListHnd, &addrbook);
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
+                               contacts_list_destroy(addrbookListHnd, true);
+                               return;
+                       }
+
+                       ret = contacts_record_get_int(addrbook, _contacts_address_book.id, &addrbookId);
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
+                               contacts_list_destroy(addrbookListHnd, true);
+                               return;
+                       }
+
+                       addrbookList[i] = addrbookId;
+
+                       ret = contacts_list_next(addrbookListHnd);
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               MSG_DEBUG("contacts_list_next() Error [%d]", ret);
+                       }
+
+               }
+
+               MsgStoClearContactInfoByAddrbookIdList(&ContactDbHandle, addrbookList, (int)changed_count);
+       }
+
+       contacts_list_destroy(addrbookListHnd, true);
+}
+
+
 void MsgSyncContact()
 {
        int ret = -1;
-       unsigned int changed_count = 0;
+       int changed_count = 0;
        int lastSyncTime = 0;
        int finalSyncTime = 0;
 
@@ -377,7 +829,7 @@ void MsgSyncContact()
                return;
        }
 
-       for (unsigned int i = 0; i < changed_count; i++)
+       for (int i = 0; i < changed_count; i++)
        {
                int index_num = 0;
                int type = 0;
@@ -406,13 +858,16 @@ void MsgSyncContact()
                        return;
                }
 
-               if (type == CONTACTS_CHANGE_UPDATED || type == CONTACTS_CHANGE_INSERTED) {
-                       MsgUpdateContact(index_num, type);
-               } else {// Delete
-                       MSG_DEBUG("Delete Contact");
+               MSG_DEBUG("type [%d]", type);
+
+               if (type != CONTACTS_CHANGE_INSERTED) {
                        MsgDeleteContact(index_num);
                }
 
+               if (type != CONTACTS_CHANGE_DELETED) {
+                       MsgUpdateContact(index_num, type);
+               }
+
                ret = contacts_list_next(contactsList);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_list_next() Error [%d]", ret);
@@ -425,8 +880,9 @@ void MsgSyncContact()
 
        contacts_list_destroy(contactsList, true);
 
-       if(changed_count > 0)
-               cbFunction();
+       if(changed_count > 0) {
+               if(cbFunction) cbFunction();
+       }
 }
 
 
@@ -457,6 +913,7 @@ bool MsgUpdateContact(int index, int type)
                return false;
        }
 
+#if 0
        MSG_CONTACT_INFO_S contactInfo;
        memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
 
@@ -469,12 +926,17 @@ bool MsgUpdateContact(int index, int type)
 
        MSG_DEBUG("Contact ID [%d]", contactInfo.contactId);
 
+       ret = contacts_record_get_int(contact, _contacts_contact.address_book_id, (int*)&contactInfo.addrbookId);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
+       }
+
+       MSG_DEBUG("Addressbook ID [%d]", contactInfo.addrbookId);
+
        char* strImagePath = NULL;
        ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return false;
        }
 
        if (strImagePath != NULL)
@@ -489,40 +951,64 @@ bool MsgUpdateContact(int index, int type)
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
        } else {
-               char* strFirstName = NULL;
-               ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
+               char* strName = NULL;
+               ret = contacts_record_get_str_p(name, _contacts_name.first, &strName);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(contactInfo.firstName, strName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
 
-               char* strLastName = NULL;
-               ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
+               ret = contacts_record_get_str_p(name, _contacts_name.last, &strName);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(contactInfo.lastName, strName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
 
-               char* strDisplayName = NULL;
-               ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &strDisplayName);
+               ret = contacts_record_get_str_p(name, _contacts_name.addition, &strName);
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(contactInfo.middleName, strName, MAX_DISPLAY_NAME_LEN);
+                       }
                }
 
-               if (strFirstName != NULL)
-                       strncpy(contactInfo.firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
-
-               if (strLastName != NULL)
-                       strncpy(contactInfo.lastName, strLastName, MAX_DISPLAY_NAME_LEN);
+               ret = contacts_record_get_str_p(name, _contacts_name.prefix, &strName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(contactInfo.prefix, strName, MAX_DISPLAY_NAME_LEN);
+                       }
+               }
 
-               if (strDisplayName != NULL)
-                       strncpy(contactInfo.displayName, strDisplayName, MAX_DISPLAY_NAME_LEN);
+               ret = contacts_record_get_str_p(name, _contacts_name.suffix, &strName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               } else {
+                       if (strName != NULL) {
+                               MSG_DEBUG("strName [%s]", strName);
+                               strncpy(contactInfo.suffix, strName, MAX_DISPLAY_NAME_LEN);
+                       }
+               }
 
-               MSG_DEBUG("First Name : [%s], Last Name : [%s]", contactInfo.firstName, contactInfo.lastName);
-               MSG_DEBUG("displayName : [%s]", contactInfo.displayName);
+               MSG_SEC_DEBUG("First Name : [%s], Last Name : [%s]", contactInfo.firstName, contactInfo.lastName);
        }
 
-       MsgStoResetContactInfo(&ContactDbHandle, index);
+       MsgStoClearContactInfo(&ContactDbHandle, index);
+#endif
 
-       unsigned int count = 0;
+       int count = 0;
        ret = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
@@ -530,12 +1016,9 @@ bool MsgUpdateContact(int index, int type)
                return false;
        }
 
-       MSG_DEBUG("_contacts_contact.number count [%d]", count);
-
        if (count > 0) {
-               for(unsigned int i=0; i < count; i++)
-               {
-                       MSG_DEBUG("Add Number Contact Data");
+               for(int i=0; i < count; i++) {
+                       MSG_DEBUG("Add Contact Data");
 
                        contacts_record_h number = NULL;
 
@@ -555,103 +1038,139 @@ bool MsgUpdateContact(int index, int type)
                        }
 
                        if (strNumber != NULL) {
-                               MSG_DEBUG("Number = %s", strNumber);
-                               if (!MsgInsertContact(&contactInfo, strNumber)) {
-                                       MSG_DEBUG("MsgInsertContact fail.");
+                               MSG_DEBUG("Number [%s]", strNumber);
+                               int strNumberLen = strlen(strNumber);
+                               char normalizeNum[strNumberLen+1];
+                               memset(normalizeNum, 0x00, sizeof(normalizeNum));
+                               if (strNumberLen > 0) {
+                                       normalizeNumber(strNumber, normalizeNum, strNumberLen);
+                                       MSG_DEBUG("normalizeNum [%s]", normalizeNum);
                                }
-                       }
-               }
-       }
-
-       count = 0;
-       ret = contacts_record_get_child_record_count(contact, _contacts_contact.email, &count);
-       if (ret != CONTACTS_ERROR_NONE) {
-               MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return false;
-       }
-
-       MSG_DEBUG("_contacts_contact.email count [%d]", count);
 
-       if (count > 0) {
-               for(unsigned int i=0; i < count; i++)
-               {
-                       MSG_DEBUG("Add Email Contact Data");
+                               MSG_CONTACT_INFO_S contactInfo;
+                               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
 
-                       contacts_record_h email = NULL;
+                               MSG_ADDRESS_INFO_S addrInfo;
+                               memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+                               strncpy(addrInfo.addressVal, normalizeNum, MAX_ADDRESS_VAL_LEN);
 
-                       ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.email, i, &email);
-                       if (ret != CONTACTS_ERROR_NONE) {
-                               MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
-                               contacts_record_destroy(contact, true);
-                               return false;
-                       }
-
-                       char* strNumber = NULL;
-                       ret = contacts_record_get_str_p(email, _contacts_email.email, &strNumber);
-                       if (ret != CONTACTS_ERROR_NONE) {
-                               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-                               contacts_record_destroy(contact, true);
-                               return false;
-                       }
-
-                       if (strNumber != NULL) {
-                               MSG_DEBUG("email = %s", strNumber);
-                               if (!MsgInsertContact(&contactInfo, strNumber)) {
-                                       MSG_DEBUG("MsgInsertContact fail.");
+                               if(MsgGetContactInfo(&addrInfo, &contactInfo) == MSG_SUCCESS) {
+                                       if (MsgInsertContact(&contactInfo, normalizeNum)) {
+                                               MsgStoSetConversationDisplayName(&ContactDbHandle, (int)contactInfo.contactId);
+                                       } else {
+                                               MSG_DEBUG("MsgInsertContact fail.");
+                                       }
                                }
                        }
                }
+       } else {// No phone number in contact
+               contacts_record_destroy(contact, true);
+               return true;
        }
 
-       MsgStoSetConversationDisplayName(&ContactDbHandle, index);
+//     MsgStoSetConversationDisplayName(&ContactDbHandle, index);
 
        contacts_record_destroy(contact, true);
 
-       if (type == -1 && cbFunction != NULL)
-               cbFunction();
-
        return true;
 }
 
 
 bool MsgDeleteContact(int index)
 {
+//     if (MsgStoClearContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
        if (MsgStoResetContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
                return false;
 
        return true;
 }
 
-
 int MsgGetContactNameOrder()
 {
-       msg_error_t err = MSG_SUCCESS;
+//     int ret = CONTACTS_ERROR_NONE;
+       contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
 
-       if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
-               MSG_DEBUG("MsgOpenContactSvc fail.");
-               return 0;
-       }
+//     if (MsgOpenContactSvc() != MSG_SUCCESS) {
+//             MSG_DEBUG("MsgOpenContactSvc fail.");
+//     }
+//
+//     if (!isContactSvcConnected) {
+//             MSG_DEBUG("Contact Service Not Opened.");
+//     } else {
+//             ret = contacts_setting_get_name_display_order(&order);
+//             if (ret != CONTACTS_ERROR_NONE) {
+//                     MSG_DEBUG("contacts_setting_get_name_display_order() Error [%d]", ret);
+//             }
+//     }
+
+       return (int)order;
+}
 
-       if (!isContactSvcConnected) {
-               MSG_DEBUG("Contact Service Not Opened.");
-               return 0; // return default value : FIRSTLAST
+
+msg_error_t MsgGetContactStyleDisplayName(const char *first, const char *last, const char *middle, const char *prefix, const char *suffix, int contactNameOrder, char *displayName, unsigned int size)
+{
+       if (first == NULL || last == NULL || middle == NULL || prefix == NULL || suffix == NULL || displayName == NULL || size ==0) {
+               MSG_DEBUG("Invalid parameter.");
+               return MSG_ERR_INVALID_PARAMETER;
        }
 
-       int ret = CONTACTS_ERROR_NONE;
+       if (contactNameOrder == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST) {
+               if (strlen(prefix) > 0) {
+                       strncpy(displayName, prefix, size);
+               }
 
-       contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
+               if (strlen(first) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
+                       strncat(displayName, first, size-strlen(displayName));
+               }
 
-       ret = contacts_setting_get_name_display_order(&order);
-       if (ret != CONTACTS_ERROR_NONE) {
-               MSG_DEBUG("contacts_setting_get_name_display_order() Error [%d]", ret);
-               return 0;
+               if (strlen(middle) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
+
+                       strncat(displayName, middle, size-strlen(displayName));
+               }
+
+               if (strlen(last) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
+                       strncat(displayName, last, size-strlen(displayName));
+               }
+
+               if (strlen(suffix) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
+                       strncat(displayName, suffix, size-strlen(displayName));
+               }
+       } else {
+               if (strlen(prefix) > 0) {
+                       strncpy(displayName, prefix, size);
+               }
+
+               if (strlen(last) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
+                       strncat(displayName, last, size-strlen(displayName));
+
+                       if (strlen(first) > 0 || strlen(middle) > 0 || strlen(suffix) > 0)
+                               strncat(displayName, ",", size-strlen(displayName));
+               }
+
+               if (strlen(first) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
+                       strncat(displayName, first, size-strlen(displayName));
+               }
+
+               if (strlen(middle) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, " ", size-strlen(displayName));
+                       strncat(displayName, middle, size-strlen(displayName));
+               }
+
+               if (strlen(suffix) > 0) {
+                       if (strlen(displayName) > 0) strncat(displayName, ", ", size-strlen(displayName));
+                       strncat(displayName, suffix, size-strlen(displayName));
+               }
        }
 
-       if (order == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST)
-               return 0;
-       else
-               return 1;
+       MSG_DEBUG("displayName [%s]", displayName);
+
+       return MSG_SUCCESS;
 }
 
 
@@ -752,7 +1271,7 @@ void MsgDeletePhoneLog(msg_message_id_t msgId)
 
        int ret = CONTACTS_ERROR_NONE;
        int index = 0;
-       unsigned int count = 0;
+       int count = 0;
        contacts_query_h query;
        contacts_filter_h filter;
        contacts_list_h plogs = NULL;
@@ -794,7 +1313,6 @@ void MsgDeletePhoneLog(msg_message_id_t msgId)
        contacts_query_destroy(query);
        contacts_filter_destroy(filter);
        contacts_list_destroy(plogs, true);
-
 }
 
 
@@ -810,3 +1328,191 @@ int MsgContactSVCEndTrans(bool bSuccess)
        //return contacts_svc_end_trans(bSuccess);
        return 0;
 }
+
+
+bool checkBlockingMode(char *address, bool *pisFavorites)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       if (pisFavorites != NULL) *pisFavorites = false;
+
+       bool isBlockModeOn = false;
+       bool isblock = true;
+
+       MsgSettingGetBool(VCONFKEY_SETAPPL_BLOCKINGMODE_NOTIFICATIONS, &isBlockModeOn);
+
+       int blockModeType = -1;
+
+       blockModeType = MsgSettingGetInt(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_TYPE);
+
+       if (!isBlockModeOn)
+               isblock = false;
+       else if (blockModeType < 0)
+               isblock = false;
+
+
+       if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgOpenContactSvc fail.");
+               return isblock;
+       }
+
+       if (!isContactSvcConnected) {
+               MSG_DEBUG("Contact Service Not Opened.");
+               return isblock;
+       }
+
+       MSG_SEC_DEBUG("Address Value [%s]", address);
+
+       if (strlen(address) > (MAX_PHONE_NUMBER_LEN+1)) {
+               MSG_SEC_DEBUG("Phone Number is too long [%s]", address);
+               return isblock;
+       }
+
+       int ret = 0;
+       int personId = 0;
+       bool isFavorites = false;
+       int count = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h personList = NULL;
+
+       ret = contacts_query_create(_contacts_person_number._uri, &query);
+       ret = contacts_filter_create(_contacts_person_number._uri, &filter);
+
+       ret = contacts_filter_add_str(filter, _contacts_person_number.number_filter, CONTACTS_MATCH_EXACTLY, address);
+
+       ret = contacts_query_set_filter(query, filter);
+       ret = contacts_db_get_records_with_query(query, 0, 1, &personList);
+
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
+               contacts_list_destroy(personList, true);
+               return isblock;
+       }
+
+       ret = contacts_list_get_count(personList, &count);
+
+       if (count == 0 || ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("No Serach Data from Contact Service.");
+               contacts_list_destroy(personList, true);
+               return isblock;
+       } else if (ret == CONTACTS_ERROR_NONE && count > 0
+                       && blockModeType == 1) { // For All contacts allow in blocking mode.
+               isblock = false;
+       }
+
+       contacts_record_h person = NULL;
+
+       ret = contacts_list_get_current_record_p(personList, &person);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
+               contacts_list_destroy(personList, true);
+               return isblock;
+       }
+
+       ret = contacts_record_get_int(person, _contacts_person_number.person_id, &personId);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
+               contacts_list_destroy(personList, true);
+               return isblock;
+       }
+
+       MSG_DEBUG("personId [%d]", personId);
+
+       ret = contacts_record_get_bool(person, _contacts_person_number.is_favorite, &isFavorites);
+       if (ret != CONTACTS_ERROR_NONE) {
+               MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
+               contacts_list_destroy(personList, true);
+               return isblock;
+       }
+
+       contacts_list_destroy(personList, true);
+
+       switch (blockModeType)
+       {
+       case 2: // For Favorites allow in blocking mode.
+       {
+               if (isFavorites) isblock = false;
+               break;
+       }
+       case 3: // For Custom allow in blocking mode.
+       {
+               char *allowList = MsgSettingGetString(VCONFKEY_SETAPPL_BLOCKINGMODE_ALLOWED_CONTACT_LIST);
+               char *personIdStr = strtok (allowList," ,");
+               while (personIdStr != NULL)
+               {
+                       MSG_DEBUG("personIdStr [%s]", personIdStr);
+                       if (personId == atoi(personIdStr)) {
+                               MSG_DEBUG("In allow list.");
+                               isblock = false;
+                               break;
+                       }
+                       personIdStr = strtok (NULL, " ,");
+               }
+
+               if (allowList) {
+                       free(allowList);
+                       allowList = NULL;
+               }
+
+               break;
+       }
+       default: // Wrong blocking mode type.
+               break;
+       }
+
+       if (pisFavorites != NULL) *pisFavorites = isFavorites;
+
+       return isblock;
+}
+
+
+int MsgContactGetMinMatchDigit()
+{
+       return phonenumberMinMatchDigit;
+}
+
+
+void MsgConvertNumber(const char* pSrcNum, char* pDestNum, int destSize)
+{
+       int len;
+       const char *temp_number;
+
+       if ('+' == pSrcNum[0]) {
+               len = countryCodeLength(&pSrcNum[1]);
+               temp_number = pSrcNum + len +1;
+       } else if ('0' == pSrcNum[0]) {
+               if ('0' == pSrcNum[1]) {
+                       len = countryCodeLength(&pSrcNum[2]);
+                       temp_number = pSrcNum + len +2;
+               } else {
+                       temp_number = pSrcNum+1;
+               }
+       } else {
+               temp_number = pSrcNum;
+       }
+
+       strncpy(pDestNum, temp_number, destSize);
+}
+
+
+bool MsgIsNumber(const char* pSrc)
+{
+       int len = strlen(pSrc);
+
+       for(int i = 0; i < len; ++i){
+
+               if(i == 0 && pSrc[i] == '+')
+                       continue;
+
+               if(pSrc[i] < '0' || pSrc[i] >'9'){
+                       return false;
+               }
+       }
+
+       return true;
+}
+
index 280f6c3..8a91c85 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
@@ -182,7 +182,6 @@ const char * MsgDbgCmdStr(MSG_CMD_TYPE_T cmdType)
 // 65
                case MSG_CMD_GET_GENERAL_MSG_OPT:
                        return "MSG_CMD_GET_GENERAL_MSG_OPT";
-
                case MSG_CMD_GET_MSG_SIZE_OPT:
                        return "MSG_CMD_GET_MSG_SIZE_OPT";
                case MSG_CMD_SET_SMSC_OPT:
@@ -224,7 +223,23 @@ const char * MsgDbgCmdStr(MSG_CMD_TYPE_T cmdType)
                        return "MSG_CMD_DELETE_PUSH_EVENT";
                case MSG_CMD_UPDATE_PUSH_EVENT:
                        return "MSG_CMD_UPDATE_PUSH_EVENT";
-
+               case MSG_CMD_DELETE_MESSAGE_BY_LIST :
+                       return "MSG_CMD_DELETE_MESSAGE_BY_LIST";
+               case MSG_CMD_SET_FILTER_ACTIVATION :
+                       return "MSG_CMD_SET_FILTER_ACTIVATION";
+               case MSG_CMD_ADD_SIM_MSG :
+                       return "MSG_CMD_ADD_SIM_MSG";
+//90
+               case MSG_CMD_PLG_RESEND_MESSAGE:
+                       return "MSG_CMD_PLG_RESEND_MESSAGE";
+#ifdef MSG_PENDING_PUSH_MESSAGE
+               case MSG_CMD_SEND_PENDING_PUSH_MESSAGE:
+                       return "MSG_CMD_SEND_PENDING_PUSH_MESSAGE";
+#endif
+               case MSG_CMD_REG_REPORT_MSG_INCOMING_CB:
+                       return "MSG_CMD_REG_REPORT_MSG_INCOMING_CB";
+               case MSG_CMD_UPDATE_IMSI:
+                       return "MSG_CMD_UPDATE_IMSI";
                default:
                        return "Unknown Command Type!!!";
        }
@@ -388,12 +403,11 @@ const char * MsgDbgEvtStr(MSG_EVENT_TYPE_T evtType)
 // 65
                case MSG_EVENT_GET_GENERAL_MSG_OPT:
                        return "MSG_EVENT_GET_GENERAL_MSG_OPT";
-
-// 65
                case MSG_EVENT_GET_MSG_SIZE_OPT:
                        return "MSG_EVENT_GET_MSG_SIZE_OPT";
                case MSG_EVENT_SET_SMSC_OPT:
                        return "MSG_EVENT_SET_SMSC_OPT";
+// 70
                case MSG_EVENT_SET_CB_OPT:
                        return "MSG_EVENT_SET_CB_OPT";
                case MSG_EVENT_SET_SMS_SEND_OPT:
@@ -402,16 +416,16 @@ const char * MsgDbgEvtStr(MSG_EVENT_TYPE_T evtType)
                        return "MSG_EVENT_SET_MMS_SEND_OPT";
                case MSG_EVENT_SET_MMS_RECV_OPT:
                        return "MSG_EVENT_SET_MMS_RECV_OPT";
-
-// 70
                case MSG_EVENT_SET_PUSH_MSG_OPT:
                        return "MSG_EVENT_SET_PUSH_MSG_OPT";
+// 75
                case MSG_EVENT_SET_VOICE_MSG_OPT:
                        return "MSG_EVENT_SET_VOICE_MSG_OPT";
                case MSG_EVENT_SET_GENERAL_MSG_OPT:
                        return "MSG_EVENT_SET_GENERAL_MSG_OPT";
                case MSG_EVENT_SET_MSG_SIZE_OPT:
                        return "MSG_EVENT_SET_MSG_SIZE_OPT";
+//80
                case MSG_EVENT_REG_INCOMING_PUSH_MSG_CB:
                        return "MSG_EVENT_REG_INCOMING_PUSH_MSG_CB";
                case MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND:
@@ -422,12 +436,31 @@ const char * MsgDbgEvtStr(MSG_EVENT_TYPE_T evtType)
                        return "MSG_EVENT_PLG_INCOMING_CB_MSG_IND";
                case MSG_EVENT_ADD_PUSH_EVENT:
                        return "MSG_EVENT_ADD_PUSH_EVENT";
-
+//85
                case MSG_EVENT_DELETE_PUSH_EVENT:
                        return "MSG_EVENT_DELETE_PUSH_EVENT";
                case MSG_EVENT_UPDATE_PUSH_EVENT:
                        return "MSG_EVENT_UPDATE_PUSH_EVENT";
-
+               case MSG_EVENT_DELETE_MESSAGE_BY_LIST :
+                       return "MSG_EVENT_DELETE_MESSAGE_BY_LIST";
+               case MSG_EVENT_SET_FILTER_ACTIVATION :
+                       return "MSG_EVENT_SET_FILTER_ACTIVATION";
+               case MSG_EVENT_ADD_SIM_MSG :
+                       return "MSG_EVENT_ADD_SIM_MSG";
+
+//90
+               case MSG_EVENT_PLG_RESEND_MESSAGE:
+                       return "MSG_EVENT_PLG_RESEND_MESSAGE";
+#ifdef MSG_PENDING_PUSH_MESSAGE
+               case MSG_EVENT_SEND_PENDING_PUSH_MESSAGE:
+                       return "MSG_EVENT_SEND_PENDING_PUSH_MESSAGE";
+#endif
+               case MSG_EVENT_REG_REPORT_MSG_INCOMING_CB:
+                       return "MSG_EVENT_REG_REPORT_MSG_INCOMING_CB";
+               case MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND:
+                       return "MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND";
+               case MSG_EVENT_UPDATE_IMSI:
+                       return "MSG_EVENT_UPDATE_IMSI";
                default:
                        return "Unknown Event Type!!!";
        }
index 48114ac..835100d 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+
+#if MSG_DRM_SUPPORT
+
 #include <drm_client_types.h>
 #include <drm_client.h>
 
+#endif //MSG_DRM_SUPPORT
+
 #define MSG_MAX_DRM_FILE_PATH MSG_FILEPATH_LEN_MAX
 
 bool MsgDrmRegisterFile(MSG_DRM_OPENMODE eMode, char *pBuffer, int nSize)
 {
+#if MSG_DRM_SUPPORT
        if (eMode == MSG_MODE_STREAM) {
                MSG_DEBUG("Fail(eMode == MSG_MODE_STREAM)");
                return false;
@@ -61,15 +67,19 @@ bool MsgDrmRegisterFile(MSG_DRM_OPENMODE eMode, char *pBuffer, int nSize)
 
        eDRMResult = drm_process_request(request_type, pBuffer, NULL);
        if (DRM_RETURN_SUCCESS != eDRMResult) {
-               MSG_DEBUG("drm_process_request is failed : %d", eDRMResult);
+               MSG_DEBUG("drm_process_request is failed : 0x%x", eDRMResult);
                return false;
        }
        MSG_END();
        return true;
+#else
+       return false;
+#endif
 }
 
 bool MsgDrmUnregisterFile(char *szFilename)
 {
+#if MSG_DRM_SUPPORT
        if (szFilename == NULL) {
                MSG_DEBUG("[Error] szFilename is NULL");
                return false;
@@ -86,10 +96,14 @@ bool MsgDrmUnregisterFile(char *szFilename)
        }
 
        return true;
+#else
+       return false;
+#endif
 }
 
 bool MsgDrmIsDrmFile(const char *szFilePath)
 {
+#if MSG_DRM_SUPPORT
        drm_bool_type_e isDrm;
        int eDRMResult = drm_is_drm_file(szFilePath, &isDrm);
 
@@ -99,16 +113,144 @@ bool MsgDrmIsDrmFile(const char *szFilePath)
        }
 
        return true;
+#else
+       return false;
+#endif
 }
 
 /*Added to convert the .dm files in to .dcf files since our platform supports only .dcf :: Start*/
 bool MsgDrmConvertDmtoDcfType(char *inputFile, char *outputFile)
 {
+#if MSG_DRM_SUPPORT
+       if ((NULL == inputFile) || (NULL == outputFile)) {
+               MSG_DEBUG("Invalid Input parameters");
+               return false;
+       }
+
+       if (strstr(inputFile, ".dm")) {
+               MSG_SEC_DEBUG("Current File extension is .dm %s", inputFile);
+               int ret;
+
+               FILE *fp = MsgOpenFile(inputFile, "rb");//Check fp
+
+               if (fp == NULL) {
+                       MSG_DEBUG("[File Open Fail(Errno=%d)][ErrStr=%s]", errno, strerror(errno));
+                       strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+                       return false;
+               }
+
+               if (MsgFseek(fp, 0L, SEEK_END) < 0) {
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("MsgFseek() returns negative value!!!");
+                       return false;
+               }
+               long retVal = MsgFtell(fp);
+
+               if (retVal < 0) {
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("ftell() returns negative value: [%ld]!!!", retVal);
+                       strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+                       return false;
+               }
+
+               unsigned long bufLen = retVal;
+               MSG_DEBUG("fopen buffer len = %d", bufLen);
+               if (MsgFseek(fp, 0, SEEK_SET) < 0) {
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("MsgFseek() returns negative value!!!");
+                       return false;
+               }
+
+               unsigned char *buffer = (unsigned char*)malloc(bufLen);
+               int readed_size = 0;
+               int pathLen = strlen(inputFile);
+
+               if (buffer == NULL) {
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("malloc is failed ");
+                       strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+                       return false;
+               }
+
+               strncpy(outputFile, inputFile, pathLen - 2);
+               strncat(outputFile, "dcf", 3);
+
+               readed_size = MsgReadFile(buffer, 1, bufLen, fp);//Check for error
+               MSG_DEBUG("fread read size = %d", readed_size);
+               if (readed_size == 0) {
+                       MsgCloseFile(fp);
+                       free(buffer);
+                       MSG_DEBUG("MsgReadFile returns 0");
+                       return false;
+               }
+
+               DRM_TRUSTED_CONVERT_HANDLE hConvert = NULL;
+               drm_trusted_opn_conv_info_s trusted_open_conv_input;
+               bzero(&trusted_open_conv_input, sizeof(drm_trusted_opn_conv_info_s));
+
+               strncpy(trusted_open_conv_input.filePath, outputFile, DRM_TRUSTED_MAX_FILEPATH_LEN-1);
+               trusted_open_conv_input.install_RO = DRM_TRUSTED_TRUE;
+
+               ret = drm_trusted_open_convert(&trusted_open_conv_input, &hConvert);
+               if (ret != DRM_RETURN_SUCCESS) {
+                       free(buffer);
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("drm_trusted_open_convert() return = failed (0x%x)", ret);
+                       remove(outputFile);
+                       strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+                       return false;
+               }
+
+               drm_trusted_write_conv_info_s trusted_write_conv_input;
+               drm_trusted_write_conv_resp_s trusted_write_conv_output;
+
+               bzero(&trusted_write_conv_input, sizeof(drm_trusted_write_conv_info_s));
+               bzero(&trusted_write_conv_output, sizeof(drm_trusted_write_conv_resp_s));
+
+               trusted_write_conv_input.data = buffer;
+               trusted_write_conv_input.data_len = bufLen;
+
+               /*We can call drm_trusted_write_convert in loop if file size is large*/
+               ret = drm_trusted_write_convert(&trusted_write_conv_input, &trusted_write_conv_output, hConvert);
+               if (ret != DRM_RETURN_SUCCESS) {
+                       free(buffer);
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("drm_trusted_write_convert() return = failed (0x%x)", ret);
+                       remove(outputFile);
+                       strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+                       return false;
+               }
+
+               ret = drm_trusted_close_convert(&hConvert);
+               if (ret != DRM_RETURN_SUCCESS) {
+                       free(buffer);
+                       MsgCloseFile(fp);
+                       MSG_DEBUG("drm_trusted_close_convert() return = failed (0x%x)", ret);
+                       remove(outputFile);
+                       strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+                       return false;
+               }
+
+               MsgCloseFile(fp);
+               free(buffer);
+       } else {
+               MSG_DEBUG("Current File extension is not .dm");
+
+               MSG_DEBUG("inputFile = (%s)", inputFile);
+               strncpy(outputFile, inputFile, MSG_MAX_DRM_FILE_PATH);
+
+               return false;
+       }
+
+       return true;
+#else
        return true;
+#endif
 }
 
 bool MsgDrmGetDrmType(const char *szFileName, MSG_DRM_TYPE *eDRMType)
 {
+#if MSG_DRM_SUPPORT
        if (szFileName == NULL || eDRMType == NULL) {
                MSG_DEBUG("Param is NULL");
                return false;
@@ -152,10 +294,14 @@ bool MsgDrmGetDrmType(const char *szFileName, MSG_DRM_TYPE *eDRMType)
        }
 
        return true;
+#else
+       return false;
+#endif
 }
 
 bool MsgDrmGetMimeTypeEx(const char *szFileName, char *szMimeType, int nMimeTypeLen)
 {
+#if MSG_DRM_SUPPORT
        if (!szFileName || !szMimeType || !nMimeTypeLen) {
                MSG_DEBUG("param is NULL");
                return false;
@@ -178,10 +324,14 @@ bool MsgDrmGetMimeTypeEx(const char *szFileName, char *szMimeType, int nMimeType
        }
 
        return true;
+#else
+       return false;
+#endif
 }
 
 bool MsgDrmGetContentID(const char *szFileName, char *szContentID, int nContentIDLen)
 {
+#if MSG_DRM_SUPPORT
        if (!szFileName || !szContentID || !nContentIDLen) {
                MSG_DEBUG("param is NULL");
                return false;
@@ -189,14 +339,14 @@ bool MsgDrmGetContentID(const char *szFileName, char *szContentID, int nContentI
 
        char strTemp[MSG_MAX_DRM_FILE_PATH + 1] = {0,};
 
-       strncpy(strTemp, szFileName, MSG_MAX_DRM_FILE_PATH);
+       strncpy(strTemp, szFileName, sizeof(strTemp)-1);
 
        drm_content_info_s  content_info;
        memset(&content_info, 0x00, sizeof(drm_content_info_s));
 
        int result = drm_get_content_info(strTemp, &content_info);
        if (DRM_RETURN_SUCCESS == result) {
-               MSG_DEBUG("contentID = %s", content_info.content_id);
+               MSG_SEC_DEBUG("contentID = %s", content_info.content_id);
         snprintf(szContentID, nContentIDLen, "%s", content_info.content_id);
        } else {
                MSG_DEBUG("drm_get_content_info is failed %d", result);
@@ -204,5 +354,39 @@ bool MsgDrmGetContentID(const char *szFileName, char *szContentID, int nContentI
        }
 
        return true;
+#else
+       return false;
+#endif
 }
 
+bool MsgDrmCheckRingtone(const char *ringtonePath)
+{
+#if MSG_DRM_SUPPORT
+       bool ret = false;
+
+       if (ringtonePath) {
+               drm_bool_type_e allowed = DRM_UNKNOWN;
+               drm_action_allowed_data_s data;
+               memset(&data, 0x00, sizeof(drm_action_allowed_data_s));
+               strncpy(data.file_path, ringtonePath, strlen(ringtonePath));
+               data.data = (int)DRM_SETAS_RINGTONE;
+
+               int res = drm_is_action_allowed(DRM_HAS_VALID_SETAS_STATUS, &data, &allowed);
+
+               if (res == DRM_RETURN_SUCCESS) {
+                       if (allowed == DRM_TRUE) {
+                               MSG_DEBUG("allowed [DRM_TRUE]");
+                               ret = true;
+                       }
+               } else {
+                       MSG_DEBUG("fail to drm_is_action_allowed [0x%x]", res);
+               }
+       } else {
+               MSG_DEBUG("ringtonePath is NULL.");
+       }
+
+       return ret;
+#else
+       return false;
+#endif
+}
index 554c3d1..556c3f6 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgException.h"
index 4dcf2a6..6981f34 100755 (executable)
@@ -1,27 +1,28 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
 
-#include <pmapi.h>
-
 #include "MsgDebug.h"
 #include "MsgUtilStorage.h"
-#include "MsgNotificationWrapper.h"
 #include "MsgGconfWrapper.h"
+#include "MsgException.h"
+#ifdef MSG_PENDING_PUSH_MESSAGE
+#include "MsgIpcSocket.h"
+#endif
 
 #ifdef USE_GCONF
 
@@ -31,14 +32,13 @@ MSG_GOBJECT_CLIENT_S* pClient = NULL;
 
 #endif
 
-bool bAutoReject = false;
-bool bUnknownAutoReject = false;
+#ifdef MSG_PENDING_PUSH_MESSAGE
+int bPushServiceReady = 0;
+#endif
 
+int autoReject = 0;
+bool bUnknownAutoReject = false;
 
-/*==================================================================================================
-                                     DEFINES
-==================================================================================================*/
-#define MSG_UNREAD_CNT         "db/badge/org.tizen.message"
 
 
 /*==================================================================================================
@@ -52,17 +52,34 @@ static void MsgVconfCB(keynode_t *key, void* data)
        if (!keyStr)
                return;
 
-       if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL)) {
-               bAutoReject = vconf_keynode_get_bool(key);
-               MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, bAutoReject);
-       } else if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL)) {
+       if (!g_strcmp0(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_INT)) {
+               autoReject = vconf_keynode_get_int(key);
+               MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_INT, autoReject);
+       } else if (!g_strcmp0(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL)) {
                bUnknownAutoReject = vconf_keynode_get_bool(key);
                MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, bUnknownAutoReject);
-       } else if (!strcmp(keyStr, VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER)) {
-               int contactDisplayOrder = vconf_keynode_get_int(key);
-               MSG_DEBUG("[%s] key CB called. Apply [%d]", VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, contactDisplayOrder);
-               MsgStoRefreshConversationDisplayName();
-       } else {
+       }
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       else if (!g_strcmp0(keyStr, VCONFKEY_USER_SERVICE_READY)){
+               bPushServiceReady = vconf_keynode_get_int(key);
+               MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_USER_SERVICE_READY, bPushServiceReady);
+
+               if(bPushServiceReady)
+               {
+                       try {
+                               if (MsgSendPendingPushMsg() == MSG_SUCCESS) {
+                                       MSG_DEBUG("MsgSendPendingPushMsg success");
+                               } else {
+                                       MSG_DEBUG("MsgSendPendingPushMsg fail");
+                               }
+                       } catch (MsgException& e) {
+                               MSG_FATAL("%s", e.what());
+                               MSG_DEBUG("MsgSendPendingPushMsg fail");
+                       }
+               }
+       }
+#endif
+       else {
                MSG_DEBUG("key did not match.");
        }
 }
@@ -186,23 +203,6 @@ int MsgSettingGetBool(const char *pKey, bool *pVal)
        return retVal;
 }
 
-void MsgChangePmState()
-{
-       MSG_BEGIN();
-       int callStatus = 0;
-
-       callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
-       MSG_DEBUG("Call Status = %d", callStatus);
-
-       if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
-               MSG_DEBUG("Call is activated. Do not turn on the lcd.");
-       } else {
-               MSG_DEBUG("Call is activated. Turn on the lcd.");
-               pm_change_state(LCD_NORMAL);
-       }
-
-       MSG_END();
-}
 
 msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
 {
@@ -217,15 +217,23 @@ msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
                return MSG_ERR_SET_SETTING;
        }
 
-       if (SmsCnt == 0 && MmsCnt == 0)
-       {
-               MSG_DEBUG("No New Message.");
-       }
-       else
-       {
-               MSG_DEBUG("New Message.");
-               MsgChangePmState();
-       }
+//     if (SmsCnt == 0 && MmsCnt == 0)
+//     {
+//             MSG_DEBUG("No New Message.");
+//     }
+//     else
+//     {
+//             MSG_DEBUG("New Message.");
+//
+//             bool bNotification = true;
+//
+//             if (MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bNotification) != MSG_SUCCESS) {
+//                     MSG_DEBUG("MsgSettingGetBool is failed.");
+//             }
+//
+//             if (bNotification)
+//                     MsgChangePmState();
+//     }
 
        MSG_END();
 
@@ -241,19 +249,13 @@ msg_error_t MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
        if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
                return MSG_ERR_SET_SETTING;
 
-       int sumCnt = SmsCnt + MmsCnt;
-
-//     if (MsgSettingSetInt(MSG_UNREAD_CNT, sumCnt) != 0)
-       if (MsgInsertBadge(sumCnt) != MSG_SUCCESS)
-               return MSG_ERR_SET_SETTING;
-
        return MSG_SUCCESS;
 }
 
 
-bool MsgSettingGetAutoReject()
+int MsgSettingGetAutoReject()
 {
-       return bAutoReject;
+       return autoReject;
 }
 
 bool MsgSettingGetUnknownAutoReject()
@@ -283,17 +285,67 @@ void MsgSettingRemoveVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
 void MsgSettingRegVconfCB()
 {
        // Set default values.
-       MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, &bAutoReject);
+       autoReject = MsgSettingGetInt(VCONFKEY_CISSAPPL_AUTO_REJECT_INT);
        MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, &bUnknownAutoReject);
 
-       MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
+       MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_INT, MsgVconfCB);
        MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
-       MsgSettingRegVconfCBCommon(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, MsgVconfCB);
+
+#ifdef MSG_PENDING_PUSH_MESSAGE
+       MsgSettingRegVconfCBCommon(VCONFKEY_USER_SERVICE_READY, MsgVconfCB);
+#endif
+
 }
 
 void MsgSettingRemoveVconfCB()
 {
-       MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
+       MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_INT, MsgVconfCB);
        MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
-       MsgSettingRemoveVconfCBCommon(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, MsgVconfCB);
+}
+
+msg_error_t MsgSendPendingPushMsg(void)
+{
+       MSG_BEGIN();
+
+       // establish connection to msgfw daemon
+       MsgIpcClientSocket client;
+       client.connect(MSG_SOCKET_PATH);
+
+       // composing command
+       int cmdSize = sizeof(MSG_CMD_S); // cmd type, MSG_SYNCML_MESSAGE_DATA_S
+
+       MSG_DEBUG("cmdSize: %d", cmdSize);
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+       MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_SEND_PENDING_PUSH_MESSAGE;
+
+       memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
+
+       // Send Command to Messaging FW
+       client.write(cmdBuf, cmdSize);
+
+       // Receive result from Transaction Manager
+       char* retBuf = NULL;
+       AutoPtr<char> wrap(&retBuf);
+       unsigned int retSize;
+       client.read(&retBuf, &retSize);
+
+       // close connection to msgfw daemon
+       client.close();
+
+       // Decoding the result from FW and Returning it to plugin
+       // the result is used for making delivery report
+       MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
+
+       if (pEvent->eventType != MSG_EVENT_SEND_PENDING_PUSH_MESSAGE)
+               MSG_FATAL("Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+               //THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
+
+       MSG_END();
+
+       return (pEvent->result);
 }
index 338fcfa..07aaea2 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/smack.h>
 
 #include <errno.h>
 #include <unistd.h>
 #include <errno.h>
 
+
 #include "MsgDebug.h"
 #include "MsgException.h"
 #include "MsgIpcSocket.h"
@@ -61,12 +63,19 @@ msg_error_t MsgIpcClientSocket::connect(const char* path)
        int len = strlen(serverSA.sun_path) + sizeof(serverSA.sun_family);
 
        if (::connect(sockfd, (struct sockaddr *)&serverSA, len) == CUSTOM_SOCKET_ERROR) {
-               THROW(MsgException::IPC_ERROR,"cannot connect server %s", strerror(errno));
+               if(errno == EACCES)
+                       THROW(MsgException::SECURITY_ERROR,"cannot connect server %s", strerror(errno));
+               else
+                       THROW(MsgException::IPC_ERROR,"cannot connect server %s", strerror(errno));
        }
 
        /* add fd for select() */
        addfd(sockfd);
 
+       if (!wait_for_reply()) {
+               THROW(MsgException::IPC_ERROR, "wait_for_reply() error");
+       }
+
        /* read remote fd for reg func */
        char *rfd = NULL;
        AutoPtr<char> wrap(&rfd);
@@ -189,6 +198,39 @@ int MsgIpcClientSocket::readn( char *buf, unsigned int len )
        return (len-nleft);
 }
 
+bool MsgIpcClientSocket::wait_for_reply ()
+{
+       int err = -1;
+       fd_set fds;
+       struct timeval tv;
+
+       if (sockfd < 0) {
+               MSG_FATAL ("Invalid file description : [%d]", sockfd);
+               return false;
+       }
+
+       FD_ZERO(&fds);
+       FD_SET(sockfd, &fds);
+
+       tv.tv_sec  = 5; /* should be tuned */
+       tv.tv_usec = 0;
+
+       MSG_DEBUG ("wait for response [%d]", sockfd);
+       err = select(sockfd + 1, &fds, NULL, NULL, &tv);
+       if (err == -1) {
+               MSG_FATAL("select error[%d] fd[%d]", errno, sockfd);
+               return false;
+       }
+       else if (err == 0) {
+               MSG_FATAL ("select timeout fd[%d]", sockfd);
+               return false;
+       }
+
+       if (FD_ISSET(sockfd, &fds)) return true;
+
+       return false;
+}
+
 
 /* what if the buf is shorter than data? */
 int MsgIpcClientSocket::read(char** buf, unsigned int* len)
@@ -306,7 +348,17 @@ msg_error_t MsgIpcServerSocket::open(const char* path)
                MSG_FATAL("chmod: %s", strerror(errno));
                return MSG_ERR_UNKNOWN;
        }
+#if 0
+       if (smack_setlabel(path, "*", SMACK_LABEL_IPIN) != 0) {
+               MSG_FATAL("smack_setlabel error");
+               return MSG_ERR_UNKNOWN;
+       }
 
+       if (smack_setlabel(path, "@", SMACK_LABEL_IPOUT) != 0) {
+               MSG_FATAL("smack_setlabel error");
+               return MSG_ERR_UNKNOWN;
+       }
+#endif
        if (listen(sockfd, CUSTOM_SOCKET_BACKLOG) == CUSTOM_SOCKET_ERROR) {
                MSG_FATAL("listen: %s", strerror(errno));
                return MSG_ERR_UNKNOWN;
diff --git a/utils/MsgJsonParser.cpp b/utils/MsgJsonParser.cpp
new file mode 100755 (executable)
index 0000000..2c1a8cb
--- /dev/null
@@ -0,0 +1,553 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <json-glib/json-glib.h>
+#include <json-glib/json-gobject.h>
+#include "MsgJsonParser.h"
+
+static char root_key[5] = "root";
+
+int msg_json_parser_get_value(msg_json_parser_object *json_obj)
+{
+       GValue value = { 0 };
+
+       /*Input params validation */
+       if (json_obj == NULL) {
+               MSG_DEBUG("Invalid Input Parameters");
+               return -1;
+       }
+
+       json_node_get_value((JsonNode *) json_obj->value, &value);
+
+       switch (json_node_get_value_type((JsonNode *) json_obj->value)) {
+       case G_TYPE_STRING:
+               {
+                       json_obj->type = MSG_JSON_PARSER_STRING;
+                       json_obj->value = (void *)g_value_get_string(&value);
+                       json_obj->number_value = 0;
+               }
+               break;
+       case G_TYPE_INT:
+               {
+                       json_obj->type = MSG_JSON_PARSER_INT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_int(&value);
+               }
+               break;
+       case G_TYPE_UINT:
+               {
+                       json_obj->type = MSG_JSON_PARSER_UINT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_uint(&value);
+               }
+               break;
+       case G_TYPE_BOOLEAN:
+               {
+                       json_obj->type = MSG_JSON_PARSER_BOOLEAN;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_boolean(&value);
+               }
+               break;
+       case G_TYPE_INT64:
+               {
+                       json_obj->type = MSG_JSON_PARSER_INT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_int64(&value);
+               }
+               break;
+       case G_TYPE_UINT64:
+               {
+                       json_obj->type = MSG_JSON_PARSER_UINT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_uint64(&value);
+               }
+               break;
+       case G_TYPE_DOUBLE:
+               {
+                       json_obj->type = MSG_JSON_PARSER_REAL;
+                       json_obj->value = NULL;
+                       json_obj->number_value = (double)g_value_get_double(&value);
+               }
+               break;
+       default:
+               {
+                       MSG_DEBUG(" Entering node default case");
+               }
+               break;
+       }
+
+       return 1;
+}
+
+int msg_json_parser_object_get_value(msg_json_parser_object *json_obj)
+{
+       GValue value = { 0 };
+       JsonNode *node = NULL;
+
+       /*Input params validation */
+       if (json_obj == NULL) {
+               MSG_DEBUG("Invalid Input Parameters");
+               return -1;
+       }
+       node = json_object_get_member((JsonObject *)json_obj->value, json_obj->key);
+
+       json_node_get_value((JsonNode *) node, &value);
+
+       switch (json_node_get_value_type((JsonNode *) node)) {
+       case G_TYPE_STRING:
+               {
+                       json_obj->type = MSG_JSON_PARSER_STRING;
+                       json_obj->value = (void *)g_value_get_string(&value);
+                       json_obj->number_value = 0;
+               }
+               break;
+       case G_TYPE_INT:
+               {
+                       json_obj->type = MSG_JSON_PARSER_INT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_int(&value);
+               }
+               break;
+       case G_TYPE_UINT:
+               {
+                       json_obj->type = MSG_JSON_PARSER_UINT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_uint(&value);
+               }
+               break;
+       case G_TYPE_BOOLEAN:
+               {
+                       json_obj->type = MSG_JSON_PARSER_BOOLEAN;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_boolean(&value);
+               }
+               break;
+       case G_TYPE_INT64:
+               {
+                       json_obj->type = MSG_JSON_PARSER_INT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_int64(&value);
+               }
+               break;
+       case G_TYPE_UINT64:
+               {
+                       json_obj->type = MSG_JSON_PARSER_UINT;
+                       json_obj->value = NULL;
+                       json_obj->number_value = g_value_get_uint64(&value);
+               }
+               break;
+       case G_TYPE_DOUBLE:
+               {
+                       json_obj->type = MSG_JSON_PARSER_REAL;
+                       json_obj->value = NULL;
+                       json_obj->number_value = (double)g_value_get_double(&value);
+               }
+               break;
+       default:
+               {
+                       MSG_DEBUG(" Entering node default case");
+               }
+               break;
+       }
+
+       return 1;
+}
+
+msg_json_parser_handle msg_json_parser_handle_create(void)
+{
+       JsonParser *jsonParser = NULL;
+
+       jsonParser = json_parser_new();
+
+       return(msg_json_parser_handle)jsonParser;
+}
+
+void msg_json_parser_handle_destory(msg_json_parser_handle *handle)
+{
+       if (handle == NULL)
+               return;
+
+       g_object_unref(*handle);
+       *handle = NULL;
+}
+
+void msg_json_parser_parse_buffer(msg_json_parser_handle handle, const char* value, int value_len, msg_json_parser_object *json_obj)
+{
+       gboolean gRet = TRUE;
+       JsonNode *root = NULL;
+       GError *error = NULL;
+       JsonParser *jsonParser = (JsonParser *)handle;
+       JsonNodeType parentType = JSON_NODE_NULL;
+
+       /*Input params validation*/
+       if (value == NULL || value_len == 0) {
+               MSG_DEBUG("Invalid Input Parameters");
+               return ;
+       }
+
+       if (jsonParser != NULL) {
+
+               /** Loads a JSON stream from a buffer and parses it */
+               gRet = json_parser_load_from_data(jsonParser, value, value_len, &error);
+               if (gRet != TRUE) {
+                       g_error_free(error);
+               } else {
+                       /** Fetch the root node */
+                       root = json_parser_get_root(jsonParser);
+
+                       if (root != NULL) {
+
+                               json_obj->key = root_key;
+                               json_obj->value = root;
+                               parentType = json_node_get_node_type(root);
+
+                               if (parentType == JSON_NODE_VALUE) {
+                                       gRet = msg_json_parser_get_value(json_obj);
+                               } else if (parentType == JSON_NODE_OBJECT) {
+                                       json_obj->type = MSG_JSON_PARSER_OBJECT;
+                               } else if (parentType == JSON_NODE_ARRAY) {
+                                       json_obj->type = MSG_JSON_PARSER_ARRAY;
+                               } else {
+                                       json_obj->type = MSG_JSON_PARSER_NULL;
+                               }
+                       } else {
+                               json_obj->key = NULL;
+                               json_obj->value = NULL;
+                       }
+               }
+       } else {
+
+       }
+
+       return ;
+}
+
+int msg_json_parser_get_next_child(const msg_json_parser_object *parent, msg_json_parser_object *child, int index)
+{
+       int lReturn = 1;
+       JsonNodeType jNodeParentType = JSON_NODE_NULL;
+       JsonNodeType jNodeChildType = JSON_NODE_NULL;
+       JsonArray *tempArray = NULL;
+       JsonObject *tempObj = NULL;
+       GList *members = NULL;
+
+       /*Input params validation */
+       if (parent == NULL || parent->value == NULL || child == NULL || index < 0) {
+               MSG_DEBUG("Invalid Input Parameters");
+               return 0;
+       }
+
+       /** Get the JSON Parent Node Type */
+       jNodeParentType = json_node_get_node_type((JsonNode *) parent->value);
+
+       switch (jNodeParentType) {
+       case JSON_NODE_OBJECT:
+               {
+                       /** Get the JSON object from JSON Parent Node */
+                       tempObj = json_node_get_object((JsonNode *) parent->value);
+
+                       /** Get the list of keys from the object node */
+                       members = json_object_get_members(tempObj);
+
+                       /** Get the key by index from the list */
+                       child->key = (char *)g_list_nth_data(members, index);
+
+                       g_list_free(members);
+                       if (child->key == NULL) {
+                               return 0;
+                       }
+
+                       /** Get the JSONNode by key from the list */
+                       child->value = json_object_get_member(tempObj, child->key);
+
+                       /** Identify the node type of the JSOSNNode */
+                       jNodeChildType = json_node_get_node_type((JsonNode *) child->value);
+
+                       switch (jNodeChildType) {
+                       case JSON_NODE_OBJECT:
+                               {
+                                       child->type = MSG_JSON_PARSER_OBJECT;
+                               }
+                               break;
+                       case JSON_NODE_ARRAY:
+                               {
+                                       child->type = MSG_JSON_PARSER_ARRAY;
+                               }
+                               break;
+                       case JSON_NODE_VALUE:
+                               {
+                                       lReturn = msg_json_parser_get_value(child);
+                               }
+                               break;
+                       case JSON_NODE_NULL:
+                               {
+                               }
+                               break;
+                       default:
+                               {
+                                       lReturn = 0;
+                               }
+                               break;
+                       }
+
+               }
+               break;
+       case JSON_NODE_ARRAY:
+               {
+                       /** Get the JSON array from the JSON node */
+                       tempArray = json_node_get_array((JsonNode *) parent->value);
+
+                       child->key = NULL;
+
+                       if ((guint) index >= json_array_get_length(tempArray)) {
+                               return 0;
+                       }
+
+                       /** Get the JSONNode from the list of values */
+                       child->value = (void *)json_array_get_element(tempArray, index);
+                       if (child->value == NULL) {
+                               return 0;
+                       }
+                       /* Get the child type */
+                       jNodeChildType = json_node_get_node_type((JsonNode *) child->value);
+
+                       switch (jNodeChildType) {
+                       case JSON_NODE_OBJECT:
+                               {
+                                       child->type = MSG_JSON_PARSER_OBJECT;
+                               }
+                               break;
+                       case JSON_NODE_ARRAY:
+                               {
+                                       child->type = MSG_JSON_PARSER_ARRAY;
+                               }
+                               break;
+                       case JSON_NODE_VALUE:
+                               {
+                                       lReturn = msg_json_parser_get_value(child);
+                               }
+                               break;
+                       case JSON_NODE_NULL:
+                               {
+                               }
+                               break;
+                       default:
+                               {
+                                       lReturn = 0;
+                                       break;
+                               }
+                       }
+
+               }
+               break;
+       case JSON_NODE_VALUE:
+       default:
+               {
+                       child->key = NULL;
+                       child->value = NULL;
+                       lReturn = 0;
+               }
+               break;
+       }
+
+       return lReturn;
+}
+
+
+/**
+ * @fn msg_json_parser_get_child_by_name
+ * This function is used for getting the child node by it's name for
+       input node.
+ * @param [IN] \n
+ * parent: msg_json_parser_object structure pointer whose child node
+       is to be retrieved \n
+ * name: const char pointer containing key of the required child \n
+ * @param [OUT] \n
+ * child: msg_json_parser_object structure pointer. Should be allocated
+       and freed after it's use by caller. It will be filled with
+       corresponding data \n
+ * @return     Return type is int. Should be typecasted to
+       msg_json_parser_parse_status to check the return status. If
+       MSG_JSON_PARSER_PARSE_SUCCESS, then only child contains
+       valid data, else some error occured. \n
+ * @remark This API is synchronous.
+ */
+int msg_json_parser_get_child_by_name(const msg_json_parser_object *parent,
+                                       msg_json_parser_object *child,
+                                       const char *name)
+{
+       int lReturn = -1;
+       JsonObject *tempObj = NULL;
+       JsonNodeType jNodeParentType = JSON_NODE_NULL;
+       JsonNodeType jNodeChildType = JSON_NODE_NULL;
+
+       /*Input params validation */
+       if (parent == NULL || parent->value == NULL || child == NULL
+           || name == NULL) {
+               MSG_DEBUG("Invalid Input Parameters");
+               return -1;
+       }
+
+       /** Get the JSON Parent Node Type */
+       jNodeParentType = json_node_get_node_type((JsonNode *) parent->value);
+
+       switch (jNodeParentType) {
+       case JSON_NODE_OBJECT:
+               {
+                       /** Get the JSON object from JSON Parent Node */
+                       tempObj =
+                           json_node_get_object((JsonNode *) parent->value);
+
+                       /** Get the list of keys from the object node */
+                       GList *members = json_object_get_members(tempObj);
+                       if (members == NULL) {
+                               return -1;
+                       }
+
+                       /** Get the key by index from the list */
+                       char *member = NULL;
+                       for (unsigned int i = 0; i < g_list_length(members); i++) {
+
+                               member = (char *)g_list_nth_data(members, i);
+
+                               if (g_strcmp0((char *)name, member) == 0) {
+                                       child->key      = member;
+                               }
+                       }
+
+                       g_list_free(members);
+
+                       if (child->key == NULL) {
+                               return -1;
+                       }
+
+                       /** Get the JSONNode by key from the list */
+                       child->value = (JsonNode *) json_object_get_member(tempObj,     child->key);
+
+                       /** Identify the node type of the JSOSNNode */
+                       jNodeChildType = json_node_get_node_type((JsonNode *) child->value);
+
+                       switch (jNodeChildType) {
+                       case JSON_NODE_OBJECT:
+                               {
+                                       child->type = MSG_JSON_PARSER_OBJECT;
+                               }
+                               break;
+                       case JSON_NODE_ARRAY:
+                               {
+                                       child->type = MSG_JSON_PARSER_ARRAY;
+                               }
+                               break;
+                       case JSON_NODE_VALUE:
+                               {
+                                       lReturn = msg_json_parser_get_value(child);
+                               }
+                               break;
+                       case JSON_NODE_NULL:
+                               {
+
+                               }
+                               break;
+                       default:
+                               {
+                                       lReturn = -1;
+                               }
+                               break;
+                       }
+
+               }
+               break;
+       case JSON_NODE_ARRAY:
+       case JSON_NODE_VALUE:
+       default:
+               {
+                       child->key = NULL;
+                       child->value = NULL;
+                       lReturn = -1;
+               }
+               break;
+       }
+
+       return lReturn;
+}
+
+#if 0
+/**
+ * @fn msg_json_parser_get_child_count
+ * This function returns the count for a specified JSON object.
+ * @param [IN] \n
+ * object: msg_json_parser_object structure pointer whose child count
+       is to be retrieved \n
+ * @return     Return type is int. This contains the value of the child node
+       for the specified JSON object \n
+ * @remark This API is synchronous.
+ */
+int msg_json_parser_get_child_count(msg_json_parser_object *object)
+{
+       JsonNodeType jNodeParentType = JSON_NODE_NULL;
+       JsonObject *tempObj = NULL;
+       JsonArray *tempArray = NULL;
+       int count = 0;
+
+       /*Input params validation */
+       if (object == NULL || object->value == NULL) {
+               MSG_DEBUG("Invalid Input Parameters");
+               return count;
+       }
+
+       /** Get the JSON Parent Node Type */
+       jNodeParentType = json_node_get_node_type((JsonNode *) object->value);
+
+       switch (jNodeParentType) {
+       case JSON_NODE_OBJECT:
+               {
+                       MSG_DEBUG("  JSON_NODE_OBJECT ");
+                       tempObj = NULL;
+                       /** Get the JSON object from JSON Parent Node */
+                       tempObj = json_node_get_object((JsonNode *) object->value);
+                       /** Get the number of members from the object node */
+                       count = json_object_get_size(tempObj);
+               }
+               break;
+       case JSON_NODE_ARRAY:
+               {
+                       MSG_DEBUG("  JSON_NODE_ARRAY ");
+                       tempArray = NULL;
+                       /** Get the JSON array from the JSON node */
+                       tempArray =
+                           json_node_get_array((JsonNode *) object->value);
+                       /** Get the number of members from the array node */
+                       count = json_array_get_length(tempArray);
+               }
+               break;
+       case JSON_NODE_VALUE:
+       default:
+               {
+
+               }
+               break;
+       }
+
+       MSG_DEBUG("COUNT :: %d ", count);
+       return count;
+}
+#endif
index 265b1ba..26255bb 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <malloc.h>
index eb81a6c..d40696b 100755 (executable)
@@ -1,26 +1,31 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
+#include <errno.h>
+#include <sys/stat.h>
 
 #include "MsgTypes.h"
 #include "MsgMmsTypes.h"
+#include "MsgUtilFile.h"
 #include "MsgMmsMessage.h"
+#include "MsgUtilFile.h"
+#include "MsgSmil.h"
 #include "MsgDebug.h"
 
 static void __release_glist_element(gpointer data, gpointer user_data);
@@ -390,7 +395,7 @@ bool _MsgMmsSetRootLayout(MMS_MESSAGE_DATA_S *pMsgData, MMS_SMIL_ROOTLAYOUT *pRo
        return true;
 }
 
-char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, size_t *pSize)
+char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, unsigned int *pSize)
 {
        MSG_BEGIN();
 
@@ -479,7 +484,7 @@ char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, size_t *pS
        memcpy(buf + offset , &filePathLen, sizeof(int));
 
        // copy file path
-       MSG_DEBUG("[#%2d][%5d] smilFilePath = %s, len = %d",serial_index++, offset, pMsgData->szSmilFilePath, filePathLen);
+       MSG_SEC_DEBUG("[#%2d][%5d] smilFilePath = %s, len = %d",serial_index++, offset, pMsgData->szSmilFilePath, filePathLen);
        offset += sizeof(int);
 
        if (filePathLen > 0) {
@@ -506,6 +511,7 @@ char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, size_t *pS
                                        MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
                                        memcpy(buf + offset, media, sizeof(MMS_MEDIA_S));
                                        offset += sizeof(MMS_MEDIA_S);
+                                       MSG_SEC_DEBUG("[#%2d][%5d][%d page][%d media] media type [%d],  drm type [%d], filepath [%s]", serial_index++, offset, pageIdx, i, media->mediatype, media->drmType, media->szFilePath);
                                }
                        }
 
@@ -547,6 +553,7 @@ char* _MsgMmsSerializeMessageData(const MMS_MESSAGE_DATA_S *pMsgData, size_t *pS
                        MMS_ATTACH_S *attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, i);
                        memcpy(buf + offset, attach, sizeof(MMS_ATTACH_S));
                        offset += sizeof(MMS_ATTACH_S);
+                       MSG_SEC_DEBUG("[#%2d][%5d][%d attach] attach filepath = %s, drm type = [%d]", serial_index++, offset, i, attach->szFilePath, attach->drmType);
                }
        }
 
@@ -669,9 +676,17 @@ bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pDa
 
                        offset += sizeof(MMS_MEDIA_S);
 
-                       pPage->medialist = g_list_append(pPage->medialist, pMedia);
+                       MSG_SEC_DEBUG("[#%2d][%5d][%d page][%d media] media type [%d], drm type [%d], filepath [%s], content type [%s]", serial_index++, offset, j, i, pMedia->mediatype, pMedia->drmType, pMedia->szFilePath, pMedia->szContentType);
+
+                       if (strlen(pMedia->szFilePath) >0) {
+                               pPage->medialist = g_list_append(pPage->medialist, pMedia);
+                       } else {
+                               free(pMedia);
+                       }
                }
 
+               pPage->mediaCnt = g_list_length(pPage->medialist);
+
                memcpy(&pPage->nDur , pData + offset, sizeof(int));
                offset += sizeof(int);
                memcpy(&pPage->nBegin , pData + offset, sizeof(int));
@@ -686,8 +701,17 @@ bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pDa
                offset += sizeof(int);
 
                pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
+//             if (pPage->medialist) {
+//                     pMsgData->pagelist = g_list_append(pMsgData->pagelist, pPage);
+//             } else {
+//                     free(pPage);
+//                     pPage = NULL;
+//             }
+
        }
 
+       pMsgData->pageCnt = g_list_length(pMsgData->pagelist);
+
        //Processing Region List
        memcpy(&pMsgData->regionCnt, pData + offset, sizeof(int));
        MSG_DEBUG("[#%2d][%5d] region count = %d",serial_index++, offset, pMsgData->regionCnt);
@@ -715,9 +739,17 @@ bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pDa
                memcpy(pAttach, pData + offset, sizeof(MMS_ATTACH_S));
                offset += sizeof(MMS_ATTACH_S);
 
-               pMsgData->attachlist = g_list_append(pMsgData->attachlist, pAttach);
+               MSG_SEC_DEBUG("[#%2d][%5d][%d attach] drm type [%d],  attach filepath = [%s], content type = [%s]", serial_index++, offset, i, pAttach->drmType, pAttach->szFilePath, pAttach->szContentType);
+               if (strlen(pAttach->szFilePath) >0)
+                       pMsgData->attachlist = g_list_append(pMsgData->attachlist, pAttach);
+               else {
+                       free(pAttach);
+                       pAttach = NULL;
+               }
        }
 
+       pMsgData->attachCnt = g_list_length(pMsgData->attachlist);
+
        //Processing Transition List
        memcpy(&pMsgData->transitionCnt, pData + offset, sizeof(int));
        MSG_DEBUG("[#%2d][%5d] transition count = %d",serial_index++, offset, pMsgData->transitionCnt);
@@ -772,3 +804,858 @@ bool _MsgMmsDeserializeMessageData(MMS_MESSAGE_DATA_S *pMsgData, const char *pDa
        return true;
 }
 
+void _MsgMmsAttachPrint(MMS_ATTACH_S *attach)
+{
+       if (attach == NULL) {
+               MSG_DEBUG("Invalid Parameter");
+               return;
+       }
+
+       MSG_DEBUG("%-25s : %d", "Attach Mimetype", attach->mediatype);
+       MSG_SEC_DEBUG("%-25s : %s", "Attach content type", attach->szContentType);
+       MSG_SEC_DEBUG("%-25s : %s", "Attach filename", attach->szFileName);
+       MSG_SEC_DEBUG("%-25s : %s", "Attach filepath", attach->szFilePath);
+       MSG_DEBUG("%-25s : %d", "Attach filesize", attach->fileSize);
+       MSG_DEBUG("%-25s : %d", "Attach drm type", attach->drmType);
+       MSG_SEC_DEBUG("%-25s : %s", "Attach drm filepath", attach->szDrm2FullPath);
+}
+
+void _MsgMmsMediaPrint(MMS_MEDIA_S *media)
+{
+       if (media == NULL) {
+               MSG_DEBUG("Invalid Parameter");
+               return;
+       }
+
+       if (media->mediatype == MMS_SMIL_MEDIA_INVALID) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_INVALID");
+       } else if (media->mediatype == MMS_SMIL_MEDIA_IMG) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_IMG");
+       } else if (media->mediatype == MMS_SMIL_MEDIA_AUDIO) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_AUDIO");
+       } else if (media->mediatype == MMS_SMIL_MEDIA_VIDEO) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_VIDEO");
+       } else if (media->mediatype == MMS_SMIL_MEDIA_TEXT) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_TEXT");
+       } else if (media->mediatype == MMS_SMIL_MEDIA_ANIMATE) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_ANIMATE");
+       } else if (media->mediatype == MMS_SMIL_MEDIA_IMG_OR_VIDEO) {
+               MSG_DEBUG("%-25s : %s", "Media type","MMS_SMIL_MEDIA_REF");
+       } else {
+               MSG_DEBUG("%-25s : Unknown [%d]", "Media type", media->mediatype);
+       }
+
+       MSG_DEBUG("%-25s : %s", "Media src", media->szSrc);
+       MSG_SEC_DEBUG("%-25s : %s", "Media filename", media->szFileName);
+       MSG_SEC_DEBUG("%-25s : %s", "Media filepath", media->szFilePath);
+       MSG_SEC_DEBUG("%-25s : %s", "Media content type", media->szContentType);
+       MSG_SEC_DEBUG("%-25s : %s", "Media content id", media->szContentID);
+       MSG_SEC_DEBUG("%-25s : %s", "Media content location", media->szContentLocation);
+       MSG_SEC_DEBUG("%-25s : %s", "Media region id", media->regionId);
+       MSG_DEBUG("%-25s : %s", "Media alt", media->szAlt);
+       MSG_DEBUG("%-25s : %d", "Media drm type", media->drmType);
+       MSG_SEC_DEBUG("%-25s : %s", "Media drm filepath", media->szDrm2FullPath);
+}
+
+void _MsgMmsPagePrint(MMS_PAGE_S *page)
+{
+       if (page == NULL) {
+               MSG_DEBUG("Invalid Parameter");
+               return;
+       }
+
+       MSG_DEBUG("%-25s : %d", "Page duration", page->nDur);
+
+       if (page->medialist) {
+               int list_count = g_list_length(page->medialist);
+               MSG_DEBUG("Media Count is [%d]", list_count);
+               for (int i = 0; i < list_count; i++) {
+                       MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, i);
+                       if (media) {
+                               MSG_DEBUG("[%d]th Media", i);
+                               _MsgMmsMediaPrint(media);
+                       } else {
+                               MSG_DEBUG("Not Exist Media Data in [%d]th", i);
+                       }
+
+               }
+       }
+}
+
+void _MsgMmsPrint(MMS_MESSAGE_DATA_S *pMsgData)
+{
+       if (pMsgData == NULL) {
+               MSG_DEBUG("Invalid Parameter");
+               return;
+       }
+
+       if (pMsgData->pagelist) {
+               int list_count = g_list_length(pMsgData->pagelist);
+               MSG_DEBUG("Page Count is [%d]", list_count);
+               for (int i = 0; i < list_count; i++) {
+                       MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, i);
+                       if (page) {
+                               MSG_DEBUG("[%d]th Page", i);
+                               _MsgMmsPagePrint(page);
+                       } else {
+                               MSG_DEBUG("Not Exist Page Data in [%d]th", i);
+                       }
+
+               }
+       }
+
+       if (pMsgData->attachlist) {
+               int list_count = g_list_length(pMsgData->attachlist);
+               MSG_DEBUG("Attach Count is [%d]", list_count);
+               for (int i = 0; i < list_count; i++) {
+                       MMS_ATTACH_S *attach = (MMS_ATTACH_S *)g_list_nth_data(pMsgData->attachlist, i);
+                       if (attach) {
+                               MSG_DEBUG("[%d]th Attach", i);
+                               _MsgMmsAttachPrint(attach);
+                       } else {
+                               MSG_DEBUG("Not Exist Attach Data in [%d]th", i);
+                       }
+               }
+       }
+
+}
+
+MMS_ADDRESS_DATA_S *MsgMmsCreateAddress(int addressType, const char *addressVal)
+{
+       MMS_ADDRESS_DATA_S * pMmsAddressData = (MMS_ADDRESS_DATA_S * )calloc(1, sizeof(MMS_ADDRESS_DATA_S));
+       pMmsAddressData->address_type = addressType;
+       pMmsAddressData->address_val = strdup(addressVal);
+       return pMmsAddressData;
+}
+
+void MsgMmsReleaseAddress(MMS_ADDRESS_DATA_S **ppMmsAddressData)
+{
+       if (ppMmsAddressData && *ppMmsAddressData) {
+               MMS_ADDRESS_DATA_S *pMmsAddressData = *ppMmsAddressData;
+
+               if (pMmsAddressData->address_val) {
+                       free(pMmsAddressData->address_val);
+                       pMmsAddressData->address_val = NULL;
+               }
+
+               free(pMmsAddressData);
+               *ppMmsAddressData = NULL;
+       }
+}
+
+void MsgMmsInitMultipart(MMS_MULTIPART_DATA_S *pMmsMultipart)
+{
+       if (pMmsMultipart) {
+               pMmsMultipart->type = MIME_UNKNOWN;
+               pMmsMultipart->szContentType[0] = '\0';
+               pMmsMultipart->szFileName[0] = '\0';
+               pMmsMultipart->szContentID[0] = '\0';
+               pMmsMultipart->szContentLocation[0] = '\0';
+               pMmsMultipart->drmType = MSG_DRM_TYPE_NONE;
+               pMmsMultipart->szFilePath[0] = '\0';
+               pMmsMultipart->pMultipartData = NULL;
+               pMmsMultipart->nMultipartDataLen = 0;
+               pMmsMultipart->tcs_bc_level = -1;
+               pMmsMultipart->malware_allow = 0;
+               pMmsMultipart->szThumbFilePath[0] = '\0';
+       }
+}
+
+MMS_MULTIPART_DATA_S *MsgMmsCreateMultipart()
+{
+       MMS_MULTIPART_DATA_S *pMmsMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
+       if (pMmsMultipart) {
+               pMmsMultipart->type = MIME_UNKNOWN;
+               pMmsMultipart->szContentType[0] = '\0';
+               pMmsMultipart->szFileName[0] = '\0';
+               pMmsMultipart->szContentID[0] = '\0';
+               pMmsMultipart->szContentLocation[0] = '\0';
+               pMmsMultipart->drmType = MSG_DRM_TYPE_NONE;
+               pMmsMultipart->szFilePath[0] = '\0';
+               pMmsMultipart->pMultipartData = NULL;
+               pMmsMultipart->nMultipartDataLen = 0;
+               pMmsMultipart->tcs_bc_level = -1;
+               pMmsMultipart->malware_allow = 0;
+               pMmsMultipart->szThumbFilePath[0] = '\0';
+       }
+
+       return pMmsMultipart;
+}
+
+void MsgMmsReleaseMultipart(MMS_MULTIPART_DATA_S **ppMmsMultipart)
+{
+       if (ppMmsMultipart && *ppMmsMultipart) {
+               MMS_MULTIPART_DATA_S *pDelMmsMultipart = *ppMmsMultipart;
+
+               if (pDelMmsMultipart->pMultipartData != NULL) {
+                       g_free(pDelMmsMultipart->pMultipartData);
+                       pDelMmsMultipart->pMultipartData = NULL;
+               }
+               g_free(pDelMmsMultipart);
+               *ppMmsMultipart = NULL;
+       }
+}
+
+void MsgMmsInitHeader(MMS_HEADER_DATA_S *pMmsHeaderData)
+{
+       if (pMmsHeaderData) {
+               pMmsHeaderData->bcc = NULL;
+               pMmsHeaderData->cc = NULL;
+               pMmsHeaderData->contentLocation[0] = '\0';
+               pMmsHeaderData->szContentType[0] = '\0';
+               pMmsHeaderData->date = 0;
+               pMmsHeaderData->bDeliveryReport = false;
+               pMmsHeaderData->delivery.type = MMS_TIMETYPE_NONE;
+               pMmsHeaderData->delivery.time = 0;
+               pMmsHeaderData->expiry.type = MMS_TIMETYPE_NONE;
+               pMmsHeaderData->expiry.time = 0;
+               pMmsHeaderData->szFrom[0] = '\0';
+               pMmsHeaderData->messageClass = -1;
+               pMmsHeaderData->messageID[0]= '\0';
+               pMmsHeaderData->messageType = -1;
+               pMmsHeaderData->mmsVersion = -1;
+               pMmsHeaderData->messageSize = 0;
+               pMmsHeaderData->mmsPriority = -1;
+               pMmsHeaderData->bReadReport = 0;
+               pMmsHeaderData->bHideAddress = false;
+               pMmsHeaderData->mmsStatus = MSG_DELIVERY_REPORT_NONE;
+               pMmsHeaderData->szSubject[0] = '\0';
+               pMmsHeaderData->to = NULL;
+               pMmsHeaderData->trID[0] = '\0';
+               pMmsHeaderData->contentClass = -1;
+       }
+}
+
+MMS_HEADER_DATA_S *MsgMmsCreateHeader()
+{
+        MMS_HEADER_DATA_S *pMmsHeaderData = (MMS_HEADER_DATA_S * )calloc(1, sizeof(MMS_HEADER_DATA_S));
+        pMmsHeaderData->bcc = NULL;//  Bcc
+        pMmsHeaderData->cc = NULL;//   Cc
+        pMmsHeaderData->contentLocation[0] = '\0';
+        pMmsHeaderData->szContentType[0] = '\0';
+        pMmsHeaderData->date = 0;
+        pMmsHeaderData->bDeliveryReport = false; //    X-Mms-Delivery-Report
+        pMmsHeaderData->delivery.type = MMS_TIMETYPE_NONE;
+        pMmsHeaderData->delivery.time = 0;
+        pMmsHeaderData->expiry.type = MMS_TIMETYPE_NONE;
+        pMmsHeaderData->expiry.time = 0;
+        pMmsHeaderData->szFrom[0] = '\0';//    From
+        pMmsHeaderData->messageClass = -1;//Personal | Advertisement | Informational | Auto
+        pMmsHeaderData->messageID[0]= '\0';
+        pMmsHeaderData->messageType = -1;//MmsMsgType : ex) sendreq
+        pMmsHeaderData->mmsVersion = -1;//1.0 1.3
+        pMmsHeaderData->messageSize = 0; //    X-Mms-Message-Size
+        pMmsHeaderData->mmsPriority = -1;//_MSG_PRIORITY_TYPE_E : Low | Normal | High
+        pMmsHeaderData->bReadReport = 0;//     X-Mms-Read-Report
+        //     X-Mms-Report-Allowed
+        //     X-Mms-Response-Status
+        //     X-Mms-Response-Text
+        pMmsHeaderData->bHideAddress = false;//        X-Mms-Sender-Visibility
+        pMmsHeaderData->mmsStatus = MSG_DELIVERY_REPORT_NONE;//        X-Mms-Status
+        pMmsHeaderData->szSubject[0] = '\0';// Subject
+        pMmsHeaderData->to = NULL;//   To
+        pMmsHeaderData->trID[0] = '\0';
+        //     X-Mms-Retrieve-Status
+        //     X-Mms-Retrieve-Text
+        //     X-Mms-Read-Status
+        //     X-Mms-Reply-Charging
+        //     X-Mms-Reply-Charging-Deadline
+        //     X-Mms-Reply-Charging-ID
+        //     X-Mms-Reply-Charging-Size
+        //     X-Mms-Previously-Sent-By
+        //     X-Mms-Previously-Sent-Date
+        //     X-Mms-Store
+        //     X-Mms-MM-State
+        //     X-Mms-MM-Flags
+        //     X-Mms-Store-Status
+        //     X-Mms-Store-Status-Text
+        //     X-Mms-Stored
+        //     X-Mms-Attributes
+        //     X-Mms-Totals
+        //     X-Mms-Mbox-Totals
+        //     X-Mms-Quotas
+        //     X-Mms-Mbox-Quotas
+        //     X-Mms-Message-Count
+        //     Content
+        //     X-Mms-Start
+        //     Additional-headers
+        //     X-Mms-Distribution-Indicator
+        //     X-Mms-Element-Descriptor
+        //     X-Mms-Limit
+        //     X-Mms-Recommended-Retrieval-Mode
+        //     X-Mms-Recommended-Retrieval-Mode-Text
+        //     X-Mms-Status-Text
+        //     X-Mms-Applic-ID
+        //     X-Mms-Reply-Applic-ID
+        //     X-Mms-Aux-Applic-Info
+        pMmsHeaderData->contentClass = -1;//text | image-basic| image-rich | video-basic | video-rich | megapixel | content-basic | content-rich
+        //     X-Mms-DRM-Content
+        //     X-Mms-Adaptation-Allowed
+        //     X-Mms-Replace-ID
+        //     X-Mms-Cancel-ID
+        //     X-Mms-Cancel-Status
+
+       return pMmsHeaderData;
+}
+
+void MsgMmsReleaseHeader(MMS_HEADER_DATA_S **ppMmHeadersData)
+{
+       if (ppMmHeadersData && *ppMmHeadersData) {
+               MMS_HEADER_DATA_S *pMmsHeaderData = *ppMmHeadersData;
+
+               free(pMmsHeaderData);
+
+               *ppMmHeadersData = NULL;
+       }
+}
+
+MMS_DATA_S *MsgMmsCreate()
+{
+       MMS_DATA_S * mms_data = (MMS_DATA_S * )calloc(1, sizeof(MMS_DATA_S));
+       return mms_data;
+}
+
+void MsgMmsRelease(MMS_DATA_S **ppMmsData)
+{
+       if (ppMmsData && *ppMmsData) {
+               MMS_DATA_S *pMmsData = *ppMmsData;
+
+               if (pMmsData->header)
+                       MsgMmsReleaseHeader(&pMmsData->header);
+
+               if (pMmsData->smil)
+                       MsgMmsReleaseMultipart(&pMmsData->smil);
+
+               MsgMmsReleaseMultipartList(&pMmsData->multipartlist);
+
+               free(pMmsData);
+
+               *ppMmsData = NULL;
+       }
+}
+
+static void __freeMultipartListItem(gpointer data)
+{
+       MMS_MULTIPART_DATA_S * pMultipart = (MMS_MULTIPART_DATA_S *)data;
+
+       if (pMultipart) {
+               MsgMmsReleaseMultipart(&pMultipart);
+       }
+}
+
+int MsgMmsReleaseMultipartList(MMSList **ppMultipartList)
+{
+       if (ppMultipartList && *ppMultipartList) {
+               g_list_free_full(*ppMultipartList, __freeMultipartListItem);
+               *ppMultipartList = NULL;
+       }
+
+       return 0;
+}
+
+static void __freeAddressListItem(gpointer data)
+{
+       MMS_ADDRESS_DATA_S * pAddressData = (MMS_ADDRESS_DATA_S *)data;
+
+       MsgMmsReleaseAddress(&pAddressData);
+
+}
+
+int MsgMmsReleaseAddressList(MMSList **ppAddressList)
+{
+       if (ppAddressList && *ppAddressList) {
+               g_list_free_full(*ppAddressList, __freeAddressListItem);
+               *ppAddressList = NULL;
+       }
+
+       return 0;
+}
+
+static void removeLessGreaterMark(const char *szSrcID, char *szDest, int destSize)
+{
+       char szBuf[MSG_MSG_ID_LEN + 1] = {0, };
+       int cLen = strlen(szSrcID);
+
+       if (cLen > 1 && szSrcID[0] == '<' && szSrcID[cLen - 1] == '>') {
+               strncpy(szBuf, &szSrcID[1], cLen - 2);
+               szBuf[cLen - 2] = '\0';
+       } else if (cLen > 1 && szSrcID[0] == '"' && szSrcID[cLen-1] == '"') {
+               strncpy(szBuf, &szSrcID[1], cLen - 2);
+               szBuf[cLen - 2] = '\0';
+       } else {
+               strncpy(szBuf, szSrcID, cLen);
+               szBuf[cLen] = '\0';
+       }
+
+       snprintf(szDest, destSize, "%s", szBuf);
+}
+
+static bool IsMatchedMedia(MMS_MEDIA_S *media, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       if (strlen(pMultipart->szContentID) > 0) {
+
+               char szTempContentID[MSG_MSG_ID_LEN + 1] = {0,};
+               removeLessGreaterMark(pMultipart->szContentID, szTempContentID, sizeof(szTempContentID));
+
+               if (strcmp(media->szContentID,  szTempContentID) == 0) {
+                       return true;
+               }
+
+               if (strcmp(media->szContentLocation,  szTempContentID) == 0) {
+                       return true;
+               }
+       }
+
+       if (strlen(pMultipart->szContentLocation) > 0) {
+               if (strcmp(media->szContentID,  pMultipart->szContentLocation) == 0) {
+                       return true;
+               }
+
+               if (strcmp(media->szContentLocation,  pMultipart->szContentLocation) == 0) {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static bool MmsFindAndInsertPart(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       bool insert_media = false;
+
+       if (pMsgData->pagelist) {
+               for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
+
+                       MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
+
+                       if (page && page->medialist) {
+
+                               for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
+
+                                       MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
+
+                                       if (media) { // add media
+                                               if (IsMatchedMedia(media, pMultipart) == true) { //matched media
+                                                       insert_media = true;
+                                                       media->drmType = pMultipart->drmType;
+                                                       snprintf(media->szFilePath, sizeof(media->szFilePath), "%s", pMultipart->szFilePath);
+                                                       snprintf(media->szFileName, sizeof(media->szFileName), "%s", pMultipart->szFileName);
+                                                       snprintf(media->szContentID, sizeof(media->szContentID), "%s", pMultipart->szContentID);
+                                                       snprintf(media->szContentLocation, sizeof(media->szContentLocation), "%s", pMultipart->szContentLocation);
+                                                       snprintf(media->szContentType, sizeof(media->szContentType), "%s", pMultipart->szContentType);
+                                                       MSG_SEC_DEBUG("InsertPart to pageIndx [%d] mediaIdx[%d] media[%p] : path = [%s], name = [%s], cid = [%s], cl = [%s], ct = [%s]"\
+                                                                       , pageIdx, mediaIdx, media, media->szFilePath, media->szFileName, media->szContentID, media->szContentLocation, media->szContentType);
+                                               }
+                                       }
+                               } //end for media list
+                       }
+               } //end for page list
+       }
+
+       return insert_media;
+}
+
+static bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       MSG_BEGIN();
+
+       bool isInsert = false;
+
+       if (pMsgData == NULL || pMultipart == NULL) {
+               return false;
+       }
+
+       isInsert = MmsFindAndInsertPart(pMsgData, pMultipart);
+
+       if (isInsert == false) {
+               MMS_ATTACH_S *attachment = NULL;
+               attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
+               attachment->drmType = pMultipart->drmType;
+               attachment->mediatype = pMultipart->type;
+               snprintf(attachment->szContentType, sizeof(attachment->szContentType), "%s", pMultipart->szContentType);
+               snprintf(attachment->szFilePath, sizeof(attachment->szFilePath), "%s", pMultipart->szFilePath);
+               snprintf(attachment->szFileName, sizeof(attachment->szFileName), "%s", pMultipart->szFileName);
+               attachment->fileSize = MsgGetFileSize(attachment->szFilePath);
+               MSG_SEC_DEBUG("Insert Attach to attachment[%p] : path = [%s], name = [%s], ct = [%s], size = [%d]"\
+                                               , attachment, attachment->szFilePath, attachment->szFileName, attachment->szContentType, attachment->fileSize);
+
+               if (_MsgMmsAddAttachment(pMsgData, attachment) != MSG_SUCCESS) {
+                       g_free(attachment);
+                       return false;
+               }
+       }
+
+       MSG_END();
+       return true;
+}
+
+int MsgMmsConvertMmsDataToMmsMessageData(MMS_DATA_S *pSrc, MMS_MESSAGE_DATA_S *pDst)
+{
+       MSG_BEGIN();
+
+       bzero(pDst, sizeof(MMS_MESSAGE_DATA_S));
+
+       if (pSrc->smil) {
+               if (MsgAccessFile(pSrc->smil->szFilePath, F_OK)) {
+                       gchar *contents = NULL;
+                       gsize length = 0;
+
+                       g_file_get_contents(pSrc->smil->szFilePath, &contents, &length, NULL);
+
+                       if (contents) {
+                               MsgSmilParseSmilDoc(pDst, contents);
+                               g_free(contents);
+                       }
+               } else {
+                       if (pSrc->smil->pMultipartData) {
+                               char *smil_data = (char *)calloc(1, sizeof(char)*(pSrc->smil->nMultipartDataLen + 1));
+                               if (smil_data) {
+                                       memcpy(smil_data, pSrc->smil->pMultipartData, pSrc->smil->nMultipartDataLen);
+                                       MsgSmilParseSmilDoc(pDst, smil_data);
+                                       g_free(smil_data);
+                               }
+                       }
+               }
+       }
+
+       int len = g_list_length(pSrc->multipartlist);
+       for (int i = 0; i < len; i++) {
+               MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pSrc->multipartlist, i);
+               if (multipart) {
+                       MmsInsertPartToMmsData(pDst, multipart);
+               }
+       }
+
+       MSG_END();
+       return 0;
+}
+
+int MsgMmsConvertMmsMessageDataToMmsData(MMS_MESSAGE_DATA_S *pSrc, MMS_DATA_S *pDst)
+{
+       MSG_BEGIN();
+
+       char *pRawData = NULL;
+
+       pDst->backup_type = pSrc->backup_type;
+
+       int pageCnt = _MsgMmsGetPageCount(pSrc);
+       if (pSrc->smil.szFilePath[0] != '\0') {
+               MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+               memcpy(pMultipart, &pSrc->smil, sizeof(MMS_MULTIPART_DATA_S));
+               pDst->smil = pMultipart;
+       } else if (pageCnt > 0 ) {      // Multipart related
+
+               MsgSmilGenerateSmilDoc(pSrc, &pRawData);
+               if (pRawData) {
+                       MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+
+                       MSG_DEBUG("%s", pRawData);
+
+                       //g_file_set_contents ("/tmp/smil.smil", pRawData, strlen(pRawData), NULL);
+                       pMultipart->pMultipartData = pRawData;
+                       pMultipart->nMultipartDataLen = strlen(pRawData);
+                       pMultipart->type = MIME_APPLICATION_SMIL;
+                       snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", "application/smil");
+//                     snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", "/tmp/smil.smil");
+//                     snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", "smil.smil");
+
+                       pDst->smil = pMultipart;
+
+               } else {
+                       MSG_DEBUG("Fail to Generate SmilDoc");
+               }
+       }
+
+       for (int i = 0; i < pageCnt; ++i) {
+               MMS_PAGE_S *pPage = _MsgMmsGetPage(pSrc, i);
+               int mediaCnt = pPage->mediaCnt;
+               MSG_DEBUG("PAGE %d's media Cnt: %d", i+1, mediaCnt);
+
+               for (int j = 0; j < mediaCnt; ++j) {
+                       MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
+                       if (pMedia->szFilePath[0] != 0) {
+                               MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+
+                               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szContentID);
+                               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szContentLocation);
+                               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
+                               snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
+                               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
+
+                               pDst->multipartlist = g_list_append(pDst->multipartlist, pMultipart);
+                       }
+               }
+       }
+
+       //Processing Attachment List
+       for (int i = 0; i < _MsgMmsGetAttachCount(pSrc); ++i) {
+               MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pSrc, i);
+               if (pMedia->szFilePath[0] != 0) {
+                       MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+
+                       snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szFileName);
+                       snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szFileName);
+                       snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
+                       snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
+                       snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
+
+                       pDst->multipartlist = g_list_append(pDst->multipartlist, pMultipart);
+               }
+       }
+
+       MSG_END();
+
+       return 0;
+}
+
+int MsgMmsGetSmilMultipart(MMSList *pMultipartList, MMS_MULTIPART_DATA_S **smil_multipart)
+{
+       const char *smil_content_type = "application/smil";
+
+       int len = g_list_length(pMultipartList);
+
+       for (int i = 0; i < len; i++) {
+               MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMultipartList, i);
+
+               if (multipart) {
+
+                       if (strcasecmp(multipart->szContentType, smil_content_type) == 0 ) {
+                               *smil_multipart = multipart;
+                               break;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+//get content from filepath and save to pMultipartData
+int MsgMmsSetMultipartData(MMS_MULTIPART_DATA_S *pMultipart)
+{
+       if (pMultipart->pMultipartData != NULL)
+               return 0;
+
+       if (g_file_get_contents(pMultipart->szFilePath, &pMultipart->pMultipartData, &pMultipart->nMultipartDataLen, NULL) == false)
+               return -1;
+
+       //Due to Get data for Backup message
+       //memset(pMultipart->szFilePath, 0x00, sizeof(pMultipart->szFilePath));
+       return 0;
+}
+
+int MsgMmsSetMultipartListData(MMS_DATA_S *pMmsData)
+{
+       MSG_BEGIN();
+
+       MMSList *multipart_list = pMmsData->multipartlist;
+
+       if (multipart_list) {
+
+               if (pMmsData->smil) {
+                       MsgMmsSetMultipartData(pMmsData->smil);
+               }
+
+               for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+
+                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+
+                       if (pMultipart) {
+                               MsgMmsSetMultipartData(pMultipart);//app file -> data
+                       }
+               }
+       }
+
+       MSG_END();
+       return 0;
+}
+
+//pMultipartData set to file path
+int MsgMmsSetMultipartFilePath(const char *dirPath, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       if (g_file_test(dirPath, G_FILE_TEST_IS_DIR) != true) {
+               MSG_SEC_DEBUG("g_file_test is false: [%s] is not dir or not exist", dirPath);
+               return -1;
+       }
+
+       memset(pMultipart->szFilePath, 0x00, sizeof(pMultipart->szFilePath));
+
+       snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s/%s", dirPath, pMultipart->szFileName);
+
+       if (!MsgCreateFile (pMultipart->szFilePath, pMultipart->pMultipartData, pMultipart->nMultipartDataLen)) {
+               MSG_SEC_DEBUG("Fail to set content to file [%s]", pMultipart->szFilePath);
+               return -1;
+       }
+
+       return 0;
+}
+
+int MsgMmsSetMultipartListFilePath(const char *dirPath, MMS_DATA_S *pMmsData)
+{
+       MSG_BEGIN();
+
+       char working_dir[MSG_FILENAME_LEN_MAX+1] = {0,};
+
+       snprintf(working_dir, sizeof(working_dir), "%s", dirPath);
+
+       if (mkdir(working_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+               if (errno == EEXIST) {
+                       MSG_SEC_DEBUG("exist dir : [%s]", working_dir);
+               } else {
+                       MSG_SEC_DEBUG("Fail to Create Dir [%s]", working_dir);
+                       return -1;
+               }
+       }
+
+       MMSList *multipart_list = pMmsData->multipartlist;
+
+       if (pMmsData->smil) {
+               snprintf(pMmsData->smil->szFileName, sizeof(pMmsData->smil->szFileName), "%s", "smil.smil");
+               MsgMmsSetMultipartFilePath(dirPath, pMmsData->smil);
+       }
+
+       if (multipart_list) {
+
+               for (int i = 0; i < (int)g_list_length(multipart_list); i++) {
+
+                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(multipart_list, i);
+
+                       if (pMultipart) {
+                               MsgMmsSetMultipartFilePath(dirPath, pMultipart);//data -> svc file
+                       }
+               }
+       }
+
+       MSG_END();
+       return 0;
+}
+
+int printMultipart(MMS_MULTIPART_DATA_S *multipart)
+{
+       if (multipart) {
+               MSG_DEBUG("multipart ptr [%p]", multipart);
+               MSG_DEBUG("type : %d", multipart->type);
+               MSG_DEBUG("type str : %s", multipart->szContentType);
+               MSG_DEBUG("cid : %s", multipart->szContentID);
+               MSG_DEBUG("cl : %s", multipart->szContentLocation);
+               MSG_DEBUG("name : %s", multipart->szFileName);
+               MSG_DEBUG("filepath : %s", multipart->szFilePath);
+               MSG_DEBUG("tcs_bc_level : %d", multipart->tcs_bc_level);
+               MSG_DEBUG("malware_allow : %d", multipart->malware_allow);
+               MSG_DEBUG("thumbfilepath : %s", multipart->szThumbFilePath);
+       }
+       return 0;
+}
+
+int printMultipartList(MMSList *pMultipartList)
+{
+       int len = g_list_length(pMultipartList);
+
+       for (int i = 0; i < len; i++) {
+               MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMultipartList, i);
+
+               if (multipart) {
+                       MSG_DEBUG("[%d] multipart ptr [%p]", i,  multipart);
+                       MSG_DEBUG("type : %d", multipart->type);
+                       MSG_DEBUG("type str : %s", multipart->szContentType);
+                       MSG_DEBUG("cid : %s", multipart->szContentID);
+                       MSG_DEBUG("cl : %s", multipart->szContentLocation);
+                       MSG_DEBUG("name : %s", multipart->szFileName);
+                       MSG_DEBUG("filepath : %s", multipart->szFilePath);
+                       MSG_DEBUG("tcs_bc_level : %d", multipart->tcs_bc_level);
+                       MSG_DEBUG("malware_allow : %d", multipart->malware_allow);
+                       MSG_DEBUG("thumbfilepath : %s", multipart->szThumbFilePath);
+               }
+       }
+
+       return 0;
+}
+
+void _MsgMmsMultipartPrint(MMS_MULTIPART_DATA_S *multipart)
+{
+       if (multipart == NULL) {
+               MSG_DEBUG("Invalid Parameter");
+               return;
+       }
+
+       MSG_DEBUG("%-25s : %d", "Multipart type", multipart->type);
+       MSG_SEC_DEBUG("%-25s : %s", "Multipart filename", multipart->szFileName);
+       MSG_SEC_DEBUG("%-25s : %s", "Multipart filepath", multipart->szFilePath);
+       MSG_SEC_DEBUG("%-25s : %s", "Multipart content type", multipart->szContentType);
+       MSG_SEC_DEBUG("%-25s : %s", "Multipart content id", multipart->szContentID);
+       MSG_SEC_DEBUG("%-25s : %s", "Multipart content location", multipart->szContentLocation);
+       MSG_DEBUG("%-25s : %d", "Multipart drm type", multipart->drmType);
+
+}
+
+bool  _MsgMmsRemoveEmptyMedia(MMS_PAGE_S *pPage)
+{
+       MMS_MEDIA_S *pMedia = NULL;
+
+       int mediaCnt  = g_list_length(pPage->medialist);
+
+       for (int i = 0; i < mediaCnt; i++) {
+
+               GList *nth = g_list_nth(pPage->medialist, i);
+
+               if (nth == NULL)
+                       return false;
+
+               pMedia = (MMS_MEDIA_S *)nth->data;
+
+               if (pMedia == NULL)
+                       continue;
+
+               if (strlen(pMedia->szFilePath) == 0) {
+                       MSG_DEBUG("Found Empty Media [%d]", i);
+
+                       g_free(pMedia);
+
+                       nth->data = NULL;
+               }
+
+       }
+
+       pPage->medialist = g_list_remove_all(pPage->medialist, NULL);
+
+       pPage->mediaCnt = g_list_length(pPage->medialist);
+
+       return true;
+}
+
+//remove media object with no filepath
+bool _MsgMmsRemoveEmptyObject(MMS_MESSAGE_DATA_S *pMmsMsg)
+{
+       MMS_PAGE_S *pPage;
+
+       int pageCnt = g_list_length(pMmsMsg->pagelist);
+
+       for (int i = 0; i < pageCnt; i++) {
+
+               GList *nth = g_list_nth(pMmsMsg->pagelist, i);
+
+               if (nth == NULL)
+                       return false;
+
+               pPage = (MMS_PAGE_S *)nth->data;
+
+               if (pPage == NULL)
+                       continue;
+
+               _MsgMmsRemoveEmptyMedia(pPage);
+
+//             if (g_list_length(pPage->medialist) == 0) {
+//
+//                     MSG_DEBUG("Found Empty Page [%d]", i);
+//
+//                     g_free(pPage);
+//
+//                     nth->data = NULL;
+//             }
+       }
+
+       pMmsMsg->pagelist = g_list_remove_all(pMmsMsg->pagelist, NULL);
+
+       pMmsMsg->pageCnt = g_list_length(pMmsMsg->pagelist);
+
+       return true;
+}
index fb6199e..a2085ad 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <fcntl.h>     /* O_RDWR */
diff --git a/utils/MsgNotificationWrapper.cpp b/utils/MsgNotificationWrapper.cpp
deleted file mode 100755 (executable)
index 933ee37..0000000
+++ /dev/null
@@ -1,1315 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include "MsgDebug.h"
-#include "MsgContact.h"
-#include "MsgStorageTypes.h"
-#include "MsgUtilStorage.h"
-#include "MsgGconfWrapper.h"
-#include "MsgNotificationWrapper.h"
-
-extern "C"
-{
-       #include <notification.h>
-       #include <appsvc.h>
-}
-
-/*==================================================================================================
-                                     FUNCTION IMPLEMENTATION
-==================================================================================================*/
-void MsgSmsClass0Noti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
-{
-       MSG_BEGIN();
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       char tempId[6];
-
-       memset(tempId, 0x00, sizeof(tempId));
-
-       appsvc_set_appid(args, "org.tizen.msg-ui-class0");
-
-       noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-       }
-
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-       }
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New CLASS 0 Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       if (pMsg->addressList[0].displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set time.
-       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
-
-       // set led.
-       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-       bundle_add(args, "type", "new_msg");
-
-       snprintf(tempId, 5, "%d", pMsg->msgId);
-       bundle_add(args, "msgId", tempId);
-
-       MSG_END();
-}
-
-
-void MsgSmsMWINoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
-{
-       MSG_BEGIN();
-
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-
-       appsvc_set_appid(args, "org.tizen.call");
-
-       noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-       }
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "MWI Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New MWI Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-       }
-
-       if (pMsg->addressList[0].displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set time.
-       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
-
-       // set led.
-       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-       bundle_add(args, "launch-type", "MO");
-       bundle_add(args, "number", pMsg->addressList[0].addressVal);
-
-       MSG_END();
-}
-
-
-void MsgSmsVoiceNoti(MSG_MESSAGE_INFO_S* pMsg)
-{
-       MSG_BEGIN();
-
-       int notiId = 0;
-       notification_h noti = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       bundle* args;
-
-       args = bundle_create();
-
-       notiId = MsgSettingGetInt(VOICE_NOTI_ID_1);
-
-       if (notiId > 0) {
-               noti = notification_load(NULL, notiId);
-               if (noti == NULL)
-                       MSG_DEBUG("notification_load is failed.");
-       }
-
-       if (noti == NULL) {
-               noti = notification_create(NOTIFICATION_TYPE_NOTI);
-               if (noti == NULL) {
-                       MSG_DEBUG("notification_new is failed.");
-                       if (args != NULL) bundle_free(args);
-                       return;
-               }
-
-               notiId = 0;
-       }
-
-       appsvc_set_appid(args, "org.tizen.call");
-
-       noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-       }
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Voicemail", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Voicemail", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-       }
-
-       if (pMsg->addressList[0].displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set time.
-       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
-
-       // set led.
-       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-       bundle_add(args, "launch-type", "MO");
-       bundle_add(args, "number", pMsg->addressList[0].addressVal);
-
-       if (args != NULL) {
-               noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_execute_option : %d", noti_err);
-               }
-       }
-
-       if (notiId > 0) {
-               noti_err = notification_update(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_update");
-               }
-       } else {
-               noti_err = notification_insert(noti, &notiId);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_insert");
-               }
-
-               if (MsgSettingSetInt(VOICE_NOTI_ID_1, notiId) == MSG_SUCCESS)
-                       MSG_DEBUG("Insert VOICE_NOTI_ID_1 [%d]", notiId);
-               else
-                       MSG_DEBUG("MsgSettingSetInt fail: VOICE_NOTI_ID_1");
-       }
-
-       noti_err = notification_free(noti);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_free");
-       }
-
-       if (args != NULL) {
-               bundle_free(args);
-       }
-
-       MsgChangePmState();
-
-       MSG_END();
-}
-
-
-void MsgSmsReportNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
-{
-       MSG_BEGIN();
-
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-
-       noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-       }
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Report", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       if(pMsg->networkStatus == MSG_NETWORK_DELIVER_SUCCESS)
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message Delivered", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message delivery failed", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-       }
-
-       // get contact info.
-       MSG_CONTACT_INFO_S contactInfo;
-       memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
-       MsgGetContactInfo(&(pMsg->addressList[0]), &contactInfo);
-
-       int order = MsgGetContactNameOrder();
-
-       if (order == 0) {
-               if (contactInfo.firstName[0] != '\0') {
-                       strncpy(pMsg->addressList[0].displayName, contactInfo.firstName, MAX_DISPLAY_NAME_LEN);
-               }
-
-               if (contactInfo.lastName[0] != '\0') {
-                       strncat(pMsg->addressList[0].displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
-                       strncat(pMsg->addressList[0].displayName, contactInfo.lastName, MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
-               }
-       } else if (order == 1) {
-               if (contactInfo.lastName[0] != '\0') {
-                       strncpy(pMsg->addressList[0].displayName, contactInfo.lastName, MAX_DISPLAY_NAME_LEN);
-                       strncat(pMsg->addressList[0].displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
-               }
-
-               if (contactInfo.firstName[0] != '\0') {
-                       strncat(pMsg->addressList[0].displayName, contactInfo.firstName, MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
-               }
-       }
-
-       if (pMsg->addressList[0].displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message delivered.", pMsg->msgText, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set time.
-       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
-
-       // set led.
-       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-       // set launch type
-       noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
-       if (noti_err != NOTIFICATION_ERROR_NONE)
-               MSG_DEBUG("Fail to notification_set_display_applist");
-
-       MSG_END();
-}
-
-
-msg_error_t MsgInsertNoti(MSG_MESSAGE_INFO_S* pMsg)
-{
-       MSG_DEBUG("Start to Insert Notification.");
-       notification_h noti = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       bundle* args = NULL;
-
-       noti = notification_create(NOTIFICATION_TYPE_NOTI);
-       if (noti == NULL) {
-               MSG_DEBUG("notification_create is failed.");
-               return MSG_ERR_UNKNOWN;
-       }
-
-       switch(pMsg->msgType.subType)
-       {
-       case MSG_CB_SMS :
-               noti_err = notification_free(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_free");
-               }
-               MsgRefreshCBNoti(true);
-               return MSG_SUCCESS;
-               break;
-       case MSG_MWI_FAX_SMS :
-       case MSG_MWI_EMAIL_SMS :
-       case MSG_MWI_OTHER_SMS :
-               args = bundle_create();
-               MsgSmsMWINoti(pMsg, noti, args);
-               break;
-       case MSG_MWI_VOICE_SMS :
-               noti_err = notification_free(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_free");
-               }
-               MsgSmsVoiceNoti(pMsg);
-               return MSG_SUCCESS;
-               break;
-       case MSG_STATUS_REPORT_SMS :
-               //args = bundle_create();
-               MsgSmsReportNoti(pMsg, noti, NULL);
-               break;
-       case MSG_NORMAL_SMS :
-               if (pMsg->msgType.classType == MSG_CLASS_0) {
-                       args = bundle_create();
-                       MsgSmsClass0Noti(pMsg, noti, args);
-                       break;
-               } // Do not break here.
-       default :
-               noti_err = notification_free(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_free");
-               }
-               MsgRefreshNoti(true);
-               return MSG_SUCCESS;
-               break;
-       }
-
-       if (args != NULL) {
-               // set execute option
-               noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_execute_option : %d", noti_err);
-               }
-       }
-
-       noti_err = notification_insert(noti, NULL);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_insert");
-       }
-
-       noti_err = notification_free(noti);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_free");
-       }
-
-       if (args != NULL) {
-               bundle_free(args);
-       }
-
-       MsgChangePmState();
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
-{
-
-       notification_h noti = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-
-       char addressVal[MAX_ADDRESS_VAL_LEN+1];
-       char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
-       char displayName[MAX_DISPLAY_NAME_LEN+1];
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       memset(addressVal, 0x00, sizeof(addressVal));
-       memset(firstName, 0x00, sizeof(firstName));
-       memset(lastName, 0x00, sizeof(lastName));
-       memset(displayName, 0x00, sizeof(displayName));
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       int report_status_type;
-       int report_status_value;
-
-       if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
-               report_status_type = MSG_REPORT_TYPE_DELIVERY;
-               MSG_DEBUG("mms subtype is Delivery Report type");
-       } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
-               report_status_type = MSG_REPORT_TYPE_READ;
-               MSG_DEBUG("mms subtype is Read Report type");
-       } else {
-               MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
-               return MSG_SUCCESS;
-       }
-
-       MSG_ADDRESS_INFO_S *address_info_s = &pMsg->addressList[0];
-       MSG_DEBUG("address info : %s, type : %d", address_info_s->addressVal, address_info_s->addressType);
-
-       if (address_info_s->addressType == MSG_ADDRESS_TYPE_PLMN) {
-
-               if (strlen(address_info_s->addressVal) > MAX_PRECONFIG_NUM) {
-                       char newPhoneNum[MAX_PRECONFIG_NUM+1];
-
-                       memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
-
-                       MsgConvertNumber(address_info_s->addressVal, newPhoneNum);
-
-                       snprintf(sqlQuery, sizeof(sqlQuery),
-                                               "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
-                                               "FROM %s A, %s B "
-                                               "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL LIKE '%%%s' AND B.ADDRESS_VAL LIKE \'%%%s\';"
-                                               , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, newPhoneNum, newPhoneNum);
-               } else {
-
-                       snprintf(sqlQuery, sizeof(sqlQuery),
-                               "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
-                               "FROM %s A, %s B "
-                               "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL LIKE '%s' AND B.ADDRESS_VAL LIKE '%s';"
-                               , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, address_info_s->addressVal, address_info_s->addressVal);
-               }
-
-       } else if (address_info_s->addressType == MSG_ADDRESS_TYPE_EMAIL) {//check full
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                       "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
-                       "FROM %s A, %s B "
-                       "WHERE B.MSG_ID=%d AND B.STATUS_TYPE=%d AND A.ADDRESS_VAL=\'%s\' AND B.ADDRESS_VAL LIKE \'%s\';"
-                       , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type, address_info_s->addressVal, address_info_s->addressVal);
-       } else {
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                       "SELECT A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, B.STATUS "
-                       "FROM %s A, %s B "
-                       "WHERE B.MSG_ID=%d B.STATUS_TYPE=%d;"
-                       , MSGFW_ADDRESS_TABLE_NAME, MSGFW_REPORT_TABLE_NAME, pMsg->msgId, report_status_type);
-       }
-
-       MSG_DEBUG("sqlQuery = [%s]", sqlQuery);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
-               if (pDbHandle->columnText(0) != NULL) {
-                       strncpy(addressVal, (char*)pDbHandle->columnText(0), MAX_ADDRESS_VAL_LEN);
-                       MSG_DEBUG("addressVal is [%s]",addressVal);
-               } else {
-                       MSG_DEBUG("address Val is Null");
-               }
-
-               char *pTempDisplayName = (char *)pDbHandle->columnText(1);
-               if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
-                       strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
-               } else {
-                       if (pDbHandle->columnText(2) != NULL)
-                               strncpy(firstName, (char*)pDbHandle->columnText(2), MAX_DISPLAY_NAME_LEN);
-
-                       if (pDbHandle->columnText(3) != NULL)
-                               strncpy(lastName, (char*)pDbHandle->columnText(3), MAX_DISPLAY_NAME_LEN);
-
-                       int order = MsgGetContactNameOrder();
-
-                       if (order == 0) {
-                               if (firstName[0] != '\0') {
-                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
-
-                               if (lastName[0] != '\0') {
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       } else if (order == 1) {
-                               if (lastName[0] != '\0') {
-                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-
-                               if (firstName[0] != '\0') {
-                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       }
-               }
-
-               report_status_value = pDbHandle->columnInt(4);
-               MSG_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
-       } else {
-               MSG_DEBUG("DB Query Result Fail");
-               pDbHandle->finalizeQuery();
-               return MSG_ERR_DB_STEP;
-       }
-
-       pDbHandle->finalizeQuery();
-
-       noti = notification_create(NOTIFICATION_TYPE_NOTI);
-       if (noti == NULL) {
-               MSG_DEBUG("notification_create is failed.");
-               return MSG_ERR_UNKNOWN;
-       }
-
-       noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-       }
-
-       if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) { // MMS delivery report
-
-               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-               }
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Delivery Report", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {  // MMS read report
-
-               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-               }
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Read Report", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       }
-
-       if (displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set launch type
-       noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
-       if (noti_err != NOTIFICATION_ERROR_NONE)
-               MSG_DEBUG("Fail to notification_set_display_applist");
-
-       if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
-
-               switch(report_status_value) {
-               case MSG_DELIVERY_REPORT_NONE:
-                       noti_err = notification_free(noti);
-                       if (noti_err != NOTIFICATION_ERROR_NONE) {
-                               MSG_DEBUG("Fail to notification_free");
-                       }
-
-                       return MSG_ERR_UNKNOWN;
-
-               case MSG_DELIVERY_REPORT_EXPIRED:
-                       MSG_DEBUG("Message expired.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message expired", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message expired", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_REJECTED:
-                       MSG_DEBUG("Message rejected.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message rejected", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message rejected", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_DEFERRED:
-                       MSG_DEBUG("Message deferred.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message deferred", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message deferred", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_UNRECOGNISED:
-                       MSG_DEBUG("Message unrecognised.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message unrecognised", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message unrecognised", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_INDETERMINATE:
-                       MSG_DEBUG("Message indeterminate.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message indeterminate", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message indeterminate", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_FORWARDED:
-                       MSG_DEBUG("Message forwarded.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message forwarded", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message forwarded", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_UNREACHABLE:
-                       MSG_DEBUG("Message unreachable.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message unreachable", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message unreachable", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               case MSG_DELIVERY_REPORT_ERROR:
-                       MSG_DEBUG("Message error.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message error", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message error", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               default :
-                       MSG_DEBUG("Message delivered.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message delivered", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message delivered", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-               }
-
-               noti_err = notification_insert(noti, NULL);
-               if (noti_err != NOTIFICATION_ERROR_NONE)
-                       MSG_DEBUG("Fail to notification_insert");
-
-       } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {
-
-               switch(report_status_value) {
-               case MSG_READ_REPORT_NONE:
-                       noti_err = notification_free(noti);
-                       if (noti_err != NOTIFICATION_ERROR_NONE)
-                               MSG_DEBUG("Fail to notification_free");
-
-                       return MSG_ERR_UNKNOWN;
-
-               case MSG_READ_REPORT_IS_DELETED:
-                       MSG_DEBUG("Message deleted.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message deleted", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-
-               default :
-                       MSG_DEBUG("Message read.");
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message read", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-                       break;
-               }
-
-               // set time.
-               notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
-
-               // set led.
-               notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-               noti_err = notification_insert(noti, NULL);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_insert");
-               }
-       } else {
-               MSG_DEBUG("No matching subtype. subtype [%d]", pMsg->msgType.subType);
-
-               noti_err = notification_free(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_free");
-               }
-               return MSG_SUCCESS;
-       }
-
-       noti_err = notification_free(noti);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_free");
-       }
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgRefreshNoti(bool bWithTicker)
-{
-
-       MsgDbHandler dbhandler;
-       MSG_MESSAGE_INFO_S msg = {0,};
-
-       int notiPrivId = MsgSettingGetInt(NOTIFICATION_PRIV_ID);
-
-       notification_h noti = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       bundle* args = NULL;
-       bundle* reply = NULL;
-
-       int contactId = 0;
-       msg_thread_id_t threadId = 0;
-       time_t msgTime = 0;
-       char tempId[6];
-       char addressVal[MAX_ADDRESS_VAL_LEN+1];
-       char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
-       char displayName[MAX_DISPLAY_NAME_LEN+1];
-       char thumbPath[MAX_IMAGE_PATH_LEN+1];
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       memset(tempId, 0x00, sizeof(tempId));
-       memset(addressVal, 0x00, sizeof(addressVal));
-       memset(firstName, 0x00, sizeof(firstName));
-       memset(lastName, 0x00, sizeof(lastName));
-       memset(displayName, 0x00, sizeof(displayName));
-       memset(thumbPath, 0x00, sizeof(thumbPath));
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, "
-                       "B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH, B.MSG_ID, B.MSG_TEXT, B.SUBJECT, B.MAIN_TYPE "
-                       "FROM %s A, %s B WHERE A.CONV_ID=B.CONV_ID AND B.READ_STATUS=0 AND B.FOLDER_ID=%d AND "
-                       "(B.STORAGE_ID = %d OR B.STORAGE_ID = %d) "
-                       "ORDER BY B.DISPLAY_TIME DESC;",
-                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_STORAGE_PHONE, MSG_STORAGE_SIM);
-
-       if (dbhandler.prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       if (dbhandler.stepQuery() == MSG_ERR_DB_ROW) {
-               threadId = dbhandler.columnInt(0);
-
-               if (dbhandler.columnText(1) != NULL)
-                       strncpy(addressVal, (char*)dbhandler.columnText(1), MAX_ADDRESS_VAL_LEN);
-
-
-               char *pTempDisplayName = (char *)dbhandler.columnText(2);
-               if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
-                       strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
-               } else {
-                       if (dbhandler.columnText(3) != NULL)
-                               strncpy(firstName, (char*)dbhandler.columnText(3), MAX_DISPLAY_NAME_LEN);
-
-                       if (dbhandler.columnText(4) != NULL)
-                               strncpy(lastName, (char*)dbhandler.columnText(4), MAX_DISPLAY_NAME_LEN);
-
-                       int order = MsgGetContactNameOrder();
-
-                       if (order == 0) {
-                               if (firstName[0] != '\0') {
-                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
-
-                               if (lastName[0] != '\0') {
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       } else if (order == 1) {
-                               if (lastName[0] != '\0') {
-                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-
-                               if (firstName[0] != '\0') {
-                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       }
-               }
-
-               msgTime = (time_t)dbhandler.columnInt(5);
-
-               contactId = dbhandler.columnInt(6);
-
-               strncpy(thumbPath, (char*)dbhandler.columnText(7), MAX_IMAGE_PATH_LEN);
-
-               msg.msgId = dbhandler.columnInt(8);
-
-               strncpy(msg.msgText, (char*)dbhandler.columnText(9), MAX_MSG_TEXT_LEN);
-
-               strncpy(msg.subject, (char*)dbhandler.columnText(10), MAX_SUBJECT_LEN);
-
-               msg.msgType.mainType = dbhandler.columnInt(11);
-
-               MSG_DEBUG("unread message [%d].", msg.msgId);
-       } else {
-
-               MSG_DEBUG("No unread message.");
-               MSG_DEBUG("notiPrivId [%d]", notiPrivId);
-
-               dbhandler.finalizeQuery();
-
-               // No unread message.
-               if (notiPrivId > 0) {
-                       noti_err = notification_delete_by_priv_id("8r4r5ddzzn.Messages", NOTIFICATION_TYPE_NOTI, notiPrivId);
-                       if (noti_err != NOTIFICATION_ERROR_NONE) {
-                               MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
-                       }
-               }
-
-               notiPrivId = 0;
-
-               if(MsgSettingSetInt(NOTIFICATION_PRIV_ID, notiPrivId) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgSettingSetInt fail : NOTIFICATION_PRIV_ID");
-
-               return MSG_ERR_DB_STEP;
-       }
-
-       dbhandler.finalizeQuery();
-
-       int unreadMsgCnt = 0;
-#if 0
-       unreadMsgCnt = MsgStoGetUnreadCnt(&dbhandler, MSG_SMS_TYPE);
-       unreadMsgCnt += MsgStoGetUnreadCnt(&dbhandler, MSG_MMS_TYPE);
-#else
-       if (dbhandler.getTable(sqlQuery , &unreadMsgCnt) != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to getTable");
-               dbhandler.freeTable();
-               return MSG_ERR_DB_GETTABLE;
-       }
-
-       dbhandler.freeTable();
-#endif
-
-       MSG_DEBUG("notiPrivId [%d], unreadMsgCnt [%d]", notiPrivId, unreadMsgCnt);
-
-       if (notiPrivId > 0) {
-               noti = notification_load(NULL, notiPrivId);
-               if (noti == NULL)
-                       MSG_DEBUG("notification_load is failed.");
-       }
-
-       if (noti == NULL) {
-               noti = notification_create(NOTIFICATION_TYPE_NOTI);
-               if (noti == NULL) {
-                       MSG_DEBUG("notification_new is failed.");
-                       return MSG_ERR_UNKNOWN;
-               }
-
-               notiPrivId = 0;
-       }
-
-       // set pkg name.
-       noti_err = notification_set_pkgname(noti, "8r4r5ddzzn.Messages");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_pkgname : %d", noti_err);
-       }
-
-       // create bundle
-       args = bundle_create();
-
-       appsvc_set_appid(args, "8r4r5ddzzn.Messages");
-
-       // Set bundle values
-       memset(&tempId, 0x00, sizeof(tempId));
-       bundle_add(args, "type", "new_msg");
-       snprintf(tempId, 5, "%d", msg.msgId);
-       bundle_add(args, "msgId", tempId);
-
-       if (unreadMsgCnt > 1) {
-
-               noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-               }
-
-               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-               }
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               char unreadMsgCntStr[5] = {0,};
-               snprintf(unreadMsgCntStr, 5, "%d", unreadMsgCnt);
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Messages", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               // set execute option
-               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, args);
-
-               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, NULL);
-
-       } else {
-
-               noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-               }
-
-               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-               }
-
-               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, NORMAL_MSG_ICON_PATH);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-               }
-
-               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, NORMAL_MSG_ICON_PATH);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-               }
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               // set execute option
-               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
-
-               // Set responding option
-               reply = bundle_create();
-               appsvc_set_appid(reply, "8r4r5ddzzn.Messages");
-
-               bundle_add(reply, "type", "reply");
-               bundle_add(reply, "show_list", "list_show");
-
-               memset(&tempId, 0x00, sizeof(tempId));
-               snprintf(tempId, 5, "%d", msg.msgId);
-               bundle_add(reply, "msgId", tempId);
-
-               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, reply);
-       }
-
-
-       if (displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       if (msg.msgType.mainType == MSG_SMS_TYPE)
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2,msg.msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msg.subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set time.
-       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
-
-       // set led.
-       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-       notification_set_property(noti, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
-
-       if (bWithTicker)
-               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL);
-       else
-               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER);
-
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
-       }
-
-       if (notiPrivId > 0) {
-               noti_err = notification_update(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_update");
-               }
-       } else {
-               noti_err = notification_insert(noti, &notiPrivId);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_insert");
-               }
-
-               if (MsgSettingSetInt(NOTIFICATION_PRIV_ID, notiPrivId) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgSettingSetInt fail: NOTIFICATION_PRIV_ID");
-               MSG_DEBUG("Insert notiPrivId [%d]", notiPrivId);
-       }
-
-       noti_err = notification_free(noti);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_free");
-       }
-
-       if (args != NULL) {
-               bundle_free(args);
-       }
-
-       if (reply != NULL) {
-               bundle_free(reply);
-       }
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgRefreshCBNoti(bool bWithTicker)
-{
-       MsgDbHandler dbhandler;
-
-       int notiCbId = MsgSettingGetInt(CB_NOTI_PRIV_ID);
-
-       notification_h noti = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       bundle* args = NULL;
-
-       int contactId = 0;
-       msg_thread_id_t threadId = 0;
-       msg_message_id_t msgId = 0;
-       time_t msgTime = 0;
-       char tempId[6];
-       char addressVal[MAX_ADDRESS_VAL_LEN+1];
-       char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
-       char displayName[MAX_DISPLAY_NAME_LEN+1];
-       char thumbPath[MAX_IMAGE_PATH_LEN+1];
-       char msgText[MAX_MSG_TEXT_LEN+1];
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       memset(tempId, 0x00, sizeof(tempId));
-       memset(addressVal, 0x00, sizeof(addressVal));
-       memset(firstName, 0x00, sizeof(firstName));
-       memset(lastName, 0x00, sizeof(lastName));
-       memset(displayName, 0x00, sizeof(displayName));
-       memset(thumbPath, 0x00, sizeof(thumbPath));
-       memset(msgText, 0x00, sizeof(msgText));
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, "
-                       "B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH, B.MSG_ID, B.MSG_TEXT "
-                       "FROM %s A, %s B WHERE A.CONV_ID=B.CONV_ID AND B.READ_STATUS=0 AND B.FOLDER_ID=%d AND B.STORAGE_ID = %d "
-                       "ORDER BY B.DISPLAY_TIME DESC;",
-                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
-
-       if (dbhandler.prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       if (dbhandler.stepQuery() == MSG_ERR_DB_ROW) {
-               threadId = dbhandler.columnInt(0);
-
-               if (dbhandler.columnText(1) != NULL)
-                       strncpy(addressVal, (char*)dbhandler.columnText(1), MAX_ADDRESS_VAL_LEN);
-
-
-               char *pTempDisplayName = (char *)dbhandler.columnText(2);
-               if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
-                       strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
-               } else {
-                       if (dbhandler.columnText(3) != NULL)
-                               strncpy(firstName, (char*)dbhandler.columnText(3), MAX_DISPLAY_NAME_LEN);
-
-                       if (dbhandler.columnText(4) != NULL)
-                               strncpy(lastName, (char*)dbhandler.columnText(4), MAX_DISPLAY_NAME_LEN);
-
-                       int order = MsgGetContactNameOrder();
-
-                       if (order == 0) {
-                               if (firstName[0] != '\0') {
-                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
-
-                               if (lastName[0] != '\0') {
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       } else if (order == 1) {
-                               if (lastName[0] != '\0') {
-                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-
-                               if (firstName[0] != '\0') {
-                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       }
-               }
-
-               msgTime = (time_t)dbhandler.columnInt(5);
-
-               contactId = dbhandler.columnInt(6);
-
-               strncpy(thumbPath, (char*)dbhandler.columnText(7), MAX_IMAGE_PATH_LEN);
-
-               msgId = dbhandler.columnInt(8);
-
-               strncpy(msgText, (char*)dbhandler.columnText(9), MAX_MSG_TEXT_LEN);
-
-               MSG_DEBUG("unread CB message [%d].", msgId);
-       } else {
-
-               MSG_DEBUG("No unread CB message.");
-               MSG_DEBUG("notiCbId [%d]", notiCbId);
-
-               dbhandler.finalizeQuery();
-
-               // No unread message.
-               if (notiCbId > 0) {
-                       noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiCbId);
-                       if (noti_err != NOTIFICATION_ERROR_NONE) {
-                               MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
-                       }
-               }
-
-               notiCbId = 0;
-
-               if(MsgSettingSetInt(CB_NOTI_PRIV_ID, notiCbId) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
-
-               return MSG_ERR_DB_STEP;
-       }
-
-       dbhandler.finalizeQuery();
-
-       int unreadCbMsgCnt = 0;
-
-       if (dbhandler.getTable(sqlQuery, &unreadCbMsgCnt) != MSG_SUCCESS) {
-               MSG_DEBUG("getTable is failed");
-               dbhandler.freeTable();
-               return MSG_ERR_DB_GETTABLE;
-       }
-
-       MSG_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", notiCbId, unreadCbMsgCnt);
-
-       if (notiCbId > 0) {
-               noti = notification_load(NULL, notiCbId);
-               if (noti == NULL)
-                       MSG_DEBUG("notification_load is failed.");
-       }
-
-       if (noti == NULL) {
-               noti = notification_create(NOTIFICATION_TYPE_NOTI);
-               if (noti == NULL) {
-                       MSG_DEBUG("notification_new is failed.");
-                       return MSG_ERR_UNKNOWN;
-               }
-               notiCbId = 0;
-       }
-
-       args = bundle_create();
-
-       appsvc_set_appid(args, "8r4r5ddzzn.Messages");
-
-       // Set bundle values
-       memset(&tempId, 0x00, sizeof(tempId));
-       bundle_add(args, "type", "new_msg");
-       snprintf(tempId, 5, "%d", msgId);
-       bundle_add(args, "msgId", tempId);
-
-       if (unreadCbMsgCnt > 1) {
-               noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-               }
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Messages", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               char unreadCbMsgCntStr[5] = {0,};
-               snprintf(unreadCbMsgCntStr, 5, "%d", unreadCbMsgCnt);
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadCbMsgCntStr, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, args);
-       } else {
-               noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
-               }
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
-       }
-
-
-       if (displayName[0] == '\0')
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-       else
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       // set time.
-       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
-
-       // set icon image
-       notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-
-       // set led.
-       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
-
-       if (bWithTicker)
-               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK);
-       else
-               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR);
-
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
-       }
-
-       if (notiCbId > 0) {
-               noti_err = notification_update(noti);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_update");
-               }
-       } else {
-               noti_err = notification_insert(noti, &notiCbId);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_insert");
-               }
-
-               if (MsgSettingSetInt(CB_NOTI_PRIV_ID, notiCbId) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgSettingSetInt fail: CB_NOTI_PRIV_ID");
-               MSG_DEBUG("Insert notiCbId [%d]", notiCbId);
-       }
-
-       noti_err = notification_free(noti);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_free");
-       }
-
-       if (args != NULL) {
-               bundle_free(args);
-       }
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgCleanAndResetNoti()
-{
-       msg_error_t err = MSG_SUCCESS;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-
-       noti_err = notification_delete_all_by_type("8r4r5ddzzn.Messages", NOTIFICATION_TYPE_NOTI);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_delete_all_by_type noti_err [%d]", noti_err);
-       }
-
-       err = MsgRefreshNoti(false);
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to MsgRefreshNoti : [err=%d]", err);
-       }
-
-       err = MsgRefreshCBNoti(false);
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to MsgRefreshCBNoti : [err=%d]", err);
-       }
-
-       return err;
-}
-
-
-msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg)
-{
-       notification_h noti = NULL;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-
-       noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
-       if (noti == NULL) {
-               MSG_DEBUG("notification_new is failed.");
-               return MSG_ERR_UNKNOWN;
-       }
-
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
-       }
-
-       noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
-       }
-
-       noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
-       }
-
-       noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
-       }
-
-       noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
-       if (noti_err != NOTIFICATION_ERROR_NONE)
-               MSG_DEBUG("Fail to notification_set_display_applist");
-
-       noti_err = notification_insert(noti, NULL);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_insert");
-       }
-
-       noti_err = notification_free(noti);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_free");
-       }
-
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt)
-{
-       return MSG_SUCCESS;
-}
-
-
-msg_error_t MsgClearVoiceNoti(MSG_SUB_TYPE_T subType)
-{
-       MSG_BEGIN();
-
-       msg_error_t err = MSG_SUCCESS;
-       int notiId = 0;
-       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-
-       if (subType == MSG_MWI_VOICE_SMS) {
-               notiId = MsgSettingGetInt(VOICE_NOTI_ID_1);
-       } else {
-               return MSG_ERR_UNKNOWN;
-       }
-
-       if (notiId>0) {
-               noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiId);
-               if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
-                       err = MSG_ERR_UNKNOWN;
-               }
-       }
-
-       notiId = 0;
-
-       if (subType == MSG_MWI_VOICE_SMS) {
-               if (MsgSettingSetInt(VOICE_NOTI_ID_1, notiId) == MSG_SUCCESS)
-                       MSG_DEBUG("Insert VOICE_NOTI_ID_1 [%d]", notiId);
-               else
-                       MSG_DEBUG("MsgSettingSetInt fail: VOICE_NOTI_ID_1");
-       }
-
-       MSG_END();
-
-       return err;
-}
diff --git a/utils/MsgSerialize.cpp b/utils/MsgSerialize.cpp
new file mode 100755 (executable)
index 0000000..9c45bef
--- /dev/null
@@ -0,0 +1,826 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include "MsgJsonParser.h"
+#include "MsgSerialize.h"
+#include "MsgMmsTypes.h"
+#include "MsgDebug.h"
+#include "MsgMmsMessage.h"
+
+#include <glib.h>
+#include <glib-object.h>
+#include <json-glib/json-glib.h>
+#include <json-glib/json-gobject.h>
+
+typedef enum {
+       TYPE_STR,
+       TYPE_INT,
+       TYPE_ARRAY,
+       TYPE_OBJECT,
+} mms_json_data_type_e;
+
+typedef struct _mms_json_item {
+       const char *key;
+       int e_val;
+       int type;
+} mms_json_item_s;
+
+typedef enum {
+       MMS_UNKNOWN = -1,
+       MMS_HEADER = 0,
+       MMS_MULTIPART_LIST,
+       MMS_SMIL_MULTIPART,
+
+       MULTIPART_TYPE ,
+       MULTIPART_CONTENT_TYPE,
+       MULTIPART_NAME,
+       MULTIPART_FILEPATH,
+       MULTIPART_FILEDATA,
+       MULTIPART_CONTENT_ID,
+       MULTIPART_CONTENT_LOCATION,
+
+       HEADER_CONTENT_LOCATION,
+       HEADER_CONTENT_TYPE,
+       HEADER_CONTENT_TYPE_INT,
+       HEADER_DATE,
+       HEADER_DELIVERY_REPORT,
+       HEADER_DELIVERY_TIME,
+       HEADER_EXPIRY_TIME,
+       HEADER_MESSAGE_CLASS,
+       HEADER_MID,
+       HEADER_MESSAGE_TYPE,
+       HEADER_VERSION,
+       HEADER_PRIORITY,
+       HEADER_READ_REPORT,
+       HEADER_HIDE_ADDRESS,
+       HEADER_TRID,
+       HEADER_CONTENT_CLASS,
+
+       MMS_BACKUP_TYPE,
+} mms_json_enum_e;
+
+static mms_json_item_s mms_json_table[] = {
+       {"header",              MMS_HEADER,     TYPE_INT},
+       {"multipart_list",      MMS_MULTIPART_LIST, TYPE_ARRAY},
+       {"smil",                MMS_SMIL_MULTIPART,     TYPE_OBJECT},
+//multipart
+       {"mp_type",      MULTIPART_TYPE,        TYPE_INT},
+       {"mp_ct",        MULTIPART_CONTENT_TYPE,        TYPE_STR},
+       {"mp_name",      MULTIPART_NAME,        TYPE_STR},
+       {"mp_path",      MULTIPART_FILEPATH,    TYPE_STR},
+       {"mp_data",      MULTIPART_FILEDATA,    TYPE_STR},
+
+       {"mp_cid",       MULTIPART_CONTENT_ID,  TYPE_STR},
+       {"mp_cl",        MULTIPART_CONTENT_LOCATION,    TYPE_STR},
+//header
+       {"h_cl",        HEADER_CONTENT_LOCATION,        TYPE_STR},
+       {"h_ct",        HEADER_CONTENT_TYPE,    TYPE_STR},
+       {"h_ct_int",    HEADER_CONTENT_TYPE_INT,        TYPE_INT},
+       {"h_date",      HEADER_DATE, TYPE_INT},
+       {"h_d_rpt",     HEADER_DELIVERY_REPORT, TYPE_INT},
+       {"h_d_time",    HEADER_DELIVERY_TIME, TYPE_INT},
+       {"h_exp",       HEADER_EXPIRY_TIME, TYPE_INT},
+       {"h_mclass",    HEADER_MESSAGE_CLASS,   TYPE_INT},
+       {"h_mid",       HEADER_MID, TYPE_STR},
+       {"h_mtype",     HEADER_MESSAGE_TYPE,    TYPE_INT},
+       {"h_v",         HEADER_VERSION, TYPE_INT},
+       {"h_prioriy",   HEADER_PRIORITY,        TYPE_INT},
+       {"h_r_rpt",     HEADER_READ_REPORT, TYPE_INT},
+       {"h_hide_addr", HEADER_HIDE_ADDRESS, TYPE_INT},
+       {"h_tid",       HEADER_TRID,    TYPE_STR},
+       {"h_cclass",    HEADER_CONTENT_CLASS, TYPE_INT},
+       {"backup_type", MMS_BACKUP_TYPE, TYPE_INT},
+
+};
+
+mms_json_enum_e get_mms_key_type(const char * key)
+{
+       int i;
+
+       int table_count = sizeof(mms_json_table)/sizeof(mms_json_item_s);
+       if (key) {
+               for (i = 0; i < table_count; i++) {
+                       if (g_strcmp0(mms_json_table[i].key, key) == 0)
+                               return (mms_json_enum_e)mms_json_table[i].e_val;
+               }
+       }
+
+       return MMS_UNKNOWN;
+}
+
+const char *get_mms_key(mms_json_enum_e e)
+{
+       int i;
+
+       int table_count = sizeof(mms_json_table)/sizeof(mms_json_item_s);
+
+       for (i = 0; i < table_count; i++) {
+               if (mms_json_table[i].e_val == e)
+                       return mms_json_table[i].key;
+       }
+
+       return NULL;
+}
+
+int MsgSerializeHeader(const MMS_HEADER_DATA_S *pheader, JsonObject **headerObject)
+{
+       JsonObject *header_object = json_object_new();
+
+       MSG_JSON_OBJ_SET_STR(header_object, get_mms_key(HEADER_CONTENT_LOCATION), pheader->contentLocation);
+
+       MSG_JSON_OBJ_SET_STR(header_object, get_mms_key(HEADER_CONTENT_TYPE), pheader->szContentType);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_CONTENT_TYPE_INT), pheader->contentType);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_DATE), pheader->date);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_DELIVERY_REPORT), pheader->bDeliveryReport);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_DELIVERY_TIME), pheader->delivery.time);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_EXPIRY_TIME), pheader->expiry.time);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_MESSAGE_CLASS), pheader->messageClass);
+
+       MSG_JSON_OBJ_SET_STR(header_object, get_mms_key(HEADER_MID), pheader->messageID);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_MESSAGE_TYPE), pheader->messageType);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_VERSION), pheader->mmsVersion);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_PRIORITY), pheader->mmsPriority);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_READ_REPORT), pheader->bReadReport);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_HIDE_ADDRESS), pheader->bHideAddress);
+
+       MSG_JSON_OBJ_SET_STR(header_object, get_mms_key(HEADER_TRID), pheader->trID);
+
+       MSG_JSON_OBJ_SET_INT(header_object, get_mms_key(HEADER_CONTENT_CLASS), pheader->contentClass);
+
+       *headerObject = header_object;
+
+       return 0;
+}
+
+int MsgParseHeader(msg_json_parser_object *parse_obj, MMS_HEADER_DATA_S *pheader)
+{
+       MSG_BEGIN();
+
+       int index_child = 0;
+       mms_json_enum_e type;
+       msg_json_parser_object child = {};
+
+       if (parse_obj == NULL)
+               return -1;
+
+       while(msg_json_parser_get_next_child(parse_obj, &child, index_child))
+       {
+               MSG_PRINT_PARSER_OBJECT(index_child, child);
+               type = get_mms_key_type(child.key);
+
+               switch (type) {
+               case HEADER_CONTENT_LOCATION:
+                       snprintf(pheader->contentLocation, sizeof(pheader->contentLocation), "%s", (char *)child.value);
+                       break;
+               case HEADER_CONTENT_TYPE:
+                       snprintf(pheader->szContentType, sizeof(pheader->szContentType), "%s", (char *)child.value);
+                       break;
+               case HEADER_CONTENT_TYPE_INT:
+                       pheader->contentType = (int)child.number_value;
+                       break;
+               case HEADER_DATE:
+                       pheader->date = (unsigned long int)child.number_value;
+                       break;
+               case HEADER_DELIVERY_REPORT:
+                       pheader->bDeliveryReport = (bool)child.number_value;
+                       break;
+               case HEADER_DELIVERY_TIME:
+                       if ((unsigned int)child.number_value > 0) {
+                               pheader->delivery.type = MMS_TIMETYPE_RELATIVE;
+                               pheader->delivery.time = (unsigned int)child.number_value;
+                       }
+                       break;
+               case HEADER_EXPIRY_TIME:
+                       if ((unsigned int)child.number_value > 0) {
+                       pheader->expiry.type = MMS_TIMETYPE_RELATIVE;
+                       pheader->expiry.time = (unsigned int)child.number_value;
+                       }
+                       break;
+               case HEADER_MESSAGE_CLASS:
+                       pheader->messageClass = (int)child.number_value;
+                       break;
+               case HEADER_MID:
+                       snprintf(pheader->messageID, sizeof(pheader->messageID), "%s", (char *)child.value);
+                       break;
+               case HEADER_MESSAGE_TYPE:
+                       pheader->messageType = (int)child.number_value;
+                       break;
+               case HEADER_VERSION:
+                       pheader->mmsVersion = (int)child.number_value;
+                       break;
+               case HEADER_PRIORITY:
+                       pheader->mmsPriority = (int)child.number_value;
+                       break;
+               case HEADER_READ_REPORT:
+                       pheader->bReadReport = (bool)child.number_value;
+                       break;
+               case HEADER_HIDE_ADDRESS:
+                       pheader->bHideAddress = (bool)child.number_value;
+                       break;
+               case HEADER_TRID:
+                       snprintf(pheader->trID, sizeof(pheader->trID), "%s", (char *)child.value);
+                       break;
+               case HEADER_CONTENT_CLASS:
+                       pheader->contentClass = (int)child.number_value;
+                       break;
+               default:
+                       MSG_DEBUG("Not Support key = [%s], type = [%d]", child.key, type);
+                       break;
+               }
+
+               index_child++;
+       }
+
+       MSG_END();
+       return 0;
+}
+
+int MsgSerializeMultipart(const MMS_MULTIPART_DATA_S *pMultipart, JsonObject **multipartObject)
+{
+       JsonObject *object = json_object_new();
+
+       MSG_JSON_OBJ_SET_INT(object, get_mms_key(MULTIPART_TYPE), pMultipart->type);
+
+       MSG_JSON_OBJ_SET_STR(object, get_mms_key(MULTIPART_CONTENT_TYPE), pMultipart->szContentType);
+       MSG_JSON_OBJ_SET_STR(object, get_mms_key(MULTIPART_NAME), pMultipart->szFileName);
+       MSG_JSON_OBJ_SET_STR(object, get_mms_key(MULTIPART_FILEPATH), pMultipart->szFilePath);
+
+       if (pMultipart->pMultipartData) {
+               char* base64data = g_base64_encode((const guchar*)pMultipart->pMultipartData, pMultipart->nMultipartDataLen);
+               MSG_JSON_OBJ_SET_STR(object, get_mms_key(MULTIPART_FILEDATA), base64data);
+               g_free(base64data);
+       }
+
+       MSG_JSON_OBJ_SET_STR(object, get_mms_key(MULTIPART_CONTENT_ID), pMultipart->szContentID);
+       MSG_JSON_OBJ_SET_STR(object, get_mms_key(MULTIPART_CONTENT_LOCATION), pMultipart->szContentLocation);
+
+       *multipartObject = object;
+
+       return 0;
+}
+
+int MsgParseMultipartData(msg_json_parser_object *parse_obj, MMS_MULTIPART_DATA_S *pMultipart)
+{
+       MSG_BEGIN();
+
+       int index_child = 0;
+       mms_json_enum_e type;
+       msg_json_parser_object child = {};
+
+       if (parse_obj == NULL)
+               return -1;
+
+       while(msg_json_parser_get_next_child(parse_obj, &child, index_child))
+       {
+               MSG_PRINT_PARSER_OBJECT(index_child, child);
+
+               type = get_mms_key_type(child.key);
+
+               switch (type) {
+               case MULTIPART_TYPE:
+                       pMultipart->type = (MimeType)child.number_value;
+                       break;
+               case MULTIPART_CONTENT_TYPE:
+                       snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", (char *)child.value);
+                       break;
+               case MULTIPART_NAME:
+                       snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", (char *)child.value);
+                       break;
+               case MULTIPART_FILEPATH:
+                       snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", (char *)child.value);
+                       break;
+               case MULTIPART_FILEDATA:
+                       pMultipart->pMultipartData = (char*)g_base64_decode((char *)child.value, &pMultipart->nMultipartDataLen);
+                       break;
+               case MULTIPART_CONTENT_ID:
+                       snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", (char *)child.value);
+                       break;
+               case MULTIPART_CONTENT_LOCATION:
+                       snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", (char *)child.value);
+                       break;
+               default:
+                       MSG_DEBUG("Not Support key = [%s], type = [%d]", child.key, type);
+                       break;
+               }
+
+               index_child++;
+       }
+
+       MSG_END();
+       return 0;
+}
+
+int MsgParseMultipartListData(msg_json_parser_object *parse_obj, MMS_DATA_S *pMsgData)
+{
+       MSG_BEGIN();
+
+       int index_child = 0;
+
+       msg_json_parser_object child = {};
+
+       if (parse_obj == NULL)
+               return -1;
+
+       while(msg_json_parser_get_next_child(parse_obj, &child, index_child))
+       {
+               if (child.value != NULL && child.type) {
+
+                       MSG_PRINT_PARSER_OBJECT(index_child, child);
+
+                       MMS_MULTIPART_DATA_S *pMultipart= MsgMmsCreateMultipart();
+
+                       if (MsgParseMultipartData(&child, pMultipart) == 0) {
+                               pMsgData->multipartlist = g_list_append(pMsgData->multipartlist, pMultipart);
+                       } else {
+                               free(pMultipart);
+                               pMultipart = NULL;
+                       }
+
+               } else {
+                       MSG_DEBUG("Get child : idx  = %d, key = %s, type = %d, value = %p", index_child, child.key, child.type, child.value);
+               }
+
+               index_child++;
+       }
+
+       MSG_END();
+       return 0;
+}
+
+int MsgParseMmsData(msg_json_parser_object *parse_obj, MMS_DATA_S *pMsgData)
+{
+       MSG_BEGIN();
+
+       int index_child = 0;
+       mms_json_enum_e type;
+       msg_json_parser_object child = {};
+
+       if (parse_obj == NULL)
+               return -1;
+
+       while(msg_json_parser_get_next_child(parse_obj, &child, index_child))
+       {
+               if (child.key != NULL) {
+
+                       MSG_PRINT_PARSER_OBJECT(index_child, child);
+
+                       type = get_mms_key_type(child.key);
+
+                       switch (type) {
+                       case MMS_MULTIPART_LIST:
+                               MsgParseMultipartListData(&child, pMsgData);
+                               break;
+                       case MMS_HEADER:
+                               pMsgData->header = MsgMmsCreateHeader();
+                               MsgParseHeader(&child, pMsgData->header);
+                               break;
+                       case MMS_SMIL_MULTIPART:
+                       {
+                               MMS_MULTIPART_DATA_S *pMultipart = MsgMmsCreateMultipart();
+
+                               if (MsgParseMultipartData(&child, pMultipart) == 0) {
+                                       pMsgData->smil = pMultipart;
+                               } else {
+                                       free(pMultipart);
+                                       pMultipart = NULL;
+                               }
+
+                               break;
+                       }
+                       case MMS_BACKUP_TYPE:
+                               pMsgData->backup_type = (int)child.number_value;
+                               break;
+                       default:
+                               MSG_DEBUG("Not Support key = [%s], type = [%d]", child.key, type);
+                               break;
+                       }
+
+               } else {
+                       MSG_PRINT_PARSER_OBJECT(index_child, child);
+               }
+
+               index_child++;
+       }
+
+       MSG_END();
+       return 0;
+}
+
+
+int MsgSerializeMmsJsonData(const MMS_DATA_S *pMsgData, char **pValue)
+{
+       MSG_BEGIN();
+
+       if (pMsgData == NULL)
+               return MSG_ERR_NULL_POINTER;
+
+       JsonGenerator *generator;
+       JsonNode *root;
+
+       JsonObject *object_main, *object_header;
+       JsonArray *array_multipart;
+
+       gsize len = 0;
+
+       g_type_init();
+
+       generator = json_generator_new();
+
+       root = json_node_new(JSON_NODE_OBJECT);
+
+       object_main = json_object_new();
+
+       MSG_JSON_OBJ_SET_INT(object_main, get_mms_key(MMS_BACKUP_TYPE), pMsgData->backup_type);
+
+       //smil multipart
+       if (pMsgData->smil) {
+               JsonObject *smil_object = NULL;
+
+               MsgSerializeMultipart(pMsgData->smil, &smil_object);
+               MSG_JSON_OBJ_SET_OBJ(object_main, get_mms_key(MMS_SMIL_MULTIPART), smil_object);
+       }
+
+       if (pMsgData->multipartlist) {
+               //multipart
+               array_multipart = json_array_new();
+
+               int list_count = g_list_length(pMsgData->multipartlist);
+
+               MSG_DEBUG("Page Count is [%d]", list_count);
+
+               for (int i = 0; i < list_count; i++) {
+
+                       MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMsgData->multipartlist, i);
+
+                       if (multipart) {
+                               JsonObject *multipart_object = NULL;
+
+                               MsgSerializeMultipart(multipart, &multipart_object);
+
+                               MSG_JSON_ARRAY_ADD_OBJECT(array_multipart, multipart_object);
+
+                       } else {
+                               MSG_DEBUG("Not Exist Multipart Data in [%d]th", i);
+                       }
+               }
+
+               MSG_JSON_OBJ_SET_ARRAY(object_main, get_mms_key(MMS_MULTIPART_LIST), array_multipart);
+       }
+
+       //header
+       if (pMsgData->header) {
+               MsgSerializeHeader(pMsgData->header, &object_header);
+
+               MSG_JSON_OBJ_SET_OBJ(object_main, get_mms_key(MMS_HEADER), object_header);
+       }
+
+       json_node_take_object(root, object_main);
+
+       json_generator_set_root(generator, root);
+
+       *pValue = json_generator_to_data(generator, &len);
+       MSG_BEGIN();
+       MSG_DEBUG("Serialized Data : %s", *pValue);
+
+       json_node_free(root);
+
+       g_object_unref(generator);
+
+       MSG_END();
+
+       return 0;
+}
+
+
+int MsgDeserializeMmsJsonData(char* value, int value_len, MMS_DATA_S **ppMmsData)
+{
+       MSG_BEGIN();
+
+       int ret = 0;
+
+       msg_json_parser_handle parser_handle = NULL;
+       msg_json_parser_object root = {};
+       MMS_DATA_S *pMmsData = NULL;
+
+       g_type_init();
+
+       pMmsData = MsgMmsCreate();
+
+       parser_handle = msg_json_parser_handle_create();
+
+       msg_json_parser_parse_buffer(parser_handle, value, value_len, &root);
+
+       MSG_DEBUG("Deserialized : %s", value);
+
+       MSG_DEBUG("root : key = %s, type = %d, value = %p", root.key, root.type, root.value);
+
+       ret = MsgParseMmsData(&root, pMmsData);
+       if (ret != 0) {
+               MSG_DEBUG("Fail to MsgParseMessageData, ret = %d", ret);
+               MsgMmsRelease(&pMmsData);
+       } else {
+               *ppMmsData = pMmsData;
+       }
+
+       msg_json_parser_handle_destory(&parser_handle);
+
+       MSG_END();
+
+       return ret;
+}
+
+
+int MsgSerializeMms(const MMS_DATA_S *pMsgData, char **pValue)
+{
+       MSG_BEGIN();
+
+       if (pMsgData == NULL)
+               return MSG_ERR_NULL_POINTER;
+
+       int bufsize = 0;
+
+       int isExistHeader = 0, isExistSmil = 0, isExistMultipart = 0;
+       int multipart_cnt = 0;
+       char *buf = NULL;
+       int i;
+
+       bufsize += sizeof(int); // back-up type
+
+//     int bcc_cnt = g_list_length(pMsgData->header->bcc);
+//     int cc_cnt = g_list_length(pMsgData->header->cc);
+       int to_cnt = 0;
+
+       bufsize += sizeof(int); // check header data
+
+       if (pMsgData->header) {
+               isExistHeader = 1;
+
+               bufsize += sizeof(MMS_HEADER_DATA_S); // header
+
+               to_cnt = g_list_length(pMsgData->header->to);
+
+               bufsize += sizeof(int);
+
+               MSG_DEBUG("Address \"to\" count = [%d]", to_cnt);
+
+               for (i = 0; i < to_cnt; i++) {
+                       MMS_ADDRESS_DATA_S *addr_data = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pMsgData->header->to, i);
+                       if (addr_data && addr_data->address_val) {
+                               bufsize += (sizeof(int) + sizeof(int) + strlen(addr_data->address_val)); // type, length, address
+                       }
+               }
+       }
+
+       bufsize += sizeof(int); // check smil data
+
+       if (pMsgData->smil) {
+               isExistSmil = 1;
+               bufsize += (sizeof(MMS_MULTIPART_DATA_S) + (sizeof(char)*pMsgData->smil->nMultipartDataLen)); // smil data
+       }
+
+       bufsize += sizeof(int); // check multipart list data
+
+       if (pMsgData->multipartlist) {
+               isExistMultipart = 1;
+               multipart_cnt = g_list_length(pMsgData->multipartlist);
+
+               bufsize += sizeof(int); // multipart count
+
+               for (i = 0; i < multipart_cnt; i++) {
+                       MMS_MULTIPART_DATA_S *multipart_data = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMsgData->multipartlist, i);
+                       bufsize += sizeof(MMS_MULTIPART_DATA_S) + (sizeof(char)*multipart_data->nMultipartDataLen);
+               }
+       }
+
+       MSG_DEBUG("Serialize bufsize = %d", bufsize);
+
+       buf = (char *)calloc(1, bufsize);
+
+       int serial_index = 0;
+       int offset = 0;
+
+       // 1. Backup type
+       memcpy(buf, &pMsgData->backup_type, sizeof(int));
+       MSG_DEBUG("[#%2d][%5d] backup type = %d", serial_index++, offset, pMsgData->backup_type);
+       offset += sizeof(int);
+
+       // 2. Header Data
+       memcpy(buf + offset, &isExistHeader, sizeof(int));
+       offset += sizeof(int);
+
+       if (pMsgData->header) {
+               memcpy(buf + offset, pMsgData->header, sizeof(MMS_HEADER_DATA_S));
+               offset += sizeof(MMS_HEADER_DATA_S);
+
+               // address
+               memcpy(buf + offset, &to_cnt, sizeof(int));
+               MSG_DEBUG("[#%2d][%5d] TO Count = %d", serial_index++, offset, to_cnt);
+               offset += sizeof(int);
+
+               for (i = 0; i < to_cnt; i++) {
+                       MMS_ADDRESS_DATA_S *to_addr = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pMsgData->header->to, i);
+                       if (to_addr && to_addr->address_val) {
+                               memcpy(buf + offset, &to_addr->address_type, sizeof(int));
+                               MSG_DEBUG("[#%2d][%5d] address type = %d", serial_index++, offset, to_addr->address_type);
+                               offset += sizeof(int);
+                               memcpy(buf + offset, to_addr->address_val, sizeof(char)*MAX_ADDRESS_VAL_LEN);
+                               MSG_DEBUG("[#%2d][%5d] address val = %s", serial_index++, offset, to_addr->address_val);
+                               offset += sizeof(char)*MAX_ADDRESS_VAL_LEN;
+                       }
+               }
+       }
+
+       // 3. Smil Data
+       memcpy(buf + offset, &isExistSmil, sizeof(int));
+       offset += sizeof(int);
+
+       if (pMsgData->smil) {
+               memcpy(buf + offset, pMsgData->smil, sizeof(MMS_MULTIPART_DATA_S));
+               offset += sizeof(MMS_MULTIPART_DATA_S);
+
+               MSG_DEBUG("SMIL file path = [%s]", pMsgData->smil->szFilePath);
+               MSG_DEBUG("SMIL nMultipartDataLen = [%d]", pMsgData->smil->nMultipartDataLen);
+
+               if (pMsgData->smil->pMultipartData) {
+                       memcpy(buf + offset, pMsgData->smil->pMultipartData, sizeof(char)*pMsgData->smil->nMultipartDataLen);
+                       MSG_DEBUG("[#%2d][%5d] smil data = %s", serial_index++, offset, pMsgData->smil->pMultipartData);
+                       offset += sizeof(char)*pMsgData->smil->nMultipartDataLen;
+               }
+       }
+
+       // 4. Multipart list data
+       memcpy(buf + offset, &isExistMultipart, sizeof(int));
+       offset += sizeof(int);
+
+       if (pMsgData->multipartlist) {
+               MSG_DEBUG("Multipart list count = [ %d]", multipart_cnt);
+               memcpy(buf + offset, &multipart_cnt, sizeof(int));
+               offset += sizeof(int);
+
+               for (i = 0; i < multipart_cnt; i++) {
+                       MMS_MULTIPART_DATA_S *multipart_data = (MMS_MULTIPART_DATA_S *)g_list_nth_data(pMsgData->multipartlist, i);
+                       MSG_DEBUG("multipart_data = [%p]", multipart_data);
+                       if (multipart_data) {
+                               memcpy(buf + offset, multipart_data, sizeof(MMS_MULTIPART_DATA_S));
+                               offset += sizeof(MMS_MULTIPART_DATA_S);
+
+                               MSG_DEBUG("Multipart file path = [%s]", multipart_data->szFilePath);
+
+                               if (multipart_data->pMultipartData) {
+                                       memcpy(buf + offset, multipart_data->pMultipartData, sizeof(char)*multipart_data->nMultipartDataLen);
+                                       MSG_DEBUG("[#%2d][%5d] multipart data ptr = %p", serial_index++, offset, multipart_data->pMultipartData);
+                                       offset += sizeof(char)*multipart_data->nMultipartDataLen;
+                               }
+                       }
+               }
+       }
+
+       *pValue = buf;
+
+       MSG_DEBUG("Expect Buffer Size: %d, Final offset : %d", bufsize, offset);
+
+       MSG_END();
+
+       return bufsize;
+}
+
+
+int MsgDeserializeMmsData(char* value, int value_len, MMS_DATA_S **ppMmsData)
+{
+       MSG_BEGIN();
+
+       if (value == NULL) {
+               MSG_DEBUG("Serialized data is NULL");
+               return -1;
+       }
+
+       MMS_DATA_S *pMmsData = NULL;
+
+       int isExistHeader = 0, isExistSmil = 0, isExistMultipart = 0;
+       int addr_cnt = 0;
+       int multipart_cnt = 0;
+
+       int deserial_index = 0;
+       int offset = 0;
+       int i = 0;
+
+       pMmsData = MsgMmsCreate();
+       *ppMmsData = pMmsData;
+
+       // 1. Backup type
+       memcpy(&(pMmsData->backup_type), value, sizeof(int));
+       MSG_DEBUG("[#%2d][%5d] backup type = %d", deserial_index++, offset, pMmsData->backup_type);
+       offset += sizeof(int);
+
+       // 2. Header Data
+       memcpy(&isExistHeader, value + offset, sizeof(int));
+       offset += sizeof(int);
+
+       if (isExistHeader) {
+               pMmsData->header = (MMS_HEADER_DATA_S *)calloc(1, sizeof(MMS_HEADER_DATA_S));
+               memcpy(pMmsData->header, value + offset, sizeof(MMS_HEADER_DATA_S));
+               offset += sizeof(MMS_HEADER_DATA_S);
+
+               memcpy(&addr_cnt, value + offset, sizeof(int));
+               offset += sizeof(int);
+
+               pMmsData->header->to = NULL;
+
+               for (i = 0; i < addr_cnt; i++) {
+                       MMS_ADDRESS_DATA_S* to_addr = (MMS_ADDRESS_DATA_S*)calloc(1, sizeof(MMS_ADDRESS_DATA_S));
+
+                       memcpy(&(to_addr->address_type), value + offset, sizeof(int));
+                       MSG_DEBUG("[#%2d][%5d] address type = %d", deserial_index++, offset, to_addr->address_type);
+                       offset += sizeof(int);
+
+                       memcpy(to_addr->address_val, value + offset, sizeof(char)*MAX_ADDRESS_VAL_LEN);
+                       MSG_DEBUG("[#%2d][%5d] address val = %s", deserial_index++, offset, to_addr->address_val);
+                       offset += sizeof(char)*MAX_ADDRESS_VAL_LEN;
+
+                       pMmsData->header->to = g_list_append(pMmsData->header->to, (void *)to_addr);
+               }
+       }
+
+       // 3. Smil Data
+       memcpy(&isExistSmil, value + offset, sizeof(int));
+       offset += sizeof(int);
+
+       if (isExistSmil) {
+               pMmsData->smil = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
+               memcpy(pMmsData->smil, value + offset, sizeof(MMS_MULTIPART_DATA_S));
+               offset += sizeof(MMS_MULTIPART_DATA_S);
+
+               MSG_DEBUG("SMIL file path = [%s]", pMmsData->smil->szFilePath);
+               MSG_DEBUG("SMIL nMultipartDataLen = [%d]", pMmsData->smil->nMultipartDataLen);
+
+               if (pMmsData->smil->nMultipartDataLen > 0) {
+                       pMmsData->smil->pMultipartData = (char *)calloc(1, sizeof(char)*pMmsData->smil->nMultipartDataLen);
+                       memcpy(pMmsData->smil->pMultipartData, value + offset, sizeof(char)*pMmsData->smil->nMultipartDataLen);
+                       MSG_DEBUG("[#%2d][%5d] smil data ptr = %p", deserial_index++, offset, pMmsData->smil->pMultipartData);
+                       offset += sizeof(char)*pMmsData->smil->nMultipartDataLen;
+               } else {
+                       pMmsData->smil->pMultipartData = NULL;
+               }
+       }
+
+       // 4. Multipart list data
+       memcpy(&isExistMultipart, value + offset, sizeof(int));
+       offset += sizeof(int);
+
+       if (isExistMultipart) {
+               memcpy(&multipart_cnt, value + offset, sizeof(int));
+               offset += sizeof(int);
+
+               MSG_DEBUG("Multipart list count = [ %d]", multipart_cnt);
+
+               pMmsData->multipartlist = NULL;
+
+               for (i = 0; i < multipart_cnt; i++) {
+                       MMS_MULTIPART_DATA_S *multipart_data = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
+                       memcpy(multipart_data, value + offset, sizeof(MMS_MULTIPART_DATA_S));
+                       offset += sizeof(MMS_MULTIPART_DATA_S);
+
+                       MSG_DEBUG("Multipart file path = [%s]", multipart_data->szFilePath);
+
+                       if (multipart_data->nMultipartDataLen > 0) {
+                               multipart_data->pMultipartData = (char *)calloc(1, sizeof(char)*multipart_data->nMultipartDataLen);
+                               memcpy(multipart_data->pMultipartData, value + offset, sizeof(char)*multipart_data->nMultipartDataLen);
+                               MSG_DEBUG("[#%2d][%5d] multipart_data ptr = %p", deserial_index++, offset, multipart_data->pMultipartData);
+                               offset += sizeof(char)*multipart_data->nMultipartDataLen;
+                       } else {
+                               multipart_data->pMultipartData = NULL;
+                       }
+
+                       pMmsData->multipartlist = g_list_append(pMmsData->multipartlist, (void *)multipart_data);
+               }
+       }
+
+       MSG_DEBUG("Final offset : %d", offset);
+
+       MSG_END();
+       return 0;
+}
diff --git a/utils/MsgSmil.cpp b/utils/MsgSmil.cpp
new file mode 100755 (executable)
index 0000000..bc8df8d
--- /dev/null
@@ -0,0 +1,2006 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+#include <ctype.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#include "MsgMmsMessage.h"
+#include "MsgInternalTypes.h"
+#include "MsgSmil.h"
+#include "MsgDebug.h"
+
+#define INVALID_HOBJ   -1
+#define MSG_SMIL_MAX_DOC       1
+#define MSG_SMIL_COLOR_SIZE    10
+#define MSG_STDSTR_SHORT       0x7F
+
+typedef int HMsgSmil; //SmilDoc Handle
+
+typedef enum _SMIL_ELEMENT_T {
+       ELEMENT_SMIL,
+       ELEMENT_HEAD,
+       ELEMENT_LAYOUT,
+       ELEMENT_ROOTLAYOUT,
+       ELEMENT_REGION,
+       ELEMENT_TRANSITION,
+       ELEMENT_META,
+       ELEMENT_BODY,
+       ELEMENT_PAR,
+       ELEMENT_PARAM,
+       ELEMENT_TEXT,
+       ELEMENT_IMG,
+       ELEMENT_AUDIO,
+       ELEMENT_VIDEO,
+       ELEMENT_REF,
+       ELEMENT_ANIMATE,
+       ELEMENT_MAX,
+} SMIL_ELEMENT_T;
+
+typedef enum _SMIL_ATTRIBUTE_T {
+       ATTRIBUTE_UNKNOWN = -1,
+       ATTRIBUTE_ID,
+       ATTRIBUTE_TOP,
+       ATTRIBUTE_LEFT,
+       ATTRIBUTE_WIDTH,
+       ATTRIBUTE_HEIGHT,
+       ATTRIBUTE_FIT,
+       ATTRIBUTE_BGCOLOR,
+       ATTRIBUTE_DUR,
+       ATTRIBUTE_SRC,
+       ATTRIBUTE_COLOR,
+       ATTRIBUTE_BOLD,
+       ATTRIBUTE_UNDERLINE,
+       ATTRIBUTE_ITALIC,
+       ATTRIBUTE_REVERSE,
+       ATTRIBUTE_DIRECTION,
+       ATTRIBUTE_SIZE,
+       ATTRIBUTE_FONT,
+       ATTRIBUTE_REGION,
+       ATTRIBUTE_NAME,
+       ATTRIBUTE_VALUE,
+       ATTRIBUTE_ALT,
+       ATTRIBUTE_TYPE,
+       ATTRIBUTE_SUBTYPE,
+       ATTRIBUTE_CONTENT,
+       ATTRIBUTE_FGCOLOR,
+       ATTRIBUTE_TEXTFORMAT,
+       ATTRIBUTE_TRANSIN,
+       ATTRIBUTE_TRANSOUT,
+       ATTRIBUTE_BEGIN,
+       ATTRIBUTE_END,
+       ATTRIBUTE_REPEAT_COUNT,
+} SMIL_ATTRIBUTE_T;
+
+typedef struct _MsgSmilDoc {
+       xmlDocPtr pSmilDoc;
+       xmlNodePtr pstRootNode;
+} MsgSmilDoc;
+
+/* static variables */
+static char gszEmptyRawDoc[] = "<smil><head><layout></layout></head><body></body></smil>";
+
+__thread MsgSmilDoc *__gpaMsgSmilDoc[MSG_SMIL_MAX_DOC]={NULL, };
+__thread char gszColor[MSG_SMIL_COLOR_SIZE + 1] = {0, };
+
+__thread bool gCmd[ELEMENT_MAX] = {false, };
+__thread MMS_SMIL_ROOTLAYOUT gRootlayout = {};
+__thread MMS_SMIL_REGION *gRegion = NULL;
+__thread MMS_PAGE_S *gPage = NULL;
+__thread MMS_MEDIA_S *gMedia = NULL;
+__thread MMS_SMIL_TRANSITION *gTransition = NULL;
+__thread MMS_SMIL_META *gMeta = NULL;
+
+//For Parse Smil
+static int MsgSmilGetColorValue(xmlChar *content);
+static int MsgSmilGetTime(char *pValue);
+static int MsgSmilAtoIHexa(char *pInput);
+static int MsgSmilGetElementID(char *pString);
+static int MsgSmilGetAttrID(char *pString);
+static int MsgSmilGetFontSizeValue(char *pString);
+static bool MsgSmilGetFontAttrib(char *pString);
+static MmsTextDirection MsgSmilGetFontDirection(char *pString);
+static MmsSmilFontType MsgSmilGetFontTypeValue(char *pString);
+
+static xmlNodePtr MsgSmilGetNodeByElementName(xmlNodePtr pstNode, char *pszName);
+
+//For Generate Smil
+static HMsgSmil MsgSmilCreateEmptySmilDoc(void);
+static HMsgSmil MsgSmilCreateSmilDoc(char *pszRawData);
+static bool MsgSmilDestroyDoc(HMsgSmil hSmilDoc);
+static bool IsValidSmilDocNo(int nSmilDocNo);
+static char *MsgSmilGetRawData(HMsgSmil hSmilDoc);
+
+static const char *MsgSmilColorValueToString(int nValue);
+
+static bool MsgSmilAddPage(HMsgSmil hSmilDoc, MMS_PAGE_S *pstSmilPage);
+static bool MsgSmilAddRootLayout(HMsgSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout);
+static bool MsgSmilAddRegion(HMsgSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion);
+static bool MsgSmilAddMedia(HMsgSmil hSmilDoc, int nPageNo, int nMediaIdx, MMS_MEDIA_S *pstSmilMedia, char *pszContentID);
+static xmlNode *MsgSmilCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID);
+static xmlNode *MsgSmilCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID);
+static bool MsgSmilInsertFirstChild(xmlNode *pParent, xmlNode *pNode);
+static bool MsgSmilInsertNode(xmlNode *pParent, xmlNode *pLeftSibling, xmlNode *pNode);
+static void MsgSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue);
+
+
+int MsgSmilGetColorValue(xmlChar *content)
+{
+       int color;
+       char color_inp[9] = {0,};
+
+       if (content[0] == '#') {        // RGB value
+               snprintf(color_inp, sizeof(color_inp),"FF%s", (char *)&content[1]);
+               color = MsgSmilAtoIHexa(color_inp);
+       } else if (content[0] == '0' && (content[1] == 'x' || content[1] == 'X')) {
+               snprintf(color_inp, sizeof(color_inp),"%s", (char *)&content[2]);
+               color = MsgSmilAtoIHexa(color_inp);
+       } else {
+               MSG_DEBUG("Invalid Color Value");
+               color = 0x00000000;
+       }
+
+       return color;
+}
+
+
+const char *MsgSmilColorValueToString(int nValue)
+{
+       unsigned char alpha = (nValue & 0xFF000000) >> 24;
+       unsigned char red = (nValue & 0xFF0000) >> 16;
+       unsigned char green = (nValue & 0x00FF00) >> 8;
+       unsigned char blue = nValue & 0x0000FF;
+
+       if (alpha == 0xFF) {
+               snprintf(gszColor, sizeof(gszColor), "#%02x%02x%02x", red, green, blue);
+       } else {
+               snprintf(gszColor, sizeof(gszColor), "0x%02x%02x%02x%02x", alpha, red, green, blue);
+       }
+
+       MSG_DEBUG("color value : [%s]", gszColor);
+
+       return gszColor;
+}
+
+
+int MsgSmilAtoIHexa(char *pInput)
+{
+       int res = 0;
+       int len = 0;
+       int temp = 1;
+       int i  = 0;
+       int j = 0;
+       char *pOutput = NULL;
+
+       len = strlen(pInput);
+       pOutput = (char *)malloc(len + 1);
+
+       if (pOutput == NULL) {
+               MSG_DEBUG("Memory full");
+               goto __CATCH;
+       }
+
+       memset(pOutput, 0, len + 1);
+
+       for (i = len - 1; i >= 0; i--) {
+               for (j = 0; j < (len - 1 - i); j++) {
+                       temp *= 16;
+               }
+
+               switch (pInput[i]) {
+               case '0':
+                       pOutput[i] = 0;
+                       break;
+
+               case '1':
+                       pOutput[i] = 1;
+                       break;
+
+               case '2':
+                       pOutput[i] = 2;
+                       break;
+
+               case '3':
+                       pOutput[i] = 3;
+                       break;
+
+               case '4':
+                       pOutput[i] = 4;
+                       break;
+
+               case '5':
+                       pOutput[i] = 5;
+                       break;
+
+               case '6':
+                       pOutput[i] = 6;
+                       break;
+
+               case '7':
+                       pOutput[i] = 7;
+                       break;
+
+               case '8':
+                       pOutput[i] = 8;
+                       break;
+
+               case '9':
+                       pOutput[i] = 9;
+                       break;
+
+               case 'a':
+               case 'A':
+                       pOutput[i] = 10;
+                       break;
+
+               case 'b':
+               case 'B':
+                       pOutput[i] = 11;
+                       break;
+
+               case 'c':
+               case 'C':
+                       pOutput[i] = 12;
+                       break;
+
+               case 'd':
+               case 'D':
+                       pOutput[i] = 13;
+                       break;
+
+               case 'e':
+               case 'E':
+                       pOutput[i] = 14;
+                       break;
+
+               case 'f':
+               case 'F':
+                       pOutput[i] = 15;
+                       break;
+               }
+
+               res += (pOutput[i] * temp);
+               temp = 1;
+       }
+
+__CATCH:
+
+       if (pOutput) {
+               free(pOutput);
+               pOutput = NULL;
+       }
+
+       return res;
+}
+
+int MsgSmilGetTime(char *pValue)
+{
+       char *pTemp = NULL;
+       bool bMSec = false;
+       int retVal = 0;
+       int i = 0;
+
+       if (pValue == NULL || pValue[0] == '\0')
+               return 0;
+
+       /* Default time unit -> millisecond */
+       if (strstr(pValue, "msec"))
+               bMSec = true;
+
+       if (strstr(pValue, "ms"))
+               bMSec = true;
+
+       pTemp = (char *)malloc(strlen(pValue) + 1);
+
+       if (NULL == pTemp) {
+               MSG_DEBUG("malloc for <time> attribute is failed");
+               return 0;
+       }
+
+       while (isdigit(pValue[i])) {
+               pTemp[i] = pValue[i];
+               i++;
+       }
+       pTemp[i] = '\0';
+
+       /* Detect 's' and 'ms' here */
+       retVal = atoi(pTemp);
+
+       if (bMSec == false)
+               retVal *= 1000;
+
+       if (pTemp) {
+               free(pTemp);
+               pTemp = NULL;
+       }
+
+       return retVal;
+}
+
+int MsgSmilGetElementID(char *pString)
+{
+       if (!strcmp(pString, "smil"))
+               return ELEMENT_SMIL;
+       else if (!strcmp(pString, "head"))
+               return ELEMENT_HEAD;
+       else if (!strcmp(pString, "layout"))
+               return ELEMENT_LAYOUT;
+       else if (!strcmp(pString, "root-layout"))
+               return ELEMENT_ROOTLAYOUT;
+       else if (!strcmp(pString, "region"))
+               return ELEMENT_REGION;
+       else if (!strcmp(pString, "body"))
+               return ELEMENT_BODY;
+       else if (!strcmp(pString, "par"))
+               return ELEMENT_PAR;
+       else if (!strcmp(pString, "param"))
+               return ELEMENT_PARAM;
+       else if (!strcmp(pString, "text"))
+               return ELEMENT_TEXT;
+       else if (!strcmp(pString, "img"))
+               return ELEMENT_IMG;
+       else if (!strcmp(pString, "audio"))
+               return ELEMENT_AUDIO;
+       else if (!strcmp(pString, "video"))
+               return ELEMENT_VIDEO;
+       else if (!strcmp(pString, "ref"))
+               return ELEMENT_REF;
+       else if (!strcmp(pString, "animate"))
+               return ELEMENT_ANIMATE;
+       else if (!strcmp(pString, "root-layout"))
+               return ELEMENT_HEAD;
+       else if (!strcmp(pString, "transition"))
+               return ELEMENT_TRANSITION;
+       else if (!strcmp(pString, "meta"))
+               return ELEMENT_META;
+       else
+               return -1;
+}
+
+int MsgSmilGetAttrID(char *pString)
+{
+       if (!strcmp(pString, "id"))
+               return ATTRIBUTE_ID;
+       else if (!strcmp(pString, "top"))
+               return ATTRIBUTE_TOP;
+       else if (!strcmp(pString, "left"))
+               return ATTRIBUTE_LEFT;
+       else if (!strcmp(pString, "width"))
+               return ATTRIBUTE_WIDTH;
+       else if (!strcmp(pString, "height"))
+               return ATTRIBUTE_HEIGHT;
+       else if (!strcmp(pString, "fit"))
+               return ATTRIBUTE_FIT;
+       else if (!strcmp(pString, "backgroundColor") || !strcmp(pString, "background-color"))
+               return ATTRIBUTE_BGCOLOR;
+       else if (!strcmp(pString, "dur"))
+               return ATTRIBUTE_DUR;
+       else if (!strcmp(pString, "src"))
+               return ATTRIBUTE_SRC;
+       else if (!strcmp(pString, "color"))
+               return ATTRIBUTE_COLOR;
+       else if (!strcmp(pString, "bold"))
+               return ATTRIBUTE_BOLD;
+       else if (!strcmp(pString, "underline"))
+               return ATTRIBUTE_UNDERLINE;
+       else if (!strcmp(pString, "italic"))
+               return ATTRIBUTE_ITALIC;
+       else if (!strcmp(pString, "reverse"))
+               return ATTRIBUTE_REVERSE;
+       else if (!strcmp(pString, "direction"))
+               return ATTRIBUTE_DIRECTION;
+       else if (!strcmp(pString, "size"))
+               return ATTRIBUTE_SIZE;
+       else if (!strcmp(pString, "font"))
+               return ATTRIBUTE_FONT;
+       else if (!strcmp(pString, "region"))
+               return ATTRIBUTE_REGION;
+       else if (!strcmp(pString, "name"))
+               return ATTRIBUTE_NAME;
+       else if (!strcmp(pString, "value"))
+               return ATTRIBUTE_VALUE;
+       else if (!strcmp(pString, "alt"))
+               return ATTRIBUTE_ALT;
+       else if (!strcmp(pString, "type"))
+               return ATTRIBUTE_TYPE;
+       else if (!strcmp(pString, "subtype"))
+               return ATTRIBUTE_SUBTYPE;
+       else if (!strcmp(pString, "content"))
+               return ATTRIBUTE_CONTENT;
+       else if (!strcmp(pString, "transIn"))
+               return ATTRIBUTE_TRANSIN;
+       else if (!strcmp(pString, "transOut"))
+               return ATTRIBUTE_TRANSOUT;
+       else if (!strcmp(pString, "begin"))
+               return ATTRIBUTE_BEGIN;
+       else if (!strcmp(pString, "end"))
+               return ATTRIBUTE_END;
+       else if (!strcmp(pString, "repeatCount"))
+               return ATTRIBUTE_REPEAT_COUNT;
+
+       return -1;
+}
+
+bool MsgSmilGetFontAttrib(char *pString)
+{
+       if (!strcmp(pString, "true"))
+               return true;
+       else
+               return false;
+}
+
+MmsTextDirection MsgSmilGetFontDirection(char *pString)
+{
+       MmsTextDirection direction = MMS_TEXT_DIRECTION_INVALID;
+
+       if (!strcmp(pString, "right"))
+               direction = MMS_TEXT_DIRECTION_RIGHT;
+       else if (!strcmp(pString, "down"))
+               direction = MMS_TEXT_DIRECTION_DOWN;
+
+       return direction;
+}
+
+int MsgSmilGetFontSizeValue(char *pString)
+{
+       if (!strcmp(pString, "small"))
+               return MMS_SMIL_FONT_SIZE_SMALL;
+       else if (!strcmp(pString, "normal"))
+               return MMS_SMIL_FONT_SIZE_NORMAL;
+       else if (!strcmp(pString, "large"))
+               return MMS_SMIL_FONT_SIZE_LARGE;
+       else
+               return atoi(pString);
+}
+
+MmsSmilFontType MsgSmilGetFontTypeValue(char *pString)
+{
+
+       if (!strcmp(pString, "normal"))
+               return MMS_SMIL_FONT_TYPE_NORMAL;
+       else if (!strcmp(pString, "italic"))
+               return MMS_SMIL_FONT_TYPE_ITALIC;
+       else if (!strcmp(pString, "bold"))
+               return MMS_SMIL_FONT_TYPE_BOLD;
+       else if (!strcmp(pString, "underline"))
+               return MMS_SMIL_FONT_TYPE_UNDERLINE;
+       else
+               return MMS_SMIL_FONT_TYPE_NORMAL;
+}
+
+HMsgSmil MsgSmilCreateEmptySmilDoc(void)
+{
+       HMsgSmil hMmsSmil;
+
+       MSG_BEGIN();
+
+       hMmsSmil = MsgSmilCreateSmilDoc(gszEmptyRawDoc);
+
+       MSG_DEBUG("Create an empty smilDoc.(Handle = %d)", hMmsSmil);
+
+       MSG_END();
+
+       return hMmsSmil;
+}
+
+HMsgSmil MsgSmilCreateSmilDoc(char *pszRawData)
+{
+       int nSmilDocNo = 0;
+       xmlNodePtr stRootNode;
+
+       MSG_BEGIN();
+
+       // Destroy smil doc if present
+       if (NULL != __gpaMsgSmilDoc[nSmilDocNo]) {
+
+               if (false == MsgSmilDestroyDoc(nSmilDocNo)) {
+                       MSG_DEBUG("MsgSmilDestroyDoc: Failed!");
+               }
+       }
+
+       for (nSmilDocNo = 0; nSmilDocNo < MSG_SMIL_MAX_DOC; nSmilDocNo++) {
+               if (NULL == __gpaMsgSmilDoc[nSmilDocNo])
+                       break;
+       }
+
+       if (MSG_SMIL_MAX_DOC == nSmilDocNo) {
+               MSG_DEBUG("SmilDoc table is full. Can't create.");
+               return INVALID_HOBJ;
+       }
+       __gpaMsgSmilDoc[nSmilDocNo] = (MsgSmilDoc*)malloc(sizeof(MsgSmilDoc));
+       if (NULL ==  __gpaMsgSmilDoc[nSmilDocNo]) {
+               MSG_DEBUG("Memory Allocation Failed.");
+               return INVALID_HOBJ;
+       }
+       memset(__gpaMsgSmilDoc[nSmilDocNo], 0, sizeof(MsgSmilDoc));
+
+       __gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc = xmlParseMemory(pszRawData, strlen(pszRawData));
+       if (NULL == __gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc) {
+
+               if (false == MsgSmilDestroyDoc(nSmilDocNo)) {
+                       MSG_DEBUG("MsgSmilDestroyDoc: Failed!");
+               }
+               return INVALID_HOBJ;
+       }
+
+       stRootNode = xmlDocGetRootElement(__gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc);
+       if (NULL == stRootNode) {
+               MSG_DEBUG("Empty document");
+               if (false == MsgSmilDestroyDoc(nSmilDocNo)) {
+                       MSG_DEBUG("MsgSmilDestroyDoc: Failed!");
+               }
+               return INVALID_HOBJ;
+       }
+
+       if (xmlStrcmp(stRootNode->name, (const xmlChar *) "smil")) {
+               MSG_DEBUG("Document of the wrong type, root node != smil");
+               if (false == MsgSmilDestroyDoc(nSmilDocNo)) {
+                       MSG_DEBUG("MsgSmilDestroyDoc: Failed!");
+               }
+               return INVALID_HOBJ;
+       }
+
+       __gpaMsgSmilDoc[nSmilDocNo]->pstRootNode = stRootNode;
+
+       MSG_END();
+       return ((HMsgSmil)nSmilDocNo);
+}
+
+bool MsgSmilDestroyDoc(HMsgSmil hSmilDoc)
+{
+       int nSmilDocNo = (int)hSmilDoc;
+       bool bFlag = true;
+       MSG_BEGIN();
+
+       if (0 <= nSmilDocNo &&
+               nSmilDocNo < MSG_SMIL_MAX_DOC &&
+               __gpaMsgSmilDoc[nSmilDocNo]) {
+               if (__gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc) {
+                       xmlFreeDoc(__gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc);
+               }
+
+               if (__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode) {
+                       //Need to Check
+               }
+               free(__gpaMsgSmilDoc[nSmilDocNo]);
+               __gpaMsgSmilDoc[nSmilDocNo] = NULL;
+       } else {
+               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
+               bFlag =  false;
+       }
+
+       MSG_END();
+       return bFlag;
+}
+
+bool IsValidSmilDocNo(int nSmilDocNo)
+{
+       bool bIsValidSmil = false;
+
+       MSG_BEGIN();
+
+       if (0 <= nSmilDocNo &&
+               nSmilDocNo < MSG_SMIL_MAX_DOC &&
+               __gpaMsgSmilDoc[nSmilDocNo] &&
+               __gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc) {
+               bIsValidSmil = true;
+       }
+
+       MSG_END();
+       return bIsValidSmil;
+}
+
+char *MsgSmilGetRawData(HMsgSmil hSmilDoc)
+{
+       int nSmilDocNo = (int)hSmilDoc;
+       char *pszRawData = NULL;
+
+       MSG_BEGIN();
+
+       if (IsValidSmilDocNo(nSmilDocNo)) {
+               //xmlSaveFormatFileEnc("-", __gpaMmsSmilDoc[nSmilDocNo]->pSmilDoc, "UTF-8", 1);
+               xmlDocDumpMemory(__gpaMsgSmilDoc[nSmilDocNo]->pSmilDoc, (xmlChar **)(&pszRawData) , NULL);
+               if (NULL == pszRawData) {
+                       MSG_DEBUG("Invalid pSmilDoc (now wellformed document)");
+               }
+               MSG_END();
+       } else {
+               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
+       }
+       return pszRawData;
+}
+
+bool MsgSmilAddPage(HMsgSmil hSmilDoc, MMS_PAGE_S *pstSmilPage)
+{
+       int nSmilDocNo = hSmilDoc;
+
+       MSG_BEGIN();
+
+       bool ret = true;
+
+       if (IsValidSmilDocNo(nSmilDocNo)) {
+               xmlNodePtr pstParElement;
+               xmlNodePtr pstBodyElement;
+               xmlNodePtr pstParList;
+               char szBuf[MSG_STDSTR_SHORT] = {0, };
+
+               pstBodyElement = MsgSmilGetNodeByElementName(__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode, (char *)"body");
+
+               if (NULL == pstBodyElement) {
+                       MSG_DEBUG("There is no <body> node. Can't create <par> node.");
+                       return false;
+               }
+
+               /* Create "par"  node and insert it */
+               pstParElement = xmlNewNode(NULL, (xmlChar *)"par");
+
+               if (NULL == pstParElement) {
+                       MSG_DEBUG("Can't create <par> node. (from XmlParser)");
+                       return false;
+               }
+
+               MSG_SEC_DEBUG("Par Element Name = %s", (char *)pstParElement->name);
+
+               /* Add attributes to "par" */
+               if (pstSmilPage->nDur > 0) {
+                       snprintf(szBuf, MSG_STDSTR_SHORT, "%dms", pstSmilPage->nDur);
+                       xmlSetProp(pstParElement, (const xmlChar *)"dur", (const xmlChar *)szBuf);
+                       MSG_DEBUG("[Set Attribute] : dur : [%s]", szBuf);
+               }
+
+               /* Find the insertion point : right sibling of the last <par> node or first child of <body> */
+               pstParList = xmlGetLastChild(pstBodyElement);
+
+               if (pstParList) {
+                       ret = MsgSmilInsertNode(pstBodyElement, pstParList, pstParElement);
+                       if (ret == false)
+                               xmlFreeNode(pstParElement);
+               } else {
+                       ret = MsgSmilInsertFirstChild(pstBodyElement, pstParElement);
+                       if (ret == false)
+                               xmlFreeNode(pstParElement);
+               }
+       } else {
+               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
+               return false;
+       }
+
+
+       return ret;
+}
+
+bool MsgSmilAddRootLayout(HMsgSmil hSmilDoc, MMS_SMIL_ROOTLAYOUT *pstSmilRootLayout)
+{
+       int nSmilDocNo = hSmilDoc;
+       xmlNodePtr pstRootLayout = NULL;
+       xmlNodePtr pstLayoutList = NULL;
+       xmlNodePtr pstRootLayoutList = NULL;
+       char szBuf[MSG_STDSTR_SHORT] = {0, };
+
+       MSG_BEGIN();
+
+       if (IsValidSmilDocNo(nSmilDocNo)) {
+               pstLayoutList = MsgSmilGetNodeByElementName(__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode, (char *)"layout");
+
+               if (NULL == pstLayoutList) {
+                       MSG_DEBUG("There is no <layout> node. Can't create <root-layout> node.");
+                       return false;
+               }
+               MSG_SEC_DEBUG("Layout Element Name = %s ", (char *)pstLayoutList->name);
+
+               pstRootLayoutList = MsgSmilGetNodeByElementName(__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode, (char *)"root-layout");
+
+               if (NULL != pstRootLayoutList) {
+                       MSG_DEBUG("There is <root-layout> node already");
+                       MSG_SEC_DEBUG("Root Layout Element Name = %s", (char *)pstRootLayoutList->name);
+                       return false;
+               }
+               /* Create "root-layout" node and insert it */
+               pstRootLayout = xmlNewNode(NULL, (xmlChar *)"root-layout");
+               if (NULL == pstRootLayout) {
+                       MSG_DEBUG("Can't create <root-layout> node. (from XmlParser)");
+                       return false;
+               }
+               MSG_SEC_DEBUG("Root Layout Element Name = %s", (char *)pstRootLayout->name);
+
+               if (pstSmilRootLayout->bBgColor == true) {      // Replace value later
+                       if ( ( (pstSmilRootLayout->bgColor & 0xFF000000) >> 24 ) > 0) {//check alpha value
+                               xmlSetProp(pstRootLayout, (const xmlChar *)"backgroundColor", (const xmlChar *)MsgSmilColorValueToString(pstSmilRootLayout->bgColor));
+                       }
+               }
+
+
+               //width
+               if (true == pstSmilRootLayout->width.bUnitPercent) {
+                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRootLayout->width.value);
+                       xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)szBuf);
+               } else {
+                       if (pstSmilRootLayout->width.value > 0) {
+                               snprintf(szBuf, MSG_STDSTR_SHORT, "%d", pstSmilRootLayout->width.value);
+                               xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)szBuf);
+                       } else {
+                               MSG_DEBUG("Set Width : default value [100%%]");
+                               xmlSetProp(pstRootLayout, (const xmlChar *)"width", (const xmlChar *)"100%");
+                       }
+               }
+
+               //Height
+               if (true == pstSmilRootLayout->height.bUnitPercent) {
+                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRootLayout->height.value);
+                       xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)szBuf);
+               } else {
+                       if (pstSmilRootLayout->height.value > 0) {
+                               snprintf(szBuf, MSG_STDSTR_SHORT, "%d", pstSmilRootLayout->height.value);
+                               xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)szBuf);
+                       } else {
+
+                               xmlSetProp(pstRootLayout, (const xmlChar *)"height", (const xmlChar *)"100%");
+                       }
+               }
+
+               xmlAddChild(pstLayoutList, pstRootLayout);
+
+               return true;
+       } else {
+               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
+               return false;
+       }
+
+}
+
+bool MsgSmilAddRegion(HMsgSmil hSmilDoc, MMS_SMIL_REGION *pstSmilRegion)
+{
+       int nSmilDocNo = hSmilDoc;
+
+       MSG_BEGIN();
+
+       if (IsValidSmilDocNo(nSmilDocNo)) {
+               int nRootWidth = 0;
+               int nRootHeight = 0;
+               xmlNodePtr pstRegion;
+               xmlNodePtr pstLayoutList;
+               xmlNodePtr pstRootLayoutList;
+               xmlAttrPtr pAttribute;
+               char szBuf[MSG_STDSTR_SHORT] = {0, };
+
+               pstLayoutList = MsgSmilGetNodeByElementName(__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode, (char *)"layout");
+               if (NULL == pstLayoutList) {
+                       MSG_DEBUG(" There is no <layout> node. Can't create <region> node");
+                       return false;
+               }
+
+               /* Find the insertion point : right sibling of the last root-layout node or first child of pLayout */
+               pstRootLayoutList = MsgSmilGetNodeByElementName(__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode, (char *)"root-layout");
+
+               if (NULL == pstRootLayoutList) {
+                       MSG_DEBUG("There is no <root-layout> node. Can't create <root-layout> node.");
+                       return false;
+               } else {
+                       pAttribute =  pstRootLayoutList->properties;
+               }
+
+               if (NULL == pAttribute) {
+                       MSG_DEBUG("There is no Attribute in <root-layout> node.");
+                       return false;
+               }
+
+               xmlAttrPtr pstAttr = pAttribute;
+               for ( ; pstAttr; pstAttr = pstAttr->next) {
+                       int     attrType;
+                       MSG_SEC_DEBUG("AttributeType: (%s, %s) ", pstAttr->name, pstAttr->children->content);
+                       switch (attrType = MsgSmilGetAttrID((char *)pstAttr->name)) {
+                       case ATTRIBUTE_WIDTH:
+                               {
+//                                     int bUnitPercent;
+
+//                                     if (strchr((char *)pstAttr->children->content, '%'))
+//                                             bUnitPercent = true;
+//                                     else
+//                                             bUnitPercent = false;
+
+                                       nRootWidth = atoi((char *)pstAttr->children->content);
+                               }
+                               break;
+
+                       case ATTRIBUTE_HEIGHT:
+                               {
+//                                     int bUnitPercent;
+
+//                                     if (strchr((char *)pstAttr->children->content, '%'))
+//                                             bUnitPercent = true;
+//                                     else
+//                                             bUnitPercent = false;
+
+                                       nRootHeight = atoi((char *)pstAttr->children->content);
+                               }
+                               break;
+                       }
+               }
+
+
+               /* Add attributes */
+               if (pstSmilRegion) {
+                       /* Create "region" node and insert it */
+                       pstRegion = xmlNewNode(NULL, (xmlChar *)"region");
+                       if (NULL == pstRegion) {
+                               MSG_DEBUG("Can't create <region> node. (from XmlParser)");
+                               return false;
+                       }
+
+                       MSG_SEC_DEBUG("Region Element Name = %s", (char *)pstRegion->name);
+
+                       if (strlen(pstSmilRegion->szID) > 0) {
+                               xmlSetProp(pstRegion, (const xmlChar *)"id", (const xmlChar *)pstSmilRegion->szID);
+                               MSG_DEBUG("[Set Attribute] : Region Id : [%s]", pstSmilRegion->szID);
+                       }
+
+                       if (pstSmilRegion->bBgColor == true) {
+                               MSG_DEBUG(" [Set Attribute] : BkGrd Color");
+                               if ( ( (pstSmilRegion->bgColor & 0xFF000000) >> 24 ) > 0) {
+                                       xmlSetProp(pstRegion, (const xmlChar *)"backgroundColor", (const xmlChar *)MsgSmilColorValueToString(pstSmilRegion->bgColor));
+                                       MSG_DEBUG("[Set Attribute] : backgroundColor [%s]", MsgSmilColorValueToString(pstSmilRegion->bgColor));
+                               }
+                       }
+
+
+                       if (true == pstSmilRegion->width.bUnitPercent) {
+                               if (pstSmilRegion->width.value > 0) {
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->width.value);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"width", (const xmlChar *)szBuf);
+                                       MSG_DEBUG("[Set Attribute] : Width : [%s]", szBuf);
+                               }
+                       } else {
+                               // Note: nRootWidth should be in terms of value(pixel) not unitpercent(%)
+                               // Validation should be done before this.
+                               if (pstSmilRegion->width.value >= 0 &&
+                                       pstSmilRegion->width.value <= nRootWidth) {
+                                       int iWidth = (pstSmilRegion->width.value * 100) / nRootWidth;
+
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iWidth);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"width", (const xmlChar *)szBuf);
+                                       MSG_DEBUG("[Set Attribute] : Width : [%s]", szBuf);
+                               }
+                       }
+
+                       if (true == pstSmilRegion->height.bUnitPercent) {
+                               if (pstSmilRegion->height.value > 0) {
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->height.value);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"height", (const xmlChar *)szBuf);
+                                       MSG_DEBUG("[Set Attribute] : Height : [%s]", szBuf);
+                               }
+                       } else {
+                               // Note: nRootHeight should be in terms of value(pixel) not unitpercent(%)
+                               // Validation should be done before this.
+                               if (pstSmilRegion->height.value >= 0 &&
+                                       pstSmilRegion->height.value <= nRootHeight) {
+                                       int iHeight = (pstSmilRegion->height.value * 100) / nRootHeight;
+
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iHeight);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"height", (const xmlChar *)szBuf);
+
+                                       MSG_DEBUG("[Set Attribute] : Height : [%s]", szBuf);
+                               }
+                       }
+
+                       if (true == pstSmilRegion->nLeft.bUnitPercent) {
+                               if (pstSmilRegion->nLeft.value > 0) {
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->nLeft.value);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"left", (const xmlChar *)szBuf);
+
+                                       MSG_DEBUG("[Set Attribute] : Left : [%s]", szBuf);
+                               }
+                       } else {
+                               // Note: nRootWidth should be in terms of value(pixel) not unitpercent(%)
+                               // Validation should be done before this.
+                               if (pstSmilRegion->nLeft.value >= 0) {
+                                       int iLeft = (pstSmilRegion->nLeft.value * 100) / nRootWidth;
+
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iLeft);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"left", (const xmlChar *)szBuf);
+                                       MSG_DEBUG("[Set Attribute] : Left : [%s]", szBuf);
+                               }
+                       }
+
+                       if (true == pstSmilRegion->nTop.bUnitPercent) {
+                               if (pstSmilRegion->nTop.value > 0) {
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", pstSmilRegion->nTop.value);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"top", (const xmlChar *)szBuf);
+                                       MSG_DEBUG("[Set Attribute] : Top : [%s]", szBuf);
+                               }
+                       } else {
+                               // Note: nRootHeight should be in terms of value(pixel) not unitpercent(%)
+                               // Validation should be done before this.
+                               if (pstSmilRegion->nTop.value >= 0) {
+                                       int iTop = (pstSmilRegion->nTop.value * 100) / nRootHeight;
+
+                                       snprintf(szBuf, MSG_STDSTR_SHORT, "%d%%", iTop);
+                                       xmlSetProp(pstRegion, (const xmlChar *)"top", (const xmlChar *)szBuf);
+                                       MSG_DEBUG("[Set Attribute] : Top : [%s]", szBuf);
+                               }
+                       }
+
+                       //Fit Attribute
+                       if (MMSUI_IMAGE_REGION_FIT_MEET == pstSmilRegion->fit) {
+                               xmlSetProp(pstRegion, (const xmlChar *)"fit", (const xmlChar *)"meet");
+                               MSG_DEBUG("[Set Attribute] : fit : [meet]");
+                       } else if (MMSUI_IMAGE_REGION_FIT_HIDDEN == pstSmilRegion->fit) {
+                               xmlSetProp(pstRegion, (const xmlChar *)"fit", (const xmlChar *)"hidden");
+                               MSG_DEBUG("[Set Attribute] : fit : [hidden]");
+                       }
+
+                       MsgSmilInsertNode(pstLayoutList, pstRootLayoutList, pstRegion);
+
+               } else
+                       MSG_DEBUG("There is no attribute in <region> node");
+
+               MSG_END();
+               return true;
+       } else {
+               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
+               return false;
+       }
+}
+
+bool MsgSmilAddMedia( HMsgSmil hSmilDoc, int nPageNo, int nMediaIdx, MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
+{
+       int nSmilDocNo = hSmilDoc;
+
+       MSG_BEGIN();
+
+       if (NULL == pszContentID) {
+               MSG_DEBUG(" Content Id is NULL");
+               return false;
+       }
+       memset(pszContentID, 0, sizeof(pstSmilMedia->szContentID));
+       if (IsValidSmilDocNo(nSmilDocNo)) {
+               int nIndex = 0;
+               xmlNode *pstMedia;
+               xmlNode *pstLastChild;
+               xmlNodePtr pstParList;
+               char *pszExt ;
+
+               pstParList = MsgSmilGetNodeByElementName(__gpaMsgSmilDoc[nSmilDocNo]->pstRootNode, (char *)"par");
+
+               if (NULL == pstParList) {
+                       MSG_DEBUG("There is no <par> node. Can't create <media> node.");
+                       return false;
+               }
+
+               for (nIndex = 0; (pstParList &&  nIndex < nPageNo); nIndex++) {
+                       pstParList = pstParList->next;
+               }
+
+               if (NULL == pstParList) {
+                       MSG_DEBUG("There is no such page node. Can't insert <media> node.");
+                       return false;
+               }
+
+               /* Find insertion point and make a contentID */
+               pstLastChild = xmlGetLastChild(pstParList);
+
+               pszExt = strrchr(pstSmilMedia->szFileName, '.');
+               if (pszExt && !strrchr(pszExt, '/'))
+                       snprintf(pszContentID, MSG_MSG_ID_LEN+1, "%lu_%lu%s", (unsigned long)nPageNo, (unsigned long)nMediaIdx, pszExt);
+               else
+                       snprintf(pszContentID, MSG_MSG_ID_LEN+1, "%lu_%lu", (unsigned long)nPageNo, (unsigned long)nMediaIdx);
+
+               snprintf(pstSmilMedia->szContentLocation, sizeof(pstSmilMedia->szContentLocation), "%s", pstSmilMedia->szFileName);
+
+               /* Create <media> node and insert set attribute */
+               switch (pstSmilMedia->mediatype) {
+               case MMS_SMIL_MEDIA_TEXT:
+                       pstMedia = MsgSmilCreateTextNode(pstSmilMedia, pszContentID);
+                       break;
+               case MMS_SMIL_MEDIA_AUDIO:
+               case MMS_SMIL_MEDIA_VIDEO:
+               case MMS_SMIL_MEDIA_IMG:
+                       pstMedia = MsgSmilCreateMMNode(pstSmilMedia, pszContentID);
+                       break;
+               default:
+                       MSG_DEBUG("Invalid media type. Can't insert such-<media> node.");
+                       return false;
+               }
+
+               if (NULL == pstMedia) {
+                       MSG_DEBUG("Can't create <media> node. (from XmlParser) (media-type:%d)", pstSmilMedia->mediatype);
+                       return false;
+               }
+
+               /* Find the insertion point : the last child of <par> node */
+               if (pstLastChild)
+                       MsgSmilInsertNode(pstParList, pstLastChild, pstMedia);
+               else
+                       MsgSmilInsertFirstChild(pstParList, pstMedia);
+
+               MSG_END();
+               return true;
+       } else {
+               MSG_DEBUG("Invalid SmilDoc(hSmilDoc:%d)", nSmilDocNo);
+               return false;
+       }
+}
+
+xmlNode *MsgSmilCreateTextNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
+{
+       xmlNode *pstMedia = NULL;
+       xmlNode *pstParam = NULL;
+       char szBuf[MSG_STDSTR_SHORT] = {0, };
+       char szSizeBuf[MSG_STDSTR_SHORT] = {0, };
+
+       MSG_BEGIN();
+
+       pstMedia = xmlNewNode(NULL, (xmlChar *)"text");
+       if (NULL == pstMedia) {
+               MSG_DEBUG("Can't create <Text> node.");
+               return NULL;
+       }
+
+       /* Add attributes */
+       if (pstSmilMedia) {
+
+               if (strlen(pstSmilMedia->regionId) > 0) {
+                       xmlSetProp(pstMedia, (const xmlChar *)"region", (const xmlChar *)pstSmilMedia->regionId);
+                       MSG_DEBUG("[Set Attribute] Region Id : [%s]", pstSmilMedia->regionId);
+               }
+
+               if (pstSmilMedia->sMedia.sText.nBegin > 0) {
+                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sText.nBegin);
+                       xmlSetProp(pstMedia, (const xmlChar *)"begin", (const xmlChar *) szBuf);
+                       MSG_DEBUG("[Set Attribute] Begin : [%s]", szBuf);
+               }
+
+               if (pstSmilMedia->sMedia.sText.nDurTime > 0) {
+                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sText.nDurTime);
+                       xmlSetProp(pstMedia, (const xmlChar *)"dur", (const xmlChar *)szBuf);
+                       MSG_DEBUG("[Set Attribute] Duration : [%s]", szBuf);
+               }
+
+               if (strlen(pstSmilMedia->szAlt) > 0) {
+                       snprintf (szBuf, sizeof(szBuf), "%s", pstSmilMedia->szAlt);
+                       xmlSetProp(pstMedia, (const xmlChar *)"alt", (const xmlChar *)szBuf);
+                       MSG_DEBUG("[Set Attribute] Alternate : [%s]", szBuf);
+               }
+
+#if 0
+               char szFilePathWithCid[MSG_MSG_ID_LEN + 5];     // for "cid:"
+
+               snprintf (szFilePathWithCid, sizeof(szFilePathWithCid), "cid:%s", pszContentID);
+               MsgSmilSetAttribute(pstMedia, (char *)"src", szFilePathWithCid);
+#endif
+               if (strlen(pstSmilMedia->szContentLocation) > 0) {
+                       MsgSmilSetAttribute(pstMedia, (char *)"src", pstSmilMedia->szContentLocation); //using content Location in Smil
+                       MSG_DEBUG("[Set Attribute] Src : [%s]", pstSmilMedia->szContentLocation);
+               }
+
+               if ( ( (pstSmilMedia->sMedia.sText.nColor & 0xFF000000) >> 24 ) > 0) {
+                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
+
+                       if (NULL == pstParam) {
+                               MSG_DEBUG("Cannot create <param> node");
+                               return false;
+                       }
+
+                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"foreground-color");
+                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)MsgSmilColorValueToString(pstSmilMedia->sMedia.sText.nColor));
+
+                       MSG_DEBUG("[Set param] Font Foreground Color : [0x%08x]", pstSmilMedia->sMedia.sText.nColor);
+
+                       MsgSmilInsertFirstChild(pstMedia, pstParam);
+               }
+
+               if ( ( (pstSmilMedia->sMedia.sText.nBgColor & 0xFF000000) >> 24 ) > 0) {
+                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
+
+                       if (NULL == pstParam) {
+                               MSG_DEBUG("Cannot create <param> node");
+                               return false;
+                       }
+
+                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"background-color");
+                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)MsgSmilColorValueToString(pstSmilMedia->sMedia.sText.nBgColor));
+
+                       MSG_DEBUG("[Set param] Font Background Color : [0x%08x]", pstSmilMedia->sMedia.sText.nBgColor);
+
+                       MsgSmilInsertFirstChild(pstMedia, pstParam);
+               }
+
+               if (pstSmilMedia->sMedia.sText.nSize > 0) {
+                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
+                       if (NULL == pstParam) {
+                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node");
+                               return false;
+                       }
+
+                       if (pstSmilMedia->sMedia.sText.nSize  <= MMS_SMIL_FONT_SIZE_SMALL) {
+                               snprintf(szSizeBuf, sizeof(szSizeBuf), "%s", "small");
+                       } else if ((pstSmilMedia->sMedia.sText.nSize  > MMS_SMIL_FONT_SIZE_SMALL) && (pstSmilMedia->sMedia.sText.nSize  < MMS_SMIL_FONT_SIZE_LARGE)) {
+                               snprintf(szSizeBuf, sizeof(szSizeBuf), "%s", "normal");
+                       } else {
+                               snprintf(szSizeBuf, sizeof(szSizeBuf), "%s", "large");
+                       }
+
+                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textsize");
+                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
+
+                       MSG_DEBUG("[Set param] textsize : [%s]", szSizeBuf);
+
+                       MsgSmilInsertFirstChild(pstMedia, pstParam);
+               }
+
+               if (pstSmilMedia->sMedia.sText.bBold == true) {
+                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
+                       if (NULL == pstParam) {
+                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node");
+                               return false;
+                       }
+
+                       snprintf(szSizeBuf, sizeof(szSizeBuf), "%s", "bold");
+
+                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
+                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
+
+                       MSG_DEBUG("[Set param] textattribute : [%s]", szSizeBuf);
+
+                       MsgSmilInsertFirstChild(pstMedia, pstParam);
+               }
+
+               if (pstSmilMedia->sMedia.sText.bItalic == true) {
+                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
+                       if (NULL == pstParam) {
+                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node");
+                               return false;
+                       }
+
+                       snprintf(szSizeBuf, sizeof(szSizeBuf), "%s", "italic");
+
+                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
+                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
+
+                       MSG_DEBUG("[Set param] textattribute : [%s]", szSizeBuf);
+
+                       MsgSmilInsertFirstChild(pstMedia, pstParam);
+               }
+
+               if (pstSmilMedia->sMedia.sText.bUnderLine == true) {
+                       pstParam = xmlNewNode(NULL, (xmlChar *)"param");
+                       if (NULL == pstParam) {
+                               MSG_DEBUG(" __MmsCreateTextNode: cannot create <param> node");
+                               return false;
+                       }
+
+                       snprintf(szSizeBuf, sizeof(szSizeBuf), "%s", "underline");
+
+                       xmlSetProp(pstParam, (const xmlChar *)"name", (const xmlChar *)"textattribute");
+                       xmlSetProp(pstParam, (const xmlChar *)"value", (const xmlChar *)szSizeBuf);
+
+                       MSG_DEBUG("[Set param] textattribute : [%s]", szSizeBuf);
+
+                       MsgSmilInsertFirstChild(pstMedia, pstParam);
+               }
+       }
+
+       MSG_END();
+       return pstMedia;
+}
+
+xmlNode *MsgSmilCreateMMNode(MMS_MEDIA_S *pstSmilMedia, char *pszContentID)
+{
+       xmlNode *pstMedia = NULL;
+       char szBuf[MSG_STDSTR_SHORT] = {0, };
+
+       MSG_BEGIN();
+
+       if (!pstSmilMedia)
+               return NULL;
+
+       switch (pstSmilMedia->mediatype) {
+       case MMS_SMIL_MEDIA_AUDIO:
+               pstMedia = xmlNewNode(NULL, (xmlChar *)"audio");
+               break;
+
+       case MMS_SMIL_MEDIA_VIDEO:
+               pstMedia = xmlNewNode(NULL, (xmlChar *)"video");
+               break;
+
+       case MMS_SMIL_MEDIA_IMG:
+               pstMedia = xmlNewNode(NULL, (xmlChar *)"img");
+               break;
+       default:
+               MSG_DEBUG("Invalid media type. Can't insert such-<media> node.");
+               return NULL;
+       }
+
+       if (pstMedia) {
+
+               if (strlen(pstSmilMedia->regionId) > 0) {
+                       xmlSetProp(pstMedia, (const xmlChar *)"region", (const xmlChar *)pstSmilMedia->regionId);
+                       MSG_DEBUG("[Set Attribute] Region Id : [%s]", pstSmilMedia->regionId);
+               }
+
+#if 0 //set src attribute cid
+               char szFilePathWithCid[MSG_MSG_ID_LEN + 5];     // for "cid:"
+               snprintf (szFilePathWithCid, sizeof(szFilePathWithCid), "cid:%s", pszContentID);
+               MsgSmilSetAttribute(pstMedia, (char *)"src", szFilePathWithCid);
+#endif
+               if (strlen(pstSmilMedia->szContentLocation) > 0) {
+                       MsgSmilSetAttribute(pstMedia, (char *)"src", pstSmilMedia->szContentLocation); //using content Location in Smil
+                       MSG_DEBUG("[Set Attribute] src : [%s]", pstSmilMedia->szContentLocation);
+               }
+
+               if (pstSmilMedia->sMedia.sAVI.nBegin > 0) {
+                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sAVI.nBegin);
+                       xmlSetProp(pstMedia, (const xmlChar *)"begin", (const xmlChar *)szBuf);
+                       MSG_DEBUG("[Set Attribute] begin : [%s]", szBuf);
+               }
+
+               if (pstSmilMedia->sMedia.sAVI.nDurTime > 0) {
+                       snprintf (szBuf, sizeof(szBuf), "%dms", pstSmilMedia->sMedia.sAVI.nDurTime);
+                       xmlSetProp(pstMedia, (const xmlChar *)"dur", (const xmlChar *)szBuf);
+                       MSG_DEBUG("[Set Attribute] dur : [%s]", szBuf);
+               }
+
+               if (strlen(pstSmilMedia->szAlt) > 0) {
+                       snprintf (szBuf, sizeof(szBuf), "%s", pstSmilMedia->szAlt);
+                       xmlSetProp(pstMedia, (const xmlChar *)"alt", (const xmlChar *)szBuf);
+                       MSG_DEBUG("[Set Attribute] alt : [%s]", szBuf);
+               }
+       } else {
+               MSG_DEBUG("There is no attribute in such-<media> node");
+       }
+
+       MSG_END();
+       return pstMedia;
+}
+
+bool MsgSmilInsertFirstChild(xmlNode *pstParent, xmlNode *pstCurr)
+{
+       bool bFlag = true;
+
+       MSG_BEGIN();
+
+        if (NULL == xmlAddChild(pstParent, pstCurr)) {
+                MSG_SEC_DEBUG("%s Node not added", pstCurr->name);
+               bFlag = false;
+        }
+
+        MSG_END();
+        return bFlag;
+}
+
+bool MsgSmilInsertNode(xmlNode *pstParent, xmlNode *pstLeftSibling, xmlNode *pstCurr)
+{
+       MSG_BEGIN();
+       bool bFlag = true;
+
+       if (pstLeftSibling) {
+               /* Parent Node is Unused */
+
+               while (pstLeftSibling->next !=NULL)
+                       pstLeftSibling = pstLeftSibling->next;
+
+                if (NULL == xmlAddNextSibling(pstLeftSibling, pstCurr)) {
+                        MSG_SEC_DEBUG("%s Node not added", pstCurr->name);
+                       bFlag = false;
+                }
+       } else {
+                if (NULL == xmlAddChild(pstParent, pstCurr)) {
+                        MSG_SEC_DEBUG("%s Node not added", pstCurr->name);
+                       bFlag = false;
+                }
+       }
+       MSG_END();
+       return bFlag;
+}
+
+void MsgSmilSetAttribute(xmlNode *pNode, char *szField, char *szValue)
+{
+       MSG_BEGIN();
+
+       if (pNode && szField && strlen(szField)) {
+               if (szValue && strlen(szValue)) {
+                       xmlSetProp(pNode, (const xmlChar *)szField, (const xmlChar *)szValue);
+               } else {
+                       xmlSetProp(pNode, (const xmlChar *)szField, (const xmlChar *)"");
+               }
+       }
+
+       MSG_END();
+}
+
+xmlNodePtr MsgSmilGetNodeByElementName(xmlNodePtr pstNode, char *pszName)
+{
+
+       if ((NULL != pstNode) && (NULL != pszName)) {
+               xmlNodePtr pstTempNode;
+               xmlNodePtr pstReturnNode;
+
+               pstTempNode = pstNode;
+
+               for ( ; pstTempNode; pstTempNode = pstTempNode->next) {
+
+                       if (0 == strcasecmp((char *)pstTempNode->name, pszName)) {
+                               MSG_SEC_DEBUG("Find Node : name [%s][%p]", (char *)pstTempNode->name, pstTempNode);
+                               return pstTempNode;
+                       }
+
+                       if (pstTempNode->children) {
+                               pstReturnNode = MsgSmilGetNodeByElementName(pstTempNode->children, pszName);
+                               if (NULL != pstReturnNode) {
+                                       return pstReturnNode;
+                               }
+                       }
+
+               }
+       }
+       return NULL;
+}
+
+void MsgSmilParseNode(MMS_MESSAGE_DATA_S *pMmsMsg, xmlNode *a_node, int depth)
+{
+       MSG_BEGIN();
+
+       int elementType;
+       int attrType;
+
+       xmlNode *cur_node = NULL;
+
+       if (depth == 0) {//init
+               memset(gCmd, 0x00, ELEMENT_MAX);
+               memset(&gRootlayout, 0x00, sizeof(MMS_SMIL_ROOTLAYOUT));
+               gRegion = NULL;
+               gPage = NULL;
+               gMedia = NULL;
+               gTransition = NULL;
+               gMeta = NULL;
+       }
+
+       for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
+               MSG_SEC_DEBUG("## [%d] node type : [Element], name: [%s] ##", depth, cur_node->name);
+
+               if (cur_node->type == XML_ELEMENT_NODE) {
+                       // Get Smil Element =====================================================
+
+                       switch (elementType = MsgSmilGetElementID((char *)cur_node->name)) {
+                       case ELEMENT_ROOTLAYOUT:
+                               gCmd[ELEMENT_ROOTLAYOUT] = true;
+                               break;
+
+                       case ELEMENT_REGION:
+                               if (gRegion) {
+                                       MSG_DEBUG("region exist");
+                                       return;
+                               }
+
+                               gRegion = (MMS_SMIL_REGION *)calloc(1, sizeof(MMS_SMIL_REGION));
+                               gCmd[ELEMENT_REGION] = true;
+                               break;
+
+                       case ELEMENT_TRANSITION:
+                               if (gTransition) {
+                                       MSG_DEBUG("Transition exist");
+                                       return;
+                               }
+
+                               gTransition = (MMS_SMIL_TRANSITION *)calloc(1, sizeof(MMS_SMIL_TRANSITION));
+                               gCmd[ELEMENT_TRANSITION] = true;
+                               break;
+
+                       case ELEMENT_META:
+                               if (gMeta) {
+                                       MSG_DEBUG("Meta exist");
+                                       return;
+                               }
+
+                               gMeta = (MMS_SMIL_META *)calloc(1, sizeof(MMS_SMIL_META));
+                               gCmd[ELEMENT_META] = true;
+                               break;
+
+                       case ELEMENT_PAR:
+                               if (gPage) {
+                                       MSG_DEBUG("Page exist");
+                                       return;
+                               }
+
+                               gPage = (MMS_PAGE_S *)calloc(1, sizeof(MMS_PAGE_S));
+                               gCmd[ELEMENT_PAR] = true;
+                               break;
+
+                       case ELEMENT_PARAM: // Need to check the original element type
+                               gCmd[ELEMENT_PARAM] = true;
+                               break;
+
+                       case ELEMENT_TEXT:
+                               if (gMedia) {
+                                       MSG_DEBUG("Media exist");
+                                       return;
+                               }
+
+                               gMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               gMedia->mediatype = MMS_SMIL_MEDIA_TEXT;
+                               gCmd[ELEMENT_TEXT] = true;
+                               break;
+
+                       case ELEMENT_IMG:
+                               if (gMedia) {
+                                       MSG_DEBUG("Media exist");
+                                       return;
+                               }
+
+                               gMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               gMedia->mediatype = MMS_SMIL_MEDIA_IMG;
+                               gCmd[ELEMENT_IMG] = true;
+                               break;
+
+                       case ELEMENT_AUDIO:
+                               if (gMedia) {
+                                       MSG_DEBUG("Media exist");
+                                       return;
+                               }
+
+                               gMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               gMedia->mediatype = MMS_SMIL_MEDIA_AUDIO;
+                               gCmd[ELEMENT_AUDIO] = true;
+                               break;
+
+                       case ELEMENT_VIDEO:
+                               if (gMedia) {
+                                       MSG_DEBUG("Media exist");
+                                       return;
+                               }
+
+                               gMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               gMedia->mediatype = MMS_SMIL_MEDIA_VIDEO;
+                               gCmd[ELEMENT_VIDEO] = true;
+                               break;
+
+                       case ELEMENT_REF:
+                               if (gMedia) {
+                                       MSG_DEBUG("Media exist");
+                                       return;
+                               }
+
+                               gMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               gMedia->mediatype = MMS_SMIL_MEDIA_IMG_OR_VIDEO;
+                               gCmd[ELEMENT_REF] = true;
+                               break;
+
+                       case ELEMENT_ANIMATE:
+                               if (gMedia) {
+                                       MSG_DEBUG("Media exist");
+                                       return;
+                               }
+
+                               gMedia = (MMS_MEDIA_S *)calloc(1, sizeof(MMS_MEDIA_S));
+                               gMedia->mediatype = MMS_SMIL_MEDIA_ANIMATE;
+                               gCmd[ELEMENT_ANIMATE] = true;
+                               break;
+
+                       default:
+                               MSG_DEBUG("Unsupported element type [%d]", elementType);
+                               break;
+                       }
+
+                       //Get Smil Attribute =====================================================
+                       xmlAttr *pAttr = cur_node->properties;
+
+                       SMIL_ATTRIBUTE_T paramType = ATTRIBUTE_UNKNOWN;
+
+                       for ( ; pAttr; pAttr = pAttr->next) {
+
+                               MSG_SEC_DEBUG("## attribute type : name [%s] value [%s] ##", pAttr->name, pAttr->children->content);
+
+                               switch (attrType = MsgSmilGetAttrID((char *)pAttr->name)) {
+                               case ATTRIBUTE_ID:
+                                       {
+                                               if (gCmd[ELEMENT_REGION] && gRegion) {
+                                                       strncpy(gRegion->szID, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
+                                               } else if (gCmd[ELEMENT_TRANSITION] && gTransition) {
+                                                       strncpy(gTransition->szID, (char *)pAttr->children->content, MAX_SMIL_TRANSITION_ID - 1);
+                                               } else if (gCmd[ELEMENT_META] && gMeta) {
+                                                       strncpy(gMeta->szID, (char *)pAttr->children->content, MAX_SMIL_META_ID - 1);
+                                               }
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_TOP:
+                                       {
+                                               int bUnitPercent;
+                                               int value;
+
+                                               if (strchr((char *)pAttr->children->content, '%'))
+                                                       bUnitPercent = true;
+                                               else
+                                                       bUnitPercent = false;
+
+                                               value = atoi((char *)pAttr->children->content);
+
+                                               if (gCmd[ELEMENT_REGION] && gRegion) {
+                                                       gRegion->nTop.bUnitPercent = bUnitPercent;
+                                                       gRegion->nTop.value = value;
+                                               }
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_LEFT:
+                                       {
+                                               int bUnitPercent;
+                                               int value;
+
+                                               if (strchr((char *)pAttr->children->content, '%'))
+                                                       bUnitPercent = true;
+                                               else
+                                                       bUnitPercent = false;
+
+                                               value = atoi((char *)pAttr->children->content);
+
+                                               if (gCmd[ELEMENT_REGION] && gRegion) {
+                                                       gRegion->nLeft.bUnitPercent = bUnitPercent;
+                                                       gRegion->nLeft.value = value;
+                                               }
+                                       }
+                                       break;
+
+
+                               case ATTRIBUTE_WIDTH:
+                                       {
+                                               int bUnitPercent;
+                                               int value;
+
+                                               if (strchr((char *)pAttr->children->content, '%'))
+                                                       bUnitPercent = true;
+                                               else
+                                                       bUnitPercent = false;
+
+                                               value = atoi((char *)pAttr->children->content);
+
+                                               if (gCmd[ELEMENT_ROOTLAYOUT]) {
+                                                       gRootlayout.width.bUnitPercent = bUnitPercent;
+                                                       gRootlayout.width.value = value;
+                                               } else if (gCmd[ELEMENT_REGION] && gRegion) {
+                                                       gRegion->width.bUnitPercent = bUnitPercent;
+                                                       gRegion->width.value = value;
+                                               }
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_HEIGHT:
+                                       {
+                                               int bUnitPercent;
+                                               int value;
+
+                                               if (strchr((char *)pAttr->children->content, '%'))
+                                                       bUnitPercent = true;
+                                               else
+                                                       bUnitPercent = false;
+
+                                               value = atoi((char *)pAttr->children->content);
+
+                                               if (gCmd[ELEMENT_ROOTLAYOUT]) {
+                                                       gRootlayout.height.bUnitPercent = bUnitPercent;
+                                                       gRootlayout.height.value = value;
+                                               } else if (gCmd[ELEMENT_REGION] && gRegion) {
+                                                       gRegion->height.bUnitPercent = bUnitPercent;
+                                                       gRegion->height.value = value;
+                                               }
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_FIT:
+                                       if (gCmd[ELEMENT_REGION] && gRegion) {
+                                               if (!strcmp((char *)pAttr->children->content, "meet")) {
+                                                       gRegion->fit = MMSUI_IMAGE_REGION_FIT_MEET;
+                                               } else {
+                                                       gRegion->fit = MMSUI_IMAGE_REGION_FIT_HIDDEN;
+                                               }
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_BGCOLOR:
+                                       if (gCmd[ELEMENT_ROOTLAYOUT]) {
+                                               gRootlayout.bBgColor = true;
+                                               gRootlayout.bgColor = MsgSmilGetColorValue(pAttr->children->content);
+                                       } else if (gCmd[ELEMENT_REGION] && gRegion) {
+                                               gRegion->bBgColor = true;
+                                               gRegion->bgColor = MsgSmilGetColorValue(pAttr->children->content);
+                                       } else if (gCmd[ELEMENT_TEXT] && gMedia) {
+                                               gMedia->sMedia.sText.nBgColor = MsgSmilGetColorValue(pAttr->children->content);
+                                       } else if (gMedia) {
+                                               gMedia->sMedia.sAVI.nBgColor = MsgSmilGetColorValue(pAttr->children->content);
+                                       }
+
+                                       break;
+
+                               case ATTRIBUTE_DUR:
+                                       if (gCmd[ELEMENT_PAR] && gPage) {
+                                               if (elementType == ELEMENT_PAR)
+                                                       gPage->nDur =  MsgSmilGetTime((char *)pAttr->children->content);
+                                       } else if (gCmd[ELEMENT_TRANSITION] && gTransition) {
+                                               gTransition->nDur =  MsgSmilGetTime((char *)pAttr->children->content);
+                                       } else if (gCmd[ELEMENT_TEXT] && gMedia) {
+                                               gMedia->sMedia.sText.nDurTime =  MsgSmilGetTime((char *)pAttr->children->content);
+                                       } else if (gMedia) {
+                                               gMedia->sMedia.sAVI.nDurTime =  MsgSmilGetTime((char *)pAttr->children->content);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_SRC:
+                               {
+                                       if (gMedia) {
+                                               char szContentID[MSG_MSG_ID_LEN + 1] = {0,};
+                                               int cLen;
+
+                                               snprintf(szContentID, sizeof(szContentID), "%s", (char *)pAttr->children->content);
+
+                                               cLen = strlen(szContentID);
+                                               if (!strncasecmp(szContentID, "cid:", 4)) {
+                                                       strncpy(gMedia->szContentID, szContentID + 4, cLen - 4);
+                                                       gMedia->szContentID[cLen - 4] = '\0';
+                                               } else {
+                                                       strncpy(gMedia->szContentID, szContentID, cLen);
+                                                       gMedia->szContentID[cLen] = '\0';
+                                               }
+                                       }
+                                       break;
+                               }
+                               case ATTRIBUTE_COLOR:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.nColor = MsgSmilGetColorValue(pAttr->children->content);
+                                       break;
+
+                               case ATTRIBUTE_SIZE:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.nSize = atoi((char *)pAttr->children->content);
+                                       break;
+
+                               case ATTRIBUTE_BOLD:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia) {
+                                               gMedia->sMedia.sText.bBold = MsgSmilGetFontAttrib((char *)pAttr->children->content);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_UNDERLINE:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.bUnderLine = MsgSmilGetFontAttrib((char *)pAttr->children->content);
+                                       break;
+
+                               case ATTRIBUTE_ITALIC:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.bItalic = MsgSmilGetFontAttrib((char *)pAttr->children->content);
+                                       break;
+
+                               case ATTRIBUTE_REVERSE:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.bReverse = MsgSmilGetFontAttrib((char *)pAttr->children->content);
+                                       break;
+
+                               case ATTRIBUTE_DIRECTION:
+                                       if (gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.nDirection = MsgSmilGetFontDirection((char *)pAttr->children->content);
+                                       break;
+                               case ATTRIBUTE_REGION:
+                                       if (gMedia) {
+                                               strncpy(gMedia->regionId, (char *)pAttr->children->content, MAX_SMIL_REGION_ID - 1);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_TRANSIN:
+                                       if (gMedia) {
+                                               if (gCmd[ELEMENT_TEXT] )
+                                                       strncpy(gMedia->sMedia.sText.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
+                                               else
+                                                       strncpy(gMedia->sMedia.sAVI.szTransInId, (char *)pAttr->children->content, MAX_SMIL_TRANSIN_ID - 1);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_TRANSOUT:
+                                       if (gMedia) {
+                                               if (gCmd[ELEMENT_TEXT])
+                                                       strncpy(gMedia->sMedia.sText.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
+                                               else
+                                                       strncpy(gMedia->sMedia.sAVI.szTransOutId, (char *)pAttr->children->content, MAX_SMIL_TRANSOUT_ID - 1);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_BEGIN:
+                                       if (gMedia) {
+                                               if (gCmd[ELEMENT_TEXT])
+                                                       gMedia->sMedia.sText.nBegin = MsgSmilGetTime((char *)pAttr->children->content);
+                                               else
+                                                       gMedia->sMedia.sAVI.nBegin = MsgSmilGetTime((char *)pAttr->children->content);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_END:
+                                       if (gMedia) {
+                                               if (gCmd[ELEMENT_TEXT])
+                                                       gMedia->sMedia.sText.nEnd = MsgSmilGetTime((char *)pAttr->children->content);
+                                               else
+                                                       gMedia->sMedia.sAVI.nEnd = MsgSmilGetTime((char *)pAttr->children->content);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_REPEAT_COUNT:
+                                       if (gMedia) {
+                                               if (gCmd[ELEMENT_TEXT])
+                                                       gMedia->sMedia.sText.nRepeat = atoi((char *)pAttr->children->content);
+                                               else
+                                                       gMedia->sMedia.sAVI.nRepeat = atoi((char *)pAttr->children->content);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_NAME:
+                                       if (gCmd[ELEMENT_PARAM]) {
+
+                                               if (!strcmp((char *)pAttr->children->content, "foreground-color") || !strcmp((char *)pAttr->children->content, "foregroundcolor"))
+                                                       paramType = ATTRIBUTE_FGCOLOR;
+                                               else if (!strcmp((char *)pAttr->children->content, "background-color") || !strcmp((char *)pAttr->children->content, "backgroundcolor"))
+                                                       paramType = ATTRIBUTE_BGCOLOR;
+                                               else if (!strcmp((char *)pAttr->children->content, "textsize"))
+                                                       paramType = ATTRIBUTE_SIZE;
+                                               else if (!strcmp((char *)pAttr->children->content, "textattribute"))
+                                                       paramType = ATTRIBUTE_TEXTFORMAT;
+
+                                       } else if (gCmd[ELEMENT_META] && gMeta) {
+                                               strncpy(gMeta->szName, (char *)pAttr->children->content, MAX_SMIL_META_NAME - 1);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_VALUE:
+
+                                       if (paramType == ATTRIBUTE_SIZE && gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.nSize = MsgSmilGetFontSizeValue((char *)pAttr->children->content);
+                                       else if (paramType == ATTRIBUTE_FGCOLOR && gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.nColor =  MsgSmilGetColorValue(pAttr->children->content);
+                                       else if (paramType == ATTRIBUTE_BGCOLOR && gCmd[ELEMENT_TEXT] && gMedia)
+                                               gMedia->sMedia.sText.nBgColor =  MsgSmilGetColorValue(pAttr->children->content);
+                                       else if (paramType == ATTRIBUTE_TEXTFORMAT && gCmd[ELEMENT_TEXT] && gMedia) {
+                                               MmsSmilFontType fontType;
+
+                                               fontType = MsgSmilGetFontTypeValue((char *)pAttr->children->content);
+
+                                               if (fontType == MMS_SMIL_FONT_TYPE_BOLD)
+                                                       gMedia->sMedia.sText.bBold = true;
+                                               else
+                                                       gMedia->sMedia.sText.bBold = false;
+
+                                               if (fontType == MMS_SMIL_FONT_TYPE_ITALIC)
+                                                       gMedia->sMedia.sText.bItalic = true;
+                                               else
+                                                       gMedia->sMedia.sText.bItalic = false;
+
+                                               if (fontType == MMS_SMIL_FONT_TYPE_UNDERLINE)
+                                                       gMedia->sMedia.sText.bUnderLine = true;
+                                               else
+                                                       gMedia->sMedia.sText.bUnderLine = false;
+                                       }
+                                       paramType = ATTRIBUTE_UNKNOWN;
+                                       break;
+
+                               case ATTRIBUTE_ALT:
+                                       if (gMedia) {
+                                               strncpy(gMedia->szAlt, (char *)pAttr->children->content, MAX_SMIL_ALT_LEN - 1);
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_TYPE:
+                                       if (gTransition) {
+                                               gTransition->nType = (MmsSmilTransType)atoi((char *)pAttr->children->content);
+
+                                               switch (gTransition->nType) {
+                                               case MMS_SMIL_TRANS_SLIDEWIPE:
+                                                       gTransition->nSubType = MMS_SMIL_TRANS_SUB_FROM_LEFT;
+                                                       break;
+                                               case MMS_SMIL_TRANS_BARWIPE:
+                                                       gTransition->nSubType = MMS_SMIL_TRANS_SUB_TOP_TO_BOTTOM;
+                                                       break;
+                                               case MMS_SMIL_TRANS_BARNDOORWIPE:
+                                                       gTransition->nSubType = MMS_SMIL_TRANS_SUB_HORIZONTAL;
+                                                       break;
+                                               default:
+                                                       gTransition->nSubType = MMS_SMIL_TRANS_SUB_NONE;
+                                                       break;
+                                               }
+                                       }
+                                       break;
+
+                               case ATTRIBUTE_SUBTYPE:
+                                       if (gTransition)
+                                               gTransition->nSubType = (MmsSmilTransSubType)atoi((char *)pAttr->children->content);
+                                       break;
+
+                               case ATTRIBUTE_CONTENT:
+                                       if (gMeta)
+                                               strncpy(gMeta->szContent, (char *)pAttr->children->content, MAX_SMIL_META_CONTENT - 1);
+                                       break;
+
+                               default:
+                                       MSG_DEBUG("Undefined Attribute was found!!!!!");
+                                       break;
+                               }
+                       }
+
+                       if (cur_node->children) {//child first
+                               MsgSmilParseNode(pMmsMsg, cur_node->children, depth + 1);
+                       }
+
+                       if (elementType == ELEMENT_REGION && gRegion) {
+                               _MsgMmsAddRegion(pMmsMsg, gRegion);
+                               gRegion = NULL;
+                       } else if (elementType ==  ELEMENT_PAR && gPage) {
+                               _MsgMmsAddPage(pMmsMsg, gPage);
+                               gPage = NULL;
+                       } else if ((elementType == ELEMENT_TEXT || elementType == ELEMENT_IMG || elementType == ELEMENT_AUDIO || elementType == ELEMENT_VIDEO || elementType == ELEMENT_ANIMATE || elementType == ELEMENT_REF)
+                                       && gCmd[ELEMENT_PAR] && gPage && gMedia) {
+                               _MsgMmsAddMedia(gPage, gMedia);
+                               gMedia = NULL;
+                       } else if (elementType == ELEMENT_ROOTLAYOUT) {
+                               _MsgMmsSetRootLayout(pMmsMsg, &gRootlayout);
+                       } else if (elementType == ELEMENT_TRANSITION  && gTransition) {
+                               _MsgMmsAddTransition(pMmsMsg, gTransition);
+                               gTransition = NULL;
+                       } else if (elementType == ELEMENT_META && gMeta) {
+                               _MsgMmsAddMeta(pMmsMsg, gMeta);
+                               gMeta = NULL;
+                       }
+
+                       if (elementType >= ELEMENT_SMIL)
+                               gCmd[elementType] = false;
+
+                       paramType = ATTRIBUTE_UNKNOWN;
+               }
+       }
+
+       MSG_END();
+}
+
+bool MsgSmilParseSmilDoc(MMS_MESSAGE_DATA_S *pstMsgMmsBody, const char *pSmilDoc)
+{
+       MSG_BEGIN();
+
+       xmlDocPtr doc;
+       xmlNodePtr cur;
+
+       if (pSmilDoc == NULL || strlen(pSmilDoc) == 0) {
+               MSG_DEBUG("Invalid Parameter : pSmilDoc [%p]", pSmilDoc);
+               return false;
+       }
+
+       MSG_SEC_INFO("Parse Smil : [%s]", pSmilDoc);
+
+       doc = xmlParseMemory(pSmilDoc, strlen(pSmilDoc));
+       if (doc == NULL) {
+               MSG_DEBUG("Failed xmlParseMemory");
+               return false;
+       }
+
+       cur = xmlDocGetRootElement(doc);
+       if (cur == NULL) {
+               MSG_DEBUG("Failed xmlDocGetRootElement");
+               xmlFreeDoc(doc);
+               return false;
+       }
+
+       if (xmlStrcmp(cur->name, (const xmlChar *) "smil")) {
+               MSG_DEBUG("document of the wrong type, root node != smil");
+               xmlFreeDoc(doc);
+               return false;
+       }
+
+       MsgSmilParseNode(pstMsgMmsBody, cur, 0);
+
+       xmlFreeDoc(doc);
+       MSG_END();
+       return true;
+}
+
+bool MsgSmilGenerateSmilDoc(MMS_MESSAGE_DATA_S *pstMsgMmsBody, char **ppSmilDoc)
+{
+       MSG_BEGIN();
+
+       HMsgSmil hSmilDoc = INVALID_HOBJ;
+       int nIndex;
+       int nMediaIndex;
+       int nTotalPageNum;
+       int nTotalMediaNum;
+       int nRegionCount;
+       MMS_PAGE_S *pstPage;
+       MMS_MEDIA_S *pstMedia;
+       MMS_SMIL_REGION *pstRegion;
+       char *pszRawData;
+
+       hSmilDoc = MsgSmilCreateEmptySmilDoc();
+       if (INVALID_HOBJ == hSmilDoc) {
+               MSG_DEBUG("Invalid SmilDoc[%d]",hSmilDoc);
+               return false;
+       }
+       // Add Root Layout to Smil Document
+       if (false == MsgSmilAddRootLayout(hSmilDoc, &(pstMsgMmsBody->rootlayout))) {
+               MSG_DEBUG("MsgSmilAddRootLayout Failed");
+               MsgSmilDestroyDoc(hSmilDoc);
+       }
+       //Add Region list to Smil Document
+       nRegionCount = pstMsgMmsBody->regionCnt;
+       MSG_DEBUG(" Region Count = [%d]",nRegionCount);
+       for (nIndex = 0; nIndex < nRegionCount; nIndex++) {
+
+               pstRegion = _MsgMmsGetSmilRegion(pstMsgMmsBody, nIndex);
+               if (NULL == pstRegion) {
+                       MSG_DEBUG("pstRegion is NULL");
+                       MsgSmilDestroyDoc(hSmilDoc);
+                       return false;
+               }
+
+               if (false == MsgSmilAddRegion(hSmilDoc, pstRegion)) {
+                       MSG_DEBUG("Adding Region to smil doc failed");
+                       MsgSmilDestroyDoc(hSmilDoc);
+                       return false;
+               }
+       }
+
+       // Add page list to Smil Document
+       nTotalPageNum = pstMsgMmsBody->pageCnt ;
+       MSG_DEBUG(" Page Count = [%d]",nTotalPageNum);
+       for (nIndex = 0; nIndex < nTotalPageNum; nIndex++) {
+
+               pstPage = _MsgMmsGetPage(pstMsgMmsBody, nIndex);
+               if (NULL == pstPage) {
+                       MSG_DEBUG("pstPage is NULL");
+                       MsgSmilDestroyDoc(hSmilDoc);
+                       return false;
+               }
+
+               // Add page to smil doc
+               if (false == MsgSmilAddPage(hSmilDoc, pstPage)) {
+                       MSG_DEBUG("Adding page to smil doc failed");
+                       MsgSmilDestroyDoc(hSmilDoc);
+                       return false;
+               }
+
+               nTotalMediaNum = pstPage->mediaCnt;
+               MSG_DEBUG(" Media Count = [%d]",nTotalMediaNum);
+               for (nMediaIndex = 0; nMediaIndex < nTotalMediaNum; nMediaIndex++) {
+
+                       pstMedia = _MsgMmsGetMedia(pstPage, nMediaIndex);
+                       if (NULL == pstMedia) {
+                               MSG_DEBUG("pMedia is NULL");
+                               MsgSmilDestroyDoc(hSmilDoc);
+                               return false;
+                       }
+
+                       if (false == MsgSmilAddMedia(hSmilDoc, nIndex, nMediaIndex, pstMedia, pstMedia->szContentID)) {
+                               MSG_DEBUG("MsgSmilAddMedia failed");
+                               MsgSmilDestroyDoc(hSmilDoc);
+                               return false;
+                       }
+               }
+       }
+
+       pszRawData = MsgSmilGetRawData(hSmilDoc);
+       if (NULL == pszRawData) {
+               MSG_DEBUG("MsgSmilGetRawData failed");
+               MsgSmilDestroyDoc(hSmilDoc);
+               return false;
+       }
+
+       if (ppSmilDoc) {
+               *ppSmilDoc = pszRawData;
+               MSG_SEC_INFO("Generated Smil : [%s]", pszRawData);
+       }
+
+       MsgSmilDestroyDoc(hSmilDoc);
+       MSG_END();
+       return true;
+}
diff --git a/utils/MsgSoundPlayer.cpp b/utils/MsgSoundPlayer.cpp
deleted file mode 100755 (executable)
index 96bea63..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <wait.h>
-
-#include "MsgHelper.h"
-#include "MsgDebug.h"
-#include "MsgGconfWrapper.h"
-#include "MsgSettingTypes.h"
-#include "MsgSoundPlayer.h"
-
-#include <alarm.h>
-
-/*==================================================================================================
-                                     VARIABLES
-==================================================================================================*/
-static bool g_bRepeat = false;
-static alarm_id_t g_alarmId = 0;
-
-
-/*==================================================================================================
-                                     FUNCTION IMPLEMENTATION
-==================================================================================================*/
-
-
-void MsgSoundPlayStart(bool isEmergency)
-{
-       MSG_BEGIN();
-
-       // Run helper App
-       pid_t childpid;
-       childpid = fork();
-
-       if (childpid == -1)
-       {
-               MSG_DEBUG("Failed to fork");
-       }
-
-       if (childpid == 0)
-       {
-               MSG_DEBUG("Child Process - Run helper app for Sound");
-
-               if (isEmergency)
-                       execl("/usr/bin/msg-helper", MSG_EMERGENCY_SOUND_START, NULL);
-               else
-                       execl("/usr/bin/msg-helper", MSG_NORMAL_SOUND_START, NULL);
-
-               MSG_DEBUG("Faild to run helper app for Sound");
-
-               exit(0);
-       }
-       else if (childpid != 0)
-       {
-               MSG_DEBUG("Parent Process - Mms Plugin Storage.");
-       }
-
-       if (g_bRepeat == false)
-               g_bRepeat = MsgSoundSetRepeatAlarm();
-
-       MSG_END();
-}
-
-void MsgSoundPlayStop()
-{
-       MSG_BEGIN();
-
-       // Run helper App
-       pid_t childpid;
-       childpid = fork();
-
-       if (childpid == -1)
-       {
-               MSG_DEBUG("Failed to fork");
-       }
-
-       if (childpid == 0)
-       {
-               MSG_DEBUG("Child Process - Run helper app for Sound");
-
-               execl("/usr/bin/msg-helper", MSG_SOUND_STOP, NULL);
-
-               MSG_DEBUG("Faild to run helper app for Sound");
-
-               exit(0);
-       }
-       else if (childpid != 0)
-       {
-               MSG_DEBUG("Parent Process - Mms Plugin Storage.");
-       }
-
-       MSG_END();
-}
-
-
-bool MsgSoundSetRepeatAlarm()
-{
-       bool bRet = false;
-
-       int nRepeatValue = 0;
-       long    nRepeatTime = 0;
-
-       nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
-
-       switch (nRepeatValue)
-       {
-               case MSG_ALERT_TONE_ONCE:
-                       nRepeatTime = 0;
-               break;
-
-               case MSG_ALERT_TONE_2MINS:
-                       nRepeatTime = 2;
-               break;
-
-               case MSG_ALERT_TONE_5MINS:
-                       nRepeatTime = 5;
-               break;
-
-               case MSG_ALERT_TONE_10MINS:
-                       nRepeatTime = 10;
-               break;
-
-               default:
-                       MSG_DEBUG("Invalid Repetition time");
-               break;
-       }
-
-       MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
-
-       if (nRepeatTime > 0)
-       {
-               bRet = MsgSoundCreateRepeatAlarm(nRepeatTime);
-       }
-
-       return bRet;
-}
-
-
-bool MsgSoundCreateRepeatAlarm(int RepeatTime)
-{
-       MSG_BEGIN();
-
-       time_t current_time;
-       struct tm current_tm;
-
-       time(&current_time);
-
-       localtime_r(&current_time, &current_tm);
-
-       int retval =0;
-
-       retval = alarmmgr_init("msg-service-tools");
-
-       if (retval != 0)
-       {
-               MSG_FATAL("alarmmgr_init() error [%d]", retval);
-               return false;
-       }
-
-       alarm_info_t* alarm_info;
-       alarm_date_t target_time;
-
-       alarm_info = alarmmgr_create_alarm();
-
-       target_time.year = 0;
-       target_time.month = 0;
-       target_time.day = 0;
-
-       if (current_tm.tm_min+RepeatTime < 60)
-       {
-               target_time.hour = current_tm.tm_hour;
-               target_time.min = current_tm.tm_min+RepeatTime;
-       }
-       else
-       {
-               if (current_tm.tm_hour < 12)
-               {
-                       target_time.hour = current_tm.tm_hour+1;
-               }
-               else
-               {
-                       target_time.hour = (current_tm.tm_hour+1)%12;
-               }
-
-               target_time.min = (current_tm.tm_min+RepeatTime)%60;
-       }
-
-       target_time.sec = current_tm.tm_sec;
-
-       retval = alarmmgr_set_time(alarm_info, target_time);
-       MSG_DEBUG("alarmmgr_set_time return = [%d]", retval);
-       retval = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
-       MSG_DEBUG("alarmmgr_set_repeat_mode return = [%d]", retval);
-       retval = alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
-       MSG_DEBUG("alarmmgr_set_type return = [%d]", retval);
-       retval = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
-       MSG_DEBUG("alarmmgr_add_alarm_with_localtime return = [%d]", retval);
-
-       retval = alarmmgr_set_cb(MsgSoundRepeatAlarmCB, (void *)alarm_info);
-
-       if (retval != 0)
-       {
-               MSG_DEBUG("alarmmgr_set_cb() error [%d]", retval);
-               return false;
-       }
-
-       MSG_DEBUG("Repeat Alarm Time : [%d-%d-%d %d:%d:%d]",
-               target_time.year,target_time.month,target_time.day,
-               target_time.hour, target_time.min, target_time.sec);
-
-       MSG_END();
-
-       return true;
-}
-
-
-int MsgSoundRepeatAlarmCB(int TimerId, void *pUserParam)
-{
-       MSG_BEGIN();
-
-       alarm_info_t *alarm_info = (alarm_info_t *)pUserParam;
-
-       g_bRepeat = false;
-
-       if (MsgSoundGetUnreadMsgCnt() <= 0) {
-               MSG_DEBUG("no unread msg");
-       } else {
-               MsgSoundPlayStart(false);
-       }
-
-       if (alarmmgr_free_alarm(alarm_info) != ALARMMGR_RESULT_SUCCESS)
-               MSG_DEBUG("alarmmgr_free_alarm is failed");
-
-       MSG_END();
-
-       return 0;
-}
-
-
-int MsgSoundGetUnreadMsgCnt()
-{
-       int unreadCnt = 0;
-
-       // Get SMS Count
-       unreadCnt = MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE);
-
-       // Get MMS Count
-       unreadCnt += MsgSettingGetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE);
-
-       MSG_DEBUG("unread count : [%d]", unreadCnt);
-
-       return unreadCnt;
-}
-
-void MsgSoundInitRepeatAlarm()
-{
-       MSG_BEGIN();
-
-       int nRepeatValue = 0;
-       long    nRepeatTime = 0;
-
-       g_bRepeat = false;
-
-       if (MsgSoundGetUnreadMsgCnt() <= 0) {
-               MSG_DEBUG("no unread msg");
-               return;
-       }
-
-       nRepeatValue = MsgSettingGetInt(MSG_ALERT_TONE);
-
-       switch (nRepeatValue)
-       {
-               case MSG_ALERT_TONE_ONCE:
-                       nRepeatTime = 0;
-               break;
-
-               case MSG_ALERT_TONE_2MINS:
-                       nRepeatTime = 2;
-               break;
-
-               case MSG_ALERT_TONE_5MINS:
-                       nRepeatTime = 5;
-               break;
-
-               case MSG_ALERT_TONE_10MINS:
-                       nRepeatTime = 10;
-               break;
-
-               default:
-                       MSG_DEBUG("Invalid Repetition time");
-               break;
-       }
-
-       MSG_DEBUG("nRepeatTime = %d", nRepeatTime);
-
-       if (nRepeatTime > 0)
-               MsgSoundPlayStart(false);
-
-       MSG_END();
-}
index 68734f9..bd631ad 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
+#include <map>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pthread.h>
 
 #include "MsgDebug.h"
 #include "MsgSqliteWrapper.h"
@@ -32,10 +37,8 @@ extern "C"
 /*==================================================================================================
                                      VARIABLES
 ==================================================================================================*/
-__thread sqlite3 *handle = NULL;
-__thread sqlite3_stmt *stmt = NULL;
-//__thread char **result = NULL;
-
+//__thread sqlite3 *handle = NULL;
+//__thread sqlite3_stmt *stmt = NULL;
 
 /*==================================================================================================
                                      IMPLEMENTATION OF MsgDbHandler - Member Functions
@@ -43,22 +46,26 @@ __thread sqlite3_stmt *stmt = NULL;
 MsgDbHandler::MsgDbHandler()
 {
        result = NULL;
+       handle = NULL;
+       stmt   = NULL;
+       mmapMx = NULL;
+       shm_fd = -1;
 }
 
 
 MsgDbHandler::~MsgDbHandler()
 {
-       if(result != NULL)
-               freeTable();
+       freeTable();
+       finalizeQuery();
+       if (disconnect() != MSG_SUCCESS)
+               MSG_DEBUG("DB disconnect is failed.");
 }
 
-
 msg_error_t MsgDbHandler::connect()
 {
        int ret = 0;
 
-       if (handle == NULL)
-       {
+       if (handle == NULL) {
                char strDBName[64];
 
                memset(strDBName, 0x00, sizeof(strDBName));
@@ -66,19 +73,14 @@ msg_error_t MsgDbHandler::connect()
 
                ret = db_util_open(strDBName, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
 
-               if (ret == SQLITE_OK)
-               {
+               if (ret == SQLITE_OK) {
                        MSG_DEBUG("DB Connect Success : [%p]", handle);
                        return MSG_SUCCESS;
-               }
-               else
-               {
+               } else {
                        MSG_DEBUG("DB Connect Fail [%d]", ret);
                        return MSG_ERR_DB_CONNECT;
                }
-       }
-       else
-       {
+       } else {
                MSG_DEBUG("DB Connect exist : [%p]", handle);
        }
 
@@ -90,18 +92,14 @@ msg_error_t MsgDbHandler::disconnect()
 {
        int ret = 0;
 
-       if (handle != NULL)
-       {
+       if (handle != NULL) {
                ret = db_util_close(handle);
 
-               if (ret == SQLITE_OK)
-               {
+               if (ret == SQLITE_OK) {
                        handle = NULL;
                        MSG_DEBUG("DB Disconnect Success");
                        return MSG_SUCCESS;
-               }
-               else
-               {
+               } else {
                        MSG_DEBUG("DB Disconnect Fail [%d]", ret);
                        return MSG_ERR_DB_DISCONNECT;
                }
@@ -120,8 +118,7 @@ bool MsgDbHandler::checkTableExist(const char *pTableName)
        memset(strQuery, 0x00, sizeof(strQuery));
        snprintf(strQuery, sizeof(strQuery), "select count(name) from sqlite_master where name='%s'", pTableName);
 
-       if (getTable(strQuery, &nRowCnt) != MSG_SUCCESS)
-       {
+       if (getTable(strQuery, &nRowCnt) != MSG_SUCCESS) {
                freeTable();
                return false;
        }
@@ -140,27 +137,27 @@ bool MsgDbHandler::checkTableExist(const char *pTableName)
 
 msg_error_t MsgDbHandler::execQuery(const char *pQuery)
 {
-       int ret = 0;
+//     int ret = 0;
 
-       if (!pQuery)
+       if (!pQuery)
                return MSG_ERR_INVALID_PARAMETER;
 
        if(connect() != MSG_SUCCESS)
                return MSG_ERR_DB_DISCONNECT;
 
-       ret = sqlite3_exec(handle, pQuery, 0, 0, NULL);
-
-       if (ret == SQLITE_OK)
-       {
-               MSG_DEBUG("Execute Query Success");
-               return MSG_SUCCESS;
+       if (prepareQuery(pQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to prepareQuery.");
+               return MSG_ERR_DB_EXEC;
        }
-       else
-       {
-               MSG_DEBUG("Execute Query Fail [%d]", ret);
+
+       if (stepQuery() == MSG_ERR_DB_STEP) {
+               MSG_DEBUG("Fail to stepQuery.");
+               finalizeQuery();
                return MSG_ERR_DB_EXEC;
        }
 
+       finalizeQuery();
+
        return MSG_SUCCESS;
 }
 
@@ -175,21 +172,21 @@ msg_error_t MsgDbHandler::getTable(const char *pQuery, int *pRowCnt)
                return MSG_ERR_DB_DISCONNECT;
 
        freeTable();
+       MSG_DEBUG("[%s]", pQuery);
        ret = sqlite3_get_table(handle, pQuery, &result, pRowCnt, 0, NULL);
 
-       if (ret == SQLITE_OK)
-       {
-               if (*pRowCnt == 0)    // when the no record return 'MSG_ERR_DB_NORECORD'
-               {
+       if (ret == SQLITE_OK) {
+               if (*pRowCnt == 0) {// when the no record return 'MSG_ERR_DB_NORECORD'
                        MSG_DEBUG("No Query Result");
                        return MSG_ERR_DB_NORECORD;
                }
 
                MSG_DEBUG("Get Table Success");
                return MSG_SUCCESS;
-       }
-       else
-       {
+       } else if (ret == SQLITE_BUSY) {
+               MSG_DEBUG("The database file is locked [%d]", ret);
+               return MSG_ERR_DB_BUSY;
+       } else {
                MSG_DEBUG("Get Table Fail [%d]", ret);
                return MSG_ERR_DB_GETTABLE;
        }
@@ -200,8 +197,7 @@ msg_error_t MsgDbHandler::getTable(const char *pQuery, int *pRowCnt)
 
 void MsgDbHandler::freeTable()
 {
-       if (result)
-       {
+       if (result) {
                sqlite3_free_table(result);
                result = NULL;
        }
@@ -219,6 +215,16 @@ msg_error_t MsgDbHandler::bindText(const char *pBindStr, int index)
 }
 
 
+msg_error_t MsgDbHandler::bindInt(const int pBindint, int index)
+{
+       int ret = 0;
+
+       ret = sqlite3_bind_int(stmt, index, pBindint);
+
+       return ret;
+}
+
+
 msg_error_t MsgDbHandler::bindBlob(const void * pBindBlob, int size, int index)
 {
        int ret = 0;
@@ -239,14 +245,12 @@ msg_error_t MsgDbHandler::prepareQuery(const char *pQuery)
                return MSG_ERR_DB_DISCONNECT;
 
 
-       if ((ret = sqlite3_prepare_v2(handle, pQuery, strlen(pQuery), &stmt, NULL)) == SQLITE_OK)
-       {
+       if ((ret = sqlite3_prepare_v2(handle, pQuery, strlen(pQuery), &stmt, NULL)) == SQLITE_OK) {
                MSG_DEBUG("Prepare Query Success");
                return MSG_SUCCESS;
-       }
-       else
-       {
-               MSG_DEBUG("Prepare Query Fail [%d]", ret);
+       } else {
+               MSG_ERR("Prepare Query Fail [%d]", ret);
+               finalizeQuery();
                return MSG_ERR_DB_PREPARE;
        }
 
@@ -260,19 +264,15 @@ msg_error_t MsgDbHandler::stepQuery()
 
        ret = sqlite3_step(stmt);
 
-       if (ret == SQLITE_ROW)
-       {
+       if (ret == SQLITE_ROW) {
                MSG_DEBUG("MsgStepQuery() SQLITE_ROW");
                return MSG_ERR_DB_ROW;
-       }
-       else if (ret == SQLITE_DONE)
-       {
+       } else if (ret == SQLITE_DONE) {
                MSG_DEBUG("MsgStepQuery() SQLITE_DONE");
                return MSG_ERR_DB_DONE;
-       }
-       else
-       {
-               MSG_DEBUG("MsgStepQuery() Fail [%d]", ret);
+       } else {
+               MSG_ERR("MsgStepQuery() Fail [%d]", ret);
+               finalizeQuery();
                return MSG_ERR_DB_STEP;
        }
 
@@ -280,6 +280,13 @@ msg_error_t MsgDbHandler::stepQuery()
 }
 
 
+void MsgDbHandler::resetQuery()
+{
+       if (stmt)
+               sqlite3_reset(stmt);
+}
+
+
 void MsgDbHandler::finalizeQuery()
 {
        if(stmt != NULL)
@@ -305,6 +312,69 @@ const void* MsgDbHandler::columnBlob(int ColumnIndex)
        return sqlite3_column_blob(stmt, ColumnIndex);
 }
 
+void MsgDbHandler::getMmapMutex(const char *shm_file_name)
+{
+       MSG_BEGIN();
+
+       if(!shm_file_name) {
+               MSG_FATAL ("NULL INPUT_PARAM");
+               return;
+       }
+
+       MSG_DEBUG("** mapping begin **");
+
+        /*  open shm_file_name at first. Otherwise, the num of files in /proc/pid/fd will be increasing  */
+       shm_fd = shm_open(shm_file_name, O_RDWR, 0);
+       if (shm_fd == -1) {
+               MSG_FATAL("shm_open error [%d]", errno);
+               return;
+       }
+
+       pthread_mutex_t *tmp = (pthread_mutex_t *)mmap(NULL, sizeof(pthread_mutex_t), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0);
+       if (tmp == MAP_FAILED) {
+               MSG_FATAL("mmap error [%d]", errno);
+               return;
+       }
+       mmapMx = tmp;
+}
+
+void MsgDbHandler::shm_mutex_timedlock (int sec)
+{
+       MSG_BEGIN();
+       if (!mmapMx) {
+               MSG_DEBUG("mmapMx not initd");
+               return;
+       }
+
+       struct timespec abs_time;
+       clock_gettime(CLOCK_REALTIME, &abs_time);
+       abs_time.tv_sec += sec;
+
+       int err = pthread_mutex_timedlock(mmapMx, &abs_time);
+
+       if (err == EOWNERDEAD) {
+               err = pthread_mutex_consistent(mmapMx);
+               MSG_DEBUG("Previous owner is dead with lock. Fix mutex");
+       }
+       else if (err != 0) {
+               MSG_FATAL("pthread_mutex_timedlock error [%d]", errno);
+               return;
+       }
+
+       MSG_END();
+}
+
+void MsgDbHandler::shm_mutex_unlock()
+{
+       MSG_BEGIN();
+       if(!mmapMx) {
+               MSG_DEBUG("mmapMx not initd");
+               return;
+       }
+
+       pthread_mutex_unlock(mmapMx);
+       MSG_END();
+}
 
 msg_error_t MsgDbHandler::beginTrans()
 {
@@ -313,16 +383,17 @@ msg_error_t MsgDbHandler::beginTrans()
        if(connect() != MSG_SUCCESS)
                return MSG_ERR_DB_DISCONNECT;
 
+       if (!mmapMx) {
+               getMmapMutex(SHM_FILE_FOR_DB_LOCK);
+       }
+       shm_mutex_timedlock(2);
 
-       ret = sqlite3_exec(handle, "BEGIN deferred;", 0, 0, NULL);
+       ret = sqlite3_exec(handle, "BEGIN DEFERRED TRANSACTION;", 0, 0, NULL);
 
-       if (ret == SQLITE_OK)
-       {
+       if (ret == SQLITE_OK) {
                MSG_DEBUG("Begin Transaction Success");
                return MSG_SUCCESS;
-       }
-       else
-       {
+       } else {
                MSG_DEBUG("Begin Transaction Fail [%d]", ret);
                return MSG_ERR_DB_EXEC;
        }
@@ -339,24 +410,20 @@ msg_error_t MsgDbHandler::endTrans(bool Success)
                return MSG_ERR_DB_DISCONNECT;
 
 
-       if (Success == true)
-       {
-               ret = sqlite3_exec(handle, "END;", 0, 0, NULL);
-       }
-       else
-       {
-               ret = sqlite3_exec(handle, "rollback", 0, 0, NULL);
-               ret = sqlite3_exec(handle, "END;", 0, 0, NULL);
+       if (Success) {
+               ret = sqlite3_exec(handle, "COMMIT TRANSACTION;", 0, 0, NULL);
+       } else {
+               ret = sqlite3_exec(handle, "ROLLBACK TRANSACTION;", 0, 0, NULL);
        }
 
-       if (ret == SQLITE_OK)
-       {
+       shm_mutex_unlock();
+
+       if (ret == SQLITE_OK) {
                MSG_DEBUG("End Transaction Success");
                return MSG_SUCCESS;
-       }
-       else
-       {
+       } else {
                MSG_DEBUG("End Transaction Fail [%d]", ret);
+               if (Success) endTrans(false);
                return MSG_ERR_DB_EXEC;
        }
 
@@ -370,8 +437,7 @@ int MsgDbHandler::getColumnToInt(int RowIndex)
 
        int nTemp = 0;
 
-       if (pTemp == NULL)
-       {
+       if (pTemp == NULL) {
                MSG_DEBUG("NULL");
                return nTemp;
        }
@@ -386,8 +452,7 @@ char MsgDbHandler::getColumnToChar(int RowIndex)
 {
        char* pTemp = result[RowIndex];
 
-       if (pTemp == NULL)
-       {
+       if (pTemp == NULL) {
                MSG_DEBUG("NULL");
                return '\0';
        }
@@ -396,12 +461,24 @@ char MsgDbHandler::getColumnToChar(int RowIndex)
 }
 
 
+char *MsgDbHandler::getColumnToString(int RowIndex)
+{
+       char* pTemp = result[RowIndex];
+
+       if (pTemp == NULL) {
+               MSG_DEBUG("NULL");
+               return NULL;
+       }
+
+       return pTemp;
+}
+
+
 void MsgDbHandler::getColumnToString(int RowIndex, int Length, char *pString)
 {
        char* pTemp = result[RowIndex];
 
-       if (pTemp == NULL)
-       {
+       if (pTemp == NULL) {
                MSG_DEBUG("NULL");
                return;
        }
@@ -418,24 +495,21 @@ msg_error_t MsgDbHandler::getRowId(const char *pTableName, unsigned int *pRowId)
        if (pTableName == NULL || pRowId == NULL)
                return MSG_ERR_INVALID_PARAMETER;
 
-       MSG_DEBUG("Table Name [%s]", pTableName);
+       MSG_SEC_DEBUG("Table Name [%s]", pTableName);
 
        memset(strQuery, 0x00, sizeof(strQuery));
        snprintf(strQuery, sizeof(strQuery), "select max(rowid) from %s", pTableName);
 
        ret = getTable(strQuery, &nRowCnt);
 
-       if (ret == SQLITE_OK)
-       {
+       if (ret == SQLITE_OK) {
                nRowId = getColumnToInt(1);
 
                if ((nRowCnt <= 1) && (nRowId == 0))
                        *pRowId = 1;
                else
                        *pRowId = nRowId + 1;
-       }
-       else
-       {
+       } else {
                MSG_DEBUG("MsgGetRowId failed");
                *pRowId = 0;
                freeTable();
@@ -450,9 +524,6 @@ msg_error_t MsgDbHandler::getRowId(const char *pTableName, unsigned int *pRowId)
 }
 
 
-/*==================================================================================================
-                                     FUNCTION IMPLEMENTATION
-==================================================================================================*/
 void MsgReleaseMemoryDB()
 {
        int freeSize = 0;
@@ -495,3 +566,43 @@ msg_error_t MsgConvertStrWithEscape(const char *input, char **output)
 
        return MSG_SUCCESS;
 }
+
+typedef std::map<pthread_t, MsgDbHandler*> dbMap_t;
+dbMap_t gDbHandles;
+pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
+
+MsgDbHandler *getDbHandle()
+{
+       pthread_t self = pthread_self();
+       MsgDbHandler *tmp = NULL;
+
+       pthread_mutex_lock(&mu);
+       dbMap_t::iterator it = gDbHandles.find(self);
+       if (it == gDbHandles.end()) {
+               MSG_DEBUG("New DB handle added.");
+               tmp = new MsgDbHandler();
+               gDbHandles.insert ( std::pair<pthread_t,MsgDbHandler*>(self,tmp));
+
+       } else {
+               tmp = it->second;
+       }
+       pthread_mutex_unlock(&mu);
+
+       return tmp;
+}
+
+void removeDbHandle()
+{
+       pthread_t self = pthread_self();
+       MsgDbHandler *tmp = NULL;
+
+       pthread_mutex_lock(&mu);
+       dbMap_t::iterator it = gDbHandles.find(self);
+       if (it != gDbHandles.end()) {
+               tmp = it->second;
+               delete tmp;
+               gDbHandles.erase (it);
+       }
+       pthread_mutex_unlock(&mu);
+}
+
index d45099a..7a8acfd 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <glib.h>
@@ -23,6 +23,7 @@
 /*==================================================================================================
                                      IMPLEMENTATION OF MsgConvertText - Member Functions
 ==================================================================================================*/
+MsgTextConvert* MsgTextConvert::pInstance = NULL;
 
 MsgTextConvert::MsgTextConvert()
 {
@@ -32,6 +33,7 @@ MsgTextConvert::MsgTextConvert()
        ucs2toTurkishList.clear();
        ucs2toSpanishList.clear();
        ucs2toPortuList.clear();
+       replaceCharList.clear();
 
        extCharList[0x000C] = MSG_CHAR_GSM7EXT;
        extCharList[0x005B] = MSG_CHAR_GSM7EXT;
@@ -42,7 +44,7 @@ MsgTextConvert::MsgTextConvert()
        extCharList[0x007C] = MSG_CHAR_GSM7EXT;
        extCharList[0x007D] = MSG_CHAR_GSM7EXT;
        extCharList[0x007E] = MSG_CHAR_GSM7EXT;
-       extCharList[0x20AC] = MSG_CHAR_GSM7EXT; // ï¿½ï¿½
+       extCharList[0x20AC] = MSG_CHAR_GSM7EXT;
 
        extCharList[0x00E7] = MSG_CHAR_TURKISH;
        extCharList[0x011E] = MSG_CHAR_TURKISH;
@@ -91,7 +93,7 @@ MsgTextConvert::MsgTextConvert()
        ucs2toGSM7ExtList[0x005E] = 0x14; // ^
        ucs2toGSM7ExtList[0x007C] = 0x40; // |
        ucs2toGSM7ExtList[0x007E] = 0x3D; // ~
-       ucs2toGSM7ExtList[0x20AC] = 0x65; // ï¿½ï¿½
+       ucs2toGSM7ExtList[0x20AC] = 0x65; // â‚¬
 
        // Turkish
        ucs2toTurkishList[0x005B] = 0x3C; // [
@@ -103,16 +105,16 @@ MsgTextConvert::MsgTextConvert()
        ucs2toTurkishList[0x005E] = 0x14; // ^
        ucs2toTurkishList[0x007C] = 0x40; // |
        ucs2toTurkishList[0x007E] = 0x3D; // ~
-       ucs2toTurkishList[0x20AC] = 0x65; // ï¿½ï¿½
-       ucs2toTurkishList[0x00E7] = 0x63; // c LATIN SMALL LETTER S WITH CEDILLA *
+       ucs2toTurkishList[0x20AC] = 0x65; // â‚¬
+       ucs2toTurkishList[0x00E7] = 0x63; // c LATIN SMALL LETTER S WITH CEDILLA
        ucs2toTurkishList[0x011E] = 0x47; // G LATIN CAPITAL LETTER G WITH BREVE
        ucs2toTurkishList[0x011F] = 0x67; // g LATIN SMALL LETTER G WITH BREVE
        ucs2toTurkishList[0x01E6] = 0x47; // G LATIN CAPITAL LETTER G WITH CARON
        ucs2toTurkishList[0x01E7] = 0x67; // g LATIN SMALL LETTER G WITH CARON
        ucs2toTurkishList[0x0130] = 0x49; // I LATIN CAPITAL LETTER I WITH DOT ABOVE
        ucs2toTurkishList[0x0131] = 0x69; // i LATIN SMALL LETTER DOTLESS
-       ucs2toTurkishList[0x015E] = 0x53; // S LATIN CAPITAL LETTER S WITH CEDILLA *
-       ucs2toTurkishList[0x015F] = 0x73; // s LATIN SMALL LETTER S WITH CEDILLA *
+       ucs2toTurkishList[0x015E] = 0x53; // S LATIN CAPITAL LETTER S WITH CEDILLA
+       ucs2toTurkishList[0x015F] = 0x73; // s LATIN SMALL LETTER S WITH CEDILLA
 
        // Spanish
        ucs2toSpanishList[0x005B] = 0x3C; // [
@@ -124,15 +126,15 @@ MsgTextConvert::MsgTextConvert()
        ucs2toSpanishList[0x005E] = 0x14; // ^
        ucs2toSpanishList[0x007C] = 0x40; // |
        ucs2toSpanishList[0x007E] = 0x3D; // ~
-       ucs2toSpanishList[0x20AC] = 0x65; // ï¿½ï¿½
-       ucs2toSpanishList[0x00C1] = 0x41; // A
-       ucs2toSpanishList[0x00E1] = 0x61; // a
-       ucs2toSpanishList[0x00CD] = 0x49; // I
-       ucs2toSpanishList[0x00ED] = 0x69; // i
-       ucs2toSpanishList[0x00D3] = 0x4F; // O
-       ucs2toSpanishList[0x00F3] = 0x6F; // o
-       ucs2toSpanishList[0x00DA] = 0x55; // U
-       ucs2toSpanishList[0x00FA] = 0x75; // u
+       ucs2toSpanishList[0x20AC] = 0x65; // â‚¬
+       ucs2toSpanishList[0x00C1] = 0x41; // A LATIN CAPITAL LETTER A WITH ACUTE
+       ucs2toSpanishList[0x00E1] = 0x61; // a LATIN SMALL LETTER A WITH ACUTE
+       ucs2toSpanishList[0x00CD] = 0x49; // I LATIN CAPITAL LETTER I WITH ACUTE
+       ucs2toSpanishList[0x00ED] = 0x69; // i LATIN SMALL LETTER I WITH ACUTE
+       ucs2toSpanishList[0x00D3] = 0x4F; // O LATIN CAPITAL LETTER O WITH ACUTE
+       ucs2toSpanishList[0x00F3] = 0x6F; // o LATIN SMALL LETTER O WITH ACUTE
+       ucs2toSpanishList[0x00DA] = 0x55; // U LATIN CAPITAL LETTER U WITH ACUTE
+       ucs2toSpanishList[0x00FA] = 0x75; // u LATIN SMALL LETTER U WITH ACUTE
 
        // Portuguese
        ucs2toPortuList[0x005B] = 0x3C; // [
@@ -144,34 +146,264 @@ MsgTextConvert::MsgTextConvert()
        ucs2toPortuList[0x005E] = 0x14; // ^
        ucs2toPortuList[0x007C] = 0x40; // |
        ucs2toPortuList[0x007E] = 0x3D; // ~
-       ucs2toPortuList[0x20AC] = 0x65; // ï¿½ï¿½
-       ucs2toPortuList[0x00D4] = 0x0B; // O
-       ucs2toPortuList[0x00F4] = 0x0C; // o
-       ucs2toPortuList[0x00C1] = 0x0E; // A
-       ucs2toPortuList[0x00E1] = 0x0F; // a
-       ucs2toPortuList[0x00CA] = 0x1F; // E
-       ucs2toPortuList[0x00EA] = 0x05; // e
-       ucs2toPortuList[0x00C0] = 0x41; // A
-       ucs2toPortuList[0x00E7] = 0x09; // c
-       ucs2toPortuList[0x00CD] = 0x49; // I
-       ucs2toPortuList[0x00ED] = 0x69; // i
-       ucs2toPortuList[0x00D3] = 0x4F; // O
-       ucs2toPortuList[0x00F3] = 0x6F; // o
-       ucs2toPortuList[0x00DA] = 0x55; // U
-       ucs2toPortuList[0x00FA] = 0x75; // u
-       ucs2toPortuList[0x00C3] = 0x61; // A
-       ucs2toPortuList[0x00E3] = 0x7B; // a
-       ucs2toPortuList[0x00D5] = 0x5C; // O
-       ucs2toPortuList[0x00F5] = 0x7C; // o
-       ucs2toPortuList[0x00C2] = 0x61; // A
-       ucs2toPortuList[0x00E2] = 0x7F; // a
-       ucs2toPortuList[0x03A6] = 0x12; // ï¿½ï¿½
-       ucs2toPortuList[0x0393] = 0x13; // ï¿½ï¿½
-       ucs2toPortuList[0x03A9] = 0x15; // ï¿½ï¿½
-       ucs2toPortuList[0x03A0] = 0x16; // ï¿½ï¿½
-       ucs2toPortuList[0x03A8] = 0x17; // ï¿½ï¿½
-       ucs2toPortuList[0x03A3] = 0x18; // ï¿½ï¿½
-       ucs2toPortuList[0x0398] = 0x19; // ï¿½ï¿½
+       ucs2toPortuList[0x20AC] = 0x65; // â‚¬
+       ucs2toPortuList[0x00D4] = 0x0B; // O LATIN CAPITAL LETTER O WITH CIRCUMFLEX
+       ucs2toPortuList[0x00F4] = 0x0C; // o LATIN SMALL LETTER O WITH CIRCUMFLEX
+       ucs2toPortuList[0x00C1] = 0x0E; // A LATIN CAPITAL LETTER A WITH ACUTE
+       ucs2toPortuList[0x00E1] = 0x0F; // a LATIN SMALL LETTER A WITH ACUTE
+       ucs2toPortuList[0x00CA] = 0x1F; // E LATIN CAPITAL LETTER E WITH CIRCUMFLEX
+       ucs2toPortuList[0x00EA] = 0x05; // e LATIN SMALL LETTER E WITH CIRCUMFLEX
+       ucs2toPortuList[0x00C0] = 0x41; // A LATIN CAPITAL LETTER A WITH GRAVE
+       ucs2toPortuList[0x00E7] = 0x09; // c LATIN SMALL LETTER C WITH CEDILLA
+       ucs2toPortuList[0x00CD] = 0x49; // I LATIN CAPITAL LETTER I WITH ACUTE
+       ucs2toPortuList[0x00ED] = 0x69; // i LATIN SMALL LETTER I WITH ACUTE
+       ucs2toPortuList[0x00D3] = 0x4F; // O LATIN CAPITAL LETTER O WITH ACUTE
+       ucs2toPortuList[0x00F3] = 0x6F; // o LATIN SMALL LETTER O WITH ACUTE
+       ucs2toPortuList[0x00DA] = 0x55; // U LATIN CAPITAL LETTER U WITH ACUTE
+       ucs2toPortuList[0x00FA] = 0x75; // u LATIN SMALL LETTER U WITH ACUTE
+       ucs2toPortuList[0x00C3] = 0x61; // A LATIN CAPITAL LETTER A WITH TILDE
+       ucs2toPortuList[0x00E3] = 0x7B; // a LATIN SMALL LETTER A WITH TILDE
+       ucs2toPortuList[0x00D5] = 0x5C; // O LATIN CAPITAL LETTER O WITH TILDE
+       ucs2toPortuList[0x00F5] = 0x7C; // o LATIN SMALL LETTER O WITH TILDE
+       ucs2toPortuList[0x00C2] = 0x61; // A LATIN CAPITAL LETTER A WITH CIRCUMFLEX
+       ucs2toPortuList[0x00E2] = 0x7F; // a LATIN SMALL LETTER A WITH CIRCUMFLEX
+       ucs2toPortuList[0x03A6] = 0x12; // Î¦ GREEK CAPITAL LETTER PHI
+       ucs2toPortuList[0x0393] = 0x13; // Î“ GREEK CAPITAL LETTER GAMMA
+       ucs2toPortuList[0x03A9] = 0x15; // Î© GREEK CAPITAL LETTER OMEGA
+       ucs2toPortuList[0x03A0] = 0x16; // Î  GREEK CAPITAL LETTER PI
+       ucs2toPortuList[0x03A8] = 0x17; // Î¨ GREEK CAPITAL LETTER PSI
+       ucs2toPortuList[0x03A3] = 0x18; // Î£ GREEK CAPITAL LETTER SIGMA
+       ucs2toPortuList[0x0398] = 0x19; // Î˜ GREEK CAPITAL LETTER THETA
+
+
+       // character replacement table
+       replaceCharList[0x00E0] = 0x61; // a LATIN SMALL LETTER A WITH GRAVE
+       replaceCharList[0x00E1] = 0x61; // a LATIN SMALL LETTER A WITH ACUTE
+       replaceCharList[0x00E2] = 0x61; // a LATIN SMALL LETTER A WITH CIRCUMFLEX
+       replaceCharList[0x00E3] = 0x61; // a LATIN SMALL LETTER A WITH TILDE
+       replaceCharList[0x00E4] = 0x61; // a LATIN SMALL LETTER A WITH DIAERESIS
+       replaceCharList[0x00E5] = 0x61; // a LATIN SMALL LETTER A WITH RING ABOVE
+       replaceCharList[0x00E6] = 0x61; // a LATIN SMALL LETTER AE
+       replaceCharList[0x0101] = 0x61; // a LATIN SMALL LETTER A WITH MACRON
+       replaceCharList[0x0103] = 0x61; // a LATIN SMALL LETTER A WITH BREVE
+       replaceCharList[0x0105] = 0x61; // a LATIN SMALL LETTER A WITH OGONEK
+       replaceCharList[0x01CE] = 0x61; // a LATIN SMALL LETTER A WITH CARON
+
+       replaceCharList[0x00C0] = 0x41; // A LATIN CAPITAL LETTER A WITH GRAVE
+       replaceCharList[0x00C1] = 0x41; // A LATIN CAPITAL LETTER A WITH ACUTE
+       replaceCharList[0x00C2] = 0x41; // A LATIN CAPITAL LETTER A WITH CIRCUMFLEX
+       replaceCharList[0x00C3] = 0x41; // A LATIN CAPITAL LETTER A WITH TILDE
+       replaceCharList[0x00C4] = 0x41; // A LATIN CAPITAL LETTER A WITH DIAERESIS
+       replaceCharList[0x00C5] = 0x41; // A LATIN CAPITAL LETTER A WITH RING ABOVE
+       replaceCharList[0x00C6] = 0x41; // A LATIN CAPITAL LETTER AE
+       replaceCharList[0x0100] = 0x41; // A LATIN CAPITAL LETTER A WITH MACRON
+       replaceCharList[0x0102] = 0x41; // A LATIN CAPITAL LETTER A WITH BREVE
+       replaceCharList[0x0104] = 0x41; // A LATIN CAPITAL LETTER A WITH OGONEK
+       replaceCharList[0x01CD] = 0x41; // A LATIN CAPITAL LETTER A WITH CARON
+
+       replaceCharList[0x00E7] = 0x63; // c LATIN SMALL LETTER C WITH CEDILLA
+       replaceCharList[0x0107] = 0x63; // c LATIN SMALL LETTER C WITH ACUTE
+       replaceCharList[0x0109] = 0x63; // c LATIN SMALL LETTER C WITH CIRCUMFLEX
+       replaceCharList[0x010B] = 0x63; // c LATIN SMALL LETTER C WITH DOT ABOVE
+       replaceCharList[0x010D] = 0x63; // c LATIN SMALL LETTER C WITH CARON
+
+       replaceCharList[0x00C7] = 0x43; // C LATIN CAPITAL LETTER C WITH CEDILLA
+       replaceCharList[0x0106] = 0x43; // C LATIN CAPITAL LETTER C WITH ACUTE
+       replaceCharList[0x0108] = 0x43; // C LATIN CAPITAL LETTER C WITH CIRCUMFLEX
+       replaceCharList[0x010A] = 0x43; // C LATIN CAPITAL LETTER C WITH DOT ABOVE
+       replaceCharList[0x010C] = 0x43; // C LATIN CAPITAL LETTER C WITH CARON
+
+       replaceCharList[0x010F] = 0x64; // d LATIN SMALL LETTER D WITH CARON
+       replaceCharList[0x0111] = 0x64; // d LATIN SMALL LETTER D WITH STROKE
+
+       replaceCharList[0x010E] = 0x44; // D LATIN CAPITAL LETTER D WITH CARON
+       replaceCharList[0x0110] = 0x44; // D LATIN CAPITAL LETTER D WITH STROKE
+
+       replaceCharList[0x00E8] = 0x65; // e LATIN SMALL LETTER E WITH GRAVE
+       replaceCharList[0x00E9] = 0x65; // e LATIN SMALL LETTER E WITH ACUTE
+       replaceCharList[0x00EA] = 0x65; // e LATIN SMALL LETTER E WITH CIRCUMFLEX
+       replaceCharList[0x00EB] = 0x65; // e LATIN SMALL LETTER E WITH DIAERESIS
+       replaceCharList[0x0113] = 0x65; // e LATIN SMALL LETTER E WITH MACRON
+       replaceCharList[0x0115] = 0x65; // e LATIN SMALL LETTER E WITH BREVE
+       replaceCharList[0x0117] = 0x65; // e LATIN SMALL LETTER E WITH DOT ABOVE
+       replaceCharList[0x0119] = 0x65; // e LATIN SMALL LETTER E WITH OGONEK
+       replaceCharList[0x011B] = 0x65; // e LATIN SMALL LETTER E WITH CARON
+       replaceCharList[0x0259] = 0x65; // e LATIN SMALL LETTER SCHWA
+
+       replaceCharList[0x00C8] = 0x45; // E LATIN CAPITAL LETTER E WITH GRAVE
+       replaceCharList[0x00C9] = 0x45; // E LATIN CAPITAL LETTER E WITH ACUTE
+       replaceCharList[0x00CA] = 0x45; // E LATIN CAPITAL LETTER E WITH CIRCUMFLEX
+       replaceCharList[0x00CB] = 0x45; // E LATIN CAPITAL LETTER E WITH DIAERESIS
+       replaceCharList[0x0112] = 0x45; // E LATIN CAPITAL LETTER E WITH MACRON
+       replaceCharList[0x0114] = 0x45; // E LATIN CAPITAL LETTER E WITH BREVE
+       replaceCharList[0x0116] = 0x45; // E LATIN CAPITAL LETTER E WITH DOT ABOVE
+       replaceCharList[0x0118] = 0x45; // E LATIN CAPITAL LETTER E WITH OGONEK
+       replaceCharList[0x011A] = 0x45; // E LATIN CAPITAL LETTER E WITH CARON
+       replaceCharList[0x018F] = 0x45; // E LATIN CAPITAL LETTER SCHWA
+
+       replaceCharList[0x011D] = 0x67; // g LATIN SMALL LETTER G WITH CIRCUMFLEX
+       replaceCharList[0x011F] = 0x67; // g LATIN SMALL LETTER G WITH BREVE
+       replaceCharList[0x0121] = 0x67; // g LATIN SMALL LETTER G WITH DOT ABOVE
+       replaceCharList[0x0123] = 0x67; // g LATIN SMALL LETTER G WITH CEDILLA
+       replaceCharList[0x01E7] = 0x67; // g LATIN SMALL LETTER G WITH CARON
+       replaceCharList[0x01F5] = 0x67; // g LATIN SMALL LETTER G WITH ACUTE
+       replaceCharList[0x1E21] = 0x67; // g LATIN SMALL LETTER G WITH MACRON
+
+       replaceCharList[0x011C] = 0x47; // G LATIN CAPITAL LETTER G WITH CIRCUMFLEX
+       replaceCharList[0x011E] = 0x47; // G LATIN CAPITAL LETTER G WITH BREVE
+       replaceCharList[0x0120] = 0x47; // G LATIN CAPITAL LETTER G WITH DOT ABOVE
+       replaceCharList[0x0122] = 0x47; // G LATIN CAPITAL LETTER G WITH CEDILLA
+       replaceCharList[0x01E6] = 0x47; // G LATIN CAPITAL LETTER G WITH CARON
+       replaceCharList[0x01F4] = 0x47; // G LATIN CAPITAL LETTER G WITH ACUTE
+       replaceCharList[0x1E20] = 0x47; // G LATIN CAPITAL LETTER G WITH MACRON
+
+       replaceCharList[0x00EC] = 0x69; // i LATIN SMALL LETTER I WITH GRAVE
+       replaceCharList[0x00ED] = 0x69; // i LATIN SMALL LETTER I WITH ACUTE
+       replaceCharList[0x00EE] = 0x69; // i LATIN SMALL LETTER I WITH CIRCUMFLEX
+       replaceCharList[0x00EF] = 0x69; // i LATIN SMALL LETTER I WITH DIAERESIS
+       replaceCharList[0x0129] = 0x69; // i LATIN SMALL LETTER I WITH TILDE
+       replaceCharList[0x012B] = 0x69; // i LATIN SMALL LETTER I WITH MACRON
+       replaceCharList[0x012D] = 0x69; // i LATIN SMALL LETTER I WITH BREVE
+       replaceCharList[0x012F] = 0x69; // i LATIN SMALL LETTER I WITH OGONEK
+       replaceCharList[0x01D0] = 0x69; // i LATIN SMALL LETTER I WITH CARON
+       replaceCharList[0x0131] = 0x69; // i LATIN SMALL LETTER DOTLESS I
+
+       replaceCharList[0x00CC] = 0x49; // I LATIN CAPITAL LETTER I WITH GRAVE
+       replaceCharList[0x00CD] = 0x49; // I LATIN CAPITAL LETTER I WITH ACUTE
+       replaceCharList[0x00CE] = 0x49; // I LATIN CAPITAL LETTER I WITH CIRCUMFLEX
+       replaceCharList[0x00CF] = 0x49; // I LATIN CAPITAL LETTER I WITH DIAERESIS
+       replaceCharList[0x0128] = 0x49; // I LATIN CAPITAL LETTER I WITH TILDE
+       replaceCharList[0x012A] = 0x49; // I LATIN CAPITAL LETTER I WITH MACRON
+       replaceCharList[0x012C] = 0x49; // I LATIN CAPITAL LETTER I WITH BREVE
+       replaceCharList[0x012E] = 0x49; // I LATIN CAPITAL LETTER I WITH OGONEK
+       replaceCharList[0x0130] = 0x49; // I LATIN CAPITAL LETTER I WITH DOT ABOVE
+
+       replaceCharList[0x0137] = 0x6B; // k LATIN SMALL LETTER K WITH CEDILLA
+
+       replaceCharList[0x0136] = 0x4B; // K LATIN CAPITAL LETTER K WITH CEDILLA
+
+       replaceCharList[0x013A] = 0x6C; // l LATIN SMALL LETTER L WITH ACUTE
+       replaceCharList[0x013C] = 0x6C; // l LATIN SMALL LETTER L WITH CEDILLA
+       replaceCharList[0x013E] = 0x6C; // l LATIN SMALL LETTER L WITH CARON
+       replaceCharList[0x0140] = 0x6C; // l LATIN SMALL LETTER L WITH MIDDLE DOT
+       replaceCharList[0x0142] = 0x6C; // l LATIN SMALL LETTER L WITH STROKE
+
+       replaceCharList[0x0139] = 0x4C; // L LATIN CAPITAL LETTER L WITH ACUTE
+       replaceCharList[0x013B] = 0x4C; // L LATIN CAPITAL LETTER L WITH CEDILLA
+       replaceCharList[0x013D] = 0x4C; // L LATIN CAPITAL LETTER L WITH CARON
+       replaceCharList[0x013F] = 0x4C; // L LATIN CAPITAL LETTER L WITH MIDDLE DOT
+       replaceCharList[0x0141] = 0x4C; // L LATIN CAPITAL LETTER L WITH STROKE
+
+       replaceCharList[0x00F1] = 0x6E; // n LATIN SMALL LETTER N WITH TILDE
+       replaceCharList[0x0144] = 0x6E; // n LATIN SMALL LETTER N WITH ACUTE
+       replaceCharList[0x0146] = 0x6E; // n LATIN SMALL LETTER N WITH CEDILLA
+       replaceCharList[0x0148] = 0x6E; // n LATIN SMALL LETTER N WITH CARON
+
+       replaceCharList[0x00D1] = 0x4E; // N LATIN CAPITAL LETTER N WITH TILDE
+       replaceCharList[0x0143] = 0x4E; // N LATIN CAPITAL LETTER N WITH ACUTE
+       replaceCharList[0x0145] = 0x4E; // N LATIN CAPITAL LETTER N WITH CEDILLA
+       replaceCharList[0x0147] = 0x4E; // N LATIN CAPITAL LETTER N WITH CARON
+
+       replaceCharList[0x00F2] = 0x6F; // o LATIN SMALL LETTER O WITH GRAVE
+       replaceCharList[0x00F3] = 0x6F; // o LATIN SMALL LETTER O WITH ACUTE
+       replaceCharList[0x00F4] = 0x6F; // o LATIN SMALL LETTER O WITH CIRCUMFLEX
+       replaceCharList[0x00F5] = 0x6F; // o LATIN SMALL LETTER O WITH TILDE
+       replaceCharList[0x00F6] = 0x6F; // o LATIN SMALL LETTER O WITH DIAERESIS
+       replaceCharList[0x00F8] = 0x6F; // o LATIN SMALL LETTER O WITH STROKE
+       replaceCharList[0x014D] = 0x6F; // o LATIN SMALL LETTER O WITH MACRON
+       replaceCharList[0x014F] = 0x6F; // o LATIN SMALL LETTER O WITH BREVE
+       replaceCharList[0x01D2] = 0x6F; // o LATIN SMALL LETTER O WITH CARON
+       replaceCharList[0x01EB] = 0x6F; // o LATIN SMALL LETTER O WITH OGONEK
+       replaceCharList[0x0151] = 0x6F; // o LATIN SMALL LETTER O WITH DOUBLE ACUTE
+       replaceCharList[0x0153] = 0x6F; // LATIN SMALL LIGATURE OE
+
+       replaceCharList[0x00D2] = 0x4F; // O LATIN CAPITAL LETTER O WITH GRAVE
+       replaceCharList[0x00D3] = 0x4F; // O LATIN CAPITAL LETTER O WITH ACUTE
+       replaceCharList[0x00D4] = 0x4F; // O LATIN CAPITAL LETTER O WITH CIRCUMFLEX
+       replaceCharList[0x00D5] = 0x4F; // O LATIN CAPITAL LETTER O WITH TILDE
+       replaceCharList[0x00D6] = 0x4F; // O LATIN CAPITAL LETTER O WITH DIAERESIS
+       replaceCharList[0x00D8] = 0x4F; // O LATIN CAPITAL LETTER O WITH STROKE
+       replaceCharList[0x014C] = 0x4F; // O LATIN CAPITAL LETTER O WITH MACRON
+       replaceCharList[0x014E] = 0x4F; // O LATIN CAPITAL LETTER O WITH BREVE
+       replaceCharList[0x01D1] = 0x4F; // O LATIN CAPITAL LETTER O WITH CARON
+       replaceCharList[0x01EA] = 0x4F; // O LATIN CAPITAL LETTER O WITH OGONEK
+       replaceCharList[0x0150] = 0x4F; // O LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
+       replaceCharList[0x0152] = 0x4F; // LATIN CAPITAL LIGATURE OE
+
+       replaceCharList[0x0155] = 0x72; // r LATIN SMALL LETTER R WITH ACUTE
+       replaceCharList[0x0157] = 0x72; // r LATIN SMALL LETTER R WITH CEDILLA
+       replaceCharList[0x0159] = 0x72; // r LATIN SMALL LETTER R WITH CARON
+
+       replaceCharList[0x0154] = 0x52; // R LATIN CAPITAL LETTER R WITH ACUTE
+       replaceCharList[0x0156] = 0x52; // R LATIN CAPITAL LETTER R WITH CEDILLA
+       replaceCharList[0x0158] = 0x52; // R LATIN CAPITAL LETTER R WITH CARON
+
+       replaceCharList[0x015B] = 0x73; // s LATIN SMALL LETTER S WITH ACUTE
+       replaceCharList[0x015D] = 0x73; // s LATIN SMALL LETTER S WITH CIRCUMFLEX
+       replaceCharList[0x015F] = 0x73; // s LATIN SMALL LETTER S WITH CEDILLA
+       replaceCharList[0x0161] = 0x73; // s LATIN SMALL LETTER S WITH CARON
+
+       replaceCharList[0x015A] = 0x53; // S LATIN CAPITAL LETTER S WITH ACUTE
+       replaceCharList[0x015C] = 0x53; // S LATIN CAPITAL LETTER S WITH CIRCUMFLEX
+       replaceCharList[0x015E] = 0x53; // S LATIN CAPITAL LETTER S WITH CEDILLA
+       replaceCharList[0x0160] = 0x53; // S LATIN CAPITAL LETTER S WITH CARON
+
+       replaceCharList[0x00FE] = 0x74; // t LATIN CAPITAL LETTER THORN
+       replaceCharList[0x0163] = 0x74; // t LATIN SMALL LETTER T WITH CEDILLA
+       replaceCharList[0x0165] = 0x74; // t LATIN SMALL LETTER T WITH CARON
+       replaceCharList[0x0167] = 0x74; // t LATIN SMALL LETTER T WITH STROKE
+       replaceCharList[0x021B] = 0x74; // t LATIN SMALL LETTER T WITH COMMA BELOW
+
+       replaceCharList[0x00DE] = 0x54; // T LATIN CAPITAL LETTER THORN
+       replaceCharList[0x0162] = 0x54; // T LATIN CAPITAL LETTER T WITH CEDILLA
+       replaceCharList[0x0164] = 0x54; // T LATIN CAPITAL LETTER T WITH CARON
+       replaceCharList[0x0166] = 0x54; // T LATIN CAPITAL LETTER T WITH STROKE
+
+       replaceCharList[0x00F9] = 0x75; // u LATIN SMALL LETTER U WITH GRAVE
+       replaceCharList[0x00FA] = 0x75; // u LATIN SMALL LETTER U WITH ACUTE
+       replaceCharList[0x00FB] = 0x75; // u LATIN SMALL LETTER U WITH CIRCUMFLEX
+       replaceCharList[0x00FC] = 0x75; // u LATIN SMALL LETTER U WITH DIAERESIS
+       replaceCharList[0x0169] = 0x75; // u LATIN SMALL LETTER U WITH TILDE
+       replaceCharList[0x016B] = 0x75; // u LATIN SMALL LETTER U WITH MACRON
+       replaceCharList[0x016D] = 0x75; // u LATIN SMALL LETTER U WITH BREVE
+       replaceCharList[0x016F] = 0x75; // u LATIN SMALL LETTER U WITH RING ABOVE
+       replaceCharList[0x0171] = 0x75; // u LATIN SMALL LETTER U WITH DOUBLE ACUTE
+       replaceCharList[0x0173] = 0x75; // u LATIN SMALL LETTER U WITH OGONEK
+       replaceCharList[0x01D4] = 0x75; // u LATIN SMALL LETTER U WITH CARON
+
+       replaceCharList[0x00D9] = 0x55; // U LATIN CAPITAL LETTER U WITH GRAVE
+       replaceCharList[0x00DA] = 0x55; // U LATIN CAPITAL LETTER U WITH ACUTE
+       replaceCharList[0x00DB] = 0x55; // U LATIN CAPITAL LETTER U WITH CIRCUMFLEX
+       replaceCharList[0x00DC] = 0x55; // U LATIN CAPITAL LETTER U WITH DIAERESIS
+       replaceCharList[0x0168] = 0x55; // U LATIN CAPITAL LETTER U WITH TILDE
+       replaceCharList[0x016A] = 0x55; // U LATIN CAPITAL LETTER U WITH MACRON
+       replaceCharList[0x016C] = 0x55; // U LATIN CAPITAL LETTER U WITH BREVE
+       replaceCharList[0x016E] = 0x55; // U LATIN CAPITAL LETTER U WITH RING ABOVE
+       replaceCharList[0x0170] = 0x55; // U LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
+       replaceCharList[0x0172] = 0x55; // U LATIN CAPITAL LETTER U WITH OGONEK
+       replaceCharList[0x01D3] = 0x55; // U LATIN CAPITAL LETTER U WITH CARON
+
+       replaceCharList[0x00FD] = 0x79; // y LATIN SMALL LETTER Y WITH ACUTE
+       replaceCharList[0x00FF] = 0x79; // y LATIN SMALL LETTER Y WITH DIAERESIS
+       replaceCharList[0x0177] = 0x79; // y LATIN SMALL LETTER Y WITH CIRCUMFLEX
+       replaceCharList[0x0233] = 0x79; // y LATIN SMALL LETTER Y WITH MACRON
+       replaceCharList[0x1EF3] = 0x79; // y LATIN SMALL LETTER Y WITH GRAVE
+       replaceCharList[0x1EF9] = 0x79; // y LATIN SMALL LETTER Y WITH TILDE
+
+       replaceCharList[0x00DD] = 0x59; // Y LATIN CAPITAL LETTER Y WITH ACUTE
+       replaceCharList[0x0176] = 0x59; // Y LATIN CAPITAL LETTER Y WITH CIRCUMFLEX
+       replaceCharList[0x0178] = 0x59; // Y LATIN CAPITAL LETTER Y WITH DIAERESIS
+       replaceCharList[0x0232] = 0x59; // Y LATIN CAPITAL LETTER Y WITH MACRON
+       replaceCharList[0x1EF2] = 0x59; // Y LATIN CAPITAL LETTER Y WITH GRAVE
+       replaceCharList[0x1EF8] = 0x59; // Y LATIN CAPITAL LETTER Y WITH TILDE
+
+       replaceCharList[0x017A] = 0x7A; // z LATIN SMALL LETTER Z WITH ACUTE
+       replaceCharList[0x017C] = 0x7A; // z LATIN SMALL LETTER Z WITH DOT ABOVE
+       replaceCharList[0x017E] = 0x7A; // z LATIN SMALL LETTER Z WITH CARON
+
+       replaceCharList[0x0179] = 0x5A; // Z LATIN CAPITAL LETTER Z WITH ACUTE
+       replaceCharList[0x017B] = 0x5A; // Z LATIN CAPITAL LETTER Z WITH DOT ABOVE
+       replaceCharList[0x017D] = 0x5A; // Z LATIN CAPITAL LETTER Z WITH CARON
 }
 
 
@@ -183,9 +415,20 @@ MsgTextConvert::~MsgTextConvert()
        ucs2toTurkishList.clear();
        ucs2toSpanishList.clear();
        ucs2toPortuList.clear();
+       replaceCharList.clear();
 }
 
 
+MsgTextConvert* MsgTextConvert::instance()
+{
+       if (!pInstance) {
+               MSG_DEBUG("pInstance is NULL. Now creating instance.");
+               pInstance = new MsgTextConvert();
+       }
+
+       return pInstance;
+}
+
 
 int MsgTextConvert::convertUTF8ToGSM7bit(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT bool *bIncludeAbnormalChar)
 {
@@ -193,13 +436,10 @@ int MsgTextConvert::convertUTF8ToGSM7bit(OUT unsigned char *pDestText, IN int ma
        int gsm7bitLength = 0;
        int ucs2Length = 0;
 
-       if (srcTextLen <= 0)
-       {
+       if (srcTextLen <= 0) {
                utf8Length = strlen((char*)pSrcText);
                srcTextLen = utf8Length;
-       }
-       else
-       {
+       } else {
                utf8Length = srcTextLen;
        }
 
@@ -226,7 +466,6 @@ return :
 */
 int MsgTextConvert::convertUTF8ToUCS2(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen)
 {
-       int i, j;
        int textLen;
        unsigned char *unicodeTemp = (unsigned char*)pDestText;
        int ucs2Length = 0;
@@ -238,42 +477,32 @@ int MsgTextConvert::convertUTF8ToUCS2(OUT unsigned char *pDestText, IN int maxLe
        const unsigned char * pTempDestText = pDestText;
 #endif
 
-       i = j = 0;
-
-       if(maxLength == 0 || pSrcText == NULL || pDestText ==  NULL)
-       {
+       if(maxLength == 0 || pSrcText == NULL || pDestText ==  NULL) {
                MSG_DEBUG("UTF8 to UCS2 Failed as text length is 0\n");
                return -1;
        }
 
        // null terminated string
-       if ( srcTextLen == -1 )
-       {
+       if ( srcTextLen == -1 ) {
                textLen = strlen((char*)pSrcText);
                srcTextLen = textLen;
-       }
-       else
-       {
+       } else {
                textLen = srcTextLen;
        }
 
        GIConv cd;
        int err=0;
 
-       cd = g_iconv_open("UCS-2BE", "UTF8");
+       cd = g_iconv_open("UTF16BE", "UTF8");
 
-       if (cd > 0)
-       {
+       if (cd > 0) {
                err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&unicodeTemp, (gsize*)&remainedBuffer);
        }
 
-       if(err < 0)
-       {
+       if(err < 0) {
                MSG_DEBUG("Error in g_iconv.");
                ucs2Length = -1;
-       }
-       else
-       {
+       } else {
                ucs2Length = maxLength - remainedBuffer;
        }
 
@@ -289,7 +518,7 @@ int MsgTextConvert::convertUTF8ToUCS2(OUT unsigned char *pDestText, IN int maxLe
 }
 
 
-int MsgTextConvert::convertUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, OUT msg_encode_type_t *pCharType)
+int MsgTextConvert::convertUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLength,  IN const unsigned char *pSrcText, IN int srcTextLen, OUT MSG_LANGUAGE_ID_T *pLangId, OUT msg_encode_type_t *pCharType)
 {
        int utf8Length = 0;
        int gsm7bitLength = 0;
@@ -309,28 +538,22 @@ int MsgTextConvert::convertUTF8ToAuto(OUT unsigned char *pDestText, IN int maxLe
 
        ucs2Length = convertUTF8ToUCS2((unsigned char*)pUCS2Text, maxUCS2Length * sizeof(WCHAR), pSrcText, srcTextLen);
 
-       if(ucs2Length < 0)
-       {
+       if(ucs2Length < 0) {
                *pCharType = MSG_ENCODE_8BIT;
 
                memcpy(pDestText, pSrcText, srcTextLen);
                return srcTextLen;
-       }
-       else
-       {
-               gsm7bitLength = convertUCS2ToGSM7bitAuto(pDestText, maxLength, (unsigned char*)pUCS2Text, ucs2Length, &bUnknown);
+       } else {
+               gsm7bitLength = convertUCS2ToGSM7bit(pDestText, maxLength, (unsigned char*)pUCS2Text, ucs2Length, pLangId, &bUnknown);
 
-               if (bUnknown == true)
-               {
+               if (bUnknown == true) {
                        *pCharType = MSG_ENCODE_UCS2;
 
                        if (ucs2Length > 0)
                                memcpy(pDestText, pUCS2Text, ucs2Length);
 
                        return ucs2Length;
-               }
-               else
-               {
+               } else {
                        *pCharType = MSG_ENCODE_GSM7BIT;
                }
 
@@ -383,8 +606,7 @@ int MsgTextConvert::convertUCS2ToUTF8(OUT unsigned char *pDestText, IN int maxLe
 #endif
        unsigned char * pTempDestText = pDestText;
 
-       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0)
-       {
+       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0) {
                MSG_DEBUG("UCS2 to UTF8 Failed as text length is 0\n");
                return false;
        }
@@ -392,13 +614,14 @@ int MsgTextConvert::convertUCS2ToUTF8(OUT unsigned char *pDestText, IN int maxLe
        GIConv cd;
        int err=0;
 
-       cd = g_iconv_open( "UTF8", "UCS-2BE" );
+       cd = g_iconv_open( "UTF8", "UTF16BE" );
 
-       if (cd > 0)
-       {
+       if (cd > 0) {
                err = g_iconv(cd, (char**)&pSrcText, (gsize*)&srcTextLen, (char**)&pDestText, (gsize*)&remainedBuffer);
        }
 
+       MSG_DEBUG("g_iconv() return value = %d", err);
+
        utf8Length = maxLength - remainedBuffer;
        pTempDestText[utf8Length] = 0x00;
 
@@ -425,8 +648,7 @@ int MsgTextConvert::convertEUCKRToUTF8(OUT unsigned char *pDestText, IN int maxL
 #endif
        unsigned char * pTempDestText = pDestText;
 
-       if(srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0)
-       {
+       if(srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0) {
                MSG_DEBUG("EUCKR to UTF8 Failed as text length is 0\n");
                return false;
        }
@@ -436,11 +658,12 @@ int MsgTextConvert::convertEUCKRToUTF8(OUT unsigned char *pDestText, IN int maxL
 
        cd = g_iconv_open( "UTF8", "EUCKR" );
 
-       if (cd > 0)
-       {
+       if (cd > 0) {
                err = g_iconv(cd, (char**)&pSrcText, (gsize*)&srcTextLen, (char**)&pDestText, (gsize*)&remainedBuffer);
        }
 
+       MSG_DEBUG("g_iconv() return value = %d", err);
+
        utf8Length = maxLength - remainedBuffer;
        pTempDestText[utf8Length] = 0x00;
 
@@ -456,6 +679,48 @@ int MsgTextConvert::convertEUCKRToUTF8(OUT unsigned char *pDestText, IN int maxL
 }
 
 
+int MsgTextConvert::convertSHIFTJISToUTF8(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN  int srcTextLen)
+{
+       int remainedBuffer = maxLength;
+       int utf8Length;
+
+#ifdef CONVERT_DUMP
+       int srcLen = srcTextLen;
+       const unsigned char * pTempSrcText = pSrcText;
+#endif
+       unsigned char * pTempDestText = pDestText;
+
+       if(srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0) {
+               MSG_DEBUG("EUCKR to UTF8 Failed as text length is 0\n");
+               return false;
+       }
+
+       GIConv cd;
+       int err=0;
+
+       cd = g_iconv_open( "UTF8", "SHIFT-JIS" );
+
+       if (cd > 0) {
+               err = g_iconv(cd, (char**)&pSrcText, (gsize*)&srcTextLen, (char**)&pDestText, (gsize*)&remainedBuffer);
+       }
+
+       MSG_DEBUG("g_iconv() return value = %d", err);
+
+       utf8Length = maxLength - remainedBuffer;
+       pTempDestText[utf8Length] = 0x00;
+
+#ifdef CONVERT_DUMP
+       MSG_DEBUG("\n########## Dump SHIFT-JIS -> UTF8\n");
+       convertDumpTextToHex((unsigned char*)pTempSrcText, srcLen);
+       convertDumpTextToHex((unsigned char*)pTempDestText, utf8Length);
+#endif
+
+       g_iconv_close(cd);
+
+       return utf8Length;
+}
+
+
 /**
 
 args:
@@ -473,14 +738,14 @@ int MsgTextConvert::convertUCS2ToGSM7bit(OUT unsigned char *pDestText, IN int ma
        int outTextLen = 0;
        unsigned char lowerByte, upperByte;
 
-       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0)
-       {
-               MSG_DEBUG("UCS2 to GSM7bit Failed as text length is 0\n");
+       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0) {
+               MSG_DEBUG("Invalid parameter.");
                return -1;
        }
 
        std::map<unsigned short, unsigned char>::iterator itChar;
        std::map<unsigned short, unsigned char>::iterator itExt;
+       std::map<unsigned short, unsigned char>::iterator itReplace;
 
        MSG_CHAR_TYPE_T currType = MSG_CHAR_DEFAULT;
        MSG_CHAR_TYPE_T newType = MSG_CHAR_DEFAULT;
@@ -497,22 +762,21 @@ int MsgTextConvert::convertUCS2ToGSM7bit(OUT unsigned char *pDestText, IN int ma
 
                inText = inText | lowerByte;
 
-//MSG_DEBUG("inText : [%04x]", inText);
-
                itExt = extCharList.find(inText);
 
-               if (itExt != extCharList.end())
-               {
+               if (itExt != extCharList.end()) {
                        newType = (MSG_CHAR_TYPE_T)itExt->second;
 
-                       if (newType >= currType)
-                       {
-                               currType = newType;
+                       if (newType >= currType) {
+                               if (inText == 0x00e7 && currType <= MSG_CHAR_TURKISH)
+                                       currType = MSG_CHAR_TURKISH;
+                               else
+                                       currType = newType;
                        }
                }
        }
 
-MSG_DEBUG("charType : [%d]", currType);
+       MSG_DEBUG("charType : [%d]", currType);
 
        for (int index = 0; index < srcTextLen; index++)
        {
@@ -522,202 +786,121 @@ MSG_DEBUG("charType : [%d]", currType);
                inText = (upperByte << 8) & 0xFF00;
                inText = inText | lowerByte;
 
-MSG_DEBUG("inText : [%04x]", inText);
-
                // Check Default Char
                itChar = ucs2toGSM7DefList.find(inText);
 
-               if (itChar != ucs2toGSM7DefList.end())
-               {
-MSG_DEBUG("default char");
+               if (itChar != ucs2toGSM7DefList.end()) {
                        pDestText[outTextLen++] = (unsigned char)itChar->second;
-               }
-               else
-               {
-                       if (currType == MSG_CHAR_GSM7EXT)
-                       {
+               } else {
+                       if (currType == MSG_CHAR_GSM7EXT) {
                                itExt = ucs2toGSM7ExtList.find(inText);
 
-                               if (itExt != ucs2toGSM7ExtList.end())
-                               {
+                               if (itExt != ucs2toGSM7ExtList.end()) {
                                        // prevent buffer overflow
-                                       if (maxLength <= outTextLen + 1)
-                                       {
-                                               MSG_DEBUG("Buffer Full");
+                                       if (maxLength <= outTextLen + 1) {
+                                               MSG_DEBUG("Buffer Full.");
                                                break;
                                        }
 
                                        pDestText[outTextLen++] = 0x1B;
                                        pDestText[outTextLen++] = (unsigned char)itExt->second;
-                               }
-                               else
-                               {
-                                       pDestText[outTextLen++] = 0x20;
+                               } else {
+                                       itReplace = replaceCharList.find(inText);
+                                       if (itReplace != replaceCharList.end()) {
+                                               pDestText[outTextLen++] = (unsigned char)itReplace->second;
+                                       } else {
+                                               pDestText[outTextLen++] = 0x3F;
+                                       }
                                        *bIncludeAbnormalChar = true;
+                                       MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
                                }
-                       }
-                       else if (currType == MSG_CHAR_TURKISH)
-                       {
+                       } else if (currType == MSG_CHAR_TURKISH) {
                                *pLangId = MSG_LANG_ID_TURKISH;
 
                                itExt = ucs2toTurkishList.find(inText);
 
-                               if (itExt != ucs2toTurkishList.end())
-                               {
+                               if (itExt != ucs2toTurkishList.end()) {
                                        // prevent buffer overflow
-                                       if (maxLength <= outTextLen + 1)
-                                       {
-                                               MSG_DEBUG("Buffer Full");
+                                       if (maxLength <= outTextLen + 1) {
+                                               MSG_DEBUG("Buffer Full.");
                                                break;
                                        }
 
                                        pDestText[outTextLen++] = 0x1B;
                                        pDestText[outTextLen++] = (unsigned char)itExt->second;
-                               }
-                               else
-                               {
-                                       pDestText[outTextLen++] = 0x20;
+                               } else {
+                                       itReplace = replaceCharList.find(inText);
+                                       if (itReplace != replaceCharList.end()) {
+                                               pDestText[outTextLen++] = (unsigned char)itReplace->second;
+                                       } else {
+                                               pDestText[outTextLen++] = 0x3F;
+                                       }
                                        *bIncludeAbnormalChar = true;
+                                       MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
                                }
-                       }
-                       else if (currType == MSG_CHAR_SPANISH)
-                       {
+                       } else if (currType == MSG_CHAR_SPANISH) {
                                *pLangId = MSG_LANG_ID_SPANISH;
 
                                itExt = ucs2toSpanishList.find(inText);
 
-                               if (itExt != ucs2toSpanishList.end())
-                               {
+                               if (itExt != ucs2toSpanishList.end()) {
                                        // prevent buffer overflow
-                                       if (maxLength <= outTextLen + 1)
-                                       {
-                                               MSG_DEBUG("Buffer Full");
+                                       if (maxLength <= outTextLen + 1) {
+                                               MSG_DEBUG("Buffer Full.");
                                                break;
                                        }
 
                                        pDestText[outTextLen++] = 0x1B;
                                        pDestText[outTextLen++] = (unsigned char)itExt->second;
-                               }
-                               else
-                               {
-                                       pDestText[outTextLen++] = 0x20;
+                               } else {
+                                       itReplace = replaceCharList.find(inText);
+                                       if (itReplace != replaceCharList.end()) {
+                                               pDestText[outTextLen++] = (unsigned char)itReplace->second;
+                                       } else {
+                                               pDestText[outTextLen++] = 0x3F;
+                                       }
                                        *bIncludeAbnormalChar = true;
+                                       MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
                                }
-                       }
-                       else if (currType == MSG_CHAR_PORTUGUESE)
-                       {
+                       } else if (currType == MSG_CHAR_PORTUGUESE) {
                                *pLangId = MSG_LANG_ID_PORTUGUESE;
 
                                itExt = ucs2toPortuList.find(inText);
 
-                               if (itExt != ucs2toPortuList.end())
-                               {
+                               if (itExt != ucs2toPortuList.end()) {
                                        // prevent buffer overflow
-                                       if (maxLength <= outTextLen + 1)
-                                       {
-                                               MSG_DEBUG("Buffer Full");
+                                       if (maxLength <= outTextLen + 1) {
+                                               MSG_DEBUG("Buffer Full.");
                                                break;
                                        }
 
-MSG_DEBUG("ucs2toPortuList : [%02x]", (unsigned char)itExt->second);
-
                                        pDestText[outTextLen++] = 0x1B;
                                        pDestText[outTextLen++] = (unsigned char)itExt->second;
-                               }
-                               else
-                               {
-MSG_DEBUG("no char");
-                                       pDestText[outTextLen++] = 0x20;
+                               } else {
+                                       itReplace = replaceCharList.find(inText);
+                                       if (itReplace != replaceCharList.end()) {
+                                               pDestText[outTextLen++] = (unsigned char)itReplace->second;
+                                       } else {
+                                               pDestText[outTextLen++] = 0x3F;
+                                       }
                                        *bIncludeAbnormalChar = true;
+                                       MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
                                }
-                       }
-                       else
-                       {
-                               pDestText[outTextLen++] = 0x20;
-                               *bIncludeAbnormalChar = true;
-                       }
-               }
-
-               // prevent buffer overflow
-               if (maxLength <= outTextLen)
-               {
-                       MSG_DEBUG("Buffer full\n");
-                       break;
-               }
-       }
-
-#ifdef CONVERT_DUMP
-       MSG_DEBUG("\n########## Dump UCS2 -> GSM7bit\n");
-       convertDumpTextToHex((unsigned char*)pSrcText, srcTextLen);
-       convertDumpTextToHex((unsigned char*)pDestText, outTextLen);
-#endif
-
-       return outTextLen;
-}
-
-
-int MsgTextConvert::convertUCS2ToGSM7bitAuto(OUT unsigned char *pDestText, IN int maxLength, IN const unsigned char *pSrcText, IN int srcTextLen, OUT bool *pUnknown)
-{
-       // for UNICODE
-       int outTextLen = 0;
-       unsigned char lowerByte, upperByte;
-
-       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0)
-       {
-               MSG_DEBUG("UCS2 to GSM7bit Failed as text length is 0\n");
-               return -1;
-       }
-
-       std::map<unsigned short, unsigned char>::iterator itChar;
-       std::map<unsigned short, unsigned char>::iterator itExt;
-
-       unsigned short inText;
-
-       for (int index = 0; index < srcTextLen; index++)
-       {
-               upperByte = pSrcText[index++];
-               lowerByte = pSrcText[index];
-
-               inText = (upperByte << 8) & 0xFF00;
-               inText = inText | lowerByte;
-
-//MSG_DEBUG("inText : [%04x]", inText);
-
-               // Check Default Char
-               itChar = ucs2toGSM7DefList.find(inText);
-
-               if (itChar != ucs2toGSM7DefList.end())
-               {
-//MSG_DEBUG("default char");
-                       pDestText[outTextLen++] = (unsigned char)itChar->second;
-               }
-               else
-               {
-                       itExt = ucs2toGSM7ExtList.find(inText);
-
-                       if (itExt != ucs2toGSM7ExtList.end())
-                       {
-                               // prevent buffer overflow
-                               if (maxLength <= outTextLen + 1)
-                               {
-                                       MSG_DEBUG("Buffer Full");
-                                       break;
+                       } else {
+                               itReplace = replaceCharList.find(inText);
+                               if (itReplace != replaceCharList.end()) {
+                                       pDestText[outTextLen++] = (unsigned char)itReplace->second;
+                               } else {
+                                       pDestText[outTextLen++] = 0x3F;
                                }
-
-                               pDestText[outTextLen++] = 0x1B;
-                               pDestText[outTextLen++] = (unsigned char)itExt->second;
-                       }
-                       else
-                       {
-                               *pUnknown = true;
-                               return 0;
+                               *bIncludeAbnormalChar = true;
+                               MSG_DEBUG("Abnormal character is included. inText : [%04x]", inText);
                        }
                }
 
                // prevent buffer overflow
-               if (maxLength <= outTextLen)
-               {
-                       MSG_DEBUG("Buffer full\n");
+               if (maxLength <= outTextLen) {
+                       MSG_DEBUG("Buffer full.");
                        break;
                }
        }
@@ -747,159 +930,111 @@ int MsgTextConvert::convertGSM7bitToUCS2(OUT unsigned char *pDestText, IN int ma
        int outTextLen = 0;
        unsigned char lowerByte = 0, upperByte = 0;
 
-       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0)
-       {
-               MSG_DEBUG("UCS2 to GSM7bit Failed as text length is 0\n");
+       if (srcTextLen == 0 || pSrcText == NULL || pDestText ==  NULL || maxLength == 0) {
+               MSG_ERR("UCS2 to GSM7bit Failed as text length is 0\n");
                return -1;
        }
 
        for (int i = 0; i<srcTextLen; i++)
        {
-               if (maxLength == 0)
-               {
+               if (maxLength == 0) {
                        break;
                }
 
-               if (pSrcText[i] >= 0x80)
-               {
+               if (pSrcText[i] >= 0x80) {
                        //error
-                       MSG_DEBUG(">>>>>>>a_pTextString[i]=%x, The alpha isn't the gsm 7bit code, Never Come here!!!\n", pSrcText[i]);
+                       MSG_ERR(">>>>>>>a_pTextString[i]=%x, The alpha isn't the gsm 7bit code, Never Come here!!!\n", pSrcText[i]);
                        return -1;
                }
 
-               if (pLangInfo->bLockingShift == true) // National Language Locking Shift
-               {
+               if (pLangInfo->bLockingShift == true) { // National Language Locking Shift
                        MSG_DEBUG("Locking Shift [%d]", pLangInfo->lockingLang);
 
-                       if (pLangInfo->lockingLang == MSG_LANG_ID_TURKISH)
-                       {
+                       if (pLangInfo->lockingLang == MSG_LANG_ID_TURKISH) {
                                // Check Escape
-                               if (g_TurkishLockingToUCS2[pSrcText[i]] == 0x001B)
-                               {
+                               if (g_TurkishLockingToUCS2[pSrcText[i]] == 0x001B) {
                                        i++;
 
-                                       if (pLangInfo->bSingleShift == true) // National Language Single Shift
-                                       {
+                                       if (pLangInfo->bSingleShift == true) { // National Language Single Shift
                                                MSG_DEBUG("Single Shift [%d]", pLangInfo->singleLang);
 
-                                               if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH)
-                                               {
+                                               if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH) {
                                                        lowerByte = g_TurkishSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_TurkishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                               }
-                                               else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH)
-                                               {
+                                               } else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH) {
                                                        lowerByte = g_SpanishSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_SpanishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                               }
-                                               else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE)
-                                               {
+                                               } else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE) {
                                                        lowerByte = g_PortuSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_PortuSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                               }
-                                               else
-                                               {
+                                               } else {
                                                        lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                                }
-                                       }
-                                       else // GSM 7 bit Default Alphabet Extension Table
-                                       {
+                                       } else { // GSM 7 bit Default Alphabet Extension Table
                                                lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
                                                upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                        }
-                               }
-                               else // TURKISH - National Language Locking Shift
-                               {
+                               } else { // TURKISH - National Language Locking Shift
                                        lowerByte = g_TurkishLockingToUCS2[pSrcText[i]] & 0x00FF;
                                        upperByte = (g_TurkishLockingToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                }
-                       }
-                       else if (pLangInfo->lockingLang == MSG_LANG_ID_PORTUGUESE)
-                       {
+                       } else if (pLangInfo->lockingLang == MSG_LANG_ID_PORTUGUESE) {
                                // Check Escape
-                               if (g_PortuLockingToUCS2[pSrcText[i]] == 0x001B)
-                               {
+                               if (g_PortuLockingToUCS2[pSrcText[i]] == 0x001B) {
                                        i++;
 
-                                       if (pLangInfo->bSingleShift == true) // National Language Single Shift
-                                       {
+                                       if (pLangInfo->bSingleShift == true) { // National Language Single Shift
                                                MSG_DEBUG("Single Shift [%d]", pLangInfo->singleLang);
 
-                                               if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH)
-                                               {
+                                               if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH) {
                                                        lowerByte = g_TurkishSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_TurkishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                               }
-                                               else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH)
-                                               {
+                                               } else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH) {
                                                        lowerByte = g_SpanishSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_SpanishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                               }
-                                               else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE)
-                                               {
+                                               } else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE) {
                                                        lowerByte = g_PortuSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_PortuSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                               }
-                                               else
-                                               {
+                                               } else {
                                                        lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
                                                        upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                                }
-                                       }
-                                       else // GSM 7 bit Default Alphabet Extension Table
-                                       {
+                                       } else { // GSM 7 bit Default Alphabet Extension Table
                                                lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
                                                upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                        }
-                               }
-                               else // PORTUGUESE - National Language Locking Shift
-                               {
+                               } else { // PORTUGUESE - National Language Locking Shift
                                        lowerByte = g_PortuLockingToUCS2[pSrcText[i]] & 0x00FF;
                                        upperByte = (g_PortuLockingToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                }
                        }
-               }
-               else
-               {
+               } else {
                        // Check Escape
-                       if (g_GSM7BitToUCS2[pSrcText[i]] == 0x001B)
-                       {
+                       if (g_GSM7BitToUCS2[pSrcText[i]] == 0x001B) {
                                i++;
 
-                               if (pLangInfo->bSingleShift == true) // National Language Single Shift
-                               {
+                               if (pLangInfo->bSingleShift == true) { // National Language Single Shift
                                        MSG_DEBUG("Single Shift [%d]", pLangInfo->singleLang);
 
-                                       if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH)
-                                       {
+                                       if (pLangInfo->singleLang == MSG_LANG_ID_TURKISH) {
                                                lowerByte = g_TurkishSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                upperByte = (g_TurkishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                       }
-                                       else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH)
-                                       {
+                                       } else if (pLangInfo->singleLang == MSG_LANG_ID_SPANISH) {
                                                lowerByte = g_SpanishSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                upperByte = (g_SpanishSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                       }
-                                       else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE)
-                                       {
+                                       } else if (pLangInfo->singleLang == MSG_LANG_ID_PORTUGUESE) {
                                                lowerByte = g_PortuSingleToUCS2[pSrcText[i]] & 0x00FF;
                                                upperByte = (g_PortuSingleToUCS2[pSrcText[i]] & 0xFF00) >> 8;
-                                       }
-                                       else
-                                       {
+                                       } else {
                                                lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
                                                upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                        }
-                               }
-                               else // GSM 7 bit Default Alphabet Extension Table
-                               {
+                               } else { // GSM 7 bit Default Alphabet Extension Table
                                        lowerByte = g_GSM7BitExtToUCS2[pSrcText[i]] & 0x00FF;
                                        upperByte = (g_GSM7BitExtToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                                }
-                       }
-                       else
-                       {
+                       } else {
                                lowerByte = g_GSM7BitToUCS2[pSrcText[i]] & 0x00FF;
                                upperByte = (g_GSM7BitToUCS2[pSrcText[i]] & 0xFF00) >> 8;
                        }
@@ -922,18 +1057,14 @@ int MsgTextConvert::convertGSM7bitToUCS2(OUT unsigned char *pDestText, IN int ma
 
 void MsgTextConvert::convertDumpTextToHex(const unsigned char *pText, int length)
 {
-       printf("\n=======================================\n");
-       printf("   Dump Text To Hex - Length :%d\n", length);
-       printf("=======================================");
+       MSG_DEBUG("=======================================");
+       MSG_DEBUG("   Dump Text To Hex - Length :%d\n", length);
+       MSG_DEBUG("=======================================");
 
        for (int i = 0; i < length; i++ )
        {
-               if ( i % MAX_DUMP_COLUMN == 0 )
-               {
-                       printf("\n\t");
-               }
-               printf("%02x ", pText[i]);
+               MSG_DEBUG("[%02x]", pText[i]);
        }
 
-       printf("\n=======================================\n\n");
+       MSG_DEBUG("=======================================");
 }
index f1b7901..53d529c 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include <stdio.h>
@@ -23,6 +23,8 @@
 #include <string.h>
 #include <dirent.h>
 #include <unistd.h>    //sync()
+#include <fcntl.h>
+#include <libgen.h>
 
 #include "MsgStorageTypes.h"
 #include "MsgDebug.h"
@@ -44,7 +46,7 @@ FILE *MsgOpenFile(const char *filepath, const char *opt)
                return NULL;
        }
 
-       MSG_DEBUG("[FILE] filepath : [%s], opt [%s]", filepath, opt);
+       MSG_SEC_DEBUG("[FILE] filepath : [%s], opt [%s]", filepath, opt);
 
        FILE *pFile = NULL;
 
@@ -221,14 +223,18 @@ bool MsgCreateFileName(char *pFileName)
 
 bool MsgOpenAndReadFile(const char *pFileName, char **ppData, int *pDataSize)
 {
+       if (!pFileName || !ppData || !pDataSize) {
+               MSG_ERR("Invalid params!! pFileName=%x, ppData=%x, pDataSize=%x", pFileName, ppData, pDataSize);
+               return false;
+       }
        MSG_DEBUG("MsgOpenAndReadFile");
 
        FILE *pFile = NULL;
 
        char fullPath[MAX_FULL_PATH_SIZE] = {0};
 
-       snprintf(fullPath, MAX_FULL_PATH_SIZE, MSG_IPC_DATA_PATH"%s", pFileName);
-       MSG_DEBUG("open file name: %s", fullPath);
+       snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
+       MSG_SEC_DEBUG("open file name: %s", fullPath);
 
 
        pFile = MsgOpenFile(fullPath, "rb");
@@ -302,7 +308,7 @@ bool MsgWriteIpcFile(const char *pFileName, const char *pData, int DataSize)
 
        char fullPath[MAX_FULL_PATH_SIZE] = {0};
 
-       snprintf(fullPath, MAX_FULL_PATH_SIZE, MSG_IPC_DATA_PATH"%s", pFileName);
+       snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
 
        FILE *pFile = MsgOpenFile(fullPath, "wb+");
 
@@ -326,11 +332,11 @@ bool MsgWriteIpcFile(const char *pFileName, const char *pData, int DataSize)
        MsgFflush(pFile);
        MsgCloseFile(pFile);
 
-       if (chmod(fullPath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ) != 0) {
+       if (MsgChmod(fullPath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ) == false) {
                MSG_DEBUG("File chmod Error: %s", strerror(errno));
        }
 
-       if (chown(fullPath, 0, 6502 ) != 0) {
+       if (MsgChown(fullPath, 0, 6502 ) == false) {
                MSG_DEBUG("File chown Error: %s", strerror(errno));
        }
 
@@ -347,9 +353,9 @@ int MsgReadSmilFile(const char *pFileName, char **ppData)
        int     nSize = 0;
        char fullPath[MAX_FULL_PATH_SIZE] = {0};
 
-       snprintf(fullPath, MAX_FULL_PATH_SIZE, MSG_SMIL_FILE_PATH"%s", pFileName);
+       snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_SMIL_FILE_PATH, pFileName);
 
-       MSG_DEBUG("open file name: %s", fullPath);
+       MSG_SEC_DEBUG("open file name: %s", fullPath);
 
        FILE *pFile = MsgOpenFile(fullPath, "rb");
 
@@ -373,6 +379,7 @@ int MsgReadSmilFile(const char *pFileName, char **ppData)
        }
 
        *ppData = new char[FileSize + 1];
+       memset(*ppData, 0x00, (FileSize+1));
 
        if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
                MsgCloseFile(pFile);
@@ -386,10 +393,9 @@ int MsgReadSmilFile(const char *pFileName, char **ppData)
                return -1;
        }
 
-       ppData[FileSize] = '\0';
+       //ppData[FileSize] = '\0';
 
        nSize = FileSize;
-
        MsgCloseFile(pFile);
 
        return nSize;
@@ -405,9 +411,9 @@ bool MsgWriteSmilFile(const char *pFilePath,char *pData, int DataSize)
 
        if (mkdir(MSG_SMIL_FILE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
                if (errno == EEXIST) {
-                       MSG_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
+                       MSG_SEC_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
                } else {
-                       MSG_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
+                       MSG_SEC_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
                }
        }
 
@@ -452,7 +458,7 @@ void MsgDeleteFile(const char *pFileName)
        char fullPath[MAX_FULL_PATH_SIZE] = {0};
 
        try {
-               snprintf(fullPath, MAX_FULL_PATH_SIZE, MSG_IPC_DATA_PATH"%s", pFileName);
+               snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_IPC_DATA_PATH, pFileName);
 
                MSG_DEBUG("%s", fullPath);
 
@@ -475,7 +481,7 @@ void MsgDeleteSmilFile(const char *pFileName)
        try {
                char fullPath[MAX_FULL_PATH_SIZE] = {0};
 
-               snprintf(fullPath, MAX_FULL_PATH_SIZE, MSG_SMIL_FILE_PATH"%s", pFileName);
+               snprintf(fullPath, MAX_FULL_PATH_SIZE, "%s%s", MSG_SMIL_FILE_PATH, pFileName);
 
                if (remove(fullPath) != 0)
                        MSG_FATAL("File Delete Error [%s]: %s", fullPath, strerror(errno));
@@ -619,7 +625,7 @@ bool MsgOpenCreateAndOverwriteFile(char *pFullPath, char *pBuff, int TotalLength
        MsgFflush(pFile);
        MsgCloseFile(pFile);
 
-       if (chmod(pFullPath, file_mode) < 0)
+       if (!MsgChmod(pFullPath, file_mode))
                MSG_FATAL("File chmod Error: %s", strerror(errno));
 
        return true;
@@ -654,11 +660,11 @@ char *MsgOpenAndReadMmsFile( const char *szFilePath, int offset, int size, int *
        } else {
                readSize = size;
        }
-
-       if (readSize > FM_READ_WRITE_BUFFER_MAX) {
-               MSG_DEBUG("MsgOpenAndReadMmsFile: File size tried to read too big");
-               goto __CATCH;
-       }
+// restore Kies backup data size greater than FM_READ_WRITE_BUFFER_MAX
+//     if (readSize > FM_READ_WRITE_BUFFER_MAX) {
+//             MSG_DEBUG("MsgOpenAndReadMmsFile: File size tried to read too big");
+//             goto __CATCH;
+//     }
 
        pData = (char *)malloc(readSize + 1);
        if ( NULL == pData ) {
@@ -901,7 +907,7 @@ void MsgMmsInitDir()
 
                        if(strstr(d->d_name, ".dir") != NULL) {
                                char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
-                               snprintf(filePath, MSG_FILEPATH_LEN_MAX, MSG_DATA_PATH"%s", d->d_name);
+                               snprintf(filePath, MSG_FILEPATH_LEN_MAX, "%s%s", MSG_DATA_PATH, d->d_name);
 
                                MsgRmRf(filePath);
                                rmdir(filePath);
@@ -921,7 +927,7 @@ bool MsgAccessFile(const char *filepath, int mode)
                return false;
        }
 
-       MSG_DEBUG("request access path = %s, mode = %d", filepath, mode);
+       MSG_SEC_DEBUG("request access path = %s, mode = %d", filepath, mode);
 
        ret = access(filepath, mode);
 
@@ -933,3 +939,141 @@ bool MsgAccessFile(const char *filepath, int mode)
 
        return true;
 }
+
+
+bool MsgChmod(const char *filepath, int mode)
+{
+       struct stat lstat_info;
+       struct stat fstat_info;
+       int fd;
+
+       if (lstat(filepath, &lstat_info) == -1) {
+               MSG_SEC_DEBUG("No such file as [%s].", filepath);
+               return false;
+       }
+
+       fd = open(filepath, O_RDONLY);
+
+       if (fd == -1) {
+               MSG_SEC_DEBUG("Fail to open [%s].", filepath);
+               return false;
+       }
+
+       if (fstat(fd, &fstat_info) == -1) {
+               MSG_SEC_DEBUG("Fail to fstat [%s].", filepath);
+               close(fd);
+               return false;
+       }
+
+       if (lstat_info.st_mode == fstat_info.st_mode &&
+                       lstat_info.st_ino == fstat_info.st_ino  &&
+                       lstat_info.st_dev == fstat_info.st_dev) {
+               if (fchmod(fd, mode) < 0) {
+                       MSG_SEC_DEBUG("Fail to fchmod [%s].", filepath);
+                       close(fd);
+                       return false;
+               }
+       }
+
+       close(fd);
+       return true;
+}
+
+
+bool MsgChown(const char *filepath, int uid, int gid)
+{
+       struct stat lstat_info;
+       struct stat fstat_info;
+       int fd;
+
+       if (lstat(filepath, &lstat_info) == -1) {
+               MSG_SEC_DEBUG("No such file as [%s].", filepath);
+               return false;
+       }
+
+       fd = open(filepath, O_RDONLY);
+
+       if (fd == -1) {
+               MSG_SEC_DEBUG("Fail to open [%s].", filepath);
+               return false;
+       }
+
+       if (fstat(fd, &fstat_info) == -1) {
+               MSG_SEC_DEBUG("Fail to fstat [%s].", filepath);
+               close(fd);
+               return false;
+       }
+
+       if (lstat_info.st_mode == fstat_info.st_mode &&
+                       lstat_info.st_ino == fstat_info.st_ino  &&
+                       lstat_info.st_dev == fstat_info.st_dev) {
+               if (fchown(fd, uid, gid) < 0) {
+                       MSG_SEC_DEBUG("Fail to fchown [%s].", filepath);
+                       close(fd);
+                       return false;
+               }
+       }
+
+       close(fd);
+       return true;
+}
+
+bool MsgCreateFile(const char *pFilePath,char *pData, int DataSize)
+{
+       if(!pFilePath) {
+               MSG_DEBUG("pFilePath is NULL");
+               return false;
+       }
+
+       FILE *pFile = MsgOpenFile(pFilePath, "wb+");
+
+       if (pFile == NULL) {
+               MSG_DEBUG("File Open Error: %s", strerror(errno));
+               return false;
+       }
+
+       if (MsgFseek(pFile, 0L, SEEK_SET) < 0) {
+               MsgCloseFile(pFile);
+               MSG_DEBUG("File Seek Error: %s", strerror(errno));
+               return false;
+       }
+
+       if (MsgWriteFile(pData, sizeof(char), DataSize, pFile) != (size_t)DataSize) {
+               MsgCloseFile(pFile);
+               MSG_DEBUG("File Write Error: %s", strerror(errno));
+               return false;
+       }
+
+       MsgFflush(pFile);
+       MsgFsync( pFile);
+       MsgCloseFile(pFile);
+
+       return true;
+}
+
+char *MsgGetDirName(char *file_path)
+{
+       char *tmp_path = NULL;
+       tmp_path = g_strdup(file_path);
+
+       char *ret_name = g_strdup(dirname(tmp_path));
+
+       g_free(tmp_path);
+       tmp_path = NULL;
+
+       return ret_name;
+}
+
+
+char *MsgGetFileName(char *file_path)
+{
+       char *tmp_path = NULL;
+       tmp_path = g_strdup(file_path);
+
+       char *ret_name = g_strdup(basename(tmp_path));
+
+       g_free(tmp_path);
+       tmp_path = NULL;
+
+       return ret_name;
+}
index aef2a31..9400489 100755 (executable)
@@ -1,20 +1,21 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "MsgDebug.h"
+#include "MsgContact.h"
 #include "MsgUtilFunction.h"
 
  /*==================================================================================================
@@ -94,11 +95,11 @@ int MsgEncodeMsgId(msg_message_id_t *pMsgId, char **ppDest)
 }
 
 
-int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
+int MsgEncodeMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
 {
        int dataSize = 0;
 
-       dataSize = sizeof(MSG_MESSAGE_INFO_S);
+       dataSize = sizeof(MSG_MESSAGE_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt);
 
        *ppDest = (char*)new char[dataSize];
 
@@ -108,6 +109,11 @@ int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
 
        p = (void*)((char*)p + sizeof(MSG_MESSAGE_INFO_S));
 
+       for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
+               memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
+               p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
+       }
+
        return dataSize;
 }
 
@@ -116,7 +122,7 @@ int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendO
 {
        int dataSize = 0;
 
-       dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S));
+       dataSize = (sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S) + (sizeof(MSG_ADDRESS_INFO_S)*pMsgInfo->nAddressCnt));
 
        *ppDest = (char*)new char[dataSize];
 
@@ -128,9 +134,17 @@ int MsgEncodeMsgInfo(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendO
 
        memcpy(p, pSendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
 
+       p = (void*)((char*)p + sizeof(MSG_SENDINGOPT_INFO_S));
+
+       for (int i=0; i < pMsgInfo->nAddressCnt; i++) {
+               memcpy(p, &(pMsgInfo->addressList[i]), sizeof(MSG_ADDRESS_INFO_S));
+               p = (void*)((char*)p + sizeof(MSG_ADDRESS_INFO_S));
+       }
+
        return dataSize;
 }
 
+
 int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
 {
        int count = 0, dataSize = 0;
@@ -157,6 +171,7 @@ int MsgEncodeFolderList(msg_struct_list_s *pFolderList, char **ppDest)
        return dataSize;
 }
 
+
 int MsgEncodeFilterList(msg_struct_list_s *pFilterList, char **ppDest)
 {
        int count = 0, dataSize = 0;
@@ -357,6 +372,35 @@ int MsgEncodeStorageChangeData(const msg_storage_change_type_t storageChangeType
 }
 
 
+int MsgEncodeReportMsgData(const msg_report_type_t msgReportType, const MSG_MESSAGE_INFO_S *pMsgInfo, char **ppDest)
+{
+       int dataSize = 0;
+       int addr_len = 0;
+
+       addr_len = strlen(pMsgInfo->addressList->addressVal);
+
+       dataSize = sizeof(msg_report_type_t) + sizeof(msg_message_id_t) + sizeof(int) + addr_len;
+
+       *ppDest = (char*)new char[dataSize];
+
+       void* p = (void*)*ppDest;
+
+       memcpy(p, &msgReportType, sizeof(msg_report_type_t));
+       p = (void*)((char*)p + sizeof(msg_report_type_t));
+
+       memcpy(p, &(pMsgInfo->msgId), sizeof(msg_message_id_t));
+       p = (void*)((char*)p + sizeof(msg_message_id_t));
+
+       memcpy(p, &addr_len, sizeof(int));
+       p = (void*)((char*)p + sizeof(int));
+
+       memcpy(p, &(pMsgInfo->addressList->addressVal), addr_len);
+       p = (void*)((char*)p + addr_len);
+
+       return dataSize;
+}
+
+
 int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, char **ppDest)
 {
        int dataSize = 0;
@@ -369,7 +413,7 @@ int MsgEncodeReportStatus(MSG_REPORT_STATUS_INFO_S* pReportStatus, int count, ch
 
        memcpy(p, &count, sizeof(int));
 
-       p = (void*)(p + sizeof(int));
+       p = (void*)((int)p + sizeof(int));
 
        memcpy(p, pReportStatus, sizeof(MSG_REPORT_STATUS_INFO_S)*count);
 
@@ -431,6 +475,23 @@ void MsgDecodeMemSize(char *pSrc, unsigned int *memsize)
 }
 
 
+void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
+
+       pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
+
+       pMsgInfo->addressList = NULL;
+
+       pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
+       memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
+
+       for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
+               memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
+       }
+}
+
+
 void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo)
 {
        memcpy(pMsgInfo, pSrc, sizeof(MSG_MESSAGE_INFO_S));
@@ -438,8 +499,23 @@ void MsgDecodeMsgInfo(char *pSrc, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I
        pSrc = pSrc + sizeof(MSG_MESSAGE_INFO_S);
 
        memcpy(pSendOptInfo, pSrc, sizeof(MSG_SENDINGOPT_INFO_S));
+
+       pSrc = pSrc + sizeof(MSG_SENDINGOPT_INFO_S);
+
+
+       if(pMsgInfo->nAddressCnt > 0) {
+               pMsgInfo->addressList = NULL;
+
+               pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt];
+               memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pMsgInfo->nAddressCnt);
+
+               for (int i=0; i<pMsgInfo->nAddressCnt; i++) {
+                       memcpy(&(pMsgInfo->addressList[i]), pSrc + (sizeof(MSG_ADDRESS_INFO_S)*i), sizeof(MSG_ADDRESS_INFO_S));
+               }
+       }
 }
 
+
 void MsgDecodeRecipientList(char *pSrc, MSG_RECIPIENTS_LIST_S *pRecipientList)
 {
        int count = 0;
@@ -471,17 +547,16 @@ void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
        if( count > 0 )
        {
                pFolderList->nCount = count;
-               pFolderList->msg_struct_info = (msg_struct_t *)new char[sizeof(MSG_FOLDER_INFO_S *)*count];
+               pFolderList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*count];
 
                msg_struct_s *pInfoTmp = NULL;
 
                for (int i = 0; i < count; i++)
                {
-
-                       pFolderList->msg_struct_info[i] = (msg_struct_t )new char[sizeof(msg_struct_s)];
+                       pFolderList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
                        pInfoTmp = (msg_struct_s *)pFolderList->msg_struct_info[i];
                        pInfoTmp->type = MSG_STRUCT_FOLDER_INFO;
-                       pInfoTmp->data = new char[sizeof(MSG_FOLDER_INFO_S)];
+                       pInfoTmp->data = new MSG_FOLDER_INFO_S;
                        memcpy(pInfoTmp->data, pSrc, sizeof(MSG_FOLDER_INFO_S));
                        pSrc = pSrc + sizeof(MSG_FOLDER_INFO_S);
                }
@@ -493,6 +568,7 @@ void MsgDecodeFolderList(char *pSrc, msg_struct_list_s *pFolderList)
        }
 }
 
+
 void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
 {
        int count = 0;
@@ -509,10 +585,10 @@ void MsgDecodeFilterList(char *pSrc, msg_struct_list_s *pFilterList)
 
                for (int i = 0; i < count; i++)
                {
-                       pFilterList->msg_struct_info[i] = (msg_struct_t )new char[sizeof(msg_struct_s)];
+                       pFilterList->msg_struct_info[i] = (msg_struct_t )new msg_struct_s;
                        pStructTmp = (msg_struct_s *)pFilterList->msg_struct_info[i];
                        pStructTmp->type = MSG_STRUCT_FILTER;
-                       pStructTmp->data = new char[sizeof(MSG_FILTER_S)];
+                       pStructTmp->data = new MSG_FILTER_S;
                        memcpy(pStructTmp->data, pSrc, sizeof(MSG_FILTER_S));
                        pSrc = pSrc + sizeof(MSG_FILTER_S);
                }
@@ -537,6 +613,7 @@ void MsgDecodeMsgType(char *pSrc, MSG_MESSAGE_TYPE_S* pMsgType)
        memcpy(pMsgType, pSrc, sizeof(MSG_MESSAGE_TYPE_S));
 }
 
+
 void   MsgDecodeContactCount(char *pSrc,  MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
 {
        int count = 0;
@@ -619,6 +696,11 @@ int MsgMakeEvent(const void *pData, int DataSize, MSG_EVENT_TYPE_T MsgEvent, msg
 {
        MSG_EVENT_S* pMsgEvent = NULL;
 
+       if (*ppEvent) {
+               MSG_DEBUG("*ppEvent is not NULL.");
+               delete [] (char *)*ppEvent;
+       }
+
        *ppEvent = (MSG_EVENT_S*)new char[sizeof(MSG_EVENT_S) + DataSize];
 
        pMsgEvent = (MSG_EVENT_S*)*ppEvent;
@@ -703,3 +785,258 @@ int msg_verify_email(const char *raw)
 
        return MSG_SUCCESS;
 }
+
+
+char* msg_clean_country_code(char *src)
+{
+       int ret = 1;
+
+       switch (src[ret++]-'0')
+       {
+               case 1:
+               case 7:
+                       break;
+               case 2:
+                       switch (src[ret++]-'0')
+                       {
+                               case 0:
+                               case 7:
+                                       break;
+                               case 1:
+                               case 2:
+                               case 3:
+                               case 4:
+                               case 5:
+                               case 6:
+                               case 8:
+                               case 9:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 3:
+                       switch (src[ret++]-'0')
+                       {
+                               case 0:
+                               case 1:
+                               case 2:
+                               case 3:
+                               case 4:
+                               case 6:
+                               case 9:
+                                       break;
+                               case 5:
+                               case 7:
+                               case 8:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 4:
+                       switch (src[ret++]-'0')
+                       {
+                               case 0:
+                               case 1:
+                               case 3:
+                               case 4:
+                               case 5:
+                               case 6:
+                               case 7:
+                               case 8:
+                               case 9:
+                                       break;
+                               case 2:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 5:
+                       switch (src[ret++]-'0')
+                       {
+                               case 1:
+                               case 2:
+                               case 3:
+                               case 4:
+                               case 5:
+                               case 6:
+                               case 7:
+                               case 8:
+                                       break;
+                               case 0:
+                               case 9:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 6:
+                       switch (src[ret++]-'0')
+                       {
+                               case 0:
+                               case 1:
+                               case 2:
+                               case 3:
+                               case 4:
+                               case 5:
+                               case 6:
+                                       break;
+                               case 7:
+                               case 8:
+                               case 9:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 8:
+                       switch (src[ret++]-'0')
+                       {
+                               case 1:
+                               case 2:
+                               case 4:
+                               case 6:
+                                       break;
+                               case 0:
+                               case 3:
+                               case 5:
+                               case 7:
+                               case 8:
+                               case 9:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 9:
+                       switch (src[ret++]-'0')
+                       {
+                               case 0:
+                               case 1:
+                               case 2:
+                               case 3:
+                               case 4:
+                               case 5:
+                               case 8:
+                                       break;
+                               case 6:
+                               case 7:
+                               case 9:
+                                       ret += 1;
+                                       break;
+                               default:
+                                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                                       break;
+                       }
+                       break;
+               case 0:
+               default:
+                       MSG_DEBUG("The parameter(src:%s) has invalid character set", src);
+                       return src;
+       }
+
+       return &src[ret];
+}
+
+
+char* msg_normalize_number(char *src)
+{
+       char *normalized_number;
+
+       if ('+' == src[0])
+               normalized_number = msg_clean_country_code(src);
+       else if ('0' == src[0])
+               normalized_number = src+1;
+       else
+               normalized_number = src;
+
+       MSG_DEBUG("src = %s, normalized = %s", src, normalized_number);
+
+       return normalized_number;
+}
+
+
+msg_error_t MsgMakeSortRule(const MSG_SORT_RULE_S *pSortRule, char *pSqlSort)
+{
+       char sql[128];
+       char order[6];
+
+       memset(sql, 0x00, sizeof(sql));
+       memset(order, 0x00, sizeof(order));
+
+       if (pSortRule->bAscending == true)
+               strncpy(order, "ASC", 5);
+       else
+               strncpy(order, "DESC", 5);
+
+       int nameOrder = MsgGetContactNameOrder();
+
+       switch (pSortRule->sortType)
+       {
+               case MSG_SORT_BY_DISPLAY_FROM :
+                       if (nameOrder == 0)
+                               snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
+                       else
+                               snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
+                       break;
+               case MSG_SORT_BY_DISPLAY_TO :
+                       if (nameOrder == 0)
+                               snprintf(sql, sizeof(sql), "ORDER BY B.FIRST_NAME %s, B.LAST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
+                       else
+                               snprintf(sql, sizeof(sql), "ORDER BY B.LAST_NAME %s, B.FIRST_NAME %s, B.ADDRESS_VAL, A.DISPLAY_TIME DESC;", order, order);
+                       break;
+               case MSG_SORT_BY_DISPLAY_TIME :
+                       snprintf(sql, sizeof(sql), "ORDER BY DISPLAY_TIME %s;", order);
+                       break;
+               case MSG_SORT_BY_MSG_TYPE :
+                       snprintf(sql, sizeof(sql), "ORDER BY MAIN_TYPE %s, DISPLAY_TIME DESC;", order);
+                       break;
+               case MSG_SORT_BY_READ_STATUS :
+                       snprintf(sql, sizeof(sql), "ORDER BY READ_STATUS %s, DISPLAY_TIME DESC;", order);
+                       break;
+               case MSG_SORT_BY_STORAGE_TYPE :
+                       snprintf(sql, sizeof(sql), "ORDER BY A.STORAGE_ID %s, A.DISPLAY_TIME DESC;", order);
+                       break;
+               case MSG_SORT_BY_THREAD_NAME :
+                       if (nameOrder == 0)
+                               snprintf(sql, sizeof(sql), "ORDER BY FIRST_NAME %s, LAST_NAME %s;", order, order);
+                       else
+                               snprintf(sql, sizeof(sql), "ORDER BY LAST_NAME %s, FIRST_NAME %s;", order, order);
+                       break;
+               case MSG_SORT_BY_THREAD_DATE :
+                       snprintf(sql, sizeof(sql), "ORDER BY MSG_TIME %s;", order);
+                       break;
+               case MSG_SORT_BY_THREAD_COUNT :
+                       snprintf(sql, sizeof(sql), "ORDER BY UNREAD_CNT %s;", order);
+                       break;
+               default :
+                       snprintf(sql, sizeof(sql), "ORDER BY A.DISPLAY_TIME %s;", order);
+                       break;
+       }
+
+       memcpy(pSqlSort, sql, strlen(sql));
+
+       return MSG_SUCCESS;
+}
+bool msg_is_valid_email(char *pAddress)
+{
+       if (!pAddress || pAddress[0] == 0)
+               return false;
+       if (!strchr (pAddress, MSG_UTIL_CH_EMAIL_AT))
+               return false;
+       return true;
+}
index b4034aa..7e038aa 100755 (executable)
@@ -1,37 +1,47 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <tr1/unordered_set>
+#include <queue>
+#include <glib.h>
+
 #include "MsgDebug.h"
 #include "MsgUtilFile.h"
 #include "MsgContact.h"
 #include "MsgCppTypes.h"
 #include "MsgGconfWrapper.h"
-#include "MsgNotificationWrapper.h"
+#include "MsgUtilFunction.h"
 #include "MsgUtilStorage.h"
 
-#include <sys/stat.h>
-#include <sys/vfs.h>
-
+//#include <sys/stat.h>
+//#include <sys/vfs.h>
+#include <storage.h>
 
 static int msgCntLimit[MSG_COUNT_LIMIT_MAILBOX_TYPE_MAX][MSG_COUNT_LIMIT_MSG_TYPE_MAX] = {{10, 10, 0, 10, 10}, {5, 10, 0, 0, 0}, {10, 10, 0, 0, 0}, {10, 10, 0, 0, 0}, {0, 0, 10, 0, 0}};
 
+using namespace std;
 
+#define ITERATION_SIZE 200
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
+
 unsigned int MsgStoAddMessageTable(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        MSG_BEGIN();
@@ -58,31 +68,40 @@ unsigned int MsgStoAddMessageTable(MsgDbHandler *pDbHandle, const MSG_MESSAGE_IN
                MSG_DEBUG("file size [%d]", fileSize);
        }
 
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       memset(keyName, 0x00, sizeof(keyName));
+       sprintf(keyName, "%s/%d", MSG_SIM_IMSI, pMsgInfo->sim_idx);
+
+       char *imsi = MsgSettingGetString(keyName);
+
        // Add Message
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %ld, %d, %d, %d, %d, %d, %d, %ld, %d, ?, ?, ?, ?, 0);",
+       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');",
                        MSGFW_MESSAGE_TABLE_NAME, msgId, pMsgInfo->threadId, pMsgInfo->folderId, pMsgInfo->storageId, pMsgInfo->msgType.mainType,
-                       pMsgInfo->msgType.subType, pMsgInfo->displayTime, pMsgInfo->dataSize, pMsgInfo->networkStatus, pMsgInfo->bRead, pMsgInfo->bProtected,
-                       pMsgInfo->priority, pMsgInfo->direction, 0, pMsgInfo->bBackup);
+                       pMsgInfo->msgType.subType, (unsigned int)pMsgInfo->displayTime, pMsgInfo->dataSize, pMsgInfo->networkStatus, pMsgInfo->bRead, pMsgInfo->bProtected,
+                       pMsgInfo->priority, pMsgInfo->direction, 0, pMsgInfo->bBackup, pMsgInfo->sim_idx, imsi);
 
        MSG_DEBUG("QUERY : %s", sqlQuery);
 
+       g_free(imsi);
+       imsi = NULL;
+
        if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                return 0;
 
        pDbHandle->bindText(pMsgInfo->subject, 1);
 
-       pDbHandle->bindText(pMsgInfo->msgData, 2);
-
-       pDbHandle->bindText(pMsgInfo->thumbPath, 3);
+       if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
+               pDbHandle->bindText("", 2);
+       } else {
+               if (pMsgInfo->bTextSms == false)
+                       pDbHandle->bindText(pFileData, 2);
+               else
+                       pDbHandle->bindText(pMsgInfo->msgText, 2);
 
-       if (pMsgInfo->bTextSms == false)
-               pDbHandle->bindText(pFileData, 4);
-       else
-               pDbHandle->bindText(pMsgInfo->msgText, 4);
+       }
 
        if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
                pDbHandle->finalizeQuery();
@@ -136,15 +155,6 @@ msg_error_t MsgStoSetReadStatus(MsgDbHandler *pDbHandle, msg_message_id_t msgId,
                return MSG_ERR_STORAGE_ERROR;
        }
 
-       int smsCnt = 0, mmsCnt = 0;
-
-       smsCnt = MsgStoGetUnreadCnt(pDbHandle, MSG_SMS_TYPE);
-       mmsCnt = MsgStoGetUnreadCnt(pDbHandle, MSG_MMS_TYPE);
-
-       MsgSettingSetIndicator(smsCnt, mmsCnt);
-
-       MsgRefreshNoti(false);
-
        return MSG_SUCCESS;
 }
 
@@ -176,27 +186,27 @@ msg_error_t MsgStoGetOldestMessage(MsgDbHandler *pDbHandle, const MSG_MESSAGE_IN
 }
 
 
-msg_error_t MsgStoCheckMsgCntFull(MsgDbHandler *pDbHandle, const MSG_MESSAGE_TYPE_S* pMsgType, msg_folder_id_t folderId)
+msg_error_t MsgStoCheckMsgCntFull(MsgDbHandler *pDbHandle, const MSG_MESSAGE_TYPE_S* pMsgType, msg_folder_id_t folderId, int simIndex)
 {
        MSG_BEGIN();
 
        msg_error_t err = MSG_SUCCESS;
-               struct statfs buf = {0};
 
-               if (statfs(MSG_DATA_ROOT_PATH, &buf) == -1) {
-                       MSG_DEBUG("statfs(\"%s\") failed - %d", MSG_DATA_ROOT_PATH);
-                       return MSG_ERR_STORAGE_ERROR;
-               }
-
-               unsigned long freeSpace = (buf.f_bfree * buf.f_bsize);
-
-               MSG_DEBUG("f_bfree [%d] f_bsize [%d]", buf.f_bfree, buf.f_bsize);
-               MSG_DEBUG("Free space of storage is [%ul] MB.", freeSpace);
+       struct statvfs s;
+       double freeSpace;
+       int r;
+       r = storage_get_internal_memory_size(&s);
+       if (r < 0)
+               return MSG_ERR_STORAGE_ERROR;
+       else {
+               freeSpace = (double)s.f_bsize*s.f_bavail;
+               MSG_DEBUG("Free space of storage is [%lu] MB.", freeSpace);
 
                if (freeSpace < SMS_MINIMUM_SPACE && pMsgType->mainType == MSG_SMS_TYPE)
                        err = MSG_ERR_MESSAGE_COUNT_FULL;
                else if(freeSpace < MMS_MINIMUM_SPACE && pMsgType->mainType == MSG_MMS_TYPE)
                        err = MSG_ERR_MESSAGE_COUNT_FULL;
+       }
 
        MSG_END();
 
@@ -333,6 +343,28 @@ int MsgStoCheckMsgCntLimit(const MSG_MESSAGE_TYPE_S* pMsgType, msg_folder_id_t f
 }
 
 
+msg_error_t MsgStocheckMemoryStatus()
+{
+       msg_error_t err = MSG_SUCCESS;
+       struct statvfs s;
+       double freeSpace;
+       int r;
+       r = storage_get_internal_memory_size(&s);
+       if (r < 0)
+               return MSG_ERR_STORAGE_ERROR;
+       else {
+               freeSpace = (double)s.f_bsize*s.f_bavail;
+           MSG_DEBUG("Free space of storage is [%ul] MB.", freeSpace);
+               if (freeSpace < SMS_MINIMUM_SPACE)
+                       err = MSG_ERR_MESSAGE_COUNT_FULL;
+       }
+
+       MSG_DEBUG("Memory status =[%d]", err);
+
+       return err;
+}
+
+
 msg_error_t MsgStoAddAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pConvId)
 {
        msg_error_t err = MSG_SUCCESS;
@@ -342,130 +374,117 @@ msg_error_t MsgStoAddAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *
        // Check if new address or not
        if (MsgExistAddress(pDbHandle, pMsg, pConvId) == true) {
                MSG_DEBUG("The address already exists. Conversation ID : [%d]", *pConvId);
-               return err;
-       }
-
-       MSG_DEBUG("Conversation ID : [%d]", *pConvId);
-
-       /* conversation insert */
-       err = MsgStoAddConversation(pDbHandle, pConvId);
-       if (err != MSG_SUCCESS) {
-               MSG_DEBUG("MsgStoAddConversation() fail [%d]", err);
-               return err;
-       }
-
-       /* insert address in loop */
-       for (int i=0; i<pMsg->nAddressCnt; i++) {
+               MsgStoUpdateAddress(pDbHandle, pMsg, *pConvId);
+       } else {
 
-               unsigned int addrId;
-               MSG_CONTACT_INFO_S contactInfo;
-               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+               *pConvId = 0;
 
-               // Get Contact Info
-               if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) {
-                       MSG_DEBUG("MsgGetContactInfo() fail.");
-               }
+               if(pMsg->threadId)
+                       *pConvId = pMsg->threadId;
 
-               err = pDbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
+               /* conversation insert */
+               err = MsgStoAddConversation(pDbHandle, pConvId);
                if (err != MSG_SUCCESS) {
-                       MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
+                       MSG_DEBUG("MsgStoAddConversation() fail [%d]", err);
                        return err;
                }
 
-               // Add Address
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, ?, ?, ?, '%s', 0);",
-                                       MSGFW_ADDRESS_TABLE_NAME, addrId, *pConvId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
-                                       contactInfo.contactId, contactInfo.imagePath);
+               /* insert address in loop */
+               for (int i=0; i<pMsg->nAddressCnt; i++) {
 
-               MSG_DEBUG("Add Address Info. [%s]", sqlQuery);
+                       unsigned int addrId;
+                       MSG_CONTACT_INFO_S contactInfo;
+                       memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
 
-               if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
-                       return MSG_ERR_DB_PREPARE;
+                       // Get Contact Info
+//                     if (MsgGetContactInfo(&(pMsg->addressList[i]), &contactInfo) != MSG_SUCCESS) {
+//                             MSG_DEBUG("MsgGetContactInfo() fail.");
+//                     }
 
-               pDbHandle->bindText(contactInfo.displayName, 1);
-               pDbHandle->bindText(contactInfo.firstName, 2);
-               pDbHandle->bindText(contactInfo.lastName, 3);
+                       err = pDbHandle->getRowId(MSGFW_ADDRESS_TABLE_NAME, &addrId);
+                       if (err != MSG_SUCCESS) {
+                               MSG_DEBUG("pDbHandle->getRowId fail. [%d]", err);
+                               return err;
+                       }
 
-               if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
-                       pDbHandle->finalizeQuery();
-                       return MSG_ERR_DB_STEP;
-               }
+                       // Add Address
+                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, %d, ?, ?, ?, ?, ?, '%s', 0);",
+                                               MSGFW_ADDRESS_TABLE_NAME, addrId, *pConvId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
+                                               contactInfo.contactId, contactInfo.addrbookId, contactInfo.imagePath);
 
-               pDbHandle->finalizeQuery();
+                       MSG_SEC_DEBUG("Add Address Info. [%s]", sqlQuery);
+
+                       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+                               return MSG_ERR_DB_PREPARE;
 
-               // set conversation display name by conv id
-               MsgStoSetConversationDisplayName(pDbHandle, *pConvId);
+                       pDbHandle->bindText(contactInfo.firstName, 1);
+                       pDbHandle->bindText(contactInfo.lastName, 2);
+                       pDbHandle->bindText(contactInfo.middleName, 3);
+                       pDbHandle->bindText(contactInfo.prefix, 4);
+                       pDbHandle->bindText(contactInfo.suffix, 5);
+
+                       if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                               pDbHandle->finalizeQuery();
+                               return MSG_ERR_DB_STEP;
+                       }
 
+                       pDbHandle->finalizeQuery();
+               }
        }
 
+       // set conversation display name by conv id
+       MsgStoSetConversationDisplayName(pDbHandle, *pConvId);
+
        return err;
 }
 
-msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int contactNameOrder, int *nAddressCnt, MSG_ADDRESS_INFO_S *pAddress)
+msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int contactNameOrder, int *nAddressCnt, MSG_ADDRESS_INFO_S **pAddress)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
-       char firstName[MAX_DISPLAY_NAME_LEN+1];
-       char lastName[MAX_DISPLAY_NAME_LEN+1];
+       int index = 3;
+       int rowCnt = 0;
 
        *nAddressCnt = 0;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_TYPE, A.RECIPIENT_TYPE, \
-                               A.CONTACT_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME \
-                               FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.MSG_ID = %d;",
-                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, msgId);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               MSG_DEBUG("Query Failed [%s]", sqlQuery);
-               return MSG_ERR_DB_PREPARE;
-       }
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "A.ADDRESS_TYPE, "
+                       "A.RECIPIENT_TYPE, "
+                       "A.ADDRESS_VAL "
+                       "FROM %s A, %s B "
+                       "WHERE A.CONV_ID = B.CONV_ID "
+                       "AND B.MSG_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                       msgId);
 
-       while (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
-               memset(firstName, 0x00, sizeof(firstName));
-               memset(lastName, 0x00, sizeof(lastName));
-
-               pAddress[*nAddressCnt].addressType = pDbHandle->columnInt(0);
-               pAddress[*nAddressCnt].recipientType = pDbHandle->columnInt(1);
-               pAddress[*nAddressCnt].contactId = pDbHandle->columnInt(2);
+       msg_error_t  err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
-               if (pDbHandle->columnText(3) != NULL)
-                       strncpy(pAddress[*nAddressCnt].addressVal, (char *)pDbHandle->columnText(3), MAX_ADDRESS_VAL_LEN);
+       if (err == MSG_ERR_DB_NORECORD) {
+               pDbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               pDbHandle->freeTable();
+               return err;
+       }
 
-               if (pDbHandle->columnText(4) != NULL && ((char *)pDbHandle->columnText(4))[0]!='\0') {
-                       MSG_DEBUG("displayName  : [%s]", pDbHandle->columnText(4));
-                       strncpy(pAddress[*nAddressCnt].displayName, (char *)pDbHandle->columnText(4), MAX_DISPLAY_NAME_LEN);
-               } else {
-                       if (pDbHandle->columnText(5) != NULL)
-                                       strncpy(firstName, (char *)pDbHandle->columnText(5), MAX_DISPLAY_NAME_LEN);
+       *nAddressCnt = rowCnt;
 
-                       if (pDbHandle->columnText(6) != NULL)
-                                       strncpy(lastName, (char *)pDbHandle->columnText(6), MAX_DISPLAY_NAME_LEN);
+       MSG_DEBUG("*nAddressCnt [%d]", *nAddressCnt);
 
-                       if (contactNameOrder == 0) {
-                               if (strlen(firstName) > 0) {
-                                       strncpy(pAddress[*nAddressCnt].displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
-                               if (strlen(lastName) > 0) {
-                                       strncat(pAddress[*nAddressCnt].displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pAddress[*nAddressCnt].displayName));
-                                       strncat(pAddress[*nAddressCnt].displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(pAddress[*nAddressCnt].displayName));
-                               }
-                       } else if (contactNameOrder == 1) {
-                               if (strlen(lastName) > 0) {
-                                       strncpy(pAddress[*nAddressCnt].displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(pAddress[*nAddressCnt].displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pAddress[*nAddressCnt].displayName));
-                               }
+       MSG_ADDRESS_INFO_S *tmpAddressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * rowCnt];
+       memset(tmpAddressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * rowCnt);
+       *pAddress = tmpAddressList;
 
-                               if (strlen(firstName) > 0) {
-                                       strncat(pAddress[*nAddressCnt].displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(pAddress[*nAddressCnt].displayName));
-                               }
-                       }
-               }
+       for (int i = 0; i < rowCnt; i++) {
+               tmpAddressList[i].addressType = pDbHandle->getColumnToInt(index++);
+               tmpAddressList[i].recipientType = pDbHandle->getColumnToInt(index++);
+               pDbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, tmpAddressList[i].addressVal);
 
-               (*nAddressCnt)++;
+               strncpy(tmpAddressList[i].displayName, tmpAddressList[i].addressVal, MAX_DISPLAY_NAME_LEN);
        }
-
-       pDbHandle->finalizeQuery();
+       pDbHandle->freeTable();
 
        return MSG_SUCCESS;
 }
@@ -473,86 +492,64 @@ msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t ms
 msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t msgId, int contactNameOrder, msg_struct_list_s *pAddress)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
-       char firstName[MAX_DISPLAY_NAME_LEN+1];
-       char lastName[MAX_DISPLAY_NAME_LEN+1];
+
+       int index = 3;
+       int rowCnt = 0;
 
        pAddress->nCount = 0;
        pAddress->msg_struct_info = NULL;
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.ADDRESS_TYPE, A.RECIPIENT_TYPE, \
-                       A.CONTACT_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME \
-                       FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.MSG_ID = %d;",
-                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, msgId);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
-               MSG_DEBUG("Query Failed [%s]", sqlQuery);
-               return MSG_ERR_DB_PREPARE;
-       }
-
        msg_struct_s *pTmp = NULL;
        MSG_ADDRESS_INFO_S *pAddr = NULL;
 
        pAddress->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * MAX_TO_ADDRESS_CNT];
 
        for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
-               pAddress->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
+               pAddress->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
                pTmp = (msg_struct_s *)pAddress->msg_struct_info[i];
                pTmp->type = MSG_STRUCT_ADDRESS_INFO;
-               pTmp->data = new char[sizeof(MSG_ADDRESS_INFO_S)];
+               pTmp->data = new MSG_ADDRESS_INFO_S;
                memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
        }
 
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "A.ADDRESS_TYPE, "
+                       "A.RECIPIENT_TYPE, "
+                       "A.ADDRESS_VAL "
+                       "FROM %s A, %s B "
+                       "WHERE A.CONV_ID = B.CONV_ID "
+                       "AND B.MSG_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                       msgId);
 
-       while (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
-               memset(firstName, 0x00, sizeof(firstName));
-               memset(lastName, 0x00, sizeof(lastName));
-
-               pTmp = (msg_struct_s *)pAddress->msg_struct_info[pAddress->nCount];
-               pAddr = (MSG_ADDRESS_INFO_S *)pTmp->data;
-
-               pAddr->addressType = pDbHandle->columnInt(0);
-               pAddr->recipientType = pDbHandle->columnInt(1);
-               pAddr->contactId = pDbHandle->columnInt(2);
-
-               if (pDbHandle->columnText(3) != NULL)
-                                       strncpy(pAddr->addressVal, (char *)pDbHandle->columnText(3), MAX_ADDRESS_VAL_LEN);
+       msg_error_t  err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
-               if (pDbHandle->columnText(4) != NULL && ((char *)pDbHandle->columnText(4))[0]!='\0') {
-                                       MSG_DEBUG("displayName  : [%s]", pDbHandle->columnText(4));
-                                       strncpy(pAddr->displayName, (char *)pDbHandle->columnText(4), MAX_DISPLAY_NAME_LEN);
-               } else {
-                       if (pDbHandle->columnText(5) != NULL)
-                               strncpy(firstName, (char *)pDbHandle->columnText(5), MAX_DISPLAY_NAME_LEN);
+       if (err == MSG_ERR_DB_NORECORD) {
+               pDbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               pDbHandle->freeTable();
+               return err;
+       }
 
-                       if (pDbHandle->columnText(6) != NULL)
-                               strncpy(lastName, (char *)pDbHandle->columnText(6), MAX_DISPLAY_NAME_LEN);
+       rowCnt = (rowCnt > 10)? MAX_TO_ADDRESS_CNT: rowCnt;
+       pAddress->nCount = rowCnt;
 
-                       if (contactNameOrder == 0) {
-                               if (strlen(firstName) > 0) {
-                                       strncpy(pAddr->displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
+       for (int i = 0; i < rowCnt; i++) {
+               pTmp = (msg_struct_s *)pAddress->msg_struct_info[i];
+               pAddr = (MSG_ADDRESS_INFO_S *)pTmp->data;
 
-                               if (strlen(lastName) > 0) {
-                                       strncat(pAddr->displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                                       strncat(pAddr->displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                               }
-                       } else if (contactNameOrder == 1) {
-                               if (strlen(lastName) > 0) {
-                                       strncpy(pAddr->displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(pAddr->displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                               }
+               pAddr->addressType = pDbHandle->getColumnToInt(index++);
+               pAddr->recipientType = pDbHandle->getColumnToInt(index++);
 
-                               if (strlen(firstName) > 0) {
-                                       strncat(pAddr->displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                               }
-                       }
-               }
+               pDbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pAddr->addressVal);
 
-               pAddress->nCount++;
+               strncpy(pAddr->displayName, pAddr->addressVal, MAX_DISPLAY_NAME_LEN);
        }
 
-       pDbHandle->finalizeQuery();
+       pDbHandle->freeTable();
 
        return MSG_SUCCESS;
 }
@@ -561,18 +558,18 @@ msg_error_t MsgStoGetAddressByMsgId(MsgDbHandler *pDbHandle, msg_message_id_t ms
 msg_error_t MsgStoGetAddressByConvId(MsgDbHandler *pDbHandle, msg_thread_id_t convId, int contactNameOrder, msg_struct_list_s *pAddrlist)
 {
        char sqlQuery[MAX_QUERY_LEN+1];
-       char firstName[MAX_DISPLAY_NAME_LEN+1];
-       char lastName[MAX_DISPLAY_NAME_LEN+1];
-       int index = 7;
+       int index = 3;
        int rowCnt = 0;
 
        pAddrlist->nCount = 0;
        pAddrlist->msg_struct_info = NULL;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_TYPE, RECIPIENT_TYPE, \
-                       CONTACT_ID, ADDRESS_VAL, DISPLAY_NAME, FIRST_NAME, LAST_NAME \
-                       FROM %s WHERE CONV_ID  = %d;",
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "ADDRESS_TYPE, "
+                       "RECIPIENT_TYPE, "
+                       "ADDRESS_VAL "
+                       "FROM %s WHERE CONV_ID  = %d;",
                        MSGFW_ADDRESS_TABLE_NAME, convId);
 
        msg_error_t  err = pDbHandle->getTable(sqlQuery, &rowCnt);
@@ -581,7 +578,7 @@ msg_error_t MsgStoGetAddressByConvId(MsgDbHandler *pDbHandle, msg_thread_id_t co
                pDbHandle->freeTable();
                return MSG_SUCCESS;
        } else if (err != MSG_SUCCESS) {
-               MSG_DEBUG("sqlQuery is - %s", sqlQuery);
+               MSG_DEBUG("Fail to getTable().");
                pDbHandle->freeTable();
                return err;
        }
@@ -593,52 +590,27 @@ msg_error_t MsgStoGetAddressByConvId(MsgDbHandler *pDbHandle, msg_thread_id_t co
        msg_struct_s *pTmp = NULL;
        MSG_ADDRESS_INFO_S *pAddr = NULL;
 
-       pAddrlist->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * MAX_TO_ADDRESS_CNT];
+       pAddrlist->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
 
-       for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
-               pAddrlist->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
+       for (int i = 0; i < rowCnt; i++) {
+               pAddrlist->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
                pTmp = (msg_struct_s *)pAddrlist->msg_struct_info[i];
                pTmp->type = MSG_STRUCT_ADDRESS_INFO;
-               pTmp->data = new char[sizeof(MSG_ADDRESS_INFO_S)];
+               pTmp->data = new MSG_ADDRESS_INFO_S;
                memset(pTmp->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
        }
 
+//     rowCnt = (rowCnt > 10)? MAX_TO_ADDRESS_CNT: rowCnt;
+
        for (int i = 0; i < rowCnt; i++) {
                pTmp = (msg_struct_s *)pAddrlist->msg_struct_info[i];
                pAddr = (MSG_ADDRESS_INFO_S *)pTmp->data;
 
                pAddr->addressType = pDbHandle->getColumnToInt(index++);
                pAddr->recipientType = pDbHandle->getColumnToInt(index++);
-               pAddr->contactId = pDbHandle->getColumnToInt(index++);
                pDbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pAddr->addressVal);
-               pDbHandle->getColumnToString(index++, MAX_DISPLAY_NAME_LEN, pAddr->displayName);
-               if(!strlen(pAddr->displayName)) {
-                       pDbHandle->getColumnToString(index++,MAX_DISPLAY_NAME_LEN, firstName);
-                       pDbHandle->getColumnToString(index++,MAX_DISPLAY_NAME_LEN, lastName);
-
-                       if (contactNameOrder == 0) {
-                               if (strlen(firstName) > 0) {
-                                       strncpy(pAddr->displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
-
-                               if (strlen(lastName) > 0) {
-                                       strncat(pAddr->displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                                       strncat(pAddr->displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                               }
-                       } else if (contactNameOrder == 1) {
-                               if (strlen(lastName) > 0) {
-                                       strncpy(pAddr->displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(pAddr->displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                               }
 
-                               if (strlen(firstName) > 0) {
-                                       strncat(pAddr->displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
-                               }
-                       }
-               } else {
-                       index++; // firstname
-                       index++; // lastname
-               }
+               strncpy(pAddr->displayName, pAddr->addressVal, MAX_DISPLAY_NAME_LEN);
 
        }
        pDbHandle->freeTable();
@@ -651,144 +623,158 @@ msg_error_t MsgStoUpdateConversation(MsgDbHandler *pDbHandle, msg_thread_id_t co
 {
        MSG_BEGIN();
 
-       msg_error_t err = MSG_SUCCESS;
-
-       int unreadCnt = 0;
-       int smsCnt = 0;
-       int mmsCnt = 0;
-
-       char msgText[MAX_THREAD_DATA_LEN+1];
-       char sqlQuery[MAX_QUERY_LEN+1];
-
-       memset(msgText, 0x00, sizeof(msgText));
-
-       // Get Unread Count
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d AND READ_STATUS = 0;",
-                       MSGFW_MESSAGE_TABLE_NAME, convId, MSG_INBOX_ID, MSG_STORAGE_PHONE);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       err = pDbHandle->stepQuery();
-
-       if (err == MSG_ERR_DB_ROW) {
-               unreadCnt = pDbHandle->columnInt(0);
-       } else if (err != MSG_ERR_DB_DONE) {
-               pDbHandle->finalizeQuery();
-               return MSG_ERR_DB_STEP;
-       }
-
-       pDbHandle->finalizeQuery();
-
-       // Get SMS Count
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND MAIN_TYPE = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
-                       MSGFW_MESSAGE_TABLE_NAME, convId, MSG_SMS_TYPE, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       err = pDbHandle->stepQuery();
-
-       if (err == MSG_ERR_DB_ROW) {
-               smsCnt = pDbHandle->columnInt(0);
-       }
-       else if (err != MSG_ERR_DB_DONE) {
-               pDbHandle->finalizeQuery();
-               return MSG_ERR_DB_STEP;
-       }
-
-       pDbHandle->finalizeQuery();
-
-       // Get MMS Count
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       char sqlQuery[MAX_QUERY_LEN];
+       unsigned int tmpSize = 0;
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s \
-                       WHERE CONV_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE NOT IN (%d, %d, %d) AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d;",
-                       MSGFW_MESSAGE_TABLE_NAME, convId, MSG_MMS_TYPE, MSG_DELIVERYIND_MMS, MSG_READRECIND_MMS, MSG_READORGIND_MMS,
-                       MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       err = pDbHandle->stepQuery();
-
-       if (err == MSG_ERR_DB_ROW) {
-               mmsCnt = pDbHandle->columnInt(0);
-       } else if (err != MSG_ERR_DB_DONE) {
-               pDbHandle->finalizeQuery();
-               return MSG_ERR_DB_STEP;
+#ifdef MSG_NOTI_INTEGRATION
+       memset(sqlQuery, 0x00, MAX_QUERY_LEN);
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT * "
+                       "FROM %s "
+                       "WHERE CONV_ID = %d "
+                       "AND FOLDER_ID > %d AND FOLDER_ID < %d "
+                       "AND STORAGE_ID = %d;",
+                       MSGFW_MESSAGE_TABLE_NAME,
+                       convId,
+                       MSG_ALLBOX_ID, MSG_SPAMBOX_ID,
+                       MSG_STORAGE_PHONE);
+#else
+       memset(sqlQuery, 0x00, MAX_QUERY_LEN);
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT * "
+                       "FROM %s "
+                       "WHERE CONV_ID = %d "
+                       "AND FOLDER_ID > %d AND FOLDER_ID < %d "
+                       "AND STORAGE_ID = %d;",
+                       MSGFW_MESSAGE_TABLE_NAME,
+                       convId,
+                       MSG_ALLBOX_ID, MSG_CBMSGBOX_ID,
+                       MSG_STORAGE_PHONE);
+#endif
+
+       msg_error_t err = pDbHandle->prepareQuery(sqlQuery);
+       if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("Fail to prepareQuery().");
+                       pDbHandle->finalizeQuery();
+                       return err;
        }
 
-       pDbHandle->finalizeQuery();
-
-       // Get Latest Msg Data
-       MSG_MAIN_TYPE_T mainType = MSG_UNKNOWN_TYPE;
-       MSG_SUB_TYPE_T subType = MSG_NORMAL_SMS;
-       msg_direction_type_t direction = MSG_DIRECTION_TYPE_MO;
-       time_t msgTime = 0;
-
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, MSG_DIRECTION, DISPLAY_TIME, SUBJECT, MSG_TEXT FROM %s \
-                       WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC;",
-                       MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
-               return MSG_ERR_DB_PREPARE;
-
-       err = pDbHandle->stepQuery();
-
-       if (err == MSG_ERR_DB_ROW) {
-               mainType = pDbHandle->columnInt(0);
-               subType = pDbHandle->columnInt(1);
-               direction = pDbHandle->columnInt(2);
-
-               msgTime = (time_t)pDbHandle->columnInt(3);
-
-               memset(msgText, 0x00, sizeof(msgText));
-
-               if (mainType == MSG_SMS_TYPE) {
-                       if (pDbHandle->columnText(5) != NULL)
-                               strncpy(msgText, (char*)pDbHandle->columnText(5), MAX_THREAD_DATA_LEN);
-               } else if (mainType == MSG_MMS_TYPE) {
-                       if (pDbHandle->columnText(4) != NULL) {
-                               strncpy(msgText, (char*)pDbHandle->columnText(4), MAX_THREAD_DATA_LEN);
-                       }
-
-                       if ((strlen(msgText) <= 0) && (pDbHandle->columnText(5) != NULL) && (subType != MSG_NOTIFICATIONIND_MMS)) {
-                               memset(msgText, 0x00, sizeof(msgText));
-                               strncpy(msgText, (char*)pDbHandle->columnText(5), MAX_THREAD_DATA_LEN);
-                       }
-               }
-       } else if (err != MSG_ERR_DB_DONE) {
-               pDbHandle->finalizeQuery();
-               return MSG_ERR_DB_STEP;
+       if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               memset(sqlQuery, 0x00, MAX_QUERY_LEN);
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "UPDATE %s SET ",
+                               MSGFW_CONVERSATION_TABLE_NAME);
+
+               tmpSize = strlen(sqlQuery);
+#ifdef MSG_NOTI_INTEGRATION
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "UNREAD_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND (FOLDER_ID = %d OR FOLDER_ID = %d) AND STORAGE_ID = %d AND READ_STATUS = 0), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_INBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
+#else
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "UNREAD_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d AND READ_STATUS = 0), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_INBOX_ID, MSG_STORAGE_PHONE);
+#endif
+
+               tmpSize = strlen(sqlQuery);
+#ifdef MSG_NOTI_INTEGRATION
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "SMS_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND MAIN_TYPE = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_SMS_TYPE, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+#else
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "SMS_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND MAIN_TYPE = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_SMS_TYPE, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
+#endif
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "MMS_CNT = (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND MAIN_TYPE = %d AND SUB_TYPE NOT IN (%d, %d, %d) AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_MMS_TYPE, MSG_DELIVERYIND_MMS, MSG_READRECIND_MMS, MSG_READORGIND_MMS, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "MAIN_TYPE = (SELECT MAIN_TYPE FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "SUB_TYPE = (SELECT SUB_TYPE FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "MSG_DIRECTION = (SELECT MSG_DIRECTION FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC), ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+
+               tmpSize = strlen(sqlQuery);
+#if 1
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "DISPLAY_TIME = CASE "
+                               "WHEN (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC) > 0 "
+                               "THEN (SELECT DISPLAY_TIME FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC) "
+                               "ELSE 0 "
+                               "END, ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+#else
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "DISPLAY_TIME = CASE "
+                               "WHEN (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d AND READ_STATUS = 0) > 0 "
+                               "THEN (SELECT DISPLAY_TIME FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d AND READ_STATUS = 0 ORDER BY DISPLAY_TIME DESC) "
+                               "WHEN (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d) > 0 "
+                               "THEN (SELECT DISPLAY_TIME FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC) "
+                               "WHEN (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d AND NETWORK_STATUS = %d) > 0 "
+                               "THEN (SELECT DISPLAY_TIME FROM %s WHERE CONV_ID = %d AND FOLDER_ID = %d AND STORAGE_ID = %d AND NETWORK_STATUS = %d ORDER BY DISPLAY_TIME DESC) "
+                               "ELSE (SELECT DISPLAY_TIME FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC) "
+                               "END, ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_INBOX_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_INBOX_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_DRAFT_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_DRAFT_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_OUTBOX_ID, MSG_STORAGE_PHONE, MSG_NETWORK_SEND_FAIL,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_OUTBOX_ID, MSG_STORAGE_PHONE, MSG_NETWORK_SEND_FAIL,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+#endif
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "MSG_TEXT = CASE "
+                               "WHEN (SELECT COUNT(MSG_ID) FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC) > 0 "
+                               "THEN CASE "
+                               "WHEN (SELECT LENGTH(SUBJECT) FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC) > 0 "
+                               "THEN (SELECT SUBJECT FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC) "
+                               "ELSE (SELECT MSG_TEXT FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d AND SCHEDULED_TIME = 0 ORDER BY DISPLAY_TIME DESC) "
+                               "END ELSE '' "
+                               "END, ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE,
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "LAST_MSG_ID = (SELECT MSG_ID FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME DESC) ",
+                               MSGFW_MESSAGE_TABLE_NAME, convId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                               "WHERE CONV_ID = %d;",
+                               convId);
+       } else {
+               memset(sqlQuery, 0x00, MAX_QUERY_LEN);
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "UPDATE %s SET UNREAD_CNT = 0, SMS_CNT = 0, MMS_CNT = 0, MAIN_TYPE = 0, SUB_TYPE = 0, MSG_DIRECTION = 0, DISPLAY_TIME = 0, MSG_TEXT = '' "
+                               "WHERE CONV_ID = %d;",
+                               MSGFW_CONVERSATION_TABLE_NAME, convId);
        }
 
        pDbHandle->finalizeQuery();
 
-       // Update Address Table
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET \
-                       UNREAD_CNT = %d, SMS_CNT = %d, MMS_CNT = %d, MAIN_TYPE = %d, SUB_TYPE = %d, MSG_DIRECTION = %d, DISPLAY_TIME = %ld, MSG_TEXT = ? \
-                       WHERE CONV_ID = %d;", MSGFW_CONVERSATION_TABLE_NAME, unreadCnt, smsCnt, mmsCnt, mainType, subType, direction, msgTime, convId);
-
-       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+       if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("Query Failed [%s]", sqlQuery);
-               return MSG_ERR_DB_PREPARE;
-       }
-
-       pDbHandle->bindText(msgText, 1);
-
-       if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
                pDbHandle->finalizeQuery();
-               MSG_DEBUG("Update Address Info. Fail [%d] [%s]", err, sqlQuery);
-               return MSG_ERR_DB_STEP;
+               return MSG_ERR_DB_EXEC;
        }
 
        pDbHandle->finalizeQuery();
@@ -823,126 +809,91 @@ msg_error_t MsgStoClearConversationTable(MsgDbHandler *pDbHandle)
 }
 
 
-void MsgConvertNumber(const char* pSrcNum, char* pDestNum)
-{
-       int overLen = 0;
-       int i = 0;
-
-       overLen = strlen(pSrcNum) - MAX_PRECONFIG_NUM;
-
-       for (i = 0; i < MAX_PRECONFIG_NUM; i++)
-               pDestNum[i] = pSrcNum[i+overLen];
-
-       pDestNum[i] = '\0';
-}
-
 /* Change the function name to conversation related. */
 bool MsgExistAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t *pConvId)
 {
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
+       unsigned int tmpSize = 0;
 
        *pConvId = 0;
 
-       if(pMsg->nAddressCnt == 1) {
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT CONV_ID FROM ( SELECT CONV_ID FROM %s WHERE ( ",
+                       MSGFW_ADDRESS_TABLE_NAME);
 
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "SELECT CONV_ID FROM (SELECT B.CONV_ID FROM %s A, %s B WHERE A.ADDRESS_VAL = '%s' AND A.CONV_ID=B.CONV_ID) GROUP BY CONV_ID HAVING COUNT(CONV_ID)=1;",
-                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList[0].addressVal);
+       for (int i = 0; i < pMsg->nAddressCnt; i++) {
+               if (strlen(pMsg->addressList[i].addressVal) >= (unsigned int)MsgContactGetMinMatchDigit()
+                               && pMsg->addressList[i].addressType != MSG_ADDRESS_TYPE_EMAIL
+                               && MsgIsNumber(pMsg->addressList[i].addressVal)) {
+                       int addrSize = strlen(pMsg->addressList[i].addressVal);
+                       char newPhoneNum[addrSize+1];
+                       memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+                       MsgConvertNumber(pMsg->addressList[i].addressVal, newPhoneNum, addrSize);
 
-               int rowCnt = 0;
-               msg_thread_id_t convId = 0;
-               err = pDbHandle->getTable(sqlQuery, &rowCnt);
+                       tmpSize = strlen(sqlQuery);
+                       snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                                       "ADDRESS_VAL LIKE '%%%%%s' ",
+                                       newPhoneNum);
 
-               /* No record or other error */
-               if (err != MSG_SUCCESS) {
-                       MSG_DEBUG("Query Failed [%s]", sqlQuery);
-                       pDbHandle->freeTable();
-                       return false;
-               }
+                       if ((pMsg->nAddressCnt-1) == i) break;
 
-               if(rowCnt > 0) {
-                       convId = pDbHandle->getColumnToInt(1);
+                       tmpSize = strlen(sqlQuery);
+                       snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize, " OR ");
 
-                       MSG_DEBUG("CONV_ID : [%d]", convId);
+               } else {
 
-                       if (convId > 0) {
-                               *pConvId = convId;
-                               pDbHandle->freeTable();
-                               return true;
-                       } else {
-                               pDbHandle->freeTable();
-                               return false;
-                       }
-               }
+                       tmpSize = strlen(sqlQuery);
+                       snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                                       "ADDRESS_VAL LIKE '%s' ",
+                                       pMsg->addressList[i].addressVal);
 
-       } else { /* multiple address */
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                       if ((pMsg->nAddressCnt-1) == i) break;
 
-               snprintf(sqlQuery, sizeof(sqlQuery),
-                               "SELECT CONV_ID FROM (SELECT B.CONV_ID FROM %s A, %s B WHERE A.ADDRESS_VAL = '%s' AND A.CONV_ID=B.CONV_ID) GROUP BY CONV_ID HAVING COUNT(CONV_ID)=%d;",
-                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList[0].addressVal, pMsg->nAddressCnt);
+                       tmpSize = strlen(sqlQuery);
+                       snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize, " OR ");
 
-               int rowCnt = 0;
-               int convId = 0;
+               }
+       }
 
-               MSG_DEBUG("Query [%s]", sqlQuery);
+       tmpSize = strlen(sqlQuery);
+       snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                       ") AND CONV_ID IN (SELECT CONV_ID FROM %s GROUP BY CONV_ID HAVING COUNT(CONV_ID)=%d) ",
+                       MSGFW_ADDRESS_TABLE_NAME, pMsg->nAddressCnt);
 
-               err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
-               /* No record or other error */
-               if (err != MSG_SUCCESS) {
-                       MSG_DEBUG("Query Failed [%s]", sqlQuery);
-                       pDbHandle->freeTable();
-                       return false;
-               }
+       tmpSize = strlen(sqlQuery);
+       snprintf(sqlQuery+tmpSize, MAX_QUERY_LEN-tmpSize,
+                       ") GROUP BY CONV_ID HAVING COUNT(CONV_ID)=%d;",
+                       pMsg->nAddressCnt);
 
-               for (int i = 1; i <= rowCnt; i++) {
-                       convId = pDbHandle->getColumnToInt(i);
+       int rowCnt = 0;
+       int convId = 0;
 
-                       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
-                       snprintf(sqlQuery, sizeof(sqlQuery),
-                                       "SELECT COUNT(*) FROM %s WHERE CONV_ID=%d AND (",
-                                       MSGFW_ADDRESS_TABLE_NAME, convId);
+       /* No record or other error */
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               pDbHandle->freeTable();
+               return false;
+       }
 
-                       for (int j = 0; j<(pMsg->nAddressCnt); j++ ) {
+       convId = pDbHandle->getColumnToInt(1);
 
-                               if (j!=0)
-                                       strncat(sqlQuery, "OR ", MAX_QUERY_LEN-strlen(sqlQuery));
+       if (convId > 0) {
+               MSG_DEBUG("Success  to get convId [%d]", convId);
+               *pConvId = convId;
+               pDbHandle->freeTable();
+               return true;
+       }
 
-                               strncat(sqlQuery, "ADDRESS_VAL = '", MAX_QUERY_LEN-strlen(sqlQuery));
+       pDbHandle->freeTable();
 
-                               strncat(sqlQuery, pMsg->addressList[j].addressVal, MAX_QUERY_LEN-strlen(sqlQuery));
-
-                               strncat(sqlQuery, "' ", MAX_QUERY_LEN-strlen(sqlQuery));
-                       }
-                       strncat(sqlQuery, ");", MAX_QUERY_LEN-strlen(sqlQuery));
-                       MSG_DEBUG("Query [%s]", sqlQuery);
-                       if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                               MSG_DEBUG("Query Failed [%s]", sqlQuery);
-                               pDbHandle->freeTable();
-                               pDbHandle->finalizeQuery();
-                               return false;
-                       }
-
-                       if (pDbHandle->stepQuery() == MSG_ERR_DB_ROW) {
-                               if (pMsg->nAddressCnt == pDbHandle->columnInt(0)) {
-                                       *pConvId = convId;
-                                       pDbHandle->finalizeQuery();
-                                       pDbHandle->freeTable();
-                                       return true;
-                               }
-                       }
-                       pDbHandle->finalizeQuery();
-               }
-               pDbHandle->freeTable();
-       }
-
-       return false;
-}
+       return false;
+}
 
 
 int MsgStoGetUnreadCnt(MsgDbHandler *pDbHandle, MSG_MAIN_TYPE_T msgType)
@@ -954,13 +905,23 @@ int MsgStoGetUnreadCnt(MsgDbHandler *pDbHandle, MSG_MAIN_TYPE_T msgType)
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
        if (msgType == MSG_SMS_TYPE) {
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s \
-                               WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d, %d, %d, %d, %d) AND FOLDER_ID = %d AND READ_STATUS = 0;",
-                               MSGFW_MESSAGE_TABLE_NAME, MSG_SMS_TYPE, MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS, MSG_MWI_VOICE_SMS, MSG_SYNCML_CP, MSG_INBOX_ID);
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s "
+                               "WHERE MAIN_TYPE = %d "
+                               "AND (SUB_TYPE IN (%d, %d, %d, %d, %d, %d, %d) OR (SUB_TYPE >= %d AND SUB_TYPE <= %d)) "
+                               "AND FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               MSG_SMS_TYPE,
+                               MSG_NORMAL_SMS, MSG_STATUS_REPORT_SMS, MSG_CONCAT_SIM_SMS, MSG_WAP_SI_SMS, MSG_WAP_SL_SMS, MSG_MWI_VOICE_SMS, MSG_SYNCML_CP,
+                               MSG_REPLACE_TYPE1_SMS, MSG_REPLACE_TYPE7_SMS,
+                               MSG_INBOX_ID, MSG_STORAGE_PHONE);
        } else if (msgType == MSG_MMS_TYPE) {
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s \
-                               WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d) AND FOLDER_ID = %d AND READ_STATUS = 0;",
-                               MSGFW_MESSAGE_TABLE_NAME, MSG_MMS_TYPE, MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS, MSG_NOTIFICATIONIND_MMS, MSG_INBOX_ID);
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(MSG_ID) FROM %s "
+                               "WHERE MAIN_TYPE = %d AND SUB_TYPE IN (%d, %d, %d) "
+                               "AND FOLDER_ID = %d AND READ_STATUS = 0 AND STORAGE_ID = %d;",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               MSG_MMS_TYPE,
+                               MSG_RETRIEVE_AUTOCONF_MMS, MSG_RETRIEVE_MANUALCONF_MMS, MSG_NOTIFICATIONIND_MMS,
+                               MSG_INBOX_ID, MSG_STORAGE_PHONE);
        }
 
        if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
@@ -981,26 +942,61 @@ int MsgStoGetUnreadCnt(MsgDbHandler *pDbHandle, MSG_MAIN_TYPE_T msgType)
 
 msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber)
 {
+
+       if (pDbHandle == NULL || pContactInfo == NULL || pNumber == NULL) {
+               MSG_DEBUG("pDbHandle == NULL || pContactInfo == NULL || pNumber == NULL");
+               return  MSG_ERR_NULL_POINTER;
+       }
+
        char sqlQuery[MAX_QUERY_LEN+1];
+       char displayName[MAX_DISPLAY_NAME_LEN+1];
+       memset(displayName, 0x00, sizeof(displayName));
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
-                       "CONTACT_ID = %d, "
-                       "DISPLAY_NAME = ?, "
-                       "FIRST_NAME = ?, "
-                       "LAST_NAME = ?, "
-                       "IMAGE_PATH = '%s' "
-                       "WHERE ADDRESS_VAL = '%s';",
-                       MSGFW_ADDRESS_TABLE_NAME, pContactInfo->contactId, pContactInfo->imagePath, pNumber);
+       if (strlen(pNumber) > (unsigned int)MsgContactGetMinMatchDigit()) {
+               int addrSize = strlen(pNumber);
+               char newPhoneNum[addrSize+1];
+               memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+               MsgConvertNumber(pNumber, newPhoneNum, addrSize);
+
+               MSG_DEBUG("Phone Number to Compare : [%s]", newPhoneNum);
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
+                               "CONTACT_ID = %d, "
+                               "ADDR_BOOK_ID = %d, "
+                               "FIRST_NAME = ?, "
+                               "LAST_NAME = ?, "
+                               "MIDDLE_NAME = ?, "
+                               "PREFIX = ?, "
+                               "SUFFIX = ?, "
+                               "IMAGE_PATH = '%s' "
+                               "WHERE ADDRESS_VAL LIKE '%%%%%s';",
+                               MSGFW_ADDRESS_TABLE_NAME, pContactInfo->contactId, pContactInfo->addrbookId, pContactInfo->imagePath, newPhoneNum);
+       } else {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
+                               "CONTACT_ID = %d, "
+                               "ADDR_BOOK_ID = %d, "
+                               "FIRST_NAME = ?, "
+                               "LAST_NAME = ?, "
+                               "MIDDLE_NAME = ?, "
+                               "PREFIX = ?, "
+                               "SUFFIX = ?, "
+                               "IMAGE_PATH = '%s' "
+                               "WHERE ADDRESS_VAL = '%s';",
+                               MSGFW_ADDRESS_TABLE_NAME, pContactInfo->contactId, pContactInfo->addrbookId, pContactInfo->imagePath, pNumber);
+       }
 
        if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
                MSG_DEBUG("sqlQuery [%s]", sqlQuery);
                return MSG_ERR_DB_PREPARE;
        }
 
-       pDbHandle->bindText(pContactInfo->displayName, 1);
-       pDbHandle->bindText(pContactInfo->firstName, 2);
-       pDbHandle->bindText(pContactInfo->lastName, 3);
+       pDbHandle->bindText(pContactInfo->firstName, 1);
+       pDbHandle->bindText(pContactInfo->lastName, 2);
+       pDbHandle->bindText(pContactInfo->middleName, 3);
+       pDbHandle->bindText(pContactInfo->prefix, 4);
+       pDbHandle->bindText(pContactInfo->suffix, 5);
 
        if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
                pDbHandle->finalizeQuery();
@@ -1014,79 +1010,158 @@ msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pC
 }
 
 
-msg_error_t MsgStoResetContactInfo(MsgDbHandler *pDbHandle, int contactId)
+msg_error_t MsgStoClearContactInfoByAddrbookIdList(MsgDbHandler *pDbHandle, int* addrbookList, int addrbookCnt)
 {
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
        int rowCnt = 0;
-       int index = 2;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_VAL, CONV_ID FROM %s WHERE CONTACT_ID = %d;",
-                       MSGFW_ADDRESS_TABLE_NAME, contactId);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONTACT_ID) FROM %s WHERE ADDR_BOOK_ID NOT IN ( ", MSGFW_ADDRESS_TABLE_NAME);
+
+       for (int i=0; i<(addrbookCnt-1); i++) {
+               snprintf(sqlQuery+strlen(sqlQuery), sizeof(sqlQuery)-strlen(sqlQuery), "%d, ", addrbookList[i]);
+       }
+
+       snprintf(sqlQuery+strlen(sqlQuery), sizeof(sqlQuery)-strlen(sqlQuery), "%d );", addrbookList[addrbookCnt-1]);
 
        err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS) {
                pDbHandle->freeTable();
-               MSG_DEBUG("[Error]Failed to Get Table");
+               MSG_DEBUG("Fail to getTable().");
                return err;
        }
 
        MsgDbHandler tmpDbHandle;
-       for (int i=0; i<rowCnt; i++) {
+       for (int i=1; i<=rowCnt; i++)
+               MsgStoClearContactInfo(&tmpDbHandle, pDbHandle->getColumnToInt(i));
 
-               MSG_CONTACT_INFO_S contactInfo;
-               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
-               MSG_ADDRESS_INFO_S addrInfo;
-               memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+       pDbHandle->freeTable();
 
-               pDbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, addrInfo.addressVal);
+       return err;
+}
 
-               MsgGetContactInfo(&addrInfo, &contactInfo);
-               MsgStoAddContactInfo(&tmpDbHandle, &contactInfo, addrInfo.addressVal);
 
-               MsgStoSetConversationDisplayName(&tmpDbHandle, (msg_thread_id_t)pDbHandle->getColumnToInt(index++));
+msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int contactId)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       int rowCnt = 0;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE CONTACT_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME, contactId);
+
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err != MSG_SUCCESS) {
+               pDbHandle->freeTable();
+               MSG_DEBUG("[Error]Failed to Get Table");
+               return err;
+       }
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
+                       "CONTACT_ID = 0, "
+                       "ADDR_BOOK_ID = 0, "
+                       "FIRST_NAME = '', "
+                       "LAST_NAME = '', "
+                       "MIDDLE_NAME = '', "
+                       "PREFIX = '', "
+                       "SUFFIX = '', "
+                       "IMAGE_PATH = '' "
+                       "WHERE CONTACT_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME,
+                       contactId);
+
+       if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               pDbHandle->freeTable();
+               MSG_DEBUG("Fail to execute query");
+               return MSG_ERR_DB_EXEC;
        }
 
+       MsgDbHandler tmpDbHandle;
+       for (int i=1; i<=rowCnt; i++)
+               MsgStoSetConversationDisplayName(&tmpDbHandle, (msg_thread_id_t)pDbHandle->getColumnToInt(i));
+
        pDbHandle->freeTable();
 
        return err;
 }
 
 
-msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int contactId, const char *pNumber)
+msg_error_t MsgStoResetContactInfo(MsgDbHandler *pDbHandle, int contactId)
 {
-       char newPhoneNum[MAX_PRECONFIG_NUM+1];
+       msg_error_t err = MSG_SUCCESS;
+
        char sqlQuery[MAX_QUERY_LEN+1];
+       int rowCnt = 0;
+       int index = 2;
 
-       memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       if (strlen(pNumber) > MAX_PRECONFIG_NUM) {
-               MsgConvertNumber(pNumber, newPhoneNum);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_VAL, CONV_ID FROM %s WHERE CONTACT_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME, contactId);
 
-               MSG_DEBUG("Phone Number to Compare : [%s]", newPhoneNum);
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
 
-               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET \
-                               CONTACT_ID = 0, DISPLAY_NAME = '', FIRST_NAME = '', LAST_NAME = '', IMAGE_PATH = '' \
-                               WHERE CONTACT_ID = %d AND ADDRESS_VAL NOT LIKE '%%%s';",
-                               MSGFW_ADDRESS_TABLE_NAME, contactId, newPhoneNum);
-       } else {
-               snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET \
-                               CONTACT_ID = 0, DISPLAY_NAME = '', FIRST_NAME = '', LAST_NAME = '', IMAGE_PATH = '' \
-                               WHERE CONTACT_ID = %d AND ADDRESS_VAL <> '%s';",
-                               MSGFW_ADDRESS_TABLE_NAME, contactId, pNumber);
+       if (err != MSG_SUCCESS) {
+               pDbHandle->freeTable();
+               MSG_DEBUG("[Error]Failed to Get Table");
+               return err;
        }
 
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
+                       "CONTACT_ID = 0, "
+                       "ADDR_BOOK_ID = 0, "
+                       "FIRST_NAME = '', "
+                       "LAST_NAME = '', "
+                       "MIDDLE_NAME = '', "
+                       "PREFIX = '', "
+                       "SUFFIX = '', "
+                       "IMAGE_PATH = '' "
+                       "WHERE CONTACT_ID = %d;",
+                       MSGFW_ADDRESS_TABLE_NAME,
+                       contactId);
+
        if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               pDbHandle->freeTable();
                MSG_DEBUG("Fail to execute query");
                return MSG_ERR_DB_EXEC;
        }
 
-       return MSG_SUCCESS;
+       MsgDbHandler tmpDbHandle;
+       for (int i=0; i<rowCnt; i++) {
+
+               char *strNumber = pDbHandle->getColumnToString(index++);
+               MSG_CONTACT_INFO_S contactInfo;
+               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+
+               if (strNumber != NULL) {
+                       MSG_DEBUG("Number [%s]", strNumber);
+
+                       MSG_ADDRESS_INFO_S addrInfo;
+                       memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+                       strncpy(addrInfo.addressVal, strNumber, MAX_ADDRESS_VAL_LEN);
+
+                       if(MsgGetContactInfo(&addrInfo, &contactInfo) == MSG_SUCCESS) {
+                               if (!MsgInsertContact(&contactInfo, strNumber))
+                                       MSG_DEBUG("MsgInsertContact fail.");
+                       }
+               }
+
+               MsgStoSetConversationDisplayName(&tmpDbHandle, (msg_thread_id_t)pDbHandle->getColumnToInt(index++));
+       }
+
+       pDbHandle->freeTable();
+
+       return err;
 }
 
 
@@ -1194,13 +1269,14 @@ msg_error_t MsgStoAddConversation(MsgDbHandler *pDbHandle, msg_thread_id_t *pCon
 {
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       if (pDbHandle->getRowId(MSGFW_CONVERSATION_TABLE_NAME, pConvId) != MSG_SUCCESS) {
-               return MSG_ERR_DB_EXEC;
+       if(*pConvId == 0) {
+               if (pDbHandle->getRowId(MSGFW_CONVERSATION_TABLE_NAME, pConvId) != MSG_SUCCESS) {
+                       return MSG_ERR_DB_EXEC;
+               }
        }
-
        // Add Conversation
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 0, 0, 0, 0, 0, 0, 0, '', '');",
+       snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0);",
                        MSGFW_CONVERSATION_TABLE_NAME, *pConvId);
 
        if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
@@ -1229,7 +1305,7 @@ msg_error_t MsgStoSetConversationDisplayName(MsgDbHandler *pDbHandle, int contac
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
                pDbHandle->freeTable();
-               MSG_DEBUG("Query Failed [%s]", sqlQuery);
+               MSG_DEBUG("Fail to getTable().");
                return err;
        }
 
@@ -1263,6 +1339,7 @@ msg_error_t MsgStoSetConversationDisplayName(MsgDbHandler *pDbHandle, int contac
                                MSGFW_CONVERSATION_TABLE_NAME, pDbHandle->getColumnToInt(i));
 
                if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       pDbHandle->freeTable();
                        MSG_DEBUG("Query Failed [%s]", sqlQuery);
                        return MSG_ERR_DB_PREPARE;
                }
@@ -1270,19 +1347,23 @@ msg_error_t MsgStoSetConversationDisplayName(MsgDbHandler *pDbHandle, int contac
                pDbHandle->bindText(displayName, 1);
 
                if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                       pDbHandle->freeTable();
                        pDbHandle->finalizeQuery();
-                       MSG_DEBUG("Update Conversation disply name. Fail [%s]", sqlQuery);
+                       MSG_SEC_DEBUG("Update Conversation disply name. Fail [%s]", sqlQuery);
                        return MSG_ERR_DB_STEP;
                }
 
                pDbHandle->finalizeQuery();
 
                // free address list
-               for(int j = 0; j < MAX_TO_ADDRESS_CNT; j++){
+               for (int j = 0; j < addressList.nCount; j++) {
                        msg_struct_s *pStruct = (msg_struct_s *)addressList.msg_struct_info[j];
                        delete [] (MSG_ADDRESS_INFO_S *)pStruct->data;
                        delete [] (msg_struct_s *)pStruct;
                }
+               if (addressList.msg_struct_info != NULL) {
+                       delete [] (msg_struct_t *)addressList.msg_struct_info;
+               }
        }
 
        pDbHandle->freeTable();
@@ -1335,17 +1416,20 @@ msg_error_t MsgStoSetConversationDisplayName(MsgDbHandler *pDbHandle, msg_thread
 
        if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
                pDbHandle->finalizeQuery();
-               MSG_DEBUG("Update Conversation disply name. Fail [%s]", sqlQuery);
+               MSG_SEC_DEBUG("Update Conversation disply name. Fail [%s]", sqlQuery);
                return MSG_ERR_DB_STEP;
        }
 
        pDbHandle->finalizeQuery();
 
-       for(int j = 0; j < MAX_TO_ADDRESS_CNT; j++){
+       for (int j = 0; j < addressList.nCount; j++) {
                msg_struct_s *pStruct = (msg_struct_s *)addressList.msg_struct_info[j];
                delete [] (MSG_ADDRESS_INFO_S *)pStruct->data;
                delete [] (msg_struct_s *)pStruct;
        }
+       if (addressList.msg_struct_info != NULL) {
+               delete [] (msg_struct_t *)addressList.msg_struct_info;
+       }
 
        return err;
 }
@@ -1364,84 +1448,1831 @@ msg_error_t MsgStoUpdateNetworkStatus(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_
        if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS)
                err = MSG_ERR_DB_EXEC;
 
+       pDbHandle->finalizeQuery();
+
        return err;
 }
 
-char *MsgStoReplaceString(const char *origStr, const char *oldStr, const char *newStr)
+bool MsgExistConversation(MsgDbHandler *pDbHandle, msg_thread_id_t convId)
 {
-       if (origStr == NULL)
-               return NULL;
-
-       char *replaceStr = NULL;
-       char *pTemp = NULL;
-       int i = 0;
-       int matchedCnt = 0;
-       int oldStrLen = 0;
-       int newStrLen = 0;
-
-       if (g_strcmp0(oldStr, newStr) != 0) {
-               oldStrLen = strlen(oldStr);
-               newStrLen = strlen(newStr);
-
-               for (i = 0; origStr[i] != '\0';) {
-                       if (memcmp(&origStr[i], oldStr, oldStrLen) == 0) {
-                               matchedCnt++;
-                               i += oldStrLen;
-                       } else {
-                               i++;
-                       }
-               }
-       } else {
-               return g_strdup(origStr);
+       msg_error_t err = MSG_SUCCESS;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       int rowCnt = 0;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID FROM %s WHERE CONV_ID = %d;",
+                       MSGFW_CONVERSATION_TABLE_NAME, convId);
+
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               pDbHandle->freeTable();
+               return false;
        }
+       else if ( err != MSG_SUCCESS) {
+               pDbHandle->freeTable();
+               return false;
+       }
+       pDbHandle->freeTable();
+
+       return true;
+}
+
+bool MsgExistMessage(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsg)
+{
+       msg_error_t err = MSG_SUCCESS;
 
-       replaceStr = (char *)calloc(1, i + sizeof(char) * (matchedCnt * (newStrLen - oldStrLen) + 1));
-       if (replaceStr == NULL)
-               return NULL;
+       char sqlQuery[MAX_QUERY_LEN+1];
 
-       pTemp = replaceStr;
 
-       while (*origStr) {
-               if (memcmp(origStr, oldStr, oldStrLen) == 0) {
-                       memcpy(pTemp, newStr, newStrLen);
-                       pTemp += newStrLen;
-                       origStr += oldStrLen;
-               } else {
-                       *pTemp++ = *origStr++;
-               }
+       int rowCnt = 0;
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE CONV_ID = %ud AND DISPLAY_TIME = %ud;",
+                       MSGFW_MESSAGE_TABLE_NAME, pMsg->threadId, (int)pMsg->displayTime);
+
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+
+       if ( err != MSG_SUCCESS) {
+               pDbHandle->freeTable();
+               return false;
        }
 
-       return replaceStr;
+       if(rowCnt > 0) {
+               pMsg->msgId = pDbHandle->getColumnToInt(1);
+       }
+       pDbHandle->freeTable();
+
+       return true;
 }
 
 
-msg_error_t MsgStoRefreshConversationDisplayName()
+bool MsgExistAddress(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsg,  msg_thread_id_t convId, int index)
 {
        msg_error_t err = MSG_SUCCESS;
-       MsgDbHandler dbHandle;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+
        int rowCnt = 0;
-       char displayName[MAX_DISPLAY_NAME_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       if (strlen(pMsg->addressList[index].addressVal) > (unsigned int)MsgContactGetMinMatchDigit()) {
+               int addrSize = strlen(pMsg->addressList[index].addressVal);
+               char newPhoneNum[addrSize+1];
+               memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+               MsgConvertNumber(pMsg->addressList[index].addressVal, newPhoneNum, addrSize);
+
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT ADDRESS_ID FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s' AND CONV_ID= %d;",
+                               MSGFW_ADDRESS_TABLE_NAME, newPhoneNum, convId);
+       } else {
+
+               snprintf(sqlQuery, sizeof(sqlQuery),
+                               "SELECT ADDRESS_ID FROM %s WHERE ADDRESS_VAL = '%s' AND CONV_ID= %d;",
+                               MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList[index].addressVal, convId);
+       }
+
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               pDbHandle->freeTable();
+               return false;
+       }
+       else if ( err != MSG_SUCCESS) {
+               pDbHandle->freeTable();
+               return false;
+       }
+       pDbHandle->freeTable();
+
+       return true;
+}
+
+
+void MsgStoUpdateAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, msg_thread_id_t convId)
+{
+       MSG_BEGIN();
+       msg_error_t err = MSG_SUCCESS;
+
        char sqlQuery[MAX_QUERY_LEN+1];
 
+       for (int i = 0; i < pMsg->nAddressCnt; i++) {
+                       if (strlen(pMsg->addressList[i].addressVal) > (unsigned int)MsgContactGetMinMatchDigit() && pMsg->addressList[i].addressType == MSG_ADDRESS_TYPE_PLMN) {
+                               int addrSize = strlen(pMsg->addressList[i].addressVal);
+                               char newPhoneNum[addrSize+1];
+                               memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+                               MsgConvertNumber(pMsg->addressList[i].addressVal, newPhoneNum, addrSize);
+
+                               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+                               snprintf(sqlQuery, sizeof(sqlQuery),
+                                               "UPDATE %s SET "
+                                               "ADDRESS_VAL = '%s' "
+                                               "WHERE CONV_ID = %d "
+                                               "AND ADDRESS_VAL LIKE '%%%%%s';",
+                                               MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList[i].addressVal, convId, newPhoneNum);
+
+                               err = pDbHandle->execQuery(sqlQuery);
+                               if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery(). [%s]", sqlQuery);
+
+                               pDbHandle->finalizeQuery();
+                       }
+       }
+
+       MSG_END();
+}
+
+
+msg_error_t MsgStoAddCBChannelInfo(MsgDbHandler *pDbHandle, MSG_CB_CHANNEL_S *pCBChannel, msg_sim_slot_id_t simIndex)
+{
+       MSG_BEGIN();
+
+       char sqlQuery[MAX_QUERY_LEN] = {0,};
+
+       pDbHandle->beginTrans();
+
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery),
-                       "SELECT DISTINCT(CONTACT_ID) FROM %s;",
-                       MSGFW_ADDRESS_TABLE_NAME);
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE SIM_INDEX = %d;", MSGFW_CB_CHANNEL_INFO_TABLE_NAME, simIndex);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               pDbHandle->endTrans(false);
+               return MSG_ERR_DB_EXEC;
+       }
 
-       if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               dbHandle.freeTable();
-               MSG_DEBUG("Query Failed [%s]", sqlQuery);
-               return err;
+       for (int i = 0; i < pCBChannel->channelCnt; i++) {
+               int index = 1;
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s(CHANNEL_ACTIVATION, CHANNEL_FROM, CHANNEL_TO, CHANNEL_NAME, SIM_INDEX) VALUES (?, ?, ?, ?, ?);",
+                               MSGFW_CB_CHANNEL_INFO_TABLE_NAME);
+
+               if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       pDbHandle->endTrans(false);
+                       return MSG_ERR_DB_PREPARE;
+               }
+               pDbHandle->bindInt(pCBChannel->channelInfo[i].bActivate, index++);
+               pDbHandle->bindInt(pCBChannel->channelInfo[i].from, index++);
+               pDbHandle->bindInt(pCBChannel->channelInfo[i].to, index++);
+               pDbHandle->bindText(pCBChannel->channelInfo[i].name, index++);
+               pDbHandle->bindInt(simIndex, index++);
+
+               if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                       pDbHandle->finalizeQuery();
+                       pDbHandle->endTrans(false);
+                       return MSG_ERR_DB_STEP;
+               }
+
+               pDbHandle->finalizeQuery();
        }
 
-       for (int i = 1; i <= rowCnt; i++)
-       {
-               MsgUpdateContact(dbHandle.getColumnToInt(i), -1);
+       pDbHandle->endTrans(true);
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoGetCBChannelInfo(MsgDbHandler *pDbHandle, MSG_CB_CHANNEL_S *pCBChannel, msg_sim_slot_id_t simIndex)
+{
+       MSG_BEGIN();
+
+       int rowCnt = 0;
+       int index = 4;
+       char sqlQuery[MAX_QUERY_LEN] = {0,};
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CHANNEL_ACTIVATION, CHANNEL_FROM, CHANNEL_TO, CHANNEL_NAME FROM %s WHERE SIM_INDEX = %d;", MSGFW_CB_CHANNEL_INFO_TABLE_NAME, simIndex);
+
+       msg_error_t err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+       pCBChannel->channelCnt = rowCnt;
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               pDbHandle->freeTable();
+               return MSG_ERR_DB_NORECORD;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               pDbHandle->freeTable();
+               return MSG_ERR_DB_GETTABLE;
        }
 
-       dbHandle.freeTable();
+       for (int i = 0; i < rowCnt; i++) {
+               pCBChannel->channelInfo[i].bActivate = pDbHandle->getColumnToInt(index++);
+               pCBChannel->channelInfo[i].from  = pDbHandle->getColumnToInt(index++);
+               pCBChannel->channelInfo[i].to = pDbHandle->getColumnToInt(index++);
+               pDbHandle->getColumnToString(index++, CB_CHANNEL_NAME_MAX, pCBChannel->channelInfo[i].name);
+
+               MSG_DEBUG("CH_ACT = %d", pCBChannel->channelInfo[i].bActivate);
+               MSG_DEBUG("CH_FROM = %d", pCBChannel->channelInfo[i].from);
+               MSG_DEBUG("CH_TO = %d", pCBChannel->channelInfo[i].to);
+               MSG_DEBUG("CH_NAME = %s", pCBChannel->channelInfo[i].name);
+       }
 
-       return err;
+       pDbHandle->freeTable();
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+// Lists
+msg_error_t MsgStoGetFolderViewList(msg_folder_id_t folderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList)
+{
+       if (pMsgFolderViewList == NULL) {
+               MSG_DEBUG("pMsgFolderViewList is NULL");
+               return MSG_ERR_NULL_POINTER;
+       }
+
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       int rowCnt = 0;
+       int index = 19; // numbers of index
+
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       char sqlSort[64];
+
+       // Get Name Order
+       int order = MsgGetContactNameOrder();
+
+       // Get Message In Folder
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       if (folderId == MSG_ALLBOX_ID) {
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
+                               DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, BACKUP, PRIORITY, \
+                               MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, THUMB_PATH \
+                               FROM %s WHERE FOLDER_ID < %d ",
+                               MSGFW_MESSAGE_TABLE_NAME, MSG_SPAMBOX_ID);
+       } else {
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
+                               DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, BACKUP, PRIORITY, \
+                               MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, THUMB_PATH \
+                               FROM %s WHERE FOLDER_ID = %d ",
+                               MSGFW_MESSAGE_TABLE_NAME, folderId);
+       }
+
+       memset(sqlSort, 0x00, sizeof(sqlSort));
+       MsgMakeSortRule(pSortRule, sqlSort);
+       strncat(sqlQuery, sqlSort, strlen(sqlSort));
+
+       msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               pMsgFolderViewList->nCount = 0;
+               pMsgFolderViewList->msg_struct_info = NULL;
+
+               dbHandle->freeTable();
+
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
+       }
+
+       pMsgFolderViewList->nCount = rowCnt;
+
+       MSG_DEBUG("pMsgCommInfoList->nCount [%d]", pMsgFolderViewList->nCount);
+
+       pMsgFolderViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
+
+       msg_struct_s *msg = NULL;
+       MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               pMsgFolderViewList->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];;
+
+               msg = (msg_struct_s *)pMsgFolderViewList->msg_struct_info[i];
+
+               msg->type = MSG_STRUCT_MESSAGE_INFO;
+               msg->data = new char[sizeof(MSG_MESSAGE_HIDDEN_S)];
+
+               pTmp = (MSG_MESSAGE_HIDDEN_S *)msg->data;
+
+               pTmp->pData = NULL;
+               pTmp->pMmsData = NULL;
+               pTmp->addressList = NULL;
+
+               pTmp->msgId = dbHandle->getColumnToInt(index++);
+               pTmp->threadId = dbHandle->getColumnToInt(index++);
+               pTmp->folderId = dbHandle->getColumnToInt(index++);
+               pTmp->storageId = dbHandle->getColumnToInt(index++);
+               pTmp->mainType = dbHandle->getColumnToInt(index++);
+               pTmp->subType = dbHandle->getColumnToInt(index++);
+               pTmp->displayTime = (time_t)dbHandle->getColumnToInt(index++);
+               pTmp->dataSize = dbHandle->getColumnToInt(index++);
+               pTmp->networkStatus = dbHandle->getColumnToInt(index++);
+               pTmp->bRead = dbHandle->getColumnToInt(index++);
+               pTmp->bProtected = dbHandle->getColumnToInt(index++);
+               pTmp->bBackup = dbHandle->getColumnToInt(index++);
+               pTmp->priority = dbHandle->getColumnToInt(index++);
+               pTmp->direction= dbHandle->getColumnToInt(index++);
+
+               index++; // This field is reserved.
+
+               dbHandle->getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
+
+               if (pTmp->mainType == MSG_MMS_TYPE &&
+                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
+                       pTmp->pData = NULL;
+                       index++;
+               } else {
+                       pTmp->pData = (void *)new char[pTmp->dataSize + 2];
+                       memset(pTmp->pData, 0x00, pTmp->dataSize + 2);
+
+                       dbHandle->getColumnToString(index++, pTmp->dataSize+1, (char *)pTmp->pData);
+               }
+
+               // get address information from db.
+               msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
+
+               MsgDbHandler db;
+               MsgStoGetAddressByMsgId(&db, pTmp->msgId, order, addr_list);
+
+               pTmp->addr_list = addr_list;
+
+               // For GList *addressList
+               int nAddressCnt = 0;
+               MSG_ADDRESS_INFO_S *addressList = NULL;
+               MsgStoGetAddressByMsgId(&db, pTmp->msgId, order, &nAddressCnt, &addressList);
+
+               for (int i = 0; i < nAddressCnt; i++) {
+                       msg_struct_s *addr_info_s = NULL;
+                       MSG_ADDRESS_INFO_S *addr_info = NULL;
+
+                       addr_info_s = new msg_struct_s;
+                       memset(addr_info_s, 0x00, sizeof(msg_struct_s));
+
+                       addr_info_s->type = MSG_STRUCT_ADDRESS_INFO;
+                       addr_info_s->data = new MSG_ADDRESS_INFO_S;
+                       memset(addr_info_s->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                       addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
+
+                       addr_info->addressType = addressList[i].addressType;
+                       addr_info->recipientType = addressList[i].recipientType;
+                       addr_info->contactId = addressList[i].contactId;
+                       strncpy(addr_info->addressVal, addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
+                       strncpy(addr_info->displayName, addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
+                       addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
+
+                       pTmp->addressList = g_list_append(pTmp->addressList, addr_info_s);
+               }
+
+               delete [] addressList;
+
+               pTmp->attachCount = dbHandle->getColumnToInt(index++);
+
+               dbHandle->getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pTmp->thumbPath);
+       }
+
+       dbHandle->freeTable();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       pThreadViewList->nCount = 0;
+       pThreadViewList->msg_struct_info = NULL;
+
+       int rowCnt = 0;
+       int index = 21; // numbers of index
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, A.MAIN_TYPE, A.SUB_TYPE, "
+                       "A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
+                       "(COUNT(CASE WHEN B.PROTECTED = 1 THEN 1 END)) AS PROTECTED, "
+                       "(COUNT(CASE WHEN B.FOLDER_ID = %d THEN 1 END)) AS DRAFT, "
+                       "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS FAILED, "
+                       "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENDING, "
+                       "A.TRANSLATION, A.SENDER_LANG, A.RECEIVER_LANG, A.ONLY_RECEIVE, A.INCLUDE_ORGMSG, A.LAST_MSG_ID,A.TAG_TYPE "
+                       "FROM %s A, %s B ON A.SMS_CNT + A.MMS_CNT > 0 AND B.CONV_ID = A.CONV_ID "
+                       "GROUP BY A.CONV_ID ORDER BY A.DISPLAY_TIME DESC;",
+                       MSG_DRAFT_ID,
+                       MSG_NETWORK_SEND_FAIL,
+                       MSG_NETWORK_SENDING,
+                       MSGFW_CONVERSATION_TABLE_NAME,
+                       MSGFW_MESSAGE_TABLE_NAME);
+
+       msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
+       }
+
+       if (rowCnt < 1) {
+               MSG_DEBUG("rowCnt is %d", rowCnt);
+               dbHandle->freeTable();
+               return err;
+       }
+
+       pThreadViewList->nCount = rowCnt;
+
+       MSG_DEBUG("pThreadViewList->nCount [%d]", pThreadViewList->nCount);
+
+       pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*rowCnt];
+
+       MSG_THREAD_VIEW_S *pTmp = NULL;
+       msg_struct_s *thread_t = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               thread_t = (msg_struct_s *)new msg_struct_s;
+               pThreadViewList->msg_struct_info[i] = (msg_struct_t)thread_t;
+
+               thread_t->type = MSG_STRUCT_THREAD_INFO;
+               thread_t->data = new MSG_THREAD_VIEW_S;
+
+               pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
+               memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
+
+               pTmp->threadId = dbHandle->getColumnToInt(index++);
+
+               pTmp->unreadCnt = dbHandle->getColumnToInt(index++);
+               pTmp->smsCnt = dbHandle->getColumnToInt(index++);
+               pTmp->mmsCnt = dbHandle->getColumnToInt(index++);
+
+               pTmp->mainType = dbHandle->getColumnToInt(index++);
+               pTmp->subType = dbHandle->getColumnToInt(index++);
+
+               pTmp->direction = dbHandle->getColumnToInt(index++);
+               pTmp->threadTime = (time_t)dbHandle->getColumnToInt(index++);
+
+               memset(pTmp->threadName, 0x00, sizeof(pTmp->threadName));
+               dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pTmp->threadName);
+
+               memset(pTmp->threadData, 0x00, sizeof(pTmp->threadData));
+               dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pTmp->threadData);
+
+               int protectedCnt = dbHandle->getColumnToInt(index++);
+               if (protectedCnt > 0)
+                       pTmp->bProtected = true;
+
+               int draftCnt = dbHandle->getColumnToInt(index++);
+               if (draftCnt > 0)
+                       pTmp->bDraft = true;
+
+               int failedCnt = dbHandle->getColumnToInt(index++);
+               if (failedCnt > 0)
+                       pTmp->bSendFailed = true;
+
+               int sendingCnt = dbHandle->getColumnToInt(index++);
+               if (sendingCnt > 0)
+                       pTmp->bSending = true;
+
+               pTmp->msgTranslation.bTranslation = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.senderLang = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.receiverLang = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.bOnlyReceive = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.bIncludeOrgMsg = dbHandle->getColumnToInt(index++);
+
+               pTmp->lastMsgId = dbHandle->getColumnToInt(index++);
+               pTmp->tagType = dbHandle->getColumnToInt(index++);
+       }
+
+       dbHandle->freeTable();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoGetConversationPreview(MSG_CONVERSATION_VIEW_S *pConv)
+{
+       MsgDbHandler dbHandleForInner;
+
+       char sqlQuery[MAX_QUERY_LEN + 1];
+       int rowCnt;
+       int index = 3;
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       if (pConv == NULL)
+               return MSG_ERR_NULL_POINTER;
+
+       pConv->tcs_bc_level = -1; //init
+
+       //(MSG_ID INTEGER, TYPE INTEGER, VALUE TEXT, COUNT INTEGER)
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT TYPE, VALUE, COUNT "
+                       "FROM %s WHERE MSG_ID=%d;",
+                       MSGFW_MMS_PREVIEW_TABLE_NAME, pConv->msgId);
+
+       msg_error_t err = dbHandleForInner.getTable(sqlQuery, &rowCnt);
+       if (err == MSG_SUCCESS) {
+               for (int i = 0; i < rowCnt; i++) {
+                       int type = dbHandleForInner.getColumnToInt(index++);
+                       if (type == MSG_MMS_ITEM_TYPE_IMG) {
+                               dbHandleForInner.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pConv->imageThumbPath);
+                               dbHandleForInner.getColumnToInt(index++);
+                       } else if (type == MSG_MMS_ITEM_TYPE_VIDEO) {
+                               dbHandleForInner.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pConv->videoThumbPath);
+                               dbHandleForInner.getColumnToInt(index++);
+                       } else if (type == MSG_MMS_ITEM_TYPE_AUDIO) {
+                               dbHandleForInner.getColumnToString(index++, MSG_FILENAME_LEN_MAX, pConv->audioFileName);
+                               dbHandleForInner.getColumnToInt(index++);
+                       } else if (type == MSG_MMS_ITEM_TYPE_ATTACH) {
+                               dbHandleForInner.getColumnToString(index++, MSG_FILENAME_LEN_MAX, pConv->attachFileName);
+                               pConv->attachCount = dbHandleForInner.getColumnToInt(index++);
+                       } else if (type == MSG_MMS_ITEM_TYPE_PAGE) {
+                               index++;
+                               pConv->pageCount = dbHandleForInner.getColumnToInt(index++);
+                       } else if (type == MSG_MMS_ITEM_TYPE_MALWARE) {
+                               index++;
+                               pConv->tcs_bc_level = dbHandleForInner.getColumnToInt(index++);
+                       } else if (type == MSG_MMS_ITEM_TYPE_1ST_MEDIA) {
+                               dbHandleForInner.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pConv->firstMediaPath);
+                               dbHandleForInner.getColumnToInt(index++);
+                       } else {
+                               MSG_DEBUG("Unknown item type [%d]", type);
+                               index+=2;
+                       }
+               }
+       }
+
+       dbHandleForInner.freeTable();
+       return MSG_SUCCESS;
+}
+
+msg_error_t MsgStoGetConversationMultipart(MSG_CONVERSATION_VIEW_S *pConv)
+{
+       MsgDbHandler dbHandleForInner;
+       char sqlQuery[MAX_QUERY_LEN + 1];
+       int rowCnt;
+       int index = 8;
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       if (pConv == NULL)
+               return MSG_ERR_NULL_POINTER;
+
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT CONTENT_TYPE, NAME, FILE_PATH, CONTENT_ID, CONTENT_LOCATION, TCS_LEVEL, MALWARE_ALLOW, THUMB_FILE_PATH "
+                       "FROM %s WHERE MSG_ID=%d;",
+                       MSGFW_MMS_MULTIPART_TABLE_NAME, pConv->msgId);
+
+       msg_error_t err = dbHandleForInner.getTable(sqlQuery, &rowCnt);
+       if (err == MSG_SUCCESS) {
+               GList *multipart_list = NULL;
+               for (int i = 0; i < rowCnt; i++) {
+
+                       msg_struct_s *multipart_struct_s = new msg_struct_s;
+                       multipart_struct_s->type = MSG_STRUCT_MULTIPART_INFO;
+                       multipart_struct_s->data = new MMS_MULTIPART_DATA_S;
+                       memset(multipart_struct_s->data, 0x00, sizeof(MMS_MULTIPART_DATA_S));
+
+                       MMS_MULTIPART_DATA_S *multipart = (MMS_MULTIPART_DATA_S *)multipart_struct_s->data;
+
+                       dbHandleForInner.getColumnToString(index++, sizeof(multipart->szContentType), multipart->szContentType);
+                       dbHandleForInner.getColumnToString(index++, sizeof(multipart->szFileName), multipart->szFileName);
+                       dbHandleForInner.getColumnToString(index++, sizeof(multipart->szFilePath), multipart->szFilePath);
+                       dbHandleForInner.getColumnToString(index++, sizeof(multipart->szContentID), multipart->szContentID);
+                       dbHandleForInner.getColumnToString(index++, sizeof(multipart->szContentLocation), multipart->szContentLocation);
+
+                       multipart->tcs_bc_level = dbHandleForInner.getColumnToInt(index++);
+                       multipart->malware_allow = dbHandleForInner.getColumnToInt(index++);
+                       dbHandleForInner.getColumnToString(index++, sizeof(multipart->szThumbFilePath), multipart->szThumbFilePath);
+
+                       multipart_list = g_list_append(multipart_list, multipart_struct_s);
+               }
+               pConv->multipart_list = (msg_list_handle_t)multipart_list;
+       }
+
+       dbHandleForInner.freeTable();
+       return MSG_SUCCESS;
+}
+
+msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATION_VIEW_S *pConv)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       int rowCnt = 0;
+       int index = 17; /** numbers of index */
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
+                       DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
+                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, SIM_INDEX\
+                       FROM %s WHERE MSG_ID=%d;",
+                       MSGFW_MESSAGE_TABLE_NAME, msgId);
+
+       msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
+       }
+
+       memset(pConv, 0x00, sizeof(MSG_CONVERSATION_VIEW_S));
+       pConv->pText = NULL;
+
+       pConv->msgId = dbHandle->getColumnToInt(index++);
+       pConv->threadId = dbHandle->getColumnToInt(index++);
+       pConv->folderId = dbHandle->getColumnToInt(index++);
+       pConv->storageId = dbHandle->getColumnToInt(index++);
+       pConv->mainType = dbHandle->getColumnToInt(index++);
+       pConv->subType = dbHandle->getColumnToInt(index++);
+       pConv->displayTime = (time_t)dbHandle->getColumnToInt(index++);
+       pConv->textSize = dbHandle->getColumnToInt(index++);
+       pConv->networkStatus = dbHandle->getColumnToInt(index++);
+       pConv->bRead = dbHandle->getColumnToInt(index++);
+       pConv->bProtected = dbHandle->getColumnToInt(index++);
+       pConv->direction = dbHandle->getColumnToInt(index++);
+       pConv->scheduledTime = (time_t)dbHandle->getColumnToInt(index++);
+
+       dbHandle->getColumnToString(index++, MAX_SUBJECT_LEN, pConv->subject);
+
+       if (pConv->mainType == MSG_MMS_TYPE &&
+               (pConv->networkStatus == MSG_NETWORK_RETRIEVING || pConv->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pConv->subType == MSG_NOTIFICATIONIND_MMS)) {
+               pConv->pText = NULL;
+               pConv->textSize = 0;
+               index++;
+       } else {
+               if (pConv->mainType == MSG_SMS_TYPE) {
+                       pConv->pText = new char[pConv->textSize+2];
+                       memset(pConv->pText, 0x00, pConv->textSize+2);
+                       dbHandle->getColumnToString(index++, pConv->textSize+1, pConv->pText);
+               } else {
+                       char *tmpMmsText = dbHandle->getColumnToString(index++);
+
+                       pConv->textSize = strlen(tmpMmsText);
+
+                       pConv->pText = new char[pConv->textSize+1];
+                       memset(pConv->pText, 0x00, pConv->textSize+1);
+
+                       strncpy(pConv->pText, tmpMmsText, pConv->textSize);
+
+                       MsgStoGetConversationPreview(pConv);
+                       MsgStoGetConversationMultipart(pConv);
+               }
+       }
+
+       //It does Not need to Get attach count in MSG_MESSAGE_TABLE. see MsgStoGetConversationPreview
+       //pConv->attachCount = dbHandle->getColumnToInt(index++);
+       index++;
+       pConv->simIndex = dbHandle->getColumnToInt(index++);
+
+       dbHandle->freeTable();
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoGetConversationViewList(msg_thread_id_t threadId, msg_struct_list_s *pConvViewList)
+{
+       MSG_BEGIN();
+
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       pConvViewList->nCount = 0;
+       pConvViewList->msg_struct_info = NULL;
+
+       int rowCnt = 0;
+       int index = 17; /** numbers of index */
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+#ifdef MSG_NOTI_INTEGRATION
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
+                       DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
+                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT, SIM_INDEX  \
+                       FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME, MSG_ID ASC;",
+                       MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_SPAMBOX_ID, MSG_STORAGE_PHONE);
+#else
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID, CONV_ID, FOLDER_ID, STORAGE_ID, MAIN_TYPE, SUB_TYPE, \
+                       DISPLAY_TIME, DATA_SIZE, NETWORK_STATUS, READ_STATUS, PROTECTED, \
+                       MSG_DIRECTION, SCHEDULED_TIME, SUBJECT, MSG_TEXT, ATTACHMENT_COUNT \
+                       FROM %s WHERE CONV_ID = %d AND FOLDER_ID > %d AND FOLDER_ID < %d AND STORAGE_ID = %d ORDER BY DISPLAY_TIME, MSG_ID ASC;",
+                       MSGFW_MESSAGE_TABLE_NAME, threadId, MSG_ALLBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
+#endif
+
+       msg_error_t err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
+       }
+
+       pConvViewList->nCount = rowCnt;
+
+       MSG_DEBUG("pConvViewList->nCount [%d]", pConvViewList->nCount);
+
+       pConvViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
+       memset(pConvViewList->msg_struct_info, 0x00, sizeof(msg_struct_t) * rowCnt);
+
+       msg_struct_s *conv = NULL;
+       MSG_CONVERSATION_VIEW_S *pTmp = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               pConvViewList->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
+               memset(pConvViewList->msg_struct_info[i], 0x00, sizeof(msg_struct_s));
+
+               conv = (msg_struct_s *)pConvViewList->msg_struct_info[i];
+
+               conv->type = MSG_STRUCT_CONV_INFO;
+               conv->data = new MSG_CONVERSATION_VIEW_S;
+               memset(conv->data, 0x00, sizeof(MSG_CONVERSATION_VIEW_S));
+
+               pTmp = (MSG_CONVERSATION_VIEW_S *)conv->data;
+
+               pTmp->pText = NULL;
+
+               pTmp->msgId = dbHandle->getColumnToInt(index++);
+               pTmp->threadId = dbHandle->getColumnToInt(index++);
+               pTmp->folderId = dbHandle->getColumnToInt(index++);
+               pTmp->storageId = dbHandle->getColumnToInt(index++);
+               pTmp->mainType = dbHandle->getColumnToInt(index++);
+               pTmp->subType = dbHandle->getColumnToInt(index++);
+               pTmp->displayTime = (time_t)dbHandle->getColumnToInt(index++);
+               pTmp->textSize = dbHandle->getColumnToInt(index++);
+               pTmp->networkStatus = dbHandle->getColumnToInt(index++);
+               pTmp->bRead = dbHandle->getColumnToInt(index++);
+               pTmp->bProtected = dbHandle->getColumnToInt(index++);
+               pTmp->direction = dbHandle->getColumnToInt(index++);
+               index++; // This field is reserved.
+
+               dbHandle->getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
+
+               if (pTmp->mainType == MSG_MMS_TYPE &&
+                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
+                       pTmp->pText = NULL;
+                       pTmp->textSize = 0;
+                       index++;
+               } else {
+                       if (pTmp->mainType == MSG_SMS_TYPE) {
+                               pTmp->pText = new char[pTmp->textSize+2];
+                               memset(pTmp->pText, 0x00, pTmp->textSize+2);
+                               dbHandle->getColumnToString(index++, pTmp->textSize+1, pTmp->pText);
+                       } else {
+                               char *tmpMmsText = dbHandle->getColumnToString(index++);
+
+                               if (tmpMmsText) {
+                                       pTmp->textSize = strlen(tmpMmsText);
+
+                                       pTmp->pText = new char[pTmp->textSize+1];
+                                       memset(pTmp->pText, 0x00, pTmp->textSize+1);
+
+                                       strncpy(pTmp->pText, tmpMmsText, pTmp->textSize);
+                               }
+
+                               MsgStoGetConversationPreview(pTmp);
+                               MsgStoGetConversationMultipart(pTmp);
+                       }
+               }
+               //It does Not need to Get attach count in MSG_MESSAGE_TABLE. see MsgStoGetConversationPreview
+               //pTmp->attachCount = dbHandle->getColumnToInt(index++);
+               index++;
+               pTmp->simIndex = dbHandle->getColumnToInt(index++);
+       }
+
+       dbHandle->freeTable();
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
+{
+       if (!pSearchString)
+               return MSG_ERR_NULL_POINTER;
+
+       MsgDbHandler *dbHandle = getDbHandle();
+       char *escapeAddressStr = NULL;
+
+       // Clear Out Parameter
+       pThreadViewList->nCount = 0;
+       pThreadViewList->msg_struct_info = NULL;
+
+       tr1::unordered_set<msg_thread_id_t> IdList;
+       queue<MSG_THREAD_VIEW_S> searchList;
+
+       MSG_THREAD_VIEW_S threadView;
+
+       MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
+       AutoPtr<MSG_ADDRESS_INFO_S> buf(&pAddrInfo);
+       int count = 0;
+
+       // get contact search list
+       if (MsgGetContactSearchList(pSearchString, &pAddrInfo, &count) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgGetContactSearchList fail.");
+               count = 0;
+       }
+       int iteration = (count / ITERATION_SIZE) + 1;
+       int remaining = count;
+
+       for(int itr = 0; itr < iteration ; ++ itr)
+       {
+               int cnt = 0;
+               (remaining > ITERATION_SIZE) ? (cnt = ITERATION_SIZE) : (cnt = remaining);
+
+               unsigned int maxlength = MAX_QUERY_LEN + (MAX_ADDRESS_VAL_LEN * cnt) +1;
+               char sqlQuery[maxlength];
+
+               // Search - Address, Name
+               memset(sqlQuery, 0x00, maxlength);
+               snprintf(sqlQuery, maxlength, "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, A.DISPLAY_NAME, "
+                               "A.MAIN_TYPE, A.SUB_TYPE, A.MSG_DIRECTION, A.DISPLAY_TIME, A.MSG_TEXT, "
+                               "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.PROTECTED = 1) AS PROTECTED, "
+                               "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.FOLDER_ID = %d) AS DRAFT, "
+                               "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS FAILED, "
+                               "(SELECT COUNT(*) FROM %s B WHERE B.CONV_ID = A.CONV_ID AND B.NETWORK_STATUS = %d) AS SENDING, "
+                               "A.TRANSLATION, A.SENDER_LANG, A.RECEIVER_LANG, A.ONLY_RECEIVE, A.INCLUDE_ORGMSG, A.LAST_MSG_ID "
+                               "FROM %s A WHERE (A.SMS_CNT > 0 OR A.MMS_CNT > 0) "
+                               "AND A.CONV_ID IN "
+                               "(SELECT DISTINCT(CONV_ID) FROM %s WHERE "
+                               "ADDRESS_VAL LIKE ? ESCAPE '%c' ",
+                               MSGFW_MESSAGE_TABLE_NAME,
+                               MSGFW_MESSAGE_TABLE_NAME, MSG_DRAFT_ID,
+                               MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SEND_FAIL,
+                               MSGFW_MESSAGE_TABLE_NAME, MSG_NETWORK_SENDING,
+                               MSGFW_CONVERSATION_TABLE_NAME,
+                               MSGFW_ADDRESS_TABLE_NAME,
+                               MSGFW_DB_ESCAPE_CHAR);
+
+               unsigned int tmpSize = 0;
+
+               for (int i = 0; i < cnt; i++) {
+                       int addrSize = strlen(pAddrInfo[itr * ITERATION_SIZE + i].addressVal);
+                       char newPhoneNum[addrSize+1];
+                       memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+
+                       if (addrSize > MsgContactGetMinMatchDigit())
+                               MsgConvertNumber(pAddrInfo[itr * ITERATION_SIZE + i].addressVal, newPhoneNum, addrSize);
+                       else
+                               strncpy(newPhoneNum, pAddrInfo[itr * ITERATION_SIZE + i].addressVal, addrSize);
+
+                       tmpSize = strlen(sqlQuery);
+                       snprintf(sqlQuery+tmpSize, maxlength-tmpSize,
+                                       "OR ADDRESS_VAL LIKE '%%%s' ",
+                                       newPhoneNum);
+
+               }
+               remaining -= cnt;
+               tmpSize = strlen(sqlQuery);
+               snprintf(sqlQuery+tmpSize, maxlength-tmpSize,
+                               ") ORDER BY A.DISPLAY_TIME DESC;");
+               MSG_DEBUG("maxlength: [%d], Query Length: [%d]", maxlength, strlen(sqlQuery));
+               MSG_DEBUG("[%s]", sqlQuery);
+
+               if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+                       MSG_DEBUG("Prepare query fail.");
+                       return MSG_ERR_DB_PREPARE;
+               }
+
+               MsgConvertStrWithEscape(pSearchString, &escapeAddressStr);
+               MSG_DEBUG("escapeAddressStr [%s]", escapeAddressStr);
+               dbHandle->bindText(escapeAddressStr, 1);
+               //dbHandle->bindText(escapeAddressStr, 2);
+               //dbHandle->bindText(escapeAddressStr, 3);
+               //dbHandle->bindText(escapeAddressStr, 4);
+
+               while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+                       memset(&threadView, 0x00, sizeof(threadView));
+
+                       threadView.threadId = dbHandle->columnInt(0);
+                       threadView.unreadCnt = dbHandle->columnInt(1);
+                       threadView.smsCnt = dbHandle->columnInt(2);
+                       threadView.mmsCnt = dbHandle->columnInt(3);
+
+                       if (dbHandle->columnText(4))
+                               strncpy(threadView.threadName, (char *)dbHandle->columnText(4), MAX_THREAD_NAME_LEN);
+
+                       threadView.mainType = dbHandle->columnInt(5);
+                       threadView.subType = dbHandle->columnInt(6);
+
+                       threadView.direction = dbHandle->columnInt(7);
+                       threadView.threadTime = (time_t)dbHandle->columnInt(8);
+
+                       if (dbHandle->columnText(9))
+                               strncpy(threadView.threadData, (char *)dbHandle->columnText(9), MAX_THREAD_DATA_LEN);
+
+                       int protectedCnt = dbHandle->columnInt(10);
+                       if (protectedCnt > 0)
+                               threadView.bProtected = true;
+
+                       int draftCnt = dbHandle->columnInt(11);
+                       if (draftCnt > 0)
+                               threadView.bDraft = true;
+
+                       int failedCnt = dbHandle->columnInt(12);
+                       if (failedCnt > 0)
+                               threadView.bSendFailed = true;
+
+                       int sendingCnt = dbHandle->columnInt(13);
+                       if (sendingCnt > 0)
+                               threadView.bSending = true;
+
+                       threadView.msgTranslation.bTranslation = dbHandle->columnInt(14);
+                       threadView.msgTranslation.senderLang = dbHandle->columnInt(15);
+                       threadView.msgTranslation.receiverLang = dbHandle->columnInt(16);
+                       threadView.msgTranslation.bOnlyReceive = dbHandle->columnInt(17);
+                       threadView.msgTranslation.bIncludeOrgMsg = dbHandle->columnInt(18);
+
+                       threadView.lastMsgId = dbHandle->columnInt(19);
+
+                       tr1::unordered_set<msg_thread_id_t>::iterator it;
+
+                       it = IdList.find(threadView.threadId);
+
+                       if (it == IdList.end()) {
+                               IdList.insert(threadView.threadId);
+                               searchList.push(threadView);
+                       }
+
+               }
+
+               dbHandle->finalizeQuery();
+
+               if (escapeAddressStr) {
+                       free(escapeAddressStr);
+                       escapeAddressStr = NULL;
+               }
+       }
+
+
+       // Add data to Out Parameter
+       pThreadViewList->nCount = searchList.size();
+       pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * searchList.size()];
+
+       MSG_THREAD_VIEW_S *pTmp = NULL;
+       msg_struct_s *thread_t = NULL;
+
+       int index = 0;
+
+       while (!searchList.empty()) {
+               thread_t = (msg_struct_s *)new msg_struct_s;
+               pThreadViewList->msg_struct_info[index] = (msg_struct_t)thread_t;
+
+               thread_t->type = MSG_STRUCT_THREAD_INFO;
+               thread_t->data = new MSG_THREAD_VIEW_S;
+
+               pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
+               memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
+
+               memcpy(pTmp, &(searchList.front()), sizeof(MSG_THREAD_VIEW_S));
+
+               searchList.pop();
+
+               index++;
+       }
+
+       return MSG_SUCCESS;
+}
+
+msg_error_t MsgStoSearchByTag(const int tagType, msg_struct_list_s *pThreadViewList)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       pThreadViewList->nCount = 0;
+       pThreadViewList->msg_struct_info = NULL;
+
+       int rowCnt = 0;
+       int index = 21; // numbers of index
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.UNREAD_CNT, A.SMS_CNT, A.MMS_CNT, A.MAIN_TYPE, A.SUB_TYPE, "
+                       "A.MSG_DIRECTION, A.DISPLAY_TIME, A.DISPLAY_NAME, A.MSG_TEXT, "
+                       "(COUNT(CASE WHEN B.PROTECTED = 1 THEN 1 END)) AS PROTECTED, "
+                       "(COUNT(CASE WHEN B.FOLDER_ID = %d THEN 1 END)) AS DRAFT, "
+                       "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS FAILED, "
+                       "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENDING, "
+                       "A.TRANSLATION, A.SENDER_LANG, A.RECEIVER_LANG, A.ONLY_RECEIVE, A.INCLUDE_ORGMSG, A.LAST_MSG_ID,A.TAG_TYPE "
+                       "FROM %s A, %s B ON A.SMS_CNT + A.MMS_CNT > 0 AND B.CONV_ID = A.CONV_ID AND A.TAG_TYPE = %d "
+                       "GROUP BY A.CONV_ID ORDER BY A.DISPLAY_TIME DESC;",
+                       MSG_DRAFT_ID,
+                       MSG_NETWORK_SEND_FAIL,
+                       MSG_NETWORK_SENDING,
+                       MSGFW_CONVERSATION_TABLE_NAME,
+                       MSGFW_MESSAGE_TABLE_NAME,tagType);
+
+       msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle->freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
+       }
+
+       if (rowCnt < 1) {
+               MSG_DEBUG("rowCnt is %d", rowCnt);
+               dbHandle->freeTable();
+               return err;
+       }
+
+       pThreadViewList->nCount = rowCnt;
+
+       MSG_DEBUG("pThreadViewList->nCount [%d]", pThreadViewList->nCount);
+
+       pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*rowCnt];
+
+       MSG_THREAD_VIEW_S *pTmp = NULL;
+       msg_struct_s *thread_t = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               thread_t = (msg_struct_s *)new msg_struct_s;
+               pThreadViewList->msg_struct_info[i] = (msg_struct_t)thread_t;
+
+               thread_t->type = MSG_STRUCT_THREAD_INFO;
+               thread_t->data = new MSG_THREAD_VIEW_S;
+
+               pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
+               memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
+
+               pTmp->threadId = dbHandle->getColumnToInt(index++);
+
+               pTmp->unreadCnt = dbHandle->getColumnToInt(index++);
+               pTmp->smsCnt = dbHandle->getColumnToInt(index++);
+               pTmp->mmsCnt = dbHandle->getColumnToInt(index++);
+
+               pTmp->mainType = dbHandle->getColumnToInt(index++);
+               pTmp->subType = dbHandle->getColumnToInt(index++);
+
+               pTmp->direction = dbHandle->getColumnToInt(index++);
+               pTmp->threadTime = (time_t)dbHandle->getColumnToInt(index++);
+
+               memset(pTmp->threadName, 0x00, sizeof(pTmp->threadName));
+               dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pTmp->threadName);
+
+               memset(pTmp->threadData, 0x00, sizeof(pTmp->threadData));
+               dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, pTmp->threadData);
+
+               int protectedCnt = dbHandle->getColumnToInt(index++);
+               if (protectedCnt > 0)
+                       pTmp->bProtected = true;
+
+               int draftCnt = dbHandle->getColumnToInt(index++);
+               if (draftCnt > 0)
+                       pTmp->bDraft = true;
+
+               int failedCnt = dbHandle->getColumnToInt(index++);
+               if (failedCnt > 0)
+                       pTmp->bSendFailed = true;
+
+               int sendingCnt = dbHandle->getColumnToInt(index++);
+               if (sendingCnt > 0)
+                       pTmp->bSending = true;
+
+               pTmp->msgTranslation.bTranslation = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.senderLang = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.receiverLang = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.bOnlyReceive = dbHandle->getColumnToInt(index++);
+               pTmp->msgTranslation.bIncludeOrgMsg = dbHandle->getColumnToInt(index++);
+
+               pTmp->lastMsgId = dbHandle->getColumnToInt(index++);
+               pTmp->tagType = dbHandle->getColumnToInt(index++);
+       }
+
+       dbHandle->freeTable();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoGetRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       // Clear Out Parameter
+       pRejectMsgList->nCount = 0;
+       pRejectMsgList->msg_struct_info = NULL;
+
+       int rowCnt = 0;
+       int index = 3; // numbers of index
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       // Search Reject Msg
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       if (pNumber != NULL) {
+               int addrSize = strlen(pNumber);
+               char phoneNumber[addrSize+1];
+               memset(phoneNumber, 0x00, sizeof(phoneNumber));
+
+               if (addrSize > MsgContactGetMinMatchDigit())
+                       MsgConvertNumber(pNumber, phoneNumber, addrSize);
+               else
+                       strncpy(phoneNumber, pNumber, addrSize);
+
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                               "B.MSG_ID, "
+                               "B.MSG_TEXT, "
+                               "B.DISPLAY_TIME "
+                               "FROM %s A, %s B "
+                               "WHERE A.CONV_ID = B.CONV_ID "
+                               "AND B.MAIN_TYPE = %d "
+                               "AND B.SUB_TYPE = %d "
+                               "AND A.ADDRESS_VAL LIKE '%%%s' "
+                               "ORDER BY B.DISPLAY_TIME DESC;",
+                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                               MSG_SMS_TYPE,
+                               MSG_REJECT_SMS,
+                               phoneNumber);
+       } else {
+               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                               "B.MSG_ID, "
+                               "B.MSG_TEXT, "
+                               "B.DISPLAY_TIME "
+                               "FROM %s A, %s B "
+                               "WHERE A.CONV_ID = B.CONV_ID "
+                               "AND B.MAIN_TYPE = %d "
+                               "AND B.SUB_TYPE = %d "
+                               "ORDER BY B.DISPLAY_TIME DESC;",
+                               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
+                               MSG_SMS_TYPE,
+                               MSG_REJECT_SMS);
+       }
+
+       msg_error_t  err = dbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable().");
+               dbHandle->freeTable();
+               return err;
+       }
+
+       pRejectMsgList->nCount = rowCnt;
+
+       MSG_DEBUG("pRejectMsgList->nCount [%d]", pRejectMsgList->nCount);
+
+       pRejectMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(MSG_REJECT_MSG_INFO_S *)*rowCnt];
+
+       msg_struct_s* pTmp = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               pRejectMsgList->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
+
+               pTmp = (msg_struct_s *)pRejectMsgList->msg_struct_info[i];
+               pTmp->type = MSG_STRUCT_REJECT_MSG_INFO;
+               pTmp->data = new MSG_REJECT_MSG_INFO_S;
+               MSG_REJECT_MSG_INFO_S * pMsg = (MSG_REJECT_MSG_INFO_S *)pTmp->data;
+               memset(pMsg, 0x00, sizeof(MSG_REJECT_MSG_INFO_S));
+
+               pMsg->msgId = dbHandle->getColumnToInt(index++);
+               memset(pMsg->msgText, 0x00, sizeof(pMsg->msgText));
+               dbHandle->getColumnToString(index++, MAX_MSG_TEXT_LEN, pMsg->msgText);
+
+               pMsg->displayTime = (time_t)dbHandle->getColumnToInt(index++);
+       }
+
+       dbHandle->freeTable();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStoGetAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       msg_error_t err = MSG_SUCCESS;
+
+       int order = MsgGetContactNameOrder();
+
+       err = MsgStoGetAddressByConvId(dbHandle, threadId, order, pAddrList);
+
+       return err;
+}
+
+
+msg_error_t MsgStoGetMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
+{
+       MsgDbHandler *dbHandle = getDbHandle();
+
+       // Clear Out Parameter
+       pMsgList->nCount = 0;
+       pMsgList->msg_struct_info = NULL;
+
+       int index = 0;
+       int multipartCnt = 0;
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+       char sqlQuerySubset[(MAX_QUERY_LEN/5)+1];
+       char tmpsqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*) FROM %s;", MSGFW_MMS_MULTIPART_TABLE_NAME);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
+
+       if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+               multipartCnt = dbHandle->columnInt(0);
+       } else {
+               dbHandle->finalizeQuery();
+               return MSG_ERR_DB_STEP;
+       }
+
+       dbHandle->finalizeQuery();
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT "
+                       "A.MSG_ID, "
+                       "A.CONV_ID, "
+                       "A.FOLDER_ID, "
+                       "A.STORAGE_ID, "
+                       "A.MAIN_TYPE, "
+                       "A.SUB_TYPE, "
+                       "A.DISPLAY_TIME, "
+                       "A.DATA_SIZE, "
+                       "A.NETWORK_STATUS, "
+                       "A.READ_STATUS, "
+                       "A.PROTECTED, "
+                       "A.BACKUP, "
+                       "A.PRIORITY, "
+                       "A.MSG_DIRECTION, "
+                       "A.SCHEDULED_TIME, "
+                       "A.SUBJECT, "
+                       "A.MSG_TEXT, "
+                       "A.ATTACHMENT_COUNT, "
+                       "A.THUMB_PATH, "
+                       "A.SIM_INDEX, "
+                       "B.ADDRESS_TYPE, "
+                       "B.RECIPIENT_TYPE, "
+                       "B.ADDRESS_VAL ");
+
+       if (pListCond->pTextVal != NULL && multipartCnt > 0) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),        "FROM %s C, %s B, %s A WHERE A.CONV_ID > 0 AND A.CONV_ID = B.CONV_ID AND "
+                       ,MSGFW_MMS_MULTIPART_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
+       }
+       else {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),        "FROM %s B, %s A WHERE A.CONV_ID > 0 AND A.CONV_ID = B.CONV_ID AND ",
+               MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME);
+       }
+
+       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+       //// folder
+       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+
+       if (pListCond->folderId == MSG_ALLBOX_ID)
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_SPAMBOX_ID);
+       else if (pListCond->folderId == MSG_IOSBOX_ID)
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_DRAFT_ID);
+       else
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "A.FOLDER_ID = %d ", pListCond->folderId);
+
+       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+
+       //// thread
+       if (pListCond->threadId > 0) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.CONV_ID = %d ", pListCond->threadId);
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+
+       //// msg type
+       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+
+       switch (pListCond->msgType) {
+               case MSG_TYPE_SMS:
+                       if (pListCond->pAddressVal == NULL)
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d ", MSG_SMS_TYPE);
+                       else
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_NORMAL_SMS);
+                       break;
+
+               case MSG_TYPE_MMS:
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d ", MSG_MMS_TYPE);
+                       break;
+
+               case MSG_TYPE_MMS_JAVA:
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_MMS_TYPE, MSG_SENDREQ_JAVA_MMS);
+                       break;
+
+               case MSG_TYPE_SMS_SYNCML:
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_SYNCML_CP);
+                       break;
+               case MSG_TYPE_SMS_REJECT:
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_REJECT_SMS);
+                       break;
+
+               default:
+                       MSG_DEBUG("msg type is not set.");
+                       break;
+       }
+
+       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+
+       //// storage
+       if (pListCond->storageId > MSG_STORAGE_UNKNOWN) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.STORAGE_ID = %d ", pListCond->storageId);
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+
+       //// protected
+       if (pListCond->bProtected) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.PROTECTED = %d ", pListCond->bProtected);
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+
+       //// scheduled
+       if (pListCond->bScheduled) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.SCHEDULED_TIME > 0 ");
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+
+       //// sim index
+       if (pListCond->simIndex > 0) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.SIM_INDEX = %d ", pListCond->simIndex);
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+
+       //// time range
+       if (pListCond->fromTime > 0) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.DISPLAY_TIME >= %u ", (unsigned int)pListCond->fromTime);
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+       if (pListCond->toTime > 0) {
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.DISPLAY_TIME <= %u ", (unsigned int)pListCond->toTime);
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+       if (pListCond->pAddressVal == NULL) {
+               /// Text
+               if (pListCond->pTextVal != NULL) {
+
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       if (multipartCnt > 0) {
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                               "AND ((A.MSG_TEXT LIKE ? ESCAPE '%c' OR A.SUBJECT LIKE ? ESCAPE '%c' OR (C.NAME LIKE ? ESCAPE '%c' AND A.MSG_ID = C.MSG_ID AND C.CONTENT_TYPE <> 'application/smil'))) ",
+                                               MSGFW_DB_ESCAPE_CHAR, MSGFW_DB_ESCAPE_CHAR, MSGFW_DB_ESCAPE_CHAR);
+                       }
+                       else {
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                               "AND ((A.MSG_TEXT LIKE ? ESCAPE '%c' OR A.SUBJECT LIKE ? ESCAPE '%c')) ",
+                                               MSGFW_DB_ESCAPE_CHAR, MSGFW_DB_ESCAPE_CHAR);
+                       }
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+               }
+       } else {
+               /// Text
+               if (pListCond->pTextVal != NULL) {
+
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       if (multipartCnt > 0) {
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                               "AND ((A.MSG_TEXT LIKE ? ESCAPE '%c' OR A.SUBJECT LIKE ? ESCAPE '%c' OR (C.NAME LIKE ? ESCAPE '%c' AND A.MSG_ID = C.MSG_ID AND C.CONTENT_TYPE <> 'application/smil')) ",
+                                               MSGFW_DB_ESCAPE_CHAR, MSGFW_DB_ESCAPE_CHAR, MSGFW_DB_ESCAPE_CHAR);
+                       }
+                       else {
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                               "AND ((A.MSG_TEXT LIKE ? ESCAPE '%c' OR A.SUBJECT LIKE ? ESCAPE '%c') ",
+                                               MSGFW_DB_ESCAPE_CHAR, MSGFW_DB_ESCAPE_CHAR);
+                       }
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       if (pListCond->bAnd) {
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND ");
+                       } else {
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "OR ");
+                       }
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+                       // Address
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                       "(B.ADDRESS_VAL LIKE ? ESCAPE '%c' ", MSGFW_DB_ESCAPE_CHAR);
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+                       MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
+                       AutoPtr<MSG_ADDRESS_INFO_S> buf(&pAddrInfo);
+                       int count = 0;
+
+                       // get contact search list
+                       if (MsgGetContactSearchList(pListCond->pAddressVal, &pAddrInfo, &count) != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgGetContactSearchList fail.");
+                               count = 0;
+                       }
+
+                       if (count > 0) {
+                               dbHandle->beginTrans();
+                               // reset address temp table
+                               memset(tmpsqlQuery, 0x00, sizeof(tmpsqlQuery));
+                               snprintf(tmpsqlQuery, sizeof(tmpsqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
+                               MSG_DEBUG("[%s]", tmpsqlQuery);
+
+                               if (dbHandle->prepareQuery(tmpsqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_EXEC;
+
+                               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                                       dbHandle->finalizeQuery();
+                                       return MSG_ERR_DB_EXEC;
+                               }
+
+                               dbHandle->finalizeQuery();
+
+                               memset(tmpsqlQuery, 0x00, sizeof(tmpsqlQuery));
+                               snprintf(tmpsqlQuery, sizeof(tmpsqlQuery), "INSERT INTO %s VALUES ('%%%%?');", MSGFW_ADDRESS_TEMP_TABLE_NAME);
+                               if (dbHandle->prepareQuery(tmpsqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
+                                       return MSG_ERR_DB_PREPARE;
+                               }
+
+                               for (int i = 0; i < count; i++) {
+                                       int addrSize = strlen(pAddrInfo[i].addressVal);
+                                       char newPhoneNum[addrSize+1];
+                                       memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+                                       MsgConvertNumber(pAddrInfo[i].addressVal, newPhoneNum, addrSize);
+
+                                       dbHandle->resetQuery();
+                                       dbHandle->bindText(newPhoneNum, 1);
+                                       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                                               dbHandle->finalizeQuery();
+                                               dbHandle->endTrans(false);
+                                               return MSG_ERR_DB_EXEC;
+                                       }
+                               }
+
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(true);
+
+                               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                               "OR B.ADDRESS_VAL IN (SELECT D.ADDRESS_VAL FROM %s D JOIN %s E ON (D.ADDRESS_VAL LIKE E.ADDRESS_VAL)) "
+                                               , MSGFW_ADDRESS_TABLE_NAME, MSGFW_ADDRESS_TEMP_TABLE_NAME);
+                               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+                       }
+
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), ")) ");
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+               } else {
+                       // Address
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                       "AND (B.ADDRESS_VAL LIKE ? ESCAPE '%c' ", MSGFW_DB_ESCAPE_CHAR);
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+                       MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
+                       AutoPtr<MSG_ADDRESS_INFO_S> buf(&pAddrInfo);
+                       int count = 0;
+
+                       // get contact search list
+                       if (MsgGetContactSearchList(pListCond->pAddressVal, &pAddrInfo, &count) != MSG_SUCCESS) {
+                               MSG_DEBUG("MsgGetContactSearchList fail.");
+                               count = 0;
+                       }
+
+                       if (count > 0) {
+                               dbHandle->beginTrans();
+                               // reset address temp table
+                               memset(tmpsqlQuery, 0x00, sizeof(tmpsqlQuery));
+                               snprintf(tmpsqlQuery, sizeof(tmpsqlQuery), "DELETE FROM %s;", MSGFW_ADDRESS_TEMP_TABLE_NAME);
+                               MSG_DEBUG("[%s]", tmpsqlQuery);
+
+                               if (dbHandle->prepareQuery(tmpsqlQuery) != MSG_SUCCESS)
+                                       return MSG_ERR_DB_EXEC;
+
+                               if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                                       dbHandle->finalizeQuery();
+                                       return MSG_ERR_DB_EXEC;
+                               }
+
+                               dbHandle->finalizeQuery();
+
+                               memset(tmpsqlQuery, 0x00, sizeof(tmpsqlQuery));
+                               snprintf(tmpsqlQuery, sizeof(tmpsqlQuery), "INSERT INTO %s VALUES ('%%%%?');", MSGFW_ADDRESS_TEMP_TABLE_NAME);
+                               if (dbHandle->prepareQuery(tmpsqlQuery) != MSG_SUCCESS) {
+                                       dbHandle->endTrans(false);
+                                       return MSG_ERR_DB_PREPARE;
+                               }
+
+                               for (int i = 0; i < count; i++) {
+                                       int addrSize = strlen(pAddrInfo[i].addressVal);
+                                       char newPhoneNum[addrSize+1];
+                                       memset(newPhoneNum, 0x00, sizeof(newPhoneNum));
+                                       MsgConvertNumber(pAddrInfo[i].addressVal, newPhoneNum, addrSize);
+
+                                       dbHandle->resetQuery();
+                                       dbHandle->bindText(newPhoneNum, 1);
+                                       if (dbHandle->stepQuery() != MSG_ERR_DB_DONE) {
+                                               dbHandle->finalizeQuery();
+                                               dbHandle->endTrans(false);
+                                               return MSG_ERR_DB_EXEC;
+                                       }
+                               }
+
+                               dbHandle->finalizeQuery();
+                               dbHandle->endTrans(true);
+
+                               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+                                               "OR B.ADDRESS_VAL IN (SELECT D.ADDRESS_VAL FROM %s D JOIN %s E ON (D.ADDRESS_VAL LIKE E.ADDRESS_VAL)) "
+                                               , MSGFW_ADDRESS_TABLE_NAME, MSGFW_ADDRESS_TEMP_TABLE_NAME);
+                               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+                       }
+
+                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), ") ");
+                       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+               }
+       }
+
+       msg_struct_s *pSortRule = (msg_struct_s *)pListCond->sortRule;
+
+       if (pSortRule->type != MSG_STRUCT_SORT_RULE) {
+               /// Order
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY A.DISPLAY_TIME ");
+
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+               /// Sorting type
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "DESC ");
+
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       } else {
+               MSG_SORT_RULE_S *pTmp = (MSG_SORT_RULE_S *)pSortRule->data;
+               /// order // TODO: have to finish this
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               switch (pTmp->sortType)
+               {
+               case MSG_SORT_BY_MSG_TYPE :
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY A.MAIN_TYPE ");
+                       break;
+               case MSG_SORT_BY_READ_STATUS :
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY A.READ_STATUS ");
+                       break;
+               case MSG_SORT_BY_STORAGE_TYPE :
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY A.STORAGE_ID ");
+                       break;
+               default:
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY A.DISPLAY_TIME ");
+                       break;
+               }
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+               // Sorting type
+               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+               if (pTmp->bAscending)
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ASC ");
+               else
+                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "DESC ");
+
+               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+       }
+
+       // offset & limit
+       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
+       if (pListCond->offset >= 0 && pListCond->limit > 0)
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "LIMIT %d OFFSET %d;", pListCond->limit, pListCond->offset);
+       else
+               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), ";");
+
+       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+
+
+       //////// 'til here sqlQuery is complete.
+
+       queue<MSG_MESSAGE_HIDDEN_S*> searchList;
+
+       MSG_DEBUG("[%s]", sqlQuery);
+
+       if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("Prepare query fail.");
+               return MSG_ERR_DB_PREPARE;
+       }
+
+       char *escapeTextStr = NULL;
+       char *escapeAddressStr = NULL;
+
+       if (pListCond->pAddressVal == NULL) {
+               /// Text
+               if (pListCond->pTextVal != NULL) {
+
+                       MsgConvertStrWithEscape(pListCond->pTextVal, &escapeTextStr);
+                       MSG_DEBUG("escapeTextStr [%s]", escapeTextStr);
+                       dbHandle->bindText(escapeTextStr, 1);
+                       dbHandle->bindText(escapeTextStr, 2);
+                       if (multipartCnt > 0) dbHandle->bindText(escapeTextStr, 3);
+
+               }
+       } else {
+               /// Text
+               if (pListCond->pTextVal != NULL) {
+
+                       MsgConvertStrWithEscape(pListCond->pTextVal, &escapeTextStr);
+                       MSG_DEBUG("escapeTestStr [%s]", escapeTextStr);
+
+                       // Address
+                       MsgConvertStrWithEscape(pListCond->pAddressVal, &escapeAddressStr);
+                       MSG_DEBUG("escapeAddressStr [%s]", escapeAddressStr);
+
+                       dbHandle->bindText(escapeTextStr, 1);
+                       dbHandle->bindText(escapeTextStr, 2);
+                       if (multipartCnt > 0) {
+                               dbHandle->bindText(escapeTextStr, 3);
+                               dbHandle->bindText(escapeAddressStr, 4);
+                       } else {
+                               dbHandle->bindText(escapeAddressStr, 3);
+                       }
+
+               } else {
+                       // Address
+                       MsgConvertStrWithEscape(pListCond->pAddressVal, &escapeAddressStr);
+                       MSG_DEBUG("escapeAddressStr [%s]", escapeAddressStr);
+                       dbHandle->bindText(escapeAddressStr, 1);
+               }
+       }
+
+
+       MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
+       int lastMsgId = 0;  // for comparing same msg id.
+
+       while (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
+
+               index = 0;
+
+               int msgid = dbHandle->columnInt(index++);
+               MSG_DEBUG("msgid [%d]", msgid);
+
+               if (lastMsgId != msgid) {
+                       MSG_DEBUG("lastMsgId != msgid");
+
+                       lastMsgId = msgid;
+
+                       pTmp = new MSG_MESSAGE_HIDDEN_S;
+
+                       if(pTmp)
+                       {
+                               memset(pTmp, 0x00, sizeof(MSG_MESSAGE_HIDDEN_S));
+
+                               pTmp->pData = NULL;
+                               pTmp->pMmsData = NULL;
+                               pTmp->addressList = NULL;
+
+                               pTmp->msgId = msgid;
+
+                               pTmp->threadId = dbHandle->columnInt(index++);
+                               pTmp->folderId = dbHandle->columnInt(index++);
+                               pTmp->storageId = dbHandle->columnInt(index++);
+                               pTmp->mainType = dbHandle->columnInt(index++);
+                               pTmp->subType = dbHandle->columnInt(index++);
+                               pTmp->displayTime = (time_t)dbHandle->columnInt(index++);
+                               pTmp->dataSize = dbHandle->columnInt(index++);
+                               pTmp->networkStatus = dbHandle->columnInt(index++);
+                               pTmp->bRead = dbHandle->columnInt(index++);
+                               pTmp->bProtected = dbHandle->columnInt(index++);
+                               pTmp->bBackup = dbHandle->columnInt(index++);
+                               pTmp->priority = dbHandle->columnInt(index++);
+                               pTmp->direction = dbHandle->columnInt(index++);
+                               index++; // This field is reserved.
+
+                               strncpy(pTmp->subject, (char *)dbHandle->columnText(index++), MAX_SUBJECT_LEN);
+
+                               if (pTmp->mainType == MSG_MMS_TYPE &&
+                                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
+                                       pTmp->pData = NULL;
+                                       index++;
+                               } else {
+                                       pTmp->pData = (void *)new char[pTmp->dataSize+2];
+                                       memset(pTmp->pData, 0x00, pTmp->dataSize+2);
+
+                                       strncpy((char *)pTmp->pData, (char *)dbHandle->columnText(index++), pTmp->dataSize+1);
+                               }
+
+                               pTmp->attachCount = dbHandle->columnInt(index++);
+
+                               strncpy(pTmp->thumbPath, (char *)dbHandle->columnText(index++), MSG_FILEPATH_LEN_MAX);
+
+                               pTmp->simIndex = dbHandle->columnInt(index++);
+
+                               pTmp->addr_list = (msg_struct_list_s *)new msg_struct_list_s;
+                               pTmp->addr_list->nCount = 0;
+                               pTmp->addr_list->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * MAX_TO_ADDRESS_CNT];
+                               for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
+                                       pTmp->addr_list->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
+                                       memset(pTmp->addr_list->msg_struct_info[i], 0x00, sizeof(msg_struct_s));
+                               }
+
+                               searchList.push(pTmp);
+                       }
+
+               } else {
+                       MSG_DEBUG("lastMsgId == msgid");
+                       index += 19;
+               }
+
+               if(pTmp) {
+                       MSG_ADDRESS_INFO_S *pAddr = new MSG_ADDRESS_INFO_S;
+                       memset(pAddr, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                       pAddr->addressType = dbHandle->columnInt(index++);
+                       pAddr->recipientType = dbHandle->columnInt(index++);
+
+                       strncpy(pAddr->addressVal, (char *)dbHandle->columnText(index++), MAX_ADDRESS_VAL_LEN);
+
+                       strncpy(pAddr->displayName, pAddr->addressVal, MAX_DISPLAY_NAME_LEN);
+
+                       // For GList *addressList
+                       msg_struct_s *addr_info_s = new msg_struct_s;
+                       memset(addr_info_s, 0x00, sizeof(msg_struct_s));
+                       addr_info_s->type = MSG_STRUCT_ADDRESS_INFO;
+                       addr_info_s->data = new MSG_ADDRESS_INFO_S;
+                       memset(addr_info_s->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+                       MSG_ADDRESS_INFO_S *addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
+                       addr_info->addressType = pAddr->addressType;
+                       addr_info->recipientType = pAddr->recipientType;
+                       addr_info->contactId = pAddr->contactId;
+                       strncpy(addr_info->addressVal, pAddr->addressVal, MAX_ADDRESS_VAL_LEN);
+                       strncpy(addr_info->displayName, pAddr->displayName, MAX_DISPLAY_NAME_LEN);
+                       addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
+
+                       pTmp->addressList = g_list_append(pTmp->addressList, addr_info_s);
+
+                       if (pTmp->addr_list->nCount >= MAX_TO_ADDRESS_CNT) {
+
+                               delete pAddr;
+
+                       } else {
+                               msg_struct_s *pStruct = (msg_struct_s *)pTmp->addr_list->msg_struct_info[pTmp->addr_list->nCount];
+                               pTmp->addr_list->nCount++;
+                               pStruct->type = MSG_STRUCT_ADDRESS_INFO;
+                               pStruct->data = pAddr;
+                       }
+               }
+       }
+
+       dbHandle->finalizeQuery();
+
+       pMsgList->nCount = searchList.size();
+       MSG_DEBUG("pMsgList->nCount [%d]", pMsgList->nCount);
+
+       pMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * pMsgList->nCount];
+
+       int offset = 0;
+       while (!searchList.empty()) {
+
+               msg_struct_s *msg = new msg_struct_s;
+
+               pMsgList->msg_struct_info[offset++] = (msg_struct_t)msg;
+
+               msg->type = MSG_STRUCT_MESSAGE_INFO;
+               msg->data = searchList.front();
+
+               searchList.pop();
+       }
+
+
+       if (escapeTextStr)
+               free(escapeTextStr);
+
+       if (escapeAddressStr)
+               free(escapeAddressStr);
+
+       return MSG_SUCCESS;
 }
index 2761d2d..9fa9159 100755 (executable)
@@ -1,18 +1,19 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
+
 #include <VMessage.h>
 #include <VCard.h>
 #include <time.h>
@@ -23,7 +24,8 @@
 #include "MsgUtilFile.h"
 #include "MsgCppTypes.h"
 #include "MsgVMessage.h"
-
+#include "MsgMmsMessage.h"
+#include "MsgSerialize.h"
 
 /*==================================================================================================
                                      DEFINES
@@ -106,7 +108,6 @@ char* MsgVMessageAddRecord(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
        VTree *         pCurrent= NULL;
        struct tm       display_time;
        char*           encoded_data = NULL;
-       int                     err = MSG_SUCCESS;
 
        VTree* pMessage = NULL;
        if (pMessage == NULL) {
@@ -176,6 +177,7 @@ char* MsgVMessageAddRecord(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg)
        INSERT_VMSG_OBJ;
 
        pObject->property = VMSG_TYPE_DATE;
+       tzset();
        localtime_r(&(pMsg->displayTime), &display_time);
        pObject->pszValue[0] = _convert_tm_to_vdata_str(&display_time);
        pObject->valueCount = 1;
@@ -252,11 +254,11 @@ if(strlen(pMsg->subject) > 0)
        {
                //Insert VBody for mms raw data;
                char* pFileData = NULL;
-
+               MMS_DATA_S *pMmsData = NULL;
                int             fileSize = 0;
                char*   msgText = NULL;
+#if 0
                char            filePath[MSG_FILEPATH_LEN_MAX] = {0, };
-
                if(pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS)
                        pFileData = MsgOpenAndReadMmsFile(pMsg->msgData, 0, -1, &fileSize);
 
@@ -269,10 +271,53 @@ if(strlen(pMsg->subject) > 0)
 
                        pFileData = MsgOpenAndReadMmsFile(filePath, 0, -1, &fileSize);
                }
-               MSG_DEBUG("FILE SIZE IS %d", fileSize);
+#else
+
+               if (pMsg->bTextSms == false) {
+                       if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
+                               //CID 16205: Memory leak in case of failure
+                               if (pFileData) {
+                                       free(pFileData);
+                                       pFileData = NULL;
+                               }
+                               goto __CATCH_FAIL__;
+                       }
+               } else {
+                       fileSize = strlen(pMsg->msgData);
+                       pFileData = (char *)calloc(1, fileSize+1);
+                       snprintf(pFileData, fileSize, "%s", pMsg->msgData);
+               }
+
+               //CID 46178: Pulling up the null check
+               if (pFileData) {
+                       if (MsgDeserializeMmsData(pFileData, fileSize, &pMmsData) != 0) {
+                               MSG_DEBUG("Fail to Deserialize Message Data");
+                               goto __CATCH_FAIL__;
+                       }
+
+                       free(pFileData);
+                       pFileData = NULL;
+               }
+
+               MsgMmsSetMultipartListData(pMmsData);//app file -> data
+
+               int serializedDataSize = 0;
+
+               serializedDataSize = MsgSerializeMms(pMmsData, &pFileData);
+
+               if (pFileData) {
+                       fileSize = serializedDataSize;
+               }
+
+               MsgMmsRelease(&pMmsData);
+
+#endif
+               MSG_DEBUG("FILE SIZE IS %d, %s", fileSize, pFileData);
                msgText = (char *)calloc(1, fileSize);
                if(pFileData)
                        memcpy(msgText, pFileData, fileSize);
+
+
                pObject->numOfBiData = fileSize;
                pObject->pszValue[0] = msgText;
                pObject->valueCount = 1;
@@ -473,6 +518,7 @@ char *MsgVMessageEncode(MSG_MESSAGE_INFO_S *pMsg)
        INSERT_VMSG_OBJ;
 
        pObject->property = VMSG_TYPE_DATE;
+       tzset();
        localtime_r(&(pMsg->displayTime), &display_time);
        pObject->pszValue[0] = _convert_tm_to_vdata_str(&display_time);
        pObject->valueCount = 1;
index 03bccbf..e61b8f9 100755 (executable)
@@ -14,13 +14,13 @@ SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -O0 -g -Wall")
 SET(VOBJECT-SRCS
                ${CMAKE_SOURCE_DIR}/vobject-engine/VCard.c
                ${CMAKE_SOURCE_DIR}/vobject-engine/VCardCalUtil.c
-             ${CMAKE_SOURCE_DIR}/vobject-engine/VMessage.c
-       )
+       ${CMAKE_SOURCE_DIR}/vobject-engine/VMessage.c
+)
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(vobject_pkgs REQUIRED dlog)
+pkg_check_modules(vobject_pkgs REQUIRED dlog glib-2.0)
 
 SET(EXTRA_CFLAGS "")
 FOREACH(flag ${vobject_pkgs_CFLAGS})
@@ -37,4 +37,4 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 ADD_LIBRARY(${VOBJECT-LIB} SHARED ${VOBJECT-SRCS})
 TARGET_LINK_LIBRARIES(${VOBJECT-LIB} ${vobject_pkgs_LDFLAGS})
 
-INSTALL(TARGETS ${VOBJECT-LIB} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${VOBJECT-LIB} DESTINATION lib)
index a6f1892..a2469a6 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "VTypes.h"
@@ -598,17 +598,15 @@ __VCardGetParamVal( char* pVCardRaw, int* pStatus, int* pDLen )
                        break;
        }
 
-       pBuf = (char *)malloc(len);
-       if(len < 1 || (pBuf  == NULL)) {
-//             if (pBuf) {
-//                     free(pBuf);
-//                     pBuf = NULL;
-//             }
+       //if (len < 1)
+               //return NULL;
 
+       pBuf = (char *)malloc(len);
+       if(pBuf  == NULL)
                return NULL;
-       }
+
        memset(pBuf, 0x00, len);
-       memcpy( pBuf, pTemp, len-1 );
+       memcpy(pBuf, pTemp, len-1);
        TRIM(pBuf);
        VDATA_TRACE_END
        return pBuf;
@@ -863,18 +861,21 @@ vcard_decode( char *pCardRaw )
        int param_status = false;
        int numberedParam = 0;
        int enc = 0;
-       int start_status = 0;
+       //int start_status = 0;
        char* temp = NULL;
 
        bool vcard_ended = false;
 
        SysRequireEx(pCardRaw != NULL, NULL);
        len = strlen(pCardRaw);
+       VDATA_TRACE("length of pCardRaw = %d", len);
 
        pCardRaw = _VUnfoldingNoSpecNew(pCardRaw);
        pCardRawTmp = pCardRaw;
        len = _VManySpace2Space( pCardRaw );
 
+       VDATA_TRACE("ret value of _VManySpace2Space = %d", len);
+
        if(!__VIsVcardFile(pCardRaw, CHECK_START)) {
                VFREE(pCardRawTmp);
                VDATA_TRACE_END
@@ -901,12 +902,13 @@ vcard_decode( char *pCardRaw )
                                switch ( type )
                                {
                                        case VCARD_TYPE_BEGIN:
-                                               if(start_status == 1) {
-                                                       goto CATCH;
+                                               if (pVCard) {
+                                                       free(pVCard);
+                                                       pVCard = NULL;
                                                }
 
                                                if ( ( pVCard = ( VTree* )malloc( sizeof( VTree ) ) ) == NULL ) {
-                                                       start_status = 1;
+                                                       //start_status = 1;
                                                        goto CATCH;
                                                }
 
@@ -1255,11 +1257,11 @@ __VCardTypeEncode( VObject *pTypeObj, char *pType )
 #ifdef VDATA_GROUPNAME_SUPPORTED
        if ( pTypeObj->pszGroupName != NULL )
        {
-               strcat( szTypeValue, pTypeObj->pszGroupName );
-               strcat( szTypeValue, "." );
+               g_strlcat( szTypeValue, pTypeObj->pszGroupName, total);
+               g_strlcat( szTypeValue, ".", total);
        }
 #endif // VDATA_GROUPNAME_SUPPORTED
-       strcat( szTypeValue, pType );
+       g_strlcat( szTypeValue, pType, total);
 
        pTemp = __VCardParamEncode( pTypeObj, &enc );
        if ( pTemp != NULL )
@@ -1273,7 +1275,7 @@ __VCardTypeEncode( VObject *pTypeObj, char *pType )
                        VDATA_TRACE_END;
                        return NULL;
                }
-               strcat( szTypeValue, pTemp );
+               g_strlcat( szTypeValue, pTemp, total);
                VFREE( pTemp );
                pTemp = NULL;
        }
@@ -1311,7 +1313,7 @@ __VCardTypeEncode( VObject *pTypeObj, char *pType )
                        memset( pEncode, '\0', len+20 );
 
                        if(strcmp(pType, pszCardTypeList[19]) != 0)     {
-                               strcat( pEncode, pTypeObj->pszValue[i] );
+                               g_strlcat( pEncode, pTypeObj->pszValue[i], len+20);
                                _VEscape(pEncode);
                        }
                        else
@@ -1321,8 +1323,8 @@ __VCardTypeEncode( VObject *pTypeObj, char *pType )
                        char    buf[1000];
                        strncpy( buf, pTypeObj->pszValue[i], 999 );
                        _VEscape( buf );
-                       strcat( pEncode, ";" );
-                       strcat( pEncode, buf );
+                       g_strlcat( pEncode, ";", len+20);
+                       g_strlcat( pEncode, buf, len+20);
                }
        }
 
@@ -1453,8 +1455,8 @@ __VCardParamEncode(VObject* pTypeObj, int* pEnc)
                /** appending paramter name. */
                strcat( szParam, ";" );
                if(pTemp->parameter != VCARD_PARAM_TYPE) {
-                       strcat( szParam, pszCardParamList[pTemp->parameter] );
-                       strcat( szParam, "=" );
+                       g_strlcat( szParam, pszCardParamList[pTemp->parameter], len);
+                       g_strlcat( szParam, "=", len);
                }
 
                /** Set Parameter Value name. */
@@ -1498,8 +1500,8 @@ __VCardParamEncode(VObject* pTypeObj, int* pEnc)
                                                return NULL;
                                        }
 
-                                       strcat( szParam, pList[i].szName );
-                                       strcat( szParam, "; " );
+                                       g_strlcat( szParam, pList[i].szName, len);
+                                       g_strlcat( szParam, "; ", len);
                                }
 
                                sNum <<= 1;
index a924ad2..efafb75 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 
@@ -315,6 +315,8 @@ _VB64Decode( char *Dest, char *Src )
 
        len = __VBase64Check( Src );
 
+       VDATA_TRACE("total length of Src except non-base64 value = %d", len);
+
        while ( *Encoded )
        {
                for ( i = 0; i < 3; i++ )
index 3311470..41c61f4 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #include "VTypes.h"
@@ -835,10 +835,14 @@ vmsg_decode( char *pMsgRaw )
 
        SysRequireEx(pMsgRaw != NULL, NULL);
        len = strlen(pMsgRaw);
+       VDATA_TRACE("length of pCardRaw = %d", len);
+
        len = _VUnfoldingNoSpec(pMsgRaw, VMESSAGE);
        pMsgRawTmp = pMsgRaw;
        len = _VManySpace2Space( pMsgRaw );
 
+       VDATA_TRACE("ret value of _VManySpace2Space = %d", len);
+
        if(!__VIsVmsgFile(pMsgRaw, CHECK_START)) {
                VFREE(pMsgRawTmp);
                VDATA_TRACE_END
@@ -1100,6 +1104,7 @@ vmsg_decode( char *pMsgRaw )
 CATCH :
        VFREE(pTemp);
 CATCH1 :
+       VFREE(szMsgBegin);
        VFREE(pMsgRawTmp);
        __VMsgFreeVTreeMemory(pVMsg);
        VDATA_TRACE_END
@@ -1211,7 +1216,6 @@ vmsg_encode( VTree *pVMsgRaw )
                                        VDATA_TRACE("pTemp : %s", encoded);
                                        VFREE( pTemp );
                                        VFREE( encoded );
-                                       VFREE(pVMsgRes);
                                        break;
                                }
                                else
@@ -1411,8 +1415,8 @@ __VMsgTypeEncode( VObject *pTypeObj, char *pType )
                        char    buf[1000];
                        strncpy( buf, pTypeObj->pszValue[i], 999 );
                        _VEscape( buf );
-                       strcat( pEncode, ";" );
-                       strcat( pEncode, buf );
+                       g_strlcat( pEncode, ";" , len+20);
+                       g_strlcat( pEncode, buf , len+20);
                }
        }
 
@@ -1547,10 +1551,10 @@ __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
                }
 
                /** appending paramter name. */
-               strcat( szParam, ";" );
+               g_strlcat( szParam, ";" , len);
                if(pTemp->parameter != VMSG_PARAM_TYPE) {
-                       strcat( szParam, pszMsgParamList[pTemp->parameter] );
-                       strcat( szParam, "=" );
+                       g_strlcat( szParam, pszMsgParamList[pTemp->parameter], len);
+                       g_strlcat( szParam, "=", len);
                }
 
                /** Set Parameter Value name. */
@@ -1594,8 +1598,8 @@ __VMsgParamEncode(VObject* pTypeObj, int* pEnc)
                                                return NULL;
                                        }
 
-                                       strcat( szParam, pList[i].szName );
-                                       strcat( szParam, "; " );
+                                       g_strlcat( szParam, pList[i].szName, len);
+                                       g_strlcat( szParam, "; ", len);
                                }
 
                                sNum <<= 1;
index ccf2695..4079e2c 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef _VCARD_H
index ea6c127..ddf2f6a 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef _VMSG_H
index b37921c..655b53f 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef _VTYPES_H
index f938f92..4e3cb87 100755 (executable)
@@ -1,17 +1,17 @@
 /*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
 */
 
 #ifndef _VOBJECT_H
@@ -22,7 +22,7 @@
 #include "stdlib.h"
 #include "string.h"
 #include "ctype.h"
-
+#include <glib.h>
 #include <dlog.h>
 
 #ifdef __cplusplus
@@ -49,7 +49,13 @@ extern "C" {
                return retValue; }\
        else {;}
 #else
-#define VDATA_TRACE(fmt, arg...)
+#define USER_TAG "MSG_SERVICE"
+#define VDATA_TRACE(fmt, arg...) \
+       do\
+       {\
+               SLOG(LOG_DEBUG, USER_TAG, "\n[calendarui] %s:%d: " fmt "\n", __FUNCTION__, __LINE__, ##arg); \
+       } while (0)
+
 #define VDATA_TRACE_LINE()
 #define SysRequireEx(expr, retValue)
 #endif
diff --git a/vobject-engine/test_code/CQ_VCARD.c b/vobject-engine/test_code/CQ_VCARD.c
deleted file mode 100755 (executable)
index c438cdc..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdio.h>
-
-extern void utc_vdata_vcard_decode_1();
-extern void utc_vdata_vcard_decode_2();
-extern void utc_vdata_vcard_decode_3();
-extern void utc_vdata_vcard_decode_4();
-extern void utc_vdata_vcard_decode_5();
-extern void utc_vdata_vcard_decode_6();
-extern void utc_vdata_vcard_decode_7();
-extern void utc_vdata_vcard_encode_1();
-extern void utc_vdata_vcard_encode_0();
-extern void utc_vdata_vcard_encode_2();
-extern void utc_vdata_vcard_encode_3();
-extern void utc_vdata_vcard_encode_4();
-extern void utc_vdata_vcard_encode_5();
-extern void utc_vdata_vcard_encode_6();
-extern void utc_vdata_vcard_encode_7();
-extern void utc_vdata_vcard_encode_8();
-
-int CQ_TEST() {
-#if 0
-       printf("\n################################### VCard CQ Test  ##################################\n");
-       printf("[TEST CASE] utc_vdata_vcard_decode_1 : decode a raw buffer to a tree.\n");
-       utc_vdata_vcard_decode_1();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_decode_2 :  decode a raw buffer without begin token to a tree.\n");
-       utc_vdata_vcard_decode_2();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_decode_3 : decode a raw buffer without end token to a tree.\n");
-       utc_vdata_vcard_decode_3();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_decode_4 : decode a raw buffer having invalid version tag to a tree.\n");
-       utc_vdata_vcard_decode_4();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_decode_5 : decode a raw buffer without having crlf in between two tokens to a tree.\n");
-       utc_vdata_vcard_decode_5();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_decode_6 : decode a raw buffer having some invalid token to a tree.\n");
-       utc_vdata_vcard_decode_6();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_decode_7 : decode a NULL raw buffer to a tree.\n");
-       utc_vdata_vcard_decode_7();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_0 : \n");
-       utc_vdata_vcard_encode_0();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_1 : encode a tree to a buffer.\n");
-       utc_vdata_vcard_encode_1();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_2 : encode a tree with tree type as vcalendar to a buffer.\n");
-       utc_vdata_vcard_encode_2();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_3 : encode a tree with all the vobjects as NULL to a buffer.\n");
-       utc_vdata_vcard_encode_3();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_4 : encode a tree with an object having property as very high value to a buffer.\n");
-       utc_vdata_vcard_encode_4();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_5 : encode a NULL tree to a buffer.\n");
-       utc_vdata_vcard_encode_5();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_6 : encode a tree with an object having property but no other value to a buffer.\n");
-       utc_vdata_vcard_encode_6();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_7 : encode a tree with an object having value count greater than actual vales to a buffer.\n");
-       utc_vdata_vcard_encode_7();
-       printf("\n\n[TEST CASE] utc_vdata_vcard_encode_8 : encode a tree with tree type as a high value to a buffer.\n");
-       utc_vdata_vcard_encode_8();
-       printf("\n################################### VCard CQ Test  ##################################\n\n");
-#endif
-
-       return 0;
-}
-
-int main(int argc, char** argv) {
-
-       CQ_TEST();
-}
diff --git a/vobject-engine/test_code/uts_vdata_vcard_decode.c b/vobject-engine/test_code/uts_vdata_vcard_decode.c
deleted file mode 100755 (executable)
index ad2daeb..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <VCard.h>
-#include <VTypes.h>
-#include <glib.h>
-
-#define MT_CHECK_EQUAL(arg1, arg2) arg1 != arg2 ? \
-       fprintf(stderr,"[VOBJECT-TEST-CASE] %s %s:%d NOT EQUAL\n",__FILE__,__FUNCTION__,__LINE__) :\
-       fprintf(stderr,"[VOBJECT-TEST-CASE] %s %s:%d EQUAL\n",__FILE__,__FUNCTION__,__LINE__);
-
-#define VDATA_TEST_TRACE(fmt, arg...) \
-       do { {fprintf(stderr, "[VOBJECT-TEST-CASE] %s %s:%d: " fmt,__FILE__,__FUNCTION__, __LINE__, ##arg);}}while (false);
-
-
-/** decode a raw buffer to a tree */
-void utc_vdata_vcard_decode_1()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-       VDATA_TEST_TRACE("call executed \n");
-
-       if(!(tree != NULL)) return;
-
-       VDATA_TEST_TRACE("treetype is %d \n", tree->treeType);
-
-       if (!(tree->pTop)){
-               VDATA_TEST_TRACE("decodeing faili - utc_vdata_vcard_decode_%d",1);
-               return;
-       }
-       VDATA_TEST_TRACE ("top property is %d \n", tree->pTop->property);
-       VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pTop->pszValue));
-
-       if (tree->pTop->pParam){
-               VDATA_TEST_TRACE ("top param is %d \n", tree->pTop->pParam->parameter);
-               VDATA_TEST_TRACE ("top param val is %d \n", tree->pTop->pParam->paramValue);
-       }
-
-       if (tree->pCur){
-               VDATA_TEST_TRACE ("cur property is %d \n", tree->pCur->property);
-               VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pCur->pszValue));
-       }
-
-       if (!(tree->pTop->pSibling)){
-               VDATA_TEST_TRACE("decodeing faili - utc_vdata_vcard_decode_%d",1);
-               return;
-       }
-
-       VDATA_TEST_TRACE ("sibling not NULL \n");
-       VDATA_TEST_TRACE ("sibling property is %d \n", tree->pTop->pSibling->property);
-       VDATA_TEST_TRACE ("sibling property value is %s \n", *(tree->pTop->pSibling->pszValue));
-
-       if (tree->pTop->pSibling->pParam){
-               VDATA_TEST_TRACE ("sibling param is %d \n", tree->pTop->pSibling->pParam->parameter);
-               VDATA_TEST_TRACE ("sibling param val is %d \n", tree->pTop->pSibling->pParam->paramValue);
-       }
-
-       VDATA_TEST_TRACE("decodeing success - utc_vdata_vcard_decode_%d\n",1);
-
-       VObject* pSibling2 = tree->pTop->pSibling->pSibling;
-       if (!pSibling2)
-               return;
-
-       VDATA_TEST_TRACE ("sibling2 not NULL \n");
-       VDATA_TEST_TRACE ("sibling2 property is %d \n", pSibling2->property);
-       VDATA_TEST_TRACE ("sibling2 property value is %s \n", *(pSibling2->pszValue));
-
-       if (pSibling2->pParam){
-               VDATA_TEST_TRACE ("sibling param is %d \n", pSibling2->pParam->parameter);
-               VDATA_TEST_TRACE ("sibling param val is %d \n", pSibling2->pParam->paramValue);
-       }
-
-       if (tree->pTop->pParent)
-               VDATA_TEST_TRACE ("parent not NULL \n");
-       if (tree->pTop->pChild)
-               VDATA_TEST_TRACE ("child not NULL \n");
-
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
-
-/** decode a raw buffer without begin token to a tree */
-void utc_vdata_vcard_decode_2()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("VERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-       VDATA_TEST_TRACE("call executed \n");
-
-       if(!(tree != NULL)) VDATA_TEST_TRACE("tree is null");
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
-
-/*decode a raw buffer without end token to a tree*/
-void utc_vdata_vcard_decode_3()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531");
-
-       VDATA_TEST_TRACE("%s\n", buffer);
-       tree = VCardDecode(buffer);
-       VDATA_TEST_TRACE("call executed \n");
-
-       if(!tree) return;
-
-       VDATA_TEST_TRACE ("treetype is %d \n", tree->treeType);
-
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
-/*decode a raw buffer having invalid version tag to a tree*/
-void utc_vdata_vcard_decode_4()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVE:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-
-       VDATA_TEST_TRACE ("call executed \n");
-       VDATA_TEST_TRACE ("treetype is %d \n", tree->treeType);
-
-       if (!(tree->pTop)){
-               VDATA_TEST_TRACE ("tree->pTop null. \n");
-               return;
-       }
-
-       VDATA_TEST_TRACE ("top property is %d \n", tree->pTop->property);
-       VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pTop->pszValue));
-
-       MT_CHECK_EQUAL(tree->pTop->property, (int)VCARD_TYPE_N);
-
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
-
-/** decode a raw buffer without having crlf in between two tokens to a tree */
-void utc_vdata_vcard_decode_5()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARDVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-       VDATA_TEST_TRACE ("call executed \n");
-       VDATA_TEST_TRACE ("treetype is %d \n", tree->treeType);
-
-       if (!(tree->pTop)){
-               VDATA_TEST_TRACE ("tree->pTop null. \n");
-               return;
-       }
-
-       VDATA_TEST_TRACE ("top property is %d \n", tree->pTop->property);
-       VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pTop->pszValue));
-
-       MT_CHECK_EQUAL(tree->pTop->property, (int)VCARD_TYPE_N);
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
-
-/*decode a raw buffer having some invalid token to a tree*/
-void utc_vdata_vcard_decode_6()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSIOOOONNNN:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-       VDATA_TEST_TRACE ("call executed \n");
-       VDATA_TEST_TRACE ("treetype is %d \n", tree->treeType);
-
-       if (!(tree->pTop)){
-               VDATA_TEST_TRACE ("tree->pTop null. \n");
-               return;
-       }
-
-       VDATA_TEST_TRACE ("top property is %d \n", tree->pTop->property);
-       VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pTop->pszValue));
-
-       MT_CHECK_EQUAL(tree->pTop->property, (int)VCARD_TYPE_N);
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
-
-/*decode a NULL raw buffer to a tree*/
-void utc_vdata_vcard_decode_7()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       tree = VCardDecode(buffer);
-       VDATA_TEST_TRACE ("call executed \n");
-
-       MT_CHECK_EQUAL((VTree*)NULL, tree);
-
-       if(buffer != NULL)
-               g_free(buffer);
-}
diff --git a/vobject-engine/test_code/uts_vdata_vcard_encode.c b/vobject-engine/test_code/uts_vdata_vcard_encode.c
deleted file mode 100755 (executable)
index c08345c..0000000
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
-* Copyright 2012-2013  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <VCalendar.h>
-#include <VCard.h>
-#include <VTypes.h>
-#include <glib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#define MT_CHECK_EQUAL(arg1, arg2) arg1 != arg2 ? \
-  fprintf(stderr,"[VOBJECT-TEST-CASE] %s %s:%d NOT EQUAL",__FILE__,__FUNCTION__,__LINE__) :\
-  fprintf(stderr,"[VOBJECT-TEST-CASE] %s %s:%d EQUAL",__FILE__,__FUNCTION__,__LINE__);
-
-#define MT_CHECK_NOT_EQUAL(arg1, arg2) arg1 != arg2 ? \
-  fprintf(stderr,"[VOBJECT-TEST-CASE] %s %s:%d NOT EQUAL",__FILE__,__FUNCTION__,__LINE__) :\
-  fprintf(stderr,"[VOBJECT-TEST-CASE] %s %s:%d EQUAL",__FILE__,__FUNCTION__,__LINE__);
-
-#define VDATA_TEST_TRACE(fmt, arg...) \
-  do { {fprintf(stderr, "[VOBJECT-TEST-CASE] %s %s:%d: " fmt "\n" ,__FILE__,__FUNCTION__, __LINE__, ##arg);}}while (false);
-
-#define null NULL
-
-/* */
-void
-utc_vdata_vcard_encode_0() {
-
-       FILE* fp;
-       char* buffer;
-       char* temp;
-       VTree *tree = NULL;
-       VObject*        pTemp = NULL;
-       VParam*         pTmpParam = NULL;
-
-       struct stat stat_object;
-       VDATA_TEST_TRACE("START");
-
-       if(lstat("sample.vcf", &stat_object) != 0) {
-               VDATA_TEST_TRACE("error get file status..");
-               return ;
-       }
-
-       if( (buffer = (char*) malloc(stat_object.st_size)) == NULL )
-               return ;
-
-       VDATA_TEST_TRACE("sample.vcf file size : %d", stat_object.st_size);
-
-       if( (fp = fopen("sample.vcf",  "r")) == NULL )
-               return ;
-       fread(buffer, stat_object.st_size, sizeof(char), fp);
-       fclose(fp);
-
-       VDATA_TEST_TRACE("~~~~~");
-
-       tree = VCardDecode(buffer);
-
-       pTemp = tree->pTop;
-       pTmpParam = pTemp->pParam;
-
-       while(1) {
-               //VDATA_TEST_TRACE("%d %d",pTemp->property, VCARD_TYPE_PHOTO);
-               temp = pTemp->pszValue[0];
-               VDATA_TEST_TRACE("%s",temp);
-
-               if (pTemp->pSibling != NULL) {
-                       pTemp = pTemp->pSibling;
-                       pTmpParam = pTemp->pParam;
-               }
-               else {
-                       break;
-               }
-       }
-
-       VDATA_TEST_TRACE("END");
-
-
-       return ;
-
-}
-
-
-/*encode a tree to a buffer*/
-void utc_vdata_vcard_encode_1()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-       tree->pTop->property = 32;
-
-       char *temp = g_strdup("2.2");;
-       tree->pTop->pszValue[0] = temp;
-
-       if(buffer != NULL) {
-       g_free(buffer);
-       buffer = NULL;
-       }
-
-       VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pTop->pszValue));
-       buffer = VCardEncode(tree);
-
-       VCalFreeVTreeMemory(tree);
-       tree = VCardDecode(buffer);
-
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_NOT_EQUAL((gchar *)NULL, buffer);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       if(temp != NULL)
-               g_free(temp);
-
-       buffer = NULL;
-       temp = NULL;
-}
-/*encode a tree with tree type as vcalendar to a buffer*/
-void utc_vdata_vcard_encode_2()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-       tree = VCardDecode(buffer);
-
-       tree->treeType = VCALENDAR;
-
-       if(buffer != NULL)
-       g_free(buffer);
-       buffer = NULL;
-
-       buffer = VCardEncode(tree);
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_EQUAL((gchar *)NULL, buffer);
-       VCalFreeVTreeMemory(tree);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       buffer = NULL;
-}
-
-/*encode a tree with all the vobjects as NULL to a buffer*/
-void utc_vdata_vcard_encode_3()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       tree = g_new0(VTree, 1);
-       tree->treeType = VCARD;
-       tree->pTop = NULL;
-       tree->pCur = NULL;
-
-       buffer = VCardEncode(tree);
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_NOT_EQUAL((gchar *)NULL, buffer);
-       VCalFreeVTreeMemory(tree);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       buffer = NULL;
-}
-
-/*encode a tree with an object having property as very high value to a buffer*/
-void utc_vdata_vcard_encode_4()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-       tree = VCardDecode(buffer);
-
-       tree->pTop->property = 65;
-
-       if(buffer != NULL)
-       g_free(buffer);
-
-       buffer = NULL;
-
-       buffer = VCardEncode(tree);
-
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_NOT_EQUAL((gchar*)NULL, buffer);
-
-       VCalFreeVTreeMemory(tree);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       buffer = NULL;
-}
-
-/*encode a NULL tree to a buffer*/
-void utc_vdata_vcard_encode_5()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = VCardEncode(tree);
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_EQUAL((gchar *)NULL, buffer);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       buffer = NULL;
-}
-
-/*encode a tree with an object having property but no other value to a buffer*/
-void utc_vdata_vcard_encode_6()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-       tree = VCardDecode(buffer);
-
-       tree->pTop->property = 14;
-       tree->pTop->pszValue[0] = NULL;
-
-       if(buffer != NULL)
-       g_free(buffer);
-
-       buffer = NULL;
-
-       buffer = VCardEncode(tree);
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_NOT_EQUAL((gchar *)NULL, buffer);
-       VCalFreeVTreeMemory(tree);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       buffer = NULL;
-}
-
-/*encode a tree with an object having value count greater than actual vales to a buffer*/
-void utc_vdata_vcard_encode_7()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-       gchar *temp;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-       tree = VCardDecode(buffer);
-
-       tree->pTop->property = VCARD_TYPE_N;
-       tree->pTop->valueCount = 5;
-       temp = g_strdup( "amit");
-       tree->pTop->pszValue[0] = temp;
-
-
-       if(buffer != NULL)
-       g_free(buffer);
-
-       buffer = NULL;
-
-       VDATA_TEST_TRACE ("top property value is %s \n", *(tree->pTop->pszValue));
-       buffer = VCardEncode(tree);
-
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_NOT_EQUAL((gchar *)NULL, buffer);
-       VCalFreeVTreeMemory(tree);
-
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       if(temp != NULL)
-               g_free(temp);
-
-       buffer = NULL;
-       temp = NULL;
-}
-
-/*encode a tree with tree type as a high value to a buffer*/
-void utc_vdata_vcard_encode_8()
-{
-       gchar *buffer = NULL;
-       VTree *tree = NULL;
-
-       buffer = g_strdup("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Martin;Stephen\r\nTEL;HOME;VOICE:+1 (210) 555-1357\r\nTEL;HOME;FAX:+1 (210) 555-0864\r\nADR;WORK;PARCEL;POSTAL;DOM:123 Cliff Ave.;Big Town;CA;97531\r\nEND:VCARD");
-
-       tree = VCardDecode(buffer);
-
-       tree->treeType = 15;
-
-       if(buffer != NULL)
-       g_free(buffer);
-
-       buffer = NULL;
-
-       buffer = VCardEncode(tree);
-       VDATA_TEST_TRACE ("call executed buffer is %s\n", buffer);
-       MT_CHECK_EQUAL((gchar*)NULL, buffer);
-       VCalFreeVTreeMemory(tree);
-
-       if(buffer != NULL)
-               g_free(buffer);
-
-       buffer = NULL;
-}
-