Fix build error 48/37748/1 submit/tizen/20150403.102047 submit/tizen/20150406.061942 submit/tizen_common/20150403.091224 submit/tizen_mobile/20150403.091231 submit/tizen_tv/20150403.091238 submit/tizen_wearable/20150403.091245
authorseunggi.hong <seunggi.hong@samsung.com>
Fri, 3 Apr 2015 09:09:52 +0000 (18:09 +0900)
committerseunggi.hong <seunggi.hong@samsung.com>
Fri, 3 Apr 2015 09:09:52 +0000 (18:09 +0900)
Change-Id: I01b39ae0961907551abf1e8c48c469855a0470ef
Signed-off-by: seunggi.hong <seunggi.hong@samsung.com>
64 files changed:
config/msg-service-db.CDMA.sql [new file with mode: 0755]
config/msg-service-db.sql [new file with mode: 0755]
config/sysinfo-message.xml [new file with mode: 0755]
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 [new file with mode: 0755]
externals/MsgSoundPlayer.cpp [new file with mode: 0755]
externals/MsgSpamFilter.cpp [new file with mode: 0755]
include/common/MsgSmil.h [new file with mode: 0755]
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 [new file with mode: 0755]
include/utils/MsgJsonParser.h [new file with mode: 0755]
include/utils/MsgSerialize.h [new file with mode: 0755]
include/utils/MsgZoneManager.h [new file with mode: 0755]
mms-plugin.manifest [new file with mode: 0755]
msg-service-tools.manifest [new file with mode: 0755]
msg-service.manifest [new file with mode: 0755]
msg-service.rule [new file with mode: 0755]
packaging/msg-server.service [new file with mode: 0755]
packaging/msg-server.socket [new file with mode: 0644]
plugin/mms_plugin/MmsPluginAppBase.cpp [new file with mode: 0755]
plugin/mms_plugin/MmsPluginComposer.cpp [new file with mode: 0755]
plugin/mms_plugin/MmsPluginTcs.cpp [new file with mode: 0755]
plugin/mms_plugin/include/MmsPluginAppBase.h [new file with mode: 0755]
plugin/mms_plugin/include/MmsPluginComposer.h [new file with mode: 0755]
plugin/mms_plugin/include/MmsPluginTcs.h [new file with mode: 0755]
plugin/sms_cdma_plugin/CMakeLists.txt [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginCallback.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginCodec.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginEventHandler.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginMain.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginParamCodec.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginSetting.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginStorage.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginTransport.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginUAManager.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/SmsCdmaPluginWapPushHandler.cpp [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginCallback.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginCodec.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginEventHandler.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginMain.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginParamCodec.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginSetting.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginStorage.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginTransport.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginTypes.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginUAManager.h [new file with mode: 0755]
plugin/sms_cdma_plugin/include/SmsCdmaPluginWapPushHandler.h [new file with mode: 0755]
plugin/sms_plugin/SmsPluginDSHandler.cpp [new file with mode: 0755]
plugin/sms_plugin/include/SmsPluginDSHandler.h [new file with mode: 0755]
sms-plugin.manifest [new file with mode: 0755]
utils/MsgJsonParser.cpp [new file with mode: 0755]
utils/MsgSerialize.cpp [new file with mode: 0755]
utils/MsgSmil.cpp [new file with mode: 0755]
utils/MsgZoneManager.cpp [new file with mode: 0755]

diff --git a/config/msg-service-db.CDMA.sql b/config/msg-service-db.CDMA.sql
new file mode 100755 (executable)
index 0000000..6f22520
--- /dev/null
@@ -0,0 +1,327 @@
+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
+);
+
+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 ,
+
+       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_ID INTEGER PRIMARY KEY ,
+       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 ,
+       CHANNEL_ACTIVATION INTEGER DEFAULT 0,
+       CHANNEL_FROM INTEGER DEFAULT 0,
+       CHANNEL_TO INTEGER DEFAULT 0,
+       CHANNEL_NAME TEXT NOT NULL DEFAULT ''
+);
+
+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_CDMA_CB_CHANNEL_INFO_TABLE
+(
+       CHANNEL_ID INTEGER PRIMARY KEY,
+       CHANNEL_ACTIVATION INTEGER DEFAULT 0,
+       CHANNEL_CATEGORY INTEGER DEFAULT 0,
+       CHANNEL_LANGUAGE INTEGER DEFAULT 0,
+       CHANNEL_NAME TEXT NOT NULL DEFAULT ''
+);
+
+CREATE TABLE MSG_UNIQUENESS_INFO_TABLE
+(
+       MSG_ID INTEGER NOT NULL,
+       TELE_MSG_ID INTEGER NOT NULL,
+       ADDRESS TEXT DEFAULT '',
+       SUB_ADDRESS TEXT DEFAULT '',
+       TIME_STAMP TEXT DEFAULT '',
+       TELESVC_ID INTEGER NOT NULL,
+
+       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_CDMA_CB_CHANNEL_INFO_TABLE VALUES (0, 1, 4096, 1, 'Presidential');
+INSERT INTO MSG_CDMA_CB_CHANNEL_INFO_TABLE VALUES (1, 1, 4097, 1, 'Extreme');
+INSERT INTO MSG_CDMA_CB_CHANNEL_INFO_TABLE VALUES (2, 1, 4098, 1, 'Severe');
+INSERT INTO MSG_CDMA_CB_CHANNEL_INFO_TABLE VALUES (3, 1, 4099, 1, 'Amber');
+INSERT INTO MSG_CDMA_CB_CHANNEL_INFO_TABLE VALUES (4, 0, 4100, 1, 'Test');
diff --git a/config/msg-service-db.sql b/config/msg-service-db.sql
new file mode 100755 (executable)
index 0000000..a508b79
--- /dev/null
@@ -0,0 +1,301 @@
+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 ''
+);
+
+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);
diff --git a/config/sysinfo-message.xml b/config/sysinfo-message.xml
new file mode 100755 (executable)
index 0000000..be1ef51
--- /dev/null
@@ -0,0 +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="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..cc8eef5
--- /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..1c53a3f
--- /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..58f403a
--- /dev/null
@@ -0,0 +1,2864 @@
+/*
+ * 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>
+#ifndef MSG_WEARABLE_PROFILE
+#include <notification.h>
+#include <notification_internal.h>
+#include <feedback.h>
+#include <badge.h>
+#endif // MSG_WEARABLE_PROFILE
+}
+
+#ifndef MSG_WEARABLE_PROFILE
+
+/*======================================================================================*/
+/*                                                             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);
+
+
+// Alarm
+void MsgNotiSoundRepeatAlarmCB(int alarmId);
+void MsgSoundCreateRepeatAlarm(int RepeatTime);
+void MsgSoundSetRepeatAlarm();
+
+void sendMsgReplyPopup(MSG_NOTI_INFO_S *noti_info);
+
+#endif // MSG_WEARABLE_PROFILE
+
+/*======================================================================================*/
+/*                                                             FUNCTION IMPLEMENTATION                                                                 */
+/*======================================================================================*/
+
+
+msg_error_t MsgInsertNotification(MSG_MESSAGE_INFO_S *msg_info)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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;
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+
+       return err;
+
+}
+
+msg_error_t MsgDeleteReportNotification(const char *addr)
+{
+       MSG_BEGIN();
+
+       msg_error_t msg_err = MSG_SUCCESS;
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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_SEC_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_SEC_DEBUG("normalized number = %s", normalAddr);
+
+                               if (g_str_has_suffix(addr, normalAddr)) {
+                                       if (notification_delete(noti_h) == NOTIFICATION_ERROR_NONE) {
+                                               MSG_SEC_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;
+                               }
+                       }
+               }
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       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;
+#ifndef MSG_WEARABLE_PROFILE
+       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_SEC_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
+
+__END_OF_REFRESH_NOTI :
+       clearInfoData(noti_h, &noti_info);
+#endif // MSG_WEARABLE_PROFILE
+       return msg_err;
+}
+
+msg_error_t MsgRefreshNotification(msg_notification_type_t noti_type, bool bFeedback, bool bTicker)
+{
+
+       msg_error_t msg_err = MSG_SUCCESS;
+#ifndef MSG_WEARABLE_PROFILE
+       notification_h noti_h = NULL;
+       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);
+#endif // MSG_WEARABLE_PROFILE
+       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;
+#ifndef MSG_WEARABLE_PROFILE
+       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);
+#endif // MSG_WEARABLE_PROFILE
+       return msg_err;
+}
+
+
+void MsgRefreshAllNotification(bool bWithSimNoti, bool bFeedback, bool bTickerNoti)
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+       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);
+
+#endif // MSG_WEARABLE_PROFILE
+       MSG_END();
+}
+
+
+void MsgDeleteNotification(msg_notification_type_t noti_type, int simIndex)
+{
+#ifndef MSG_WEARABLE_PROFILE
+       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, simIndex);
+               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, simIndex);
+#endif // MSG_WEARABLE_PROFILE
+}
+
+
+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();
+#ifndef MSG_WEARABLE_PROFILE
+       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_SEC_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);
+
+#endif // MSG_WEARABLE_PROFILE
+       MSG_END();
+}
+
+
+msg_error_t MsgInitNoti()
+{
+#ifndef MSG_WEARABLE_PROFILE
+       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, -1);
+#endif
+               MsgRefreshAllNotification(false, true, true);           // On Booting
+               MsgInitReportNotiList();
+       }
+       else {
+               MSG_DEBUG("Notification server is not available. Init is defered");
+#ifndef MSG_NOTI_INTEGRATION
+               MSG_NOTI_INFO_S *delNotiInfo = (MSG_NOTI_INFO_S *)calloc(1, sizeof(MSG_NOTI_INFO_S));
+               delNotiInfo->type = MSG_NOTI_TYPE_SIM;
+               delNotiInfo->sim_idx = -1;
+
+               notification_add_deferred_task(MsgDeleteNotiCb, (void *)delNotiInfo);
+#endif
+               notification_add_deferred_task(MsgRefreshNotiCb, (void *)NULL);
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDeleteNoti(msg_notification_type_t noti_type, int simIndex)
+{
+#ifndef MSG_WEARABLE_PROFILE
+       bool bNotiSvcReady = false;
+
+       MSG_NOTI_INFO_S *delNotiInfo = (MSG_NOTI_INFO_S *)calloc(1, sizeof(MSG_NOTI_INFO_S));
+
+       delNotiInfo->type = noti_type;
+       delNotiInfo->sim_idx = simIndex;
+
+       bNotiSvcReady = notification_is_service_ready();
+
+       if (bNotiSvcReady == true) {
+               MSG_DEBUG("Notification server is available");
+               MsgDeleteNotiCb((void *)delNotiInfo);
+       } else {
+               MSG_DEBUG("Notification server is not available. Delete is defered");
+               notification_add_deferred_task(MsgDeleteNotiCb, (void *)delNotiInfo);
+       }
+#endif // MSG_WEARABLE_PROFILE
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
+{
+#ifndef MSG_WEARABLE_PROFILE
+       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);
+               }
+       }
+#endif // MSG_WEARABLE_PROFILE
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt)
+{
+#ifndef MSG_WEARABLE_PROFILE
+       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;
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+       return MSG_SUCCESS;
+}
+
+#ifndef MSG_WEARABLE_PROFILE
+
+void MsgRefreshNotiCb(void *data)
+{
+       MsgRefreshAllNotification(false, true, true);
+       MsgInitReportNotiList();
+
+       if (data) {
+               free(data);
+               data = NULL;
+       }
+
+       return;
+}
+
+
+void MsgDeleteNotiCb(void *data)
+{
+       if (data) {
+               MSG_NOTI_INFO_S *delNotiInfo = (MSG_NOTI_INFO_S *)data;
+
+               MsgDeleteNotification(delNotiInfo->type, delNotiInfo->sim_idx);
+
+               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);
+                       }
+                       break;
+               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;
+
+                               //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                               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);
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+
+                               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;
+
+                               //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                               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);
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                               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);
+
+       setPkgName(noti, noti_type);
+
+       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_SEC_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_ERR("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));
+
+       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       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);
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+
+       bool bPlaySound = false;
+       bool bPlayVibration = false;
+       bool bOnCall = false;
+
+       MsgSoundPlayer::instance()->MsgGetPlayStatus(bVoiceMail, &bPlaySound, &bPlayVibration, &bOnCall);
+
+       if (!bBlockingMode) { // check blocking mode.
+               if (bPlaySound) {
+                       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                       if (msg_tone_file_path)
+                               setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_USER_DATA, msg_tone_file_path);
+                       else {
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                               MSG_RINGTONE_TYPE_T ringtoneType = (MSG_RINGTONE_TYPE_T)MsgSettingGetInt(MSG_SETTING_RINGTONE_TYPE);
+                               if (ringtoneType == MSG_RINGTONE_TYPE_SILENT)
+                                       setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
+                               else
+                                       setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                       }
+#endif
+               } else {
+                       setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
+               }
+
+               if (bPlayVibration) {
+                       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                       if (contactInfo.vibrationPath[0] == '\0')
+                               setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
+                       else
+                               setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_USER_DATA, contactInfo.vibrationPath);
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                       } 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);
+
+                               //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                               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;
+                                               }
+                                       }
+                               }
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                               dbhandler->freeTable();
+
+                               MSG_SEC_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));
+
+                                               //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                                               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') {
+#else //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                                               if (addrInfo.addressVal[0] == '\0') {
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+                                                       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);
+       }
+}
+
+#endif // MSG_WEARABLE_PROFILE
diff --git a/externals/MsgSensorWrapper.cpp b/externals/MsgSensorWrapper.cpp
new file mode 100755 (executable)
index 0000000..84098af
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * 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 "MsgSensorWrapper.h"
+
+#ifndef MSG_WEARABLE_PROFILE
+#include <sensor_internal.h>
+
+/*==================================================================================================
+                                     VARIABLES
+==================================================================================================*/
+
+int sensorHandler = -1;
+
+msg_sensor_cb SensorCBFunction = NULL;
+
+#endif // MSG_WEARABLE_PROFILE
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
+#ifndef MSG_WEARABLE_PROFILE
+
+void MsgSensorCB(unsigned int event_type, sensor_event_data_t *event_data , void *data)
+{
+       int *my_event_data;
+
+       my_event_data = (int *)(event_data->event_data);
+
+       if (event_type == MOTION_ENGINE_EVENT_TOP_TO_BOTTOM)
+               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)) {
+                                       if(SensorCBFunction) SensorCBFunction();
+                               }
+               }
+}
+
+#endif // MSG_WEARABLE_PROFILE
+
+msg_error_t MsgSensorConnect()
+{
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       sensorHandler = sf_connect(MOTION_SENSOR);
+       if (sensorHandler < 0) {
+               MSG_DEBUG("sensor attach fail.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgSensorDisconnect()
+{
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       if(SensorCBFunction != NULL)
+               SensorCBFunction = NULL;
+
+       if (sensorHandler < 0)
+               return;
+
+       try
+       {
+               sf_stop(sensorHandler);
+       }
+       catch(int exception)
+       {
+               MSG_FATAL("sf_stop error[%d]", exception);
+       }
+       sf_disconnect(sensorHandler);
+
+#endif // MSG_WEARABLE_PROFILE
+
+}
+
+
+msg_error_t MsgRegSensorCB(msg_sensor_cb cb)
+{
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       int resultCondition = -1;
+
+       if (sensorHandler < 0) {
+               MSG_DEBUG("Not connected to sensor FW.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+       if(cb != NULL) {
+               // regist cb.
+               SensorCBFunction = cb;
+       } else {
+               MSG_DEBUG("cb is NULL.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+       resultCondition = sf_register_event(sensorHandler, MOTION_ENGINE_EVENT_TOP_TO_BOTTOM , NULL , MsgSensorCB,NULL);
+       if (resultCondition < 0) {
+               MSG_DEBUG("SLP_sensor_register_cb fail to gather data.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+       MSG_DEBUG("Start SF.");
+       resultCondition = sf_start(sensorHandler, 0);
+       if (resultCondition < 0) {
+               MSG_DEBUG("SLP_sensor_start fail.");
+               return MSG_ERR_UNKNOWN;
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       return MSG_SUCCESS;
+}
diff --git a/externals/MsgSoundPlayer.cpp b/externals/MsgSoundPlayer.cpp
new file mode 100755 (executable)
index 0000000..6d8c14b
--- /dev/null
@@ -0,0 +1,863 @@
+/*
+ * 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"
+
+#ifndef MSG_WEARABLE_PROFILE
+
+#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;
+
+#endif // MSG_WEARABLE_PROFILE
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF Functions
+==================================================================================================*/
+void MsgSoundRepeatAlarmCB(int alarmId)
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       MsgSoundPlayer::instance()->MsgSoundInitRepeatAlarm();
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+       return;
+}
+
+
+void MsgSensorCBStop()
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+#if 0
+       MsgSoundPlayer::instance()->MsgSoundPlayStop();
+#else
+       MsgDeleteNotification(MSG_NOTI_TYPE_ALL, -1);
+
+       MsgRefreshNotification(MSG_NOTI_TYPE_ALL, false, false);
+
+#ifndef MSG_NOTI_INTEGRATION
+       MsgRefreshNotification(MSG_NOTI_TYPE_SIM, false, false);
+#endif
+
+#endif
+
+#endif // MSG_WEARABLE_PROFILE
+
+       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)
+{
+
+#ifndef MSG_WEARABLE_PROFILE
+       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;
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       return 1;
+}
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF MsgSoundPlayer - Member Functions
+==================================================================================================*/
+MsgSoundPlayer* MsgSoundPlayer::pInstance = NULL;
+
+
+MsgSoundPlayer::MsgSoundPlayer()
+{
+
+#ifndef MSG_WEARABLE_PROFILE
+       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.");
+       }
+#endif // MSG_WEARABLE_PROFILE
+
+}
+
+
+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)
+{
+
+#ifndef MSG_WEARABLE_PROFILE
+       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;
+       }
+#endif // MSG_WEARABLE_PROFILE
+
+}
+
+
+bool MsgIsSoundPlayOnCall(void)
+{
+       bool bPlayOnCall = false;
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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|MM_SOUND_DEVICE_OUT_BT_SCO))
+                       bPlayOnCall = true;
+               else
+                       bPlayOnCall = false;
+
+               MSG_DEBUG("mm_sound_device_out=[0x%04x],bPlayOnCall=[%d]", soundOut, bPlayOnCall);
+       } else {
+               MSG_DEBUG("mm_sound_get_active_device() err=[%d]", err);
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       return bPlayOnCall;
+}
+
+
+void MsgSoundPlayer::MsgGetPlayStatus(bool bVoiceMail, bool *bPlaySound, bool *bPlayVibration, bool *bOnCall)
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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.");
+                       }
+               }
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayStart(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_SOUND_TYPE_T soundType)
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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;
+       }
+
+       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       /* 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.");
+               }
+       }
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       /* 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);
+       }
+       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       else {
+               MsgGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
+       }
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       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);
+       }
+
+       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       /* play vibration */
+       if (bPlayVibration) {
+               MsgSoundPlayVibration(contactInfo.vibrationPath, bOnCall);
+       }
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       // For repeatition.
+//     MsgSoundSetRepeatAlarm();
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayStop()
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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);
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayMelody(char *pMsgToneFilePath)
+{
+#ifndef MSG_WEARABLE_PROFILE
+
+       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);
+
+#endif // MSG_WEARABLE_PROFILE
+}
+
+
+void MsgSoundPlayer::MsgSoundPlayVibration(char *vibrationPath, bool isOnCall)
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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");
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+}
+
+void MsgSoundPlayer::MsgSoundPlayDtmf()
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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.");
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+}
+
+
+void MsgSoundPlayer::MsgSoundSetRepeatAlarm()
+{
+#ifndef MSG_WEARABLE_PROFILE
+
+       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);
+       }
+
+#endif // MSG_WEARABLE_PROFILE
+}
+
+
+void MsgSoundPlayer::MsgSoundCreateRepeatAlarm(int RepeatTime)
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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();
+
+#endif // MSG_WEARABLE_PROFILE
+}
+
+
+int MsgSoundPlayer::MsgSoundGetUnreadMsgCnt()
+{
+       int unreadCnt = 0;
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       // 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);
+
+#endif // MSG_WEARABLE_PROFILE
+
+       return unreadCnt;
+}
+
+void MsgSoundPlayer::MsgSoundInitRepeatAlarm()
+{
+       MSG_BEGIN();
+
+#ifndef MSG_WEARABLE_PROFILE
+
+       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);
+
+#endif // MSG_WEARABLE_PROFILE
+
+       MSG_END();
+}
diff --git a/externals/MsgSpamFilter.cpp b/externals/MsgSpamFilter.cpp
new file mode 100755 (executable)
index 0000000..86900c7
--- /dev/null
@@ -0,0 +1,319 @@
+/*
+ * 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 "MsgUtilFile.h"
+#include "MsgContact.h"
+#include "MsgCppTypes.h"
+#include "MsgGconfWrapper.h"
+#include "MsgSpamFilter.h"
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+msg_error_t MsgSetFilterOperation(bool bSetFlag)
+{
+       MSG_BEGIN();
+
+       if (MsgSettingSetBool(MSG_BLOCK_MESSAGE, bSetFlag) != MSG_SUCCESS) {
+               MSG_DEBUG("Error to set config data [%s]", MSG_BLOCK_MESSAGE);
+               return MSG_ERR_SET_SETTING;
+       }
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgGetFilterOperation(bool *pSetFlag)
+{
+       MSG_BEGIN();
+
+       MsgSettingGetBool(MSG_BLOCK_MESSAGE, pSetFlag);
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+bool MsgCheckFilter(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
+
+       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;
+
+       MsgGetFilterOperation(&filterFlag);
+
+       if (filterFlag == false) {
+               MSG_DEBUG("filter operation is not working");
+               return false;
+       }
+
+       // =======================================================================
+       // Check Filter by Address
+       // =======================================================================
+       int rowCnt = 0;
+
+       MSG_SEC_DEBUG("pMsg->addressList[0].addressVal [%s]", pMsgInfo->addressList[0].addressVal);
+
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       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 \
+                       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 \
+                       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_END, pMsgInfo->addressList[0].addressVal);
+
+       err = pDbHandle->getTable(sqlQuery, &rowCnt);
+
+       if (rowCnt > 0) {
+               MSG_SEC_DEBUG("Msg is Filtered by Address : [%s]", pMsgInfo->addressList[0].addressVal);
+               pDbHandle->freeTable();
+               pMsgInfo->folderId = MSG_SPAMBOX_ID;
+               return true;
+       } else {
+               MSG_SEC_DEBUG("Msg is NOT Filtered by Address : [%s]", pMsgInfo->addressList[0].addressVal);
+               pDbHandle->freeTable();
+       }
+
+       // =======================================================================
+       // Check Filter by Subject
+       // =======================================================================
+       // 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);
+
+       rowCnt = 0;
+
+       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];
+
+       char* pData = NULL;
+       AutoPtr<char> buf(&pData);
+
+       int fileSize = 0;
+       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 (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;
+                               }
+                               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);
+                                       pData[strlen(pMsgInfo->msgText)] = '\0';
+                               }
+                       }
+               } 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));
+                               pData[strlen(pMsgInfo->subject)] = '\0';
+                       }
+               }
+
+               // NULL value check
+               if (pData == NULL) {
+                       MSG_DEBUG("pData is NULL");
+
+                       bFiltered = false;
+                       break;
+               }
+
+               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_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;
+                                       break;
+                               }
+                       } else {
+                               MSG_DEBUG("MsgGetContactInfo() fail.");
+                       }
+#else
+                       MSG_DEBUG("Msg is Filtered by Subject [%s] Data [%s]", filterValue, pData);
+                       bFiltered = true;
+                       break;
+#endif
+               }
+       }
+
+       pDbHandle->freeTable();
+
+       if (bFiltered == true) {
+               MSG_DEBUG("Msg is Filtered by Subject");
+
+               pMsgInfo->folderId = MSG_SPAMBOX_ID;
+
+               return true;
+       } else {
+               MSG_DEBUG("Msg is NOT Filtered by Subject");
+       }
+
+       MSG_END();
+
+       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;
+}
+
+
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
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..ed51127
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * 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"
+
+// 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, int simIndex);
+
+void MsgRefreshAllNotification(bool bWithSimNoti, bool bFeedback, bool bTickerNoti);
+void MsgDeleteNotification(msg_notification_type_t noti_type, int simIndex);
+void MsgInitReportNotiList();
+
+char *getTranslateText(const char *pkg_name, const char *locale_dir, const char *text);
+
+#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
+
diff --git a/include/externals/MsgSpamFilter.h b/include/externals/MsgSpamFilter.h
new file mode 100755 (executable)
index 0000000..ea67d8e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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
+#define MSG_SPAM_FILTER_H
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "MsgFilterTypes.h"
+#include "MsgStorageTypes.h"
+#include "MsgInternalTypes.h"
+#include "MsgSqliteWrapper.h"
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+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
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__*/
+
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/MsgZoneManager.h b/include/utils/MsgZoneManager.h
new file mode 100755 (executable)
index 0000000..4056ce5
--- /dev/null
@@ -0,0 +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.
+*/
+
+#ifndef MSG_ZONE_MANAGER_H
+#define MSG_ZONE_MANAGER_H
+
+void MsgZoneInit();
+void MsgZoneClean();
+
+char* MsgZoneGetName(int fd);
+bool MsgZoneIsAllowed(int fd);
+
+
+void MsgZoneChange();
+void MsgZoneRevert();
+
+#endif // MSG_ZONE_MANAGER_H
+
diff --git a/mms-plugin.manifest b/mms-plugin.manifest
new file mode 100755 (executable)
index 0000000..2a0cec5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+  <request>
+    <domain name="_"/>
+  </request>
+</manifest>
diff --git a/msg-service-tools.manifest b/msg-service-tools.manifest
new file mode 100755 (executable)
index 0000000..c987f54
--- /dev/null
@@ -0,0 +1,10 @@
+<manifest>
+       <request>
+               <domain name="msg-service"/>
+       </request>
+
+       <assign>
+               <filesystem path="/etc/rc.d/init.d/msg-server" label="_" exec_label="none"/>
+               <filesystem path="/etc/config/sysinfo-message.xml" label="_"/>
+       </assign>
+</manifest>
diff --git a/msg-service.manifest b/msg-service.manifest
new file mode 100755 (executable)
index 0000000..138d9d6
--- /dev/null
@@ -0,0 +1,24 @@
+<manifest>
+       <define>
+               <domain name="msg-service" policy="restricted" plist="msg-service-tools"/>
+               <provide>
+                       <label name="msg-service::read"/>
+                       <label name="msg-service::write"/>
+               </provide>
+       </define>
+       <request>
+               <domain name="msg-service"/>
+       </request>
+       <assign>
+               <filesystem path="/usr/lib/libmsg_mapi.so.0" label="_"/>
+               <filesystem path="/usr/lib/libmsg_mapi.so.0.1.0" label="_"/>
+               <filesystem path="/usr/lib/libmsg_framework_handler.so" label="_"/>
+               <filesystem path="/usr/lib/libmsg_mms_plugin.so" label="_"/>
+               <filesystem path="/usr/lib/libmsg_plugin_manager.so" label="_"/>
+               <filesystem path="/usr/lib/libmsg_sms_plugin.so" label="_"/>
+               <filesystem path="/usr/lib/libmsg_transaction_manager.so" label="_"/>
+               <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="_"/>
+       </assign>
+</manifest>
diff --git a/msg-service.rule b/msg-service.rule
new file mode 100755 (executable)
index 0000000..00626ca
--- /dev/null
@@ -0,0 +1,51 @@
+msg-service msg-service::db rw---- ------
+msg-service msg-service::vconf 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---- ------
+msg-service device::app_logging -w---- ------
+msg-service device::sys_logging -w---- ------
+msg-service system::share -wx--- ------
+msg-service system::vconf_system r----l ------
+msg-service pkgmgr::db r----l ------
+msg-service ail::db r----- ------
+msg-service badge::db r----l ------
+msg-service notification::db r----l ------
+
+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/packaging/msg-server.service b/packaging/msg-server.service
new file mode 100755 (executable)
index 0000000..f21f414
--- /dev/null
@@ -0,0 +1,16 @@
+[Unit]
+Description=Message server
+After=tizen-runtime.target contacts-service.service
+Requires=tizen-runtime.target contacts-service.service
+
+[Service]
+User=system
+Group=system
+SmackProcessLabel=msg-service
+Type=simple
+ExecStart=/usr/bin/msg-server
+Restart=always
+MemoryLimit=10M
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packaging/msg-server.socket b/packaging/msg-server.socket
new file mode 100644 (file)
index 0000000..7efea11
--- /dev/null
@@ -0,0 +1,10 @@
+[Socket]
+SocketUser=system
+SocketGroup=system
+ListenStream=/tmp/.msgfw_socket
+SmackLabelIPIn=msg-service
+SmackLabelIPOut=msg-service
+Service=msg-server.service
+       
+[Install]
+WantedBy=sockets.target 
\ No newline at end of file
diff --git a/plugin/mms_plugin/MmsPluginAppBase.cpp b/plugin/mms_plugin/MmsPluginAppBase.cpp
new file mode 100755 (executable)
index 0000000..ee87255
--- /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 = 0; // 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/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;
+}
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;
+}
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/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
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
diff --git a/plugin/sms_cdma_plugin/CMakeLists.txt b/plugin/sms_cdma_plugin/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b94c5cf
--- /dev/null
@@ -0,0 +1,57 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(sms-plugin CXX)
+
+SET(CMAKE_SKIP_BUILD_RPATH TRUE)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+       SET(CMAKE_BUILD_TYPE "Release")
+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 SMS Plugin
+##########################################################
+
+SET(SMS-PLUGIN-SRCS
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginCallback.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginCodec.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginEventHandler.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginMain.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginParamCodec.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginStorage.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginTransport.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginUAManager.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginSetting.cpp
+       ${CMAKE_SOURCE_DIR}/plugin/sms_cdma_plugin/SmsCdmaPluginWapPushHandler.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 db-util glib-2.0 tapi libxml-2.0 libwbxml2 dlog vconf gio-2.0)
+
+FOREACH(flag ${sms_plugin_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+
+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} ${EXTERNALS-LIB})
+
+IF(_FEATURE_TELEPHONY_ENABLE)
+INSTALL(TARGETS ${SMS-PLUGIN-LIB} LIBRARY DESTINATION lib)
+ENDIF(_FEATURE_TELEPHONY_ENABLE)
+
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginCallback.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginCallback.cpp
new file mode 100755 (executable)
index 0000000..2afe93b
--- /dev/null
@@ -0,0 +1,574 @@
+/*
+* 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 <glib.h>
+#include <pthread.h>
+
+#include "MsgDebug.h"
+#include "MsgCppTypes.h"
+#include "MsgException.h"
+#include "MsgGconfWrapper.h"
+#include "SmsCdmaPluginEventHandler.h"
+#include "SmsCdmaPluginParamCodec.h"
+#include "SmsCdmaPluginCodec.h"
+#include "SmsCdmaPluginTransport.h"
+#include "SmsCdmaPluginSetting.h"
+#include "SmsCdmaPluginCallback.h"
+
+
+extern struct tapi_handle *pTapiHandle;
+extern bool isMemAvailable;
+
+void _dnet_state_changed_cb(keynode_t *key, void* data);
+void _TapiMdnChangedCb(keynode_t *key, void *data);
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
+SmsPluginCallback* SmsPluginCallback::pInstance = NULL;
+
+
+SmsPluginCallback::SmsPluginCallback()
+{
+
+
+}
+
+
+SmsPluginCallback::~SmsPluginCallback()
+{
+       if (pInstance != NULL) {
+               delete pInstance;
+               pInstance = NULL;
+       }
+}
+
+
+SmsPluginCallback* SmsPluginCallback::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginCallback();
+
+       return pInstance;
+}
+
+
+void SmsPluginCallback::registerEvent()
+{
+       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_PROP_NETWORK_SERVICE_TYPE, TapiEventNetworkStatusChange, NULL) != 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);
+
+       MsgSettingRegVconfCBCommon(VCONFKEY_DNET_STATE, _dnet_state_changed_cb);
+//     MsgSettingRegVconfCBCommon(VCONFKEY_TELEPHONY_MDN, _TapiMdnChangedCb);
+}
+
+
+void SmsPluginCallback::deRegisterEvent()
+{
+
+
+}
+
+
+void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventDeviceReady is called. : noti_id = [%d]", noti_id);
+
+       try
+       {
+               // Call Event Handler
+               SmsPluginEventHandler::instance()->setDeviceStatus();
+
+               if (SmsPluginEventHandler::instance()->getNeedInitConfig() == true) {
+                       SmsPluginEventHandler::instance()->setNeedInitConfig(false);
+                       SmsPluginSetting::instance()->SimRefreshCb();
+               }
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
+
+}
+
+
+void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+       MSG_WARN("TapiEventMsgIncoming is called. noti_id [%s]", noti_id);
+
+       if (data == NULL) {
+               MSG_DEBUG("Error. evt->pData is NULL.");
+               return;
+       }
+
+       TelSmsDatapackageInfo_t* pDataPackage = (TelSmsDatapackageInfo_t*)data;
+
+       MSG_DEBUG("pDataPackage->format = [%d]", pDataPackage->format);
+       MSG_DEBUG("pDataPackage->Sca = [%s]", pDataPackage->Sca);
+       MSG_DEBUG("pDataPackage->MsgLength = [%d]", pDataPackage->MsgLength);
+       MSG_DEBUG("pDataPackage->szData = ");
+       for (int i = 0; i < pDataPackage->MsgLength; i++) {
+               MSG_DEBUG("[%02x]", pDataPackage->szData[i]);
+       }
+
+       char tpduTmp[(pDataPackage->MsgLength*2)+1];
+       memset(tpduTmp, 0x00, sizeof(tpduTmp));
+       for (int i = 0; i < pDataPackage->MsgLength; i++) {
+               snprintf(tpduTmp+(i*2), sizeof(tpduTmp)-(i*2), "%02X", pDataPackage->szData[i]);
+       }
+       MSG_WARN("[%s]", tpduTmp);
+
+       sms_trans_msg_s sms_trans_msg;
+       memset(&sms_trans_msg, 0x00, sizeof(sms_trans_msg_s));
+
+       if (pDataPackage->format == (TelSmsNetType_t)0x03) {                            // voice mail notification
+               sms_trans_msg.data.p2p_msg.telesvc_msg.type = SMS_TYPE_DELIVER;
+               sms_trans_msg.data.p2p_msg.telesvc_id = SMS_TRANS_TELESVC_VMN_95;
+
+               int num_msg = 0;
+               for (int i = 0; i < pDataPackage->MsgLength; i++) {
+                       num_msg*=256;
+                       num_msg+=pDataPackage->szData[i];
+               }
+
+               sms_trans_msg.data.p2p_msg.telesvc_msg.data.deliver.num_msg = num_msg;
+
+               char *voiceNumber = MsgSettingGetString(VOICEMAIL_NUMBER);
+               if (voiceNumber) {
+                       snprintf(sms_trans_msg.data.p2p_msg.address.szData, sizeof(sms_trans_msg.data.p2p_msg.address.szData), "%s", voiceNumber);
+                       free(voiceNumber);
+                       voiceNumber = NULL;
+               }
+               sms_trans_msg.data.p2p_msg.address.addr_len = strlen(sms_trans_msg.data.p2p_msg.address.szData);
+       } else {
+               bool bInvalid = SmsPluginMsgCodec::checkInvalidPDU(pDataPackage->szData, pDataPackage->MsgLength);
+               if (bInvalid == true) {
+                       // Decode Incoming Message
+                       SmsPluginMsgCodec::decodeMsg(pDataPackage->szData, pDataPackage->MsgLength, &sms_trans_msg);
+
+                       if (sms_trans_msg.data.cb_msg.telesvc_msg.data.deliver.cmas_data.is_wrong_recode_type) {
+                               MSG_WARN("Invalid CMAS Record Type");
+                               return;
+                       }
+               }
+               else {
+                       MSG_WARN("Invalid PDU");
+                       return;
+               }
+       }
+
+       /// Print tpdu
+       if (sms_trans_msg.type == SMS_TRANS_P2P_MSG) {
+               MSG_DEBUG("############# SMS_TRANS_P2P_MSG Incoming decoded tpdu values ####################");
+               MSG_DEBUG("------------------------------ transport layer data -----------------------------");
+               MSG_DEBUG("sms_trans_msg.type = [%d]", sms_trans_msg.type);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.telesvc_id = [%d]", sms_trans_msg.data.p2p_msg.telesvc_id);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.address.digit_mode = [%d]", sms_trans_msg.data.p2p_msg.address.digit_mode);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.address.number_mode = [%d]", sms_trans_msg.data.p2p_msg.address.number_mode);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.address.number_plan = [%d]", sms_trans_msg.data.p2p_msg.address.number_plan);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.address.number_type = [%d]", sms_trans_msg.data.p2p_msg.address.number_type);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.address.addr_len = [%d]", sms_trans_msg.data.p2p_msg.address.addr_len);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.address.szData = [%s]", sms_trans_msg.data.p2p_msg.address.szData);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.svc_ctg = [%d]", sms_trans_msg.data.p2p_msg.svc_ctg);
+               MSG_DEBUG("----------------------- teleservice layer : deliver data -------------------------");
+               sms_telesvc_deliver_s *deliver_msg = &(sms_trans_msg.data.p2p_msg.telesvc_msg.data.deliver);
+               MSG_DEBUG("sms_trans_msg.data.p2p_msg.telesvc_msg.type = [%d]", sms_trans_msg.data.p2p_msg.telesvc_msg.type);
+               MSG_DEBUG("priority= [%d]", deliver_msg->priority);
+               MSG_DEBUG("privacy= [%d]", deliver_msg->privacy);
+               MSG_DEBUG("display_mode= [%d]", deliver_msg->display_mode);
+               MSG_DEBUG("language= [%d]", deliver_msg->language);
+               MSG_DEBUG("msg_id= [%d]", deliver_msg->msg_id);
+               MSG_DEBUG("alert_priority= [%d]", deliver_msg->alert_priority);
+               MSG_DEBUG("num_msg= [%d]", deliver_msg->num_msg);
+               MSG_DEBUG("user_data.msg_type= [%d]", deliver_msg->user_data.msg_type);
+               MSG_DEBUG("user_data.encode_type= [%d]", deliver_msg->user_data.encode_type);
+               MSG_DEBUG("user_data.data_len= [%d]", deliver_msg->user_data.data_len);
+               MSG_DEBUG("user_data.user_data= [%s]", deliver_msg->user_data.user_data);
+               MSG_DEBUG("time_stamp.year= [%d]", deliver_msg->time_stamp.year);
+               MSG_DEBUG("time_stamp.month= [%d]", deliver_msg->time_stamp.month);
+               MSG_DEBUG("time_stamp.day= [%d]", deliver_msg->time_stamp.day);
+               MSG_DEBUG("time_stamp.hours= [%d]", deliver_msg->time_stamp.hours);
+               MSG_DEBUG("time_stamp.minutes= [%d]", deliver_msg->time_stamp.minutes);
+               MSG_DEBUG("time_stamp.seconds= [%d]", deliver_msg->time_stamp.seconds);
+               MSG_DEBUG("deliver_msg->callback_number.addr_len= [%d]", deliver_msg->callback_number.addr_len);
+               MSG_DEBUG("deliver_msg->callback_number.digit_mode= [%d]", deliver_msg->callback_number.digit_mode);
+               MSG_DEBUG("deliver_msg->callback_number.number_plan= [%d]", deliver_msg->callback_number.number_plan);
+               MSG_DEBUG("deliver_msg->callback_number.number_type= [%d]", deliver_msg->callback_number.number_type);
+               MSG_DEBUG("deliver_msg->callback_number.szData= [%s]", deliver_msg->callback_number.szData);
+               MSG_DEBUG("#####################################################");
+       }
+       else if (sms_trans_msg.type == SMS_TRANS_BROADCAST_MSG) {
+               MSG_DEBUG("############# SMS_TRANS_BROADCAST_MSG Incoming decoded tpdu values ####################");
+               MSG_DEBUG("------------------------------ transport layer data -----------------------------");
+               MSG_DEBUG("sms_trans_msg.data.cb_msg.svc_ctg = [%d]", sms_trans_msg.data.cb_msg.svc_ctg);
+               MSG_DEBUG("----------------------- teleservice layer : deliver data -------------------------");
+               sms_telesvc_deliver_s *deliver_msg = &(sms_trans_msg.data.cb_msg.telesvc_msg.data.deliver);
+               MSG_DEBUG("sms_trans_msg.data.cb_msg.telesvc_msg.type = [%d]", sms_trans_msg.data.cb_msg.telesvc_msg.type);
+               MSG_DEBUG("priority= [%d]", deliver_msg->priority);
+               MSG_DEBUG("display_mode= [%d]", deliver_msg->display_mode);
+               MSG_DEBUG("language= [%d]", deliver_msg->language);
+               MSG_DEBUG("msg_id= [%d]", deliver_msg->msg_id);
+               MSG_DEBUG("msg_id.msg_id)= [%d]", deliver_msg->msg_id.msg_id);
+               MSG_DEBUG("header_ind= [%d]", deliver_msg->msg_id.header_ind);
+               MSG_DEBUG("alert_priority= [%d]", deliver_msg->alert_priority);
+               MSG_DEBUG("cmas_data.encode_type= [%d]", deliver_msg->cmas_data.encode_type);
+               MSG_DEBUG("cmas_data.data_len= [%d]", deliver_msg->cmas_data.data_len);
+               MSG_DEBUG("cmas_data.alert_text= [%s]", deliver_msg->cmas_data.alert_text);
+               MSG_DEBUG("cmas_data.response_type= [%d]", deliver_msg->cmas_data.response_type);
+               MSG_DEBUG("cmas_data.severity= [%d]", deliver_msg->cmas_data.severity);
+               MSG_DEBUG("cmas_data.urgency= [%d]", deliver_msg->cmas_data.urgency);
+               MSG_DEBUG("cmas_data.certainty= [%d]", deliver_msg->cmas_data.certainty);
+               MSG_DEBUG("cmas_data.id= [%d]", deliver_msg->cmas_data.id);
+               MSG_DEBUG("time_stamp.year= [%d]", deliver_msg->time_stamp.year);
+               MSG_DEBUG("time_stamp.month= [%d]", deliver_msg->time_stamp.month);
+               MSG_DEBUG("time_stamp.day= [%d]", deliver_msg->time_stamp.day);
+               MSG_DEBUG("time_stamp.hours= [%d]", deliver_msg->time_stamp.hours);
+               MSG_DEBUG("time_stamp.minutes= [%d]", deliver_msg->time_stamp.minutes);
+               MSG_DEBUG("time_stamp.seconds= [%d]", deliver_msg->time_stamp.seconds);
+               MSG_DEBUG("deliver_msg->callback_number.addr_len= [%d]", deliver_msg->callback_number.addr_len);
+               MSG_DEBUG("deliver_msg->callback_number.digit_mode= [%d]", deliver_msg->callback_number.digit_mode);
+               MSG_DEBUG("deliver_msg->callback_number.number_plan= [%d]", deliver_msg->callback_number.number_plan);
+               MSG_DEBUG("deliver_msg->callback_number.number_type= [%d]", deliver_msg->callback_number.number_type);
+               MSG_DEBUG("deliver_msg->callback_number.szData= [%s]", deliver_msg->callback_number.szData);
+               MSG_DEBUG("#####################################################");
+       } else if (sms_trans_msg.type == SMS_TRANS_ACK_MSG) {
+               // DLOG
+               MSG_DEBUG("#####################################################");
+       }
+
+       try
+       {
+               if (sms_trans_msg.type == SMS_TRANS_P2P_MSG) {
+                       if (sms_trans_msg.data.p2p_msg.telesvc_id == SMS_TRANS_TELESVC_WAP) {
+                               SmsPluginEventHandler::instance()->handleWapMsgIncoming(&(sms_trans_msg.data.p2p_msg));
+                       }
+                       else {
+                               SmsPluginEventHandler::instance()->handleMsgIncoming(&(sms_trans_msg.data.p2p_msg)); // Call Event Handler
+                       }
+               } else if (sms_trans_msg.type == SMS_TRANS_BROADCAST_MSG) {
+                       SmsPluginEventHandler::instance()->handleCbMsgIncoming(&(sms_trans_msg.data.cb_msg)); // Call Event Handler
+               } else if (sms_trans_msg.type == SMS_TRANS_ACK_MSG) {
+                       //SmsPluginEventHandler::instance()->handleAckMsgIncoming(&(sms_trans_msg.data.ack_msg)); // Call Event Handler
+               }
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
+}
+
+
+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_DEBUG("network status type [%d]", *type);
+
+       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();
+}
+
+
+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 TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventSentStatus is called. result = [%d]", 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_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;
+       }
+
+       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;
+
+       if (sentStatus == SMS_NETWORK_SEND_SUCCESS) {
+               netStatus = MSG_NETWORK_SEND_SUCCESS;
+       } else if (sentStatus == SMS_NETWORK_SENDING) {
+               netStatus = MSG_NETWORK_SENDING;
+       } else if (sentStatus == SMS_NETWORK_SEND_PENDING) {
+               netStatus = MSG_NETWORK_SEND_PENDING;
+       } else if (sentStatus == SMS_NETWORK_SEND_FAIL_UNKNOWN_SUBSCRIBER) {
+               netStatus = MSG_NETWORK_SEND_FAIL_UNKNOWN_SUBSCRIBER;
+       } else if (sentStatus == SMS_NETWORK_SEND_FAIL_MS_DISABLED) {
+               netStatus = MSG_NETWORK_SEND_FAIL_MS_DISABLED;
+       } else if (sentStatus == SMS_NETWORK_SEND_FAIL_NETWORK_NOT_READY) {
+               netStatus = MSG_NETWORK_SEND_FAIL_NETWORK_NOT_READY;
+       } else {
+               netStatus = MSG_NETWORK_SEND_FAIL;
+       }
+
+       try
+       {
+               SmsPluginEventHandler::instance()->handleSentStatus(netStatus);
+
+               SmsPluginTransport::instance()->setNetStatus(sentStatus);
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+               return;
+       }
+
+}
+
+
+void TapiEventDeliveryReportCNF(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventDeliveryReportCNF is called. : result = [%d]", result);
+
+       return;
+}
+
+
+void TapiEventSetConfigData(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventSetConfigData is called.");
+
+       if (data == NULL)
+       {
+               MSG_DEBUG("Error. data is NULL.");
+               return;
+       }
+
+       TelSmsSetResponse* responseType = (TelSmsSetResponse*)data;
+
+       MSG_DEBUG("responseType : [%d]", *responseType);
+
+       switch (*responseType)
+       {
+               case TAPI_NETTEXT_SETPREFERREDBEARER_RSP :
+                       MSG_DEBUG("TAPI_NETTEXT_SETPREFERREDBEARER_RSP is called");
+               break;
+
+               case TAPI_NETTEXT_SETPARAMETERS_RSP :
+                       MSG_DEBUG("TAPI_NETTEXT_SETPARAMETERS_RSP is called");
+               break;
+
+               case TAPI_NETTEXT_CBSETCONFIG_RSP :
+                       MSG_DEBUG("TAPI_NETTEXT_CBSETCONFIG_RSP is called");
+               break;
+
+               case TAPI_NETTEXT_SETMEMORYSTATUS_RSP :
+                       MSG_DEBUG("TAPI_NETTEXT_SETMEMORYSTATUS_RSP is called");
+               break;
+
+               case TAPI_NETTEXT_SETMESSAGESTATUS_RSP :
+                       MSG_DEBUG("TAPI_NETTEXT_SETMESSAGESTATUS_RSP is called");
+               break;
+
+               default :
+                       MSG_DEBUG("Unknown Response is called [%d]", *responseType);
+               break;
+       }
+
+       bool bRet = true;
+
+       MSG_DEBUG("status : [%d]", (TelSmsCause_t)result);
+
+       if ((TelSmsCause_t)result != TAPI_NETTEXT_SUCCESS) bRet = false;
+
+       SmsPluginSetting::instance()->setResultFromEvent(bRet);
+
+}
+
+
+void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventGetCBConfig is called.");
+
+       MSG_CBMSG_OPT_S cbOpt = {0};
+
+       if (result != TAPI_API_SUCCESS || data == NULL)
+       {
+               MSG_DEBUG("Error. data is NULL.");
+
+               SmsPluginSetting::instance()->setCbConfigEvent(NULL, false);
+
+               return;
+       }
+
+       TelSmsCbConfig_t* pCBConfig = (TelSmsCbConfig_t*)data;
+
+       cbOpt.bReceive = (bool)pCBConfig->CBEnabled;
+
+//     cbOpt.maxSimCnt = pCBConfig->MsgIdMaxCount;
+
+//     MSG_DEBUG("Receive [%d], Max SIM Count [%d]", cbOpt.bReceive, cbOpt.maxSimCnt);
+       MSG_DEBUG("Receive [%d]", cbOpt.bReceive);
+
+       cbOpt.channelData.channelCnt = pCBConfig->MsgIdRangeCount;
+
+       if (cbOpt.channelData.channelCnt > CB_CHANNEL_MAX)
+       {
+               MSG_DEBUG("Channel Count [%d] from TAPI is over MAX", cbOpt.channelData.channelCnt);
+               cbOpt.channelData.channelCnt = CB_CHANNEL_MAX;
+       }
+
+       MSG_DEBUG("Channel Count [%d]", cbOpt.channelData.channelCnt);
+
+       for (int i = 0; i < cbOpt.channelData.channelCnt; i++)
+       {
+               cbOpt.channelData.channelInfo[i].bActivate = pCBConfig->MsgIDs[i].Net3gpp2.Selected;
+               cbOpt.channelData.channelInfo[i].ctg = pCBConfig->MsgIDs[i].Net3gpp2.CBCategory;
+               cbOpt.channelData.channelInfo[i].lang = pCBConfig->MsgIDs[i].Net3gpp2.CBLanguage;
+               memset(cbOpt.channelData.channelInfo[i].name, 0x00, CB_CHANNEL_NAME_MAX+1);
+
+               MSG_DEBUG("Channel Category [%d], Channel Language [%d] ", cbOpt.channelData.channelInfo[i].ctg, cbOpt.channelData.channelInfo[i].lang);
+       }
+
+       SmsPluginSetting::instance()->setCbConfigEvent(&cbOpt, true);
+}
+
+void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *user_data)
+{
+       MSG_DEBUG("TapiEventGetMsisdnInfo is called.");
+
+       bool bRet = false;
+
+       if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL) {
+               MSG_DEBUG("Error. data is NULL.");
+               SmsPluginSetting::instance()->setResultFromSim(bRet);
+               return;
+       }
+
+       TelSimMsisdnList_t *list = (TelSimMsisdnList_t *)data;
+
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       int simIndex = 1;
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
+
+       for (int i = 0; i < list->count; i++) {
+               if (list->list[i].num[0] != '\0') {
+                       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 _dnet_state_changed_cb(keynode_t *key, void* data)
+{
+       int dnet_state = MsgSettingGetInt(VCONFKEY_DNET_STATE);
+
+       if (dnet_state > VCONFKEY_DNET_OFF) {
+               SmsPluginEventHandler::instance()->handleResendMessage(); // Call Event Handler
+       }
+}
+
+void _TapiMdnChangedCb(keynode_t *key, void *data)
+{
+       MSG_INFO("_TapiMdnChangedCb is called.");
+
+       char *mdn = vconf_get_str("db/telephony/mdn");
+
+       if (mdn) {
+               bool bNeedToUpdateVoicemail = SmsPluginSetting::instance()->getUpdateVoicemailByMdn();
+               MSG_INFO("bNeedToUpdateVoicemail:%d, mdn:[%s]", bNeedToUpdateVoicemail, mdn);
+
+               if (bNeedToUpdateVoicemail) {
+                       if (MsgSettingSetString(VOICEMAIL_NUMBER, mdn) != MSG_SUCCESS)
+                               MSG_DEBUG("MsgSettingSetInt is failed!!");
+
+                       if (MsgSettingSetString(VOICEMAIL_DEFAULT_NUMBER, mdn) != MSG_SUCCESS)
+                               MSG_DEBUG("Error to set config data [%s]", VOICEMAIL_DEFAULT_NUMBER);
+               }
+
+               free(mdn);
+       }
+}
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginCodec.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginCodec.cpp
new file mode 100755 (executable)
index 0000000..0ae9eff
--- /dev/null
@@ -0,0 +1,2383 @@
+/*
+* 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 "MsgDebug.h"
+#include "MsgTextConvert.h"
+
+#include "SmsCdmaPluginParamCodec.h"
+#include "SmsCdmaPluginCodec.h"
+
+
+
+SmsPluginMsgCodec* SmsPluginMsgCodec::pInstance = NULL;
+
+SmsPluginMsgCodec::SmsPluginMsgCodec()
+{
+
+}
+
+
+SmsPluginMsgCodec::~SmsPluginMsgCodec()
+{
+
+}
+
+
+SmsPluginMsgCodec* SmsPluginMsgCodec::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginMsgCodec();
+
+       return pInstance;
+}
+
+
+void _shiftNBit(unsigned char *src, unsigned int n_bytes, unsigned int n_shift_bit)
+{
+       char tmp;
+
+    for (unsigned int index = 1; index < n_bytes; index++) {
+            tmp = src[index] >> (8 - n_shift_bit);
+            src[index-1] |= tmp;
+            src[index] = src[index] << n_shift_bit;
+    }
+}
+
+
+void _shiftNBit_for_decode(unsigned char *src, unsigned int n_bytes, unsigned int n_shift_bit)
+{
+     for (unsigned int index = 0; index < n_bytes; index++) {
+         src[index]<<=n_shift_bit;
+         src[index] |= (src[index+1] >> (8 - n_shift_bit));
+         }
+}
+
+
+void _copy_short_to_char(unsigned char *dest, const unsigned short *src)
+{
+       dest[0] = (0xff00 & *src) >> 8;
+       dest[1] = 0x00ff & *src;
+}
+
+
+void _copy_char_to_short(unsigned short *dest, const unsigned char *src)
+{
+     *dest = src[0]*256 + src[1];
+}
+
+
+unsigned char _convert_to_BCD(unsigned char val)
+{
+       unsigned char ret = 0x00;
+       ret = ((val/10) << 4) | (val%10);
+       return ret;
+}
+
+
+int UnpackGSM7bitData(unsigned char *src, unsigned char *dest, unsigned int dataLen)
+{
+       unsigned int srcIdx = 0, dstIdx = 0, shift = 0;
+
+       MSG_DEBUG("dataLen = %d", dataLen);
+
+       for (; dstIdx < dataLen; dstIdx++)
+       {
+               if (shift == 0)
+               {
+                       dest[dstIdx] = src[srcIdx] & 0x7F;
+
+                       shift = 7;
+                       srcIdx++;
+                       dstIdx++;
+
+                       if (dstIdx >= dataLen) break;
+               }
+
+               if (shift > 0)
+               {
+                       dest[dstIdx] = (src[srcIdx-1] >> shift) + (src[srcIdx] << (8 - shift));
+
+                       dest[dstIdx] &= 0x7F;
+
+                       shift--;
+
+                       if (shift > 0) srcIdx++;
+               }
+       }
+
+       return dstIdx;
+}
+
+
+int PackGSM7bitData(const unsigned char *pUserData, unsigned char *pPackData, int dataLen)
+{
+       int srcIdx = 0, dstIdx = 0, shift = 0;
+
+       if (shift > 0)
+               dstIdx = 1;
+
+       while (srcIdx < dataLen)
+       {
+               if (shift == 0)
+               {
+                       pPackData[dstIdx] = pUserData[srcIdx];
+
+                       shift = 7;
+                       srcIdx++;
+                       dstIdx++;
+
+                       if (srcIdx >= dataLen) break;
+               }
+
+               if (shift > 1)
+               {
+                       pPackData[dstIdx-1] |= pUserData[srcIdx] << shift;
+                       pPackData[dstIdx] = pUserData[srcIdx] >> (8-shift);
+                       shift--;
+
+                       srcIdx++;
+                       dstIdx++;
+               }
+               else if (shift == 1)
+               {
+                       pPackData[dstIdx-1] |= pUserData[srcIdx] << shift;
+
+                       srcIdx++;
+
+                       shift--;
+               }
+       }
+
+       return dstIdx;
+}
+
+
+bool SmsPluginMsgCodec::checkInvalidPDU(const unsigned char *p_pkg_str, const int p_pkg_len)
+{
+       MSG_BEGIN();
+       int offset = 0;
+
+       if (!(p_pkg_str[offset] == 0x00 || p_pkg_str[offset] == 0x01 || p_pkg_str[offset] == 0x02)) {
+               MSG_WARN("Invalid PDU : Message Type [%2x]", p_pkg_str[offset]);
+               return false;
+       }
+
+       offset++;
+
+       while (offset < p_pkg_len) {
+               switch (p_pkg_str[offset]) {
+               case 0x00 :
+               case 0x01 :
+               case 0x02 :
+               case 0x03 :
+               case 0x04 :
+               case 0x05 :
+               case 0x06 :
+               case 0x07 :
+               case 0x08 :
+                       offset += (p_pkg_str[offset+1]+2);
+                       break;
+               default:
+                       MSG_WARN("Invalid PDU : Parameter ID [%2x], offset [%d]", p_pkg_str[offset], offset);
+                       return false;
+               }
+       }
+
+       if (offset != p_pkg_len)
+               return false;
+
+       MSG_END();
+       return true;
+}
+
+
+int SmsPluginMsgCodec::encodeMsg(const sms_trans_msg_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int encode_size = 0;
+
+       switch(p_msg->type) {
+               case SMS_TRANS_P2P_MSG:
+                       encode_size = encodeP2PMsg(&(p_msg->data.p2p_msg), p_pkg_str);
+                       break;
+               case SMS_TRANS_BROADCAST_MSG:
+                       encode_size = encodeCBMsg(&(p_msg->data.cb_msg), p_pkg_str);
+                       break;
+               case SMS_TRANS_ACK_MSG :
+                       encode_size = encodeAckMsg(&(p_msg->data.ack_msg), p_pkg_str);
+                       break;
+               default :
+                       break;
+       }
+
+
+       MSG_END();
+
+       return encode_size;
+}
+
+
+int SmsPluginMsgCodec::encodeP2PMsg(const sms_trans_p2p_msg_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0, encode_size = 0;
+       int addr_len = 0;
+       int index = 0, len_index = 0;
+
+       p_pkg_str[offset++] = SMS_TRANS_P2P_MSG;
+
+       // 1. teleservice id
+       p_pkg_str[offset++] = SMS_TRANS_PARAM_TELESVC_IDENTIFIER;
+       p_pkg_str[offset++] = 2; // fixed
+       //memcpy(p_pkg_str+offset, &(p_msg->telesvc_id), sizeof(sms_trans_telesvc_id_t));
+       _copy_short_to_char(p_pkg_str+offset, &(p_msg->telesvc_id));
+       offset += sizeof(sms_trans_telesvc_id_t);
+
+       // 2. Service category
+       if(p_msg->svc_ctg < SMS_TRANS_SVC_CTG_UNDEFINED) {
+               p_pkg_str[offset++] = SMS_TRANS_PARAM_SERVICE_CATEGORY;
+               p_pkg_str[offset++] = 0x02; // fixed
+               _copy_short_to_char(&p_pkg_str[offset],&(p_msg->svc_ctg));
+       }
+
+       // 3. Address
+       p_pkg_str[offset++] = SMS_TRANS_PARAM_DEST_ADDRESS;
+
+       len_index = offset++; // Will be set to param length
+
+       p_pkg_str[offset] = p_msg->address.digit_mode ? 0x80 : 0x00;
+       p_pkg_str[offset] |= (p_msg->address.number_mode ? 0x40 : 0x00);
+
+       if(p_msg->address.digit_mode == false) {
+               index = offset++;
+               p_pkg_str[offset++] = p_msg->address.addr_len;
+
+               addr_len = SmsPluginParamCodec::instance()->convertDigitToDTMF(p_msg->address.szData, p_msg->address.addr_len, 0, p_pkg_str+offset);
+
+               for (int j=0; j < addr_len; j++) {
+                       MSG_DEBUG("ADDRESS 4BIT DTMF [%d] = [%02x]", j, p_pkg_str[offset+j]);
+               }
+
+               offset += addr_len;
+
+               _shiftNBit(&p_pkg_str[index], offset-index+1, 6);
+       }
+       else if(p_msg->address.digit_mode == true) {
+               p_pkg_str[offset] |= p_msg->address.number_type << 3;
+
+               if(p_msg->address.number_mode == false) {
+                       p_pkg_str[offset++] |= p_msg->address.number_plan >> 1;
+                       p_pkg_str[offset++] |= p_msg->address.number_plan << 7;
+                       index = offset-1;
+                       p_pkg_str[offset++] = p_msg->address.addr_len;
+
+                       memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
+
+                       offset += p_msg->address.addr_len;
+
+                       _shiftNBit(&p_pkg_str[index], offset-index+1, 7);
+               }
+               else if(p_msg->address.number_mode == true) {
+                       index = offset++;
+                       p_pkg_str[offset++] = p_msg->address.addr_len;
+                       memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
+
+                       offset += p_msg->address.addr_len;
+
+                       _shiftNBit(&p_pkg_str[index], offset-index+1, 3);
+               }
+       }
+
+       p_pkg_str[len_index] = offset - len_index - 1 ;
+       MSG_DEBUG("Address subparam length field = [%d]", p_pkg_str[len_index]);
+
+       // 4. Sub address (optional)
+       if(p_msg->sub_address.addr_len > 0) {
+               p_pkg_str[offset++] = SMS_TRANS_PARAM_ORG_SUB_ADDRESS;
+               p_pkg_str[offset] = p_msg->sub_address.addr_len + 2;
+               index = offset++;
+               p_pkg_str[offset] |= p_msg->sub_address.type << 5;
+               p_pkg_str[offset++] |= (p_msg->sub_address.odd ? 0x10 : 0x00);
+               p_pkg_str[offset++] = p_msg->sub_address.addr_len;
+               memcpy(p_pkg_str+offset, p_msg->sub_address.szData, p_msg->sub_address.addr_len);
+
+               offset+=p_msg->sub_address.addr_len;
+
+               _shiftNBit(&p_pkg_str[index], offset-index+1, 4);
+       }
+
+       // 5. Bearer reply option (optional)
+       if(p_msg->reply_seq > 0) {
+               p_pkg_str[offset++] = SMS_TRANS_PARAM_BEARER_REPLY_OPTION;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset++] = (unsigned char)(p_msg->reply_seq << 2);
+               MSG_DEBUG("Reply sequnce number = [%d]", p_msg->reply_seq);
+       }
+
+       // 6. Bearer data
+    p_pkg_str[offset++] = SMS_TRANS_PARAM_BEARER_DATA;
+       index = offset++; // PARAMETER_LEN field should be filled at the last part.
+
+       unsigned char *encode_data = &p_pkg_str[offset];
+
+       encode_size = encodeTelesvcMsg(&(p_msg->telesvc_msg), encode_data);
+       p_pkg_str[index] = encode_size; // PARAMETER_LEN
+
+       offset += encode_size;
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeCBMsg(const sms_trans_broadcast_msg_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0, encode_size = 0;
+       int len_index = 0;
+
+       // 1. Service Category(Mandatory)
+       p_pkg_str[offset++] = SMS_TRANS_PARAM_SERVICE_CATEGORY;
+       p_pkg_str[offset++] = 0x02;
+       _copy_short_to_char(&p_pkg_str[offset],&p_msg->svc_ctg);
+
+
+       // 2. Bearer Data(Optional)
+       // TODO: give condition
+    p_pkg_str[offset++] = SMS_TRANS_PARAM_BEARER_DATA;
+       len_index = offset++; // PARAMETER_LEN field should be filled at the last part.
+
+       unsigned char *encode_data = &p_pkg_str[offset];
+
+       encode_size = encodeTelesvcMsg(&(p_msg->telesvc_msg), encode_data);
+       p_pkg_str[len_index] = encode_size; // PARAMETER_LEN
+
+       offset += encode_size;
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeAckMsg(const sms_trans_ack_msg_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0;
+       int addr_len = 0, len_index = 0;
+       int index = 0;
+
+       // 1. Address
+       p_pkg_str[offset++] = SMS_TRANS_PARAM_DEST_ADDRESS;
+
+       len_index = offset++; // Will be set to param length
+
+       p_pkg_str[offset] = p_msg->address.digit_mode ? 0x80 : 0x00;
+       p_pkg_str[offset] |= (p_msg->address.number_mode ? 0x40 : 0x00);
+
+       index = offset++;
+
+       if(p_msg->address.digit_mode == false) {
+               p_pkg_str[offset++] = p_msg->address.addr_len;
+
+               addr_len = SmsPluginParamCodec::instance()->convertDigitToDTMF(p_msg->address.szData, p_msg->address.addr_len, 0, p_pkg_str+offset);
+
+               for (int j=0; j < addr_len; j++) {
+                       MSG_DEBUG("ADDRESS 4BIT DTMF [%d] = [%02x]", j, p_pkg_str[offset+j]);
+               }
+
+               offset += addr_len;
+
+               _shiftNBit(&p_pkg_str[index], offset-index+1, 6);
+       }
+       else if(p_msg->address.digit_mode == true) {
+               p_pkg_str[offset] |= p_msg->address.number_type << 3;
+
+               if(p_msg->address.number_mode == false) {
+                       p_pkg_str[offset++] |= p_msg->address.number_plan >> 1;
+                       p_pkg_str[offset++] |= p_msg->address.number_plan << 7;
+                       index++;
+                       p_pkg_str[offset++] = p_msg->address.addr_len;
+
+                       memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
+
+                       offset += p_msg->address.addr_len;
+
+                       _shiftNBit(&p_pkg_str[index], offset-index+1, 7);
+               }
+               else if(p_msg->address.number_mode == true) {
+                       p_pkg_str[++offset] = p_msg->address.addr_len;
+                       offset++;
+                       memcpy(p_pkg_str+offset, p_msg->address.szData, p_msg->address.addr_len);
+
+                       offset += p_msg->address.addr_len;
+
+                       _shiftNBit(&p_pkg_str[index], offset-index+1, 3);
+               }
+       }
+
+       p_pkg_str[len_index] = offset - len_index - 1 ;
+       MSG_DEBUG("Address subparam length field = [%d]", p_pkg_str[len_index]);
+
+       // 2. Sub address
+       if(p_msg->sub_address.addr_len > 0) {
+               p_pkg_str[offset++] = SMS_TRANS_PARAM_ORG_SUB_ADDRESS;
+               p_pkg_str[offset] = p_msg->sub_address.addr_len + 2;
+               index = offset++;
+               p_pkg_str[offset] |= p_msg->sub_address.type << 5;
+               p_pkg_str[offset++] |= (p_msg->sub_address.odd ? 0x10 : 0x00);
+               p_pkg_str[offset++] = p_msg->sub_address.addr_len;
+               memcpy(p_pkg_str+offset, p_msg->sub_address.szData, p_msg->sub_address.addr_len);
+
+               offset+=p_msg->sub_address.addr_len;
+
+               _shiftNBit(&p_pkg_str[index], offset-index+1, 4);
+       }
+
+       // 3. Cause code
+       p_pkg_str[offset++] = SMS_TRANS_PARAM_CAUSE_CODES;
+       index = offset++;
+       p_pkg_str[offset] |= p_msg->cause_code.reply_seq << 2;
+       p_pkg_str[offset] |= p_msg->cause_code.error_class;
+       if (p_msg->cause_code.error_class != 0x0) {
+               p_pkg_str[++offset] = p_msg->cause_code.cause_code;
+       }
+       p_pkg_str[index] = offset - index;
+
+       MSG_END();
+
+       return offset;
+
+}
+
+int SmsPluginMsgCodec::encodeTelesvcMsg(const sms_telesvc_msg_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+       int encode_size = 0;
+
+       MSG_DEBUG("Teleservice msg type = [%d]", p_msg->type);
+
+       switch(p_msg->type) {
+//             case SMS_TYPE_DELIVER :
+//                     encode_size = encodeTelesvcDeliverMsg(&(p_msg->data.delever), p_pkg_str);
+//                     break;
+               case SMS_TYPE_SUBMIT :
+                       encode_size = encodeTelesvcSubmitMsg(&(p_msg->data.submit), p_pkg_str);
+                       break;
+               case SMS_TYPE_CANCEL :
+                       encode_size = encodeTelesvcCancelMsg(&(p_msg->data.cancel), p_pkg_str);
+                       break;
+               case SMS_TYPE_USER_ACK :
+                       encode_size = encodeTelesvcUserAckMsg(&(p_msg->data.user_ack), p_pkg_str);
+                       break;
+               case SMS_TYPE_READ_ACK :
+                       encode_size = encodeTelesvcReadAckMsg(&(p_msg->data.read_ack), p_pkg_str);
+                       break;
+               case SMS_TYPE_DELIVER_REPORT :
+                       encode_size = encodeTelesvcDeliverReportMsg(&(p_msg->data.report), p_pkg_str);
+                       break;
+               default :
+                       MSG_DEBUG("No matching type for [%d]", p_msg->type);
+                       break;
+       }
+
+       MSG_END();
+       return encode_size;
+}
+
+//int SmsPluginMsgCodec::encodeTelesvcDeliverMsg(const sms_telesvc_deliver_s *p_msg, char *p_pkg_str)
+//{
+//
+//}
+
+int SmsPluginMsgCodec::encodeTelesvcReadAckMsg(const sms_telesvc_read_ack_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0;
+
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeTelesvcUserAckMsg(const sms_telesvc_user_ack_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0;
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeTelesvcDeliverReportMsg(const sms_telesvc_report_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0, len_index = 0, encode_size = 0;
+       bool delReservedBit = false;
+
+       // 1. Message Identifier (Mandatory)
+       p_pkg_str[offset++] = SMS_BEARER_MESSAGE_IDENTIFIER;
+       p_pkg_str[offset++] = 3;
+       _copy_short_to_char(p_pkg_str+offset+1, &(p_msg->msg_id.msg_id));
+       _shiftNBit(&p_pkg_str[offset], 3, 4);
+       p_pkg_str[offset] |= SMS_TYPE_SUBMIT << 4;
+       offset+=2;
+       p_pkg_str[offset++] |= (p_msg->msg_id.header_ind ? 0x08 : 0x00);
+
+
+       // 2. TP-Failure Cause (Conditional)
+       if(p_msg->tp_fail_cause >= 0x8000) {
+               p_pkg_str[offset++] = SMS_BEARER_TP_FAILURE_CAUSE;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset++] = p_msg->tp_fail_cause;
+       }
+
+       // 3. User Data (Optional)
+       if(p_msg->user_data.data_len > 0) {
+               p_pkg_str[offset++] = SMS_BEARER_USER_DATA;
+               len_index = offset;
+               offset++;
+               if(p_msg->user_data.encode_type == 0x01 || p_msg->user_data.encode_type == 0x0a)
+                       p_pkg_str[offset++] = p_msg->user_data.msg_type;
+
+               p_pkg_str[offset++] = p_msg->user_data.encode_type << 3;
+               p_pkg_str[offset++] = p_msg->user_data.data_len;
+
+               if (p_msg->user_data.encode_type == SMS_ENCODE_7BIT_ASCII || p_msg->user_data.encode_type == SMS_ENCODE_GSM7BIT) {
+                       encode_size = encodeUserData(p_msg->user_data.user_data, &p_pkg_str[offset], p_msg->user_data.data_len);
+                       offset += encode_size;
+                       if(p_msg->user_data.data_len % 8 > 4)
+                               delReservedBit = true;
+               } else {
+                       memcpy(p_pkg_str+offset, p_msg->user_data.user_data, p_msg->user_data.data_len);
+                       offset += p_msg->user_data.data_len;
+               }
+               _shiftNBit(&p_pkg_str[len_index+1], offset-len_index-1, 3);
+
+               if (delReservedBit == true)
+                       offset--;
+
+               p_pkg_str[len_index] = offset - len_index - 1;
+
+       }
+
+       // 4. Language Indicator (Optional)
+       // TODO : give condition
+//     p_pkg_str[offset++] = SMS_BEARER_ALERT_ON_MSG_DELIVERY;
+//     p_pkg_str[offset++] = 1;
+//     p_pkg_str[offset++] = p_msg->language;
+
+
+       // 5. Multiple Encoding User Data (Optional)
+       // Omitted
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeTelesvcCancelMsg(const sms_telesvc_cancel_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0;
+
+       // 1. Message Identifier
+       p_pkg_str[offset++] = SMS_BEARER_MESSAGE_IDENTIFIER;
+       p_pkg_str[offset++] = 3;
+       _copy_short_to_char(p_pkg_str+offset+1, &(p_msg->msg_id.msg_id));
+       _shiftNBit(&p_pkg_str[offset], 3, 4);
+       p_pkg_str[offset] |= SMS_TYPE_SUBMIT << 4;
+       offset+=2;
+       p_pkg_str[offset++] |= (p_msg->msg_id.header_ind ? 0x08 : 0x00);
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeTelesvcSubmitMsg(const sms_telesvc_submit_s *p_msg, unsigned char *p_pkg_str)
+{
+       MSG_BEGIN();
+
+       int offset = 0, len_index = 0;
+       int encode_size = 0;
+       bool delReservedBit = false;
+
+       // 1. Message Identifier
+       p_pkg_str[offset++] = SMS_BEARER_MESSAGE_IDENTIFIER;
+       p_pkg_str[offset++] = 3;
+       _copy_short_to_char(p_pkg_str+offset+1, &(p_msg->msg_id.msg_id));
+       _shiftNBit(&p_pkg_str[offset], 3, 4);
+       p_pkg_str[offset] |= SMS_TYPE_SUBMIT << 4;
+       offset+=2;
+       p_pkg_str[offset++] |= (p_msg->msg_id.header_ind ? 0x08 : 0x00);
+
+       // 2. User Data
+       if(p_msg->user_data.data_len > 0) {
+               p_pkg_str[offset++] = SMS_BEARER_USER_DATA;
+               len_index = offset;
+               offset++;
+               if(p_msg->user_data.encode_type == 0x01 || p_msg->user_data.encode_type == 0x0a)
+                       p_pkg_str[offset++] = p_msg->user_data.msg_type;
+
+               p_pkg_str[offset++] = p_msg->user_data.encode_type << 3;
+               p_pkg_str[offset++] = p_msg->user_data.data_len;
+
+               if (p_msg->user_data.encode_type == SMS_ENCODE_7BIT_ASCII) {
+                       encode_size = encodeUserData(p_msg->user_data.user_data, &p_pkg_str[offset], p_msg->user_data.data_len);
+                       offset += encode_size;
+                       if(p_msg->user_data.data_len % 8 > 4)
+                               delReservedBit = true;
+               } else if (p_msg->user_data.encode_type == SMS_ENCODE_GSM7BIT) {
+                       encode_size = PackGSM7bitData(p_msg->user_data.user_data, &p_pkg_str[offset], p_msg->user_data.data_len);
+                       offset += encode_size;
+                       if(p_msg->user_data.data_len % 8 > 4)
+                               delReservedBit = true;
+               } else if (p_msg->user_data.encode_type == SMS_ENCODE_UNICODE) {
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       encode_size = textCvt->convertUTF8ToUCS2(&p_pkg_str[offset], SMS_MAX_USER_DATA_LEN, p_msg->user_data.user_data, p_msg->user_data.data_len);
+                       p_pkg_str[offset-1] = encode_size / 2;
+                       offset += encode_size;
+               } else {
+                       memcpy(p_pkg_str+offset, p_msg->user_data.user_data, p_msg->user_data.data_len);
+                       offset += p_msg->user_data.data_len;
+               }
+               _shiftNBit(&p_pkg_str[len_index+1], offset-len_index-1, 3);
+
+               if (delReservedBit == true)
+                       offset--;
+
+               p_pkg_str[len_index] = offset - len_index - 1;
+
+       }
+/* Sprint and Verizon issue
+       // 3. Validity Period
+       if (p_msg->val_period.format == SMS_TIME_RELATIVE) {
+               p_pkg_str[offset++] = SMS_BEARER_VALIDITY_PERIOD_RELATIVE;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset++] = p_msg->val_period.time.rel_time.rel_time;
+
+       } else if (p_msg->val_period.format == SMS_TIME_ABSOLUTE){
+               p_pkg_str[offset++] = SMS_BEARER_VALIDITY_PERIOD_ABSOLUTE;
+               p_pkg_str[offset++] = 6;
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.year);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.month);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.day);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.hours);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.minutes);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->val_period.time.abs_time.seconds);
+       }
+*/
+       // 4. Deferred Delivery Time
+       if (p_msg->defer_val_period.format == SMS_TIME_RELATIVE) {
+               p_pkg_str[offset++] = SMS_BEARER_DEFERRED_DELIVERY_TIME_RELATIVE;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset++] = p_msg->defer_val_period.time.rel_time.rel_time;
+
+       } else if (p_msg->defer_val_period.format == SMS_TIME_ABSOLUTE) {
+               p_pkg_str[offset++] = SMS_BEARER_DEFERRED_DELIVERY_TIME_ABSOLUTE;
+               p_pkg_str[offset++] = 6;
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.year);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.month);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.day);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.hours);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.minutes);
+               p_pkg_str[offset++] = _convert_to_BCD(p_msg->defer_val_period.time.abs_time.seconds);
+       }
+
+       // 5. Priority Indicator
+       if (p_msg->priority >= SMS_PRIORITY_NORMAL && p_msg->priority <=        SMS_PRIORITY_EMERGENCY) {
+               p_pkg_str[offset++] = SMS_BEARER_PRIORITY_INDICATOR;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset++] = p_msg->priority << 6;
+       }
+
+/* Sprint and Verizon issue
+       // 6. Privacy Indicator
+       if (p_msg->privacy >= SMS_PRIVACY_NOT_RESTRICTED && p_msg->privacy <= SMS_PRIVACY_SECRET) {
+               p_pkg_str[offset++] = SMS_BEARER_PRIVACY_INDICATOR;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset++] = p_msg->privacy << 6;
+       }
+*/
+       // 7. Reply Option
+       if (p_msg->reply_opt.user_ack_req | p_msg->reply_opt.deliver_ack_req | p_msg->reply_opt.read_ack_req | p_msg->reply_opt.report_req) {
+               p_pkg_str[offset++] = SMS_BEARER_REPLY_OPTION;
+               p_pkg_str[offset++] = 1;
+               p_pkg_str[offset] |= p_msg->reply_opt.user_ack_req << 7;
+               p_pkg_str[offset] |= p_msg->reply_opt.deliver_ack_req << 6;
+               p_pkg_str[offset] |= p_msg->reply_opt.read_ack_req << 5;
+               p_pkg_str[offset++] |= p_msg->reply_opt.report_req << 4;
+       }
+
+       // 8. Alert on Message Delivery
+       // TODO : give condition
+//     p_pkg_str[offset++] = SMS_BEARER_ALERT_ON_MSG_DELIVERY;
+//     p_pkg_str[offset++] = 1;
+//     p_pkg_str[offset++] = p_msg->alert_priority << 6;
+
+       // 9. Language Indicator
+       // TODO : give condition
+//     p_pkg_str[offset++] = SMS_BEARER_ALERT_ON_MSG_DELIVERY;
+//     p_pkg_str[offset++] = 1;
+//     p_pkg_str[offset++] = p_msg->language;
+
+       // 10. Call-back Number
+       if (p_msg->callback_number.addr_len > 0) {
+               p_pkg_str[offset++] = SMS_BEARER_CALLBACK_NUMBER;
+
+               int len_index = offset++;
+
+               p_pkg_str[offset] |= p_msg->callback_number.digit_mode << 7;
+
+               if(p_msg->callback_number.digit_mode == false) {
+                       p_pkg_str[offset++] |= (p_msg->callback_number.addr_len & 0xfe) >> 1;
+                       p_pkg_str[offset] |= (p_msg->callback_number.addr_len & 0x01) << 7;
+                       int addr_len = SmsPluginParamCodec::instance()->convertDigitToDTMF(p_msg->callback_number.szData, p_msg->callback_number.addr_len, 1, p_pkg_str+offset);
+                       offset += addr_len;
+               }
+               else if(p_msg->callback_number.digit_mode == true) {
+                       p_pkg_str[offset] |= p_msg->callback_number.number_type << 6;
+                       p_pkg_str[offset++] |= p_msg->callback_number.number_plan;
+                       p_pkg_str[offset++] = p_msg->callback_number.addr_len;
+                       memcpy(p_pkg_str+offset, p_msg->callback_number.szData, p_msg->callback_number.addr_len);
+                       offset += p_msg->callback_number.addr_len;
+               }
+
+               p_pkg_str[len_index] = offset- len_index - 1;
+       }
+
+       // 11. Multiple Encoding User Data
+       // Omitted
+
+       // 12. Message Deposit Index
+       // Omitted
+
+       // 13. Service Category Program Results
+       // Omitted
+
+       MSG_END();
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::decodeMsg(const unsigned char *p_pkg_str, int pkg_len, sms_trans_msg_s *p_msg)
+{
+       MSG_BEGIN();
+
+       int decodelen = 0;
+
+       char mti = p_pkg_str[0] & 0xff;
+
+       switch(mti) {
+               case SMS_TRANS_P2P_MSG:
+                       p_msg->type = SMS_TRANS_P2P_MSG;
+                       decodelen = decodeP2PMsg(p_pkg_str+1, pkg_len-1, &(p_msg->data.p2p_msg));
+                       break;
+               case SMS_TRANS_BROADCAST_MSG:
+                       p_msg->type = SMS_TRANS_BROADCAST_MSG;
+                       decodelen = decodeCBMsg(p_pkg_str+1, pkg_len-1, &(p_msg->data.cb_msg));
+                       break;
+               case SMS_TRANS_ACK_MSG:
+                       p_msg->type = SMS_TRANS_ACK_MSG;
+                       decodelen = decodeAckMsg(p_pkg_str+1, pkg_len-1, &(p_msg->data.ack_msg));
+                       break;
+               default:
+                       p_msg->type = SMS_TRANS_TYPE_RESERVED;
+                       break;
+       }
+
+       MSG_END();
+
+       return decodelen+1;
+}
+
+
+int SmsPluginMsgCodec::decodeP2PMsg(const unsigned char *p_pkg_str, int pkg_len, sms_trans_p2p_msg_s *p_p2p)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len = 0;
+
+       while (offset < pkg_len) {
+               switch (p_pkg_str[offset]) {
+               case 0x00:                              // Teleservice Identifier
+                       offset += decodeTeleId(p_pkg_str+offset, pkg_len, &(p_p2p->telesvc_id));
+                       break;
+
+               case 0x01:                              // Service Category
+                       offset += decodeSvcCtg(p_pkg_str+offset, pkg_len, &(p_p2p->svc_ctg));
+                       break;
+
+               case 0x02:
+               case 0x04:                              // Address
+                       offset += decodeAddress(p_pkg_str+offset, pkg_len, &(p_p2p->address));
+                       break;
+
+               case 0x03:
+               case 0x05:                              // Subaddress
+                       offset += decodeSubAddress(p_pkg_str+offset, pkg_len, &(p_p2p->sub_address));
+                       break;
+
+               case 0x06:                              // Bearer Reply Option
+                       offset+=2;
+                       p_p2p->reply_seq = (sms_trans_reply_seq_t)(p_pkg_str[offset] >> 2);
+                       offset++;
+                       break;
+
+               case 0x08:                              // Bearer Data
+                       tmp_len = p_pkg_str[++offset];
+                       decodeP2PTelesvcMsg(p_pkg_str+offset+1, tmp_len, &p_p2p->telesvc_msg);
+                       offset+=(tmp_len+1);
+                       break;
+
+               default:
+                       break;
+               }
+       }
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::decodeCBMsg(const unsigned char *p_pkg_str, int pkg_len, sms_trans_broadcast_msg_s *p_cb)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len = 0;
+
+       while(offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x01) {                 // Service Category
+                       offset += decodeTeleId(p_pkg_str+offset, pkg_len, &(p_cb->svc_ctg));
+               }
+               else if(p_pkg_str[offset] == 0x08) {                                                    // Bearer Data
+                       tmp_len = p_pkg_str[++offset];
+                       if(p_cb->svc_ctg >= SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL && p_cb->svc_ctg <= SMS_TRANS_SVC_CTG_CMAS_TEST) {
+                               decodeCBBearerData(p_pkg_str+offset+1, tmp_len, &(p_cb->telesvc_msg), true);
+                       }
+                       else {
+                               decodeCBBearerData(p_pkg_str+offset+1, tmp_len, &(p_cb->telesvc_msg), false);
+                       }
+
+                       offset+=(tmp_len+1);
+               }
+       }
+
+       MSG_END();
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::decodeAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_trans_ack_msg_s *p_ack)
+{
+       MSG_BEGIN();
+
+       int offset = 0;
+
+       while (offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x04) {                                 // Destination Address
+                       offset += decodeAddress(p_pkg_str+offset, pkg_len, &(p_ack->address));
+               }
+               else if(p_pkg_str[offset] == 0x05) {                                    // Destination Subaddress
+                       offset += decodeSubAddress(p_pkg_str+offset, pkg_len, &(p_ack->sub_address));
+               }
+               else if(p_pkg_str[offset] == 0x07) {                                    // Cause Codes
+                       offset+=2;
+                       p_ack->cause_code.reply_seq = (sms_trans_reply_seq_t)p_pkg_str[offset] >> 2;
+                       switch(p_pkg_str[offset++] & 0x03) {
+                       case 0x00:
+                               p_ack->cause_code.error_class = SMS_TRANS_ERR_CLASS_NONE;
+                               break;
+                       case 0x01:
+                               break;
+                       case 0x10:
+                               p_ack->cause_code.error_class = SMS_TRANS_ERR_CLASS_TEMPORARY;
+                               break;
+                       case 0x11:
+                               p_ack->cause_code.error_class = SMS_TRANS_ERR_CLASS_PERMANENT;
+                               break;
+                       }
+
+                       if(p_ack->cause_code.error_class != SMS_TRANS_ERR_CLASS_NONE) {
+                               p_ack->cause_code.cause_code = (sms_trans_cause_code_t)p_pkg_str[offset++];
+                       }
+               }
+       }
+
+       MSG_END();
+
+       return offset;
+}
+
+
+void SmsPluginMsgCodec::decodeP2PTelesvcMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_msg_s *p_telesvc)
+{
+       MSG_BEGIN();
+
+       p_telesvc->type = findMsgType(p_pkg_str, pkg_len);
+
+       MSG_DEBUG("Msg Type = [%d]", p_telesvc->type);
+
+       switch (p_telesvc->type) {
+       case SMS_TYPE_DELIVER:
+               decodeP2PDeliverMsg(p_pkg_str, pkg_len, &p_telesvc->data.deliver);
+               break;
+       case SMS_TYPE_SUBMIT:
+               decodeP2PSubmitMsg(p_pkg_str, pkg_len, &p_telesvc->data.submit);
+               break;
+       case SMS_TYPE_DELIVERY_ACK:
+               decodeP2PDeliveryAckMsg(p_pkg_str, pkg_len, &p_telesvc->data.delivery_ack);
+               break;
+       case SMS_TYPE_USER_ACK:
+               decodeP2PUserAckMsg(p_pkg_str, pkg_len, &p_telesvc->data.user_ack);
+               break;
+       case SMS_TYPE_READ_ACK:
+               decodeP2PReadAckMsg(p_pkg_str, pkg_len, &p_telesvc->data.read_ack);
+               break;
+       case SMS_TYPE_SUBMIT_REPORT:
+//             decodeP2PSubmitReportMsg(p_pkg_str, pkg_len, &p_telesvc->data.report);
+               break;
+       default:
+               break;
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeP2PDeliverMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_deliver_s *p_del)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len, tmp_off;
+       unsigned short tmp_param_s;
+       unsigned char tmp_str[pkg_len+1];
+
+       while (offset < pkg_len) {
+               MSG_DEBUG("current offset = [%d] [%x]", offset, p_pkg_str[offset]);
+
+               switch (p_pkg_str[offset])
+               {
+                       case 0x00:                              // Message Identifier
+                               offset += decodeMsgId(p_pkg_str+offset, 5, &(p_del->msg_id));
+                               break;
+
+                       case 0x01:                              // User Data
+                               offset += 2;
+                               tmp_len = p_pkg_str[offset-1];
+                               memset(tmp_str, 0x00, sizeof(tmp_str));
+                               memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+                               decodeUserData(tmp_str, tmp_len, &(p_del->user_data));
+                               offset += tmp_len;
+                               break;
+
+                       case 0x03:                              // Message Center Time Stamp
+                               offset+=2;
+                               offset += decodeAbsTime(p_pkg_str+offset, &(p_del->time_stamp));
+                               break;
+
+                       case 0x04:                              // Validity Period - Absolute
+                               offset+=2;
+                               p_del->val_period.format = SMS_TIME_ABSOLUTE;
+                               offset += decodeAbsTime(p_pkg_str+offset, &(p_del->val_period.time.abs_time));
+                               break;
+
+                       case 0x05:                              // Validity Period - Relative
+                               offset+=2;
+                               p_del->val_period.format = SMS_TIME_RELATIVE;
+                               p_del->val_period.time.rel_time.rel_time = (sms_relative_time_t)p_pkg_str[offset++];
+                               break;
+
+                       case 0x08:                              // Priority Indicator
+                               offset+=2;
+                               p_del->priority = (sms_priority_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+                               break;
+
+                       case 0x09:                              // Privacy Indicator
+                               offset+=2;
+                               p_del->privacy = (sms_privacy_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+                               break;
+
+                       case 0x0a:                              // Reply Option
+                               offset+=2;
+
+                               if(p_pkg_str[offset] & 0x80)
+                                       p_del->reply_opt.user_ack_req = true;
+                               else
+                                       p_del->reply_opt.user_ack_req = false;
+
+                               if(p_pkg_str[offset] & 0x40)
+                                       p_del->reply_opt.deliver_ack_req = true;
+                               else
+                                       p_del->reply_opt.deliver_ack_req = false;
+
+                               if(p_pkg_str[offset] & 0x20)
+                                       p_del->reply_opt.read_ack_req = true;
+                               else
+                                       p_del->reply_opt.read_ack_req = false;
+
+                               if(p_pkg_str[offset] & 0x10)
+                                       p_del->reply_opt.report_req = true;
+                               else
+                                       p_del->reply_opt.report_req = false;
+
+                               offset++;
+                               break;
+
+                       case 0x0b:                              // Number of Message
+                               offset+=2;
+                               p_del->num_msg = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+                               offset++;
+                               break;
+
+                       case 0x0c:                              // Alert on Message Delivery
+                               offset+=2;
+                               tmp_len = p_pkg_str[offset-1];
+                               if (tmp_len > 0)
+                                       p_del->alert_priority = (sms_alert_priority_t)((p_pkg_str[offset] & 0xc0) >> 6);
+                               offset+=tmp_len;
+                               break;
+
+                       case 0x0d:                              // Language Indicator
+                               offset+=2;
+                               p_del->language = (sms_language_type_t)p_pkg_str[offset++];
+                               break;
+
+                       case 0x0e:                              // Call-Back Number
+                               offset+=2;
+                               tmp_len = p_pkg_str[offset-1];
+
+                               decodeCallBackNum(&p_pkg_str[offset], tmp_len, &(p_del->callback_number));
+
+                               offset+=tmp_len;
+                               break;
+
+                       case 0x0f:                              // Message Display Mode
+                               offset+=2;
+
+                               p_del->display_mode = (sms_display_mode_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+                               break;
+
+                       case 0x10:                              // Multiple Encoding User Data
+                               offset+=2;
+                               tmp_len = p_pkg_str[offset-1];
+
+
+                               // TODO
+
+
+
+                               offset+=tmp_len;
+                               break;
+
+                       case 0x11:                              // Message Deposit Index
+                               offset+=2;
+
+                               memset(&tmp_param_s, 0x00, sizeof(unsigned short));
+                               _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
+                               p_del->deposit_id = tmp_param_s;
+
+                               offset+=2;
+                               break;
+
+                       case 0x16:                              // Enhanced VMN
+                               offset++;
+                               tmp_len = p_pkg_str[offset++];
+                               memset(tmp_str, 0x00, sizeof(tmp_str));
+                               memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+                               tmp_off = 0;
+
+                               p_del->enhanced_vmn.priority = (sms_priority_indicator_t)(p_pkg_str[offset] >> 6);
+                               p_del->enhanced_vmn.password_req = p_pkg_str[offset] & 0x20 ? true : false;
+                               p_del->enhanced_vmn.setup_req = p_pkg_str[offset] & 0x10 ? true : false;
+                               p_del->enhanced_vmn.pw_change_req = p_pkg_str[offset] & 0x08 ? true : false;
+                               _shiftNBit_for_decode(tmp_str, tmp_len, 5);
+
+                               if(p_del->enhanced_vmn.setup_req || p_del->enhanced_vmn.pw_change_req) {
+                                       p_del->enhanced_vmn.min_pw_len = tmp_str[tmp_off] >> 4;
+                                       p_del->enhanced_vmn.max_pw_len = tmp_str[tmp_off++] & 0x0f;
+                               }
+
+                               p_del->enhanced_vmn.vm_num_unheard_msg = tmp_str[tmp_off++];
+                               p_del->enhanced_vmn.vm_mailbox_alm_full = tmp_str[tmp_off] & 0x80 ? true : false;
+                               p_del->enhanced_vmn.vm_mailbox_full = tmp_str[tmp_off] & 0x40 ? true : false;
+                               p_del->enhanced_vmn.reply_allowed = tmp_str[tmp_off] & 0x20 ? true : false;
+                               p_del->enhanced_vmn.fax_included = tmp_str[tmp_off] & 0x10 ? true : false;
+                               p_del->enhanced_vmn.vm_len = ((tmp_str[tmp_off] >> 0x0f) << 8) | tmp_str[tmp_off+1];
+                               tmp_off+=2;
+                               p_del->enhanced_vmn.vm_ret_day = tmp_str[tmp_off] >> 1;
+                               _shiftNBit_for_decode(tmp_str, tmp_len, 7);
+                               p_del->enhanced_vmn.vm_msg_id = (tmp_str[tmp_off] << 8) | tmp_str[tmp_off+1];
+                               tmp_off+=2;
+                               p_del->enhanced_vmn.vm_mailbox_id = (tmp_str[tmp_off] << 8) | tmp_str[tmp_off+1];
+                               tmp_off+=2;
+
+                               p_del->enhanced_vmn.an_digit_mode = (sms_digit_mode_t)(tmp_str[tmp_off] & 0x80 ? true : false);
+                               p_del->enhanced_vmn.an_number_type = (sms_number_type_t)((tmp_str[tmp_off] & 0x70) >> 4);
+                               if (p_del->enhanced_vmn.an_digit_mode) {
+                                       p_del->enhanced_vmn.an_number_plan = (sms_number_plan_t)(tmp_str[tmp_off++] & 0x0f);
+                                       p_del->enhanced_vmn.an_num_field = tmp_str[tmp_off++];
+                                       for(int i=0; i<p_del->enhanced_vmn.an_num_field; i++) {
+                                               switch(tmp_str[tmp_off] & 0xf0)
+                                               {
+                                                       case 0x10:
+                                                       case 0x20:
+                                                       case 0x30:
+                                                       case 0x40:
+                                                       case 0x50:
+                                                       case 0x60:
+                                                       case 0x70:
+                                                       case 0x80:
+                                                       case 0x90:
+                                                               p_del->enhanced_vmn.an_char[i] = ((tmp_str[tmp_off] & 0xf0) >> 4) + '0';
+                                                               break;
+                                                       case 0xa0:
+                                                               p_del->enhanced_vmn.an_char[i] = '0';
+                                                               break;
+                                                       case 0xb0:
+                                                               p_del->enhanced_vmn.an_char[i] = '*';
+                                                               break;
+                                                       case 0xc0:
+                                                               p_del->enhanced_vmn.an_char[i] = '#';
+                                                               break;
+                                                       default:
+                                                               break;
+                                               }
+
+                                               _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+                                       }
+                               }
+                               else {
+                                       _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+                                       p_del->enhanced_vmn.an_num_field = tmp_str[tmp_off++];
+                                       memset(p_del->enhanced_vmn.an_char, 0x00, sizeof(p_del->enhanced_vmn.an_char));
+                                       memcpy(p_del->enhanced_vmn.an_char, tmp_str+tmp_off, p_del->enhanced_vmn.an_num_field);
+                                       tmp_off+=p_del->enhanced_vmn.an_num_field;
+                               }
+
+                               p_del->enhanced_vmn.cli_digit_mode = (sms_digit_mode_t)(tmp_str[offset] & 0x80 ? true : false);
+                               p_del->enhanced_vmn.cli_number_type = (sms_number_type_t)(tmp_str[offset] & 0x70 >> 4);
+                               if (p_del->enhanced_vmn.cli_digit_mode) {
+                                       p_del->enhanced_vmn.cli_number_plan = (sms_number_plan_t)(tmp_str[tmp_off++] & 0x0f);
+                                       p_del->enhanced_vmn.cli_num_field = tmp_str[tmp_off++];
+                                       for(int i=0; i<p_del->enhanced_vmn.cli_num_field; i++) {
+                                               switch(tmp_str[tmp_off] & 0xf0)
+                                               {
+                                                       case 0x10:
+                                                       case 0x20:
+                                                       case 0x30:
+                                                       case 0x40:
+                                                       case 0x50:
+                                                       case 0x60:
+                                                       case 0x70:
+                                                       case 0x80:
+                                                       case 0x90:
+                                                               p_del->enhanced_vmn.cli_char[i] = ((tmp_str[tmp_off] & 0xf0) >> 4) + '0';
+                                                               break;
+                                                       case 0xa0:
+                                                               p_del->enhanced_vmn.cli_char[i] = '0';
+                                                               break;
+                                                       case 0xb0:
+                                                               p_del->enhanced_vmn.cli_char[i] = '*';
+                                                               break;
+                                                       case 0xc0:
+                                                               p_del->enhanced_vmn.cli_char[i] = '#';
+                                                               break;
+                                                       default:
+                                                               break;
+                                               }
+
+                                               _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+                                       }
+                               }
+                               else {
+                                       _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+                                       p_del->enhanced_vmn.cli_num_field = tmp_str[tmp_off++];
+                                       memset(p_del->enhanced_vmn.cli_char, 0x00, sizeof(p_del->enhanced_vmn.cli_char));
+                                       memcpy(p_del->enhanced_vmn.cli_char, tmp_str+tmp_off, p_del->enhanced_vmn.cli_num_field);
+                                       tmp_off+=p_del->enhanced_vmn.cli_num_field;
+                               }
+
+                               offset+=tmp_len;
+                               break;
+
+                       case 0x17:                              // Enhanced VMN Ack
+                               offset++;
+                               tmp_len = p_pkg_str[offset++];
+                               memset(tmp_str, 0x00, sizeof(tmp_str));
+                               memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+                               p_del->enhanced_vmn_ack.vm_mailbox_id = tmp_str[offset] << 8 | tmp_str[offset+1];
+                               offset+=2;
+                               p_del->enhanced_vmn_ack.vm_num_unheard_msg = tmp_str[offset++];
+                               p_del->enhanced_vmn_ack.num_delete_ack = tmp_str[offset] >> 5;
+                               p_del->enhanced_vmn_ack.num_play_ack = (tmp_str[offset] & 0x1c) >> 2;
+                               _shiftNBit_for_decode(tmp_str, tmp_len, 6);
+                               for(int i=0; i<p_del->enhanced_vmn_ack.num_delete_ack; i++) {
+                                       p_del->enhanced_vmn_ack.da_vm_msg_id[i] = tmp_str[offset] << 8 | tmp_str[offset+1];
+                                       offset+=2;
+                               }
+                               for(int i=0; i<p_del->enhanced_vmn_ack.num_play_ack; i++) {
+                                       p_del->enhanced_vmn_ack.pa_vm_msg_id[i] = tmp_str[offset] << 8 | tmp_str[offset+1];
+                                       offset+=2;
+                               }
+                               break;
+
+                       default:
+                               /* skip unrecognized sub parameters */
+                               offset++;
+                               tmp_len = p_pkg_str[offset++];
+                               offset += tmp_len;
+                               break;
+               }
+
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeP2PSubmitMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_submit_s *p_sub)
+{
+       int offset = 0, tmp_len;
+       unsigned short tmp_param_s;
+       unsigned char tmp_str[pkg_len+1];
+
+       while (offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x00) {                                 // Message Identifier
+                       offset += decodeMsgId(p_pkg_str+offset, 5, &(p_sub->msg_id));
+               }
+
+               else if(p_pkg_str[offset] == 0x01) {                                    // User Data
+                       offset += 2;
+                       tmp_len = p_pkg_str[offset-1];
+                       memset(tmp_str, 0x00, sizeof(tmp_str));
+                       memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+
+                       decodeUserData(tmp_str, tmp_len, &(p_sub->user_data));
+
+                       offset += tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x04) {                            // Validity Period - Absolute
+                       offset+=2;
+                       p_sub->val_period.format = SMS_TIME_ABSOLUTE;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_sub->val_period.time.abs_time));
+               }
+
+               else if(p_pkg_str[offset] == 0x05) {                            // Validity Period - Relative
+                       offset+=2;
+                       p_sub->val_period.format = SMS_TIME_RELATIVE;
+                       p_sub->val_period.time.rel_time.rel_time = (sms_relative_time_t)p_pkg_str[offset++];
+               }
+
+               else if(p_pkg_str[offset] == 0x06) {                            // Deferred Delivery Time - Absolute
+                       offset+=2;
+                       p_sub->defer_val_period.format = SMS_TIME_ABSOLUTE;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_sub->defer_val_period.time.abs_time));
+               }
+
+               else if(p_pkg_str[offset] == 0x07) {                            // Deferred Delivery Time - Relative
+                       offset+=2;
+                       p_sub->defer_val_period.format = SMS_TIME_RELATIVE;
+                       p_sub->defer_val_period.time.rel_time.rel_time = (sms_relative_time_t)p_pkg_str[offset++];
+               }
+
+               else if(p_pkg_str[offset] == 0x08) {                            // Priority indicator
+                       offset+=2;
+                       p_sub->priority = (sms_priority_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+               }
+
+               else if(p_pkg_str[offset] == 0x09) {                            // Privacy indicator
+                       offset+=2;
+                       p_sub->privacy = (sms_privacy_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+               }
+
+               else if(p_pkg_str[offset] == 0x0a) {                            // Reply Option
+                       offset+=2;
+
+                       if(p_pkg_str[offset] & 0x80)
+                               p_sub->reply_opt.user_ack_req = true;
+                       else
+                               p_sub->reply_opt.user_ack_req = false;
+
+                       if(p_pkg_str[offset] & 0x40)
+                               p_sub->reply_opt.deliver_ack_req = true;
+                       else
+                               p_sub->reply_opt.deliver_ack_req = false;
+
+                       if(p_pkg_str[offset] & 0x20)
+                               p_sub->reply_opt.read_ack_req = true;
+                       else
+                               p_sub->reply_opt.read_ack_req = false;
+
+                       if(p_pkg_str[offset] & 0x10)
+                               p_sub->reply_opt.report_req = true;
+                       else
+                               p_sub->reply_opt.report_req = false;
+
+                       offset++;
+               }
+
+               else if(p_pkg_str[offset] == 0x0c) {                            // Alert on Message Delivery
+                       offset+=2;
+
+                       p_sub->alert_priority = (sms_alert_priority_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+               }
+
+               else if(p_pkg_str[offset] == 0x0d) {                            // Language Indicator
+                       offset+=2;
+
+                       p_sub->language = (sms_language_type_t)p_pkg_str[offset++];
+               }
+
+               else if(p_pkg_str[offset] == 0x0e) {                            // Call-Back Number
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+                       decodeCallBackNum(&p_pkg_str[offset], tmp_len, &(p_sub->callback_number));
+
+                       offset+=tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x10) {                            // Multiple Encoding User Data
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+
+                       // TODO
+
+
+
+                       offset+=tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x11) {                            // Message Deposit Index
+                       offset+=2;
+
+                       memset(&tmp_param_s, 0x00, sizeof(unsigned short));
+                       _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
+                       p_sub->deposit_id = tmp_param_s;
+
+                       offset+=2;
+               }
+       }
+
+}
+
+
+void SmsPluginMsgCodec::decodeP2PUserAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_user_ack_s *p_user_ack)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len;
+       unsigned short tmp_param_s;
+       unsigned char tmp_str[pkg_len+1];
+
+       while (offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x00) {                                 // Message Identifier
+                       offset += decodeMsgId(p_pkg_str+offset, 5, &(p_user_ack->msg_id));
+               }
+
+               else if(p_pkg_str[offset] == 0x01) {                                    // User Data
+                       offset += 2;
+                       tmp_len = p_pkg_str[offset-1];
+                       memset(tmp_str, 0x00, sizeof(tmp_str));
+                       memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+
+                       decodeUserData(tmp_str, tmp_len, &(p_user_ack->user_data));
+
+                       offset += tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x02) {                            // User Response Code
+                       offset += 2;
+                       p_user_ack->resp_code = p_pkg_str[offset++];
+               }
+
+               else if(p_pkg_str[offset] == 0x03) {                            // Message Center Time Stamp
+                       offset+=2;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_user_ack->time_stamp));
+               }
+
+               else if(p_pkg_str[offset] == 0x10) {                            // Multiple Encoding User Data
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+
+                       // TODO
+
+
+
+                       offset+=tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x11) {                            // Message Deposit Index
+                       offset+=2;
+
+                       memset(&tmp_param_s, 0x00, sizeof(unsigned short));
+                       _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
+                       p_user_ack->deposit_id = tmp_param_s;
+
+                       offset+=2;
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeP2PReadAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_read_ack_s *p_read_ack)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len;
+       unsigned short tmp_param_s;
+       unsigned char tmp_str[pkg_len+1];
+
+       while (offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x00) {                                 // Message Identifier
+                       offset += decodeMsgId(p_pkg_str+offset, 5, &(p_read_ack->msg_id));
+               }
+
+               else if(p_pkg_str[offset] == 0x01) {                                    // User Data
+                       offset += 2;
+                       tmp_len = p_pkg_str[offset-1];
+                       memset(tmp_str, 0x00, sizeof(tmp_str));
+                       memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+
+                       decodeUserData(tmp_str, tmp_len, &(p_read_ack->user_data));
+
+                       offset += tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x03) {                            // Message Center Time Stamp
+                       offset+=2;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_read_ack->time_stamp));
+               }
+
+               else if(p_pkg_str[offset] == 0x10) {                            // Multiple Encoding User Data
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+
+                       // TODO
+
+
+
+                       offset+=tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x11) {                            // Message Deposit Index
+                       offset+=2;
+
+                       memset(&tmp_param_s, 0x00, sizeof(unsigned short));
+                       _copy_char_to_short(&tmp_param_s, p_pkg_str+offset);
+                       p_read_ack->deposit_id = tmp_param_s;
+
+                       offset+=2;
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeP2PSubmitReportMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_report_s *p_sub_report)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len;
+       unsigned char tmp_str[pkg_len+1];
+
+       while (offset < pkg_len) {
+               switch (p_pkg_str[offset]) {
+               case 0x00:                                      // Message Identifier
+                       offset += decodeMsgId(p_pkg_str+offset, 5, &(p_sub_report->msg_id));
+                       break;
+
+               case 0x01:                                      // User Data
+                       offset += 2;
+                       tmp_len = p_pkg_str[offset-1];
+                       memset(tmp_str, 0x00, sizeof(tmp_str));
+                       memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+                       decodeUserData(tmp_str, tmp_len, &(p_sub_report->user_data));
+                       offset += tmp_len;
+                       break;
+
+               case 0x0d:                                      // Language Indicator
+                       offset+=2;
+                       p_sub_report->language = (sms_language_type_t)p_pkg_str[offset++];
+                       break;
+
+               case 0x10:                                      // Multiple Encoding User Data
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+
+                       // TODO
+
+
+
+                       offset+=tmp_len;
+                       break;
+
+               case 0x15:                                      // TP-Failure Cause
+                       offset += 2;
+                       p_sub_report->tp_fail_cause = p_pkg_str[offset++];
+                       break;
+
+               default:
+                       break;
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeP2PDeliveryAckMsg(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_deliver_ack_s *p_del_ack)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len;
+       unsigned char tmp_str[pkg_len+1];
+
+       while(offset < pkg_len) {
+               switch (p_pkg_str[offset]) {
+               case 0x00:                                      // Message Identifier
+                       offset += decodeMsgId(p_pkg_str+offset, 5, &(p_del_ack->msg_id));
+                       break;
+
+               case 0x01:                                      // User Data
+                       offset += 2;
+                       tmp_len = p_pkg_str[offset-1];
+                       memset(tmp_str, 0x00, sizeof(tmp_str));
+                       memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+
+                       decodeUserData(tmp_str, tmp_len, &(p_del_ack->user_data));
+
+                       offset += tmp_len;
+                       break;
+
+               case 0x03:                                      // Message Center Time Stamp
+                       offset+=2;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_del_ack->time_stamp));
+                       break;
+
+               case 0x10:                                      // Multiple Encoding User Data
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+
+                       // TODO
+
+
+
+                       offset+=tmp_len;
+                       break;
+
+               case 0x14:                                      // Message Status
+                       offset+=2;
+                       p_del_ack->msg_status = (sms_status_code_t)p_pkg_str[offset++];
+                       break;
+
+               default:
+                       break;
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeCBBearerData(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_msg_s *p_telesvc, bool isCMAS)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len;
+       unsigned char tmp_str[pkg_len+1];
+
+       while (offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x00) {                                 // Message Identifier
+                       p_telesvc->type = SMS_TYPE_DELIVER;
+                       offset += decodeMsgId(p_pkg_str+offset, 5, &(p_telesvc->data.deliver.msg_id));
+               }
+
+               else if(p_pkg_str[offset] == 0x01) {                                    // User Data
+                       offset += 2;
+                       tmp_len = p_pkg_str[offset-1];
+                       memset(tmp_str, 0x00, sizeof(tmp_str));
+                       memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+
+                       if(isCMAS)
+                               decodeCMASData(tmp_str, tmp_len, &(p_telesvc->data.deliver.cmas_data));
+                       else
+                               decodeUserData(tmp_str, tmp_len, &(p_telesvc->data.deliver.user_data));
+
+                       offset += tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x03) {                            // Message Center Time Stamp
+                       offset += 2;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_telesvc->data.deliver.time_stamp));
+               }
+
+               else if(p_pkg_str[offset] == 0x04) {                            // Validity Period - Absolute
+                       offset += 2;
+                       p_telesvc->data.deliver.val_period.format = SMS_TIME_ABSOLUTE;
+                       offset += decodeAbsTime(p_pkg_str+offset, &(p_telesvc->data.deliver.val_period.time.abs_time));
+               }
+
+               else if(p_pkg_str[offset] == 0x05) {                            // Validity Period - Relative
+                       offset+=2;
+                       p_telesvc->data.deliver.val_period.format = SMS_TIME_RELATIVE;
+                       p_telesvc->data.deliver.val_period.time.rel_time.rel_time = (sms_relative_time_t)p_pkg_str[offset++];
+               }
+
+               else if(p_pkg_str[offset] == 0x08) {                            // Priority indicator
+                       offset+=2;
+                       p_telesvc->data.deliver.priority = (sms_priority_indicator_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+               }
+
+               else if(p_pkg_str[offset] == 0x0c) {                            // Alert on Message Delivery
+                       offset+=2;
+
+                       p_telesvc->data.deliver.alert_priority = (sms_alert_priority_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+               }
+
+               else if(p_pkg_str[offset] == 0x0d) {                            // Language Indicator
+                       offset+=2;
+
+                       p_telesvc->data.deliver.language = (sms_language_type_t)p_pkg_str[offset++];
+               }
+
+               else if(p_pkg_str[offset] == 0x0e) {                            // Call-Back Number
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+                       decodeCallBackNum(&p_pkg_str[offset], tmp_len, &(p_telesvc->data.deliver.callback_number));
+
+                       offset+=tmp_len;
+               }
+
+               else if(p_pkg_str[offset] == 0x0f) {                            // Message Display Mode
+                       offset+=2;
+
+                       p_telesvc->data.deliver.display_mode = (sms_display_mode_t)((p_pkg_str[offset++] & 0xc0) >> 6);
+               }
+
+               else if(p_pkg_str[offset] == 0x10) {                            // Multiple Encoding User Data
+                       offset+=2;
+                       tmp_len = p_pkg_str[offset-1];
+
+
+                       // TODO
+
+
+
+                       offset+=tmp_len;
+               }
+       }
+
+       MSG_END();
+}
+
+
+int SmsPluginMsgCodec::decodeTeleId(const unsigned char *p_pkg_str, int pkg_len, sms_trans_telesvc_id_t *tele_id)
+{
+       int offset = 0;
+       unsigned short tmp_param_s;
+
+       offset+=2;
+
+    _copy_char_to_short(&tmp_param_s, &p_pkg_str[offset]);
+
+       switch(tmp_param_s) {
+               case SMS_TRANS_TELESVC_CMT_91:
+                       *tele_id = SMS_TRANS_TELESVC_CMT_91;
+                       break;
+               case SMS_TRANS_TELESVC_CPT_95:
+                       *tele_id = SMS_TRANS_TELESVC_CPT_95;
+                       break;
+               case SMS_TRANS_TELESVC_CMT_95:
+                       *tele_id = SMS_TRANS_TELESVC_CMT_95;
+                       break;
+               case SMS_TRANS_TELESVC_VMN_95:
+                       *tele_id = SMS_TRANS_TELESVC_VMN_95;
+                       break;
+               case SMS_TRANS_TELESVC_WAP:
+                       *tele_id = SMS_TRANS_TELESVC_WAP;
+                       break;
+               case SMS_TRANS_TELESVC_WEMT:
+                       *tele_id = SMS_TRANS_TELESVC_WEMT;
+                       break;
+               case SMS_TRANS_TELESVC_SCPT:
+                       *tele_id = SMS_TRANS_TELESVC_SCPT;
+                       break;
+               case SMS_TRANS_TELESVC_CATPT:
+                       *tele_id = SMS_TRANS_TELESVC_CATPT;
+                       break;
+               default:
+                       *tele_id = SMS_TRANS_TELESVC_RESERVED;
+                       break;
+       }
+
+       return offset+2;
+}
+
+
+int SmsPluginMsgCodec::decodeSvcCtg(const unsigned char *p_pkg_str, int pkg_len, sms_trans_svc_ctg_t *svc_ctg)
+{
+       int offset = 0;
+       unsigned short tmp_param_s;
+
+       offset+=2;
+
+       _copy_char_to_short(&tmp_param_s, &p_pkg_str[offset]);
+       if((tmp_param_s >= SMS_TRANS_SVC_CTG_UNKNOWN && tmp_param_s <= SMS_TRANS_SVC_CTG_KDDI_CORP_MAX1)
+               || (tmp_param_s >= SMS_TRANS_SVC_CTG_KDDI_CORP_MIN2 && tmp_param_s <= SMS_TRANS_SVC_CTG_KDDI_CORP_MAX2)
+               || (tmp_param_s >= SMS_TRANS_SVC_CTG_KDDI_CORP_MIN3 && tmp_param_s <= SMS_TRANS_SVC_CTG_KDDI_CORP_MAX3)) {
+               *svc_ctg = (sms_trans_svc_ctg_t)tmp_param_s;
+       }
+       else {
+               *svc_ctg = SMS_TRANS_SVC_CTG_RESERVED;
+       }
+
+       return offset+2;
+}
+
+
+int SmsPluginMsgCodec::decodeAddress(const unsigned char *p_pkg_str, int pkg_len, sms_trans_addr_s *addr)
+{
+       int offset = 0, tmp_len = 0;
+       unsigned char tmp_str[pkg_len+1];
+
+       tmp_len = p_pkg_str[++offset];
+
+       memset(tmp_str, 0x00, sizeof(tmp_str));
+       memcpy(tmp_str, p_pkg_str+offset+1, tmp_len);
+
+       offset += (tmp_len+1);
+
+       if(tmp_str[0] & 0x80)
+               addr->digit_mode = true;
+       else
+               addr->digit_mode = false;
+
+       if(tmp_str[0] & 0x40)
+               addr->number_mode = true;
+       else
+               addr->number_mode = false;
+
+       _shiftNBit_for_decode(tmp_str, tmp_len, 2);
+
+       if(addr->digit_mode == false) {
+               addr->addr_len = tmp_str[0];
+
+               memset(addr->szData, 0x00, sizeof(addr->szData));
+
+               for(unsigned int i = 0; i < addr->addr_len; i++) {
+                       switch(tmp_str[1] & 0xf0) {
+                               case 0x10:
+                               case 0x20:
+                               case 0x30:
+                               case 0x40:
+                               case 0x50:
+                               case 0x60:
+                               case 0x70:
+                               case 0x80:
+                               case 0x90:
+                                       addr->szData[i] = ((tmp_str[1] & 0xf0) >> 4) + '0';
+                                       break;
+                               case 0x00://sprint issue
+                               case 0xa0:
+                                       addr->szData[i] = '0';
+                                       break;
+                               case 0xb0:
+                                       addr->szData[i] = '*';
+                                       break;
+                               case 0xc0:
+                                       addr->szData[i] = '#';
+                                       break;
+                               default:
+                                       break;
+                       }
+
+                       _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+               }
+       }
+       else if(addr->digit_mode == true) {
+               if(addr->number_mode == false) {                                                // digit mode = 1, number mode = 0
+                       switch(tmp_str[0] & 0xe0) {
+                               case 0x00:
+                                       addr->number_type = SMS_NUMBER_TYPE_UNKNOWN;
+                                       break;
+                               case 0x20:
+                                       addr->number_type = SMS_NUMBER_TYPE_INTERNATIONAL;
+                                       break;
+                               case 0x40:
+                                       addr->number_type = SMS_NUMBER_TYPE_NATIONAL;
+                                       break;
+                               case 0x60:
+                                       addr->number_type = SMS_NUMBER_TYPE_NETWORK_SPECIFIC;
+                                       break;
+                               case 0x80:
+                                       addr->number_type = SMS_NUMBER_TYPE_SUBSCRIBER;
+                                       break;
+                               case 0xa0:
+                                       addr->number_type = SMS_NUMBER_TYPE_RESERVED_5;
+                                       break;
+                               case 0xc0:
+                                       addr->number_type = SMS_NUMBER_TYPE_ABBREVIATED;
+                                       break;
+                               case 0xe0:
+                                       addr->number_type = SMS_NUMBER_TYPE_RESERVED_7;
+                                       break;
+                       }
+
+                       _shiftNBit_for_decode(tmp_str, tmp_len, 3);
+
+                       switch(tmp_str[0] & 0xf0) {
+                               case 0x00:
+                                       addr->number_plan = SMS_NPI_UNKNOWN;
+                                       break;
+                               case 0x10:
+                                       addr->number_plan = SMS_NPI_ISDN;
+                                       break;
+                               case 0x30:
+                                       addr->number_plan = SMS_NPI_DATA;
+                                       break;
+                               case 0x40:
+                                       addr->number_plan = SMS_NPI_TELEX;
+                                       break;
+                               case 0x90:
+                                       addr->number_plan = SMS_NPI_PRIVATE;
+                                       break;
+                               default:
+                                       addr->number_plan = SMS_NPI_RESERVED;
+                                       break;
+                       }
+
+                       _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+               }
+               else if(addr->number_mode == true) {                                            // digit mode = 1, number mode = 1
+                       switch(tmp_str[0] & 0xe0) {
+                               case 0x00:
+                                       addr->number_type = SMS_TRANS_DNET_UNKNOWN;
+                                       break;
+                               case 0x20:
+                                       addr->number_type = SMS_TRANS_DNET_INTERNET_PROTOCOL;
+                                       break;
+                               case 0x40:
+                                       addr->number_type = SMS_TRANS_DNET_INTERNET_MAIL_ADDR;
+                                       break;
+                               default:
+                                       addr->number_type = SMS_TRANS_DNET_RESERVED;
+                                       break;
+                       }
+
+                       _shiftNBit_for_decode(tmp_str, tmp_len, 3);
+               }
+
+               addr->addr_len = tmp_str[0];
+
+               memset(addr->szData, 0x00, sizeof(addr->szData));
+               memcpy(addr->szData, &tmp_str[1], addr->addr_len);
+       }
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::decodeSubAddress(const unsigned char *p_pkg_str, int pkg_len, sms_trans_sub_addr_s *sub_addr)
+{
+       int offset = 0, tmp_len = 0;
+       unsigned char tmp_str[pkg_len+1];
+
+       tmp_len = p_pkg_str[++offset];
+       memset(tmp_str, 0x00, sizeof(tmp_str));
+       memcpy(tmp_str, p_pkg_str+offset+1, tmp_len);
+
+       offset += (tmp_len+1);
+
+       switch(tmp_str[0] & 0xe0) {
+               case 0x00:
+                       sub_addr->type = SMS_TRANS_SUB_ADDR_NSAP;
+                       break;
+               case 0x20:
+                       sub_addr->type = SMS_TRANS_SUB_ADDR_USER;
+                       break;
+               default:
+                       sub_addr->type = SMS_TRANS_SUB_ADDR_RESERVED;
+                       break;
+       }
+
+       if(tmp_str[0] & 0x10)
+               sub_addr->odd = true;
+       else
+               sub_addr->odd = false;
+
+       _shiftNBit_for_decode(tmp_str, tmp_len, 4);
+       memset(sub_addr->szData, 0x00, sizeof(sub_addr->szData));
+       memcpy(sub_addr->szData, tmp_str+1, tmp_str[0]);
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::decodeMsgId(const unsigned char *p_pkg_str, int pkg_len, sms_trans_msg_id_s *p_msg_id)
+{
+       int offset = 0;
+       unsigned short tmp_param_s;
+       unsigned char tmp_str[pkg_len+1];
+
+       memset(tmp_str, 0x00, sizeof(tmp_str));
+       memcpy(tmp_str, &p_pkg_str[offset+2], 3);
+
+       _shiftNBit_for_decode(tmp_str, 3, 4);
+
+       memset(&tmp_param_s, 0x00, sizeof(unsigned short));
+       _copy_char_to_short(&tmp_param_s, tmp_str);
+
+       p_msg_id->msg_id = tmp_param_s;
+       if(tmp_str[2] & 0x80)
+               p_msg_id->header_ind = true;
+       else
+               p_msg_id->header_ind = false;
+
+       offset+=5;
+
+       return offset;
+}
+
+
+void SmsPluginMsgCodec::decodeCallBackNum(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_addr_s *p_callback)
+{
+       int offset = 0;
+       unsigned char tmp_str[pkg_len+1];
+
+       if(p_pkg_str[offset] & 0x80) {
+               p_callback->digit_mode = true;
+
+               switch(p_pkg_str[offset] & 0x70) {
+                       case 0x00:
+                               p_callback->number_type = SMS_NUMBER_TYPE_UNKNOWN;
+                               break;
+                       case 0x10:
+                               p_callback->number_type = SMS_NUMBER_TYPE_INTERNATIONAL;
+                               break;
+                       case 0x20:
+                               p_callback->number_type = SMS_NUMBER_TYPE_NATIONAL;
+                               break;
+                       case 0x30:
+                               p_callback->number_type = SMS_NUMBER_TYPE_NETWORK_SPECIFIC;
+                               break;
+                       case 0x40:
+                               p_callback->number_type = SMS_NUMBER_TYPE_SUBSCRIBER;
+                               break;
+                       case 0x50:
+                               p_callback->number_type = SMS_NUMBER_TYPE_RESERVED_5;
+                               break;
+                       case 0x60:
+                               p_callback->number_type = SMS_NUMBER_TYPE_ABBREVIATED;
+                               break;
+                       case 0x70:
+                               p_callback->number_type = SMS_NUMBER_TYPE_RESERVED_7;
+                               break;
+                       default:
+                               break;
+               }
+
+               switch(p_pkg_str[offset++] & 0x0f) {
+               case 0x00:
+                       p_callback->number_plan = SMS_NPI_UNKNOWN;
+                       break;
+               case 0x01:
+                       p_callback->number_plan = SMS_NPI_ISDN;
+                       break;
+               case 0x03:
+                       p_callback->number_plan = SMS_NPI_DATA;
+                       break;
+               case 0x04:
+                       p_callback->number_plan = SMS_NPI_TELEX;
+                       break;
+               case 0x09:
+                       p_callback->number_plan = SMS_NPI_PRIVATE;
+                       break;
+               case 0x0f:
+               default:
+                       p_callback->number_plan = SMS_NPI_RESERVED;
+                       break;
+               }
+
+               p_callback->addr_len = p_pkg_str[offset++];
+               memset(p_callback->szData, 0x00, sizeof(p_callback->szData));
+
+               if (p_callback->number_type == SMS_NUMBER_TYPE_INTERNATIONAL) {
+                       memcpy(&(p_callback->szData[1]), p_pkg_str+offset, p_callback->addr_len);
+                       if(p_callback->szData[1] != '\0') {
+                               p_callback->szData[0] = '+';
+                       }
+               }
+               else {
+                       memcpy(p_callback->szData, p_pkg_str+offset, p_callback->addr_len);
+               }
+       }
+       else {
+               p_callback->digit_mode = false;
+
+               memset(tmp_str, 0x00, sizeof(tmp_str));
+               memcpy(tmp_str, p_pkg_str+offset, pkg_len);
+
+               _shiftNBit_for_decode(tmp_str, pkg_len, 1);
+
+               p_callback->addr_len = tmp_str[0];
+
+               memset(p_callback->szData, 0x00, sizeof(p_callback->szData));
+
+               for(unsigned int i = 0; i < p_callback->addr_len; i++) {
+                       switch(tmp_str[1] & 0xf0) {
+                               case 0x10:
+                               case 0x20:
+                               case 0x30:
+                               case 0x40:
+                               case 0x50:
+                               case 0x60:
+                               case 0x70:
+                               case 0x80:
+                               case 0x90:
+                                       p_callback->szData[i] = ((tmp_str[1] & 0xf0) >> 4) + '0';
+                                       break;
+                               case 0xa0:
+                                       p_callback->szData[i] = '0';
+                                       break;
+                               case 0xb0:
+                                       p_callback->szData[i] = '*';
+                                       break;
+                               case 0xc0:
+                                       p_callback->szData[i] = '#';
+                                       break;
+                               default :
+                                       break;
+                       }
+
+                       _shiftNBit_for_decode(tmp_str, pkg_len, 4);
+               }
+       }
+
+
+}
+
+
+int SmsPluginMsgCodec::decodeAbsTime(const unsigned char *p_pkg_str, sms_time_abs_s *p_time_abs)
+{
+       int offset = 0;
+
+       p_time_abs->year = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+       offset++;
+       p_time_abs->month = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+       offset++;
+       p_time_abs->day = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+       offset++;
+       p_time_abs->hours = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+       offset++;
+       p_time_abs->minutes = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+       offset++;
+       p_time_abs->seconds = (((p_pkg_str[offset] & 0xf0) >> 4) * 10) + (p_pkg_str[offset] & 0x0f);
+       offset++;
+
+       return offset;
+}
+
+
+int SmsPluginMsgCodec::encodeUserData(const unsigned char* src, unsigned char *dest, int src_size)
+{
+       int i, j;
+       int shift = 0;
+
+       unsigned char *tmp = (unsigned char *)calloc(1, src_size+1);
+       for (i = 0; i < src_size; i++) {
+               tmp[i] = src[i] << 1;
+       }
+
+       j = 0;
+       for (i = 0; i < src_size; i++) {
+               shift = j % 7;
+               dest[j++] = (tmp[i] << shift) + (tmp[i+1] >> (7-shift));
+               if(shift == 6) {
+                       i++;
+               }
+       }
+
+       if (tmp) {
+               free(tmp);
+               tmp = NULL;
+       }
+
+       return j;
+}
+
+
+void SmsPluginMsgCodec::decodeCMASData(unsigned char *p_pkg_str, int pkg_len, sms_telesvc_cmasdata_s *p_cmas)
+{
+       MSG_BEGIN();
+
+       int offset = 0, tmp_len = 0;
+       unsigned char tmp_str[pkg_len+1];
+
+       if ((p_pkg_str[offset] & 0xf8) != 0x00) {
+               MSG_ERR("Wrong Encode Type = [%d]!! The type must be 0", (p_pkg_str[offset]&0xf8)>>3);
+               return;
+       }
+       else {
+               _shiftNBit_for_decode(p_pkg_str, pkg_len, 5);
+
+               offset++;
+
+               if (p_pkg_str[offset++] != 0x00) {
+                       MSG_ERR("Wrong protocol version = [%d]!! This field must be 0", p_pkg_str[offset-1]);
+                       p_cmas->is_wrong_recode_type  = TRUE;
+                       return;
+               }
+
+               while (offset < pkg_len - 1) {
+                       if (p_pkg_str[offset] == 0x00) {
+                               MSG_DEBUG("Type 0 Decode!");
+                               offset++;
+                               tmp_len = p_pkg_str[offset++];
+                               MSG_DEBUG("Type 0 length = [%d]", tmp_len);
+                               memset(tmp_str, 0x00, sizeof(tmp_str));
+                               memcpy(tmp_str, p_pkg_str+offset, tmp_len);
+
+                               switch(tmp_str[0] & 0xf8) {
+                                       case 0x00:
+                                               p_cmas->encode_type = SMS_ENCODE_OCTET;
+                                               break;
+                                       case 0x08:
+                                               p_cmas->encode_type = SMS_ENCODE_EPM;
+                                               break;
+                                       case 0x10:
+                                               p_cmas->encode_type = SMS_ENCODE_7BIT_ASCII;
+                                               break;
+                                       case 0x18:
+                                               p_cmas->encode_type = SMS_ENCODE_IA5;
+                                               break;
+                                       case 0x20:
+                                               p_cmas->encode_type = SMS_ENCODE_UNICODE;
+                                               break;
+                                       case 0x28:
+                                               p_cmas->encode_type = SMS_ENCODE_SHIFT_JIS;
+                                               break;
+                                       case 0x30:
+                                               p_cmas->encode_type = SMS_ENCODE_KOREAN;
+                                               break;
+                                       case 0x38:
+                                               p_cmas->encode_type = SMS_ENCODE_LATIN_HEBREW;
+                                               break;
+                                       case 0x40:
+                                               p_cmas->encode_type = SMS_ENCODE_LATIN;
+                                               break;
+                                       case 0x48:
+                                               p_cmas->encode_type = SMS_ENCODE_GSM7BIT;
+                                               break;
+                                       case 0x50:
+                                               p_cmas->encode_type = SMS_ENCODE_GSMDCS;
+                                               break;
+                                       case 0x80:              // reserved value, but SKT use this value for KSC5601
+                                               p_cmas->encode_type = SMS_ENCODE_EUCKR;
+                                               break;
+                                       default :
+                                               p_cmas->encode_type = SMS_ENCODE_RESERVED;
+                                               break;
+                               }
+                               _shiftNBit_for_decode(tmp_str, tmp_len, 5);
+
+                               switch(p_cmas->encode_type) {
+                                       case SMS_ENCODE_7BIT_ASCII:
+                                       case SMS_ENCODE_IA5:
+                                       case SMS_ENCODE_GSM7BIT:
+                                               memset(p_cmas->alert_text, 0x00, sizeof(p_cmas->alert_text));
+                                               p_cmas->data_len = (tmp_len*8-5) / 7;
+                                               for(unsigned int i = 0; i < p_cmas->data_len; i++) {
+                                                       p_cmas->alert_text[i] = tmp_str[0] >> 1;
+                                                       _shiftNBit_for_decode(tmp_str, tmp_len, 7);
+                                               }
+                                               break;
+                                       case SMS_ENCODE_EPM:
+                                               break;
+                                       case SMS_ENCODE_GSMDCS:
+                                               break;
+                                       default:
+                                               p_cmas->data_len = tmp_len - 1;
+                                               memset(p_cmas->alert_text, 0x00, sizeof(p_cmas->alert_text));
+                                               memcpy(p_cmas->alert_text, tmp_str+offset, tmp_len-1);
+                                               break;
+                               }
+
+                               offset+=tmp_len;
+                       }
+
+                       else if (p_pkg_str[offset] == 0x01) {
+                               MSG_DEBUG("Type 1 Decode!");
+                               offset+=2;
+                               tmp_len = p_pkg_str[offset-1];
+                               MSG_DEBUG("Type 1 length = [%d]", tmp_len);
+                               p_cmas->category = (sms_cmae_category_t)p_pkg_str[offset++];
+                               p_cmas->response_type = (sms_cmae_response_type_t)p_pkg_str[offset++];
+                               p_cmas->severity = (sms_cmae_severity_t)(p_pkg_str[offset] >> 4);
+                               p_cmas->urgency = (sms_cmae_urgency_t)(p_pkg_str[offset++] & 0x0f);
+                               p_cmas->certainty = (sms_cmae_certainty_t)(p_pkg_str[offset++] >> 4);
+                       }
+
+                       else if (p_pkg_str[offset] == 0x02) {
+                               MSG_DEBUG("Type 2 Decode!");
+                               offset+=2;
+                               tmp_len = p_pkg_str[offset-1];
+                               MSG_DEBUG("Type 2 length = [%d]", tmp_len);
+                               _copy_char_to_short(&(p_cmas->id), p_pkg_str+offset);
+                               offset+=2;
+                               p_cmas->alert_handle = (sms_cmae_alert_handle_t)p_pkg_str[offset++];
+                               offset += decodeAbsTime(p_pkg_str+offset, &(p_cmas->expires));
+                               p_cmas->language = (sms_language_type_t)p_pkg_str[offset++];
+                       }
+
+                       MSG_DEBUG("offset = [%d], pkg_len = [%d]", offset, pkg_len);
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginMsgCodec::decodeUserData(unsigned char *p_pkg_str, int pkg_len, sms_telesvc_userdata_s *p_user)
+{
+       switch(p_pkg_str[0] & 0xf8) {
+               case 0x00:
+                       p_user->encode_type = SMS_ENCODE_OCTET;
+                       break;
+               case 0x08:
+                       p_user->encode_type = SMS_ENCODE_EPM;
+                       break;
+               case 0x10:
+                       p_user->encode_type = SMS_ENCODE_7BIT_ASCII;
+                       break;
+               case 0x18:
+                       p_user->encode_type = SMS_ENCODE_IA5;
+                       break;
+               case 0x20:
+                       p_user->encode_type = SMS_ENCODE_UNICODE;
+                       break;
+               case 0x28:
+                       p_user->encode_type = SMS_ENCODE_SHIFT_JIS;
+                       break;
+               case 0x30:
+                       p_user->encode_type = SMS_ENCODE_KOREAN;
+                       break;
+               case 0x38:
+                       p_user->encode_type = SMS_ENCODE_LATIN_HEBREW;
+                       break;
+               case 0x40:
+                       p_user->encode_type = SMS_ENCODE_LATIN;
+                       break;
+               case 0x48:
+                       p_user->encode_type = SMS_ENCODE_GSM7BIT;
+                       break;
+               case 0x50:
+                       p_user->encode_type = SMS_ENCODE_GSMDCS;
+                       break;
+               case 0x80:              // reserved value, but SKT use this value for KSC5601
+                       p_user->encode_type = SMS_ENCODE_EUCKR;
+                       break;
+               default :
+                       p_user->encode_type = SMS_ENCODE_RESERVED;
+                       break;
+       }
+
+       _shiftNBit_for_decode(p_pkg_str, pkg_len, 5);
+
+       if(p_user->encode_type == SMS_ENCODE_EPM || p_user->encode_type == SMS_ENCODE_GSMDCS) {
+               p_user->msg_type = p_pkg_str[0];
+               _shiftNBit_for_decode(p_pkg_str, pkg_len, 8);
+       }
+
+       p_user->data_len = p_pkg_str[0];
+       switch(p_user->encode_type) {
+               case SMS_ENCODE_7BIT_ASCII:
+                       memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
+                       for(unsigned int i = 0; i < p_user->data_len; i++) {
+                               p_user->user_data[i] = p_pkg_str[1] >> 1;
+                               _shiftNBit_for_decode(p_pkg_str, pkg_len, 7);
+                       }
+                       break;
+               case SMS_ENCODE_IA5:
+               case SMS_ENCODE_GSM7BIT:
+                       memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
+                       UnpackGSM7bitData(&(p_pkg_str[1]), p_user->user_data, p_user->data_len);
+                       break;
+               case SMS_ENCODE_EPM:
+                       break;
+               case SMS_ENCODE_GSMDCS:
+                       break;
+               case SMS_ENCODE_UNICODE:
+                       p_user->data_len*=2;
+                       memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
+                       memcpy(p_user->user_data, p_pkg_str+1, p_user->data_len);
+                       break;
+               default:
+                       memset(p_user->user_data, 0x00, sizeof(p_user->user_data));
+                       memcpy(p_user->user_data, p_pkg_str+1, p_user->data_len);
+                       break;
+       }
+
+}
+
+
+sms_message_type_t SmsPluginMsgCodec::findMsgType(const unsigned char *p_pkg_str, int pkg_len)
+{
+       int offset = 0;
+       while(offset < pkg_len) {
+               if(p_pkg_str[offset] == 0x00) {
+                       return (sms_message_type_t)((p_pkg_str[offset+2]&0xf0)>>4);
+               }
+               offset+=(p_pkg_str[offset+1]+2);
+       }
+
+       return SMS_TYPE_MAX_VALUE;
+}
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginEventHandler.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginEventHandler.cpp
new file mode 100755 (executable)
index 0000000..de38121
--- /dev/null
@@ -0,0 +1,1207 @@
+/*
+* 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 <stdlib.h>
+#include <errno.h>
+#include <time.h>
+
+#include "MsgDebug.h"
+#include "MsgUtilFile.h"
+#include "MsgUtilFunction.h"
+#include "MsgUtilStorage.h"
+#include "MsgCppTypes.h"
+#include "MsgContact.h"
+#include "MsgGconfWrapper.h"
+#include "MsgNotificationWrapper.h"
+
+#include "SmsCdmaPluginTransport.h"
+#include "SmsCdmaPluginStorage.h"
+#include "SmsCdmaPluginSetting.h"
+#include "SmsCdmaPluginEventHandler.h"
+#include "SmsCdmaPluginWapPushHandler.h"
+
+
+
+SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
+
+
+SmsPluginEventHandler::SmsPluginEventHandler()
+{
+       /**  Initialize global parameters */
+       memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
+       memset(&sentInfo, 0x00, sizeof(sms_sent_info_s));
+       devStatus = false;
+}
+
+
+SmsPluginEventHandler::~SmsPluginEventHandler()
+{
+
+}
+
+
+SmsPluginEventHandler* SmsPluginEventHandler::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginEventHandler();
+
+       return pInstance;
+}
+
+void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
+{
+       listener = *pListener;
+}
+
+
+void SmsPluginEventHandler::convertTpduToMsginfo(sms_trans_p2p_msg_s *p_p2p_msg, MSG_MESSAGE_INFO_S *p_msg_info)
+{
+       MSG_BEGIN();
+
+       // Address
+       if (p_p2p_msg->telesvc_msg.data.deliver.callback_number.szData[0] != '\0')
+               p_msg_info->nAddressCnt = 2;
+       else
+               p_msg_info->nAddressCnt = 1;
+
+       p_msg_info->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * p_msg_info->nAddressCnt];
+
+       if (p_msg_info->addressList) {
+               switch (p_msg_info->nAddressCnt) {
+                       case 2 :
+                               memset(p_msg_info->addressList[1].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
+                       case 1 :
+                               memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
+                               break;
+                       default :
+                               MSG_ERR("Invalid case");
+                               memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
+               }
+       }
+
+       if (p_p2p_msg->address.szData[0] != '\0') {
+               p_msg_info->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
+               memcpy(p_msg_info->addressList[0].addressVal, p_p2p_msg->address.szData, MAX_ADDRESS_VAL_LEN);
+               p_msg_info->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
+       }
+
+
+       // Teleservice message
+       switch(p_p2p_msg->telesvc_msg.type)
+       {
+               case SMS_TYPE_DELIVER :
+                       p_msg_info->msgType.subType = MSG_NORMAL_SMS;
+                       p_msg_info->folderId = MSG_INBOX_ID;
+
+                       convertDeliverMsgToMsgInfo(&(p_p2p_msg->telesvc_msg.data.deliver), p_msg_info);
+                       break;
+               case SMS_TYPE_DELIVERY_ACK :
+                       convertAckMsgToMsgInfo(&(p_p2p_msg->telesvc_msg.data.delivery_ack), p_msg_info);
+                       break;
+               case SMS_TYPE_SUBMIT_REPORT :
+                       convertReportMsgToMsgInfo(&(p_p2p_msg->telesvc_msg.data.report), p_msg_info);
+                       break;
+               default :
+                       MSG_DEBUG("No matching type = [%d]", p_p2p_msg->telesvc_msg.type);
+                       break;
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginEventHandler::convertTpduToMsginfo(sms_trans_broadcast_msg_s *p_cb_msg, MSG_MESSAGE_INFO_S *p_msg_info)
+{
+       MSG_BEGIN();
+
+       // Address
+       p_msg_info->nAddressCnt = 0;
+       p_msg_info->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
+
+       if (p_msg_info->addressList) {
+               memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
+       }
+
+       // Bearer Data
+       if(p_cb_msg->telesvc_msg.type == SMS_TYPE_DELIVER) {
+               p_msg_info->msgType.subType = MSG_CB_SMS;
+               p_msg_info->folderId = MSG_CBMSGBOX_ID;
+
+               if (p_cb_msg->svc_ctg >= SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL && p_cb_msg->svc_ctg <= SMS_TRANS_SVC_CTG_CMAS_TEST)
+                       convertCMASMsgToMsgInfo(&(p_cb_msg->telesvc_msg.data.deliver), p_msg_info);
+               else
+                       convertDeliverMsgToMsgInfo(&(p_cb_msg->telesvc_msg.data.deliver), p_msg_info);
+       }
+       else {
+               MSG_DEBUG("No matching type = [%d]", p_cb_msg->telesvc_msg.type);
+       }
+
+       if (p_msg_info->nAddressCnt == 0) {
+               p_msg_info->nAddressCnt = 1;
+               p_msg_info->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
+               p_msg_info->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
+
+               if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL)
+                       snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Presidential Alert");
+               else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_EXTREME)
+                       snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Extreme Alert");
+               else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_SEVERE)
+                       snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Severe Alert");
+               else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_AMBER)
+                       snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "AMBER Alert");
+               else if (p_cb_msg->svc_ctg == SMS_TRANS_SVC_CTG_CMAS_TEST)
+                       snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "Emergency Alert");
+               else
+                       snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "CB Message");
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginEventHandler::convertCMASMsgToMsgInfo(sms_telesvc_deliver_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
+{
+       MSG_BEGIN();
+
+       p_msg_info->msgType.mainType = MSG_SMS_TYPE;
+
+       p_msg_info->msgType.classType = MSG_CLASS_NONE;
+       p_msg_info->networkStatus = MSG_NETWORK_RECEIVED;
+       p_msg_info->bRead = false;
+       p_msg_info->bProtected = false;
+       p_msg_info->direction = MSG_DIRECTION_TYPE_MT;
+       p_msg_info->bTextSms = true;
+
+       if (p_deliver->callback_number.szData[0] != '\0') {                     // If callback number is in received pdu, replace the address value.
+               memset(p_msg_info->addressList[0].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
+               p_msg_info->nAddressCnt = 1;
+               p_msg_info->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
+               snprintf(p_msg_info->addressList[0].addressVal, MAX_ADDRESS_VAL_LEN, "%s", p_deliver->callback_number.szData);
+               p_msg_info->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_TO;
+       }
+
+       time_t rawtime = 0;
+       p_msg_info->storageId = MSG_STORAGE_PHONE;
+
+#if 0 // Save Timestamp of message center.
+               char displayTime[32];
+               struct tm * timeTM;
+
+               struct tm timeinfo;
+               memset(&timeinfo, 0x00, sizeof(tm));
+
+               if (p_deliver->time_stamp.year > 95)
+                       timeinfo.tm_year = (p_deliver->time_stamp.year + 1900);
+               else
+                       timeinfo.tm_year = (p_deliver->time_stamp.year + 2000);
+
+               timeinfo.tm_mon = (p_deliver->time_stamp.month - 1);
+               timeinfo.tm_mday = p_deliver->time_stamp.day;
+               timeinfo.tm_hour = p_deliver->time_stamp.hour;
+               timeinfo.tm_min = p_deliver->time_stamp.minute;
+               timeinfo.tm_sec = p_deliver->time_stamp.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);
+#endif
+
+       p_msg_info->displayTime = rawtime;
+
+
+       if (p_deliver->priority == SMS_PRIORITY_URGENT || p_deliver->priority == SMS_PRIORITY_EMERGENCY)
+               p_msg_info->priority = MSG_MESSAGE_PRIORITY_HIGH;
+       else
+               p_msg_info->priority = MSG_MESSAGE_PRIORITY_NORMAL;
+
+
+       memset(p_msg_info->subject, 0x00, MAX_SUBJECT_LEN+1);
+
+       p_msg_info->msgPort.valid = false;
+       p_msg_info->msgPort.dstPort = 0;
+       p_msg_info->msgPort.srcPort = 0;
+
+       p_msg_info->encodeType = getEncodeType(p_deliver->cmas_data.encode_type);
+
+       if (p_deliver->cmas_data.data_len <= 0) {
+               memset(p_msg_info->msgText, 0x00, sizeof(p_msg_info->msgText));
+               p_msg_info->dataSize = 0;
+       } else if (p_deliver->cmas_data.data_len > MAX_MSG_TEXT_LEN) {
+               sprintf(p_msg_info->msgText, "[Broken Message]");
+               p_msg_info->dataSize = strlen(p_msg_info->msgData);
+               return;
+       } else {
+               if(p_msg_info->encodeType == MSG_ENCODE_UCS2) {
+                       MSG_DEBUG("Encode Type = UCS2");
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len);
+               }
+               else if(p_msg_info->encodeType == MSG_ENCODE_EUCKR) {
+                       MSG_DEBUG("Encode Type = EUCKR");
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len);
+               }
+               else if(p_msg_info->encodeType == MSG_ENCODE_SHIFT_JIS) {
+                       MSG_DEBUG("Encode Type = Shift-JIS");
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertSHIFTJISToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len);
+               }
+               else if(p_msg_info->encodeType == MSG_ENCODE_GSM7BIT) {
+                       MSG_DEBUG("Encode Type = GSM7BIT");
+                       MSG_LANG_INFO_S langinfo = {0,};
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->cmas_data.alert_text, p_deliver->cmas_data.data_len, &langinfo);
+               }
+               else {
+                       snprintf(p_msg_info->msgText, sizeof(p_msg_info->msgText), "%s", p_deliver->cmas_data.alert_text);
+                       p_msg_info->dataSize = p_deliver->cmas_data.data_len;
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginEventHandler::convertDeliverMsgToMsgInfo(sms_telesvc_deliver_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
+{
+       MSG_BEGIN();
+
+       p_msg_info->msgType.mainType = MSG_SMS_TYPE;
+//     p_msg_info->msgType.subType = MSG_NORMAL_SMS;
+
+//     p_msg_info->folderId = MSG_INBOX_ID;
+
+       p_msg_info->msgType.classType = MSG_CLASS_NONE;
+       p_msg_info->networkStatus = MSG_NETWORK_RECEIVED;
+       p_msg_info->bRead = false;
+       p_msg_info->bProtected = false;
+       p_msg_info->direction = MSG_DIRECTION_TYPE_MT;
+       p_msg_info->bTextSms = true;
+
+       if (p_deliver->callback_number.szData[0] != '\0') {                     // If callback number is in received pdu, replace the address value.
+               memset(p_msg_info->addressList[1].addressVal, 0x00, MAX_ADDRESS_VAL_LEN+1);
+               p_msg_info->addressList[1].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
+               memcpy(p_msg_info->addressList[1].addressVal, p_deliver->callback_number.szData, MAX_ADDRESS_VAL_LEN);
+               p_msg_info->addressList[1].recipientType = MSG_RECIPIENTS_TYPE_TO;
+       }
+
+       time_t rawtime = 0;
+       p_msg_info->storageId = MSG_STORAGE_PHONE;
+
+#if 0 // Save Timestamp of message center.
+               char displayTime[32];
+               struct tm * timeTM;
+
+               struct tm timeinfo;
+               memset(&timeinfo, 0x00, sizeof(tm));
+
+               if (p_deliver->time_stamp.year > 95)
+                       timeinfo.tm_year = (p_deliver->time_stamp.year + 1900);
+               else
+                       timeinfo.tm_year = (p_deliver->time_stamp.year + 2000);
+
+               timeinfo.tm_mon = (p_deliver->time_stamp.month - 1);
+               timeinfo.tm_mday = p_deliver->time_stamp.day;
+               timeinfo.tm_hour = p_deliver->time_stamp.hour;
+               timeinfo.tm_min = p_deliver->time_stamp.minute;
+               timeinfo.tm_sec = p_deliver->time_stamp.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);
+#endif
+
+       p_msg_info->displayTime = rawtime;
+
+
+       if (p_deliver->priority == SMS_PRIORITY_URGENT || p_deliver->priority == SMS_PRIORITY_EMERGENCY)
+               p_msg_info->priority = MSG_MESSAGE_PRIORITY_HIGH;
+       else
+               p_msg_info->priority = MSG_MESSAGE_PRIORITY_NORMAL;
+
+
+       memset(p_msg_info->subject, 0x00, MAX_SUBJECT_LEN+1);
+
+       p_msg_info->msgPort.valid = false;
+       p_msg_info->msgPort.dstPort = 0;
+       p_msg_info->msgPort.srcPort = 0;
+
+       p_msg_info->encodeType = getEncodeType(p_deliver->user_data.encode_type);
+
+       if (p_deliver->user_data.data_len <= 0) {
+               memset(p_msg_info->msgText, 0x00, sizeof(p_msg_info->msgText));
+               p_msg_info->dataSize = 0;
+       } else if (p_deliver->user_data.data_len > MAX_MSG_TEXT_LEN) {
+               sprintf(p_msg_info->msgText, "[Broken Message]");
+               p_msg_info->dataSize = strlen(p_msg_info->msgData);
+               return;
+       } else {
+               if(p_msg_info->encodeType == MSG_ENCODE_UCS2) {
+                       MSG_DEBUG("Encode Type = UCS2");
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len);
+               }
+               else if(p_msg_info->encodeType == MSG_ENCODE_EUCKR) {
+                       MSG_DEBUG("Encode Type = EUCKR");
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len);
+               }
+               else if(p_msg_info->encodeType == MSG_ENCODE_SHIFT_JIS) {
+                       MSG_DEBUG("Encode Type = Shift-JIS");
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertSHIFTJISToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len);
+               }
+               else if(p_msg_info->encodeType == MSG_ENCODE_GSM7BIT) {
+                       MSG_DEBUG("Encode Type = GSM7BIT");
+                       MSG_LANG_INFO_S langinfo = {0,};
+                       MsgTextConvert *textCvt = MsgTextConvert::instance();
+                       p_msg_info->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)&p_msg_info->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)&p_deliver->user_data.user_data, p_deliver->user_data.data_len, &langinfo);
+               }
+               else {
+                       snprintf(p_msg_info->msgText, sizeof(p_msg_info->msgText), "%s", p_deliver->user_data.user_data);
+                       p_msg_info->dataSize = p_deliver->user_data.data_len;
+               }
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginEventHandler::convertAckMsgToMsgInfo(sms_telesvc_deliver_ack_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
+{
+
+}
+
+
+void SmsPluginEventHandler::convertReportMsgToMsgInfo(sms_telesvc_report_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info)
+{
+
+}
+
+
+void SmsPluginEventHandler::SetSentInfo(sms_sent_info_s *pSentInfo)
+{
+       memset(&sentInfo, 0x00, sizeof(sms_sent_info_s));
+       memcpy(&sentInfo, pSentInfo, sizeof(sms_sent_info_s));
+
+       MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
+       MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
+}
+
+
+
+void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
+{
+       MSG_DEBUG("NetStatus[%d]", NetStatus);
+
+       if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
+               /** Update Msg Status */
+               if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
+
+                       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;
+                       } else {
+                               sentInfo.reqInfo.msgInfo.bRead = false;
+                       }
+
+                       callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
+               }
+
+               MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
+               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) {
+                       callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
+               }
+
+               /** Callback to MSG FW */
+               MSG_SENT_STATUS_S msgStatus;
+
+               msgStatus.reqId = sentInfo.reqInfo.reqId;
+               msgStatus.status = NetStatus;
+
+               MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
+               MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
+
+               listener.pfSentStatusCb(&msgStatus);
+       }
+}
+
+
+void SmsPluginEventHandler::handleMsgIncoming(sms_trans_p2p_msg_s *p_p2p_msg)
+{
+
+       /** Make MSG_MESSAGE_INFO_S */
+       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);
+
+       /** convert to msgInfo */
+       convertTpduToMsginfo(p_p2p_msg, &msgInfo);
+
+       if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_RESERVED) {
+               MSG_DEBUG("This Incoming Message has Unknown Teleservice ID");
+               SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_INVALID_MSG_TYPE, p_p2p_msg);
+               return;
+       }
+
+       /** Check for Voice Mail Notification */
+       if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_VMN_95) {
+               if (p_p2p_msg->telesvc_msg.data.deliver.enhanced_vmn.fax_included)
+                       msgInfo.msgType.subType = MSG_MWI_FAX_SMS;
+               else
+                       msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
+
+               if (p_p2p_msg->telesvc_msg.data.deliver.num_msg < 0)
+                       p_p2p_msg->telesvc_msg.data.deliver.num_msg = 0;
+
+               int voice_cnt = MsgSettingGetInt(VOICEMAIL_COUNT);
+
+               // repeated msg check for voicemail
+               if (voice_cnt == p_p2p_msg->telesvc_msg.data.deliver.num_msg) {
+                       SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS, p_p2p_msg);
+                       return;
+               }
+
+               SmsPluginSetting::instance()->setMwiInfo(msgInfo.msgType.subType, p_p2p_msg->telesvc_msg.data.deliver.num_msg);
+
+               memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
+
+               snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", p_p2p_msg->telesvc_msg.data.deliver.num_msg);
+               msgInfo.dataSize = strlen(msgInfo.msgText);
+       }
+       /** Check for EMS(Unsupported) */
+       else if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_WEMT) {
+               char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_POP_ERROR_UNSUPPORTED_MSG");
+               memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
+               snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%s", msg_text);
+               msgInfo.dataSize = strlen(msgInfo.msgText);
+
+               if (msg_text) {
+                       free(msg_text);
+                       msg_text = NULL;
+               }
+       }
+
+       /** Print MSG_MESSAGE_INFO_S */
+       MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
+       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);
+       MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
+       MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
+       MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
+       MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
+       MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
+
+       if (msgInfo.bTextSms == true) {
+               MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
+       } else {
+               MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
+       }
+
+       MSG_DEBUG("###############################################################");
+
+       msg_error_t err = MSG_SUCCESS;
+       bool isUnique = true;
+       MSG_UNIQUE_INDEX_S unq_ind;
+       memset(&unq_ind, 0x00, sizeof(MSG_UNIQUE_INDEX_S));
+
+       if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
+//             /** Status Report Message */
+//             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);
+       } else { /** SMS Deliver */
+
+               /** Add message to DB */
+               if (msgInfo.msgPort.valid == false) {
+                       if (p_p2p_msg->telesvc_id != SMS_TRANS_TELESVC_VMN_95) {
+                               memcpy(unq_ind.address, p_p2p_msg->address.szData, sizeof(p_p2p_msg->address.szData));
+                               memcpy(unq_ind.sub_address, p_p2p_msg->sub_address.szData, sizeof(p_p2p_msg->sub_address.szData));
+                               unq_ind.tele_msgId = p_p2p_msg->telesvc_msg.data.deliver.msg_id.msg_id;
+                               snprintf(unq_ind.time_stamp, sizeof(unq_ind.time_stamp), "%02d%02d%02d%02d%02d%02d",
+                                               p_p2p_msg->telesvc_msg.data.deliver.time_stamp.year, p_p2p_msg->telesvc_msg.data.deliver.time_stamp.month,
+                                               p_p2p_msg->telesvc_msg.data.deliver.time_stamp.day, p_p2p_msg->telesvc_msg.data.deliver.time_stamp.hours,
+                                               p_p2p_msg->telesvc_msg.data.deliver.time_stamp.minutes, p_p2p_msg->telesvc_msg.data.deliver.time_stamp.seconds);
+                               unq_ind.telesvc_id = p_p2p_msg->telesvc_id;
+                               isUnique = listener.pfCheckUniquenessCb(&unq_ind, 0, false);
+                       }
+               }
+
+               if (isUnique) {
+                       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+               }
+               else {
+                       SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS, p_p2p_msg);
+                       return;
+               }
+
+               /** Callback to MSG FW */
+               if (err == MSG_SUCCESS) {
+                       MSG_DEBUG("callback to msg fw");
+                       err = listener.pfMsgIncomingCb(&msgInfo);
+               } else {
+                       if (msgInfo.msgType.classType == MSG_CLASS_0) {
+                               MSG_DEBUG("callback for class0 message to msg fw");
+                               if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
+                                       MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
+                       }
+               }
+
+               if (err == MSG_SUCCESS && p_p2p_msg->telesvc_id != SMS_TRANS_TELESVC_VMN_95)
+                       listener.pfCheckUniquenessCb(&unq_ind, msgInfo.msgId, true);
+
+               /** Send Deliver Report */
+               if (p_p2p_msg->telesvc_id == SMS_TRANS_TELESVC_WEMT) {
+                       SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_INVALID_MSG_TYPE, p_p2p_msg);
+               } else {
+                       SmsPluginTransport::instance()->sendDeliverReport(err, p_p2p_msg);
+               }
+
+               // Tizen Validation System
+               char *msisdn = NULL;
+               char keyName[MAX_VCONFKEY_NAME_LEN];
+               int simIndex = 1;
+
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
+
+               msisdn = MsgSettingGetString(keyName);
+
+               MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
+                                                                                                               msgInfo.addressList[0].addressVal, \
+                                                                                                               (msisdn == NULL)?"ME":msisdn, \
+                                                                                                               (err == MSG_SUCCESS)?"Success":"Fail");
+
+               MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
+
+               if (msisdn) {
+                       free(msisdn);
+                       msisdn = NULL;
+               }
+       }
+}
+
+
+void SmsPluginEventHandler::handleCbMsgIncoming(sms_trans_broadcast_msg_s *p_cb_msg)
+{
+       MSG_BEGIN();
+
+       if (p_cb_msg->telesvc_msg.data.deliver.cmas_data.encode_type == SMS_ENCODE_KOREAN
+               || p_cb_msg->telesvc_msg.data.deliver.cmas_data.encode_type == SMS_ENCODE_GSMDCS) {
+               MSG_DEBUG("This encode type is not supported [%d]", p_cb_msg->telesvc_msg.data.deliver.cmas_data.encode_type);
+               return;
+       }
+
+       /** Make MSG_MESSAGE_INFO_S */
+       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);
+
+       /** convert to msgInfo */
+       convertTpduToMsginfo(p_cb_msg, &msgInfo);
+       msgInfo.msgId = p_cb_msg->telesvc_msg.data.deliver.msg_id.msg_id;
+
+       /** Print MSG_MESSAGE_INFO_S */
+       MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
+       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);
+       MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
+       MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
+       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.msgId : %d", msgInfo.msgId);
+
+       if (msgInfo.bTextSms == true) {
+               MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
+       } else {
+               MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
+       }
+
+       MSG_DEBUG("###############################################################");
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Add message to DB */
+       if (msgInfo.msgPort.valid == false) {
+               err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+       }
+
+       if (!checkCbOpt(p_cb_msg->svc_ctg))
+       {
+               MSG_DEBUG("The CB Msg is not supported by option.");
+               return;
+       }
+
+       /** Callback to MSG FW */
+       if (err == MSG_SUCCESS) {
+
+#if 1
+               MSG_CB_MSG_S cbOutMsg = {0, };
+               bool is_duplicate = false;
+
+               switch (p_cb_msg->svc_ctg) {
+                       case SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL :
+                               msgInfo.msgType.subType = MSG_CMAS_PRESIDENTIAL;
+                               break;
+                       case SMS_TRANS_SVC_CTG_CMAS_EXTREME :
+                               msgInfo.msgType.subType = MSG_CMAS_EXTREME;
+                               break;
+                       case SMS_TRANS_SVC_CTG_CMAS_SEVERE :
+                               msgInfo.msgType.subType = MSG_CMAS_SEVERE;
+                               break;
+                       case SMS_TRANS_SVC_CTG_CMAS_AMBER :
+                               msgInfo.msgType.subType = MSG_CMAS_AMBER;
+                               break;
+                       case SMS_TRANS_SVC_CTG_CMAS_TEST :
+                               msgInfo.msgType.subType = MSG_CMAS_TEST;
+                               break;
+                       default :
+                               msgInfo.msgType.subType = MSG_CB_SMS;
+                               break;
+               }
+
+               cbOutMsg.type = msgInfo.msgType.subType;
+               cbOutMsg.receivedTime = msgInfo.displayTime;
+               cbOutMsg.serialNum = 0;//encodeCbSerialNum (CbMsgPage.pageHeader.serialNum);
+               cbOutMsg.messageId = msgInfo.msgId;
+//             cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
+               memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
+
+               cbOutMsg.cbTextLen= msgInfo.dataSize;
+               memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
+//             memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
+
+               if (!is_duplicate)
+               {
+                       MSG_DEBUG("callback to msg fw");
+                       err = listener.pfCBMsgIncomingCb(&cbOutMsg, &msgInfo);
+
+                       if (err != MSG_SUCCESS)
+                       {
+                               MSG_WARN("callbackMsgIncoming() Error !! [%d]", err);
+                       }
+               }
+               else
+               {
+                       MSG_WARN("duplicate cb serialNum[%d] messageId[%d]", cbOutMsg.serialNum, cbOutMsg.messageId);
+               }
+
+#else
+               err = listener.pfMsgIncomingCb(&msgInfo);
+#endif
+       }
+
+       /** Send Deliver Report */
+//     SmsPluginTransport::instance()->sendDeliverReport(err, p_cb_msg);
+
+       // Tizen Validation System
+       char *msisdn = NULL;
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       int simIndex = 1;
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
+
+       msisdn = MsgSettingGetString(keyName);
+
+       MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
+                                                                                                       msgInfo.addressList[0].addressVal, \
+                                                                                                       (msisdn == NULL)?"ME":msisdn, \
+                                                                                                       (err == MSG_SUCCESS)?"Success":"Fail");
+
+       MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
+
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginEventHandler::handleWapMsgIncoming(sms_trans_p2p_msg_s *p_p2p_msg)
+{
+       MSG_BEGIN();
+
+       sms_wap_msg_s msg;
+       memset(&msg, 0x00, sizeof(sms_wap_msg_s));
+
+       msg.msgId = p_p2p_msg->telesvc_msg.data.deliver.msg_id.msg_id;
+       msg.totalSeg = p_p2p_msg->telesvc_msg.data.deliver.user_data.user_data[1];
+       msg.segNum = p_p2p_msg->telesvc_msg.data.deliver.user_data.user_data[2];
+
+       char tmpUserText[SMS_MAX_USER_DATA_LEN+1] = {0,};
+       sms_telesvc_userdata_s tmpUserData;
+       memset(&tmpUserData, 0x00, sizeof(sms_telesvc_userdata_s));
+
+       tmpUserData.data_len = p_p2p_msg->telesvc_msg.data.deliver.user_data.data_len - 3;
+       memcpy(tmpUserText, &(p_p2p_msg->telesvc_msg.data.deliver.user_data.user_data[3]), tmpUserData.data_len);
+       memcpy(tmpUserData.user_data, tmpUserText, sizeof(tmpUserData.user_data));
+
+       unsigned char segCnt = checkWapMsg(&msg, &tmpUserData);
+
+       MSG_DEBUG("segNum [%d]", msg.segNum);
+       MSG_DEBUG("segCnt [%d]", segCnt);
+       MSG_DEBUG("msg.totalSeg [%d]", msg.totalSeg);
+
+       if (segCnt == msg.totalSeg) {
+               MSG_DEBUG("RECEIVED LAST WAP : %d", segCnt);
+
+               unsigned short srcPort = 0, dstPort = 0;
+               int dataSize = 0;
+               char* pUserData = NULL;
+               char* pTmpUserData = NULL;
+               AutoPtr<char> dataBuf(&pUserData);
+               AutoPtr<char> dataBuf1(&pTmpUserData);
+
+               MSG_MESSAGE_INFO_S msgInfo = {0,};
+
+               msgInfo.addressList = NULL;
+               AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
+
+               dataSize = MakeWapUserData(msg.msgId, &pUserData);
+
+               pTmpUserData = new char[dataSize];
+
+               memcpy(pTmpUserData, pUserData, dataSize);
+               memset(pUserData, 0x00, dataSize);
+
+               srcPort = pTmpUserData[0] << 8  | pTmpUserData[1];
+               dstPort = pTmpUserData[2] << 8 | pTmpUserData[3];
+
+#ifndef FEATURE_OMADM_DUPLICATE_PORT_WAPPUSH
+               dataSize -= 4;
+               memcpy(pUserData, &pTmpUserData[4], dataSize);
+#else
+               if ((srcPort == 0x23f0 && dstPort == 0x0b84) &&
+                       ((pTmpUserData[4] << 8 | pTmpUserData[5]) == 0x23f0) &&
+                       ((pTmpUserData[6] << 8 | pTmpUserData[7]) == 0x0b84)) {
+                       dataSize -= 8;
+                       memcpy(pUserData, &pTmpUserData[8], dataSize);
+               }
+               else {
+                       dataSize -= 4;
+                       memcpy(pUserData, &pTmpUserData[4], dataSize);
+               }
+#endif
+
+               if (dataSize > 0) {
+                       MSG_DEBUG("dataSize = %d", dataSize);
+                       for (int i = 0; i < dataSize; i++)
+                               MSG_DEBUG("UserData[%d] = [%c] [%02x]", i, pUserData[i], pUserData[i]);
+
+                       if      (SmsPluginWapPushHandler::instance()->IsWapPushMsg(dstPort) == true) {
+                               msgInfo.msgType.mainType = MSG_SMS_TYPE;
+                               SmsPluginWapPushHandler::instance()->copyDeliverData(&(p_p2p_msg->address));
+                               SmsPluginWapPushHandler::instance()->handleWapPushMsg(pUserData, dataSize);
+                       }
+                       else {
+                               MSG_DEBUG("not supported wap push port [%x]", dstPort);
+                       }
+               }
+
+               // remove from waplist
+               for (int index = wapList.size()-1; index >= 0 ; index--) {
+                       if (wapList[index].msgId == msg.msgId) {
+                               MSG_DEBUG("remove waplist of the index [%d]", index);
+                               wapList.erase(wapList.begin()+index);
+                               break;
+                       }
+               }
+       }
+
+       /** Send Deliver Report */
+       SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS, p_p2p_msg);
+
+       MSG_END();
+}
+
+
+void SmsPluginEventHandler::handleResendMessage(void)
+{
+       listener.pfResendMessageCb();
+}
+
+
+msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Callback to MSG FW */
+       err = listener.pfMsgIncomingCb(pMsgInfo);
+
+       MSG_END();
+
+       return err;
+}
+
+
+msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       /** Callback to MSG FW */
+       listener.pfStorageChangeCb(storageChangeType, pMsgInfo);
+
+       return MSG_SUCCESS;
+}
+
+
+void SmsPluginEventHandler::setDeviceStatus()
+{
+       mx.lock();
+       devStatus = true;
+       cv.signal();
+       mx.unlock();
+}
+
+
+bool SmsPluginEventHandler::getDeviceStatus()
+{
+       int ret = 0;
+
+       mx.lock();
+
+       ret = cv.timedwait(mx.pMutex(), 25);
+
+       if (ret == ETIMEDOUT) {
+               MSG_DEBUG("WARNING: DEVICE STATUS TIME-OUT");
+               devStatus = false;
+               bNeedInitConfig = true;
+       }
+       mx.unlock();
+       return devStatus;
+}
+
+void SmsPluginEventHandler::setNeedInitConfig(bool bNeeded)
+{
+       bNeedInitConfig = bNeeded;
+}
+
+bool SmsPluginEventHandler::getNeedInitConfig()
+{
+       return bNeedInitConfig;
+}
+
+msg_encode_type_t SmsPluginEventHandler::getEncodeType(sms_encoding_type_t encode_type)
+{
+       switch(encode_type) {
+               case SMS_ENCODE_IA5 :
+               case SMS_ENCODE_GSM7BIT :
+                       return MSG_ENCODE_GSM7BIT;
+               case SMS_ENCODE_KOREAN :
+               case SMS_ENCODE_EUCKR :
+                       return MSG_ENCODE_EUCKR;
+               case SMS_ENCODE_7BIT_ASCII :
+               case SMS_ENCODE_LATIN_HEBREW :
+               case SMS_ENCODE_LATIN :
+               case SMS_ENCODE_OCTET :
+                       return MSG_ENCODE_8BIT;
+               case SMS_ENCODE_SHIFT_JIS :
+                       return MSG_ENCODE_SHIFT_JIS;
+//             case SMS_ENCODE_EPM :
+//             case SMS_ENCODE_UNICODE :
+//             case SMS_ENCODE_GSMDCS :
+               default :
+                       return MSG_ENCODE_UCS2;
+       }
+
+       return MSG_ENCODE_UCS2;
+}
+
+
+unsigned short SmsPluginEventHandler::checkWapMsg(sms_wap_msg_s *pMsg, sms_telesvc_userdata_s *pUserdata)
+{
+       unsigned char currSegNum = 0;
+
+       bool bFind = false;
+
+       for (unsigned int i = 0; i < wapList.size(); i++) {
+               if (wapList[i].msgId == pMsg->msgId) {
+                       if (wapList[i].data.count(pMsg->segNum) != 0) {
+                               MSG_DEBUG("The Segment Number already exists [%d]", pMsg->segNum);
+                               return 0;
+                       }
+                       wap_data_s wapData = {0};
+
+                       memcpy(wapData.data, pUserdata->user_data, pUserdata->data_len);
+                       wapData.length = pUserdata->data_len;
+
+                       pair<unsigned char, wap_data_s> newData(pMsg->segNum, wapData);
+                       wapList[i].data.insert(newData);
+
+                       MSG_DEBUG("MSG DATA : %s", pUserdata->user_data);
+                       MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
+                       MSG_DEBUG("DATA SIZE [%d]", pUserdata->data_len);
+
+                       wapList[i].segNum++;
+                       wapList[i].totalSize += pUserdata->data_len;
+                       currSegNum = wapList[i].segNum;
+
+                       bFind = true;
+
+                       break;
+               }
+       }
+
+       /** New Wap Push Msg */
+       if (bFind == false) {
+               sms_wap_info_s tmpInfo;
+               tmpInfo.msgId = pMsg->msgId;
+               tmpInfo.totalSeg = pMsg->totalSeg;
+               tmpInfo.segNum = 1;
+
+               tmpInfo.totalSize = pUserdata->data_len;
+
+               wap_data_s wapData = {0};
+
+               memcpy(wapData.data, pUserdata->user_data, pUserdata->data_len);
+               wapData.length = pUserdata->data_len;
+
+               pair<unsigned char, wap_data_s> newData(pMsg->segNum, wapData);
+               tmpInfo.data.insert(newData);
+
+               MSG_DEBUG("MSG DATA : %s", pUserdata->user_data);
+               MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
+               MSG_DEBUG("DATA SIZE [%d]", pUserdata->data_len);
+
+               wapList.push_back(tmpInfo);
+
+               currSegNum = tmpInfo.segNum;
+       }
+
+       return currSegNum;
+}
+
+
+int SmsPluginEventHandler::MakeWapUserData(unsigned short msgId, char **ppTotalData)
+{
+       wapDataMap::iterator it;
+
+       int totalSize = 0, offset = 0;
+
+       for (unsigned int i = 0; i < wapList.size(); i++) {
+               if (wapList[i].msgId == msgId) {
+                       totalSize = wapList[i].totalSize;
+
+                       if (totalSize <= 0) {
+                               MSG_DEBUG("Size Error : totalSize <= 0");
+                               return 0;
+                       }
+
+                       MSG_DEBUG("totalSize [%d]", totalSize);
+
+                       *ppTotalData = new char[totalSize];
+
+                       for (it = wapList[i].data.begin(); it != wapList[i].data.end(); it++) {
+                               memcpy(*ppTotalData+offset, it->second.data, it->second.length);
+                               offset += it->second.length;
+                       }
+               }
+       }
+
+       return totalSize;
+
+}
+
+
+void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen)
+{
+       MSG_SYNCML_MESSAGE_DATA_S syncMLData;
+
+       memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
+
+       /** set syncML data */
+       syncMLData.syncmlType = msgType;
+
+       syncMLData.pushBodyLen = PushBodyLen;
+       memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
+
+       syncMLData.wspHeaderLen= WspHeaderLen;
+       memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
+
+       /** Callback to MSG FW */
+       listener.pfSyncMLMsgIncomingCb(&syncMLData);
+}
+
+
+void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
+{
+       MSG_LBS_MESSAGE_DATA_S lBSData;
+
+       memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
+
+       /** set LBA data */
+       memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
+
+       lBSData.pushBodyLen = pushBodyLen;
+       memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
+
+       /** Callback to MSG FW */
+       listener.pfLBSMsgIncomingCb(&lBSData);
+}
+
+
+void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
+{
+       MSG_PUSH_MESSAGE_DATA_S pushData;
+
+       memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
+
+       /** set PUSH data */
+       memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
+
+       pushData.pushBodyLen = pushBodyLen;
+       memcpy(pushData.pushBody, pPushBody, pushBodyLen);
+
+       memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
+       memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
+
+       /** Callback to MSG FW */
+       listener.pfPushMsgIncomingCb(&pushData);
+}
+
+
+bool SmsPluginEventHandler::checkCbOpt(sms_trans_svc_ctg_t svc_ctg)
+{
+       bool bReceive = false;
+       MsgSettingGetBool(CB_RECEIVE, &bReceive);
+
+       // Receive CB Msg = FALSE
+       if (!bReceive)
+       {
+               MSG_DEBUG("RECEIVE CB = FALSE");
+               return false;
+       }
+
+       if (svc_ctg >= SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL && svc_ctg <= SMS_TRANS_SVC_CTG_CMAS_TEST) {
+               bool bActivate = false;
+               short Category = 0;
+               MSG_CB_CHANNEL_S cbChannelInfo = {0,};
+               msg_error_t err = MSG_SUCCESS;
+               MsgDbHandler *dbHandle = getDbHandle();
+
+               err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo);
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("Error value of MsgStoGetCBChannelInfo [%d]", err);
+                       return false;
+               }
+
+               for (int i = 0; i < cbChannelInfo.channelCnt; i++)
+               {
+                       bActivate = cbChannelInfo.channelInfo[i].bActivate;
+                       Category = cbChannelInfo.channelInfo[i].ctg;
+
+                       if (bActivate == true && svc_ctg == Category)
+                       {
+                               MSG_DEBUG("FIND CHANNEL = [%d]", svc_ctg);
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
+       return true;
+}
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginMain.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginMain.cpp
new file mode 100755 (executable)
index 0000000..22c3b4b
--- /dev/null
@@ -0,0 +1,442 @@
+/*
+* 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 <errno.h>
+
+#include "MsgDebug.h"
+#include "MsgException.h"
+#include "MsgGconfWrapper.h"
+
+#include "MsgMutex.h"
+#include "SmsCdmaPluginTransport.h"
+#include "SmsCdmaPluginStorage.h"
+#include "SmsCdmaPluginCallback.h"
+#include "SmsCdmaPluginEventHandler.h"
+#include "SmsCdmaPluginUAManager.h"
+#include "SmsCdmaPluginSetting.h"
+#include "SmsCdmaPluginMain.h"
+#include <gio/gio.h>
+
+extern "C"
+{
+       #include <tapi_common.h>
+       #include <TelSms.h>
+       #include <TapiUtility.h>
+       #include <ITapiSim.h>
+       #include <ITapiNetText.h>
+}
+
+#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"
+
+struct tapi_handle *pTapiHandle = NULL;
+bool isMemAvailable = true;
+
+GDBusConnection *gdbus_conn = NULL;
+GDBusProxy *gdbus_proxy = NULL;
+gint subs_id = 0;
+
+Mutex mx;
+CndVar cv;
+
+
+void MsgResourceMonitorInit(void);
+void MsgResourceMonitorDeinit(void);
+
+/*==================================================================================================
+                                FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
+static void MsgTapiInitCB(keynode_t *key, void* data)
+{
+       MSG_DEBUG("MsgTapiInitCB is called.");
+       mx.lock();
+       cv.signal();
+       mx.unlock();
+}
+
+msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
+{
+       if (pPluginHandle == NULL)
+       {
+               MSG_DEBUG("SMS plugin: create handler error ");
+               return MSG_ERR_NULL_POINTER;
+       }
+       else
+       {
+               pPluginHandle->pfInitialize = SmsPlgInitialize;
+               pPluginHandle->pfFinalize = SmsPlgFinalize;
+               pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
+               pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
+               pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
+               pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
+               pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
+               pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
+               pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
+               pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
+               pPluginHandle->pfAddMessage = SmsPlgAddMessage;
+
+               MSG_DEBUG("SMS plugin: create handler OK");
+               MSG_DEBUG ("SMS plugin %p", pPluginHandle);
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
+{
+       if (pPluginHandle != NULL)
+       {
+               free(pPluginHandle);
+               pPluginHandle = NULL;
+       }
+
+       MSG_DEBUG("SMS plugin: destory handler OK");
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgInitialize()
+{
+       MSG_BEGIN();
+
+       bool bReady = false;
+
+       for (int i = 0; i < 100; i++) {
+               MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady);
+               MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady ? 1 : 0);
+
+               if(bReady)
+                       break;
+
+               sleep(1);
+       }
+
+       if (!bReady) {
+               MSG_DEBUG("Fail to wait telephony init complete.");
+               return MSG_ERR_PLUGIN_TAPIINIT;
+       }
+
+       pTapiHandle = tel_init(NULL);
+
+       if (pTapiHandle) {
+               // register event.
+               SmsPluginCallback::instance()->registerEvent();
+
+               // set sim change status.
+               MSG_DEBUG("Try to initialize SIM on init");
+               SmsPluginSetting::instance()->setSimChangeStatus();
+
+               // set resource monitor
+               MsgResourceMonitorInit();
+       }
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgFinalize()
+{
+       MSG_BEGIN();
+
+       MsgResourceMonitorDeinit();
+
+       if (!pTapiHandle)
+               return MSG_ERR_PLUGIN_TAPIINIT;
+
+       SmsPluginCallback::instance()->deRegisterEvent();
+
+       tel_deinit(pTapiHandle);
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
+{
+       MSG_BEGIN();
+
+       SmsPluginEventHandler::instance()->registerListener(pListener);
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       // Add Submit SMS into DB
+       if (pReqInfo->msgInfo.msgId == 0) {
+               if (pReqInfo->msgInfo.msgPort.valid == false) {
+
+                       err = SmsPluginStorage::instance()->checkMessage(&(pReqInfo->msgInfo));
+
+                       if (err != MSG_SUCCESS) {
+                               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;
+                       }
+               }
+       }
+
+       // 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..");
+//
+//             // Update Msg Status
+//             if (pReqInfo->msgInfo.msgPort.valid == false)
+//                     SmsPluginStorage::instance()->updateSentMsg(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
+//
+//             return MSG_ERR_NO_SIM;
+//     }
+
+       sms_request_info_s *request = NULL;
+
+       request = (sms_request_info_s *)calloc(1, sizeof(sms_request_info_s));
+
+       if (request != NULL) {
+               request->reqId = pReqInfo->reqId;
+
+               memcpy(&(request->msgInfo), &(pReqInfo->msgInfo), sizeof(MSG_MESSAGE_INFO_S));
+               memcpy(&(request->sendOptInfo), &(pReqInfo->sendOptInfo), sizeof(MSG_SENDINGOPT_INFO_S));
+
+               /* Add Request into Queue and Start UA Manger */
+               SmsPluginUAManager::instance()->addReqEntity(request);
+
+               free(request);
+       }
+
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
+{
+       MSG_DEBUG("CDMA does not support sim card operations.");
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
+{
+       MSG_DEBUG("CDMA does not support sim card operations.");
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
+{
+       MSG_DEBUG("CDMA does not support sim card operations.");
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
+{
+
+       int tapiRet = TAPI_API_SUCCESS;
+       int status = TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE;
+
+       if (Error == MSG_ERR_SIM_STORAGE_FULL || Error == MSG_ERR_MESSAGE_COUNT_FULL)
+       {
+               status = TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL;
+       }
+
+       MSG_DEBUG("Set Status : [%d]", status);
+
+       tapiRet = tel_set_sms_memory_status(pTapiHandle, status, TapiEventMemoryStatus, NULL);
+
+       if (tapiRet == TAPI_API_SUCCESS)
+       {
+               MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! #######");
+       }
+       else
+       {
+               MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
+{
+       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()->getConfigData(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 SmsPlgAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo,  MSG_SENDINGOPT_INFO_S* pSendOptInfo, char* pFileData)
+{
+       MSG_DEBUG("CDMA does not support sim card operations.");
+       return MSG_SUCCESS;
+}
+
+static void on_change_received(GDBusConnection *connection, const gchar *sender_name,
+               const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       MSG_DEBUG("signal_name = [%s]", signal_name);
+
+       if (g_strcmp0(signal_name, MEMBER_NAME) == 0) {
+               gint memStatus;
+               g_variant_get(parameters, "(i)", &memStatus);
+               MSG_DEBUG("memStatus = [%d]", memStatus);
+               if(memStatus == 0) {
+                       SmsPlgSetMemoryStatus(MSG_SUCCESS);
+               }
+       }
+}
+
+void MsgResourceMonitorInit(void)
+{
+    MSG_BEGIN();
+
+       GError *error = NULL;
+
+       if (gdbus_conn) {
+               g_object_unref(gdbus_conn);
+               gdbus_conn = NULL;
+       }
+
+       gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error) {
+               MSG_FATAL("g_bus_get_sync() failed : %s", error->message);
+               g_error_free(error);
+               error = NULL;
+               goto _DBUS_ERROR;
+       }
+
+       if (gdbus_proxy) {
+               g_object_unref(gdbus_proxy);
+               gdbus_proxy = NULL;
+       }
+
+       gdbus_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE,
+                                                       NULL, BUS_NAME, PATH_NAME, INTERFACE_NAME, NULL, &error);
+       if (error) {
+               MSG_FATAL("g_dbus_proxy_new_sync() failed : %s", error->message);
+               g_error_free(error);
+               error = NULL;
+               goto _DBUS_ERROR;
+       }
+
+       subs_id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL,
+                                                       INTERFACE_NAME, MEMBER_NAME, PATH_NAME,
+                                                       NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                       on_change_received,
+                                                       NULL, NULL);
+       MSG_END();
+       return;
+
+_DBUS_ERROR:
+       if (gdbus_conn) {
+               g_object_unref(gdbus_conn);
+               gdbus_conn = NULL;
+       }
+
+       if (gdbus_proxy) {
+               g_object_unref(gdbus_proxy);
+               gdbus_proxy = NULL;
+       }
+
+       MSG_END();
+       return;
+
+}
+
+
+void MsgResourceMonitorDeinit(void)
+{
+       MSG_BEGIN();
+
+       if (subs_id) {
+               g_dbus_connection_signal_unsubscribe(gdbus_conn, subs_id);
+               subs_id = 0;
+       }
+
+       if (gdbus_conn) {
+               g_object_unref(gdbus_conn);
+               gdbus_conn = NULL;
+       }
+
+       if (gdbus_proxy) {
+               g_object_unref(gdbus_proxy);
+               gdbus_proxy = NULL;
+       }
+
+       MSG_END();
+}
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginParamCodec.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginParamCodec.cpp
new file mode 100755 (executable)
index 0000000..e1885b2
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+* 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 "SmsCdmaPluginParamCodec.h"
+
+
+/*==================================================================================================
+                               IMPLEMENTATION OF SmsCdmaPluginParamCodec - Member Functions
+==================================================================================================*/
+SmsPluginParamCodec* SmsPluginParamCodec::pInstance = NULL;
+
+
+SmsPluginParamCodec::SmsPluginParamCodec()
+{
+
+
+}
+
+
+SmsPluginParamCodec::~SmsPluginParamCodec()
+{
+
+
+}
+
+SmsPluginParamCodec* SmsPluginParamCodec::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginParamCodec();
+
+       return pInstance;
+}
+
+
+
+/*==================================================================================================
+                                     Util Functions
+==================================================================================================*/
+int SmsPluginParamCodec::convertDigitToBcd(char *pDigit, int DigitLen, unsigned char *pBcd)
+{
+       int offset = 0;
+       unsigned char temp;
+
+       for (int i = 0; i < DigitLen; i++) {
+               if (pDigit[i] == '*')
+                       temp = 0x0A;
+               else if (pDigit[i] == '#')
+                       temp = 0x0B;
+               else if (pDigit[i] == 'P' || pDigit[i] == 'p')
+                       temp = 0x0C;
+               else
+                       temp = pDigit[i] - '0';
+
+               if ((i % 2) == 0)
+                       pBcd[offset] = temp & 0x0F;
+               else
+                       pBcd[offset++] |= ((temp & 0x0F) << 4);
+       }
+
+       if ((DigitLen % 2) == 1) {
+               pBcd[offset++] |= 0xF0;
+       }
+
+       return offset;
+}
+
+int SmsPluginParamCodec::convertBcdToDigit(const unsigned char *pBcd, int BcdLen, char *pDigit)
+{
+       int offset = 0;
+       unsigned char temp;
+
+       for (int i = 0; i < BcdLen; i++) {
+               temp = pBcd[i] & 0x0F;
+
+               if (temp == 0x0A)
+                       pDigit[offset++] = '*';
+               else if (temp == 0x0B)
+                       pDigit[offset++] = '#';
+               else if (temp == 0x0C)
+                       pDigit[offset++] = 'P';
+               else
+                       pDigit[offset++] = temp + '0';
+
+               temp = (pBcd[i] & 0xF0) >> 4;
+
+               if (temp == 0x0F) {
+                       pDigit[offset] = '\0';
+                       return offset;
+               }
+
+               if (temp == 0x0A)
+                       pDigit[offset++] = '*';
+               else if (temp == 0x0B)
+                       pDigit[offset++] = '#';
+               else if (temp == 0x0C)
+                       pDigit[offset++] = 'P';
+               else
+                       pDigit[offset++] = temp + '0';
+       }
+
+       pDigit[offset] = '\0';
+
+       return offset;
+}
+
+int SmsPluginParamCodec::convertDigitToDTMF(const char *pDigit, int DigitLen, int startBit, unsigned char *pDtmf)
+{
+       int shift = startBit;
+       int offset = 0;
+       int srcIdx = 0;
+       unsigned char temp;
+
+       if (shift > 7) {
+               MSG_DEBUG("Invalid Param value shift : %d", shift);
+               return 0;
+       }
+       /* shift 1 and shift 2 are supported in this spec. */
+       if (shift >= 4) {
+               MSG_DEBUG("Invalid Param value shift : %d", shift);
+               return 0;
+       }
+
+       for (int i = 0; i < DigitLen; i++) {
+               if (pDigit[srcIdx] == '*')
+                       temp = 0x0B;
+               else if (pDigit[srcIdx] == '#')
+                       temp = 0x0C;
+               else if (pDigit[srcIdx] == '0')
+                       temp = 0x0A;
+               else
+                       temp = pDigit[srcIdx] - '0';
+
+               temp &= 0x0F;
+
+               if (shift == 0) {
+                       if (i % 2 == 1) {
+                               pDtmf[offset] |= temp;
+                               offset++;
+                       } else {
+                               pDtmf[offset] |= temp << 4;
+                       }
+               } else if (shift >= 1 && shift < 4) {
+                       if (i % 2 == 1) {
+                               pDtmf[offset] |= (temp >> shift);
+                               pDtmf[offset + 1] = temp << (8 - shift);
+                               offset++;
+                       } else {
+                               pDtmf[offset] |= (temp << (8 - shift - 4));
+                       }
+               }
+
+               srcIdx++;
+       }
+
+       return offset;
+}
+
+int SmsPluginParamCodec::convertDTMFToDigit(const unsigned char *pDtmf, int DtmfLen, int startBit, char *pDigit)
+{
+       int shift = startBit;
+       int offset = 0;
+       int srcIdx = 0;
+       unsigned char temp = 0;
+
+       if (shift > 7) {
+               MSG_DEBUG("Invalid Param value shift : %d", shift);
+               return 0;
+       }
+       /* shift 1 and shift 2 are supported in this spec. */
+       if (shift >= 4) {
+               MSG_DEBUG("Invalid Param value shift : %d", shift);
+               return 0;
+       }
+
+       for (int i = 0; i < DtmfLen; i++) {
+               if (shift == 0) {
+                       if (i % 2 == 1) {
+                               temp = pDtmf[srcIdx] & 0x0F;
+                               srcIdx++;
+                       } else {
+                               temp = (pDtmf[srcIdx] >> 4) & 0x0F;
+                       }
+               } else if (shift >= 1 && shift < 4) {
+                       if (i % 2 == 1) {
+                               temp = ((pDtmf[srcIdx] << shift) & 0x0F) + (pDtmf[srcIdx + 1] >> (8 - shift));
+                               srcIdx++;
+                       } else {
+                               temp = (pDtmf[srcIdx] >> (8 - shift - 4)) & 0x0F;
+                       }
+               }
+
+               if (temp == 0x0A)
+                       pDigit[offset++] = '0';
+               else if (temp == 0x0B)
+                       pDigit[offset++] = '*';
+               else if (temp == 0x0C)
+                       pDigit[offset++] = '#';
+               else
+                       pDigit[offset++] = temp + '0';
+       }
+
+       pDigit[offset] = '\0';
+
+       return offset;
+}
+
+bool SmsPluginParamCodec::isDtmfNumber(const char *pDigit, int DigitLen)
+{
+       bool isDtmf = true;
+
+       for (int i = 0; i < DigitLen; i++) {
+               if (!((pDigit[i] >= '0' && pDigit[i] <= '9') ||
+                       pDigit[i] == '*' ||
+                       pDigit[i] == '#')) {
+                       isDtmf = false;
+                       break;
+               }
+       }
+
+       return isDtmf;
+}
+
+
+
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginSetting.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginSetting.cpp
new file mode 100755 (executable)
index 0000000..9ca4712
--- /dev/null
@@ -0,0 +1,680 @@
+/*
+* 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 <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 "SmsCdmaPluginParamCodec.h"
+#include "SmsCdmaPluginCallback.h"
+#include "SmsCdmaPluginEventHandler.h"
+#include "SmsCdmaPluginMain.h"
+#include "SmsCdmaPluginSetting.h"
+
+
+extern "C"
+{
+       #include <tapi_common.h>
+       #include <TelSms.h>
+       #include <TapiUtility.h>
+       #include <ITapiNetText.h>
+       #include <ITapiSim.h>
+       #include <ITapiModem.h>
+}
+
+extern struct tapi_handle *pTapiHandle;
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF SmsPluginSetting - Member Functions
+==================================================================================================*/
+SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
+
+
+SmsPluginSetting::SmsPluginSetting()
+{
+       // Initialize member variables
+       memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
+       memset(&meImei, 0x00, sizeof(meImei));
+
+       bTapiResult = false;
+       bUpdateVoicemailByMdn = false;
+}
+
+
+SmsPluginSetting::~SmsPluginSetting()
+{
+
+
+}
+
+
+SmsPluginSetting* SmsPluginSetting::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginSetting();
+
+       return pInstance;
+}
+
+
+void* SmsPluginSetting::initSimInfo(void *data)
+{
+       MSG_BEGIN();
+
+       int tapiRet = TAPI_API_SUCCESS;
+
+       // Get IMSI
+       char imsi[17];
+       memset(imsi, 0x00, sizeof(imsi));
+
+       // Get IMSI
+       TelSimImsiInfo_t imsiInfo;
+       memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
+
+       tapiRet = tel_get_sim_imsi(pTapiHandle, &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);
+               MsgSettingSetBool(MSG_NATIONAL_SIM, false);
+       }
+
+       MsgSettingSetString(MSG_SIM_IMSI, imsi);
+
+       instance()->updateSimStatus();
+
+       MSG_END();
+       return NULL;
+}
+
+void SmsPluginSetting::updateSimStatus()
+{
+       MSG_BEGIN();
+
+       if (!pTapiHandle) {
+               MSG_DEBUG("pTapiHandle is NULL.");
+               return;
+       }
+
+       int status = 0;
+       int 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;
+       }
+
+       if (status == 1 || status == 2) {
+               MSG_DEBUG("Device Is Ready, status = %d", status);
+               SmsPluginEventHandler::instance()->setNeedInitConfig(false);
+       } else if (status == 0) {
+               MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
+
+               if (SmsPluginEventHandler::instance()->getDeviceStatus() == true) {
+                       MSG_DEBUG("Device Is Ready");
+               } else {
+                       MSG_DEBUG("Device Is Not Ready.");
+                       return;
+               }
+       }
+
+       // init config data.
+       initConfigData();
+
+       MSG_END();
+
+       return;
+}
+
+
+void SmsPluginSetting::setSimChangeStatus()
+{
+       MSG_BEGIN();
+
+       pthread_t thd;
+
+       if(pthread_create(&thd, NULL, &initSimInfo, NULL) < 0) {
+               MSG_DEBUG("pthread_create() error");
+       }
+
+       pthread_detach(thd);
+
+       MSG_END();
+}
+
+
+
+void SmsPluginSetting::initConfigData()
+{
+       MSG_BEGIN();
+
+       msg_error_t     err = MSG_SUCCESS;
+
+#if 1
+       /*==================== CB configuration ====================*/
+//     if (simStatus != MSG_SIM_STATUS_NOT_FOUND)
+//     {
+//             MSG_DEBUG("simStatus == [%d]", simStatus);
+
+               MSG_CBMSG_OPT_S cbMsgOpt = {0,};
+
+               if (getCbConfig(&cbMsgOpt) == true) {
+                       err = addCbOpt(&cbMsgOpt);
+
+                       if (err == MSG_SUCCESS) {
+                               MSG_DEBUG("########  Add CB Option Success !!! #######");
+                               MSG_SETTING_S cbSetting;
+                               cbSetting.type = MSG_CBMSG_OPT;
+                               getCbOpt(&cbSetting);
+                               setCbConfig(&(cbSetting.option.cbMsgOpt));
+                       } else {
+                               MSG_DEBUG("########  Add CB Option Fail !!! return : %d #######", err);
+                       }
+               } else {
+                       MSG_DEBUG("########  getCbConfig Fail !!! #######");
+#endif
+
+#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
+               }
+
+               /*==================== MSISDN update ====================*/
+               if (getMsisdnInfo() == true) {
+                       MSG_DEBUG("########  getMsisdnInfo Success !!! #######");
+               } else {
+                       MSG_DEBUG("########  getMsisdnInfo Fail !!! #######");
+               }
+#if 1
+               /*==================== Default Voice mail Setting ====================*/
+               char *num = MsgSettingGetString(VOICEMAIL_DEFAULT_NUMBER);
+
+               if (num) {
+                       MSG_DEBUG("Voicemail Default Number [%s]", num);
+                       if (MsgSettingSetString(VOICEMAIL_NUMBER, num) != MSG_SUCCESS)
+                               MSG_DEBUG("MsgSettingSetInt is failed!!");
+                       free(num);
+                       num = NULL;
+               }
+               else {
+                       MSG_DEBUG("Voicemail Default Number is NULL");
+                       if (MsgSettingSetString(VOICEMAIL_NUMBER, "") != MSG_SUCCESS)
+                               MSG_DEBUG("MsgSettingSetInt is failed!!");
+               }
+
+               char *voiceNumber = MsgSettingGetString(VOICEMAIL_NUMBER);
+
+               if (!voiceNumber || (voiceNumber && voiceNumber[0] == '\0')) {
+                       MSG_DEBUG("Voice Number is Empty");
+               }
+
+               if (voiceNumber) {
+                       free(voiceNumber);
+                       voiceNumber = NULL;
+               }
+
+               if (MsgSettingSetString(VOICEMAIL_ALPHA_ID, VOICEMAIL_DEFAULT_ALPHA_ID) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgSettingSetString is failed!!");
+#endif
+
+       MSG_END();
+}
+
+
+void SmsPluginSetting::SimRefreshCb()
+{
+       pthread_t thd;
+
+       if(pthread_create(&thd, NULL, &init_config_data, NULL) < 0) {
+               MSG_DEBUG("pthread_create() error");
+       }
+
+       pthread_detach(thd);
+
+}
+
+
+void* SmsPluginSetting::init_config_data(void *data)
+{
+       instance()->initConfigData();
+       return NULL;
+}
+
+
+void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
+{
+       MSG_DEBUG("Setting Type : [%d]", pSetting->type);
+
+       switch (pSetting->type)
+       {
+#if 0
+               case MSG_SMS_SENDOPT :
+                       setNetworkMode(&pSetting->option.smsSendOpt);
+                       break;
+               case MSG_SMSC_LIST :
+                       setParamList(&pSetting->option.smscList);
+                       break;
+#endif
+               case MSG_VOICEMAIL_OPT:
+                       setVoiceMailInfo(&pSetting->option.voiceMailOpt);
+                       break;
+
+               case MSG_CBMSG_OPT :
+                       setCbConfig(&pSetting->option.cbMsgOpt);
+                       break;
+               default :
+                       THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
+                       break;
+       }
+}
+
+
+void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
+{
+       MSG_DEBUG("Setting Type : [%d]", pSetting->type);
+
+       switch (pSetting->type)
+       {
+#if 0
+               case MSG_SMSC_LIST :
+                       getParamList(&pSetting->option.smscList);
+               break;
+#endif
+               case MSG_CBMSG_OPT :
+                       getCbConfig(&pSetting->option.cbMsgOpt);
+               break;
+
+               default :
+                       THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
+               break;
+       }
+}
+
+
+msg_error_t SmsPluginSetting::addCbOpt(MSG_CBMSG_OPT_S *pCbOpt)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+//     MSG_DEBUG("Receive [%d], Max SIM Count [%d]", pCbOpt->bReceive, pCbOpt->maxSimCnt);
+
+       MSG_DEBUG("Receive [%d], Channel Count [%d]", pCbOpt->bReceive, pCbOpt->channelData.channelCnt);
+
+       for (int i = 0; i < pCbOpt->channelData.channelCnt; i++)
+       {
+               MSG_DEBUG("Channel Category [%d], Channel Language [%d]", pCbOpt->channelData.channelInfo[i].ctg, pCbOpt->channelData.channelInfo[i].lang);
+       }
+
+#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 0
+       if (MsgSettingSetInt(CB_MAX_SIM_COUNT, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
+               MSG_DEBUG("Error to set config data [%s]", CB_MAX_SIM_COUNT);
+               return MSG_ERR_SET_SETTING;
+       }
+#endif
+
+#if 0
+       MsgDbHandler dbHandle;
+       err = MsgStoAddCBChannelInfo(&dbHandle, &pCbOpt->channelData);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("MsgStoGetCBChannelInfo is failed [%d]", err);
+               return MSG_ERR_SET_SETTING;
+       }
+#endif
+
+       return err;
+}
+
+
+void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting)
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler dbHandle;
+
+       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);
+
+       err = MsgStoGetCBChannelInfo(&dbHandle, &pSetting->option.cbMsgOpt.channelData);
+       MSG_DEBUG("MsgStoAddCBChannelInfo : err=[%d]", err);
+
+#if 0
+       char keyName[128];
+
+       for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++) {
+               memset(keyName, 0x00, sizeof(keyName));
+               snprintf(keyName, sizeof(keyName), "%s/%d", CB_LANGUAGE, i);
+
+               MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bLanguage[i]);
+       }
+#endif
+
+}
+
+void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
+{
+       bUpdateVoicemailByMdn = false;
+
+       return;
+}
+
+bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
+{
+       int ret = TAPI_API_SUCCESS;
+
+#if 1
+       TelSmsCbConfig_t cbConfig = {};
+
+       cbConfig.CBEnabled = (int)pCbOpt->bReceive;
+       cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP2;
+//     cbConfig.MsgIdMaxCount = pCbOpt->maxSimCnt;
+       cbConfig.MsgIdRangeCount = pCbOpt->channelData.channelCnt;
+
+       for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
+               cbConfig.MsgIDs[i].Net3gpp2.Selected = (unsigned short)pCbOpt->channelData.channelInfo[i].bActivate;
+               cbConfig.MsgIDs[i].Net3gpp2.CBCategory = (unsigned short)pCbOpt->channelData.channelInfo[i].ctg;
+               cbConfig.MsgIDs[i].Net3gpp2.CBLanguage = (unsigned short)pCbOpt->channelData.channelInfo[i].lang;
+
+               MSG_DEBUG("Category: %d, Language: %d", cbConfig.MsgIDs[i].Net3gpp2.CBCategory, cbConfig.MsgIDs[i].Net3gpp2.CBLanguage);
+       }
+       MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);
+
+       ret = tel_set_sms_cb_config(pTapiHandle, &cbConfig, TapiEventSetConfigData, NULL);
+
+       if (ret == TAPI_API_SUCCESS) {
+               MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
+       } else {
+               MSG_DEBUG("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
+               return false;
+       }
+
+#if 0
+       if (getResultFromSim() == true) {
+               MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
+       } else {
+               MSG_DEBUG("######## Set Cb Config was Failed !!! #######");
+               return false;
+       }
+#endif
+#endif
+       return true;
+}
+
+
+bool SmsPluginSetting::getCbConfig(MSG_CBMSG_OPT_S *pCbOpt)
+{
+       int ret = TAPI_API_SUCCESS;
+#if 1
+       ret = tel_get_sms_cb_config(pTapiHandle, 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);
+               return false;
+       }
+
+       if (getCbConfigEvent(pCbOpt) == true) {
+               MSG_DEBUG("######## Get Cb Config was Successful !!! #######");
+       } else {
+               MSG_DEBUG("######## Get Cb Config was Failed !!! #######");
+               return false;
+       }
+#endif
+       return true;
+}
+
+
+void SmsPluginSetting::getMeImei(char *pImei)
+{
+#if 0
+       int ret = TAPI_API_SUCCESS;
+       ret = tel_get_misc_me_imei(pTapiHandle, 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);
+       }
+#endif
+}
+
+bool SmsPluginSetting::getUpdateVoicemailByMdn()
+{
+       return bUpdateVoicemailByMdn;
+}
+
+void SmsPluginSetting::setCbConfigEvent(const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
+{
+       mx.lock();
+
+       bTapiResult = bSuccess;
+
+       memset(&cbOpt, 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));
+       }
+
+       cv.signal();
+
+       mx.unlock();
+}
+
+
+bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
+{
+       int ret = 0;
+
+       mx.lock();
+
+       bTapiResult = false;
+       ret = cv.timedwait(mx.pMutex(), 25);
+
+       mx.unlock();
+
+       if (ret == ETIMEDOUT) {
+               MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
+               return false;
+       }
+
+       memset(pCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
+
+       if (bTapiResult == true) {
+               memcpy(pCbOpt, &cbOpt, sizeof(MSG_CBMSG_OPT_S));
+       }
+
+       return bTapiResult;
+}
+
+
+void SmsPluginSetting::setResultImei(bool bResult, char *pImei)
+{
+       mx.lock();
+
+       bTapiResult = bResult;
+
+       memset(&meImei, 0x00, sizeof(meImei));
+
+       if (bTapiResult == true && pImei) {
+               snprintf(meImei, sizeof(meImei), "%s", pImei);
+       }
+
+       cv.signal();
+
+       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::setResultFromEvent(bool bResult)
+{
+       mx.lock();
+
+       bTapiResult = bResult;
+
+       cv.signal();
+
+       mx.unlock();
+}
+
+
+void SmsPluginSetting::setMwiInfo(MSG_SUB_TYPE_T type, int count)
+{
+       MSG_DEBUG("SET MWI INFO, type=[%d]", type);
+       MSG_DEBUG("SET MWI INFO, count=[%d]", count);
+
+       if (MsgSettingSetInt(VOICEMAIL_COUNT, count) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingSetInt is failed!!");
+
+//     if (count == 0) {
+//             MsgStoClearUniquenessTable();
+//     }
+
+//     if(count <= 0) {
+//             if (type == MSG_MWI_VOICE_SMS)
+//                     MsgCleanAndResetNotification(MSG_NOTI_TYPE_VOICE_1);
+//             else if (type == MSG_MWI_VOICE2_SMS)
+//                     MsgCleanAndResetNotification(MSG_NOTI_TYPE_VOICE_2);
+//     }
+
+//     if (bMbdnEnable == false) {
+//             MSG_DEBUG("MBDN service is disable.");
+//             return;
+//     }
+
+       return;
+}
+
+
+bool SmsPluginSetting::getMsisdnInfo(void)
+{
+       int ret = TAPI_API_SUCCESS;
+
+       ret = tel_get_sim_msisdn(pTapiHandle, TapiEventGetMsisdnInfo, NULL);
+
+       if (ret == TAPI_API_SUCCESS) {
+               MSG_DEBUG("######## tel_get_sim_msisdn() Success !!! #######");
+       } else {
+               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;
+}
+
+
+void SmsPluginSetting::setResultFromSim(bool bResult)
+{
+       mx.lock();
+
+       bTapiResult = bResult;
+
+       cv.signal();
+
+       mx.unlock();
+}
+
+
+bool SmsPluginSetting::getResultFromSim()
+{
+       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;
+       }
+
+       return bTapiResult;
+}
+
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginStorage.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginStorage.cpp
new file mode 100755 (executable)
index 0000000..a549b86
--- /dev/null
@@ -0,0 +1,669 @@
+/*
+* 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 <errno.h>
+
+#include "MsgDebug.h"
+#include "MsgCppTypes.h"
+#include "MsgException.h"
+#include "MsgContact.h"
+#include "MsgUtilFile.h"
+#include "MsgUtilStorage.h"
+#include "MsgUtilFunction.h"
+#include "MsgGconfWrapper.h"
+#include "MsgNotificationWrapper.h"
+
+#include "SmsCdmaPluginMain.h"
+#include "SmsCdmaPluginStorage.h"
+
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF SmsPluginStorage - Member Functions
+==================================================================================================*/
+SmsPluginStorage* SmsPluginStorage::pInstance = NULL;
+
+
+SmsPluginStorage::SmsPluginStorage()
+{
+
+}
+
+
+SmsPluginStorage::~SmsPluginStorage()
+{
+
+}
+
+
+SmsPluginStorage* SmsPluginStorage::instance()
+{
+       if (!pInstance) {
+               MSG_DEBUG("pInstance is NULL. Now creating instance.");
+               pInstance = new SmsPluginStorage();
+       }
+
+       return pInstance;
+}
+
+
+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)
+               return MSG_ERR_DB_GETTABLE;
+
+       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;
+       }
+
+       MsgDbHandler *dbHandle = getDbHandle();
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       MSG_DEBUG("Update Msg ID : [%d], Network Status : [%d] ", pMsgInfo->msgId, status);
+
+       /** Move Msg to SENTBOX */
+       if (status == MSG_NETWORK_SEND_SUCCESS) {
+               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, READ_STATUS = 0 WHERE MSG_ID = %d;",
+                                       MSGFW_MESSAGE_TABLE_NAME, status, pMsgInfo->msgId);
+       }
+
+       if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+               MSG_DEBUG("MsgExecQuery() : [%s]", sqlQuery);
+               return MSG_ERR_DB_EXEC;
+       }
+
+       if (status == MSG_NETWORK_SEND_SUCCESS) {
+               MSG_DEBUG("MsgAddPhoneLog() : folderId [%d]", pMsgInfo->folderId);
+               MsgAddPhoneLog(pMsgInfo);
+       }
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPluginStorage::checkMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /**  Check whether storage is full or not */
+       err = checkStorageStatus(pMsgInfo);
+
+       if (err != MSG_SUCCESS) {
+               if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
+                       pMsgInfo->folderId = 0;
+                       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;
+       }
+
+       /**  Amend message information for type **/
+       if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS) {
+               MSG_DEBUG("Normal SMS");
+
+               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;
+               }
+
+       } else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
+               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("MWI Message");
+
+//                     if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
+//                             err = addClass2Message(pMsgInfo);
+//                     }
+               }
+       } else {
+               MSG_DEBUG("No matching type [%d]", pMsgInfo->msgType.subType);
+       }
+
+       if (err == MSG_SUCCESS) {
+               MSG_DEBUG("Success to check message !!");
+       } else {
+               MSG_DEBUG("fail to check message !! : [%d]", err);
+       }
+
+       return err;
+}
+
+
+msg_error_t SmsPluginStorage::addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       unsigned int rowId = 0;
+       msg_thread_id_t convId = 0;
+
+       MsgDbHandler *dbHandle = getDbHandle();
+       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;
+       }
+
+       /** Update conversation table */
+       err = MsgStoUpdateConversation(dbHandle, convId);
+
+       if (err != MSG_SUCCESS) {
+               dbHandle->endTrans(false);
+               return err;
+       }
+
+       err = dbHandle->endTrans(true);
+       if (err != MSG_SUCCESS) {
+               return err;
+       }
+
+       pMsgInfo->msgId = (msg_message_id_t)rowId;
+
+       MSG_END();
+
+       return MSG_SUCCESS;
+}
+
+
+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, CONV_ID, SIM_INDEX \
+                       FROM %s WHERE MSG_ID = %d;",
+                       MSGFW_MESSAGE_TABLE_NAME, msgId);
+
+       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;
+       int 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);
+               simIndex = dbHandle->columnInt(4);
+
+               MSG_DEBUG("Main Type:[%d] SubType:[%d] FolderId:[%d] ConversationId:[%d] simIndex:[%d]", msgType.mainType, msgType.subType, folderId, convId, simIndex);
+       } else {
+               MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
+               dbHandle->finalizeQuery();
+               return MSG_ERR_DB_STEP;
+       }
+
+       dbHandle->finalizeQuery();
+
+       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);
+               return MSG_ERR_DB_EXEC;
+       }
+
+       if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               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);
+                       return MSG_ERR_DB_EXEC;
+               }
+       } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               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);
+                       return MSG_ERR_DB_EXEC;
+               }
+       } else if (msgType.subType == MSG_SYNCML_CP) {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               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);
+                       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_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);
+               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);
+
+       if (folderId == MSG_INBOX_ID) {
+               msgType.classType = MSG_CLASS_NONE;
+
+               /**  Set memory status in SIM */
+               if (MsgStoCheckMsgCntFull(dbHandle, &msgType, folderId) == MSG_SUCCESS) {
+                       MSG_DEBUG("Set Memory Status");
+                       SmsPlgSetMemoryStatus(MSG_SUCCESS);
+               }
+       }
+
+//     MsgRefreshAllNotification(true, false, false);
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t SmsPluginStorage::addSmsSendOption(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo)
+{
+       MSG_BEGIN();
+
+       MsgDbHandler *dbHandle = getDbHandle();
+       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];
+
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               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);
+
+               MSG_DEBUG("Query = [%s]", sqlQuery);
+
+               if (dbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
+                       err = MSG_ERR_DB_EXEC;
+               }
+//     }
+
+       MSG_END();
+
+       return err;
+}
+
+
+msg_error_t SmsPluginStorage::checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+       MsgDbHandler *dbHandle = getDbHandle();
+       err = MsgStoCheckMsgCntFull(dbHandle, &(pMsgInfo->msgType), pMsgInfo->folderId);
+
+       if (err != MSG_SUCCESS) {
+
+               if (err == MSG_ERR_MESSAGE_COUNT_FULL) {
+                       bool bAutoErase = false;
+
+                       MsgSettingGetBool(MSG_AUTO_ERASE, &bAutoErase);
+
+                       MSG_DEBUG("bAutoErase: %d", bAutoErase);
+
+                       if (bAutoErase == true) {
+                               msg_message_id_t msgId;
+
+                               /** Find the oldest message's msgId */
+                               err = MsgStoGetOldestMessage(dbHandle, pMsgInfo, &msgId);
+
+                               if (err != MSG_SUCCESS)
+                                       return err;
+
+                               /** Delete the corresponding message. */
+                               err = deleteSmsMessage(msgId);
+                       }
+               }
+
+               return err;
+       }
+
+       return err;
+}
+
+
+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);
+       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;
+       }
+
+       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;
+       *count = 0;
+
+
+       for (int i = 0; i < rowCnt; i++) {
+               memset(contentType, 0, MAX_WAPPUSH_CONTENT_TYPE_LEN);
+               memset(appId, 0, MAX_WAPPUSH_ID_LEN);
+
+               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, contentType);
+               if(_content_type) {
+                       _app_id = strcasestr(pPushHeader, appId);
+                       if(appcode)
+                               default_appcode = appcode;
+
+                       if(_app_id) {
+                               PUSH_APPLICATION_INFO_S pInfo = {0, };
+                               pInfo.appcode = appcode;
+                               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;
+                       }
+               }
+       }
+
+       if(!found && default_appcode != SMS_WAP_APPLICATION_LBS)
+       {
+               // perform default action.
+               PUSH_APPLICATION_INFO_S pInfo = {0, };
+               pInfo.appcode = default_appcode;
+               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();
+
+       return err;
+}
+
+
+msg_error_t SmsPluginStorage::getnthPushEvent(int index, int *appcode)
+{
+       msg_error_t err = MSG_SUCCESS;
+       if((unsigned int)index > pushAppInfoList.size() - 1)
+               return MSG_ERR_INVALID_PARAMETER;
+
+       std::list<PUSH_APPLICATION_INFO_S>::iterator it = pushAppInfoList.begin();
+       int count = 0;
+       for (; it != pushAppInfoList.end(); it++)
+       {
+               if(index == count){
+                       *appcode = it->appcode;
+                       break;
+               }
+               count++;
+       }
+
+       return err;
+}
+
+
+msg_error_t SmsPluginStorage::releasePushEvent()
+{
+       msg_error_t err = MSG_SUCCESS;
+       std::list<PUSH_APPLICATION_INFO_S>::iterator it = pushAppInfoList.begin();
+
+       for (; it != pushAppInfoList.end(); it++)
+               it = pushAppInfoList.erase(it);
+
+       return err;
+}
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginTransport.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginTransport.cpp
new file mode 100755 (executable)
index 0000000..4d65722
--- /dev/null
@@ -0,0 +1,560 @@
+/*
+* 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 <errno.h>
+
+#include "MsgGconfWrapper.h"
+#include "MsgException.h"
+
+#include "MsgUtilStorage.h"
+#include "MsgNotificationWrapper.h"
+
+#include "SmsCdmaPluginTransport.h"
+#include "SmsCdmaPluginCodec.h"
+#include "SmsCdmaPluginEventHandler.h"
+#include "SmsCdmaPluginCallback.h"
+
+extern "C" {
+#include "TapiUtility.h"
+#include "TelSms.h"
+#include "TelNetwork.h"
+#include "ITapiNetText.h"
+}
+
+extern struct tapi_handle *pTapiHandle;
+extern bool isMemAvailable;
+
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+
+SmsPluginTransport* SmsPluginTransport::pInstance = NULL;
+
+
+SmsPluginTransport::SmsPluginTransport()
+{
+       msgRef          = 0x00;
+       msgRef8bit      = 0x00;
+       msgRef16bit     = 0x0000;
+
+       msgSeqNum   = 0x00;
+       msgSubmitId = MsgSettingGetInt(MSG_MESSAGE_ID_COUNTER);
+}
+
+
+SmsPluginTransport::~SmsPluginTransport()
+{
+
+}
+
+
+SmsPluginTransport* SmsPluginTransport::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginTransport();
+
+       return pInstance;
+}
+
+
+unsigned char SmsPluginTransport::getMsgRef()
+{
+       return msgRef++;
+}
+
+
+unsigned char SmsPluginTransport::getSeqNum()
+{
+       msgSeqNum = ((msgSeqNum + 1) % SMS_SEQ_NUM_MAX);
+
+       return msgSeqNum;
+}
+
+
+unsigned char SmsPluginTransport::getSubmitMsgId()
+{
+       msgSubmitId = ((msgSubmitId + 1) % SMS_MAX_MESSAGE_ID);
+
+       MsgSettingSetInt(MSG_MESSAGE_ID_COUNTER, msgSubmitId);
+
+       return msgSubmitId;
+}
+
+
+void SmsPluginTransport::convertMsgInfoToTelesvcMsg(const MSG_MESSAGE_INFO_S *pMsgInfo, sms_trans_msg_s *pTransMsg)
+{
+       switch (pTransMsg->type) {
+               case SMS_TRANS_P2P_MSG:
+               {
+                       MSG_DEBUG("Convert  MSG_MESSAGE_INFO_S data to SMS_TRANS_MSG_S data.");
+                       sms_trans_p2p_msg_s *pPtpMsg = (sms_trans_p2p_msg_s *)&(pTransMsg->data.p2p_msg);
+
+                       convertMsgInfoToPtp(pMsgInfo, pPtpMsg);
+               }
+                       break;
+               default:
+                       MSG_DEBUG("Error Unsupported Transport Type");
+                       break;
+       }
+}
+
+
+void SmsPluginTransport::convertMsgInfoToPtp(const MSG_MESSAGE_INFO_S *pMsgInfo, sms_trans_p2p_msg_s *pPtpMsg)
+{
+
+       /* 1. Set Teleservice ID */
+       pPtpMsg->telesvc_id = SMS_TRANS_TELESVC_CMT_95;
+
+       /* 2. Set Service category */
+       pPtpMsg->svc_ctg = SMS_TRANS_SVC_CTG_UNDEFINED;
+
+       /* 3. Convert Address values */
+       pPtpMsg->address.digit_mode = SMS_DIGIT_4BIT_DTMF;
+       pPtpMsg->address.number_mode = SMS_NUMBER_MODE_NONE_DATANETWORK;
+       pPtpMsg->address.number_type = SMS_NUMBER_TYPE_UNKNOWN;
+       pPtpMsg->address.number_plan = SMS_NPI_UNKNOWN;
+       pPtpMsg->address.addr_len = strlen(pMsgInfo->addressList[0].addressVal);
+       strncpy(pPtpMsg->address.szData, pMsgInfo->addressList[0].addressVal, pPtpMsg->address.addr_len);
+
+       if (pMsgInfo->addressList[0].addressVal[0] == '+') {
+               pPtpMsg->address.digit_mode = SMS_DIGIT_8BIT;
+               pPtpMsg->address.number_type = SMS_NUMBER_TYPE_INTERNATIONAL;
+       }
+       else {
+               pPtpMsg->address.number_type = SMS_NUMBER_TYPE_NATIONAL;
+       }
+
+       /* 4. Convert Sub-address values */
+       // TODO
+
+       /* 5. Set Reply sequence number. */
+       pPtpMsg->reply_seq = getSeqNum();
+
+       /* convert msgInfo to Teleservice Message */
+       switch (pPtpMsg->telesvc_msg.type) {
+               case SMS_TYPE_SUBMIT:
+                       convertMsgInfoToSubmit(pMsgInfo, &(pPtpMsg->telesvc_msg.data.submit));
+                       break;
+               default:
+                       break;
+       }
+
+}
+
+
+void SmsPluginTransport::convertMsgInfoToSubmit(const MSG_MESSAGE_INFO_S *pMsgInfo, sms_telesvc_submit_s *pSubmit)
+{
+       if (pSubmit == NULL)
+               return;
+
+       /* 1. Set msg ID. */
+       pSubmit->msg_id.msg_id = getSubmitMsgId();
+       pSubmit->msg_id.header_ind = false;
+
+       /* 2. Set User Data */
+       unsigned char decodeData[SMS_MAX_USER_DATA_LEN + 1];
+       memset(decodeData, 0x00, sizeof(decodeData));
+
+       MsgTextConvert *textCvt = MsgTextConvert::instance();
+
+       msg_encode_type_t encodeType = MSG_ENCODE_GSM7BIT;
+
+
+       if (pMsgInfo->bTextSms == true) {
+               if (pMsgInfo->encodeType == MSG_ENCODE_GSM7BIT)
+               {
+                       pSubmit->user_data.encode_type = SMS_ENCODE_GSM7BIT;
+               }
+               else if (pMsgInfo->encodeType == MSG_ENCODE_8BIT)
+               {
+                       pSubmit->user_data.encode_type = SMS_ENCODE_OCTET;
+               }
+               else if (pMsgInfo->encodeType == MSG_ENCODE_UCS2)
+               {
+                       pSubmit->user_data.encode_type = SMS_ENCODE_UNICODE;
+               }
+               else if (pMsgInfo->encodeType == MSG_ENCODE_AUTO)
+               {
+                       textCvt->convertUTF8ToAuto(decodeData, SMS_MAX_USER_DATA_LEN + 1, (unsigned char*)pMsgInfo->msgText, (int)pMsgInfo->dataSize, &encodeType);
+                       if (encodeType == MSG_ENCODE_ASCII7BIT) {
+                               pSubmit->user_data.encode_type = SMS_ENCODE_7BIT_ASCII;
+                       }
+                       else if (encodeType == MSG_ENCODE_8BIT) {
+                               pSubmit->user_data.encode_type = SMS_ENCODE_OCTET;
+                       }
+                       else if (encodeType == MSG_ENCODE_UCS2) {
+                               pSubmit->user_data.encode_type = SMS_ENCODE_UNICODE;
+                       }
+               }
+       }
+
+       memset(pSubmit->user_data.user_data, 0x00, sizeof(pSubmit->user_data.user_data));
+       snprintf((char *)pSubmit->user_data.user_data, sizeof(pSubmit->user_data.user_data), "%s", pMsgInfo->msgText);
+       pSubmit->user_data.data_len = pMsgInfo->dataSize;
+
+       MSG_DEBUG("encode type : [%d]", pSubmit->user_data.encode_type);
+
+       /* 3. Set Valid period */
+#if 0
+       pSubmit->val_period.format = SMS_TIME_ABSOLUTE;
+       pSubmit->val_period.time.abs_time.year = 0;
+       pSubmit->val_period.time.abs_time.month = 0;
+       pSubmit->val_period.time.abs_time.day = 0;
+       pSubmit->val_period.time.abs_time.hours = 0;
+       pSubmit->val_period.time.abs_time.minutes = 0;
+       pSubmit->val_period.time.abs_time.seconds = 0;
+#else
+       pSubmit->val_period.format = SMS_TIME_RELATIVE;
+       pSubmit->val_period.time.rel_time.rel_time = SMS_REL_TIME_INDEFINITE;
+#endif
+
+       /* 4. Set Defer valid period */
+       // TODO
+
+       /* 5. Set Priority */
+       switch (pMsgInfo->priority) {
+               case MSG_MESSAGE_PRIORITY_HIGH:
+                       pSubmit->priority = SMS_PRIORITY_URGENT;
+                       break;
+               default:
+                       pSubmit->priority = SMS_PRIORITY_NORMAL;
+                       break;
+       }
+
+       /* 6. Set Privacy */
+       pSubmit->privacy = SMS_PRIVACY_NOT_RESTRICTED;
+
+       /* 7. Set Reply option */
+       MsgSettingGetBool(SMS_SEND_DELIVERY_REPORT, (bool *)&(pSubmit->reply_opt.deliver_ack_req));
+
+       /* 8. Set Alert priority */
+       pSubmit->alert_priority = SMS_ALERT_MOBILE_DEFAULT;
+
+       /* 9. Set Language */
+       pSubmit->language = SMS_LAN_UNKNOWN;
+
+       /* 10. Set Callback number */
+       // TODO :: Set callback number to MSISDN
+
+       /* 11. Set Multi encode data */
+       // TODO
+
+       /* 12. Set Deposit id */
+       // TODO
+
+       /* 13. Set Service category program data */
+       // TODO
+
+}
+
+
+
+void SmsPluginTransport::submitRequest(sms_request_info_s *pReqInfo)
+{
+       int tapiRet = TAPI_API_SUCCESS;
+
+       if (pReqInfo == NULL) {
+               THROW(MsgException::SMS_PLG_ERROR, "pReqInfo is NULL");
+       }
+
+       // Get address informations.
+       MsgDbHandler *dbHandle = getDbHandle();
+       //contacts-service is not used for gear
+#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+       MsgStoGetAddressByMsgId(dbHandle, pReqInfo->msgInfo.msgId, 0, &pReqInfo->msgInfo.nAddressCnt, &pReqInfo->msgInfo.addressList);
+#else
+       //contactNameOrder is never used
+       MsgStoGetAddressByMsgId(dbHandle, pReqInfo->msgInfo.msgId, &pReqInfo->msgInfo.nAddressCnt, &pReqInfo->msgInfo.addressList);
+#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
+
+       MSG_DEBUG("pReqInfo->msgInfo.nAddressCnt [%d]", pReqInfo->msgInfo.nAddressCnt);
+
+       // Get MSISDN
+       char *msisdn = NULL;
+       char keyName[MAX_VCONFKEY_NAME_LEN];
+       int simIndex = 1;
+
+       memset(keyName, 0x00, sizeof(keyName));
+       snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
+
+       msisdn = MsgSettingGetString(keyName);
+
+       // Tapi Data Structure
+       TelSmsDatapackageInfo_t tapi_data_pkg;
+       memset(&tapi_data_pkg, 0x00, sizeof(TelSmsDatapackageInfo_t));
+
+       bool bMoreMsgToSend = false;
+
+       tapi_data_pkg.format = (TelSmsNetType_t)TAPI_NETTEXT_NETTYPE_3GPP2;
+
+       /* convert msg_info to trans_msg */
+       sms_trans_msg_s  trans_msg;
+       memset(&trans_msg, 0x00, sizeof(sms_trans_msg_s));
+
+       trans_msg.type = (sms_trans_msg_type_t)SMS_TRANS_P2P_MSG;
+       trans_msg.data.p2p_msg.telesvc_msg.type = (sms_message_type_t)SMS_TYPE_SUBMIT;
+
+       convertMsgInfoToTelesvcMsg(&pReqInfo->msgInfo, &trans_msg);
+
+       /* encode msg data */
+       unsigned char tel_sms_data[TAPI_NETTEXT_SMDATA_SIZE_MAX+1] = {0,};
+
+       tapi_data_pkg.MsgLength = SmsPluginMsgCodec::instance()->encodeMsg(&trans_msg, tel_sms_data);
+
+       memcpy((void *)tapi_data_pkg.szData, (void *)tel_sms_data, sizeof(tapi_data_pkg.szData));
+
+       MSG_DEBUG("Submit Request TPDU.");
+       char pduDbg[TAPI_NETTEXT_SMDATA_SIZE_MAX*2];
+       memset(pduDbg, 0x00, sizeof(pduDbg));
+
+       for (int i = 0; i < tapi_data_pkg.MsgLength; i++) {
+               snprintf(pduDbg+(i*2), sizeof(pduDbg)- (i*2), "%02x", tapi_data_pkg.szData[i]);
+       }
+       MSG_DEBUG("Encode PDU= [%s]", pduDbg);
+
+       /* send request */
+       sms_network_status_t retStatus;
+       sms_sent_info_s sent_info;
+       memset(&sent_info, 0x00, sizeof(sms_sent_info_s));
+       memcpy(&sent_info.reqInfo, pReqInfo, sizeof(sent_info.reqInfo));
+
+       sent_info.bLast = true;
+
+       SmsPluginEventHandler::instance()->SetSentInfo(&sent_info);
+
+       int svc_type;
+       tel_get_property_int(pTapiHandle, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
+
+       if(svc_type < TAPI_NETWORK_SERVICE_TYPE_2G){
+               MSG_DEBUG("Network service is not available : [%d]", svc_type);
+               SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_PENDING);
+               goto _RETURN_FUNC;
+       }
+
+       curStatus = SMS_NETWORK_SENDING;
+
+       // Send SMS
+       tapiRet = tel_send_sms(pTapiHandle, &tapi_data_pkg, bMoreMsgToSend, TapiEventSentStatus, NULL);
+
+       if (tapiRet == TAPI_API_SUCCESS)
+       {
+               MSG_DEBUG("########  tel_send_sms Success !!! return : [%d] #######", tapiRet);
+       }
+       else
+       {
+               SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
+               THROW(MsgException::SMS_PLG_ERROR, "########  tel_send_sms Fail !!! return : [%d] #######", tapiRet);
+       }
+
+       // 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_TXT("%d, [%s]", pReqInfo->msgInfo.msgId, pReqInfo->msgInfo.msgText);
+
+       retStatus = getNetStatus();
+
+       MSG_SMS_VLD_INFO("%d, SMS Send End, %s->%s, %s",  pReqInfo->msgInfo.msgId, \
+                                                                                                                       (msisdn == NULL)?"ME":msisdn, \
+                                                                                                                       pReqInfo->msgInfo.addressList[0].addressVal, \
+                                                                                                                       (retStatus == SMS_NETWORK_SEND_SUCCESS)?"Success":"Fail");
+
+       if (retStatus == SMS_NETWORK_SEND_SUCCESS)
+       {
+               MSG_DEBUG("########  Msg Sent was Successful !!! #######");
+       }
+       else
+       {
+               if (retStatus == SMS_NETWORK_SEND_FAIL_TIMEOUT)
+                       SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
+
+               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 if(retStatus == SMS_NETWORK_SEND_PENDING) {
+                       MsgInsertTicker("Unable to send message. It will be sent when service available.", SMS_MESSAGE_SENDING_PENDING, true, 0);
+               }else {
+                       MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL, true, pReqInfo->msgInfo.msgId);
+               }
+       }
+
+_RETURN_FUNC :
+       if (msisdn) {
+               free(msisdn);
+               msisdn = NULL;
+       }
+
+       MSG_END();
+
+       return;
+}
+
+void SmsPluginTransport::sendDeliverReport(msg_error_t err, sms_trans_p2p_msg_s *p_p2p_msg)
+{
+       MSG_BEGIN();
+
+       int tapiRet = TAPI_API_SUCCESS;
+       TelSmsResponse_t response;
+
+       sms_trans_msg_s  trans_msg;
+       memset(&trans_msg, 0x00, sizeof(sms_trans_msg_s));
+
+       trans_msg.type = (sms_trans_msg_type_t)SMS_TRANS_ACK_MSG;
+
+       if (p_p2p_msg)
+               memcpy(&(trans_msg.data.ack_msg.address), &(p_p2p_msg->address), sizeof(sms_trans_addr_s));
+
+       sms_trans_cause_code_s  cause_code;
+       memset(&cause_code, 0x00, sizeof(sms_trans_cause_code_s));
+
+       if (p_p2p_msg->reply_seq > 0)
+               cause_code.reply_seq = p_p2p_msg->reply_seq;
+
+
+       if (err == MSG_SUCCESS)
+       {
+               cause_code.error_class = SMS_TRANS_ERR_CLASS_NONE;
+
+               response = TAPI_NETTEXT_SENDSMS_SUCCESS;
+
+               if(isMemAvailable == false)
+               {
+                       tapiRet = tel_set_sms_memory_status(pTapiHandle, 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_MESSAGE_COUNT_FULL) {
+
+               cause_code.error_class = SMS_TRANS_ERR_CLASS_TEMPORARY;
+
+               response = TAPI_NETTEXT_ME_FULL;
+//             MsgInsertTicker("Not enough memory. Delete some items.", SMS_MESSAGE_MEMORY_FULL, true, 0);
+
+               tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, 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_UNKNOWN) {
+               cause_code.error_class = SMS_TRANS_ERR_CLASS_TEMPORARY;
+               cause_code.cause_code = SMS_CAUSE_CODE_SERVICE_TERMINATION_DENIED;
+
+               response = TAPI_NETTEXT_SENDSMS_SUCCESS;
+
+       } else if (err == MSG_ERR_INVALID_MSG_TYPE) {
+               cause_code.error_class = SMS_TRANS_ERR_CLASS_PERMANENT;
+               cause_code.cause_code = SMS_CAUSE_CODE_INVAILD_TELESERVICE_ID;
+
+               response = TAPI_NETTEXT_INVALID_MSG;
+       }
+       else
+       {
+               cause_code.error_class = SMS_TRANS_ERR_CLASS_TEMPORARY;
+               response = TAPI_NETTEXT_SIM_FULL;
+
+       }
+
+       memcpy(&(trans_msg.data.ack_msg.cause_code), &(cause_code), sizeof(sms_trans_cause_code_s));
+
+       MSG_DEBUG("err : [%d], response : [%02x]", err, response);
+
+       int bufLen = 0;
+
+       unsigned char buf[512];
+       memset(buf, 0x00, sizeof(buf));
+       bufLen = SmsPluginMsgCodec::encodeMsg(&trans_msg, buf);
+
+
+       MSG_DEBUG("######## DeliverReport tpdu #########");
+       for(int i=0; i < bufLen; i++)
+       {
+               printf("[%02x] ", buf[i]);
+       }
+       MSG_DEBUG("#################################");
+
+       // Make Telephony Structure
+       TelSmsDatapackageInfo_t pkgInfo;
+
+       pkgInfo.format = TAPI_NETTEXT_NETTYPE_3GPP2;
+
+       // Set TPDU data
+       memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData));
+       memcpy((void*)pkgInfo.szData, buf, bufLen);
+
+       pkgInfo.szData[bufLen] = 0;
+       pkgInfo.MsgLength = bufLen;
+
+
+       // Send Deliver Report
+       tapiRet = tel_send_sms_deliver_report(pTapiHandle, &pkgInfo, response, TapiEventDeliveryReportCNF, NULL);
+
+       if (tapiRet == TAPI_API_SUCCESS)
+       {
+               MSG_DEBUG("########  tel_send_sms_deliver_report() Success !!! #######");
+       }
+       else
+       {
+               MSG_DEBUG("########  tel_send_sms_deliver_report() Fail !!! return : [%d] #######", tapiRet);
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginTransport::setNetStatus(sms_network_status_t sentStatus)
+{
+       mx.lock();
+       curStatus = sentStatus;
+       cv.signal();
+       mx.unlock();
+}
+
+
+sms_network_status_t SmsPluginTransport::getNetStatus()
+{
+       mx.lock();
+
+       int ret = 0;
+
+       if (curStatus == SMS_NETWORK_SENDING)
+               ret = cv.timedwait(mx.pMutex(), 125);
+
+       mx.unlock();
+
+       if (ret == ETIMEDOUT)
+       {
+               MSG_DEBUG("WARNING: SENT STATUS TIME-OUT");
+               curStatus = SMS_NETWORK_SEND_FAIL_TIMEOUT;
+       }
+
+       return curStatus;
+}
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginUAManager.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginUAManager.cpp
new file mode 100755 (executable)
index 0000000..1518cba
--- /dev/null
@@ -0,0 +1,106 @@
+
+/*
+* 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 "MsgException.h"
+#include "MsgCppTypes.h"
+#include "SmsCdmaPluginUAManager.h"
+#include "SmsCdmaPluginTransport.h"
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF SmsPluginUAManager - Member Functions
+==================================================================================================*/
+SmsPluginUAManager* SmsPluginUAManager::pInstance = NULL;
+
+
+SmsPluginUAManager::SmsPluginUAManager() : mx(), cv()
+{
+       start();
+}
+
+
+SmsPluginUAManager::~SmsPluginUAManager()
+{
+
+}
+
+
+SmsPluginUAManager* SmsPluginUAManager::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginUAManager();
+
+       return pInstance;
+}
+
+
+void SmsPluginUAManager::run()
+{
+       while (1)
+       {
+               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
+               {
+                       SmsPluginTransport::instance()->submitRequest(&request);
+               }
+               catch (MsgException& e)
+               {
+                       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();
+       }
+}
+
+
+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();
+}
+
diff --git a/plugin/sms_cdma_plugin/SmsCdmaPluginWapPushHandler.cpp b/plugin/sms_cdma_plugin/SmsCdmaPluginWapPushHandler.cpp
new file mode 100755 (executable)
index 0000000..4a1524a
--- /dev/null
@@ -0,0 +1,3460 @@
+/*
+* 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 "MsgCppTypes.h"
+#include "MsgGconfWrapper.h"
+#include "MsgException.h"
+#include "MsgUtilFile.h"
+#include "SmsCdmaPluginStorage.h"
+#include "SmsCdmaPluginTransport.h"
+#include "SmsCdmaPluginEventHandler.h"
+#include "SmsCdmaPluginWapPushHandler.h"
+
+#include <glib.h>
+#include <gio/gio.h>
+#if MSG_DRM_SUPPORT
+#include <drm_client.h>
+#endif
+
+static unsigned short wapPushPortList [] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
+
+char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
+char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
+
+const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000};
+
+const unsigned char wspHeaderFieldCount  = 0x43;
+const unsigned char wspContentsTypeCount = 0x34;
+const unsigned long wspLanguageCount    = 0x11a;
+const unsigned char wspSecurityTypeCount = 0x04;
+
+
+static const SMS_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] =
+{
+       { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
+       { (char*)"application/vnd.wap.connectivity-wbxml", 0x36 },
+       { (char*)"application/pkcs7-mime",  0x37 },
+       { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
+       { (char*)"application/vnd.wap.signed-certificate", 0x39  },
+       { (char*)"application/vnd.wap.cert-response", 0x3A },
+       { (char*)"application/xhtml+xml", 0x3B },
+       { (char*)"application/wml+xml", 0x3C  },
+       { (char*)"text/css", 0x3D },
+
+       { (char*)"application/vnd.wap.mms-message", 0x3E },
+
+       { (char*)"application/vnd.wap.rollover-certificate", 0x3F  },
+       { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
+       { (char*)"application/vnd.wap.loc+xml", 0x41 },
+       { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
+       { (char*)"application/vnd.syncml.dm+xml", 0x43 },
+       { (char*)"application/vnd.syncml.notification", 0x44 },
+       { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
+       { (char*)"application/vnd.wv.csp.cir", 0x46 },
+
+       { (char*)"application/vnd.oma.dd+xml", 0x47},
+       { (char*)"application/vnd.oma.drm.message", 0x48 },
+       { (char*)"application/vnd.oma.drm.content", 0x49 },
+       { (char*)"application/vnd.oma.drm.rights+xml", 0x4A },
+       { (char*)"application/vnd.oma.drm.rights+wbxml", 0x4B },
+       { (char*)"application/vnd.syncml.ds.notification", 0x4E},
+       { (char*)"application/mikey", 0x52},
+       { (char*)"", 0xff }
+};
+
+
+const char* wspHeaderFieldName[] =
+{
+       (char*)"Accept",  //0x00
+       (char*)"Accept-Charset",
+       (char*)"Accept-Encoding",
+       (char*)"Accept-Language",
+       (char*)"Accept-Ranges",
+       (char*)"Age", //0x05
+       (char*)"Allow",
+       (char*)"Authorization",
+       (char*)"Cache-Control",
+       (char*)"Connection",
+       (char*)"Content-Base", //0x0a
+       (char*)"Content-Encoding",
+       (char*)"Content-Language",
+       (char*)"Content-Length",
+       (char*)"Content-Location",
+       (char*)"Content-MD5",
+       (char*)"Content-Range", //0x10
+       (char*)"Content-Type",
+       (char*)"Date",
+       (char*)"ETag",
+       (char*)"Expires",
+       (char*)"From", //0x15
+       (char*)"Host",
+       (char*)"If-Modified-Since",
+       (char*)"If-Match",
+       (char*)"If-None-Match",
+       (char*)"If-Range", //0x1a
+       (char*)"If-Unmodified-Since",
+       (char*)"Location",
+       (char*)"Last-Modified",
+       (char*)"Max-Forwards",
+       (char*)"Pragma",
+       (char*)"Proxy-Authenticate", //0x20
+       (char*)"Proxy-Authorization",
+       (char*)"Public",
+       (char*)"Range",
+       (char*)"Referer",
+       (char*)"Retry-After", //0x25
+       (char*)"Server",
+       (char*)"Transfer-Encodig",
+       (char*)"Upgrade",
+       (char*)"User-Agent",
+       (char*)"Vary", //0x2a
+       (char*)"Via",
+       (char*)"Warning",
+       (char*)"Www-Authenticate",
+       (char*)"Content-Disposition",
+       (char*)"X-Wap-Application-Id",
+       (char*)"X-Wap-Content-URI", //0x30
+       (char*)"X-Wap-Iinitiator-URI",
+       (char*)"Accept-Application", // Back
+       (char*)"Bearer-Indication",
+       (char*)"Push-Flag",
+       (char*)"Profile", //0x35
+       (char*)"Profile-Diff",
+       (char*)"Profile-Warning", // end of WAP 1.2
+       (char*)"Expect",
+       (char*)"Te",
+       (char*)"Trailer", //0x3a
+       (char*)"Accept-Charset", //Back
+       (char*)"Accept-Encoding", // Back
+       (char*)"Cache-Control", // back
+       (char*)"Content-Range",
+       (char*)"X-Wap-Tod",
+       (char*)"Content-ID", //x40
+       (char*)"Set-Cookie",
+       (char*)"Cookie",
+       (char*)"Encoding-Version"
+};
+
+
+const SMS_WSP_CHARSET_S wspCharset[] =
+{
+       { (char*)"big5", 0x07ea },
+       { (char*)"iso-10646-ucs-2", 0x03e8 },
+       { (char*)"iso-8859-1", 0x04 },
+       { (char*)"iso-8859-2", 0x05 },
+       { (char*)"iso-8859-3", 0x06 },
+       { (char*)"iso-8859-4", 0x07 },
+       { (char*)"iso-8859-5", 0x08 },
+       { (char*)"iso-8859-6", 0x09 },
+       { (char*)"iso-8859-7", 0x0a },
+       { (char*)"iso-8859-8", 0x0b },
+       { (char*)"iso-8859-9", 0x0c },
+       { (char*)"shift-JIS", 0x11 },
+       { (char*)"us-ascii", 0x03 },
+       { (char*)"utf-8", 0x6a },
+       { (char*)"none", 0x26 },
+       { (char*)"", 0xffff }
+};
+
+
+
+const char* wspEncodeMethod[] =
+{
+       (char*)"Gzip",
+       (char*)"Compress",
+       (char*)"Deflate"
+};
+
+
+const SMS_WSP_CONTENTS_TYPE_S wspContentsType[] =
+{
+       { (char*)"*/*", 0x00 },
+       { (char*)"text/*", 0x01 },
+       { (char*)"text/html", 0x02 },
+       { (char*)"text/plain", 0x03 },
+       { (char*)"text/x-hdml", 0x04 },
+       { (char*)"text/x-ttml", 0x05 },
+       { (char*)"text/x-vCalendar", 0x06 },
+       { (char*)"text/x-vCard", 0x07 },
+       { (char*)"text/vnd.wap.wml", 0x08 },
+       { (char*)"text/vnd.wap.wmlscript", 0x09 },
+       { (char*)"text/vnd.wap.wta-event", 0x0a },
+       { (char*)"multipart/*", 0x0b },
+       { (char*)"multipart/mixed", 0x0c },
+       { (char*)"multipart/form-data", 0x0d },
+       { (char*)"multipart/byteranges", 0x0e },
+       { (char*)"multipart/alternative", 0x0f },
+       { (char*)"application/*", 0x10 },
+       { (char*)"application/java-vm", 0x11 },
+       { (char*)"application/x-www-form-urlencoded", 0x12 },
+       { (char*)"application/x-hdmlc", 0x13 },
+       { (char*)"application/vnd.wap.wmlc", 0x14 },
+       { (char*)"application/vnd.wap.wmlscriptc", 0x15 },
+       { (char*)"application/vnd.wap.wta-eventc", 0x16 },
+       { (char*)"application/vnd.wap.uaprof", 0x17 },
+       { (char*)"application/vnd.wap.wtls-ca-certificate", 0x18 },
+       { (char*)"application/vnd.wap.wtls-user-certificate", 0x19 },
+       { (char*)"application/x-x509-ca-cert", 0x1a },
+       { (char*)"application/x-x509-user-cert", 0x1b },
+       { (char*)"image/*", 0x1c },
+       { (char*)"image/gif", 0x1d },
+       { (char*)"image/jpeg", 0x1e },
+       { (char*)"image/tiff", 0x1f },
+       { (char*)"image/png", 0x20 },
+       { (char*)"image/vnd.wap.wbmp", 0x21 },
+       { (char*)"application/vnd.wap.multipart.*", 0x22 },
+       { (char*)"application/vnd.wap.multipart.mixed", 0x23 },
+       { (char*)"application/vnd.wap.multipart.form-data", 0x24 },
+       { (char*)"application/vnd.wap.multipart.byteranges", 0x25 },
+       { (char*)"application/vnd.wap.multipart.alternative", 0x26 },
+       { (char*)"application/xml", 0x27 },
+       { (char*)"text/xml",0x28 },
+       { (char*)"application/vnd.wap.wbxml", 0x29 },
+       { (char*)"application/x-x968-cross-cert", 0x2a },
+       { (char*)"application/x-x968-ca-cert", 0x2b },
+       { (char*)"application/x-x968-user-cert", 0x2c },
+       { (char*)"text/vnd.wap.si", 0x2d },
+       { (char*)"application/vnd.wap.sic", 0x2e },
+       { (char*)"text/vnd.wap.sl", 0x2f },
+       { (char*)"application/vnd.wap.slc", 0x30 },
+       { (char*)"text/vnd.wap.co", 0x31 },
+       { (char*)"application/vnd.wap.coc", 0x32 },
+       { (char*)"application/vnd.wap.multipart.related", 0x33 },
+       { (char*)"application/vnd.wap.sia", 0x34 },
+
+       { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
+       { (char*)"application/vnd.connectivity-wbxml", 0x36 },
+       { (char*)"application/pkcs7-mime",  0x37 },
+       { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
+       { (char*)"application/vnd.wap.signed-certificate", 0x39  },
+       { (char*)"application/vnd.wap.cert-response", 0x3A },
+       { (char*)"application/xhtml+xml", 0x3B },
+       { (char*)"application/wml+xml", 0x3C  },
+       { (char*)"text/css", 0x3D },
+
+       { (char*)"application/vnd.wap.mms-message", 0x3E },
+
+       { (char*)"application/vnd.wap.rollover-certificate", 0x3F  },
+       { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
+       { (char*)"application/vnd.wap.loc+xml", 0x41 },
+       { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
+       { (char*)"application/vnd.syncml.dm+xml", 0x43 },
+       { (char*)"application/vnd.syncml.notification", 0x44 },
+       { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
+       { (char*)"application/vnd.wv.csp.cir", 0x46 }
+};
+
+static const SMS_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]=
+{
+       { (char*)"application/vnd.wap.emn+wbxml", 0x30A},
+       { (char*)"application/vnd.omaloc-supl-init", 0x312},
+       { (char*)"application/vnd.oma.drm.roap-trigger+wbxml", 0x316}
+};
+
+const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_WAP_UNREGISTER_CONTENTS_TYPE_S);
+
+const SMS_WSP_LANGUAGE_S wspLanguage[] =
+{
+       { (char*)"English", 0x19 },
+       { (char*)"en", 0x19 },
+       { (char*)"Korean", 0x3d },
+       { (char*)"*", 0x00 },
+       { (char*)"Afar", 0x01 },
+       { (char*)"aa", 0x01 },
+       { (char*)"Abkhazian", 0x02 },
+       { (char*)"ab", 0x02 },
+       { (char*)"Afrikaans", 0x03 },
+       { (char*)"af", 0x03 },
+       { (char*)"Amharic", 0x04 },
+       { (char*)"am", 0x04 },
+       { (char*)"Arabic", 0x05 },
+       { (char*)"ar", 0x05 },
+       { (char*)"Assamese", 0x06 },
+       { (char*)"as", 0x06 },
+       { (char*)"Aymara", 0x07 },
+       { (char*)"ay", 0x07 },
+       { (char*)"Azerbaijani", 0x08 },
+       { (char*)"az", 0x08 },
+       { (char*)"Bashkir", 0x09 },
+       { (char*)"ba", 0x09 },
+       { (char*)"Byelorussian", 0x0a },
+       { (char*)"be", 0x0a },
+       { (char*)"Bulgarian", 0x0b },
+       { (char*)"bg", 0x0b },
+       { (char*)"Bihari", 0x0c },
+       { (char*)"bh", 0x0c },
+       { (char*)"Bislama", 0x0d },
+       { (char*)"bi", 0x0f },
+       { (char*)"Bengali", 0x0e },
+       { (char*)"Bangla", 0x0e },
+       { (char*)"bn", 0x0e },
+       { (char*)"Tibetan", 0x0f },
+       { (char*)"bo", 0x0f },
+       { (char*)"Breton", 0x10 },
+       { (char*)"br", 0x10 },
+       { (char*)"Catalan", 0x11 },
+       { (char*)"ca", 0x11 },
+       { (char*)"Corsican", 0x12 },
+       { (char*)"co", 0x12 },
+       { (char*)"Czech", 0x13 },
+       { (char*)"cs", 0x13 },
+       { (char*)"Welsh", 0x14 },
+       { (char*)"cy", 0x14 },
+       { (char*)"Denish", 0x15 },
+       { (char*)"da", 0x15 },
+       { (char*)"German", 0x16 },
+       { (char*)"de", 0x16 },
+       { (char*)"Bhutani", 0x17 },
+       { (char*)"dz", 0x17 },
+       { (char*)"Greek", 0x18 },
+       { (char*)"el", 0x18 },
+       { (char*)"Esperanto", 0x81 },
+       { (char*)"eo", 0x1a },
+       { (char*)"Spanish", 0x1b },
+       { (char*)"es", 0x1b },
+       { (char*)"Estonian", 0x1c },
+       { (char*)"et", 0x1c },
+       { (char*)"Basque", 0x1d },
+       { (char*)"eu", 0x1d },
+       { (char*)"Persian", 0x1e },
+       { (char*)"fa", 0x1e },
+       { (char*)"Finnish", 0x1f },
+       { (char*)"fi", 0x1f },
+       { (char*)"Fiji", 0x20 },
+       { (char*)"fj", 0x20 },
+       { (char*)"Faeroese", 0x82 },
+       { (char*)"fo", 0x82 },
+       { (char*)"French", 0x22 },
+       { (char*)"fr", 0x22 },
+       { (char*)"Frisian", 0x83 },
+       { (char*)"fy", 0x83 },
+       { (char*)"Irish", 0x24 },
+       { (char*)"ga", 0x24 },
+       { (char*)"Scots Gaelic", 0x25 },
+       { (char*)"gd", 0x25 },
+       { (char*)"Galician", 0x26 },
+       { (char*)"gl", 0x26 },
+       { (char*)"Guarani", 0x27 },
+       { (char*)"gn", 0x27 },
+       { (char*)"Gujarati", 0x28 },
+       { (char*)"gu", 0x28 },
+       { (char*)"Hausa", 0x29 },
+       { (char*)"ha", 0x29 },
+       { (char*)"Hebrew", 0x2a },
+       { (char*)"he", 0x2a },
+       { (char*)"Hindi", 0x2b },
+       { (char*)"hi", 0x2b },
+       { (char*)"Croatian", 0x2c },
+       { (char*)"hr", 0x2c },
+       { (char*)"Hungarian", 0x2d },
+       { (char*)"hu", 0x2d },
+       { (char*)"Armenian", 0x2e },
+       { (char*)"hy", 0x2e },
+       { (char*)"Interlingua", 0x84 },
+       { (char*)"ia", 0x84 },
+       { (char*)"Indonesian", 0x30 },
+       { (char*)"id", 0x30 },
+       { (char*)"Interlingue", 0x86 },
+       { (char*)"ie", 0x86 },
+       { (char*)"Maori", 0x47 },
+       { (char*)"mi", 0x47 },
+       { (char*)"Macedonian", 0x48 },
+       { (char*)"mk", 0x48 },
+       { (char*)"Malayalam", 0x49 },
+       { (char*)"ml", 0x49 },
+       { (char*)"Mongolian", 0x4a },
+       { (char*)"mn", 0x4a },
+       { (char*)"Moldavian", 0x4b },
+       { (char*)"mo", 0x4d },
+       { (char*)"Marathi", 0x4c },
+       { (char*)"mr", 0x4c },
+       { (char*)"Malay", 0x4d },
+       { (char*)"ms", 0x4d },
+       { (char*)"Maltese", 0x4e },
+       { (char*)"mt", 0x4e },
+       { (char*)"Burmese", 0x4f },
+       { (char*)"my", 0x4f },
+       { (char*)"Nauru", 0x50 },
+       { (char*)"na", 0x50 },
+       { (char*)"Nepali", 0x51 },
+       { (char*)"ne", 0x51 },
+       { (char*)"Dutch", 0x52 },
+       { (char*)"nl", 0x52 },
+       { (char*)"Norwegian", 0x53 },
+       { (char*)"no", 0x53 },
+       { (char*)"Occitan", 0x54 },
+       { (char*)"oc", 0x54 },
+       { (char*)"(Afan) Oromo", 0x55 },
+       { (char*)"(Afan)Oromo", 0x55 },
+       { (char*)"om", 0x55 },
+       { (char*)"Oriya", 0x56 },
+       { (char*)"or", 0x56 },
+       { (char*)"Punjabi", 0x57 },
+       { (char*)"pa", 0x57 },
+       { (char*)"Polish", 0x58 },
+       { (char*)"po", 0x58 },
+       { (char*)"Pashto", 0x59 },
+       { (char*)"Pushto", 0x59 },
+       { (char*)"ps", 0x59 },
+       { (char*)"Portugurse", 0x5a },
+       { (char*)"pt", 0x5a },
+       { (char*)"Quechua", 0x5b },
+       { (char*)"qu", 0x5b },
+       { (char*)"Rhaeto-Romance", 0x8c },
+       { (char*)"rm", 0x8c },
+       { (char*)"Kirundi", 0x5d },
+       { (char*)"rn", 0x5d },
+       { (char*)"Romanian", 0x5e },
+       { (char*)"ro", 0x5e },
+       { (char*)"Russian", 0x5f },
+       { (char*)"ru", 0x5f },
+       { (char*)"Kinyarwanda", 0x60 },
+       { (char*)"rw", 0x60 },
+       { (char*)"Sanskrit", 0x61 },
+       { (char*)"sa", 0x61 },
+       { (char*)"Sindhi", 0x62 },
+       { (char*)"sd", 0x62 },
+       { (char*)"Sangho", 0x63 },
+       { (char*)"sg", 0x63 },
+       { (char*)"Serbo-Croatian", 0x64 },
+       { (char*)"sh", 0x64 },
+       { (char*)"Sinhalese", 0x65 },
+       { (char*)"si", 0x65 },
+       { (char*)"Slovak", 0x66 },
+       { (char*)"sk", 0x66 },
+       { (char*)"Slovenian", 0x67 },
+       { (char*)"sl", 0x67 },
+       { (char*)"Samoan", 0x68 },
+       { (char*)"sm", 0x68 },
+       { (char*)"Shona", 0x69 },
+       { (char*)"sn", 0x69 },
+       { (char*)"Somali", 0x6a },
+       { (char*)"so", 0x6a },
+       { (char*)"Albanian", 0x6b },
+       { (char*)"sq", 0x6b },
+       { (char*)"Serbian", 0x6c },
+       { (char*)"sr", 0x6c },
+       { (char*)"Siswati", 0x6d },
+       { (char*)"ss", 0x6d },
+       { (char*)"Sesotho", 0x6e },
+       { (char*)"st", 0x6e },
+       { (char*)"Sundanese", 0x6f },
+       { (char*)"su", 0x6f },
+       { (char*)"Swedish", 0x70 },
+       { (char*)"sv", 0x70 },
+       { (char*)"Swahili", 0x71 },
+       { (char*)"sw", 0x71 },
+       { (char*)"Tamil", 0x72 },
+       { (char*)"ta", 0x72 },
+       { (char*)"Telugu", 0x73 },
+       { (char*)"te", 0x73 },
+       { (char*)"Tajik", 0x74 },
+       { (char*)"tg", 0x74 },
+       { (char*)"Thai", 0x75 },
+       { (char*)"th", 0x75 },
+       { (char*)"Tigrinya", 0x76 },
+       { (char*)"ti", 0x76 },
+       { (char*)"Turkmen", 0x77 },
+       { (char*)"tk", 0x77 },
+       { (char*)"Inupiak", 0x87 },
+       { (char*)"ik", 0x87 },
+       { (char*)"Icelandic", 0x33 },
+       { (char*)"is", 0x33 },
+       { (char*)"Italian", 0x34 },
+       { (char*)"it", 0x34 },
+       { (char*)"Inuktitut", 0x89 },
+       { (char*)"iu", 0x89 },
+       { (char*)"Japanese", 0x36 },
+       { (char*)"ja", 0x36 },
+       { (char*)"Javanese", 0x37 },
+       { (char*)"jw", 0x37 },
+       { (char*)"Georgian", 0x38 },
+       { (char*)"ka", 0x38 },
+       { (char*)"Kazakh", 0x39 },
+       { (char*)"kk", 0x39 },
+       { (char*)"Gerrnlandic", 0x8a },
+       { (char*)"kl", 0x8a },
+       { (char*)"Cambodian", 0x3b },
+       { (char*)"km", 0x3b },
+       { (char*)"Kannada", 0x3c },
+       { (char*)"kn", 0x3c },
+       { (char*)"Kashmiri", 0x3e },
+       { (char*)"ks", 0x3e },
+       { (char*)"Kurdish", 0x3f },
+       { (char*)"ku", 0x3f },
+       { (char*)"Kirghiz", 0x40 },
+       { (char*)"ky", 0x40 },
+       { (char*)"Latin", 0x8b },
+       { (char*)"la", 0x8b },
+       { (char*)"Lingala", 0x42 },
+       { (char*)"ln", 0x42 },
+       { (char*)"Laothian", 0x43 },
+       { (char*)"lo", 0x43 },
+       { (char*)"Lithuanian", 0x44 },
+       { (char*)"lt", 0x44 },
+       { (char*)"Lavian", 0x45 },
+       { (char*)"Lettish", 0x45 },
+       { (char*)"lv", 0x45 },
+       { (char*)"Malagasy", 0x46 },
+       { (char*)"mg", 0x46 },
+       { (char*)"Tagalog", 0x78 },
+       { (char*)"tl", 0x78 },
+       { (char*)"Setswana", 0x79 },
+       { (char*)"tn", 0x79 },
+       { (char*)"Tonga", 0x7a },
+       { (char*)"to", 0x7a },
+       { (char*)"Turkish", 0x7b },
+       { (char*)"tr", 0x7b },
+       { (char*)"Tsonga", 0x7c },
+       { (char*)"ts", 0x7c },
+       { (char*)"Tatar", 0x7d },
+       { (char*)"tt", 0x7d },
+       { (char*)"Twi", 0x7e },
+       { (char*)"tw", 0x7e },
+       { (char*)"Uighur", 0x7f },
+       { (char*)"ug", 0x7f },
+       { (char*)"Ukrainian", 0x1a },
+       { (char*)"uk", 0x1a },
+       { (char*)"Urdu", 0x21 },
+       { (char*)"ur", 0x21 },
+       { (char*)"Uzbek", 0x23 },
+       { (char*)"uz", 0x23 },
+       { (char*)"Vietnamese", 0x2f },
+       { (char*)"vi", 0x2f },
+       { (char*)"Volapuk", 0x85 },
+       { (char*)"vo", 0x85 },
+       { (char*)"Wolof", 0x31 },
+       { (char*)"wo" , 0x31 },
+       { (char*)"Xhosa", 0x32 },
+       { (char*)"xh", 0x32 },
+       { (char*)"Yiddish", 0x88 },
+       { (char*)"yi", 0x88 },
+       { (char*)"Yoruba", 0x35 },
+       { (char*)"yo", 0x35 },
+       { (char*)"Zhuang", 0x3a },
+       { (char*)"z", 0x3a },
+       { (char*)"Chinese", 0x41 },
+       { (char*)"ch", 0x41 },
+       { (char*)"Zulu", 0x5c },
+       { (char*)"zu", 0x5c },
+       { (char*)"Ko", 0x3d }
+};
+
+
+const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] =
+{
+       { (char*)"x-wap-application:*",  0x00 },
+       { (char*)"x-wap-application:push.sia",  0x01},
+       { (char*)"x-wap-application:wml.ua",  0x02 },
+       { (char*)"x-wap-application:wta.ua", 0x03 },
+       { (char*)"x-wap-application:mms.ua", 0x04 },
+       { (char*)"x-wap-application:push.syncml", 0x05 },
+       { (char*)"x-wap-application:loc.ua",  0x06 },
+       { (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 ", 0x90 },
+       { (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 },
+};
+
+
+const char* wspCacheControl[] =
+{
+       (char*)"No-cache",
+       (char*)"No-store",
+       (char*)"Max-age",
+       (char*)"Max-stale",
+       (char*)"Min-fresh",
+       (char*)"Only-if-cached",
+       (char*)"Public",
+       (char*)"Private",
+       (char*)"No-transform",
+       (char*)"Must-revalidate",
+       (char*)"Proxy-revalidate"
+};
+
+const SMS_WSP_METHOD_TYPE_S wspMethodType[] =
+{
+       { (char*)"GET", 0x40 },
+       { (char*)"OPTIONS", 0x41 },
+       { (char*)"HEAD", 0x42 },
+       { (char*)"DELETE", 0x43 },
+       { (char*)"TRACE", 0x44 },
+       { (char*)"POST", 0x60 },
+       { (char*)"PUT", 0x61 }
+};
+
+
+const SMS_WSP_SECURITY_TYPE_S wspSecurityType[] =
+{
+       {(char*)"NETWPIN",0x00},
+       {(char*)"USERPIN",0x01},
+       {(char*)"USERNETWPIN",0x02},
+       {(char*)"USERPINMAC",0x03}
+};
+
+
+
+const char* wspWeek[] =
+{
+       (char*)"Sun",
+       (char*)"Mon",
+       (char*)"Tue",
+       (char*)"Wed",
+       (char*)"Thu",
+       (char*)"Fri",
+       (char*)"Sat"
+};
+
+
+const char* wspWeekDay[] =
+{
+       (char*)"Sunday",
+       (char*)"Monday",
+       (char*)"Tuesday",
+       (char*)"Wednesday",
+       (char*)"Thursday",
+       (char*)"Friday",
+       (char*)"Saturday"
+};
+
+const char* wspMonth[] =
+{
+       (char*)"Jan",
+       (char*)"Feb",
+       (char*)"Mar",
+       (char*)"Apr",
+       (char*)"May",
+       (char*)"Jun",
+       (char*)"Jul",
+       (char*)"Aug",
+       (char*)"Sep",
+       (char*)"Oct",
+       (char*)"Nov",
+       (char*)"Dec"
+};
+
+
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF SmsPluginWapPushHandler - Member Functions
+==================================================================================================*/
+SmsPluginWapPushHandler* SmsPluginWapPushHandler::pInstance = NULL;
+
+
+SmsPluginWapPushHandler::SmsPluginWapPushHandler()
+{
+       memset(&tmpAddress, 0x00, sizeof(tmpAddress));
+}
+
+
+SmsPluginWapPushHandler::~SmsPluginWapPushHandler()
+{
+
+}
+
+
+SmsPluginWapPushHandler* SmsPluginWapPushHandler::instance()
+{
+       if (!pInstance)
+               pInstance = new SmsPluginWapPushHandler();
+
+       return pInstance;
+}
+
+bool SmsPluginWapPushHandler::IsWapPushMsg(unsigned short dstport)
+{
+       MSG_BEGIN();
+
+       int PortCount = sizeof(wapPushPortList)/sizeof(wapPushPortList[0]);
+
+       MSG_DEBUG("Port Count [%d]", PortCount);
+
+       for (int i = 0; i < PortCount; i++) {
+               if (dstport == wapPushPortList[i]) {
+                       MSG_DEBUG("Wap Push Msg : [%04x]", wapPushPortList[i]);
+                       return true;
+               }
+       }
+
+       MSG_END();
+
+       return false;
+}
+
+#if 0
+sms_wap_app_code_t SmsPluginWapPushHandler::getAppCode(const char *pPushHeader)
+{
+       int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
+
+       unsigned char *header = NULL;
+       SMS_WAP_APP_CODE_T      appCode = SMS_WAP_APPLICATION_DEFAULT;
+
+       MSG_DEBUG("Application Count [%d]", appCount);
+
+       for (int i = 0; i < appCount; i++) {
+
+               header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
+
+               if (header != NULL) {
+                       appCode = pushDefaultApplication[i].appCode;
+                       break;
+               }
+       }
+
+       if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
+               MSG_DEBUG("Application Type is not supported");
+       } else {
+               MSG_DEBUG("Find Application [%d]", appCode);
+       }
+
+       return appCode;
+}
+#endif
+
+
+void SmsPluginWapPushHandler::copyDeliverData(sms_trans_addr_s *pAddr)
+{
+       memcpy(&tmpAddress, pAddr, sizeof(tmpAddress));
+
+       MSG_SEC_DEBUG("Address [%s]", tmpAddress.szData);
+
+/*
+       tmpTimeStamp.format = pDeliver->timeStamp.format;
+
+       if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
+               tmpTimeStamp.time.absolute.year = pDeliver->timeStamp.time.absolute.year;
+               tmpTimeStamp.time.absolute.month = pDeliver->timeStamp.time.absolute.month;
+               tmpTimeStamp.time.absolute.day = pDeliver->timeStamp.time.absolute.day;
+               tmpTimeStamp.time.absolute.hour = pDeliver->timeStamp.time.absolute.hour;
+               tmpTimeStamp.time.absolute.minute = pDeliver->timeStamp.time.absolute.minute;
+               tmpTimeStamp.time.absolute.second = pDeliver->timeStamp.time.absolute.second;
+               tmpTimeStamp.time.absolute.timeZone = pDeliver->timeStamp.time.absolute.timeZone;
+       }
+*/
+}
+
+
+void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize)
+{
+       MSG_BEGIN();
+
+#ifdef MSG_FW_FOR_DEBUG
+       MSG_DEBUG("DataSize [%d]", DataSize);
+
+       MSG_DEBUG("[pUserData]");
+       for (int i = 0; i < DataSize; i++)
+       {
+               printf("[%02x]", pUserData[i]);
+       }
+       printf("\n\n");
+#endif
+
+       unsigned char* pPDUTypeData = (unsigned char*)pUserData;
+       unsigned long PDUTypeDataLen = DataSize;
+
+       char* pPushHeader = NULL;
+       AutoPtr<char> pushHeaderBuf(&pPushHeader);
+       unsigned long pushHeaderLen = 0;
+
+       char* pPushBody = NULL;
+       AutoPtr<char> PushBodyBuf(&pPushBody);
+       unsigned long pushBodyLen = 0;
+
+       unsigned long iPDU = 1;
+
+       char* pWspHeader = NULL;
+       AutoPtr<char> WspHeaderBuf(&pWspHeader);
+       unsigned long   wspHeaderLen = 0;
+
+       char* pWspBody = NULL;
+       AutoPtr<char> WspBodyBuf(&pWspBody);
+       unsigned long wspBodyLen = 0;
+
+       /** pass PDU type */
+       iPDU++;
+
+       pushHeaderLen = wspRetriveUintvarDecode( pPDUTypeData, &iPDU );
+
+       MSG_DEBUG("PDUTypeDataLen [%d]", PDUTypeDataLen);
+       MSG_DEBUG("pushHeaderLen [%d]", pushHeaderLen);
+       MSG_DEBUG("iPDU [%d]", iPDU);
+
+       wspHeaderLen = pushHeaderLen + iPDU;
+
+       MSG_DEBUG("wspBodyLen [%d]", wspBodyLen);
+
+       if (wspHeaderLen > 0) {
+
+               pWspHeader = new char[wspHeaderLen];
+
+               if (pWspHeader == NULL) {
+                       MSG_DEBUG("pWspHeader Memory Allocation Failed");
+                       return;
+               } else {
+                       memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
+               }
+       }
+
+#ifdef MSG_FW_FOR_DEBUG
+       MSG_DEBUG("wspHeaderLen [%d]", wspHeaderLen);
+
+       MSG_DEBUG("[pWspHeader]");
+       for (int i = 0; i < wspHeaderLen; i++)
+       {
+               printf("[%02x]", pWspHeader[i]);
+       }
+       printf("\n\n");
+#endif
+
+       /** return if it is below case error */
+       if (PDUTypeDataLen < wspHeaderLen) {
+               MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
+               return;
+       }
+
+       /** Finding wspBody Information */
+       wspBodyLen = PDUTypeDataLen - wspHeaderLen;
+
+       if (wspBodyLen > 0) {
+
+               pWspBody = new char[wspBodyLen];
+
+               if (pWspBody == NULL) {
+                       MSG_DEBUG("pWspBody Memory Allocation Failed");
+                       return;
+               } else {
+                       memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
+               }
+       } else {
+               pWspBody = NULL;
+       }
+
+       wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
+
+       iPDU = iPDU + pushHeaderLen;
+
+       pushBodyLen = PDUTypeDataLen - iPDU ;
+
+       if (pushBodyLen > 0) {
+               pPushBody = new char[pushBodyLen];
+
+               if (pPushBody == NULL)  {
+                       MSG_DEBUG("pPushBody Memory Allocation Failed");
+                       return;
+               } else {
+                       memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
+               }
+       } else {
+               pPushBody = NULL;
+               return;
+       }
+
+       handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen);
+
+       MSG_END();
+}
+
+#if 0
+void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
+{
+       MSG_BEGIN();
+
+       if (pPushBody == NULL) {
+               MSG_DEBUG("pPushBody is NULL");
+               return;
+       }
+
+       SMS_WAP_APP_CODE_T      appCode = getAppCode(pPushHeader);
+
+       /**  check Push message receive setting */
+       bool bPushRecv = false;
+
+       MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv);
+
+       if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
+               MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
+               return;
+       }
+
+       switch (appCode) {
+       case SMS_WAP_APPLICATION_MMS_UA:
+               MSG_DEBUG("Received MMS Notification");
+               handleMMSNotification(pPushBody, PushBodyLen);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_SI:
+               MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
+               handleSIMessage(pPushBody, PushBodyLen, true);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_SIC:
+               MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
+               handleSIMessage(pPushBody, PushBodyLen, false);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_SL:
+               MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
+               handleSLMessage(pPushBody, PushBodyLen, true);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_SLC:
+               MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
+               handleSLMessage(pPushBody, PushBodyLen, false);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_CO:
+               MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
+               handleCOMessage(pPushBody, PushBodyLen, true);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_COC:
+               MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
+               handleCOMessage(pPushBody, PushBodyLen, false);
+               break;
+
+       case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
+               MSG_DEBUG("Received DM BOOTSTRAP");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               break;
+
+       case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
+               MSG_DEBUG("Received DM BOOTSTRAP");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
+               MSG_DEBUG("Received Provisioning");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
+               MSG_DEBUG("Received Provisioning");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               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);
+               break;
+
+       case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
+               MSG_DEBUG("Received DM Notification");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               break;
+
+       case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
+               MSG_DEBUG("Received DS Notification");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               break;
+
+       case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
+               MSG_DEBUG("Received DS Notification");
+               SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+               break;
+
+       case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
+       case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
+               MSG_DEBUG("Received DRM UA");
+
+               if (pPushBody != NULL)
+                       handleDrmVer1(pPushBody, PushBodyLen);
+
+               break;
+
+       case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
+       case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
+       case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
+       case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
+               MSG_DEBUG("Received DRM V2");
+               // TODO: DRM V2
+               break;
+
+       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;
+
+       case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
+               MSG_DEBUG("Received IMPS CIR");
+               // TODO: IMPS CIR
+               break;
+
+       case SMS_WAP_APPLICATION_LBS :
+               MSG_DEBUG("Received LBS related message");
+               SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
+               // TODO: LBS
+               break;
+
+       case SMS_WAP_APPLICATION_PUSH_SIA :
+               MSG_DEBUG("Received SIA");
+               // TODO: SIA
+               break;
+
+       default:
+               MSG_DEBUG("Unknown Application [%d]", appCode);
+               break;
+       }
+
+       MSG_END();
+}
+#else
+
+static void launchProcessByAppcode(int appcode)
+{
+       MSG_BEGIN();
+       GError *error = NULL;
+       GDBusConnection *connection_agent = NULL;
+       GDBusProxy *dbus_proxy_agent = NULL;
+       GDBusConnection *connection_service = NULL;
+       GDBusProxy *dbus_proxy_service = NULL;
+       GVariant *result_agent = NULL;
+       GVariant *result_service = NULL;
+
+       switch(appcode){
+               case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
+               case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
+               case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
+               case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
+               case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
+               case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
+               case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
+                       {
+                               connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE,
+                                                                                       NULL, "org.tizen.omadmagent", "/org/tizen/omadmagent",
+                                                                                       "org.tizen.omadmagent", NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("invoking agent proxy call failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               connection_service = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               dbus_proxy_service =g_dbus_proxy_new_sync(connection_service, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                                                                       "org.tizen.omadmservice", "/org/tizen/omadmservice",
+                                                                                       "org.tizen.omadmservice", NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("Connecting to service proxy failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               result_service = g_dbus_proxy_call_sync(dbus_proxy_service, "wakeup", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("invoking service proxy call failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               Mutex mx;
+                               CndVar cv;
+                               mx.lock();
+                               cv.timedwait(mx.pMutex(), 2);
+                               mx.unlock();
+
+                               MSG_END();
+                       }
+                       break;
+               case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
+               case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
+                       {
+                               connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                                                                       "org.tizen.omadsagent", "/org/tizen/omadsagent",
+                                                                                       "org.tizen.omadsagent", NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+
+                               result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL,
+                                                                               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+                               if (error) {
+                                       MSG_DEBUG("invoking service error: %s\n", error->message);
+                                       goto _DBUS_ERROR;
+                               }
+                       }
+                       break;
+               default:
+                       break;
+       }
+
+_DBUS_ERROR:
+       if (error) {
+               g_error_free(error);
+               error = NULL;
+       }
+
+       if (connection_agent) {
+               g_object_unref(connection_agent);
+               connection_agent = NULL;
+       }
+
+       if (dbus_proxy_agent) {
+               g_object_unref(dbus_proxy_agent);
+               dbus_proxy_agent = NULL;
+       }
+
+       if (result_agent) {
+               g_object_unref(result_service);
+               result_service = NULL;
+       }
+
+       if (connection_service) {
+               g_object_unref(connection_service);
+               connection_service = NULL;
+       }
+
+       if (dbus_proxy_service) {
+               g_object_unref(dbus_proxy_service);
+               dbus_proxy_service = NULL;
+       }
+
+       if (result_service) {
+               g_object_unref(result_service);
+               result_service = NULL;
+       }
+
+       MSG_END();
+}
+
+
+void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
+{
+       MSG_BEGIN();
+
+       if (pPushBody == NULL) {
+               MSG_DEBUG("pPushBody is NULL");
+               return;
+       }
+
+       msg_error_t err = MSG_SUCCESS;
+       int pushEvt_cnt = 0;
+       char app_id[MAX_WAPPUSH_ID_LEN] = {0,};
+       char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN] = {0,};
+       SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
+
+       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");
+               return;
+       }
+
+       for(int i = 0; i < pushEvt_cnt; ++i)    {
+
+               /**  check Push message receive setting */
+               bool bPushRecv = false;
+               int appcode = 0;
+               MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv);
+
+               storageHandler->getnthPushEvent(i, &appcode);
+               MSG_DEBUG("pushEvt_cnt: %d, appcode: %d", pushEvt_cnt, appcode);
+               if ((bPushRecv == false) && (appcode != SMS_WAP_APPLICATION_MMS_UA)) {
+                       MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
+                       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);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_SI:
+                       MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
+//                     handleSIMessage(pPushBody, PushBodyLen, true);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_SIC:
+                       MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
+//                     handleSIMessage(pPushBody, PushBodyLen, false);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_SL:
+                       MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
+//                     handleSLMessage(pPushBody, PushBodyLen, true);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_SLC:
+                       MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
+//                     handleSLMessage(pPushBody, PushBodyLen, false);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_CO:
+                       MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
+//                     handleCOMessage(pPushBody, PushBodyLen, true);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_COC:
+                       MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
+//                     handleCOMessage(pPushBody, PushBodyLen, false);
+                       break;
+
+               case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
+                       MSG_DEBUG("Received DM BOOTSTRAP");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       break;
+
+               case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
+                       MSG_DEBUG("Received DM BOOTSTRAP");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
+                       MSG_DEBUG("Received Provisioning");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
+                       MSG_DEBUG("Received Provisioning");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       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);
+                       break;
+
+               case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
+                       MSG_DEBUG("Received DM Notification");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       break;
+
+               case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
+                       MSG_DEBUG("Received DS Notification");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       break;
+
+               case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
+                       MSG_DEBUG("Received DS Notification");
+                       SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
+                       break;
+
+               case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
+               case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
+                       MSG_DEBUG("Received DRM UA");
+
+                       if (pPushBody != NULL)
+                               handleDrmVer1(pPushBody, PushBodyLen);
+
+                       break;
+
+               case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
+               case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
+               case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
+               case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
+                       MSG_DEBUG("Received DRM V2");
+                       // TODO: DRM V2
+                       break;
+
+               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;
+
+
+               case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
+                       MSG_DEBUG("Received IMPS CIR");
+                       // TODO: IMPS CIR
+                       break;
+
+               case SMS_WAP_APPLICATION_LBS :
+                       MSG_DEBUG("Received LBS related message");
+                       SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
+                       // TODO: LBS
+                       break;
+
+               case SMS_WAP_APPLICATION_PUSH_SIA :
+                       MSG_DEBUG("Received SIA");
+                       // TODO: SIA
+                       break;
+
+               default:
+                       SmsPluginEventHandler::instance()->handlePushMsgIncoming(pPushHeader, pPushBody, PushBodyLen, app_id, content_type);
+                       break;
+               }
+       }
+       storageHandler->releasePushEvent();
+
+       MSG_END();
+}
+#endif
+
+void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen)
+{
+       MSG_BEGIN();
+
+#ifdef MSG_FW_FOR_DEBUG
+       printf("\n\n[handleMMSNotification] Push Body.\n");
+
+       for (int i = 0; i < PushBodyLen; i++)
+       {
+               printf(" [%02x]", pPushBody[i]);
+       }
+       printf("\n\n");
+#endif
+
+       /** Make MSG_MESSAGE_INFO_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);
+
+       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;
+
+       if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
+               msgInfo.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 error");
+               }
+
+               if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false) {
+                       THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
+               }
+
+               strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
+       } else {
+               msgInfo.bTextSms = true;
+
+               memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
+               msgInfo.msgText[msgInfo.dataSize] = '\0';
+       }
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Add MMS Noti Msg into DB */
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+
+       if (err == MSG_SUCCESS) {
+               /**  Callback */
+               err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
+
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
+               }
+       } else {
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
+       }
+
+       MSG_END();
+}
+
+void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText)
+{
+       MSG_BEGIN();
+
+       MSG_PUSH_MESSAGE_S pushMsg = {};
+
+       xmlDocPtr       xmlDoc = NULL;
+       xmlNodePtr      topNode = NULL;
+       xmlNodePtr      indNode = NULL;
+
+       xmlChar*                tmpXmlChar = NULL;
+
+       if (pPushBody == NULL) {
+               MSG_DEBUG("pPushBody is NULL");
+               return;
+       }
+
+       getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
+
+       if (xmlDoc == NULL) {
+               MSG_DEBUG("xmlDoc is NULL");
+               return;
+       }
+
+       topNode = xmlDocGetRootElement(xmlDoc);
+
+       if (topNode == NULL) {
+               MSG_DEBUG("topNode is NULL");
+               xmlFreeDoc(xmlDoc);
+               return;
+       }
+
+       indNode = topNode->xmlChildrenNode;
+
+       while (indNode != NULL) {
+               if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
+                       MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
+                       break;
+               }
+
+               indNode = indNode->next;
+       }
+
+       if (indNode == NULL) {
+               MSG_DEBUG("indNode is NULL.");
+               return;
+       }
+
+       /**  temporary set to max. */
+       pushMsg.expires = 0xFFFFFFFF;
+
+       /** setting received time */
+       time_t  t               =       time(NULL);
+       time_t  utfTime =       time(&t);
+
+       pushMsg.received = (unsigned long)utfTime;
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
+
+       if (tmpXmlChar == NULL) {
+               MSG_DEBUG("href is NULL.");
+               return;
+       }
+
+       if (tmpXmlChar != NULL)
+               strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
+
+       if (tmpXmlChar != NULL)
+               strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
+
+       if (tmpXmlChar != NULL)
+               pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
+
+       if (pushMsg.created == 0)
+               pushMsg.created = pushMsg.received;
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
+
+       if (tmpXmlChar != NULL)
+               pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
+
+       pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
+
+       tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
+
+       if (tmpXmlChar == NULL) {
+               MSG_DEBUG("contents is NULL.");
+               return;
+       }
+
+       strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
+
+       /** Write push Msg to file */
+       char fileName[MSG_FILENAME_LEN_MAX+1];
+       memset(fileName, 0x00, sizeof(fileName));
+
+       if (MsgCreateFileName(fileName) == false) {
+               xmlFree(xmlDoc);
+               xmlFree(tmpXmlChar);
+               THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
+       }
+
+       if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
+               xmlFree(xmlDoc);
+               xmlFree(tmpXmlChar);
+               THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
+       }
+
+       /**  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);
+
+       strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
+
+       /**  Convert Type values */
+       msgInfo.msgType.mainType = MSG_SMS_TYPE;
+       msgInfo.msgType.subType = MSG_WAP_SI_SMS;
+
+       msgInfo.dataSize = sizeof(pushMsg);
+
+       xmlFree(xmlDoc);
+       xmlFree(tmpXmlChar);
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Add WAP Push Msg into DB */
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+
+       if (err == MSG_SUCCESS) {
+               /** Callback */
+               err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
+
+               if (err != MSG_SUCCESS){
+                       MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
+               }
+       } else {
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
+       }
+
+       MSG_END();
+
+       return;
+}
+
+
+void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText)
+{
+       MSG_BEGIN();
+
+       MSG_PUSH_MESSAGE_S pushMsg = {};
+
+       xmlDocPtr       xmlDoc = NULL;
+       xmlNodePtr      topNode = NULL;
+       xmlNodePtr      indNode = NULL;
+
+       xmlChar*                tmpXmlChar = NULL;
+
+       msg_error_t err = MSG_SUCCESS;
+
+       if (pPushBody == NULL) {
+               MSG_DEBUG("pPushBody is NULL \n" );
+               return;
+       }
+
+       getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
+
+       if (xmlDoc == NULL) {
+               MSG_DEBUG("xmlDoc is NULL \n" );
+               return;
+       }
+
+       topNode = xmlDocGetRootElement(xmlDoc);
+
+       if (topNode == NULL) {
+               MSG_DEBUG("Empty Document." );
+               xmlFreeDoc(xmlDoc);
+               return;
+       } else {
+               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_SEC_DEBUG("indNode->name = %s\n",indNode->name);
+                       break;
+               }
+
+               indNode = indNode->next;
+       }
+
+       /**  setting received time setting */
+       time_t  t               =       time(NULL);
+       time_t  utfTime =       time(&t);
+
+       pushMsg.received = (unsigned long)utfTime;
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
+
+       if (tmpXmlChar == NULL) {
+               MSG_DEBUG("href is NULL.");
+               return;
+       }
+
+       strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
+
+       tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
+       pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
+
+       /** Setting other parameters in default values */
+       pushMsg.created = pushMsg.received;
+       /** temporary set to MAX value. */
+       pushMsg.expires = 0xFFFFFFFF;
+
+       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);
+
+       /** Write push Msg to file */
+       char fileName[MSG_FILENAME_LEN_MAX+1];
+       memset(fileName, 0x00, sizeof(fileName));
+
+       if (MsgCreateFileName(fileName) == false)
+               THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
+
+       if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
+               THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
+
+       /** 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);
+
+       strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
+
+       /** Convert Type values */
+       msgInfo.msgType.mainType = MSG_SMS_TYPE;
+       msgInfo.msgType.subType = MSG_WAP_SL_SMS;
+
+       /**  Update Msg Text */
+       strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
+
+       msgInfo.dataSize = sizeof(pushMsg);
+
+       MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
+
+       /** 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);
+       } else {
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
+       }
+
+       xmlFree(xmlDoc);
+       xmlFree(tmpXmlChar);
+
+       MSG_END();
+
+       return;
+}
+
+void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText)
+{
+       MSG_PUSH_CACHEOP_S cacheOp;
+
+       xmlDocPtr       xmlDoc = NULL;
+       xmlNodePtr      topNode = NULL;
+       xmlNodePtr      indNode = NULL;
+
+       memset(&cacheOp, 0x00, sizeof(cacheOp));
+
+       MSG_DEBUG("Enter handleCOMessage");
+
+       if (pPushBody == NULL) {
+               MSG_DEBUG("pPushBody is NULL \n" );
+               return;
+       }
+
+       getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
+
+       if (xmlDoc == NULL) {
+               MSG_DEBUG("xmlDoc is NULL \n" );
+               return;
+       }
+
+       topNode = xmlDocGetRootElement(xmlDoc);
+       if (topNode == NULL) {
+               MSG_DEBUG("Warning:Empty Document\n" );
+               xmlFreeDoc(xmlDoc);
+               return;
+       }
+
+       indNode = topNode->xmlChildrenNode;
+
+
+       while(indNode != NULL) {
+
+               xmlChar* tmpUrl = NULL;
+               if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_OBJ)) {
+                       MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
+
+                       tmpUrl = xmlGetProp(indNode, (xmlChar*) SMS_PUSH_XML_CO_URI);
+
+                       if (tmpUrl != NULL) {
+                               strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
+
+                               MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
+                       } else {
+                               MSG_DEBUG("NO href value from the xmlDoc\n");
+                       }
+               } else if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_SVC)) {
+                       MSG_SEC_DEBUG("indNode->name = %s\n",indNode->name);
+                       tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
+
+                       if (tmpUrl != NULL) {
+                               strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
+                               MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
+                       } else {
+                               MSG_DEBUG("NO href value from the xmlDoc\n");
+                       }
+               }
+
+               if (tmpUrl != NULL)
+                       xmlFree(tmpUrl);
+
+               indNode = indNode->next;
+       }
+
+       /**  Write push Msg to file */
+       char fileName[MSG_FILENAME_LEN_MAX+1];
+       memset(fileName, 0x00, sizeof(fileName));
+
+       if (MsgCreateFileName(fileName) == false) {
+               xmlFree(xmlDoc);
+               THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
+       }
+
+       if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
+               xmlFree(xmlDoc);
+               THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
+       }
+
+       /**  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);
+
+       strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
+
+       /**  Convert Type values */
+       msgInfo.msgType.mainType = MSG_SMS_TYPE;
+       msgInfo.msgType.subType = MSG_WAP_CO_SMS;
+
+       msgInfo.dataSize = sizeof(cacheOp);
+
+       msg_error_t err = MSG_SUCCESS;
+
+       /** Add WAP Push Msg into DB */
+       err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
+
+       if (err == MSG_SUCCESS) {
+               /** Callback */
+               err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
+
+               if (err != MSG_SUCCESS) {
+                       MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
+               }
+       } else {
+               MSG_DEBUG("checkMessage() Error !! [%d]", err);
+       }
+
+       xmlFree(xmlDoc);
+
+       return;
+}
+
+
+void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
+{
+#if MSG_DRM_SUPPORT
+       int drmRt = DRM_RETURN_SUCCESS;
+       char* cid = NULL;
+       AutoPtr<char> buf(&cid);
+
+       MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
+       drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_LICENSE;
+       drm_register_lic_info_s lic_req_info;
+       drm_register_lic_resp_s lic_resp_info;
+
+       bzero(&lic_req_info, sizeof(drm_register_lic_info_s));
+       bzero(&lic_resp_info, sizeof(drm_register_lic_resp_s));
+       bzero(lic_req_info.lic_data, sizeof(lic_req_info.lic_data));
+
+       memcpy(lic_req_info.lic_data, pPushBody, PushBodyLen);
+
+       lic_req_info.lic_version = DRM_OMA_DRMV1_RIGHTS;
+       lic_req_info.roap_init_src = DRM_ROAP_INIT_FROM_WAPPUSH;
+       lic_req_info.operation_callback.callback = NULL;
+
+       drmRt = drm_process_request(request_type, &lic_req_info, &lic_resp_info);
+       if (drmRt == DRM_RETURN_SUCCESS) {
+               MSG_DEBUG("DRM successfully registed to drm-service.");
+       } else {
+               MSG_DEBUG("Fail to regist DRM to drm-service.");
+       }
+#endif
+       return;
+}
+
+
+void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
+{
+       /** Convert class Type values */
+       pMsgInfo->msgType.classType = MSG_CLASS_NONE;
+
+       /**  set folder id (temporary) */
+       pMsgInfo->folderId = MSG_INBOX_ID;
+
+       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);
+
+/*** Comment below lines to save local UTC time..... (it could be used later.)
+
+       if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
+
+               MSG_DEBUG("year : %d", tmpTimeStamp.time.absolute.year);
+               MSG_DEBUG("month : %d", tmpTimeStamp.time.absolute.month);
+               MSG_DEBUG("day : %d", tmpTimeStamp.time.absolute.day);
+               MSG_DEBUG("hour : %d", tmpTimeStamp.time.absolute.hour);
+               MSG_DEBUG("minute : %d", tmpTimeStamp.time.absolute.minute);
+               MSG_DEBUG("second : %d", tmpTimeStamp.time.absolute.second);
+               MSG_DEBUG("timezone : %d", tmpTimeStamp.time.absolute.timeZone);
+
+               char displayTime[32];
+               struct tm * timeTM;
+
+               struct tm timeinfo;
+               memset(&timeinfo, 0x00, sizeof(tm));
+
+               timeinfo.tm_year = (tmpTimeStamp.time.absolute.year + 100);
+               timeinfo.tm_mon = (tmpTimeStamp.time.absolute.month - 1);
+               timeinfo.tm_mday = tmpTimeStamp.time.absolute.day;
+               timeinfo.tm_hour = tmpTimeStamp.time.absolute.hour;
+               timeinfo.tm_min = tmpTimeStamp.time.absolute.minute;
+               timeinfo.tm_sec = tmpTimeStamp.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 -= (tmpTimeStamp.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);
+       }
+
+***/
+
+       pMsgInfo->displayTime = rawtime;
+
+       /**  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.szData, MAX_ADDRESS_VAL_LEN);
+
+       pMsgInfo->msgPort.valid = false;
+       pMsgInfo->msgPort.dstPort = 0;
+       pMsgInfo->msgPort.srcPort = 0;
+
+}
+
+void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
+{
+       if (pPushBody == NULL) {
+               MSG_DEBUG("pPushBody is NULL");
+               return;
+       }
+
+
+       if (isText) {
+               *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
+       } else {
+               WB_UTINY*       xmldata = NULL;
+               WBXMLConvWBXML2XML *conv = NULL;
+               WBXMLError ret = WBXML_OK;
+
+               ret = wbxml_conv_wbxml2xml_create(&conv);
+               if (ret != WBXML_OK)
+                       return;
+
+               ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
+
+               wbxml_conv_wbxml2xml_destroy(conv);
+
+               if (ret != WBXML_OK ||xmldata == NULL) {
+                       MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
+                       return;
+               }
+
+               MSG_DEBUG("xmldata : \n%s\n", xmldata);
+
+               *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
+       }
+
+}
+
+unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
+{
+       struct tm       timeStruct;
+       time_t          nTimeInSec = 0;
+       char                    tmpBuf[10];
+       int                     i = 0, index = 0;
+
+       memset(tmpBuf, 0x00, sizeof(tmpBuf));
+       memset(&timeStruct, 0x00, sizeof(struct tm));
+
+       /** check pDate */
+       if (AcStrlen(pDate)<20)
+               return 0;
+
+       MSG_DEBUG("pDate [%s]", pDate);
+
+       /** Year */
+       for (i = 0; i < 4; i++) {
+               tmpBuf[i] = pDate[index++];
+       }
+       tmpBuf[i] = '\0';
+       index++;
+       timeStruct.tm_year = (atoi( tmpBuf)-1900);
+
+       /**  Month */
+       for (i = 0; i < 2; i++) {
+               tmpBuf[i] = pDate[index++];
+       }
+       tmpBuf[i] = '\0';
+       index++;
+       timeStruct.tm_mon = (atoi( tmpBuf) - 1);
+
+       /** Date */
+       for (i = 0; i < 2; i++) {
+               tmpBuf[i] = pDate[index++];
+       }
+       tmpBuf[i] = '\0';
+       index++;
+       timeStruct.tm_mday = atoi( tmpBuf);
+
+       /** Hours */
+       for (i = 0; i < 2; i++) {
+               tmpBuf[i] = pDate[index++];
+       }
+       tmpBuf[i] = '\0';
+       index++;
+       timeStruct.tm_hour = atoi( tmpBuf);
+
+       /** Minites */
+       for (i = 0; i < 2; i++) {
+               tmpBuf[i] = pDate[index++];
+       }
+       tmpBuf[i] = '\0';
+       index++;
+       timeStruct.tm_min = atoi( tmpBuf);
+
+       /** Seconds */
+       for (i = 0; i < 2; i++) {
+               tmpBuf[i] = pDate[index++];
+       }
+       tmpBuf[i] = '\0';
+       index++;
+       timeStruct.tm_sec = atoi( tmpBuf);
+
+       nTimeInSec = mktime(&timeStruct);
+
+       return nTimeInSec;
+}
+
+msg_push_action_t SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pAction)
+{
+       int comp = 0;
+
+       if (pAction == NULL) {
+               MSG_DEBUG("pAction is NULL. Setting to default action type.");
+               return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
+       }
+
+       /** compare  with signal-none. */
+       comp = g_strcmp0( "signal-none", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
+
+       /** compare  with signal-low. */
+       comp = g_strcmp0( "signal-low", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
+
+       /**  compare  with signal-medium. */
+       comp = g_strcmp0( "signal-medium", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
+
+       /**  compare  with signal-high. */
+       comp = g_strcmp0( "signal-high", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
+
+       /**  compare  with delete. */
+       comp = g_strcmp0( "delete", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SI_ACTION_DELETE;
+
+       /**  signal-medium is default action value. */
+       return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
+
+}
+
+msg_push_action_t SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pAction)
+{
+       int comp = 0;
+
+       if (pAction == NULL) {
+               MSG_DEBUG( "MSG_DEBUG is NULL. Setting to default action type.\n" );
+               return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
+       }
+
+       /**  compare pSrcStr with execute-low. */
+       comp = g_strcmp0( "execute-low", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
+
+       /**  compare pSrcStr with execute-high. */
+       comp = g_strcmp0( "execute-high", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
+
+       /** compare pSrcStr with cache. */
+       comp = g_strcmp0( "cache", pAction );
+       if (comp == 0)
+               return MSG_PUSH_SL_ACTION_CACHE;
+
+       /** default SL action value is execute-low. */
+       return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
+
+}
+
+
+unsigned long SmsPluginWapPushHandler::wspRetriveUintvarDecode( unsigned char* sourceData, unsigned long* currentPointer )
+{
+       unsigned long i = 0;
+       unsigned long decodedValue;
+
+       while (sourceData[*currentPointer +i] >= 0x80) i++;
+
+       decodedValue = wspDecodeUintvar( i+1, sourceData + *currentPointer );
+       *currentPointer = *currentPointer + i + 1;
+       MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%d .\n",decodedValue );
+       return decodedValue;
+}
+
+
+unsigned long SmsPluginWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar )
+{
+       unsigned long i;
+       unsigned long decodedUintvar = 0;
+
+
+       for (i = 0 ; i < length; i++) {
+               decodedUintvar = decodedUintvar +  ( wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f ));
+       }
+
+       return decodedUintvar;
+}
+
+
+void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
+{
+       unsigned long iField;
+       bool   continueField = FALSE;
+       unsigned long currentLength;
+
+       char* encodedHeader = NULL;
+       AutoPtr<char> encodedHeaderbuf(&encodedHeader);
+
+       char* outTemper = NULL;
+
+       char* temper = NULL;
+       AutoPtr<char> temperbuf(&temper);
+
+       unsigned char track;
+       unsigned long iEncodedHeader = 0;
+       unsigned char fieldCode = 0xff;
+
+       /* outTemper is Decoded Headers.
+           temper is Single Decoded Header.
+       */
+       if (NULL == ( outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
+               MSG_DEBUG("outTemper Memory allocation is failed.\n" );
+               return;
+       }
+       memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
+       currentLength = WSP_STANDARD_STR_LEN_MAX;
+
+       MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n" );
+
+       int loop;
+       char szBuf[64];
+
+       szBuf[0] = 0x00;
+       MSG_DEBUG("wspDecodeHeader: RAW data \n" );
+       for (loop = 0 ; loop<(int)encodedHeaderLen; loop++) {
+               char szTempBuf[5];
+               szTempBuf[0] = 0x00;
+               sprintf( szTempBuf, "%2X ", sEncodedHeader[loop] );
+
+               if (AcStrlen( szBuf ) + 7 < 64) {
+                       strncat( szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1 );
+               } else {
+                       strncat( szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1 );
+                       MSG_DEBUG("[%s]", szBuf);
+                       szBuf[0] = 0x00;
+                       strncat( szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1 );
+               }
+       }
+       strncat( szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1 );
+       MSG_DEBUG("[%s]", szBuf);
+       MSG_DEBUG("fContentType=%d  \n",fContentType );
+       /* operation for content-type */
+       /* makes psuedo- content-type fieldcode */
+       /* content - type is processed with header. But it's come without field code. So existence of fContentType can decide adding content type header field code whether ContentType + general header is or not. */
+
+       if (fContentType) {
+               encodedHeader = new char[ encodedHeaderLen + 1 ];
+               if (encodedHeader == NULL)      {
+                       MSG_DEBUG("encodedHeader Memory allocation is failed.\n" );
+                       return;
+               }
+               encodedHeader[0] = 0x91;
+               memcpy( encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen );
+       } else {
+               encodedHeader = new char[ encodedHeaderLen ];
+               if (encodedHeader == NULL)      {
+                       MSG_DEBUG("encodedHeader Memory allocation is failed.\n" );
+                       return;
+               }
+
+               memcpy( encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen );
+       }
+
+       /* Is it reacehd end of header? */
+       while (iEncodedHeader < encodedHeaderLen) {
+               /* Get memory for single header */
+               if (temper == NULL) {
+                       temper = new char[ 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.
+               if (track == 0x 7f )
+               */
+               track = encodedHeader[iEncodedHeader];
+
+               if (track == 0x00) {
+                       MSG_DEBUG("WspLDecodeHeader: fieldcode  is 0 \n" );
+                       strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
+                       fieldCode = 0xff;
+                       iEncodedHeader++;
+               } else if (( track > 0 ) && ( track < 0x20 )) {
+                       iEncodedHeader++;
+               } else if (( track < 0x7f ) && ( track > 0x1f )) { /* In this case, first byte is normal string. So it's considered to unknown header. */
+                       unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
+                       unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
+
+                       strncpy( (char*)fieldName, (char*)(encodedHeader + iEncodedHeader ),WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
+                       fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
+                       iEncodedHeader = iEncodedHeader + AcStrlen( (char*)fieldName ) + 1;
+                       strncpy( (char*)fieldValue, (char*)(encodedHeader + iEncodedHeader ), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
+                       fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
+                       iEncodedHeader = iEncodedHeader + AcStrlen( (char*)fieldValue ) + 1;
+
+                       strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                       strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                       strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                       /* this means 'don't process anymore.' */
+                       fieldCode = 0xff;
+
+               } else if (track > 0x7f) {
+                       /* In case of first byte is field code, else case is error. */
+
+                       /*if (( track & 0x7f ) <= wspHeaderFieldCount ) */
+                       {
+
+                               unsigned long  fieldValueLen = encodedHeader[iEncodedHeader + 1];
+                               unsigned char fieldValue[1275];
+                               fieldCode = track & 0x7f;
+                               /*
+                               if (( fieldValueLen == 0 ) || ( fieldValueLen == 0x80 ))
+                               {
+                                       dprint( DNET_WAP,DNET_DBG_HIGH, "%X %X %X %X %X %X\n" , fieldCode, encodedHeader[iEncodedHeader + 1], encodedHeader[iEncodedHeader + 2],encodedHeader[iEncodedHeader + 3],encodedHeader[iEncodedHeader + 4], encodedHeader[iEncodedHeader + 5] );
+                               }
+                               */
+                               memset(fieldValue, 0, 1275);
+                               {
+                                       /* add field name */
+                                       /* This continueField flag show whether previous field code and current field code are same or not. If it's same, there are some sequential display effect by omitting field name addition process. The reason why it should be do that can be found in encoding example of spec. */
+                                       if (!continueField) {
+                                               strncat( (char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                               strncat( (char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                               continueField = FALSE;
+                                       }
+
+                                       /* field value is string */
+                                       /* In this case, it just copy field value. */
+                                       if (( fieldValueLen > LENGTH_QUOTE ) && ( fieldValueLen < 0x80 )) {
+
+                                               /* string field value should be NULL terminated */
+                                               strncat( (char*)temper, (char*)(encodedHeader + iEncodedHeader + 1 ), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+                                               strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+
+                                               iEncodedHeader = iEncodedHeader + AcStrlen( (char*)encodedHeader + iEncodedHeader + 1 ) + 2;
+                                               fieldCode = 0xff;
+                                       }
+                                       /* first field value is length */
+                                       /* If first byte of field value is length value, allocate field value by the length.
+                                       In field value, data is
+                                       1D 03 8F 24 24  - Then 8F 24 24 is field value.
+                                       1D 1F 33.... - Then  allocate 33H for FieldValue.
+                                       1D 8F - Then 8F
+                                       1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
+                                       1D 8F 24 24 - In this case, original data is wrong.
+                                       If  accept-charset: ISO-10646-ucs-2;Q=0.7 is
+                                       01 03 03 E8 47
+                                       01 - field code
+                                       03 - field value length
+                                       03 E8 47 - field value
+                                       it's decoded by above value.
+                                       */
+                                       if (fieldValueLen < 0x20) {
+
+                                               if (fieldValueLen  == LENGTH_QUOTE) {
+
+                                                       /* field length is encoded in UINTVAR */
+                                                       unsigned long  uintvarLen = 0;
+                                                       fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen );
+                                                       memcpy( fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen );
+                                                       iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
+
+                                               } else {
+
+                                                       if (fieldValueLen == 1) {
+                                                               /* field value is one byte integer over 0x80 */
+                                                               /** make it two byte integer */
+                                                               fieldValue[0] = 0x00;
+                                                               memcpy( fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
+                                                               fieldValueLen = 2;
+                                                               iEncodedHeader = iEncodedHeader + 1 + 2;
+                                                       } else {
+                                                               memcpy( fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen );
+                                                               fieldValue[fieldValueLen] = 0;
+                                                               iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
+                                                               if (( fieldValueLen == 0 ) || ( fieldValueLen == 0x80 )) {
+                                                                       MSG_DEBUG("%X \n",  encodedHeader[iEncodedHeader] );
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       /* field value is single encoded */
+                                       if (fieldValueLen > 0x7f) {
+                                               fieldValue[0] = encodedHeader[iEncodedHeader + 1];
+                                               fieldValueLen = 1;
+                                               iEncodedHeader = iEncodedHeader + 2;
+                                       }
+                                       /* processing normal pre-defined field decoding */
+
+                                       MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode );
+                                       MSG_DEBUG("WspLDecodeHeader: fieldSize %d\n", fieldValueLen );
+
+                                       if (( fieldCode  > wspHeaderFieldCount ) && ( fieldCode != 0xff )) {
+                                               MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track );
+                                               strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
+                                               fieldCode = 0xff;
+                                       }
+
+
+                                       switch ( fieldCode )
+                                       {
+                                               /* accept charset */
+                                               /* It's normal way of field process. */
+                                               case 0x01 :
+                                                       {
+                                                               unsigned long  i = 0;
+                                                               unsigned long  code;
+
+                                                               /* Case of length of charset greater than 1 are two thigins.
+                                                               1. code length of charset is greater than 1.
+                                                               2. It include parameter.
+                                                               3. Or both of two
+                                                               */
+                                                               if (1 != fieldValueLen) {
+                                                                       code = wspHeaderDecodeInteger( fieldValue );
+                                                                       /* Calculate iField. */
+                                                                       if (fieldValue[0] < 0x80 )
+                                                                               iField = fieldValue[0];
+                                                                       else
+                                                                               iField = 1;
+
+                                                                       while ( wspCharset[i].charsetCode != code )
+                                                                               i++;
+                                                                       strncat( (char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       /* If parameter exist */
+                                                                       if (iField < fieldValueLen) {
+                                                                               char* param = NULL;
+                                                                               AutoPtr<char> parambuf(&param);
+                                                                               wspHeaderDecodeQValue( fieldValueLen - iField, fieldValue + iField, &param);
+                                                                               strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       }
+                                                               } else {
+                                                                       code = fieldValue[0] & 0x7f;
+
+                                                                       while (( wspCharset[i].charsetCode != code ) && ( wspCharset[i].charsetCode != 0xffff  )) i++;
+                                                                       strncat( (char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                               }
+
+                                                       }
+                                                       break;
+
+                                               /* type encoding */
+                                               /* Like below routine, Same decoding routine process together. */
+                                               /* Accept-encoding */
+                                               case 0x02 :
+                                               /* content-encoding */
+                                               case 0x0b :
+                                                       {
+                                                               int integerValue;
+
+                                                               integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen );
+                                                               if (integerValue > 2) {
+                                                                       MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
+                                                                       break;
+                                                               }
+                                                               strncat( (char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+                                                       }
+                                                       break;
+                                               /* contents type decoder */
+                                               /* accept */
+                                               case 0x00 :
+                                               /* content-type */
+                                               case 0x11 :
+                                                       {
+                                                               unsigned long  contentsTypeCode;
+                                                               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) {
+                                                                       strncat( (char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+                                                                       break;
+                                                               }
+                                                               /* 01 AE --> 00 AE --> AE*/
+                                                               if (fieldValueLen == 2  &&  fieldValue[0] == 0) {
+                                                                       memcpy( fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1 );
+                                                                       MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n" );
+                                                               }
+
+                                                               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];
+                                                                               fieldValue[2] = fieldValue[1];
+                                                                               fieldValue[1] = fieldValue[0];
+                                                                               fieldValue[0] = 0x02;
+                                                                               tempLen = 2;
+                                                                               fieldValueLen = 3;
+                                                                               MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n" );
+                                                                       } else {
+                                                                               tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
+                                                                       }
+
+                                                                       if (tempLen == 1) {
+
+                                                                               char* szExtendedContent;
+
+                                                                               contentsTypeCode = fieldValue[0] & 0x7f;
+                                                                               while (( wspContentsType[i].contentsTypeCode != contentsTypeCode ) && ( i < wspContentsTypeCount )) i++;
+
+                                                                               /* If specified content type doesn't exist */
+                                                                               if (i < wspContentsTypeCount)
+                                                                                       strncat( (char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+
+                                                                               szExtendedContent =  wspExtendedDecodeType( (char)contentsTypeCode );
+
+                                                                               if (szExtendedContent != NULL) {
+                                                                                       MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n " );
+                                                                                       strncat( (char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                               }
+                                                                       } else {
+                                                                               contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
+
+                                                                               while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode)) i++;
+
+                                                                               /** If there is a Content-Type assigned, */
+                                                                               if (i < wspUnregisteredContentsTypeCount)
+                                                                                       strncat ((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+
+                                                                               tempLen +=1;
+                                                                       }
+                                                               } else {
+                                                                       tempLen = AcStrlen( (char*)fieldValue ) + 1;
+
+                                                                       strncat ((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+                                                                       MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type\n ", tempLen);
+                                                               }
+
+                                                               /* If there is a parameter */
+                                                               if (tempLen < fieldValueLen) {
+                                                                       char* param = NULL;
+                                                                       AutoPtr<char> parambuf(&param);
+                                                                       wspHeaderDecodeParameter( fieldValue + tempLen, fieldValueLen - tempLen, &param);
+                                                                       if (param != NULL) {
+                                                                               strncat( (char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+                                                                               strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       }
+                                                               }
+                                                       }
+                                                       break;
+
+                                               /* language */
+                                               /* content-language */
+                                               case 0x0c :
+                                               /* accept-language */
+                                               case 0x03 :
+                                                       {
+                                                               unsigned long i = 0;
+                                                               unsigned long code;
+                                                               unsigned long tempLen;
+                                                               if ((fieldValue[0] < 0x20 ) || (fieldValue[0] > 0x80 )) {
+                                                                       if (fieldValue[0] > 0x80 )
+                                                                               tempLen = 1;
+                                                                       else
+                                                                               tempLen = fieldValue[0];
+                                                               } else {
+                                                                       tempLen = AcStrlen( (char*)fieldValue ) + 1;
+                                                               }
+
+                                                               if (tempLen == 1) {
+
+                                                                       code = wspHeaderDecodeInteger( fieldValue );
+                                                                       while ( wspLanguage[i].languageCode != code) {
+                                                                               i++;
+                                                                               if (i == wspLanguageCount)
+                                                                                       break;
+                                                                       }
+
+                                                                       if (i < wspLanguageCount) {
+                                                                               strncat( (char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       }
+                                                               } else {
+                                                                       strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
+                                                               }
+
+                                                               if (tempLen < fieldValueLen) {
+                                                                       char* param = NULL;
+                                                                       AutoPtr<char> parambuf(&param);
+                                                                       wspHeaderDecodeQValue(  fieldValueLen - tempLen, fieldValue + tempLen, &param );
+                                                                       strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                               }
+                                                       }
+                                                       break;
+
+                                               /* integer */
+                                               /* Max-forwards */
+                                               case 0x1e :
+                                               /* content-length */
+                                               case 0x0d :
+                                               /* age */
+                                               case 0x05 :
+                                               /* Bearer-indication */
+                                               case 0x33 :
+                                               /* Push-Flag */
+                                               case 0x34 :
+                                                       {
+
+                                                               unsigned char temp[16];
+                                                               /*
+                                                               if (( fieldValueLen == 2 ) && ( fieldValue[0] > 0x7f ))
+                                                                       AcSprintf( (char*)temp, "%u", (unsigned int)fieldValue[1]);
+                                                               else
+                                                               */
+                                                               sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ));
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+                                               /* X-Wap-Application-Id */
+                                               case 0x2f :
+                                                       {
+                                                               unsigned char temp[64];
+                                                               int         integerValue;
+
+                                                               if (fieldValueLen == 2 &&  fieldValue[0] == 0) {
+                                                                       memcpy( fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1 );
+                                                                       MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n" );
+                                                                       fieldValueLen = 1;
+                                                               }
+
+                                                               integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
+
+                                                               int count = sizeof(wspHeaderApplId)/sizeof(SMS_WSP_HEADER_PARAMETER_S);
+                                                               for(int i = 0; i < count ; ++i)
+                                                               {
+                                                                       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)-AcStrlen(temper)-1);
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       }
+                                                       break;
+                                               /* Accept-Application */
+                                               case 0x32 :
+                                                       if (0x80 == fieldValue[0]) {
+                                                               strncat( (char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1 );
+                                                       } else {
+
+                                                               unsigned char temp[16];
+                                                               /*
+                                if (( fieldValueLen == 2 ) && ( fieldValue[0] == 1 ))
+                                       AcSprintf( (char*)temp, "%u", (unsigned int)fieldValue[0]);
+                                else
+                                                               */
+                                                               sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ));
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
+                                                       }
+                                                       break;
+
+
+                                               /* date */
+                                               /* last-modified */
+                                               case 0x1d :
+                                               /* if-unmodified-since */
+                                               case 0x1b :
+                                               /* if-range */
+                                               case 0x1a :
+                                               /* if-modified-since */
+                                               case 0x17 :
+                                               /* expires */
+                                               case 0x14 :
+                                               /* date */
+                                               case 0x12 :
+                                                       {
+                                                               char* decodedString = NULL;
+                                                               AutoPtr<char> decodedStringbuf(&decodedString);
+                                                               wspHeaderDecodeDateValue( fieldValueLen, fieldValue, &decodedString);
+                                                               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)-AcStrlen(temper)-1 );
+                                                       break;
+                                               /* accept-ranges */
+                                               case 0x04 :
+                                                       if (fieldValue[0] == 0x80 )
+                                                               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)-AcStrlen(temper)-1 );
+                                                       break;
+                                               /* content-md5 */
+                                               case 0x0f :
+                                                       {
+                                                               unsigned char temp[1275];
+                                                               memcpy( temp, fieldValue, (size_t)fieldValueLen );
+                                                               temp[fieldValueLen] = 0;
+                                                               wspHeaderCopyDecodedString( temp, &currentLength, &temper );
+                                                       }
+                                                       break;
+                                               /* Credential */
+                                               /* authorization */
+                                               case 0x07 :
+                                               /* proxy - authorization */
+                                               case 0x21 :
+                                                       if (fieldValue[0] == 0x80) {
+                                                               char* addString = NULL;
+                                                               AutoPtr<char> addStringbuf(&addString);
+                                                               wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString );
+                                                               strncat( (char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       } else {
+                                                               iField = AcStrlen( (char*)fieldValue) + 1;
+
+                                                               strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                               if (iField < fieldValueLen) {
+                                                                       char* param = NULL;
+                                                                       AutoPtr<char> parambuf(&param);
+                                                                       wspHeaderDecodeParameter( fieldValue + 1, fieldValueLen - 1, &param );
+                                                                       if (param != NULL) {
+                                                                               strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                               strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       }
+                                                               }
+                                                       }
+                                                       break;
+
+
+                                               /* Challenge */
+                                               /* www - auth */
+                                               case 0x2d :
+                                               /* Proxy-authenticate */
+                                               case 0x20 :
+                                                       if (0 == fieldValueLen )
+                                                               break;
+                                                       if (fieldValue[0] == 0x80) {
+                                                               char* addString = NULL;
+                                                               AutoPtr<char> addStringbuf(&addString);
+                                                               wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString );
+                                                               strncat( (char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       } else {
+                                                               unsigned char  authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
+                                                               unsigned char  realmValue[WSP_STANDARD_STR_LEN_MAX];
+                                                               unsigned char  addedString[WSP_STANDARD_STR_LEN_MAX];
+
+                                                               strncpy( (char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
+                                                               iField = AcStrlen( (char*)authScheme ) + 1;
+                                                               strncpy( (char*)realmValue, (char*)(fieldValue + iField ), WSP_STANDARD_STR_LEN_MAX-1);
+                                                               iField = iField + AcStrlen( (char*)realmValue ) + 1;
+                                                               snprintf( (char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue );
+                                                               wspHeaderCopyDecodedString( addedString, &currentLength, &temper );
+
+                                                               if (iField < fieldValueLen) {
+                                                                       char* param = NULL;
+                                                                       AutoPtr<char> parambuf(&param);
+                                                                       wspHeaderDecodeParameter( fieldValue + iField, fieldValueLen - iField, &param );
+                                                                       if (param != NULL) {
+                                                                               strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                               wspHeaderCopyDecodedString( (unsigned char*)param, &currentLength, &temper );
+                                                                       }
+                                                               }
+                                                       }
+                                                       break;
+
+                                               /* content -range */
+                                               case 0x10 :
+                                                       {
+                                                               unsigned long  first, len, last;
+
+                                                               unsigned char  temp[16];
+                                                               iField = 0;
+
+                                                               strncat( (char*)temper," bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+
+                                                               first = wspRetriveUintvarDecode( fieldValue, &iField );
+                                                               len = wspRetriveUintvarDecode( fieldValue, &iField );
+                                                               /* Originally range of HTTP include entity length. But WSP omit it. Finally to calculate this, it should be get content length from export. If this field is included without content length, then it can get wrong result. This content length can be get by calculating PDU length.
+                                                               */
+                                                               last = first + contentsLength - 1;
+
+                                                               sprintf( (char*)temp, "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len );
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+
+                                               /* cache-control */
+                                               case 0x08 :
+                                                       {
+                                                               char* cacheString = NULL;
+                                                               AutoPtr<char> cacheStringbuf(&cacheString);
+
+                                                               wspHeaderDecodeCacheControl( fieldValue, fieldValueLen, &cacheString );
+                                                               strncat( (char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+
+                                               /* pragma */
+                                               case 0x1f :
+                                                       if (fieldValue[0] == 0x80) {
+                                                               strncat( (char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       } else {
+                                                               if (1 < fieldValueLen) {
+                                                                       char* param = NULL;
+                                                                       AutoPtr<char> parambuf(&param);
+                                                                       wspHeaderDecodeParameter( fieldValue, fieldValueLen, &param );
+
+                                                                       if (param != NULL) {
+                                                                               strncat( (char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                               strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       }
+                                                               }
+                                                       }
+
+                                                       break;
+                                               /* public */
+                                               case 0x22 :
+                                               /* allow */
+                                               case 0x06 :
+                                                       {
+                                                               unsigned long  i = 0;
+                                                               while ( wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ) != wspMethodType[i].methodCode ) i++;
+                                                               strncat( (char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+                                               /* range */
+                                               case 0x23 :
+                                                       strncat( (char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       if (fieldValue[0] == 0x80) {
+                                                               unsigned char temp[16];
+                                                               unsigned long  first, last;
+                                                               iField = 0;
+
+                                                               first = wspRetriveUintvarDecode( fieldValue, &iField );
+                                                               last = wspRetriveUintvarDecode( fieldValue, &iField );
+
+                                                               sprintf( (char*)temp, "%u-%u", (unsigned int)first, (unsigned int)last );
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       if (fieldValue[0] == 0x81) {
+                                                               unsigned char temp[16];
+                                                               unsigned long  suffix;
+
+                                                               suffix = wspRetriveUintvarDecode( fieldValue, &iField );
+
+                                                               sprintf( (char*)temp, "-%u", (unsigned int)suffix );
+
+                                                       }
+                                                       break;
+                                               /* retry-after */
+                                               case 0x25 :
+                                                       if (fieldValue[0] == 0x80) {
+                                                               char* temp = NULL;
+                                                               AutoPtr<char> tempbuf(&temp);
+
+                                                               wspHeaderDecodeDateValue( fieldValueLen - 1, fieldValue + 1, &temp );
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+
+                                                       if (fieldValue[0] == 0x81) {
+                                                               unsigned char temp[16];
+
+                                                               sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue,fieldValueLen ));
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+                                               /* transfer-encoding */
+                                               case 0x27 :
+                                                       /* No other cases allowed */
+                                                       if (fieldValue[0] == 0x80 )
+                                                               strncat( (char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+
+                                                       break;
+                                               /* vary */
+                                               case 0x2a :
+                                                       {
+                                                               int integerValue = wspHeaderDecodeIntegerByLength(fieldValue,fieldValueLen );
+                                                               if (integerValue > wspHeaderFieldCount) {
+                                                                       MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n",wspHeaderFieldCount);
+                                                                       break;
+                                                               }
+                                                               strncat( (char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+                                               /* warning */
+                                               case 0x2c :
+                                                       {
+                                                               unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
+
+                                                               if (fieldValue[0] < 0x20 )
+                                                                       iField = fieldValue[0];
+                                                               else
+                                                                       iField = 1;
+
+                                                               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];
+                                                                       unsigned char text[WSP_STANDARD_STR_LEN_MAX];
+                                                                       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);
+                                                                       snprintf( (char*)temp, sizeof(temp), " %s %s", agent, text );
+                                                                       wspHeaderCopyDecodedString( temp, &currentLength, &temper );
+                                                               }
+                                                       }
+                                                       break;
+                                               /* content-disposition */
+                                               case 0x2e :
+                                                       if (fieldValue[0] == 0x80 )
+                                                               strncat( (char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+
+                                                       if (fieldValue[0] == 0x81 )
+                                                               strncat( (char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+
+                                                       if (1 < fieldValueLen) {
+                                                               char* param = NULL;
+                                                               AutoPtr<char> parambuf(&param);
+                                                               wspHeaderDecodeParameter( fieldValue + 1, fieldValueLen - 1, &param );
+
+                                                               if (param != NULL) {
+                                                                       strncat( (char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                                       strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                               }
+                                                       }
+                                                       break;
+                                               /* Profile-diff */
+                                               case 0x36 :
+                                                       temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
+                                                       memcpy( temper, fieldValue, (size_t)fieldValueLen );
+                                                       break;
+                                               /* Profile-Warning */
+                                               case 0x37 :
+                                                       {
+                                                               unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
+
+                                                               snprintf( (char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue ));
+                                                               temp[2] = temp[1];
+                                                               temp[1] = (unsigned char)0x30;
+                                                               temp[3] = '\0';
+                                                               if (fieldValueLen > 1) {
+                                                                       /* copy warn-target - URI */
+                                                                       strncat( (char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1 );
+                                                                       if (fieldValueLen > ( AcStrlen( (char*)(fieldValue + 1)) + 1 )) {
+                                                                               /* copy warn-date */
+                                                                               char* decodedString = NULL;
+                                                                               AutoPtr<char> decodedStringbuf(&decodedString);
+                                                                               wspHeaderDecodeDateValue( fieldValueLen - ( AcStrlen( (char*)(fieldValue + 1)) + 2 ), fieldValue + AcStrlen( (char*)(fieldValue + 1)) + 1, &decodedString );
+                                                                               strncat( (char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1 );
+                                                                       }
+                                                               }
+                                                               strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                                                       }
+                                                       break;
+
+                                               default :
+                                                       break;
+                                       }
+
+                               }
+                       }
+               }
+               /* It deosn't finished decoding yet. */
+               if (( iEncodedHeader < encodedHeaderLen ) && ( fieldCode != 0xff )) {
+                       /* In here, iEncodedHeader already point next field code to be decoded. */
+                       /* If this code is same, then set continueField else add CRLF. */
+                       if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f )) {
+                               strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                               continueField = TRUE;
+                       } else {
+                               strncat( (char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+                               continueField = FALSE;
+                       }
+               } else {
+                       strncat( (char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
+               }
+
+               /* add single header to total headers */
+               strncat( (char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1 );
+               MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper );
+
+       }
+
+
+       MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n" );
+
+       *pHeader = outTemper;
+
+       return;
+
+}
+
+
+unsigned long SmsPluginWapPushHandler::wspHeaderDecodeInteger( unsigned char* data )
+{
+       /* we only can handle max 32bit integer */
+       unsigned long i;
+
+       union {
+               unsigned long integer;
+               unsigned char seg[4];
+       } returner;
+
+       returner.integer = 0;
+
+       if (data[0] < 0x80) {
+               unsigned long IntLen = 0;
+
+               IntLen = (data[0]>0x04) ? 0x04:data[0];
+
+               MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %d\n", data[0], IntLen);
+
+               for (i=0; i<IntLen; i++)
+                       returner.seg[IntLen-( i+1)] = data[i+1];
+
+               return returner.integer;
+       }
+
+       return data[0] & 0x7f;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeQValue( unsigned long length, unsigned char* data, char** pDecodedString)
+{
+       unsigned short qBase = 0;
+       float  qValue;
+
+       *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
+       if (*pDecodedString == NULL) {
+               MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
+               return;
+       }
+
+       memcpy( &qBase, data, (size_t)length );
+       qValue = (float)qBase;
+       if (qValue > 100) {
+               qValue = qValue - 100;
+               qValue = qValue / 1000;
+               sprintf( (char*)*pDecodedString, "; q=%.3f", qValue );
+       } else {
+               /* qValue variable is divided by 100. And it's multiplied by 100.
+                  It's to resolve problem of changed 0.01 of qValue. */
+               unsigned long qValueTemp;
+               qValue = qValue - 1;
+               qValue = qValue / 100;
+               qValueTemp = (unsigned long)(qValue * 100);
+               if (0 == (qValueTemp % 10 ))
+                       sprintf( (char*)*pDecodedString, "; q=%.1f", qValue );
+               else
+                       sprintf( (char*)*pDecodedString, "; q=%.2f", qValue );
+       }
+       return;
+}
+
+
+unsigned long SmsPluginWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length )
+{
+       unsigned long i;
+
+       union {
+               unsigned long integer;
+               unsigned short  seg[4];
+       } returner;
+
+       returner.integer = 0;
+
+       if (length == 1 )
+               return data[0] & 0x7f;
+
+       returner.integer = 0;
+
+       for (i = 0 ; i < length; i++) {
+               returner.integer  =  returner.integer + ( data[i]  *  (0x1  << ( ( length - ( i + 1)) * 8 )));
+               MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %d \n", returner.integer );
+       }
+
+       return returner.integer;
+}
+
+
+char* SmsPluginWapPushHandler::wspExtendedDecodeType(char contentType  )
+{
+       int i = 0;
+
+       while ( wspExtendedContentsType[i].contentsTypeCode != contentType) {
+               if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
+                       return NULL;
+               i++;
+       }
+
+       return (char*)wspExtendedContentsType[i].contentsTypeName;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeParameter( unsigned char* data, unsigned long length, char** pParam)
+{
+       char* param = *pParam;
+
+       unsigned long SecurityTypeCode;
+       unsigned long  i = 0;
+
+       if (data[0] < 0x80) {
+               /* unknown parameter type */
+               param = new char[WSP_STANDARD_STR_LEN_MAX];
+
+               if (param == NULL) {
+                       MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n" );
+                       return;
+               }
+
+               strncpy( (char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
+
+               if (NO_VALUE == data[AcStrlen( (char*)param ) + 1]) {
+                       *pParam = param;
+                       return;
+               }
+
+               strncat( (char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1 );
+               strncat( (char*)param, (char*)(data + AcStrlen( (char*)param )), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
+
+               *pParam = param;
+
+               return;
+       }
+
+       switch ( data[0] & 0x7f )
+       {
+               case 0x00 :
+                       wspHeaderDecodeQValue(  length - 1, data + 1, &param);
+                       break;
+               case 0x01 :
+                       wspHeaderDecodeCharset( length - 1 , data + 1, &param);
+                       break;
+               case 0x02 :
+                       wspHeaderDecodeVersion( length - 1, data + 1, &param);
+                       break;
+                       /* integer */
+               case 0x03 :
+                       //param = (unsigned char *)malloc( (size_t)WSP_STANDARD_STR_LEN_MAX );
+                       param = new char[WSP_STANDARD_STR_LEN_MAX];
+                       if (param == NULL) {
+                               MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
+                               return;
+                       } else {
+                               sprintf( (char*)param, "Type=%i", (int)wspHeaderDecodeInteger( data + 1 ));
+                       }
+                       break;
+               case 0x08 :
+                       param = new char[WSP_STANDARD_STR_LEN_MAX];
+
+                       if (param == NULL) {
+                               MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
+                               return;
+                       } else {
+                               sprintf( (char*)param, "Padding=%i", (int)wspHeaderDecodeInteger( data + 1 ));
+                       }
+                       break;
+               case 0x05 :
+                       param = new char[WSP_STANDARD_STR_LEN_MAX];
+
+                       if (param == NULL) {
+                               MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
+                               return;
+                       } else {
+                               strncpy( (char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
+                               memcpy( param + 5, data + 1, length - 1 );
+                               param[5 + length - 1] = '\0';
+                       }
+                       break;
+               case 0x06 :
+                       param = new char[WSP_STANDARD_STR_LEN_MAX];
+
+                       if (param == NULL) {
+                               MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
+                               return;
+                       } else {
+                               strncpy( (char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
+                               memcpy( param + 9, (char*)(data + 1), (size_t)(length - 1) );
+                               param[9 + length - 1] = '\0';
+                       }
+                       break;
+               case 0x07 :
+                       param = NULL;
+                       /* TBI */
+                       break;
+                       /*OMA Provisioning*/
+               case 0x11 :
+                       param = new char[WSP_STANDARD_STR_LEN_MAX];
+
+                       if (param == NULL) {
+                               MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
+                               return;
+                       } else {
+                               strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
+                               SecurityTypeCode = data[1] & 0x7f;
+                               while (( i < wspSecurityTypeCount ) && ( wspSecurityType[i].SecurityTypeCode != SecurityTypeCode )) i++;
+
+                               if (i < wspSecurityTypeCount) {
+                                       strncat( (char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
+                               }
+
+                               if (0x12 == (data[2] & 0x7f)) {
+                                       strncat( (char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1 );
+                                       memcpy(param+AcStrlen( (char*)param),(char*)(data+3),(size_t)length-3 );
+                               }
+                       }
+                       break;
+
+               default :
+                       param = NULL;
+                       break;
+       }
+
+       *pParam = param;
+       return;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeCharset( unsigned long length, unsigned char* data, char**pDecodedString)
+{
+
+       *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
+
+       if (*pDecodedString == NULL) {
+               MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
+               return;
+       }
+
+       strncpy( (char*)*pDecodedString, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
+
+       if (data[0] > 0x80) {
+               unsigned long code = wspHeaderDecodeInteger(data );
+               unsigned long i = 0;
+               while (wspCharset[i].charsetCode !=  code) {
+                       if (wspCharset[i].charsetCode == 0xffff) {
+                               return;
+                       }
+                       i++;
+               }
+               strncat( (char*)*pDecodedString, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pDecodedString)-1 );
+       } else {
+               unsigned long  lastLen = AcStrlen((char*)*pDecodedString);
+               memcpy( (char*)(*pDecodedString + lastLen), data, (size_t)length );
+               *pDecodedString[length + lastLen] = '\0';
+       }
+
+       return;
+}
+
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeVersion( unsigned long length, unsigned char* data, char** pDecodedString )
+{
+       *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
+
+       if (*pDecodedString == NULL) {
+               MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
+               return;
+       }
+
+       if (length > 1) {
+               /* untyped version */
+               memcpy( *pDecodedString, data, (size_t)length );
+       } else {
+               /* typed version */
+               unsigned char majorVer  = ((data[0] & 0x7f ) >> 4 );
+               unsigned char minorVer = data[0] & 0x0f;
+               sprintf( (char*)*pDecodedString, "level=%u.%u", majorVer, minorVer );
+       }
+
+       return;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeDateValue( unsigned long length, unsigned char* data, char** pDecodedString )
+{
+       time_t  lTime;
+       struct  tm* pTMData;
+
+       MSG_DEBUG("WspLHeaderDecodeDateValue:   \n" );
+
+       *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
+
+       if (*pDecodedString == NULL) {
+               MSG_DEBUG( "WspLHeaderDecodeDateValue:MemAlloc failed\n");
+               return;
+       }
+
+       lTime = wspHeaderDecodeIntegerByLength(data, length);
+
+       pTMData = (struct tm*)gmtime((const time_t* )&lTime);
+
+       if (pTMData == NULL) {
+               MSG_DEBUG( "WspLHeaderDecodeDateValue: Date decode fail \n" );
+               strncpy( (char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
+               return;
+       }
+
+       /* check date value validity */
+       {
+               if (( pTMData->tm_wday > 6 ) || (pTMData->tm_mon > 11 ) || (pTMData->tm_mday >  31 ))
+               {
+                       MSG_DEBUG( "WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData->tm_wday, pTMData->tm_mon, pTMData->tm_mday );
+                       strncpy( (char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
+                       return;
+               }
+       }
+
+#ifdef MSG_FW_FOR_DEBUG
+       /** Date type selection */
+       switch ( wspMachineStatus.dateType )
+       {
+                       /* UNIX asciitime function */
+               case UNIX_DATE_TYPE :
+                       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 :
+                       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.                     */
+                       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 : */
+       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;
+
+}
+
+void SmsPluginWapPushHandler::wspHeaderCopyDecodedString( unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper )
+{
+       unsigned long elementLen = AcStrlen( (char*)szDecodedString );
+       char* temper2 = NULL;
+
+       /**  // CR+LF */
+       *currentLen = *currentLen + elementLen + 2;
+
+       if ( *currentLen > AcStrlen( (char*)* pTemper ) + 2) {
+               temper2 = new char[(*currentLen + 1 )];
+
+               if (temper2 == NULL) {
+                       MSG_DEBUG( "WspLHeaderCopyDecodedString:MemAlloc failed\n");
+                       return;
+               }
+               strncpy( (char*)temper2, (char*)* pTemper, *currentLen);
+               delete[] *pTemper;
+               strncpy( (char*)temper2, (char*)szDecodedString, *currentLen);
+       }
+
+       *pTemper = temper2;
+
+       return;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString )
+{
+       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];
+
+       if (*pDecodedString == NULL) {
+               MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n" );
+               return;
+       }
+
+       /* skip 'basic' code */
+       iField++;
+       memset(authStr, 0x00, sizeof(authStr));
+       snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
+       sscanf((char*)(fieldValue + iField), authStr, userId );
+       iField = iField + AcStrlen( (char*)userId ) + 1;
+       memset(authStr, 0x00, sizeof(authStr));
+       snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(passWd));
+       sscanf( (char*)(fieldValue + iField), authStr, passWd );
+       iField = iField + AcStrlen( (char*)userId ) + 1;
+       snprintf( (char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd );
+
+       return;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString )
+{
+       unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
+       unsigned long iField = 0;
+       char authStr[256];
+
+       *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
+
+       if (*pDecodedString == NULL) {
+               MSG_DEBUG( "WspLHeaderDecodeChallenge:MemAlloc failed\n");
+               return;
+       }
+
+       /* skip 'basic' code */
+       iField++;
+       memset(authStr, 0x00, sizeof(authStr));
+       snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
+       sscanf( (char*)(fieldValue + iField), authStr, userId );
+       iField = iField + AcStrlen( (char*)userId ) + 1;
+
+       snprintf( (char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId );
+
+       return;
+}
+
+
+void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
+{
+       unsigned char  paramString[WSP_STANDARD_STR_LEN_MAX];
+       unsigned char  cacheCode;
+
+       *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
+       if (*pCacheString == NULL) {
+               MSG_DEBUG( "WspLHeaderDecodeCacheControl:MemAlloc failed\n");
+               return;
+       }
+
+       if (1 == fieldValueLen) {
+               /* only one directive */
+               if (fieldValue[0] > 0x8b) {
+                       return; /* It's error detection. can be omitted. */
+               }
+               strncpy( (char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
+               return;
+       }
+
+       if (fieldValue[0] > 0x7f) {
+               /* directive that has parameter */
+               cacheCode = fieldValue[0] & 0x7f;
+               switch ( cacheCode )
+               {
+                               /* field name */
+                               /* no-cache */
+                       case 0x00 :
+                               /* private */
+                       case 0x07 :
+                               if (fieldValue[1] > 0x7f) {
+                                       /* well known field name */
+                                       strncpy( (char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f],WSP_STANDARD_STR_LEN_MAX-1 );
+                                       paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
+                               } else {
+                                       /* unknown field name */
+                                       strncpy( (char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
+                               }
+                               break;
+                               /* secound */
+                               /* max-age */
+                       case 0x02 :
+                               /* max- stale */
+                       case 0x03 :
+                               /* min-fresh */
+                       case 0x04 :
+                               snprintf( (char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger( fieldValue + 1));
+                               break;
+
+                       default :
+                               break;
+
+               }
+               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 */
+
+               unsigned long stringLen;
+               char szString[32];
+               strncpy( (char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
+               stringLen = AcStrlen((char*)*pCacheString );
+
+               if (stringLen + 1 < fieldValueLen) {
+
+                       if (fieldValue[stringLen+ 1] > 0x7f) {
+                               int untyped = (int)wspHeaderDecodeIntegerByLength( fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1 ));
+
+                               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 {
+                               if (fieldValue[fieldValueLen] == 0) {
+                                       strncat( (char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1 );
+                                       strncat( (char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
+                               }
+                       }
+               }
+       }
+
+       return;
+}
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginCallback.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginCallback.h
new file mode 100755 (executable)
index 0000000..70aa3e4
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+* 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 SMS_CDMA_PLUGIN_CALLBACK_H
+#define SMS_CDMA_PLUGIN_CALLBACK_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include <map>
+#include <vector>
+
+extern "C"
+{
+       #include <tapi_common.h>
+       #include <TelSms.h>
+       #include <TelSim.h>
+       #include <TapiUtility.h>
+       #include <ITapiNetText.h>
+       #include <ITapiNetwork.h>
+}
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
+
+void TapiEventMsgIncoming(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 TapiEventMemoryStatus(TapiHandle *handle, int result, void *data, void *user_data);
+
+void TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_data);
+
+void TapiEventDeliveryReportCNF(TapiHandle *handle, int result, void *data, void *user_data);
+
+void TapiEventSetConfigData(TapiHandle *handle, int result, void *data, void *user_data);
+
+void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user_data);
+
+void TapiEventSimRefreshed(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
+
+void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *user_data);
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginCallback
+{
+public:
+       static SmsPluginCallback* instance();
+
+       void registerEvent();
+       void deRegisterEvent();
+
+private:
+       SmsPluginCallback();
+       ~SmsPluginCallback();
+
+       static SmsPluginCallback* pInstance;
+};
+
+#endif //SMS_CDMA_PLUGIN_CALLBACK_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginCodec.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginCodec.h
new file mode 100755 (executable)
index 0000000..cdfd814
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+* 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 SMS_CDMA_PLUGIN_CODEC_H
+#define SMS_CDMA_PLUGIN_CODEC_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "SmsCdmaPluginTypes.h"
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginMsgCodec
+{
+public:
+
+       static SmsPluginMsgCodec* instance();
+
+       static bool checkInvalidPDU(const unsigned char *p_pkg_str, const int p_pkg_len);
+
+       static int encodeMsg(const sms_trans_msg_s *pMsg, unsigned char *p_pkg_str);
+       static int decodeMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_msg_s *p_msg);
+
+private:
+       SmsPluginMsgCodec();
+       ~SmsPluginMsgCodec();
+
+       static SmsPluginMsgCodec* pInstance;
+
+       static int encodeP2PMsg(const sms_trans_p2p_msg_s *p_msg, unsigned char *p_pkg_str);
+       static int encodeAckMsg(const sms_trans_ack_msg_s *p_msg, unsigned char *p_pkg_str);
+       static int encodeCBMsg(const sms_trans_broadcast_msg_s *p_msg, unsigned char *p_pkg_str);
+
+       static int encodeTelesvcMsg(const sms_telesvc_msg_s *p_msg, unsigned char *p_pkg_str);
+
+       static int encodeTelesvcCancelMsg(const sms_telesvc_cancel_s *p_msg, unsigned char *p_pkg_str);
+       static int encodeTelesvcSubmitMsg(const sms_telesvc_submit_s *p_msg, unsigned char *p_pkg_str);
+       static int encodeTelesvcUserAckMsg(const sms_telesvc_user_ack_s *p_msg, unsigned char *p_pkg_str);
+       static int encodeTelesvcReadAckMsg(const sms_telesvc_read_ack_s *p_msg, unsigned char *p_pkg_str);
+       static int encodeTelesvcDeliverReportMsg(const sms_telesvc_report_s *p_msg, unsigned char *p_pkg_str);
+
+       static int decodeP2PMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_p2p_msg_s *p_p2p);
+       static int decodeCBMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_broadcast_msg_s *p_cb);
+       static int decodeAckMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_ack_msg_s *p_ack);
+
+       static void decodeP2PTelesvcMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_msg_s *p_telesvc);
+       static void decodeP2PDeliveryAckMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_deliver_ack_s *p_del_ack);
+       static void decodeP2PSubmitReportMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_report_s *p_sub_report);
+       static void decodeP2PUserAckMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_user_ack_s *p_user_ack);
+       static void decodeP2PReadAckMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_read_ack_s *p_read_ack);
+       static void decodeP2PDeliverMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_deliver_s *p_del);
+       static void decodeP2PSubmitMsg(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_submit_s *p_sub);
+       static void decodeCBBearerData(const unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_msg_s *p_telesvc, bool isCMAS);
+
+       static int encodeUserData(const unsigned char* src, unsigned char *dest, int src_size);
+       static void decodeUserData(unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_userdata_s *p_user);
+       static void decodeCMASData(unsigned char *p_pkg_str, int p_pkg_len, sms_telesvc_cmasdata_s *p_cmas);
+
+       static int decodeTeleId(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_telesvc_id_t *tele_id);
+       static int decodeSvcCtg(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_svc_ctg_t *svc_ctg);
+       static int decodeAddress(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_addr_s *addr);
+       static int decodeSubAddress(const unsigned char *p_pkg_str, int p_pkg_len, sms_trans_sub_addr_s *sub_addr);
+
+       static int decodeMsgId(const unsigned char *p_pkg_str, int pkg_len, sms_trans_msg_id_s *p_msg_id);
+       static void decodeCallBackNum(const unsigned char *p_pkg_str, int pkg_len, sms_telesvc_addr_s *p_callback);
+       static int decodeAbsTime(const unsigned char *p_pkg_str, sms_time_abs_s *p_time_abs);
+       static sms_message_type_t findMsgType(const unsigned char *p_pkg_str, int pkg_len);
+};
+
+#endif //SMS_CDMA_PLUGIN_CODEC_H
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginEventHandler.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginEventHandler.h
new file mode 100755 (executable)
index 0000000..2abf4c9
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+* 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 SMS_CDMA_PLUGIN_EVENT_HANDLER_H
+#define SMS_CDMA_PLUGIN_EVENT_HANDLER_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include <string>
+#include <map>
+#include <vector>
+#include <list>
+
+using namespace std;
+
+#include "MsgMutex.h"
+#include "MsgTextConvert.h"
+#include "MsgPluginInterface.h"
+#include "SmsCdmaPluginTypes.h"
+
+
+/*==================================================================================================
+                                     VARIABLES AND DEFINES
+==================================================================================================*/
+struct wap_data_s
+{
+       int     length;
+       char data[SMS_MAX_USER_DATA_LEN+1];
+};
+
+typedef map<unsigned char, wap_data_s> wapDataMap;
+
+typedef struct _sms_wap_msg_s
+{
+       unsigned short  msgId;
+       unsigned char           totalSeg;
+       unsigned char           segNum;
+} sms_wap_msg_s;
+
+typedef struct _sms_wap_info_s
+{
+       unsigned short  msgId;
+       unsigned char           totalSeg;
+       unsigned char           segNum;
+
+       unsigned int            totalSize;
+       wapDataMap                      data;
+} sms_wap_info_s;
+
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginEventHandler
+{
+public:
+       static SmsPluginEventHandler* instance();
+
+       void registerListener(MSG_PLUGIN_LISTENER_S *pListener);
+       void handleSentStatus(msg_network_status_t NetStatus);
+       void handleMsgIncoming(sms_trans_p2p_msg_s *p_p2p_msg);
+       void handleCbMsgIncoming(sms_trans_broadcast_msg_s *p_cb_msg);
+       void handleWapMsgIncoming(sms_trans_p2p_msg_s *p_p2p_msg);
+
+       void handleResendMessage(void);
+
+       msg_error_t callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo);
+       msg_error_t callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo);
+
+       void convertTpduToMsginfo(sms_trans_p2p_msg_s *p_p2p_msg, MSG_MESSAGE_INFO_S *p_msg_info);
+       void convertTpduToMsginfo(sms_trans_broadcast_msg_s *p_cb_msg, MSG_MESSAGE_INFO_S *p_msg_info);
+
+       void SetSentInfo(sms_sent_info_s *pSentInfo);
+
+       void setDeviceStatus();
+       bool getDeviceStatus();
+       void setNeedInitConfig(bool bNeeded);
+       bool getNeedInitConfig();
+
+       void handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen);
+       void handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen);
+       void handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *app_id, char *content_type);
+
+private:
+       SmsPluginEventHandler();
+       virtual ~SmsPluginEventHandler();
+
+       static SmsPluginEventHandler* pInstance;
+
+       MSG_PLUGIN_LISTENER_S listener;
+
+       sms_sent_info_s sentInfo;
+
+       bool devStatus;
+       bool bNeedInitConfig;
+
+       Mutex mx;
+       CndVar cv;
+       vector<sms_wap_info_s> wapList;
+
+       void convertDeliverMsgToMsgInfo(sms_telesvc_deliver_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info);
+       void convertCMASMsgToMsgInfo(sms_telesvc_deliver_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info);
+       void convertAckMsgToMsgInfo(sms_telesvc_deliver_ack_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info);
+       void convertReportMsgToMsgInfo(sms_telesvc_report_s *p_deliver, MSG_MESSAGE_INFO_S *p_msg_info);
+
+       msg_encode_type_t getEncodeType(sms_encoding_type_t encode_type);
+
+       unsigned short checkWapMsg(sms_wap_msg_s *pMsg, sms_telesvc_userdata_s *pUserdata);
+       int MakeWapUserData(unsigned short msgId, char **ppTotalData);
+
+       bool checkCbOpt(sms_trans_svc_ctg_t svc_ctg);
+       std::list<MSG_CB_DUPLICATE_S> duplicateCb;
+
+};
+
+#endif //SMS_CDMA_PLUGIN_EVENT_HANDLER_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginMain.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginMain.h
new file mode 100755 (executable)
index 0000000..2ff6bd8
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+* 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 SMS_CDMA_PLUGIN_MAIN_H
+#define SMS_CDMA_PLUGIN_MAIN_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "SmsCdmaPluginTypes.h"
+#include "MsgPluginInterface.h"
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+msg_error_t SmsPlgInitialize();
+
+msg_error_t SmsPlgFinalize();
+
+msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener);
+
+msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo);
+
+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 SmsPlgGetSimMessage(msg_sim_id_t SimMsgId);
+
+msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId);
+
+msg_error_t SmsPlgSetMemoryStatus(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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //SMS_CDMA_PLUGIN_MAIN_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginParamCodec.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginParamCodec.h
new file mode 100755 (executable)
index 0000000..bf4fd61
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+* 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 SMS_CDMA_PLUGIN_PARAMCODEC_H
+#define SMS_CDMA_PLUGIN_PARAMCODEC_H
+
+
+/*==================================================================================================
+                                                                               INCLUDE FILES
+==================================================================================================*/
+#include "SmsCdmaPluginTypes.h"
+
+
+/*==================================================================================================
+                                                                               CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginParamCodec
+{
+public:
+
+       static SmsPluginParamCodec* instance();
+
+       static int convertDigitToBcd(char *pDigit, int DigitLen, unsigned char *pBcd);
+       static int convertBcdToDigit(const unsigned char *pBcd, int BcdLen, char *pDigit);
+       static int convertDigitToDTMF(const char *pDigit, int DigitLen, int startBit, unsigned char *pDtmf);
+       static int convertDTMFToDigit(const unsigned char *pDtmf, int DtmfLen, int startBit, char *pDigit);
+
+private:
+       SmsPluginParamCodec();
+       virtual ~SmsPluginParamCodec();
+
+       static SmsPluginParamCodec* pInstance;
+
+       static bool isDtmfNumber(const char *pDigit, int DigitLen);
+};
+
+#endif /*SMS_CDMA_PLUGIN_PARAMCODEC_H*/
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginSetting.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginSetting.h
new file mode 100755 (executable)
index 0000000..c31fb9d
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+* 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 SMS_CDMA_PLUGIN_SETTING_H
+#define SMS_CDMA_PLUGIN_SETTING_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "MsgMutex.h"
+#include "MsgSettingTypes.h"
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginSetting
+{
+public:
+       static SmsPluginSetting* instance();
+
+       void setSimChangeStatus();
+
+       void setConfigData(const MSG_SETTING_S *pSetting);
+       void getConfigData(MSG_SETTING_S *pSetting);
+       void getMeImei(char *pImei);
+
+       void setCbConfigEvent(const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess);
+
+       void setResultImei(bool bResult, char *pImei);
+       void setResultFromEvent(bool bResult);
+       void setResultFromSim(bool bResult);
+
+       void setMwiInfo(MSG_SUB_TYPE_T type, int count);
+       void SimRefreshCb();
+
+       bool getUpdateVoicemailByMdn();
+
+private:
+       SmsPluginSetting();
+       ~SmsPluginSetting();
+
+       void updateSimStatus();
+
+       void initConfigData();
+       static void* init_config_data(void *data);
+       static void* initSimInfo(void *data);
+
+       msg_error_t addCbOpt(MSG_CBMSG_OPT_S *pCbOpt);
+       void getCbOpt(MSG_SETTING_S *pSetting);
+
+       void setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt);
+       bool setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt);
+       bool getCbConfig(MSG_CBMSG_OPT_S *pCbOpt);
+
+       bool getMsisdnInfo(void);
+
+       bool getResultImei(char *pImei);
+
+       bool getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt);
+
+       bool getResultFromSim();
+
+       static SmsPluginSetting* pInstance;
+
+       MSG_SMSC_DATA_S         smscData;
+       MSG_CBMSG_OPT_S         cbOpt;
+
+       bool            bTapiResult;
+       bool            bUpdateVoicemailByMdn;
+
+       char    meImei[MAX_ME_IMEI_LEN + 1];
+
+       Mutex mx;
+       CndVar cv;
+};
+
+#endif //SMS_CDMA_PLUGIN_SETTING_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginStorage.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginStorage.h
new file mode 100755 (executable)
index 0000000..85910bd
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+* 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 SMS_CDMA_PLUGIN_STORAGE_H
+#define SMS_CDMA_PLUGIN_STORAGE_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "MsgMutex.h"
+
+#include "MsgStorageTypes.h"
+#include "SmsCdmaPluginTypes.h"
+#include "MsgInternalTypes.h"
+#include "MsgSqliteWrapper.h"
+#include <list>
+
+extern "C"
+{
+       #include <tapi_common.h>
+       #include <TelSms.h>
+       #include <TapiUtility.h>
+       #include <ITapiNetText.h>
+}
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+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 checkMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
+       msg_error_t addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo);
+       msg_error_t deleteSmsMessage(msg_message_id_t msgId);
+       msg_error_t addSmsSendOption(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo);
+
+       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();
+
+       static SmsPluginStorage* pInstance;
+
+       MSG_MESSAGE_INFO_S msgInfo;
+       MSG_ADDRESS_INFO_S addrInfo;
+
+       std::list<PUSH_APPLICATION_INFO_S> pushAppInfoList;
+};
+
+#endif //SMS_CDMA_PLUGIN_STORAGE_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginTransport.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginTransport.h
new file mode 100755 (executable)
index 0000000..38169ea
--- /dev/null
@@ -0,0 +1,76 @@
+
+/*
+* 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 SMS_CDMA_PLUGIN_TRANSPORT_H
+#define SMS_CDMA_PLUGIN_TRANSPORT_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "MsgInternalTypes.h"
+#include "MsgMutex.h"
+#include "SmsCdmaPluginTypes.h"
+
+extern "C"
+{
+       #include <TelSat.h>
+}
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginTransport
+{
+public:
+       static SmsPluginTransport* instance();
+
+       void submitRequest(sms_request_info_s *pReqInfo);
+       void sendDeliverReport(msg_error_t err, sms_trans_p2p_msg_s *p_p2p_msg);
+
+       void setNetStatus(sms_network_status_t sentStatus);
+
+private:
+       SmsPluginTransport();
+       ~SmsPluginTransport();
+
+       static SmsPluginTransport* pInstance;
+
+       unsigned char getMsgRef();
+       unsigned char getSeqNum();
+       unsigned char getSubmitMsgId();
+
+       sms_network_status_t getNetStatus();
+
+       void convertMsgInfoToTelesvcMsg(const MSG_MESSAGE_INFO_S *pMsgInfo, sms_trans_msg_s *pMsg);
+       void convertMsgInfoToPtp(const MSG_MESSAGE_INFO_S *pMsgInfo, sms_trans_p2p_msg_s *pPtpMsg);
+       void convertMsgInfoToSubmit(const MSG_MESSAGE_INFO_S *pMsgInfo, sms_telesvc_submit_s *pSubmit);
+
+       unsigned char           msgRef;
+       unsigned char           msgSeqNum;
+       unsigned char           msgSubmitId;
+
+       unsigned char           msgRef8bit;
+       unsigned short          msgRef16bit;
+
+       sms_network_status_t    curStatus;
+
+       Mutex mx;
+       CndVar cv;
+};
+
+#endif //SMS_PLUGIN_TRANSPORT_H
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginTypes.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginTypes.h
new file mode 100755 (executable)
index 0000000..e15039d
--- /dev/null
@@ -0,0 +1,1011 @@
+/*
+* 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 "MsgTypes.h"
+#include "MsgInternalTypes.h"
+
+#ifndef SMS_CDMA_PLUGIN_TYPES_H
+#define SMS_CDMA_PLUGIN_TYPES_H
+
+#define SMS_MAX_MESSAGE_ID                     65536
+#define SMS_SEQ_NUM_MAX                                64
+#define SMS_MAX_USER_DATA_LEN          160
+#define SMS_MAX_SUBMIT_MESSAGE_ID      256
+
+#define SMS_TRANS_ADDRESS_MAX_LEN      256
+
+#define SMS_MAX_NUMBER_OF_ACK          8
+
+#define SMS_PUSH_XML_HREF_TAG          "href"
+#define SMS_PUSH_XML_SI_ID_TAG         "si-id"
+#define SMS_PUSH_XML_CREATED_TAG       "created"
+#define SMS_PUSH_XML_EXPIRES_TAG       "si-expires"
+#define SMS_PUSH_XML_ACTION_TAG                "action"
+
+#define SMS_PUSH_XML_INVAL_OBJ         "invalidate-object"
+#define SMS_PUSH_XML_INVAL_SVC         "invalidate-service"
+#define SMS_PUSH_XML_CO_URI                    "uri"
+
+
+typedef unsigned char sms_wap_app_code_t;      /* _sms_wap_app_code_e */
+
+typedef struct _SMS_WSP_CONTENTS_TYPE_S
+{
+       char*         contentsTypeName;
+       unsigned char contentsTypeCode;
+} SMS_WSP_CONTENTS_TYPE_S;
+
+
+typedef struct _SMS_WSP_CHARSET_S
+{
+       char*  charsetName;
+       unsigned short charsetCode;
+} SMS_WSP_CHARSET_S;
+
+
+typedef struct _SMS_WAP_UNREGISTER_CONTENTS_TYPE_S
+{
+       char*         contentsTypeName;
+       unsigned short contentsTypeCode;
+} SMS_WAP_UNREGISTER_CONTENTS_TYPE_S;
+
+
+typedef struct _SMS_WSP_LANGUAGE_S
+{
+       char*         languageName;
+       unsigned char languageCode;
+} SMS_WSP_LANGUAGE_S;
+
+
+typedef struct _SMS_WSP_HEADER_PARAMETER_S
+{
+       char*         parameterToken;
+       unsigned int parameterCode;
+} SMS_WSP_HEADER_PARAMETER_S;
+
+
+typedef struct _SMS_WSP_METHOD_TYPE_S
+{
+       char*         methodName;
+       unsigned char methodCode;
+} SMS_WSP_METHOD_TYPE_S;
+
+
+typedef struct _SMS_WSP_SECURITY_TYPE_S
+{
+       char*         SecurityTypeName;
+       unsigned char SecurityTypeCode;
+}SMS_WSP_SECURITY_TYPE_S;
+
+typedef struct
+{
+       msg_request_id_t                        reqId;          /**< Indicates the request ID, which is unique. When applications submit a request to the framework, this value will be set by the framework. */
+       MSG_MESSAGE_INFO_S                      msgInfo;        /**< Indicates the message structure to be sent by applications. */
+       MSG_SENDINGOPT_INFO_S           sendOptInfo;
+} sms_request_info_s;
+
+
+typedef struct _sms_sent_info_s
+{
+       sms_request_info_s              reqInfo;                /**< Indicates the corresponding request structure. */
+       bool                                            bLast;
+} sms_sent_info_s;
+
+
+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,
+       SMS_NETWORK_SEND_FAIL_UNKNOWN_SUBSCRIBER,
+       SMS_NETWORK_SEND_FAIL_MS_DISABLED,
+       SMS_NETWORK_SEND_FAIL_NETWORK_NOT_READY,
+};
+
+enum _sms_wap_app_code_e
+{
+       SMS_WAP_APPLICATION_DEFAULT = 0x00,
+
+       SMS_WAP_APPLICATION_PUSH_SI,
+       SMS_WAP_APPLICATION_PUSH_SIC,
+
+       SMS_WAP_APPLICATION_PUSH_SL,
+       SMS_WAP_APPLICATION_PUSH_SLC,
+
+       SMS_WAP_APPLICATION_PUSH_CO,
+       SMS_WAP_APPLICATION_PUSH_COC,
+
+       SMS_WAP_APPLICATION_MMS_UA,
+
+       SMS_WAP_APPLICATION_PUSH_SIA,
+
+       SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP,
+       SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML,
+       SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION,
+       SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION,
+       SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML,
+
+       SMS_WAP_APPLICATION_LOC_UA_WBXML,
+       SMS_WAP_APPLICATION_LOC_UA_XML,
+
+       SMS_WAP_APPLICATION_DRM_UA_XML,
+       SMS_WAP_APPLICATION_DRM_UA_MESSAGE,
+       SMS_WAP_APPLICATION_DRM_UA_CONETENT,
+       SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML,
+       SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML,
+       SMS_WAP_APPLICATION_DRM_V2_RO_XML,
+       SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML,
+       SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML,
+       SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML,
+
+       SMS_WAP_APPLICATION_PUSH_PROVISIONING,
+       SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML,
+       SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML,
+
+       SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS,
+       SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS,
+       SMS_WAP_APPLICATION_PUSH_SYNCSET_WBXML,
+       SMS_WAP_APPLICATION_PUSH_SYNCSET_XML,
+
+       SMS_WAP_APPLICATION_PUSH_EMAIL_XML,
+       SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML,
+
+       SMS_WAP_APPLICATION_PUSH_IMPS_CIR,
+
+       SMS_WAP_APPLICATION_PUSH_WAP_WMLC,
+
+       SMS_WAP_APPLICATION_WML_UA,
+       SMS_WAP_APPLICATION_WTA_UA,
+
+       SMS_WAP_APPLICATION_PUSH_SYNCML,
+       SMS_WAP_APPLICATION_LOC_UA,
+       SMS_WAP_APPLICATION_SYNCML_DM,
+       SMS_WAP_APPLICATION_PUSH_EMAIL,
+
+       SMS_OMA_APPLICATION_ULP_UA,
+       SMS_OMA_APPLICATION_DLOTA_UA,
+
+       SMS_WAP_APPLICATION_LBS,
+};
+
+
+typedef unsigned char  sms_network_status_t;   /* _sms_network_status_e */
+
+/********************************************************************************/
+/*                                                             TELESERVICE LAYER                                                               */
+/********************************************************************************/
+
+
+typedef bool                           sms_digit_mode_t;                       /* _sms_digit_mode_e */
+
+typedef bool                           sms_number_mode_t;                      /* _sms_number_mode_e */
+
+typedef unsigned char          sms_number_type_t;                      /* _sms_number_type_e */
+
+typedef unsigned char          sms_number_plan_t;                      /* _sms_number_plan_e */
+
+
+typedef enum _sms_message_type_e
+{
+       SMS_TYPE_RESERVED               = 0x00,         // reserved
+       SMS_TYPE_DELIVER,                                       // mobile-terminated only
+       SMS_TYPE_SUBMIT,                                        // mobile-originated only
+       SMS_TYPE_CANCEL,                                        // mobile-originated only
+       SMS_TYPE_DELIVERY_ACK,                          // mobile-terminated only
+       SMS_TYPE_USER_ACK,                                      // either direction
+       SMS_TYPE_READ_ACK,                                      // either direction
+       SMS_TYPE_DELIVER_REPORT,                        // mobile-originated only
+       SMS_TYPE_SUBMIT_REPORT  = 0x08,         // mobile-terminated only
+       SMS_TYPE_MAX_VALUE
+}sms_message_type_t;
+
+
+typedef enum _sms_alert_option_e
+{
+       SMS_ALERT_NO_ALERT                              = 0,
+       SMS_ALERT_DEFAULT_ALERT,
+       SMS_ALERT_VIBRATE_ONCE,
+       SMS_ALERT_VIBRATE_REPEAT,
+       SMS_ALERT_VISUAL_ONCE,
+       SMS_ALERT_VISUAL_REPEAT,
+       SMS_ALERT_LOW_PRIORITY_ONCE,
+       SMS_ALERT_LOW_PRIORITY_REPEAT,
+       SMS_ALERT_MEDIUM_PRIORITY_ONCE,
+       SMS_ALERT_MEDIUM_PRIORITY_REPEAT,
+       SMS_ALERT_HIGH_PRIORITY_ONCE,
+       SMS_ALERT_HIGH_PRIORITY_REPEAT,
+       SMS_ALERT_RESERVED
+}sms_alert_option_t;
+
+
+typedef enum _sms_language_type_e {
+       SMS_LAN_UNKNOWN,
+       SMS_LAN_ENGLISH,
+       SMS_LAN_FRENCH,
+       SMS_LAN_SPANISH,
+       SMS_LAN_JAPANESE,
+       SMS_LAN_KOREAN,
+       SMS_LAN_CHINESE,
+       SMS_LAN_HEBREW,
+}sms_language_type_t;
+
+
+typedef enum _sms_priority_indicator_e
+{
+       SMS_PRIORITY_NORMAL                             = 0x00,
+       SMS_PRIORITY_INTERACTIVE,
+       SMS_PRIORITY_URGENT,
+       SMS_PRIORITY_EMERGENCY
+}sms_priority_indicator_t;
+
+
+typedef enum _sms_privacy_indicator_e
+{
+       SMS_PRIVACY_NOT_RESTRICTED              = 0x00,
+       SMS_PRIVACY_RESTRICTED,
+       SMS_PRIVACY_CONFIDENTIAL,
+       SMS_PRIVACY_SECRET
+}sms_privacy_indicator_t;
+
+
+typedef enum _sms_alert_priority_e
+{
+       SMS_ALERT_MOBILE_DEFAULT                = 0x00,
+       SMS_ALERT_LOW_PRIORITY,
+       SMS_ALERT_MEDIUM_PRIORITY,
+       SMS_ALERT_HIGH_PRIORITY
+}sms_alert_priority_t;
+
+
+typedef enum _sms_display_mode_e
+{
+       SMS_DISPLAY_IMMEDIATE                   = 0x00,
+       SMS_DISPLAY_DEFAULT_SETTING,
+       SMS_DISPLAY_USER_INVOKE,
+       SMS_DISPLAY_RESERVED
+}sms_display_mode_t;
+
+
+typedef enum _sms_encoding_type_e
+{
+       SMS_ENCODE_OCTET        = 0x0,
+       SMS_ENCODE_EPM  = 0x1,  /*IS-91 Extended Protocol Message*/
+       SMS_ENCODE_7BIT_ASCII   = 0x2,
+       SMS_ENCODE_IA5  = 0x3,
+       SMS_ENCODE_UNICODE      = 0x4,
+       SMS_ENCODE_SHIFT_JIS    = 0x5,
+       SMS_ENCODE_KOREAN       = 0x6,
+       SMS_ENCODE_LATIN_HEBREW = 0x7,
+       SMS_ENCODE_LATIN        = 0x8,
+       SMS_ENCODE_GSM7BIT      = 0x9,
+       SMS_ENCODE_GSMDCS = 0xa,
+       SMS_ENCODE_EUCKR = 0x10,
+       SMS_ENCODE_RESERVED
+}sms_encoding_type_t;
+
+
+typedef enum _sms_relative_time_e
+{
+       SMS_REL_TIME_5_MINS                     = 0,
+       SMS_REL_TIME_12_HOURS           = 143,
+       SMS_REL_TIME_1_DAY                      = 167,
+       SMS_REL_TIME_2_DAYS                     = 168,
+       SMS_REL_TIME_3_DAYS                     = 169,
+       SMS_REL_TIME_1_WEEK                     = 173,
+       SMS_REL_TIME_INDEFINITE         = 245,
+       SMS_REL_TIME_IMMEDIATE          = 246,
+       SMS_REL_TIME_ACTIVE                     = 247,
+       SMS_REL_TIME_REGISTRATION       = 248,
+       SMS_REL_TIME_RESERVED
+}sms_relative_time_t;
+
+
+typedef enum _sms_status_code_e
+{
+       /* ERROR_CLASS = '00' (no error) */
+       SMS_STATUS_ACCEPTED                             = 0x00,
+       SMS_STATUS_DEPOSITED                    = 0x01,
+       SMS_STATUS_DELIVERED                    = 0x02,
+       SMS_STATUS_CANCELLED                    = 0x03,
+
+       /* ERROR_CLASS = '10' (temporary condition) */
+       SMS_STATUS_TEMP_NETWORK_CONGESTION      = 0x84,
+       SMS_STATUS_TEMP_NETWORK_ERROR           = 0x85,
+       SMS_STATUS_TEMP_UNKNOWN_ERROR           = 0x9F,
+
+       /* ERROR_CLASS = '11' (permanent condition) */
+       SMS_STATUS_PERMANENT_NETWORK_CONGESTION = 0xC4,
+       SMS_STATUS_PERMANENT_NETWORK_ERROR              = 0xC5,
+       SMS_STATUS_PERMANENT_CANCEL_FAILED              = 0xC6,
+       SMS_STATUS_PERMANENT_BLOCKED_DESTINATION        = 0xC7,
+       SMS_STATUS_PERMANENT_TEXT_TOO_LONG              = 0xC8,
+       SMS_STATUS_PERMANENT_DUPLICATE_MESSAGE  = 0xC9,
+       SMS_STATUS_PERMANENT_INVALID_DESTINATION        = 0xCA,
+       SMS_STATUS_PERMANENT_MESSAGE_EXPIRED    = 0xCD,
+       SMS_STATUS_PERMANENT_UNKNOWN_ERROR              = 0xDF,
+
+}sms_status_code_t;
+
+
+typedef enum _sms_cmae_category_e {
+       SMS_CMAE_CTG_GEO                                = 0x00,
+       SMS_CMAE_CTG_MET                                = 0x01,
+       SMS_CMAE_CTG_SAFETY                     = 0x02,
+       SMS_CMAE_CTG_SECURITY           = 0x03,
+       SMS_CMAE_CTG_RESCUE                     = 0x04,
+       SMS_CMAE_CTG_FIRE                               = 0x05,
+       SMS_CMAE_CTG_HEALTH                     = 0x06,
+       SMS_CMAE_CTG_ENV                                = 0x07,
+       SMS_CMAE_CTG_TRANSPORT          = 0x08,
+       SMS_CMAE_CTG_INFRA                      = 0x09,
+       SMS_CMAE_CTG_CBRNE                      = 0x0a,
+       SMS_CMAE_CTG_OTHER                      = 0x0b,
+       SMS_CMAE_CTG_RESERVED,
+}sms_cmae_category_t;
+
+
+typedef enum _sms_cmae_response_type_e {
+       SMS_CMAE_RESP_TYPE_SHELTER                              = 0x00,
+       SMS_CMAE_RESP_TYPE_EVACUATE                             = 0x01,
+       SMS_CMAE_RESP_TYPE_PREPARE                              = 0x02,
+       SMS_CMAE_RESP_TYPE_EXECUTE                              = 0x03,
+       SMS_CMAE_RESP_TYPE_MONITOR                              = 0x04,
+       SMS_CMAE_RESP_TYPE_AVOID                                        = 0x05,
+       SMS_CMAE_RESP_TYPE_ASSESS                               = 0x06,
+       SMS_CMAE_RESP_TYPE_NONE                                 = 0x07,
+       SMS_CMAE_RESP_TYPE_RESERVED,
+}sms_cmae_response_type_t;
+
+
+typedef enum _sms_cmae_severity_e {
+       SMS_CMAE_SEVERITY_EXTREME                       = 0x0,
+       SMS_CMAE_SEVERITY_SEVERE                                = 0x1,
+       SMS_CMAE_SEVERITY_RESERVED,
+}sms_cmae_severity_t;
+
+
+typedef enum _sms_cmae_urgency_e {
+       SMS_CMAE_URGENCY_IMMEDIATE                      = 0x0,
+       SMS_CMAE_URGENCY_EXPECTED                       = 0x1,
+       SMS_CMAE_URGENCY_RESERVED,
+}sms_cmae_urgency_t;
+
+
+typedef enum _sms_cmae_certainty_e {
+       SMS_CMAE_CERTAINTY_OBSERVED                     = 0x0,
+       SMS_CMAE_CERTAINTY_LIKELY                       = 0x1,
+       SMS_CMAE_CERTAINTY_RESERVED,
+}sms_cmae_certainty_t;
+
+
+typedef enum _sms_cmae_alert_handle_e {
+       SMS_CMAE_ALERT_PRESIDENTIAL                             = 0x00,
+       SMS_CMAE_ALERT_EXTREME                                  = 0x01,
+       SMS_CMAE_ALERT_SEVERE                                   = 0x02,
+       SMS_CMAE_ALERT_AMBER                                            = 0x03,
+       SMS_CMAE_ALERT_RESERVED,
+}sms_cmae_alert_handle_t;
+
+
+enum _sms_bearer_sub_param_e
+{
+       SMS_BEARER_MESSAGE_IDENTIFIER                           = 0x00,
+       SMS_BEARER_USER_DATA                                            = 0x01,
+       SMS_BEARER_USER_RESPONSE_CODE                           = 0x02,
+       SMS_BEARER_MSG_CENTER_TIME_STAMP                        = 0x03,
+       SMS_BEARER_VALIDITY_PERIOD_ABSOLUTE                     = 0x04,
+       SMS_BEARER_VALIDITY_PERIOD_RELATIVE                     = 0x05,
+       SMS_BEARER_DEFERRED_DELIVERY_TIME_ABSOLUTE      = 0x06,
+       SMS_BEARER_DEFERRED_DELIVERY_TIME_RELATIVE      = 0x07,
+       SMS_BEARER_PRIORITY_INDICATOR                           = 0x08,
+       SMS_BEARER_PRIVACY_INDICATOR                            = 0x09,
+       SMS_BEARER_REPLY_OPTION                                         = 0x0A,
+       SMS_BEARER_NUMBER_OF_MESSAGES                           = 0x0B,
+       SMS_BEARER_ALERT_ON_MSG_DELIVERY                        = 0x0C,
+       SMS_BEARER_LANGUAGE_INDICATOR                           = 0x0D,
+       SMS_BEARER_CALLBACK_NUMBER                                      = 0x0E,
+       SMS_BEARER_MSG_DISPLAY_MODE                                     = 0x0F,
+       SMS_BEARER_MULTI_ENCODING_USER_DATA                     = 0x10,
+       SMS_BEARER_MSG_DEPOSIT_INDEX                            = 0x11,
+       SMS_BEARER_SVC_CATEGORY_PROGRAM_DATA            = 0x12,
+       SMS_BEARER_SVC_CATEGORY_PROGRAM_RESULT          = 0x13,
+       SMS_BEARER_MESSAGE_STATUS                                       = 0x14,
+       SMS_BEARER_TP_FAILURE_CAUSE                                     = 0x15,
+       SMS_BEARER_ENHANCED_VMN                                         = 0x16,
+       SMS_BEARER_ENHANCED_VMN_ACK                                     = 0x17,
+       SMS_BEARER_MAX_VALUE
+};
+
+
+enum _sms_svc_ctg_result_e
+{
+       SMS_SVC_RESULT_SUCCESS                                  = 0x00,
+       SMS_SVC_RESULT_MEMORY_LIMIT_EXCEEDED,
+       SMS_SVC_RESULT_LIMIT_EXCEEDED,
+       SMS_SVC_RESULT_ALREADY_PROGRAMMED,
+       SMS_SVC_RESULT_NOT_PREVIOUSLY_PROGRAMMED,
+       SMS_SVC_RESULT_INVALID_MAX_MESSAGES,
+       SMS_SVC_RESULT_INVALID_ALERT_OPTION,
+       SMS_SVC_RESULT_INVALID_SVC_CTG_NAME,
+       SMS_SVC_RESULT_INSPECIFIED_PROGRAMMING_FAILURE,
+       SMS_SVC_RESULT_RESERVED
+};
+
+enum _SMS_TIME_FORMAT_E {
+       SMS_TIME_EMPTY = 0,
+       SMS_TIME_RELATIVE       ,
+       SMS_TIME_ABSOLUTE
+};
+
+
+enum _sms_tp_failure_cause_e {
+       /*      0x00 ~ 0x7f reserved                    */
+       SMS_TP_CAUSE_RESERVED,
+
+       /*      0x80 ~ 0x8f TP-PID errors       */
+       SMS_TP_CAUSE_TELEMATIC_INTERWORKING_NOT_SUPPORTED       = 0x80,
+       SMS_TP_CAUSE_SHORT_MSG_TYPE_0_NOT_SUPPORTED                     = 0x81,
+       SMS_TP_CAUSE_CANNOT_REPLACE_SHORT_MSG                                   = 0x82,
+       SMS_TP_CAUSE_UNSPECIFIED_TP_PID_ERROR                                   = 0x8f,
+
+       /* 0x90 ~ 0x9f TP-DCS errors    */
+       SMS_TP_CAUSE_DCS_NOT_SPPORTED                                           = 0x90,
+       SMS_TP_CAUSE_MSG_CLASS_NOT_SUPPORTED                            = 0x91,
+       SMS_TP_CAUSE_UNSPECIFIED_TP_DCS_ERROR                           = 0x9f,
+
+       /* 0xa0 ~ 0xaf TP-Command Errors        */
+       SMS_TP_CAUSE_CMD_CANNOT_BE_ACTIONED                             = 0xa0,
+       SMS_TP_CAUSE_CMD_UNSUPPORTED                                            = 0xa1,
+       SMS_TP_CAUSE_UNSPECIFIED_TP_CMD_ERROR                           = 0xaf,
+
+       SMS_TP_CAUSE_TPDU_NOT_SUPPORTED                                         = 0xb0,
+
+       SMS_TP_CAUSE_SC_BUSY                                                                    = 0xc0,
+       SMS_TP_CAUSE_NO_SC_SUBCRIPTION                                          = 0xc1,
+       SMS_TP_CAUSE_SC_SYSTEM_FAILURE                                          = 0xc2,
+       SMS_TP_CAUSE_INVALID_SME_ADDRESS                                        = 0xc3,
+       SMS_TP_CAUSE_DESTINATION_SME_BARRED                             = 0xc4,
+       SMS_TP_CAUSE_SM_REJECTED_DUPLICATE_SM                           = 0xc5,
+       SMS_TP_CAUSE_TP_VPF_NOT_SUPPORTED                                       = 0xc6,
+       SMS_TP_CAUSE_TP_VP_NOT_SUPPORTED                                        = 0xc7,
+
+       SMS_TP_CAUSE_SIM_SMS_STORAGE_FULL                                       = 0xd0,
+       SMS_TP_CAUSE_NO_SMS_STORAGE_CAPABILITY_IN_SIM           = 0xd1,
+       SMS_TP_CAUSE_ERROR_IN_MS                                                                = 0xd2,
+       SMS_TP_CAUSE_MEMORY_CAPACITY_EXCEEDED                           = 0xd3,
+       SMS_TP_CAUSE_SIM_APPLICATION_TOOLKIT_BUSY                       = 0xd4,
+       SMS_TP_CAUSE_SIM_DATA_DOWNLOAD_ERROR                            = 0xd5,
+
+       /* 0xe0 ~ 0xfe Values specific to an application        */
+       SMS_TP_CAUSE_SPECIFIC_TO_APPLICATION_MIN                        = 0xe0,
+       SMS_TP_CAUSE_SPECIFIC_TO_APPLICATION_MAX                        = 0xfe,
+
+       SMS_TP_CAUSE_UNSPECIFIED_ERROR_CAUSE                            = 0xff
+};
+
+
+typedef struct _sms_trans_msg_id_s
+{
+       unsigned short          msg_id;
+       bool                            header_ind;
+}sms_trans_msg_id_s;
+
+
+typedef struct _sms_telesvc_addr_s
+{
+       sms_digit_mode_t        digit_mode;
+       sms_number_type_t       number_type;
+       sms_number_plan_t       number_plan;
+       unsigned int            addr_len;
+       char                            szData[SMS_TRANS_ADDRESS_MAX_LEN + 1];
+}sms_telesvc_addr_s;
+
+
+typedef struct _sms_reply_option_s
+{
+       bool    user_ack_req;
+       bool    deliver_ack_req;
+       bool    read_ack_req;
+       bool    report_req;
+}sms_reply_option_s;
+
+
+typedef struct _sms_time_relative_s
+{
+       sms_relative_time_t             rel_time;
+}sms_time_rel_s;
+
+typedef struct _sms_time_stamp_s
+{
+       unsigned char           year;           // range 00-99 (96~99 : 19xx, 00~95 : 20xx)
+       unsigned char           month;          // range 1-12
+       unsigned char           day;
+       unsigned char           hours;          // range 0-23
+       unsigned char           minutes;        // range 0-59
+       unsigned char           seconds;        // range 0-59
+}sms_time_abs_s;
+
+
+typedef struct _sms_val_period_s
+{
+       unsigned char           format;
+       union {
+               sms_time_rel_s  rel_time;
+               sms_time_abs_s  abs_time;
+       }time;
+}sms_val_period_s;
+
+
+typedef struct _sms_encoding_specific_s
+{
+       sms_encoding_type_t             encode_type;
+       unsigned int                    data_len;
+       char                                    user_data[SMS_MAX_USER_DATA_LEN +1];
+}sms_encoding_specific_s;
+
+
+typedef struct _sms_ctg_specific_s
+{
+       unsigned char           operation_code;
+       unsigned short          category;
+       sms_language_type_t     language;
+       unsigned char           max_msg;
+       sms_alert_option_t      alert_option;
+       unsigned int            data_len;
+       char                            user_data[SMS_MAX_USER_DATA_LEN +1];
+}sms_ctg_specific_s;
+
+
+typedef struct _sms_svc_ctg_program_data_s
+{
+       sms_encoding_type_t             encode_type;
+       unsigned int                    num_data;
+       sms_ctg_specific_s              *specific_data;
+}sms_svc_ctg_program_data_s;
+
+
+typedef struct _sms_telesvc_userdata_s
+{
+       sms_encoding_type_t             encode_type;
+       unsigned char                   msg_type;
+       unsigned int                    data_len;
+       unsigned char                   user_data[SMS_MAX_USER_DATA_LEN +1];
+}sms_telesvc_userdata_s;
+
+
+typedef struct _sms_telesvc_cmasdata_s
+{
+       unsigned int                            data_len;
+       sms_encoding_type_t             encode_type;
+       unsigned char                           alert_text[SMS_MAX_USER_DATA_LEN +1];
+       sms_cmae_category_t             category;
+       sms_cmae_response_type_t                response_type;
+       sms_cmae_severity_t                     severity;
+       sms_cmae_urgency_t                      urgency;
+       sms_cmae_certainty_t                    certainty;
+       unsigned short          id;
+       sms_cmae_alert_handle_t                 alert_handle;           /* 00:Presidential 01:Extreme 02:Severe 03:AMBER 04:Test */
+       sms_time_abs_s                  expires;
+       sms_language_type_t             language;
+       bool                                    is_wrong_recode_type;
+}sms_telesvc_cmasdata_s;
+
+
+typedef struct _sms_enhanced_vmn_s
+{
+       sms_priority_indicator_t                priority;
+       bool                                                    password_req;
+       bool                                                    setup_req;
+       bool                                                    pw_change_req;
+       unsigned char                                   min_pw_len;
+       unsigned char                                   max_pw_len;
+       unsigned char                                   vm_num_unheard_msg;
+       bool                                                    vm_mailbox_alm_full;
+       bool                                                    vm_mailbox_full;
+       bool                                                    reply_allowed;
+       bool                                                    fax_included;
+       unsigned short                          vm_len;
+       unsigned char                                   vm_ret_day;
+       unsigned short                          vm_msg_id;
+       unsigned short                          vm_mailbox_id;
+
+       sms_digit_mode_t                                an_digit_mode;
+       sms_number_type_t                               an_number_type;
+       sms_number_plan_t                               an_number_plan;
+       unsigned char                                   an_num_field;
+       unsigned char                                   an_char[SMS_MAX_USER_DATA_LEN+1];
+
+       sms_digit_mode_t                                cli_digit_mode;
+       sms_number_type_t                               cli_number_type;
+       sms_number_plan_t                               cli_number_plan;
+       unsigned char                                   cli_num_field;
+       unsigned char                                   cli_char[SMS_MAX_USER_DATA_LEN+1];
+}sms_enhanced_vmn_s;
+
+
+typedef struct _sms_enhanced_vmn_ack_s
+{
+       unsigned short                          vm_mailbox_id;
+       unsigned char                                   vm_num_unheard_msg;
+       unsigned char                                   num_delete_ack;
+       unsigned char                                   num_play_ack;
+
+       unsigned short                          da_vm_msg_id[SMS_MAX_NUMBER_OF_ACK+1];
+       unsigned short                          pa_vm_msg_id[SMS_MAX_NUMBER_OF_ACK+1];
+}sms_enhanced_vmn_ack_s;
+
+
+typedef struct _sms_telesvc_deliver_s
+{
+       sms_trans_msg_id_s                      msg_id;
+       sms_telesvc_userdata_s          user_data;
+       sms_telesvc_cmasdata_s          cmas_data;
+       sms_time_abs_s                          time_stamp;
+       sms_val_period_s                        val_period;
+       sms_val_period_s                        defer_val_period;
+       sms_priority_indicator_t                priority;
+       sms_privacy_indicator_t         privacy;
+       sms_reply_option_s                      reply_opt;
+       unsigned int                            num_msg;
+       sms_alert_priority_t            alert_priority;
+       sms_language_type_t                     language;
+       sms_telesvc_addr_s                      callback_number;
+       sms_display_mode_t                      display_mode;
+       sms_encoding_specific_s         multi_encode_data;
+       unsigned short                          deposit_id;
+       //sms_svc_ctg_program_data_s    svc_ctg;
+       sms_enhanced_vmn_s                      enhanced_vmn;
+       sms_enhanced_vmn_ack_s          enhanced_vmn_ack;
+}sms_telesvc_deliver_s;
+
+
+typedef struct _sms_telesvc_submit_s
+{
+       sms_trans_msg_id_s                      msg_id;
+       sms_telesvc_userdata_s          user_data;
+       sms_val_period_s                        val_period;
+       sms_val_period_s                        defer_val_period;
+       sms_priority_indicator_t        priority;
+       sms_privacy_indicator_t         privacy;
+       sms_reply_option_s                      reply_opt;
+       sms_alert_priority_t            alert_priority;
+       sms_language_type_t                     language;
+       sms_telesvc_addr_s                      callback_number;
+       sms_encoding_specific_s         multi_encode_data;
+       unsigned char                           deposit_id;
+       //sms_svc_ctg_program_data_s    svc_ctg;
+}sms_telesvc_submit_s;
+
+
+typedef struct _sms_telesvc_cancel_s
+{
+       sms_trans_msg_id_s              msg_id;
+}sms_telesvc_cancel_s;
+
+
+typedef struct _sms_telesvc_user_ack_s
+{
+       sms_trans_msg_id_s                      msg_id;
+       sms_telesvc_userdata_s          user_data;
+       unsigned char                           resp_code;
+       sms_time_abs_s                          time_stamp;
+       sms_encoding_specific_s         multi_encode_data;
+       unsigned char                           deposit_id;
+}sms_telesvc_user_ack_s;
+
+
+typedef struct _sms_telesvc_deliver_ack_s
+{
+       sms_trans_msg_id_s                      msg_id;
+       sms_telesvc_userdata_s          user_data;
+       sms_time_abs_s                          time_stamp;
+       sms_encoding_specific_s         multi_encode_data;
+       sms_status_code_t                       msg_status;
+}sms_telesvc_deliver_ack_s;
+
+
+typedef struct _sms_telesvc_read_ack_s
+{
+       sms_trans_msg_id_s                      msg_id;
+       sms_telesvc_userdata_s          user_data;
+       sms_time_abs_s                          time_stamp;
+       sms_encoding_specific_s         multi_encode_data;
+       unsigned char                           deposit_id;
+}sms_telesvc_read_ack_s;
+
+typedef struct _sms_telesvc_deliver_report_s
+{
+       sms_trans_msg_id_s              msg_id;
+       unsigned char                   tp_fail_cause;
+       sms_telesvc_userdata_s  user_data;
+       sms_language_type_t             language;
+       unsigned char                   multi_encode_data;
+}sms_telesvc_report_s;
+
+
+typedef struct _sms_telesvc_msg_s
+{
+       sms_message_type_t              type;
+
+       union {
+               sms_telesvc_deliver_s                   deliver;
+               sms_telesvc_submit_s                    submit;
+               sms_telesvc_cancel_s                    cancel;
+               sms_telesvc_user_ack_s                  user_ack;
+               sms_telesvc_deliver_ack_s               delivery_ack;
+               sms_telesvc_read_ack_s                  read_ack;
+               sms_telesvc_report_s                    report;
+       }data;
+}sms_telesvc_msg_s;
+
+
+
+/********************************************************************************/
+/*                                                             TRANSPORT LAYER                                                                 */
+/********************************************************************************/
+
+typedef unsigned short                 sms_trans_param_id_t;           /* _sms_trans_param_id_e */
+
+typedef unsigned short                 sms_trans_telesvc_id_t;         /* _sms_trans_telesvc_id_e */
+
+typedef unsigned short                 sms_trans_svc_ctg_t;                    /* _sms_trans_svc_ctg_e */
+
+typedef unsigned char          sms_trans_reply_seq_t;
+
+
+typedef enum _sms_trans_msg_type_e
+{
+       SMS_TRANS_P2P_MSG                       = 0x00,
+       SMS_TRANS_BROADCAST_MSG         = 0x01,
+       SMS_TRANS_ACK_MSG                       = 0x02,
+       SMS_TRANS_TYPE_RESERVED
+}sms_trans_msg_type_t;
+
+
+enum _sms_trans_param_id_e
+{
+       SMS_TRANS_PARAM_TELESVC_IDENTIFIER              = 0x00,
+       SMS_TRANS_PARAM_SERVICE_CATEGORY                = 0x01,
+       SMS_TRANS_PARAM_ORG_ADDRESS                             = 0x02,
+       SMS_TRANS_PARAM_ORG_SUB_ADDRESS                 = 0x02,
+       SMS_TRANS_PARAM_DEST_ADDRESS                    = 0x04,
+       SMS_TRANS_PARAM_DEST_SUB_ADDRESS                = 0x05,
+       SMS_TRANS_PARAM_BEARER_REPLY_OPTION             = 0x06,
+       SMS_TRANS_PARAM_CAUSE_CODES                             = 0x07,
+       SMS_TRANS_PARAM_BEARER_DATA                             = 0x08,
+       SMS_TRANS_PARAM_RESERVED
+};
+
+
+enum _sms_trans_telesvc_id_e
+{
+       SMS_TRANS_TELESVC_CMT_91                = 0x1000,       /* IS-91 Extended Protocol Enhanced Services */
+       SMS_TRANS_TELESVC_CPT_95                = 0x1001,       /* Wireless Paging Teleservice */
+       SMS_TRANS_TELESVC_CMT_95                = 0x1002,       /* Wireless Messaging Teleservice */
+       SMS_TRANS_TELESVC_VMN_95                = 0x1003,       /* Voice Mail Notification */
+       SMS_TRANS_TELESVC_WAP                   = 0x1004,       /* Wireless Application Protocol */
+       SMS_TRANS_TELESVC_WEMT                  = 0x1005,       /* Wireless Enhanced Messaging Teleservice */
+       SMS_TRANS_TELESVC_SCPT                  = 0x1006,       /* Service Category Programming Teleservice */
+       SMS_TRANS_TELESVC_CATPT                 = 0x1007,       /* Card Application Toolkit Protocol Teleservice */
+       SMS_TRANS_TELESVC_RESERVED              = 0xffff
+};
+
+
+enum _sms_trans_svc_ctg_e
+{
+       SMS_TRANS_SVC_CTG_UNKNOWN                               = 0x0000,
+       SMS_TRANS_SVC_CTG_EMERGENCY                             = 0x0001,
+       SMS_TRANS_SVC_CTG_ADMINISTRATIVE                = 0x0002,
+       SMS_TRANS_SVC_CTG_MAINTENANCE                   = 0x0003,
+       SMS_TRANS_SVC_CTG_GNEWS_LOCAL                   = 0x0004,
+       SMS_TRANS_SVC_CTG_GNEWS_REGIONAL                = 0x0005,
+       SMS_TRANS_SVC_CTG_GNEWS_NATIONAL                = 0x0006,
+       SMS_TRANS_SVC_CTG_GNEWS_INTERNATIONAL   = 0x0007,
+       SMS_TRANS_SVC_CTG_BFNEWS_LOCAL                  = 0x0008,
+       SMS_TRANS_SVC_CTG_BFNEWS_REGIONAL               = 0x0009,
+       SMS_TRANS_SVC_CTG_BFNEWS_NATIONAL               = 0x000a,
+       SMS_TRANS_SVC_CTG_BFNEWS_INTERNATIONAL  = 0x000b,
+       SMS_TRANS_SVC_CTG_SNEWS_LOCAL                   = 0x000c,
+       SMS_TRANS_SVC_CTG_SNEWS_REGIONAL                = 0x000d,
+       SMS_TRANS_SVC_CTG_SNEWS_NATIONAL                = 0x000e,
+       SMS_TRANS_SVC_CTG_SNEWS_INTERNATIONAL   = 0x000f,
+       SMS_TRANS_SVC_CTG_ENEWS_LOCAL                   = 0x0010,
+       SMS_TRANS_SVC_CTG_ENEWS_REGIONAL                = 0x0011,
+       SMS_TRANS_SVC_CTG_ENEWS_NATIONAL                = 0x0012,
+       SMS_TRANS_SVC_CTG_ENEWS_INTERNATIONAL   = 0x0013,
+       SMS_TRANS_SVC_CTG_LOCAL_WEATHER                 = 0x0014,
+       SMS_TRANS_SVC_CTG_TRAFFIC_REPORTS               = 0x0015,
+       SMS_TRANS_SVC_CTG_FLIGHT_SCHEDULES              = 0x0016,
+       SMS_TRANS_SVC_CTG_RESTAURANTS                   = 0x0017,
+       SMS_TRANS_SVC_CTG_LODGINGS                              = 0x0018,
+       SMS_TRANS_SVC_CTG_RETAIL_DIRECTORY              = 0x0019,
+       SMS_TRANS_SVC_CTG_ADVERTISEMENTS                = 0x001a,
+       SMS_TRANS_SVC_CTG_STOCK_QUOTES                  = 0x001b,
+       SMS_TRANS_SVC_CTG_EMPLOYMENT                    = 0x001c,
+       SMS_TRANS_SVC_CTG_MEDICAL                               = 0x001d,
+       SMS_TRANS_SVC_CTG_TECHNOLOGY_NEWS               = 0x001e,
+       SMS_TRANS_SVC_CTG_MULTI_CTG                             = 0x001f,
+       SMS_TRANS_SVC_CTG_CATPT                                 = 0x0020,
+       SMS_TRANS_SVC_CTG_KDDI_CORP_MIN1                = 0x0021,
+       SMS_TRANS_SVC_CTG_KDDI_CORP_MAX1                = 0x003f,
+       SMS_TRANS_SVC_CTG_CMAS_PRESIDENTIAL     = 0x1000,
+       SMS_TRANS_SVC_CTG_CMAS_EXTREME                  = 0x1001,
+       SMS_TRANS_SVC_CTG_CMAS_SEVERE                   = 0x1002,
+       SMS_TRANS_SVC_CTG_CMAS_AMBER                    = 0x1003,
+       SMS_TRANS_SVC_CTG_CMAS_TEST                             = 0x1004,
+       SMS_TRANS_SVC_CTG_KDDI_CORP_MIN2                = 0x8001,
+       SMS_TRANS_SVC_CTG_KDDI_CORP_MAX2                = 0x803f,
+       SMS_TRANS_SVC_CTG_KDDI_CORP_MIN3                = 0xc001,
+       SMS_TRANS_SVC_CTG_KDDI_CORP_MAX3                = 0xc03f,
+       SMS_TRANS_SVC_CTG_RESERVED,
+       SMS_TRANS_SVC_CTG_UNDEFINED                             = 0x8001,
+};
+
+
+typedef enum _sms_trans_err_class_e
+{
+       SMS_TRANS_ERR_CLASS_NONE                                = 0x00,
+       SMS_TRANS_ERR_CLASS_TEMPORARY                   = 0x02,
+       SMS_TRANS_ERR_CLASS_PERMANENT                   = 0x03
+}sms_trans_err_class_t;
+
+
+typedef enum _sms_trans_cause_code_e
+{
+       SMS_CAUSE_CODE_INVAILD_TELESERVICE_ID   = 0x04,
+       SMS_CAUSE_CODE_SERVICE_TERMINATION_DENIED               = 0x62,
+       SMS_TODO_FILL_THIS_ENUMS
+}sms_trans_cause_code_t;
+
+
+typedef enum _sms_trans_sub_addr_type_e
+{
+       SMS_TRANS_SUB_ADDR_NSAP                                 = 0x00,
+       SMS_TRANS_SUB_ADDR_USER                                 = 0x01,
+       SMS_TRANS_SUB_ADDR_RESERVED
+}sms_trans_sub_addr_type_t;
+
+
+
+enum _sms_trans_dnet_addr_type_e
+{
+       SMS_TRANS_DNET_UNKNOWN                                  = 0x00,
+       SMS_TRANS_DNET_INTERNET_PROTOCOL                = 0x01,
+       SMS_TRANS_DNET_INTERNET_MAIL_ADDR               = 0x02,
+       SMS_TRANS_DNET_RESERVED
+};
+
+
+enum _sms_digit_mode_e {
+       SMS_DIGIT_4BIT_DTMF     = 0,
+       SMS_DIGIT_8BIT  = 1
+};
+
+
+enum _sms_number_mode_e {
+       SMS_NUMBER_MODE_NONE_DATANETWORK        = 0,
+       SMS_NUMBER_MODE_DATANETWORK     = 1,    /*using data network address format*/
+};
+
+
+enum _sms_dnet_number_type_e {
+       SMS_ADDRESS_TYPE_UNKNOWN        = 0x00,
+       SMS_ADDRESS_TYPE_INTERNET_PROTOCOL      = 0x01,
+       SMS_ADDRESS_TYPE_EMAIL_ADDRESS  = 0x02,
+};
+
+
+enum _sms_number_type_e {
+       SMS_NUMBER_TYPE_UNKNOWN = 0x00,
+       SMS_NUMBER_TYPE_INTERNATIONAL   = 0x01,
+       SMS_NUMBER_TYPE_NATIONAL        = 0x02,
+       SMS_NUMBER_TYPE_NETWORK_SPECIFIC        = 0x03,
+       SMS_NUMBER_TYPE_SUBSCRIBER      = 0x04,
+       SMS_NUMBER_TYPE_RESERVED_5      = 0x05,
+       SMS_NUMBER_TYPE_ABBREVIATED     = 0x06,
+       SMS_NUMBER_TYPE_RESERVED_7      = 0x07,
+/*
+ * TODO : check this type is valid or not
+ *     SMS_NUMBER_TYPE_IP      = 0x11,
+ *     SMS_NUMBER_TYPE_EMAILADDR       = 0x12,
+ */
+};
+
+
+enum _sms_number_plan_e {
+       SMS_NPI_UNKNOWN = 0,
+       SMS_NPI_ISDN    = 1,
+       SMS_NPI_DATA    = 3,
+       SMS_NPI_TELEX   = 4,
+       SMS_NPI_PRIVATE = 9,
+       SMS_NPI_RESERVED        = 15,
+};
+
+
+typedef struct _sms_trans_addr_s
+{
+       sms_digit_mode_t        digit_mode;
+       sms_number_mode_t       number_mode;
+       sms_number_type_t       number_type;
+       sms_number_plan_t       number_plan;
+       unsigned int            addr_len;
+       char                            szData[SMS_TRANS_ADDRESS_MAX_LEN + 1];
+}sms_trans_addr_s;
+
+
+typedef struct _sms_trans_sub_addr_s
+{
+       sms_trans_sub_addr_type_t       type;
+       bool                                            odd;
+       unsigned int                            addr_len;
+       char                                            szData[SMS_TRANS_ADDRESS_MAX_LEN + 1];
+}sms_trans_sub_addr_s;
+
+
+typedef struct _sms_trans_cause_code_s
+{
+       sms_trans_reply_seq_t                   reply_seq;
+       sms_trans_err_class_t                   error_class;
+       sms_trans_cause_code_t                  cause_code;
+}sms_trans_cause_code_s;
+
+
+typedef struct _sms_trans_p2p_msg_s
+{
+       sms_trans_telesvc_id_t                  telesvc_id;
+       sms_trans_svc_ctg_t                             svc_ctg;
+       sms_trans_addr_s                                address;
+       sms_trans_sub_addr_s                    sub_address;
+       sms_trans_reply_seq_t                   reply_seq;
+       sms_telesvc_msg_s                               telesvc_msg;
+}sms_trans_p2p_msg_s;
+
+
+typedef struct _sms_trans_broadcast_msg_s
+{
+       sms_trans_svc_ctg_t                             svc_ctg;
+       sms_telesvc_msg_s                               telesvc_msg;
+}sms_trans_broadcast_msg_s;
+
+
+typedef struct _sms_trans_ack_msg_s
+{
+       sms_trans_addr_s                                address;
+       sms_trans_sub_addr_s                    sub_address;
+       sms_trans_cause_code_s                  cause_code;
+}sms_trans_ack_msg_s;
+
+
+typedef struct _sms_trans_msg_s
+{
+       sms_trans_msg_type_t            type;
+       union {
+               sms_trans_p2p_msg_s                     p2p_msg;
+               sms_trans_broadcast_msg_s       cb_msg;
+               sms_trans_ack_msg_s                     ack_msg;
+       }data;
+}sms_trans_msg_s;
+
+
+#endif //SMS_CDMA_PLUGIN_TYPES_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginUAManager.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginUAManager.h
new file mode 100755 (executable)
index 0000000..e4de518
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+* 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 SMS_CDMA_PLUGIN_UA_MANAGER_H
+#define SMS_CDMA_PLUGIN_UA_MANAGER_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include "MsgMutex.h"
+#include "MsgQueue.h"
+#include "MsgThread.h"
+#include "SmsCdmaPluginTypes.h"
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginUAManager : public MsgThread
+{
+public:
+       static SmsPluginUAManager* instance();
+
+       //virtual void start();
+
+       void addReqEntity(sms_request_info_s *request);
+
+private:
+       SmsPluginUAManager();
+       ~SmsPluginUAManager();
+       void lock()     { mx.lock(); };
+       void unlock()   { mx.unlock(); };
+       void wait()     { cv.wait(mx.pMutex()); };
+       void signal()   { cv.signal(); };
+
+       virtual void run();
+
+       static SmsPluginUAManager* pInstance;
+
+       bool bRunning;
+
+       MsgSimpleQ <sms_request_info_s> smsTranQ;
+
+       Mutex mx;
+       CndVar cv;
+};
+
+#endif //SMS_CDMA_PLUGIN_UA_MANAGER_H
+
diff --git a/plugin/sms_cdma_plugin/include/SmsCdmaPluginWapPushHandler.h b/plugin/sms_cdma_plugin/include/SmsCdmaPluginWapPushHandler.h
new file mode 100755 (executable)
index 0000000..dea5882
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+* 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 SMS_CDMA_PLUGIN_WAPPUSH_HANDLER_H
+#define SMS_CDMA_PLUGIN_WAPPUSH_HANDLER_H
+
+
+/*==================================================================================================
+                                         INCLUDE FILES
+==================================================================================================*/
+#include <wbxml/wbxml.h>
+#include <libxml/parser.h>
+
+
+#include "SmsCdmaPluginTypes.h"
+
+
+/*==================================================================================================
+                                         DEFINES
+==================================================================================================*/
+#define WSP_STANDARD_STR_LEN_MAX        255
+#define LENGTH_QUOTE  0x1F
+#define        NO_VALUE                                                0x00
+
+#define WSP_CODE_BUFFER_LEFT_LEN_MAX   1024
+#define WSP_CODE_BUFFER_RIGHT_LEN_MAX  2048
+
+#define  AcStrlen(x) ((x==NULL)?0:strlen(x))
+#define MIN(a,b)  (((a)  <  (b)) ? (a)  :  (b))
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class SmsPluginWapPushHandler
+{
+public:
+       static SmsPluginWapPushHandler* instance();
+
+       //void registerPushCallback();
+       bool IsWapPushMsg(unsigned short dstport);
+
+       void copyDeliverData(sms_trans_addr_s *pAddr);
+       void handleWapPushMsg(const char *pUserData, int DataSize);
+       void handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen);
+
+private:
+       SmsPluginWapPushHandler();
+       virtual ~SmsPluginWapPushHandler();
+
+       static SmsPluginWapPushHandler* pInstance;
+
+       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 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);
+       unsigned long convertXmlCharToSec(char* pDate);
+       msg_push_action_t convertSIActionStrToEnum(char* pAction);
+       msg_push_action_t convertSLActionStrToEnum(char* pAction);
+
+       unsigned long wspRetriveUintvarDecode( unsigned char* sourceData, unsigned long* currentPointer );
+       unsigned long wspDecodeUintvar(unsigned long length, unsigned char* userVar );
+       void wspDecodeHeader( unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader);
+       unsigned long wspHeaderDecodeInteger( unsigned char* data );
+       void wspHeaderDecodeQValue( unsigned long length, unsigned char* data, char** pDecodedString);
+       unsigned long wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length );
+       char* wspExtendedDecodeType(char contentType  );
+       void wspHeaderDecodeParameter( unsigned char* data, unsigned long length, char** pParam);
+       void wspHeaderDecodeCharset( unsigned long length, unsigned char* data, char**pDecodedString);
+       void wspHeaderDecodeVersion( unsigned long length, unsigned char* data, char** pDecodedString );
+       void wspHeaderDecodeDateValue( unsigned long length, unsigned char* data, char** pDecodedString );
+       void wspHeaderCopyDecodedString( unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper );
+       void wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString );
+       void wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString );
+       void wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString);
+
+
+       sms_trans_addr_s        tmpAddress;
+//     SMS_TIMESTAMP_S tmpTimeStamp;
+};
+
+#endif //SmsPluginWapPushHandler
+
diff --git a/plugin/sms_plugin/SmsPluginDSHandler.cpp b/plugin/sms_plugin/SmsPluginDSHandler.cpp
new file mode 100755 (executable)
index 0000000..5339c13
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * 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>
+       #include <ITapiSim.h>
+#if 0
+       #include <telephony_common.h>
+       #include <telephony_sim.h>
+#endif
+}
+
+/*==================================================================================================
+                                     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++;
+       }
+
+       g_strfreev(cp_list);
+
+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;
+}
+
+
+int SmsPluginDSHandler::getSubscriberId(unsigned int simIndex, char **subscriber_id)
+{
+#if 0
+       if (simIndex <= 0 || simIndex > (unsigned int)handle_list.count) {
+               MSG_DEBUG("Invalid SIM index");
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       int tel_ret = TELEPHONY_ERROR_NONE;
+       telephony_handle_list_s capi_tel_handle_list;
+
+       tel_ret = telephony_init(&capi_tel_handle_list);
+       if (tel_ret != TELEPHONY_ERROR_NONE) {
+               MSG_DEBUG("Initialize failed!!!");
+               return MSG_ERR_PLUGIN_TAPIINIT;
+       }
+
+       tel_ret = telephony_sim_get_subscriber_id(capi_tel_handle_list.handle[simIndex-1], subscriber_id);
+       if (tel_ret != TELEPHONY_ERROR_NONE) {
+               MSG_DEBUG("telephony_sim_get_subscriber_id() failed!!! [%d]", tel_ret);
+       } else {
+               MSG_DEBUG("Subscriber ID is [%s]", *subscriber_id);
+       }
+
+       tel_ret = telephony_deinit(&capi_tel_handle_list);
+       if (tel_ret != TELEPHONY_ERROR_NONE) {
+               MSG_DEBUG("Deinitialize failed!!!");
+       }
+
+#endif
+    return MSG_SUCCESS;
+}
diff --git a/plugin/sms_plugin/include/SmsPluginDSHandler.h b/plugin/sms_plugin/include/SmsPluginDSHandler.h
new file mode 100755 (executable)
index 0000000..48d095b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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);
+
+       int getSubscriberId(unsigned int simIndex, char **subscriber_id);
+
+private:
+       static SmsPluginDSHandler* pInstance;
+       SmsPluginDSHandler();
+       virtual ~SmsPluginDSHandler();
+       char **cp_list;
+       SMS_TELEPHONY_HANDLE_LIST_S handle_list;
+};
+
+#endif //SMS_PLUGIN_DS_HANDLER_H
+
diff --git a/sms-plugin.manifest b/sms-plugin.manifest
new file mode 100755 (executable)
index 0000000..2a0cec5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+  <request>
+    <domain name="_"/>
+  </request>
+</manifest>
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
diff --git a/utils/MsgSerialize.cpp b/utils/MsgSerialize.cpp
new file mode 100755 (executable)
index 0000000..9c1e9ae
--- /dev/null
@@ -0,0 +1,908 @@
+/*
+ * 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;
+
+       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;
+
+       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 to_cnt = 0;
+       int cc_cnt = 0;
+       int bcc_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);
+               cc_cnt = g_list_length(pMsgData->header->cc);
+               bcc_cnt = g_list_length(pMsgData->header->bcc);
+
+               bufsize += (3 * 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
+                       }
+               }
+               for (i = 0; i < cc_cnt; i++) {
+                       MMS_ADDRESS_DATA_S *addr_data = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pMsgData->header->cc, i);
+                       if (addr_data && addr_data->address_val) {
+                               bufsize += (sizeof(int) + sizeof(int) + strlen(addr_data->address_val)); // type, length, address
+                       }
+               }
+               for (i = 0; i < bcc_cnt; i++) {
+                       MMS_ADDRESS_DATA_S *addr_data = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pMsgData->header->bcc, 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_SEC_DEBUG("[#%2d][%5d] address val = %s", serial_index++, offset, to_addr->address_val);
+                               offset += sizeof(char)*MAX_ADDRESS_VAL_LEN;
+                       }
+               }
+
+               // address
+               memcpy(buf + offset, &cc_cnt, sizeof(int));
+               MSG_DEBUG("[#%2d][%5d] CC Count = %d", serial_index++, offset, cc_cnt);
+               offset += sizeof(int);
+
+               for (i = 0; i < cc_cnt; i++) {
+                       MMS_ADDRESS_DATA_S *cc_addr = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pMsgData->header->cc, i);
+                       if (cc_addr && cc_addr->address_val) {
+                               memcpy(buf + offset, &cc_addr->address_type, sizeof(int));
+                               MSG_DEBUG("[#%2d][%5d] address type = %d", serial_index++, offset, cc_addr->address_type);
+                               offset += sizeof(int);
+                               memcpy(buf + offset, cc_addr->address_val, sizeof(char)*MAX_ADDRESS_VAL_LEN);
+                               MSG_SEC_DEBUG("[#%2d][%5d] address val = %s", serial_index++, offset, cc_addr->address_val);
+                               offset += sizeof(char)*MAX_ADDRESS_VAL_LEN;
+                       }
+               }
+
+               // address
+               memcpy(buf + offset, &bcc_cnt, sizeof(int));
+               MSG_DEBUG("[#%2d][%5d] BCC Count = %d", serial_index++, offset, bcc_cnt);
+               offset += sizeof(int);
+
+               for (i = 0; i < bcc_cnt; i++) {
+                       MMS_ADDRESS_DATA_S *bcc_addr = (MMS_ADDRESS_DATA_S *)g_list_nth_data(pMsgData->header->bcc, i);
+                       if (bcc_addr && bcc_addr->address_val) {
+                               memcpy(buf + offset, &bcc_addr->address_type, sizeof(int));
+                               MSG_DEBUG("[#%2d][%5d] address type = %d", serial_index++, offset, bcc_addr->address_type);
+                               offset += sizeof(int);
+                               memcpy(buf + offset, bcc_addr->address_val, sizeof(char)*MAX_ADDRESS_VAL_LEN);
+                               MSG_SEC_DEBUG("[#%2d][%5d] address val = %s", serial_index++, offset, bcc_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_SEC_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);
+               }
+
+               memcpy(&addr_cnt, value + offset, sizeof(int));
+               offset += sizeof(int);
+
+               pMmsData->header->cc = NULL;
+
+               for (i = 0; i < addr_cnt; i++) {
+                       MMS_ADDRESS_DATA_S* cc_addr = (MMS_ADDRESS_DATA_S*)calloc(1, sizeof(MMS_ADDRESS_DATA_S));
+
+                       memcpy(&(cc_addr->address_type), value + offset, sizeof(int));
+                       MSG_DEBUG("[#%2d][%5d] address type = %d", deserial_index++, offset, cc_addr->address_type);
+                       offset += sizeof(int);
+
+                       memcpy(cc_addr->address_val, value + offset, sizeof(char)*MAX_ADDRESS_VAL_LEN);
+                       MSG_SEC_DEBUG("[#%2d][%5d] address val = %s", deserial_index++, offset, cc_addr->address_val);
+                       offset += sizeof(char)*MAX_ADDRESS_VAL_LEN;
+
+                       pMmsData->header->cc = g_list_append(pMmsData->header->cc, (void *)cc_addr);
+               }
+
+               memcpy(&addr_cnt, value + offset, sizeof(int));
+               offset += sizeof(int);
+
+               pMmsData->header->bcc = NULL;
+
+               for (i = 0; i < addr_cnt; i++) {
+                       MMS_ADDRESS_DATA_S* bcc_addr = (MMS_ADDRESS_DATA_S*)calloc(1, sizeof(MMS_ADDRESS_DATA_S));
+
+                       memcpy(&(bcc_addr->address_type), value + offset, sizeof(int));
+                       MSG_DEBUG("[#%2d][%5d] address type = %d", deserial_index++, offset, bcc_addr->address_type);
+                       offset += sizeof(int);
+
+                       memcpy(bcc_addr->address_val, value + offset, sizeof(char)*MAX_ADDRESS_VAL_LEN);
+                       MSG_SEC_DEBUG("[#%2d][%5d] address val = %s", deserial_index++, offset, bcc_addr->address_val);
+                       offset += sizeof(char)*MAX_ADDRESS_VAL_LEN;
+
+                       pMmsData->header->bcc = g_list_append(pMmsData->header->bcc, (void *)bcc_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/MsgZoneManager.cpp b/utils/MsgZoneManager.cpp
new file mode 100755 (executable)
index 0000000..e2bb438
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+* 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 <glib.h>
+#include <sys/socket.h>
+
+#include "MsgDebug.h"
+#include "MsgZoneManager.h"
+
+#ifdef FEATURE_CONTAINER_ENABLE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#define MSG_ZONE_KNOX "knox"
+#define MSG_ZONE_PERSONAL "personal"
+
+#include <vasum.h>
+
+vsm_context_h vsm_ctx = NULL;
+vsm_zone_h real_zone = NULL;
+GIOChannel *gio_channel = NULL;
+
+int zone_ref_count = 0;
+
+
+gboolean _zone_mainloop_cb(GIOChannel *channel, GIOCondition condition, void *data)
+{
+       MSG_BEGIN();
+#ifdef FEATURE_CONTAINER_ENABLE
+       struct vsm_context *ctx = (struct vsm_context *)data;
+       vsm_enter_eventloop(ctx, 0, 0);
+       MSG_END();
+#endif
+       return true;
+}
+
+
+int _get_peer_pid(int fd)
+{
+       struct ucred cred;
+       socklen_t cr_len = sizeof(cred);
+       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &cr_len) < 0) {
+               return -1;
+       }
+       return cred.pid;
+}
+
+#endif
+
+void MsgZoneInit()
+{
+       MSG_BEGIN();
+#ifdef FEATURE_CONTAINER_ENABLE
+
+       MsgZoneClean();
+
+       vsm_ctx = vsm_create_context();
+       if (vsm_ctx == NULL) {
+               MSG_FATAL("vsm_create_context failed");
+               return;
+       }
+
+       int fd = vsm_get_poll_fd(vsm_ctx);
+       gio_channel = g_io_channel_unix_new(fd);
+       if (gio_channel == NULL) {
+               MSG_FATAL("g_io_channel_unix_new failed");
+               return;
+       }
+
+       g_io_add_watch(gio_channel, G_IO_IN, _zone_mainloop_cb, vsm_ctx);
+
+#endif
+       MSG_END();
+}
+
+
+void MsgZoneClean()
+{
+       MSG_BEGIN();
+#ifdef FEATURE_CONTAINER_ENABLE
+       if (vsm_ctx != NULL) {
+               vsm_cleanup_context(vsm_ctx);
+               vsm_ctx = NULL;
+       }
+       if (gio_channel != NULL) {
+               g_io_channel_unref(gio_channel);
+               gio_channel = NULL;
+       }
+#endif
+       MSG_END();
+}
+
+
+char* MsgZoneGetName(int fd)
+{
+       MSG_BEGIN();
+#ifdef FEATURE_CONTAINER_ENABLE
+       if (vsm_ctx == NULL) {
+               MsgZoneInit();
+       }
+       int pid = _get_peer_pid(fd);
+       vsm_zone_h zone = vsm_lookup_zone_by_pid(vsm_ctx, pid);
+       if (zone == NULL) {
+               MSG_FATAL("vsm_lookup_zone_by_pid failed, PID = %d", pid);
+               return NULL;
+       }
+       MSG_END();
+       return strdup(vsm_get_zone_name(zone));
+#endif
+       return NULL;
+}
+
+
+bool MsgZoneIsAllowed(int fd)
+{
+#ifdef FEATURE_CONTAINER_ENABLE
+       char *zone_name = MsgZoneGetName(fd);
+       if (zone_name == NULL) {
+               return false;
+       }
+
+       MSG_DEBUG("zone_name=[%s]", zone_name);
+       bool result = (!g_strcmp0(zone_name, MSG_ZONE_PERSONAL) || (!g_strcmp0(zone_name, "")));
+       g_free(zone_name);
+       zone_name = NULL;
+
+       return result;
+#endif
+       return true;
+}
+
+
+void MsgZoneChange()
+{
+       MSG_BEGIN();
+#ifdef FEATURE_CONTAINER_ENABLE
+       if (vsm_ctx == NULL) {
+               MSG_DEBUG("vsm_ctx == NULL");
+               return;
+       }
+       if (real_zone != NULL && zone_ref_count > 0) {
+               zone_ref_count++;
+               MSG_DEBUG("zone_ref_count++");
+               return;
+       }
+
+       vsm_zone_h current_zone = vsm_get_foreground(vsm_ctx);
+       vsm_zone_h effective_zone = vsm_lookup_zone_by_name(vsm_ctx, MSG_ZONE_PERSONAL);
+       if (!g_strcmp0(vsm_get_zone_name(current_zone), MSG_ZONE_KNOX) && real_zone == NULL) {
+               real_zone = vsm_join_zone(effective_zone);
+               MSG_DEBUG("Change Zone");
+               zone_ref_count++;
+       }
+#endif
+       MSG_END();
+}
+
+
+void MsgZoneRevert()
+{
+       MSG_BEGIN();
+#ifdef FEATURE_CONTAINER_ENABLE
+       if (real_zone == NULL || zone_ref_count == 0) {
+               MSG_DEBUG("real_zone == NULL || zone_ref_count == 0");
+               return;
+       }
+       zone_ref_count--;
+       if (zone_ref_count == 0) {
+               vsm_join_zone(real_zone);
+               real_zone = NULL;
+               MSG_DEBUG("Revert Zone");
+       }
+#endif
+       MSG_END();
+}