#include "Messaging.h"
#include "CallbackMgr.h"
#include "MsgServiceHandleMgr.h"
+#include "WidgetFilePathMgr.h"
#include <Logger.h>
+#include <vconf.h>
extern "C" {
#include <msg.h>
namespace {
const char* TEXT_AREA = "Text";
const char* TEXT_FILE_EXTENSION = ".txt";
-const char* TEXT_DIR_PREFIX = "/tmp/";
+const char* TEXT_DIR_SEPERATOR = "/";
const int WHITE_COLOR = 0xffffff;
const int BLACK_COLOR = 0x000000;
const int ROOT_LAYOUT_WIDTH = 100;
Mms::Mms(const string& id) :
IMessage(MMS, id),
-// m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
m_messageData(NULL)
{
LoggerD("m_id=" << getIdRef());
- LoggerD("m_msgType=" << getMessageType());
char buf[] = "XXXXXX";
mode_t mask = umask(S_IWGRP | S_IWOTH);
LoggerD("buf : " << buf << " i : " << i);
umask(mask);
m_bodyFilePath = buf;
- m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
-
- LoggerD("m_bodyFilePath : " << m_bodyFilePath);
+ m_bodyFilePath = getWidgetPath()+TEXT_DIR_SEPERATOR+m_bodyFilePath+TEXT_FILE_EXTENSION;
if (getIdRef().empty()) {
- LoggerD("create new message");
createNewMessage();
} else {
- LoggerD("read existing message");
readExistingMessage();
}
}
Mms::Mms(const string& id, const msg_struct_t msg_data) :
IMessage(MMS, id),
-// m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
- m_messageData(msg_data)
+ m_messageData(NULL)
{
LoggerD("m_id=" << getIdRef());
- LoggerD("m_msgType=" << getMessageType());
+
+ m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
char buf[] = "XXXXXX";
mode_t mask = umask(S_IWGRP | S_IWOTH);
LoggerD("buf : " << buf << " i : " << i);
umask(mask);
m_bodyFilePath = buf;
- m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
-
- LoggerD("m_bodyFilePath : " << m_bodyFilePath);
-
+ m_bodyFilePath = getWidgetPath()+TEXT_DIR_SEPERATOR+m_bodyFilePath+TEXT_FILE_EXTENSION;
+
readConversationId(m_messageData);
readRecipientList(m_messageData);
readPriority(m_messageData);
readDateTime(m_messageData);
readReadStatus(m_messageData);
readMessageStatus(m_messageData);
-// setMessageStatus(MESSAGE_STATUS_LOADED);
}
// int recipientCount = msg_get_address_count(messageData);
// LoggerD("Recipient count " << recipientCount);
- msg_list_handle_t addr_list = NULL;
- msg_struct_t addr_info = NULL;
-
- msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
+ msg_struct_list_s *addr_list;
+ msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
int tempInt = 0;
char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
- int recipientCount = msg_list_length(addr_list);
+ int recipientCount = addr_list->nCount;
LoggerD("Recipient count " << recipientCount);
for (int i = 0; i < recipientCount; ++i)
if (MSG_DIRECTION_TYPE_MT == type)
{
- addr_info = (msg_struct_t)msg_list_nth_data(addr_list, i);
+ msg_struct_t addr_info = addr_list->msg_struct_info[i];
memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
phoneNumber = strNumber;
}
else if (MSG_DIRECTION_TYPE_MO == type)
{
- addr_info = (msg_struct_t)msg_list_nth_data(addr_list, i);
+ msg_struct_t addr_info = addr_list->msg_struct_info[i];
memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
LoggerD("attachment count: " << attachLen);
for (int a = 0; a < attachLen; ++a)
{
+ std::string tempString;
+ int tempInt;
+
attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
if (NULL == attach)
{
msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
+
+ msg_get_int_value(attach, MSG_MMS_ATTACH_MIME_TYPE_INT, &tempInt);
+ tempString = indexIntToMimeTypeString((MimeType)tempInt);
IAttachmentPtr att = appendAttachment(szFilePath, false);
if ((szFileName[0] =! '\0') &&
LoggerD("renaming to " << szFileName);
att->rename(szFileName);
}
+ att->setMimeType(tempString);
+ att->setAttachmentID((int)a);
+ att->setDownloaded(true);
}
msg_release_struct(&mms_struct);
}
+void Mms::readBody(msg_struct_t& messageData)
+{
+
+ int pageLen, mediaLen, tempInt, ret;
+
+ msg_struct_t mms_struct = NULL;
+
+ msg_list_handle_t page_list = NULL;
+ msg_list_handle_t media_list = NULL;
+
+ msg_struct_t page = NULL;
+ msg_struct_t media = NULL;
+
+ mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+ ret = msg_get_mms_struct(messageData, mms_struct);
+
+ if (ret != MSG_SUCCESS)
+ {
+ LoggerE("cannot get mms struct");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
+ }
+
+ char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
+ char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
+
+ msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
+ pageLen = msg_list_length(page_list);
+
+ if (pageLen > 0) {
+ setMmsType(MULTIPART_RELATED);
+ } else {
+ setMmsType(MULTIPART_MIXED);
+ }
+
+ LoggerD("page count: " << pageLen);
+
+ for (int p = 0; p < pageLen; ++p)
+ {
+ LoggerD("page " << p);
+ page = (msg_struct_t)msg_list_nth_data(page_list, p);
+
+ if (NULL == page) {
+ LoggerE("returned page is null, continue");
+ continue;
+ }
+
+ msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
+ mediaLen = msg_list_length(media_list);
+
+ for (int m = 0; m < mediaLen; ++m)
+ {
+ LoggerD("media file " << m);
+ media = (msg_struct_t)msg_list_nth_data(media_list, m);
+ if (NULL == media)
+ {
+ LoggerE("returned media is null, continue");
+ continue;
+ }
+
+ msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
+
+ memset(szFilePath, 0, sizeof(szFilePath));
+ msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
+
+ if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
+ {
+ //text value on first page goes to body attribute
+ LoggerD("setting body from " << szFilePath);
+
+ FILE* f = NULL;
+ f = fopen(szFilePath, "r");
+ if (!f)
+ {
+ LoggerE("cannot read file with body" << szFilePath);
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cannot read file with body");
+ }
+ fseek(f, 0, SEEK_END);
+ long int size = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ char* data = new (nothrow) char[size + 1];
+ size_t error;
+ if (data) {
+ memset(data, 0, size + 1);
+ error = fread(data, 1, size, f);
+ setBody(data);
+ delete[] data;
+ } else {
+ LoggerE("body is not set");
+ }
+ LoggerD("message body: '" << getBody() << "'");
+ fclose(f);
+ }
+ else
+ {
+ LoggerD("adding attachment " << szFilePath);
+
+ IAttachmentPtr attachment = appendAttachment(szFilePath, false);
+ //attachment->setMessage(this); //set IMessagePtr
+
+ memset(szFileName, 0, sizeof(szFileName));
+ msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
+ if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0))
+ {
+ LoggerD("renaming to " << szFileName);
+ attachment->rename(szFileName);
+ }
+ else if (MMS_SMIL_MEDIA_TEXT == tempInt)
+ {
+ std::stringstream newName;
+ newName << "body_page_" << p + 1 << ".txt";
+ LoggerD("renaming to " << newName.str());
+ attachment->rename(newName.str());
+ }
+ }
+ }
+ }
+ msg_release_struct(&mms_struct);
+}
+
+
bool Mms::hasAttachment()
{
std::size_t attachmentSize = getAttachmentsCount();
LoggerI("MMS updating platform recipients");
+ // reset addresses in platform structure
+// msg_reset_address(m_messageData);
+ msg_struct_list_s *addr_list = NULL;
+ msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
int nToCnt = 0;
+ nToCnt = addr_list->nCount;
+
+ LoggerI("addr_list->nCount" << addr_list->nCount);
+
+ if (nToCnt > 0)
+ {
+ for (int i = 0; i < nToCnt; i++) {
+ msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
+ msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
+ msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+ msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
+ msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
+ }
+ nToCnt = 0;
+ addr_list->nCount = nToCnt;
+ }
- msg_list_clear(m_messageData, MSG_MESSAGE_ADDR_LIST_HND);
+ LoggerI("addr_list->nCount" << addr_list->nCount);
vector<string> to = getToRecipients().getRecipients();
vector<string> cc = getCcRecipients().getRecipients();
LoggerI("updating to");
for (size_t i = 0; i < to.size(); i++)
{
- msg_struct_t tmpAddr;
-
if (i >= MAX_TO_ADDRESS_CNT)
{
LoggerE("max number of recipient exceeded");
}
LoggerD("adding to[" << i << "]=" << to[i]);
- msg_list_add_item(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr);
+ msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
- msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
-
- if (msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
+ if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
{
LoggerE("problem with adding to address");
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
}
- if(msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
+ if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
{
LoggerE("problem with adding to address");
}
nToCnt ++;
}
+ addr_list->nCount = nToCnt;
LoggerE("nToCnt : " << nToCnt);
+ LoggerE("addr_list->nCount: " <<addr_list->nCount);
+
}
+ LoggerI("addr_list->nCount" << addr_list->nCount);
if (cc.size())
{
LoggerI("updating cc");
for (size_t i = 0; i < cc.size(); i++)
{
- msg_struct_t tmpAddr;
-
if (nToCnt >= MAX_TO_ADDRESS_CNT)
{
LoggerE("max number of recipient exceeded");
}
LoggerD("adding cc[" << i << "]=" << cc[i]);
- msg_list_add_item(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr);
+ msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
- msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
-
- if (msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
+ if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
{
LoggerE("problem with adding cc address");
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
}
- if(msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
+ if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
{
LoggerE("problem with adding cc address");
}
nToCnt ++;
}
+ addr_list->nCount = nToCnt;
LoggerE("nToCnt : " << nToCnt);
+ LoggerE("addr_list->nCount: " <<addr_list->nCount);
}
+ LoggerI("addr_list->nCount" << addr_list->nCount);
if (bcc.size())
{
LoggerI("updating bcc");
for (size_t i = 0; i < bcc.size(); i++)
{
- msg_struct_t tmpAddr;
-
if (nToCnt >= MAX_TO_ADDRESS_CNT)
{
LoggerE("max number of recipient exceeded");
}
LoggerD("adding bcc[" << i << "]=" << bcc[i]);
- msg_list_add_item(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, &tmpAddr);
+ msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
- msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
-
- if (msg_set_int_value(tmpAddr, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
+ if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
{
LoggerE("problem with adding bcc address");
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
}
- if(msg_set_str_value(tmpAddr, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
+ if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
{
LoggerE("problem with adding bcc address");
}
nToCnt ++;
}
+ addr_list->nCount = nToCnt;
LoggerE("nToCnt : " << nToCnt);
+ LoggerE("addr_list->nCount: " <<addr_list->nCount);
}
+ LoggerI("addr_list->nCount" << addr_list->nCount);
setToValidity(true);
setCcValidity(true);
setBccValidity(true);
msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
- msg_list_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
+ msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
- msg_list_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
+ msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
- msg_list_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
+ msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
int error;
msg_struct_t attachment[20];
- for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
- IAttachmentPtr att = getAttachment(i);
+ for (size_t idx = 0; idx < getAttachmentsRef().size(); ++idx) {
+ IAttachmentPtr att = getAttachment(idx);
if (!att) {
continue;
}
}
//this function should return valid pointer
+ att->setMessage(SharedFromThis()); // setMessage to setMessageId
+ att->setAttachmentID((int)idx);
+ att->setDownloaded(true);
+
+ int ret = mimeTypeStringToIndexInt(att->getMimeType());
+
+ msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[idx]);
+ msg_set_str_value(attachment[idx], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
- msg_list_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[i]);
- msg_set_str_value(attachment[i], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
+ if(ret != MIME_UNKNOWN)
+ {
+ msg_set_int_value(attachment[idx], MSG_MMS_ATTACH_MIME_TYPE_INT, ret);
+ }
LoggerD("Attachment added");
{
LoggerD("updating m_id=" << getIdRef());
msg_error_t err = MSG_SUCCESS;
+ int tempInt = 0;
+
msg_struct_t msg = NULL;
msg_struct_t sendOpt = NULL;
if (err != MSG_SUCCESS)
{
- LoggerE("Get Message Failed!");
- ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+ LoggerE("msg_get_message() Failed!");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to get message for update");
}
if (this->getIdRef().empty()) {
ThrowMsg(WrtDeviceApis::Commons::PlatformException,
"existing msgId is zero, update msg not done");
}
-
+
+ err = msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+ if(err == MSG_SUCCESS)
+ {
+ msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
+ }
+
+ err = msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+ if(err == MSG_SUCCESS)
+ {
+ msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+ }
+
update(TRUE);
if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
{
- LoggerE("Failed to update message");
+ LoggerE("msg_update_message() Failed!");
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
}
msg_release_struct(&msg);
msg_release_struct(&msg);
msg_release_struct(&sendOpt);
LoggerE("platform error occurs");
+ ReThrow(WrtDeviceApis::Commons::PlatformException);
}
}
{
LoggerD("convert m_id= " << convertId(getIdRef()));
+ msg_struct_t sendOpt = NULL;
+
//prepare for add sms to draft folder
if (!m_messageData) {
//error if platform message not exists
Throw(WrtDeviceApis::Commons::PlatformException);
}
- //update all sms data
+ //update all mms data
if (getCurrentFolder() == DRAFTBOX) {
LoggerD("update all mms data");
updateSubject();
Try
{
int msgId = 0;
-// MSG_SENDINGOPT_S option = { false, false, false };
-// option.option.smsSendOpt.bReplyPath = true;
- // trying to get message from platform
+ sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+ // trying to add message
-// msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
-// msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+// msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
+ int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
+ if (ret < MSG_SUCCESS) {
+ LoggerE("msg_add_message failed, error code=" << ret);
+ Throw(WrtDeviceApis::Commons::PlatformException);
+ }
+ else
+ {
+ msgId = ret;
+ }
-// const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
+ LoggerD("Message ID : " << msgId);
-// msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
-// msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
-// msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
+ msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
setId(convertId(msgId));
- setFolderType(DRAFTBOX);
+ loadDraftMessage();
+
+ setFolderType(OUTBOX);
setMessageStatus(MESSAGE_STATUS_DRAFT);
+
+ msg_release_struct(&sendOpt);
}
Catch(WrtDeviceApis::Commons::PlatformException) {
LoggerE("remove message error");
- if (m_messageData) {
- //releasing platform message structure
-// msg_release_message(&m_messageData);
- msg_release_struct(&m_messageData);
- }
+ msg_release_struct(&sendOpt);
throw;
}
-
}
void Mms::addMessageToDraft()
msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
setId(convertId(msgId));
- setFolderType(DRAFTBOX);
- setMessageStatus(MESSAGE_STATUS_DRAFT);
+ loadDraftMessage();
msg_release_struct(&sendOpt);
}
+void Mms::loadDraftMessage()
+{
+ LoggerD("entered");
+
+ if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
+ }
+
+ msg_release_struct(&m_messageData);
+ m_messageData = NULL;
+ msg_struct_t sendOpt = NULL;
+
+ Try {
+
+ m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+ sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+ // trying to get message from platform
+ if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
+ {
+ LoggerE("get message error");
+ Throw(WrtDeviceApis::Commons::PlatformException);
+ }
+ LoggerD("message found with msgId=" << getIdRef());
+
+ // read all mms dat to abstraction layer
+ readConversationId(m_messageData);
+ readPriority(m_messageData);
+ readSubject(m_messageData);
+ readFolder(m_messageData);
+ readDateTime(m_messageData);
+ readReadStatus(m_messageData);
+ readMessageStatus(m_messageData);
+ readBody(m_messageData);
+
+ msg_release_struct(&sendOpt);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException) {
+ LoggerE("exception");
+ // nothing to do
+ msg_release_struct(&sendOpt);
+ }
+
+}
+
void Mms::readAllData()
{
- readExistingMessage();
+ LoggerD("entered");
+
+ if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
+ {
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
+ }
+
+ msg_release_struct(&m_messageData);
+ m_messageData = NULL;
+ msg_struct_t sendOpt = NULL;
+
+ Try {
+
+ m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+ sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+ // trying to get message from platform
+ if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
+ {
+ LoggerE("get message error");
+ Throw(WrtDeviceApis::Commons::PlatformException);
+ }
+ LoggerD("message found with msgId=" << getIdRef());
+
+ // read all mms dat to abstraction layer
+ readConversationId(m_messageData);
+// readRecipientList(m_messageData);
+ readPriority(m_messageData);
+ readSubject(m_messageData);
+ readBodyAndAttachments(m_messageData);
+ readFolder(m_messageData);
+ readDateTime(m_messageData);
+ readReadStatus(m_messageData);
+ readMessageStatus(m_messageData);
+
+ msg_release_struct(&sendOpt);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException) {
+ LoggerE("exception");
+ // nothing to do
+ msg_release_struct(&sendOpt);
+ }
+
}
void Mms::moveToFolder(const FolderType newFolder)
int Mms::send()
{
LoggerD("sending message, id=" << getIdRef());
+ msg_error_t err = MSG_SUCCESS;
+
Try
{
//prepare for sending sms/mms
update();
- LoggerD("Start Sending Message...");
-
LoggerD("trying to send mms");
- msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+ if (!getCellularOn())
+ {
+ err = MSG_ERR_TRANSPORT_ERROR;
+ LoggerW("MMS send error. No transport possible over network");
+ }
+ else
+ {
+ err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+ }
if (err != MSG_SUCCESS)
{
LoggerE("Sending Message (submit request) failed!!! err=" << err);
setMessageStatus(MESSAGE_STATUS_FAILED);
- goto ERROR;
+ Throw(WrtDeviceApis::Commons::PlatformException);
}
setMessageStatus(MESSAGE_STATUS_SENDING);
}
Catch(WrtDeviceApis::Commons::PlatformException) {
LoggerE("message is not send, manually run callback");
- goto ERROR;
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver) {
+ LoggerE("send Error");
+ EventMessagingServicePtr event = getMessagingServiceEvent();
+ if(err == MSG_ERR_TRANSPORT_ERROR)
+ {
+ event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformWrongStateException);
+ }
+ else
+ {
+ event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+ }
+ requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
+ }
}
return 0;
-
- ERROR:
- ReqReceiverMessage *requestReceiver = getRequestReceiver();
- if (requestReceiver) {
- LoggerE("send Error");
- EventMessagingServicePtr event = getMessagingServiceEvent();
- event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
- requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
- }
- return 0;
}
void Mms::sendingCallback(msg_struct_t sent_status)
{
-// LoggerI("sendingCallback callback received. Req id = " <<
-// sent_status->reqId << " Status = " << (int)sent_status->status);
-// msg_struct_t request_data = NULL;
-// msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
-// msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
int status = MSG_NETWORK_SEND_FAIL;
msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
{
//success callback should be executed here
ReqReceiverMessage *requestReceiver = getRequestReceiver();
- msg_list_handle_t addr_list = NULL;
- msg_struct_t addr_info = NULL;
-
+ msg_struct_list_s *addr_list = NULL;
char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
int nToCnt;
EventMessagingServicePtr event = getMessagingServiceEvent();
event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
- msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
+ msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
- nToCnt = msg_list_length(addr_list);
+ nToCnt = addr_list->nCount;
for ( int index=0; index < nToCnt; index++)
{
- addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
- msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+ msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
event->m_successRecipients.push_back(strNumber);
}
{
//error callback should be executed here
EventOnSendingFailedEmitterPtr emitter = getEmitter();
- msg_list_handle_t addr_list = NULL;
- msg_struct_t addr_info = NULL;
-
+ msg_struct_list_s *addr_list = NULL;
char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
int nToCnt;
{
LoggerE("calling JS error callback");
event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
-
- msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
- nToCnt = msg_list_length(addr_list);
+ msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+ nToCnt = addr_list->nCount;
LoggerD("nToCnt : " << nToCnt);
for ( int index=0; index < nToCnt; index++)
{
- addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
- msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+ msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
event->m_failRecipients.push_back(strNumber);
}
}
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
}
+
+bool Mms::getCellularOn()
+{
+ auto cellularOn = true;
+ int tempInt;
+ int tempbool;
+
+ vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &tempInt);
+ vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &tempbool);
+ if(tempInt <= VCONFKEY_TELEPHONY_SVCTYPE_SEARCH || tempbool == TRUE)
+ {
+ LoggerE("VCONFKEY_TELEPHONY_SVCTYPE error " << tempInt);
+ LoggerE("VCONFKEY_TELEPHONY_FLIGHT_MODE error " << tempbool);
+ cellularOn = false;
+ return cellularOn;
+ }
+
+ vconf_get_bool(VCONFKEY_3G_ENABLE, &tempbool);
+ vconf_get_int(VCONFKEY_TELEPHONY_SVC_PS, &tempInt);
+ if(tempbool == FALSE || tempInt != VCONFKEY_TELEPHONY_SVC_PS_ON)
+ {
+ LoggerE("VCONFKEY_3G_ENABLE error " << tempbool);
+ LoggerE("VCONFKEY_TELEPHONY_SVC_PS_ON error " << tempInt);
+ cellularOn = false;
+ }
+ return cellularOn;
+}
+
+
+MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
+{
+ const char* szMimeStr = inputString.c_str();
+ MimeType retInt = MIME_UNKNOWN;
+
+ LoggerD("szMimeStr " << szMimeStr);
+
+ for(int idx =0; strcmp(mimeTable[idx].szMIME, "") != 0; idx++)
+ {
+ if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
+ retInt = mimeTable[idx].mime;
+ break;
+ }
+ }
+ return retInt;
+
+}
+
+std::string Mms::indexIntToMimeTypeString(MimeType inputIndex)
+{
+ std::string retString;
+
+ for (int idx=0; mimeTable[idx].szMIME != NULL; idx++) {
+ if (inputIndex == mimeTable[idx].mime) {
+ retString = (char *)mimeTable[idx].szMIME;
+ }
+ }
+ return retString;
+}
+
+msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
+{
+ int tempInt, nCount, ret;
+ bool tempBool;
+ msg_struct_list_s *addr_list;
+ msg_struct_list_s *new_addr_list;
+
+ msg_struct_t mms_struct = NULL;
+ msg_struct_t mms_struct_dummy = NULL;
+
+ msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+
+ msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
+
+ char strSubject[MAX_SUBJECT_LEN] = {0};
+ msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+ msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+
+ msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
+
+ msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
+
+ msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+
+// msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+// char tempStr[tempInt+1];
+// memset(tempStr, 0, tempInt+1);
+
+// msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
+// msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
+// copy mms body and attachment
+ mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+ mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
+ ret = msg_get_mms_struct(src, mms_struct);
+ if (ret != MSG_SUCCESS)
+ {
+ LoggerE("cannot get mms struct");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
+ }
+
+ msg_set_mms_struct(src, mms_struct_dummy);
+ msg_set_mms_struct(msg, mms_struct);
+
+ msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
+
+// msg_set_network_status(msg, msg_get_network_status(src));
+ msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
+
+// msg_set_encode_type(msg, msg_get_encode_type(src));
+ msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
+
+// msg_set_read_status(msg, msg_is_read(src));
+ msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
+ msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
+
+// msg_set_protect_status(msg, msg_is_protected(src));
+ msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
+ msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
+
+// msg_set_priority_info(msg, msg_get_priority_info(src));
+ msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
+
+// msg_set_direction_info(msg, msg_get_direction_info(src));
+ msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
+
+// msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
+ msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
+ msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
+
+// copy addr list
+ msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+ msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
+
+ new_addr_list->nCount = addr_list->nCount;
+
+ for(int i=0; i<addr_list->nCount; i++)
+ {
+ msg_struct_t addr_info = NULL;
+ msg_struct_t new_addr_info = NULL;
+ char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
+
+ //get original address
+ addr_info = addr_list->msg_struct_info[i];
+ msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+ msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
+
+ //copy original address
+ new_addr_info = new_addr_list->msg_struct_info[i];
+ msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+ msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
+ }
+
+ msg_release_struct(&mms_struct_dummy);
+ msg_release_struct(&mms_struct);
+
+ return msg;
+}
+
}
}