From: Robert Karolak Date: Tue, 13 Jan 2015 13:33:56 +0000 (+0100) Subject: [Messaging] Add support for MMS messages, changes LOG to LOGGER in X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~602^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72458c59f25949422bf05b8c4ca5c01470d34c3f;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Messaging] Add support for MMS messages, changes LOG to LOGGER in whole messaging plugin [Verification] Code compiles without errors, 233/309 tests passes Change-Id: I637d250b531059683822945db68fcda4c29e9473 Signed-off-by: Robert Karolak --- diff --git a/src/messaging/DBus/Connection.cpp b/src/messaging/DBus/Connection.cpp index 6eed4926..c39d01bd 100644 --- a/src/messaging/DBus/Connection.cpp +++ b/src/messaging/DBus/Connection.cpp @@ -28,7 +28,7 @@ namespace DBus { Connection& Connection::getInstance() { - LOGD("Entered"); + LoggerD("Entered"); static Connection instance; return instance; } diff --git a/src/messaging/DBus/EmailSignalProxy.cpp b/src/messaging/DBus/EmailSignalProxy.cpp index b11254bb..8f8739d5 100644 --- a/src/messaging/DBus/EmailSignalProxy.cpp +++ b/src/messaging/DBus/EmailSignalProxy.cpp @@ -64,7 +64,7 @@ void EmailSignalProxy::signalCallback(GDBusConnection* connection, //It is better to log this only when subclass is responsible of handling //passed signal (usually determined by status value). // - //LOGD("email:\n status: %d\n mail_id: %d\n " + //LoggerD("email:\n status: %d\n mail_id: %d\n " // "source: %s\n op_handle: %d\n error_code: %d", // status, mail_id, source, op_handle, error_code); diff --git a/src/messaging/DBus/Proxy.cpp b/src/messaging/DBus/Proxy.cpp index fc5c6c57..c7c817e2 100644 --- a/src/messaging/DBus/Proxy.cpp +++ b/src/messaging/DBus/Proxy.cpp @@ -93,7 +93,7 @@ void Proxy::signalCallbackProxy(GDBusConnection *connection, try { //It is better to log this only when subclass is responsible of handling //passed signal. If you need it put it into your signalCallback(...) method - //LOGD("signal: %s from: %s path: %s interface: %s", + //LoggerD("signal: %s from: %s path: %s interface: %s", // signal_name, sender_name, object_path, interface_name); this_ptr->signalCallback(connection, sender_name, object_path, interface_name, diff --git a/src/messaging/DBus/SyncProxy.cpp b/src/messaging/DBus/SyncProxy.cpp index 6fd99f9f..adc0cc85 100644 --- a/src/messaging/DBus/SyncProxy.cpp +++ b/src/messaging/DBus/SyncProxy.cpp @@ -104,7 +104,7 @@ void SyncProxy::handleEmailSignal(const int status, callback_it = findSyncCallbackByOpHandle(op_handle); callback = callback_it->second; if (!callback) { - LOGE("Callback is null"); + LoggerE("Callback is null"); throw common::UnknownException("Callback is null"); } diff --git a/src/messaging/MsgCommon/AbstractFilter.cpp b/src/messaging/MsgCommon/AbstractFilter.cpp index 7352b10e..dd9df7b4 100644 --- a/src/messaging/MsgCommon/AbstractFilter.cpp +++ b/src/messaging/MsgCommon/AbstractFilter.cpp @@ -43,56 +43,6 @@ FilterType AbstractFilter::getFilterType() const return m_filter_type; } -//JSValueRef AbstractFilter::makeJSValue(JSContextRef context, -// AbstractFilterPtr native) -//{ -// LOGD("Entered"); -// -// if (!native) { -// LOGE("Native is null"); -// throw UnknownException("Native is null"); -// } -// -// switch (native->getFilterType()) { -// case ATTRIBUTE_FILTER: -// return JSAttributeFilter::makeJSObject(context, native); -// case ATTRIBUTE_RANGE_FILTER: -// return JSAttributeRangeFilter::makeJSObject(context, native); -// case COMPOSITE_FILTER: -// return JSCompositeFilter::makeJSObject(context, native); -// default: -// LOGE("Unsupported filter type"); -// throw UnknownException("Unsupported filter type"); -// } -//} -// -//AbstractFilterPtr AbstractFilter::getPrivateObject(JSContextRef context, -// JSValueRef value) -//{ -// JSObjectRef object = JSUtil::JSValueToObject(context, value); -// -// if (!JSValueIsObjectOfClass(context, value, JSAttributeFilter::getClassRef()) && -// !JSValueIsObjectOfClass(context, value, JSAttributeRangeFilter::getClassRef()) && -// !JSValueIsObjectOfClass(context, value, JSCompositeFilter::getClassRef())) { -// LOGE("JSObjectRef:%p - Object type is not JSAttributeFilter, " -// "JSAttributeRangeFilter nor JSCompositeFilter", object); -// throw TypeMismatchException("Object type is not valid filter"); -// } -// -// AbstractFilterHolder* priv = -// static_cast(JSObjectGetPrivate(object)); -// if (!priv) { -// LOGE("Holder is null"); -// throw UnknownException("Holder is null"); -// } -// if (!(priv->ptr)) { -// LOGE("Priv is null"); -// throw UnknownException("Priv is null"); -// } -// return priv->ptr; -//} - - bool AbstractFilter::isMatching(const FilterableObject* const tested_object) const { LoggerE("Calling isMatching on AbstractFilter!"); diff --git a/src/messaging/MsgCommon/CompositeFilter.cpp b/src/messaging/MsgCommon/CompositeFilter.cpp index 1c4fa4e4..5ecac84d 100644 --- a/src/messaging/MsgCommon/CompositeFilter.cpp +++ b/src/messaging/MsgCommon/CompositeFilter.cpp @@ -70,7 +70,7 @@ const AbstractFilterPtrVector& CompositeFilter::getFilters() const //JSFilterArray CompositeFilter::getJSFilters(JSContextRef global_ctx) //{ // if (!m_context && !global_ctx) { -// LOGE("Context is not set"); +// LoggerE("Context is not set"); // throw Common::UnknownException("Context is not set"); // } // else if (!m_context && global_ctx) { @@ -79,7 +79,7 @@ const AbstractFilterPtrVector& CompositeFilter::getFilters() const // // if (!Common::GlobalContextManager::getInstance()->isAliveGlobalContext( // m_context)) { -// LOGE("Context is not alive"); +// LoggerE("Context is not alive"); // throw Common::UnknownException("Context is not alive"); // } // else if (!m_js_filters) { diff --git a/src/messaging/message.cc b/src/messaging/message.cc index 4a774218..ac3bb480 100644 --- a/src/messaging/message.cc +++ b/src/messaging/message.cc @@ -14,6 +14,7 @@ #include "Ecore_File.h" #include "message_email.h" #include "message_sms.h" +#include "message_mms.h" #include "short_message_manager.h" #include "messaging_util.h" @@ -332,7 +333,7 @@ std::string copyFileToTemp(const std::string& sourcePath) mode_t mask = umask(S_IWGRP | S_IWOTH); int err = mkstemp(buf); if (-1 == err) { - LOGW("Failed to create unique filename"); + LoggerW("Failed to create unique filename"); } umask(mask); @@ -485,7 +486,7 @@ void addSingleEmailAttachment(std::shared_ptr message, LoggerE("Error while adding attachment %d", err); err = email_free_attachment_data(&tmp, 1); if (EMAIL_ERROR_NONE != err) { - LOGW("Failed to free attachment data"); + LoggerW("Failed to free attachment data"); } throw common::UnknownException("Unknown error while adding attachment"); } @@ -494,7 +495,7 @@ void addSingleEmailAttachment(std::shared_ptr message, att->setMessageId(id); err = email_free_attachment_data(&tmp, 1); if (EMAIL_ERROR_NONE != err) { - LOGW("Failed to free attachment data"); + LoggerW("Failed to free attachment data"); } removeDirFromTemp(dirPath); @@ -630,27 +631,28 @@ void Message::addMMSRecipientsToStruct(const std::vector &recipient } } -//void Message::addMMSBodyAndAttachmentsToStruct(const AttachmentPtrVector attach, -// msg_struct_t &mms_struct, Message* message) -//{ -// LoggerD("Entered with %d attachments", attach.size()); -// -// int size = attach.size(); -// for (int i = 0; i < size; i++) { -// -// msg_struct_t tmpAtt = NULL; -// int error = msg_list_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &tmpAtt); -// if (MSG_SUCCESS == error) { -// -// //Ensure we have right id set -// attach[i]->setId(i+1); -// attach[i]->setMessageId(message->getId()); -// -// //------------------------------------------------------------------------- -// // set file path, file name, file size -// if (attach.at(i)->isFilePathSet()) { -// std::string filepath = attach.at(i)->getFilePath(); -// LoggerD("att[%d]: org filepath: %s", i, filepath.c_str()); +void Message::addMMSBodyAndAttachmentsToStruct(const AttachmentPtrVector attach, + msg_struct_t &mms_struct, Message* message) +{ + LoggerD("Entered with %d attachments", attach.size()); + + int size = attach.size(); + for (int i = 0; i < size; i++) { + + msg_struct_t tmpAtt = NULL; + int error = msg_list_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &tmpAtt); + if (MSG_SUCCESS == error) { + + //Ensure we have right id set + attach[i]->setId(i+1); + attach[i]->setMessageId(message->getId()); + + //------------------------------------------------------------------------- + // set file path, file name, file size + if (attach.at(i)->isFilePathSet()) { + std::string filepath = attach.at(i)->getFilePath(); + LoggerD("att[%d]: org filepath: %s", i, filepath.c_str()); +// TODO uncomment when filesystem will be available // if(Filesystem::External::isVirtualPath(filepath)) { // // TODO // // When introducing below line fromVirtualPath() function @@ -660,45 +662,45 @@ void Message::addMMSRecipientsToStruct(const std::vector &recipient // filepath = Filesystem::External::fromVirtualPath(filepath); // LoggerD("att[%d]: org virtual filepath: %s", i, filepath.c_str()); // } -// msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_FILEPATH_STR, -// const_cast(filepath.c_str()), filepath.size()); -// const size_t last_slash_idx = filepath.find_last_of("\\/"); -// if (std::string::npos != last_slash_idx) { -// filepath.erase(0, last_slash_idx + 1); -// } -// -// LoggerD("att[%d] filename: %s", i, filepath.c_str()); -// msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_FILENAME_STR, -// const_cast(filepath.c_str()), filepath.size()); -// struct stat st; -// if (stat(const_cast(filepath.c_str()), &st)) { -// LoggerE("Stat error"); -// } -// const int fsize = st.st_size; -// msg_set_int_value(tmpAtt, MSG_MMS_ATTACH_FILESIZE_INT, fsize); -// LoggerD("att[%d]: filesize: %d", i,fsize); -// } -// -// //------------------------------------------------------------------------- -// //set mime type -// if (attach.at(i)->isMimeTypeSet()) { -// unsigned int type = MessageAttachment::MIMETypeStringToEnum( -// attach.at(i)->getMimeType()); -// msg_set_int_value(tmpAtt, MSG_MMS_ATTACH_MIME_TYPE_INT, type); -// msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_CONTENT_TYPE_STR, -// const_cast(attach.at(i)->getMimeType().c_str()), -// MSG_MSG_ID_LEN); -// -// -// LoggerD("att[%d]: setting mime type:0x%x (orignal:%s)", i, type, -// attach.at(i)->getMimeType().c_str()); -// } -// } else { -// LoggerE("att[%d]: failed to add attachment"); -// throw common::UnknownException("failed to add attachment"); -// } -// } -//} + msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_FILEPATH_STR, + const_cast(filepath.c_str()), filepath.size()); + const size_t last_slash_idx = filepath.find_last_of("\\/"); + if (std::string::npos != last_slash_idx) { + filepath.erase(0, last_slash_idx + 1); + } + + LoggerD("att[%d] filename: %s", i, filepath.c_str()); + msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_FILENAME_STR, + const_cast(filepath.c_str()), filepath.size()); + struct stat st; + if (stat(const_cast(filepath.c_str()), &st)) { + LoggerE("Stat error"); + } + const int fsize = st.st_size; + msg_set_int_value(tmpAtt, MSG_MMS_ATTACH_FILESIZE_INT, fsize); + LoggerD("att[%d]: filesize: %d", i,fsize); + } + + //------------------------------------------------------------------------- + //set mime type + if (attach.at(i)->isMimeTypeSet()) { + unsigned int type = MessageAttachment::MIMETypeStringToEnum( + attach.at(i)->getMimeType()); + msg_set_int_value(tmpAtt, MSG_MMS_ATTACH_MIME_TYPE_INT, type); + msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_CONTENT_TYPE_STR, + const_cast(attach.at(i)->getMimeType().c_str()), + MSG_MSG_ID_LEN); + + + LoggerD("att[%d]: setting mime type:0x%x (orignal:%s)", i, type, + attach.at(i)->getMimeType().c_str()); + } + } else { + LoggerE("att[%d]: failed to add attachment"); + throw common::UnknownException("failed to add attachment"); + } + } +} msg_struct_t Message::convertPlatformShortMessageToStruct(Message* message, msg_handle_t handle) @@ -798,83 +800,83 @@ msg_struct_t Message::convertPlatformShortMessageToStruct(Message* message, } } // Set MMS message text -// std::shared_ptr body; -// body = message->getBody(); -// if (!body->getPlainBody().empty()) { -// LoggerD("Message(%p): PlainBody is NOT empty", message); -// -// static const int ROOT_LAYOUT_WIDTH = 100; -// static const int ROOT_LAYOUT_HEIGHT = 100; -// static const int WHITE_COLOR = 0xffffff; -// static const int BLACK_COLOR = 0x000000; -// -// //---------------------------------------------------------------------------- -// //Region -// msg_struct_t region; -// msg_list_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); -// msg_set_str_value(region, MSG_MMS_REGION_ID_STR, const_cast("Text"), 4); -// -// msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0); -// msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0); -// msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, -// ROOT_LAYOUT_WIDTH); -// msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, -// ROOT_LAYOUT_HEIGHT); -// msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR); -// -// msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true); -// msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true); -// msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true); -// msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true); -// -// //---------------------------------------------------------------------------- -// //Page -// msg_struct_t page; -// msg_list_add_item(mms_data, MSG_STRUCT_MMS_PAGE, &page); -// msg_set_int_value(page, MSG_MMS_PAGE_PAGE_DURATION_INT, 0); -// -// //---------------------------------------------------------------------------- -// //Media -// msg_struct_t media; -// msg_list_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); -// msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT); -// msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, -// const_cast("Text"), 4); -// -// std::string body_file_path = saveToTempFile(body->getPlainBody()); -// int error = msg_set_str_value(media, -// MSG_MMS_MEDIA_FILEPATH_STR, -// const_cast(body_file_path.c_str()), -// body_file_path.size()); -// if (error != MSG_SUCCESS) { -// LoggerE("Message(%p): Failed to set mms body filepath", message); -// throw common::UnknownException("Failed to set mms body filepath"); -// } -// msg_set_str_value(media, MSG_MMS_MEDIA_CONTENT_TYPE_STR, -// "text/plain", 10); -// -// //---------------------------------------------------------------------------- -// //Smile text -// msg_struct_t smil_text; -// msg_get_struct_handle(media, MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text); -// msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR); -// msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_SIZE_INT, -// MMS_SMIL_FONT_SIZE_NORMAL); -// msg_set_bool_value(smil_text, MSG_MMS_SMIL_TEXT_BOLD_BOOL, true); -// } else { -// LoggerD("Message(%p): PlainBody is EMPTY", message); -// } -// // Set MMS attachments -// AttachmentPtrVector attach_list = message->getMessageAttachments(); -// LoggerD("Message(%p): id:%d subject:[%s] plainBody:[%s] contains %d attachments", -// message, message->getId(), message->getSubject().c_str(), -// message->getBody()->getPlainBody().c_str(), attach_list.size()); -// -// msg_set_int_value(mms_data, MSG_MESSAGE_ATTACH_COUNT_INT, -// attach_list.size()); -// if (!attach_list.empty()) { -// addMMSBodyAndAttachmentsToStruct(attach_list, mms_data, message); -// } + std::shared_ptr body; + body = message->getBody(); + if (!body->getPlainBody().empty()) { + LoggerD("Message(%p): PlainBody is NOT empty", message); + + static const int ROOT_LAYOUT_WIDTH = 100; + static const int ROOT_LAYOUT_HEIGHT = 100; + static const int WHITE_COLOR = 0xffffff; + static const int BLACK_COLOR = 0x000000; + + //---------------------------------------------------------------------------- + //Region + msg_struct_t region; + msg_list_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); + msg_set_str_value(region, MSG_MMS_REGION_ID_STR, const_cast("Text"), 4); + + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, + ROOT_LAYOUT_WIDTH); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, + ROOT_LAYOUT_HEIGHT); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR); + + msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true); + msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true); + msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true); + msg_set_bool_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true); + + //---------------------------------------------------------------------------- + //Page + msg_struct_t page; + msg_list_add_item(mms_data, MSG_STRUCT_MMS_PAGE, &page); + msg_set_int_value(page, MSG_MMS_PAGE_PAGE_DURATION_INT, 0); + + //---------------------------------------------------------------------------- + //Media + msg_struct_t media; + msg_list_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT); + msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, + const_cast("Text"), 4); + + std::string body_file_path = saveToTempFile(body->getPlainBody()); + int error = msg_set_str_value(media, + MSG_MMS_MEDIA_FILEPATH_STR, + const_cast(body_file_path.c_str()), + body_file_path.size()); + if (error != MSG_SUCCESS) { + LoggerE("Message(%p): Failed to set mms body filepath", message); + throw common::UnknownException("Failed to set mms body filepath"); + } + msg_set_str_value(media, MSG_MMS_MEDIA_CONTENT_TYPE_STR, + "text/plain", 10); + + //---------------------------------------------------------------------------- + //Smile text + msg_struct_t smil_text; + msg_get_struct_handle(media, MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text); + msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR); + msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_SIZE_INT, + MMS_SMIL_FONT_SIZE_NORMAL); + msg_set_bool_value(smil_text, MSG_MMS_SMIL_TEXT_BOLD_BOOL, true); + } else { + LoggerD("Message(%p): PlainBody is EMPTY", message); + } + // Set MMS attachments + AttachmentPtrVector attach_list = message->getMessageAttachments(); + LoggerD("Message(%p): id:%d subject:[%s] plainBody:[%s] contains %d attachments", + message, message->getId(), message->getSubject().c_str(), + message->getBody()->getPlainBody().c_str(), attach_list.size()); + + msg_set_int_value(mms_data, MSG_MESSAGE_ATTACH_COUNT_INT, + attach_list.size()); + if (!attach_list.empty()) { + addMMSBodyAndAttachmentsToStruct(attach_list, mms_data, message); + } // Set MMS body int r = msg_set_mms_struct(msg, mms_data); if (r != MSG_SUCCESS) { @@ -1152,7 +1154,7 @@ void Message::setMMSBodyAndAttachmentsFromStruct(Message* message, } if(false == body_has_been_set) { - LOGW("Warning: body has not been set!"); + LoggerW("Warning: body has not been set!"); } LoggerD("after MSG_MMS_PAGE_LIST attachments count is:%d", @@ -1171,7 +1173,7 @@ void Message::setMMSBodyAndAttachmentsFromStruct(Message* message, msg_struct_t attach_info = NULL; attach_info = (msg_struct_t) msg_list_nth_data(attach_list, i); if(!attach_info) { - LOGW("[att:%d] attach_info is NULL!", i); + LoggerW("[att:%d] attach_info is NULL!", i); continue; } @@ -1233,57 +1235,57 @@ Message* Message::convertPlatformShortMessageToObject(msg_struct_t msg){ std::vector recp_list = message->getSMSRecipientsFromStruct(msg); message->setTO(recp_list); } else if (infoInt == MSG_TYPE_MMS) { -// message = new MessageMMS(); -// -// // get MMS body -// msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &infoInt); -// const int mms_body_length = infoInt; -// -// if(mms_body_length > 0) { -// std::unique_ptr mms_body_str(new char[mms_body_length + 1]); -// memset(mms_body_str.get(), 0, (mms_body_length + 1) * sizeof(char)); -// -// int error = msg_get_str_value(msg, MSG_MESSAGE_MMS_TEXT_STR, -// mms_body_str.get(), mms_body_length); -// if(MSG_SUCCESS != error) { -// LoggerE("Error:%d occured during: " -// "msg_get_str_value(...,MSG_MESSAGE_MMS_TEXT_STR,...)", error); -// } else { -// //Check if fetched string is not empty -// if((mms_body_str.get())[0] != 0) { -// LoggerD("Fetched plain body (with MSG_MESSAGE_MMS_TEXT_STR):" -// "[%s] length:%d", mms_body_str.get(), mms_body_length); -// -// std::shared_ptr body (new MessageBody()); -// std::string infoString; -// infoString.assign(mms_body_str.get()); -// body->setPlainBody(infoString); -// message->setBody(body); -// } else { -// LOGW("Warning: fetched plain body is empty " -// "despite reported length is:%d!", mms_body_length); -// } -// -// LoggerD("Set plain body: [%s]", message->getBody()->getPlainBody().c_str()); -// } -// } else { -// LOGW("Warning: mms plain body length is 0!"); -// } -// -// // get recipients -// std::vector recp_list = getMMSRecipientsFromStruct(msg, -// MSG_RECIPIENTS_TYPE_TO); -// message->setTO(recp_list); -// recp_list = getMMSRecipientsFromStruct(msg, MSG_RECIPIENTS_TYPE_CC); -// message->setCC(recp_list); -// recp_list = getMMSRecipientsFromStruct(msg, MSG_RECIPIENTS_TYPE_BCC); -// message->setBCC(recp_list); -// // get subject -// memset(infoStr, 0, MAX_ADDRESS_VAL_LEN + 1); -// msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, infoStr, MAX_SUBJECT_LEN); -// message->setSubject(infoStr); -// //set attachments -// setMMSBodyAndAttachmentsFromStruct(message, msg); + message = new MessageMMS(); + + // get MMS body + msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &infoInt); + const int mms_body_length = infoInt; + + if(mms_body_length > 0) { + std::unique_ptr mms_body_str(new char[mms_body_length + 1]); + memset(mms_body_str.get(), 0, (mms_body_length + 1) * sizeof(char)); + + int error = msg_get_str_value(msg, MSG_MESSAGE_MMS_TEXT_STR, + mms_body_str.get(), mms_body_length); + if(MSG_SUCCESS != error) { + LoggerE("Error:%d occured during: " + "msg_get_str_value(...,MSG_MESSAGE_MMS_TEXT_STR,...)", error); + } else { + //Check if fetched string is not empty + if((mms_body_str.get())[0] != 0) { + LoggerD("Fetched plain body (with MSG_MESSAGE_MMS_TEXT_STR):" + "[%s] length:%d", mms_body_str.get(), mms_body_length); + + std::shared_ptr body (new MessageBody()); + std::string infoString; + infoString.assign(mms_body_str.get()); + body->setPlainBody(infoString); + message->setBody(body); + } else { + LoggerW("Warning: fetched plain body is empty " + "despite reported length is:%d!", mms_body_length); + } + + LoggerD("Set plain body: [%s]", message->getBody()->getPlainBody().c_str()); + } + } else { + LoggerW("Warning: mms plain body length is 0!"); + } + + // get recipients + std::vector recp_list = getMMSRecipientsFromStruct(msg, + MSG_RECIPIENTS_TYPE_TO); + message->setTO(recp_list); + recp_list = getMMSRecipientsFromStruct(msg, MSG_RECIPIENTS_TYPE_CC); + message->setCC(recp_list); + recp_list = getMMSRecipientsFromStruct(msg, MSG_RECIPIENTS_TYPE_BCC); + message->setBCC(recp_list); + // get subject + memset(infoStr, 0, MAX_ADDRESS_VAL_LEN + 1); + msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, infoStr, MAX_SUBJECT_LEN); + message->setSubject(infoStr); + //set attachments + setMMSBodyAndAttachmentsFromStruct(message, msg); } else { LoggerE("Invalid Message type: %d", infoInt); throw common::InvalidValuesException("Invalid Message type"); @@ -1349,7 +1351,7 @@ Message* Message::convertPlatformShortMessageToObject(msg_struct_t msg){ } else if (infoInt == MSG_NETWORK_NOT_SEND) { msg_status = MessageStatus::STATUS_DRAFT; } else { - LOGW("warning undefined messageStatus: %d!", infoInt); + LoggerW("warning undefined messageStatus: %d!", infoInt); msg_status = MessageStatus::STATUS_UNDEFINED; } message->setMessageStatus(msg_status); @@ -1360,7 +1362,7 @@ Message* Message::convertPlatformShortMessageToObject(msg_struct_t msg){ LoggerE("Couldn't get MSG_SENT_STATUS_NETWORK_STATUS_INT, error:%d", error); if(0 == message->getId()) { - LOGW("Both MSG_SENT_STATUS_NETWORK_STATUS_INT and " + LoggerW("Both MSG_SENT_STATUS_NETWORK_STATUS_INT and " "MSG_MESSAGE_FOLDER_ID_INT failed, messageId == 0 ASSUMING that" "this message is in DRAFT"); message->setMessageStatus(MessageStatus::STATUS_DRAFT); @@ -1459,7 +1461,7 @@ std::shared_ptr Message::convertPlatformEmailToObject( void Message::updateEmailMessage(email_mail_data_t& mail) { - LOGW("This should be called on MessageEmail instance"); + LoggerW("This should be called on MessageEmail instance"); } /** diff --git a/src/messaging/message_attachment.cc b/src/messaging/message_attachment.cc index be4111a1..d529af09 100755 --- a/src/messaging/message_attachment.cc +++ b/src/messaging/message_attachment.cc @@ -14,7 +14,7 @@ std::map& MessageAttachment::MIMETypeEnumToStringMap MessageAttachment::MessageAttachment() { - LOGD("MessageAttachment constructor (%p)", this); + LoggerD("MessageAttachment constructor (%p)", this); m_id = -1; m_isIdSet = false; m_messageId = -1; @@ -28,7 +28,7 @@ MessageAttachment::MessageAttachment() MessageAttachment::~MessageAttachment() { - LOGD("MessageAttachment destructor (%p)", this); + LoggerD("MessageAttachment destructor (%p)", this); } // id @@ -561,8 +561,8 @@ void MessageAttachment::updateWithAttachmentData(const email_attachment_data_t& if (attachment_data.attachment_path) { setFilePath(attachment_data.attachment_path); - LOGD("save status: %d", attachment_data.save_status); - LOGD("attachment_size : %d", attachment_data.attachment_size); + LoggerD("save status: %d", attachment_data.save_status); + LoggerD("attachment_size : %d", attachment_data.attachment_size); isSaved = attachment_data.save_status; } diff --git a/src/messaging/message_body.cc b/src/messaging/message_body.cc index 8837888a..90ae6679 100644 --- a/src/messaging/message_body.cc +++ b/src/messaging/message_body.cc @@ -94,26 +94,26 @@ bool MessageBody::is_message_id_set() const void MessageBody::updateBody(email_mail_data_t& mail) { - LOGD("Enter"); + LoggerD("Enter"); setMessageId(mail.mail_id); setLoaded(mail.body_download_status); if (mail.file_path_plain) { try { - LOGD("Plain body"); + LoggerD("Plain body"); setPlainBody(MessagingUtil::loadFileContentToString(mail.file_path_plain)); } catch (...) { - LOGE("Fail to open plain body."); + LoggerE("Fail to open plain body."); throw common::UnknownException("Fail to open plain body."); } } if (mail.file_path_html) { try { - LOGD("Html body"); + LoggerD("Html body"); setHtmlBody(MessagingUtil::loadFileContentToString(mail.file_path_html)); } catch (...) { - LOGE("Fail to open html body."); + LoggerE("Fail to open html body."); throw common::UnknownException("Fail to open html body."); } } diff --git a/src/messaging/message_email.cc b/src/messaging/message_email.cc index 955d7471..b95765bf 100644 --- a/src/messaging/message_email.cc +++ b/src/messaging/message_email.cc @@ -103,7 +103,7 @@ void MessageEmail::updateEmailMessage(email_mail_data_t& mail) setIsHighPriority((EMAIL_MAIL_PRIORITY_HIGH == mail.priority) ? true : false); if (mail.subject == NULL) { - LOGW("Subject is null"); + LoggerW("Subject is null"); } else { LoggerD("Subject: %s", mail.subject); setSubject(mail.subject); diff --git a/src/messaging/message_mms.cc b/src/messaging/message_mms.cc new file mode 100644 index 00000000..3c265546 --- /dev/null +++ b/src/messaging/message_mms.cc @@ -0,0 +1,88 @@ +// +// Tizen Web Device API +// Copyright (c) 2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file message_mm.cpp + */ +#include "message_mms.h" + +#include "common/platform_exception.h" +#include "common/logger.h" + +namespace extension { +namespace messaging { + +MessageMMS::MessageMMS(): + Message() +{ + LoggerD("MessageMMS constructor."); + this->m_type = MessageType(MessageType(MMS)); +} + +MessageMMS::~MessageMMS() +{ + LoggerD("MessageMMS destructor."); +} + +// *** overrided methods +void MessageMMS::setCC(std::vector &cc) +{ + // CC recipient's format validation should be done by email service + m_cc = cc; + + if(m_cc.empty()) { + LoggerD("Recipient's list cleared"); + return; + } +} + +void MessageMMS::setBCC(std::vector &bcc) +{ + // BCC recipient's format validation should be done by email service + m_bcc = bcc; + + if(m_bcc.empty()) { + LoggerD("Recipient's list cleared"); + return; + } +} + +void MessageMMS::setSubject(std::string subject) +{ + m_subject = subject; +} + +void MessageMMS::setMessageAttachments(AttachmentPtrVector &attachments) +{ + m_attachments = attachments; + + m_has_attachment = true; + if(m_attachments.empty()) { + LoggerD("Recipient's list cleared"); + m_has_attachment = false; + } +} + +bool MessageMMS::getHasAttachment() const +{ + LoggerD("MessageMMS::getHasAttachment()"); + // TODO: Analyze relation between hasAttachment flag and inlineAttachments + return m_has_attachment; +} + +} // messaging +} // extension diff --git a/src/messaging/message_mms.h b/src/messaging/message_mms.h new file mode 100644 index 00000000..cb486b75 --- /dev/null +++ b/src/messaging/message_mms.h @@ -0,0 +1,52 @@ +// +// Tizen Web Device API +// Copyright (c) 2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file MessageMMS.h + */ + +#ifndef __TIZEN_MESSAGE_MMS_H__ +#define __TIZEN_MESSAGE_MMS_H__ + +// Header with core msg-service declarations +#include + +#include "message.h" +#include "message_attachment.h" + +namespace extension { +namespace messaging { + +class MessageMMS: public Message { +public: +// constructor + MessageMMS(); + ~MessageMMS(); + +//overrided base class functions + void setCC(std::vector &cc); + void setBCC(std::vector &bcc); + void setSubject(std::string subject); + void setMessageAttachments(AttachmentPtrVector &attachments); + + bool getHasAttachment() const; +}; + +} // messaging +} // extension + +#endif // __TIZEN_MESSAGE_MMS_H__ diff --git a/src/messaging/message_service_email.cc b/src/messaging/message_service_email.cc index 93af8e0f..9566ade8 100644 --- a/src/messaging/message_service_email.cc +++ b/src/messaging/message_service_email.cc @@ -262,7 +262,7 @@ void MessageServiceEmail::stopSync(long op_id) long* data = new long(op_id); guint id = g_idle_add(stopSyncTask, static_cast(data)); if (!id) { - LOGE("g_idle_add failed"); + LoggerE("g_idle_add failed"); delete data; data = NULL; throw common::UnknownException("Could not add task"); diff --git a/src/messaging/message_sms.cc b/src/messaging/message_sms.cc index 234b5537..6e4e9fef 100644 --- a/src/messaging/message_sms.cc +++ b/src/messaging/message_sms.cc @@ -4,9 +4,6 @@ #include -#include "common/platform_exception.h" -#include "common/logger.h" - #include "message_sms.h" namespace extension { diff --git a/src/messaging/messaging.gyp b/src/messaging/messaging.gyp index d9b414c0..4b47560b 100644 --- a/src/messaging/messaging.gyp +++ b/src/messaging/messaging.gyp @@ -111,7 +111,9 @@ 'message_storage_short_msg.cc', 'message_storage_short_msg.h', 'short_message_manager.cc', - 'short_message_manager.h' + 'short_message_manager.h', + 'message_mms.cc', + 'message_mms.h' ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc index a08dc0dc..8c70b3d2 100644 --- a/src/messaging/messaging_util.cc +++ b/src/messaging/messaging_util.cc @@ -13,6 +13,7 @@ #include #include "message_email.h" #include "message_sms.h" +#include "message_mms.h" #include "message_conversation.h" #include "tizen/tizen.h" @@ -254,7 +255,7 @@ std::string MessagingUtil::loadFileContentToString(const std::string& file_path) } std::string MessagingUtil::messageStatusToString(MessageStatus status) { - LOGD("Converting MessageStatus %d to string.", (int)status); + LoggerD("Converting MessageStatus %d to string.", (int)status); switch(status) { case STATUS_SENT: return SENT; @@ -268,7 +269,7 @@ std::string MessagingUtil::messageStatusToString(MessageStatus status) { // According to Web API documentation: If the status of the current // message does not correspond to any item from the list, an empty // value is returned. - LOGD("Unsupported or undefined MessageStatus"); + LoggerD("Unsupported or undefined MessageStatus"); return ""; } } @@ -297,8 +298,6 @@ picojson::value MessagingUtil::messageToJson(std::shared_ptr message) case MessageType::SMS: break; case MessageType::MMS: - LoggerD("Currently unsupported"); - // TODO add class which will extended message_service and call message_service_short_msg o[MESSAGE_ATTRIBUTE_HAS_ATTACHMENT] = picojson::value(message->getHasAttachment()); o[MESSAGE_ATTRIBUTE_SUBJECT] = picojson::value(message->getSubject()); break; @@ -413,11 +412,14 @@ picojson::value MessagingUtil::conversationToJson(std::shared_ptrgetSubject()); + break; case MessageType::EMAIL: + o[MESSAGE_ATTRIBUTE_SUBJECT] = picojson::value(conversation->getSubject()); std::vector to = conversation->getTo(); for_each(to.begin(), to.end(), vectorToArray); - o[MESSAGE_ATTRIBUTE_IN_RESPONSE_TO] = picojson::value(array); + o[MESSAGE_ATTRIBUTE_TO] = picojson::value(array); array.clear(); std::vector cc = conversation->getCC(); @@ -430,7 +432,6 @@ picojson::value MessagingUtil::conversationToJson(std::shared_ptrgetSubject()); break; } @@ -472,18 +473,20 @@ std::shared_ptr MessagingUtil::jsonToMessage(const picojson::value& jso switch (mtype) { case MessageType::SMS: LoggerD("SMS type"); - if (!data.at(MESSAGE_ATTRIBUTE_ID).is()) { + if(data.at(MESSAGE_ATTRIBUTE_ID).is()) { + message = std::shared_ptr(new MessageSMS()); + break; + } + case MessageType::MMS: + LoggerD("MMS type"); + if(data.at(MESSAGE_ATTRIBUTE_ID).is()) { + message = std::shared_ptr(new MessageMMS()); + } else { std::string mid = data.at(MESSAGE_ATTRIBUTE_ID).get(); int message_id = std::atoi(mid.c_str()); message = Message::findShortMessageById(message_id); - } else { - message = std::shared_ptr(new MessageSMS()); } break; - case MessageType::MMS: - LoggerD("Currently unsupported"); - // TODO add class which will extended message_service and call message_service_short_msg - break; case MessageType::EMAIL: if (!data.at(MESSAGE_ATTRIBUTE_ID).is()) { std::string mid = data.at(MESSAGE_ATTRIBUTE_ID).get();