diff options
Diffstat (limited to 'src/messages.c')
-rwxr-xr-x[-rw-r--r--] | src/messages.c | 779 |
1 files changed, 519 insertions, 260 deletions
diff --git a/src/messages.c b/src/messages.c index 8fd9986..2b62a85 100644..100755 --- a/src/messages.c +++ b/src/messages.c @@ -11,7 +11,7 @@ * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ #include <sys/stat.h> @@ -22,7 +22,6 @@ #include <memory.h> #include <glib.h> - #include <dlog.h> #include <msg.h> #include <msg_transport.h> @@ -32,6 +31,8 @@ #include <messages_types.h> #include <messages_private.h> +#include <privacy_checker_client.h> + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -41,38 +42,27 @@ #define MAX_MESSAGES_TEXT_LEN 1530 /* Private Utility Functions */ -int _messages_error_converter(int err, const char *func, int line); int _messages_get_media_type_from_filepath(const char *filepath); int _messages_save_mms_data(messages_message_s *msg); int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle); int _messages_save_textfile(const char *text, char **filepath); int _messages_load_textfile(const char *filepath, char **text); void _messages_sent_mediator_cb(msg_handle_t handle, msg_struct_t pStatus, void *user_param); - -int _messages_convert_mbox_to_fw(messages_message_box_e mbox); -int _messages_convert_msgtype_to_fw(messages_message_type_e type); -int _messages_convert_recipient_to_fw(messages_recipient_type_e type); - - -#define ERROR_CONVERT(err) _messages_error_converter(err, __FUNCTION__, __LINE__); -#define CHECK_NULL(p) \ - if (NULL == p) { \ - LOGE("[%s] INVALID_PARAMETER(0x%08x) %s is null.", \ - __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER, #p); \ - return MESSAGES_ERROR_INVALID_PARAMETER; \ - } +int _messages_check_feature(char *feature_name); int messages_open_service(messages_service_h *svc) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; messages_service_s *_svc; CHECK_NULL(svc); _svc = (messages_service_s*)calloc(1, sizeof(messages_service_s)); - if (NULL == svc) + if (NULL == _svc) { - LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create a 'svc'." + LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create a '_svc'." , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); return MESSAGES_ERROR_OUT_OF_MEMORY; } @@ -80,39 +70,58 @@ int messages_open_service(messages_service_h *svc) _svc->sent_cb_list = NULL; _svc->incoming_cb = NULL; _svc->incoming_cb_enabled = false; + _svc->push_incoming_cb_list = NULL; ret = msg_open_msg_handle(&_svc->service_h); if (MSG_SUCCESS != ret) { free(_svc); return ERROR_CONVERT(ret); } - + ret = msg_reg_sent_status_callback(_svc->service_h, &_messages_sent_mediator_cb, (void*)_svc); if (MSG_SUCCESS != ret) { free(_svc); return ERROR_CONVERT(ret); - } + } *svc = (messages_service_h)_svc; return MESSAGES_ERROR_NONE; } +void _free_push_incoming_cb(messages_push_incoming_callback_s *cb) +{ + if (NULL != cb) { + if (NULL != cb->app_id) { + free(cb->app_id); + } + free(cb); + } +} + int messages_close_service(messages_service_h svc) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; - + messages_service_s *_svc = (messages_service_s *)svc; CHECK_NULL(_svc); ret = msg_close_msg_handle(&_svc->service_h); - - if (_svc->sent_cb_list) { + + if (_svc->sent_cb_list) { g_slist_foreach(_svc->sent_cb_list, (GFunc)g_free, NULL); g_slist_free(_svc->sent_cb_list); _svc->sent_cb_list = NULL; } + if (_svc->push_incoming_cb_list) { + g_slist_foreach(_svc->push_incoming_cb_list, (GFunc)_free_push_incoming_cb, NULL); + g_slist_free(_svc->push_incoming_cb_list); + _svc->push_incoming_cb_list = NULL; + } + free(svc); return ERROR_CONVERT(ret); @@ -120,6 +129,8 @@ int messages_close_service(messages_service_h svc) int messages_create_message(messages_message_type_e type, messages_message_h *msg) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; messages_message_s *_msg = NULL; @@ -132,7 +143,7 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); return MESSAGES_ERROR_OUT_OF_MEMORY; } - + _msg->msg_h = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); if (NULL == _msg->msg_h) { @@ -157,13 +168,20 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms } else if (MESSAGES_TYPE_MMS == type) { + ret = _messages_check_feature(MESSAGES_TELEPHONY_MMS_FEATURE); + if (MESSAGES_ERROR_NONE != ret) { + msg_release_struct(&_msg->msg_h); + free(_msg); + return ret; + } + ret = ERROR_CONVERT(msg_set_int_value(_msg->msg_h, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS)); if (MESSAGES_ERROR_NONE != ret) { msg_release_struct(&_msg->msg_h); free(_msg); return ret; - } + } } else { @@ -181,10 +199,12 @@ int messages_create_message(messages_message_type_e type, messages_message_h *ms int messages_destroy_message(messages_message_h msg) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; messages_message_s *_msg = (messages_message_s*)msg; - + CHECK_NULL(_msg); messages_mms_remove_all_attachments(msg); @@ -203,6 +223,8 @@ int messages_destroy_message(messages_message_h msg) int messages_get_message_type(messages_message_h msg, messages_message_type_e *type) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int msgType; int ret; @@ -219,10 +241,17 @@ int messages_get_message_type(messages_message_h msg, messages_message_type_e *t switch (msgType) { - case MSG_TYPE_SMS: case MSG_TYPE_SMS_CB: case MSG_TYPE_SMS_JAVACB: + *type = MESSAGES_TYPE_SMS_CB; + break; case MSG_TYPE_SMS_WAPPUSH: + *type = MESSAGES_TYPE_SMS_PUSH; + break; +// case MSG_TYPE_SMS_ETWS: +// *type = MESSAGES_TYPE_SMS_ETWS; +// break; + case MSG_TYPE_SMS: case MSG_TYPE_SMS_MWI: case MSG_TYPE_SMS_SYNCML: case MSG_TYPE_SMS_REJECT: @@ -243,32 +272,31 @@ int messages_get_message_type(messages_message_h msg, messages_message_type_e *t int messages_add_address(messages_message_h msg, const char *address, messages_recipient_type_e type) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; - int msgType; - msg_struct_list_s *addr_list = NULL; + messages_message_type_e msgType; msg_struct_t addr_info; - + messages_message_s *_msg = (messages_message_s*)msg; - + CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(address); - - msg_get_int_value(_msg->msg_h, MSG_MESSAGE_TYPE_INT, (int *)&msgType); - - ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list); + + messages_get_message_type(msg, &msgType); + + ret = msg_list_add_item(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_HND, &addr_info); if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - - addr_info = addr_list->msg_struct_info[addr_list->nCount]; - - if (MSG_TYPE_SMS == msgType) + + if (IS_SMS(msgType)) { msg_set_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_TO); } - else if (MSG_TYPE_MMS == msgType) + else if (IS_MMS(msgType)) { if (strchr(address, '@') == NULL) { @@ -291,40 +319,43 @@ int messages_add_address(messages_message_h msg, const char *address, messages_r if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - - addr_list->nCount++; return MESSAGES_ERROR_NONE; } int messages_get_address_count(messages_message_h msg, int *count) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; - msg_struct_list_s *addr_list = NULL; - + msg_list_handle_t addr_list = NULL; + messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(count); - - ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list); + + ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list); if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - *count = addr_list->nCount; + *count = msg_list_length(addr_list); return MESSAGES_ERROR_NONE; } int messages_get_address(messages_message_h msg, int index, char **address, messages_recipient_type_e *type) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; - char _address[MAX_ADDRESS_VAL_LEN] = {0, }; + char _address[MAX_ADDRESS_VAL_LEN+1] = {0, }; int _type; - - msg_struct_list_s *addr_list = NULL; + int count; + + msg_list_handle_t addr_list = NULL; msg_struct_t addr_info; messages_message_s *_msg = (messages_message_s*)msg; @@ -332,21 +363,22 @@ int messages_get_address(messages_message_h msg, int index, char **address, mess CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(address); - - ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list); + + ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list); if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - - if (index > addr_list->nCount) + + count = msg_list_length(addr_list); + if (index > count) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : index(%d) > addr_list->nCount(%d) " - , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER, index, addr_list->nCount); + , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER, index, count); return MESSAGES_ERROR_INVALID_PARAMETER; } - - addr_info = addr_list->msg_struct_info[index]; - + + addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index); + ret = msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, _address, MAX_ADDRESS_VAL_LEN); if (MSG_SUCCESS != ret) { @@ -364,7 +396,7 @@ int messages_get_address(messages_message_h msg, int index, char **address, mess } if (NULL != type) - { + { ret = msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &_type); if (MSG_SUCCESS != ret) { @@ -384,7 +416,7 @@ int messages_get_address(messages_message_h msg, int index, char **address, mess break; default: *type = MESSAGES_RECIPIENT_UNKNOWN; - break; + break; } } } @@ -394,19 +426,15 @@ int messages_get_address(messages_message_h msg, int index, char **address, mess int messages_remove_all_addresses(messages_message_h msg) { - int ret; - msg_struct_list_s *addr_list = NULL; + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); - ret = msg_get_list_handle(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list); - if (MSG_SUCCESS == ret) - { - addr_list->nCount = 0; - } + ret = msg_list_clear(_msg->msg_h, MSG_MESSAGE_ADDR_LIST_HND); return ERROR_CONVERT(ret); } @@ -419,6 +447,14 @@ void _dump_message(messages_message_h msg) int messages_send_message(messages_service_h svc, messages_message_h msg, bool save_to_sentbox, messages_sent_cb callback, void *user_data) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + + /* Privacy check */ + int privacy_ret = privacy_checker_check_by_privilege(MESSAGES_PRIVILEGE_WRITE); + if (privacy_ret == PRIV_MGR_ERROR_USER_NOT_CONSENTED) { + return MESSAGES_ERROR_PERMISSION_DENIED; + } + int ret; int reqId; msg_struct_t req; @@ -428,7 +464,7 @@ int messages_send_message(messages_service_h svc, messages_message_h msg, bool s messages_service_s *_svc = (messages_service_s*)svc; messages_message_s *_msg = (messages_message_s*)msg; - + messages_sent_callback_s *_cb; CHECK_NULL(_svc); @@ -439,23 +475,29 @@ int messages_send_message(messages_service_h svc, messages_message_h msg, bool s sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, true); msg_set_bool_value(sendOpt, MSG_SEND_OPT_DELIVER_REQ_BOOL, false); - msg_set_bool_value(sendOpt, MSG_SEND_OPT_KEEPCOPY_BOOL, save_to_sentbox); + msg_set_bool_value(sendOpt, MSG_SEND_OPT_KEEPCOPY_BOOL, save_to_sentbox); messages_get_message_type(msg, &msgType); - if (MESSAGES_TYPE_SMS == msgType) - { + if (IS_SMS(msgType)) + { req = msg_create_struct(MSG_STRUCT_REQUEST_INFO); msg_set_struct_handle(req, MSG_REQUEST_MESSAGE_HND, _msg->msg_h); - msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt); - + msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt); + ret = msg_sms_send_message(_svc->service_h, req); - + msg_get_int_value(req, MSG_REQUEST_REQUESTID_INT, &reqId); msg_release_struct(&req); } - else if (MESSAGES_TYPE_MMS == msgType) + else if (IS_MMS(msgType)) { + ret = _messages_check_feature(MESSAGES_TELEPHONY_MMS_FEATURE); + if (MESSAGES_ERROR_NONE != ret) { + msg_release_struct(&sendOpt); + return ret; + } + ret = _messages_save_mms_data(_msg); if (MESSAGES_ERROR_NONE == ret) { @@ -463,32 +505,33 @@ int messages_send_message(messages_service_h svc, messages_message_h msg, bool s { _dump_message(msg); } - + req = msg_create_struct(MSG_STRUCT_REQUEST_INFO); msg_set_struct_handle(req, MSG_REQUEST_MESSAGE_HND, _msg->msg_h); - msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt); - + msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt); + msg_get_struct_handle(sendOpt, MSG_SEND_OPT_MMS_OPT_HND, &option); msg_set_bool_value(option, MSG_MMS_SENDOPTION_READ_REQUEST_BOOL, false); msg_set_int_value(option, MSG_MMS_SENDOPTION_PRIORITY_INT, MSG_MESSAGE_PRIORITY_NORMAL); msg_set_int_value(option, MSG_MMS_SENDOPTION_EXPIRY_TIME_INT, MSG_EXPIRY_TIME_MAXIMUM); - msg_set_int_value(option, MSG_MMS_SENDOPTION_DELIVERY_TIME_INT, MSG_DELIVERY_TIME_IMMEDIATLY); - + msg_set_int_value(option, MSG_MMS_SENDOPTION_DELIVERY_TIME_INT, MSG_DELIVERY_TIME_IMMEDIATLY); + ret = msg_mms_send_message(_svc->service_h, req); - + msg_get_int_value(req, MSG_REQUEST_REQUESTID_INT, &reqId); msg_release_struct(&req); } } else { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : Invalid Message Type.", - __FUNCTION__, TIZEN_ERROR_INVALID_PARAMETER); - return TIZEN_ERROR_INVALID_PARAMETER; + LOGE("[%s] INVALID_PARAMETER(0x%08x) : Invalid Message Type.", + __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); + msg_release_struct(&sendOpt); + return MESSAGES_ERROR_INVALID_PARAMETER; } - + msg_release_struct(&sendOpt); - + if (NULL != callback && MSG_SUCCESS == ret) { // Add callback to mapping table @@ -504,26 +547,28 @@ int messages_send_message(messages_service_h svc, messages_message_h msg, bool s return ERROR_CONVERT(ret); } -int messages_get_message_count(messages_service_h service, +int messages_get_message_count(messages_service_h service, messages_message_box_e mbox, messages_message_type_e type, int *count) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; msg_folder_id_t folderId; msg_struct_t countInfo = NULL; int nSms, nMms; - + messages_service_s *_svc = (messages_service_s*)service; - + CHECK_NULL(_svc); CHECK_NULL(count); - + nSms = 0; nMms = 0; - + if (MESSAGES_MBOX_ALL == mbox) { - if (MESSAGES_TYPE_SMS == type || MESSAGES_TYPE_UNKNOWN == type) + if (IS_SMS(type) || MESSAGES_TYPE_UNKNOWN == type) { ret = ERROR_CONVERT(msg_count_msg_by_type(_svc->service_h, MSG_TYPE_SMS, &nSms)); if (MESSAGES_ERROR_NONE != ret) @@ -532,7 +577,7 @@ int messages_get_message_count(messages_service_h service, } } - if (MESSAGES_TYPE_MMS == type || MESSAGES_TYPE_UNKNOWN == type) + if (IS_MMS(type) || MESSAGES_TYPE_UNKNOWN == type) { ret = ERROR_CONVERT(msg_count_msg_by_type(_svc->service_h, MSG_TYPE_MMS, &nMms)); if (MESSAGES_ERROR_NONE != ret) @@ -546,13 +591,20 @@ int messages_get_message_count(messages_service_h service, else { countInfo = msg_create_struct(MSG_STRUCT_COUNT_INFO); + if (NULL == countInfo) { + LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create 'countInfo'." + , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); + return MESSAGES_ERROR_OUT_OF_MEMORY; + } + folderId = _messages_convert_mbox_to_fw(mbox); ret = ERROR_CONVERT(msg_count_message(_svc->service_h, folderId, countInfo)); if (MESSAGES_ERROR_NONE != ret) { + msg_release_struct(&countInfo); return ret; } - + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &nSms); msg_get_int_value(countInfo, MSG_COUNT_INFO_MMS_INT, &nMms); @@ -566,7 +618,7 @@ int messages_get_message_count(messages_service_h service, default: *count = 0; break; } } - + return MESSAGES_ERROR_NONE; } @@ -577,105 +629,123 @@ int messages_search_message(messages_service_h service, int offset, int limit, messages_message_h **message_array, int *length, int *total) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int i; int ret; msg_struct_list_s msg_list; - msg_struct_t searchCon; + msg_struct_t listCond; messages_message_type_e _msgType; - + messages_service_s *_svc = (messages_service_s*)service; messages_message_s *_msg = NULL; messages_message_h *_array; - + CHECK_NULL(_svc); CHECK_NULL(message_array); - + // Set Condition - searchCon = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION); - msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_FOLDERID_INT, _messages_convert_mbox_to_fw(mbox)); - msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_MSGTYPE_INT, _messages_convert_msgtype_to_fw(type)); + listCond = msg_create_struct(MSG_STRUCT_MSG_LIST_CONDITION); + if (NULL == listCond) { + LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create 'listCond'." + , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); + return MESSAGES_ERROR_OUT_OF_MEMORY; + } + + msg_set_int_value(listCond, MSG_LIST_CONDITION_FOLDER_ID_INT, _messages_convert_mbox_to_fw(mbox)); + msg_set_int_value(listCond, MSG_LIST_CONDITION_MSGTYPE_INT, _messages_convert_msgtype_to_fw(type)); + if (NULL != keyword) { - msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, strdup(keyword), sizeof(keyword)); + msg_set_str_value(listCond, MSG_LIST_CONDITION_TEXT_VALUE_STR, strdup(keyword), strlen(keyword)); } if (NULL != address) { - msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR, strdup(address), sizeof(address)); + msg_set_str_value(listCond, MSG_LIST_CONDITION_ADDRESS_VALUE_STR, strdup(address), strlen(address)); } // Search - ret = msg_search_message(_svc->service_h, searchCon, offset, limit, &msg_list); + msg_set_bool_value(listCond, MSG_LIST_CONDITION_AND_OPERATER_BOOL, true); + msg_set_int_value(listCond, MSG_LIST_CONDITION_OFFSET_INT, offset); + msg_set_int_value(listCond, MSG_LIST_CONDITION_LIMIT_INT, limit); + ret = msg_get_message_list2(_svc->service_h, listCond, &msg_list); + msg_release_struct(&listCond); if (MSG_SUCCESS != ret) { - msg_release_struct(&searchCon); + msg_release_list_struct(&msg_list); return ERROR_CONVERT(ret); } - msg_release_struct(&searchCon); // Result _array = (messages_message_h*)calloc(msg_list.nCount + 1, sizeof(messages_message_h)); if (NULL == _array) { + msg_release_list_struct(&msg_list); LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_array'." , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); return MESSAGES_ERROR_OUT_OF_MEMORY; } - + for (i=0; i < msg_list.nCount; i++) { _msg = (messages_message_s*)calloc(1, sizeof(messages_message_s)); - _msg->text = NULL; - _msg->attachment_list = NULL; if (NULL == _msg) { LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'." - , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); + , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); + for (; i > 0; i--) { + free(_array[i-1]); + } free(_array); + msg_release_list_struct(&msg_list); return MESSAGES_ERROR_OUT_OF_MEMORY; } + _msg->text = NULL; + _msg->attachment_list = NULL; _msg->msg_h = msg_list.msg_struct_info[i]; - + messages_get_message_type((messages_message_h)_msg, &_msgType); - if (MESSAGES_TYPE_MMS == _msgType) + if (IS_MMS(_msgType)) { // TODO: Well... performance issue. // Shoud I load mms data at here? _messages_load_mms_data(_msg, _svc->service_h); } - + _array[i] = (messages_message_h)_msg; } - + *message_array = (messages_message_h*)_array; - + if (NULL != length) { *length = msg_list.nCount; } - + if (NULL != total) { *total = -1; // TODO: total count is not supported yet. } - + // TODO: where should I free msg_list? - return MESSAGES_ERROR_NONE; } int messages_free_message_array(messages_message_h *message_array) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; int i=0; messages_message_h* _array = (messages_message_h*)message_array; CHECK_NULL(_array); - + while (_array[i] != NULL) { ret = messages_destroy_message(_array[i]); @@ -684,12 +754,12 @@ int messages_free_message_array(messages_message_h *message_array) LOGW("[%s:%d] messages_destroy_message() is fail. ret = %d" , __FUNCTION__, __LINE__, ret); } - + i++; } - + free(message_array); - + return MESSAGES_ERROR_NONE; } @@ -700,6 +770,14 @@ int messages_foreach_message(messages_service_h svc, int offset, int limit, messages_search_cb callback, void *user_data) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + + /* Privacy check */ + int privacy_ret = privacy_checker_check_by_privilege(MESSAGES_PRIVILEGE_READ); + if (privacy_ret == PRIV_MGR_ERROR_USER_NOT_CONSENTED) { + return MESSAGES_ERROR_PERMISSION_DENIED; + } + int i; int ret; bool ret_cb; @@ -707,25 +785,28 @@ int messages_foreach_message(messages_service_h svc, messages_message_h* msg_array; int length; int total; - + ret = messages_search_message(svc, mbox, type, keyword, address, offset, limit, &msg_array, &length, &total); if (MESSAGES_ERROR_NONE != ret) { - return ret; + return ret; } - + for (i=0; i < length; i++) { ret_cb = callback((messages_message_h)msg_array[i], i, length, total, user_data); + if (!ret_cb) { + break; + } } - + ret = messages_free_message_array(msg_array); if (MESSAGES_ERROR_NONE != ret) { - return ret; + return ret; } - + return MESSAGES_ERROR_NONE; } @@ -752,7 +833,7 @@ void _messages_sent_mediator_cb(msg_handle_t handle, msg_struct_t pStatus, void _cb = (messages_sent_callback_s *)g_slist_nth_data(_svc->sent_cb_list, i); if (NULL != _cb && _cb->req_id == reqId) { - ret = (status == MSG_NETWORK_SEND_SUCCESS) ? + ret = (status == MSG_NETWORK_SEND_SUCCESS) ? MESSAGES_SENDING_SUCCEEDED : MESSAGES_SENDING_FAILED; ((messages_sent_cb)_cb->callback)(ret, _cb->user_data); @@ -783,24 +864,32 @@ void _messages_incoming_mediator_cb(msg_handle_t handle, msg_struct_t msg, void , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); return; } - + _msg->msg_h = msg; messages_get_message_type((messages_message_h)_msg, &msgType); - if (MESSAGES_TYPE_MMS == msgType) + if (IS_MMS(msgType)) { + if (MESSAGES_ERROR_NONE != _messages_check_feature(MESSAGES_TELEPHONY_MMS_FEATURE)) { + free(_msg); + return; + } + _messages_load_mms_data(_msg, handle); } ((messages_incoming_cb)_svc->incoming_cb)((messages_message_h)_msg, _svc->incoming_cb_user_data); + messages_mms_remove_all_attachments((messages_message_h)_msg); free(_msg); } } int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_cb callback, void *user_data) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + int ret; messages_service_s *_svc = (messages_service_s*)svc; @@ -836,29 +925,33 @@ int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_c int messages_add_sms_listening_port(messages_service_h service, int port) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; messages_service_s *_svc = (messages_service_s*)service; CHECK_NULL(_svc); - + if (port <= 0) { return MESSAGES_ERROR_INVALID_PARAMETER; } - + ret = ERROR_CONVERT( msg_reg_sms_message_callback(_svc->service_h, &_messages_incoming_mediator_cb, port, (void*)_svc) ); - + if (MESSAGES_ERROR_NONE != ret) { return ret; } - + return MESSAGES_ERROR_NONE; } int messages_unset_message_incoming_cb(messages_service_h svc) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + messages_service_s *_svc = (messages_service_s*)svc; CHECK_NULL(_svc); @@ -870,27 +963,31 @@ int messages_unset_message_incoming_cb(messages_service_h svc) int messages_get_message_port(messages_message_h msg, int *port) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; int _port; - + messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(port); - + ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_DEST_PORT_INT, &_port); if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - + *port = _port; - + return MESSAGES_ERROR_NONE; } int messages_set_text(messages_message_h msg, const char *text) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; int len; messages_message_type_e type; @@ -905,10 +1002,10 @@ int messages_set_text(messages_message_h msg, const char *text) return ret; } - if (MESSAGES_TYPE_SMS == type) + if (IS_SMS(type)) { len = strlen(text); - if (len > MAX_MESSAGES_TEXT_LEN) + if (len > MAX_MESSAGES_TEXT_LEN) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : the length of body exceeded the max, 1530 ." , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); @@ -916,8 +1013,10 @@ int messages_set_text(messages_message_h msg, const char *text) } ret = ERROR_CONVERT(msg_set_str_value(_msg->msg_h, MSG_MESSAGE_SMS_DATA_STR, (char *)text, len)); } - else if (MESSAGES_TYPE_MMS == type) + else if (IS_MMS(type)) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + if (NULL != _msg->text) { free(_msg->text); @@ -937,7 +1036,7 @@ int messages_set_text(messages_message_h msg, const char *text) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : unknown message type" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); - return MESSAGES_ERROR_INVALID_PARAMETER; + return MESSAGES_ERROR_INVALID_PARAMETER; } return ret; @@ -945,8 +1044,10 @@ int messages_set_text(messages_message_h msg, const char *text) int messages_get_text(messages_message_h msg, char **text) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; - char _text[MAX_MSG_TEXT_LEN]; + char _text[MAX_MSG_TEXT_LEN+1] = {0,}; messages_message_type_e type; messages_message_s *_msg = (messages_message_s*)msg; @@ -959,7 +1060,7 @@ int messages_get_text(messages_message_h msg, char **text) return ret; } - if (MESSAGES_TYPE_SMS == type) + if (IS_SMS(type)) { ret = msg_get_str_value(_msg->msg_h, MSG_MESSAGE_SMS_DATA_STR, _text, MAX_MSG_TEXT_LEN); if (MSG_SUCCESS != ret) @@ -977,7 +1078,7 @@ int messages_get_text(messages_message_h msg, char **text) } } } - else if (MESSAGES_TYPE_MMS == type) + else if (IS_MMS(type)) { if (NULL == _msg->text) { @@ -994,7 +1095,7 @@ int messages_get_text(messages_message_h msg, char **text) } } } - else + else { LOGE("[%s] INVALID_PARAMETER(0x%08x) : unknown message type" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); @@ -1008,14 +1109,16 @@ int messages_get_text(messages_message_h msg, char **text) int messages_get_time(messages_message_h msg, time_t *time) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; int _time; - + messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(time); - + ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_DISPLAY_TIME_INT, &_time); if (MSG_SUCCESS != ret) { @@ -1029,27 +1132,76 @@ int messages_get_time(messages_message_h msg, time_t *time) int messages_get_message_id(messages_message_h msg, int *msg_id) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; int _id; - + messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(msg_id); - + ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_ID_INT, &_id); if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - + *msg_id = _id; - + + return MESSAGES_ERROR_NONE; +} + + +int messages_set_sim_id(messages_message_h msg, int sim_id) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + + int ret; + + messages_message_s *_msg = (messages_message_s*)msg; + CHECK_NULL(_msg); + CHECK_NULL(_msg->msg_h); + + ret = msg_set_int_value(_msg->msg_h, MSG_MESSAGE_SIM_INDEX_INT, sim_id); + if (MSG_SUCCESS != ret) + { + return ERROR_CONVERT(ret); + } + + return MESSAGES_ERROR_NONE; +} + + +int messages_get_sim_id(messages_message_h msg, int *sim_id) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + + int ret; + int _id; + + messages_message_s *_msg = (messages_message_s*)msg; + CHECK_NULL(_msg); + CHECK_NULL(_msg->msg_h); + CHECK_NULL(sim_id); + + ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_SIM_INDEX_INT, &_id); + if (MSG_SUCCESS != ret) + { + return ERROR_CONVERT(ret); + } + + *sim_id = _id; + return MESSAGES_ERROR_NONE; } + int messages_search_message_by_id(messages_service_h service, int msg_id, messages_message_h *msg) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; msg_struct_t new_msg_h; messages_message_type_e _msgType; @@ -1057,66 +1209,92 @@ int messages_search_message_by_id(messages_service_h service, int msg_id, messag messages_service_s *_svc = (messages_service_s*)service; messages_message_s *_msg = NULL; - + CHECK_NULL(_svc); CHECK_NULL(_svc->service_h); CHECK_NULL(msg); - + new_msg_h = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); + if (NULL == new_msg_h) { + LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create 'new_msg_h'." + , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); + return MESSAGES_ERROR_OUT_OF_MEMORY; + } + sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); + if (NULL == sendOpt) { + msg_release_struct(&new_msg_h); + LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create 'sendOpt'." + , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); + return MESSAGES_ERROR_OUT_OF_MEMORY; + } + ret = msg_get_message(_svc->service_h, msg_id, new_msg_h, sendOpt); if (MSG_SUCCESS != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_message failed.", - __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); - return MESSAGES_ERROR_OPERATION_FAILED; + msg_release_struct(&sendOpt); + msg_release_struct(&new_msg_h); + return ERROR_CONVERT(ret); } - + + msg_release_struct(&sendOpt); + _msg = (messages_message_s*)calloc(1, sizeof(messages_message_s)); - _msg->text = NULL; - _msg->attachment_list = NULL; if (NULL == _msg) { + msg_release_struct(&new_msg_h); LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'." , __FUNCTION__, __LINE__, MESSAGES_ERROR_OUT_OF_MEMORY); return MESSAGES_ERROR_OUT_OF_MEMORY; } - + + _msg->text = NULL; + _msg->attachment_list = NULL; _msg->msg_h = new_msg_h; - - messages_get_message_type((messages_message_h)_msg, &_msgType); - if (MESSAGES_TYPE_MMS == _msgType) + + messages_get_message_type((messages_message_h)_msg, &_msgType); + if (IS_MMS(_msgType)) { + ret = _messages_check_feature(MESSAGES_TELEPHONY_MMS_FEATURE); + if (MESSAGES_ERROR_NONE != ret) { + free(_msg); + msg_release_struct(&new_msg_h); + return ret; + } + ret = _messages_load_mms_data(_msg, _svc->service_h); if (MESSAGES_ERROR_NONE != ret) { free(_msg); + msg_release_struct(&new_msg_h); return ret; } } - + *msg = (messages_message_h)_msg; - + return MESSAGES_ERROR_NONE; } int messages_get_mbox_type(messages_message_h msg, messages_message_box_e *mbox) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + int ret; int folder_id; - + messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); CHECK_NULL(mbox); - + ret = msg_get_int_value(_msg->msg_h, MSG_MESSAGE_FOLDER_ID_INT, &folder_id); if (MSG_SUCCESS != ret) { return ERROR_CONVERT(ret); } - + switch (folder_id) { - case MSG_INBOX_ID: + case MSG_INBOX_ID: *mbox = MESSAGES_MBOX_INBOX; break; case MSG_OUTBOX_ID: @@ -1132,7 +1310,7 @@ int messages_get_mbox_type(messages_message_h msg, messages_message_box_e *mbox) *mbox = MESSAGES_MBOX_ALL; break; } - + return MESSAGES_ERROR_NONE; } @@ -1141,6 +1319,8 @@ int messages_get_mbox_type(messages_message_h msg, messages_message_box_e *mbox) int messages_mms_set_subject(messages_message_h msg, const char *subject) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + int ret; messages_message_type_e type; @@ -1154,13 +1334,13 @@ int messages_mms_set_subject(messages_message_h msg, const char *subject) return ret; } - if (MESSAGES_TYPE_MMS != type) + if (!IS_MMS(type)) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type should be MESSAGES_TYPE_MMS" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); - return MESSAGES_ERROR_INVALID_PARAMETER; + return MESSAGES_ERROR_INVALID_PARAMETER; } - + ret = msg_set_str_value(_msg->msg_h, MSG_MESSAGE_SUBJECT_STR, (char *)subject, strlen(subject)); return ERROR_CONVERT(ret); @@ -1168,8 +1348,10 @@ int messages_mms_set_subject(messages_message_h msg, const char *subject) int messages_mms_get_subject(messages_message_h msg, char **subject) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + int ret; - char _subject[MAX_SUBJECT_LEN]; + char _subject[MAX_SUBJECT_LEN+1] = {0,}; messages_message_type_e type; messages_message_s *_msg = (messages_message_s*)msg; @@ -1182,13 +1364,13 @@ int messages_mms_get_subject(messages_message_h msg, char **subject) return ret; } - if (MESSAGES_TYPE_MMS != type) + if (!IS_MMS(type)) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type should be MESSAGES_TYPE_MMS" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); - return MESSAGES_ERROR_INVALID_PARAMETER; + return MESSAGES_ERROR_INVALID_PARAMETER; } - + ret = msg_get_str_value(_msg->msg_h, MSG_MESSAGE_SUBJECT_STR, _subject, MAX_SUBJECT_LEN); if (MSG_SUCCESS != ret) { @@ -1211,10 +1393,13 @@ int messages_mms_get_subject(messages_message_h msg, char **subject) int messages_mms_add_attachment(messages_message_h msg, messages_media_type_e type, const char *path) { - messages_message_type_e msg_type; + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + + messages_message_type_e msg_type; messages_message_s *_msg = (messages_message_s*)msg; messages_attachment_s *attach; + int input_file_name_length; CHECK_NULL(_msg); CHECK_NULL(_msg->msg_h); @@ -1222,11 +1407,20 @@ int messages_mms_add_attachment(messages_message_h msg, messages_media_type_e ty // Check Message Type messages_get_message_type(msg, &msg_type); - if (MESSAGES_TYPE_MMS != msg_type) + if (!IS_MMS(msg_type)) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type should be MESSAGES_TYPE_MMS" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); - return MESSAGES_ERROR_INVALID_PARAMETER; + return MESSAGES_ERROR_INVALID_PARAMETER; + } + + //CID 350148: Putting a check so that input buffer does not exceed max_size which will cause seg fault. + //CID 358513: Also putting this check before calloc of var attach to prevent memory leak in case of error. + input_file_name_length = strlen(path); + if(input_file_name_length > MSG_FILEPATH_LEN_MAX) { + LOGE("[%s] INVALID_PARAMETER(0x%08x) : maximum length of file_name_path can be %d" + , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER, MSG_FILEPATH_LEN_MAX); + return MESSAGES_ERROR_INVALID_PARAMETER; } // New Attach @@ -1235,11 +1429,12 @@ int messages_mms_add_attachment(messages_message_h msg, messages_media_type_e ty { LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create a 'attach'." , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); - return MESSAGES_ERROR_OUT_OF_MEMORY; + return MESSAGES_ERROR_OUT_OF_MEMORY; } - attach->media_type = type; - strncpy(attach->filepath, path, strlen(path)); + attach->media_type = type; + + strncpy(attach->filepath, path, input_file_name_length); // Append _msg->attachment_list = g_slist_append(_msg->attachment_list, attach); @@ -1249,6 +1444,8 @@ int messages_mms_add_attachment(messages_message_h msg, messages_media_type_e ty int messages_mms_get_attachment_count(messages_message_h msg, int *count) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + messages_message_type_e type; messages_message_s *_msg = (messages_message_s*)msg; @@ -1259,11 +1456,11 @@ int messages_mms_get_attachment_count(messages_message_h msg, int *count) // Check Message Type messages_get_message_type(msg, &type); - if (MESSAGES_TYPE_MMS != type) + if (!IS_MMS(type)) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type should be MESSAGES_TYPE_MMS" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); - return MESSAGES_ERROR_INVALID_PARAMETER; + return MESSAGES_ERROR_INVALID_PARAMETER; } // Count @@ -1274,6 +1471,8 @@ int messages_mms_get_attachment_count(messages_message_h msg, int *count) int messages_mms_get_attachment(messages_message_h msg, int index, messages_media_type_e *type, char **path) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + messages_attachment_s *_attach; messages_message_type_e msg_type; @@ -1285,11 +1484,11 @@ int messages_mms_get_attachment(messages_message_h msg, int index, messages_medi // Check Message Type messages_get_message_type(msg, &msg_type); - if (MESSAGES_TYPE_MMS != msg_type) + if (!IS_MMS(msg_type)) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : the message type should be MESSAGES_TYPE_MMS" , __FUNCTION__, MESSAGES_ERROR_INVALID_PARAMETER); - return MESSAGES_ERROR_INVALID_PARAMETER; + return MESSAGES_ERROR_INVALID_PARAMETER; } _attach = (messages_attachment_s *)g_slist_nth_data(_msg->attachment_list, index); @@ -1315,6 +1514,8 @@ int messages_mms_get_attachment(messages_message_h msg, int index, messages_medi int messages_mms_remove_all_attachments(messages_message_h msg) { + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_MMS_FEATURE); + messages_message_s *_msg = (messages_message_s*)msg; CHECK_NULL(_msg); @@ -1337,7 +1538,7 @@ int _messages_save_mms_data(messages_message_s *msg) msg_struct_t mms_data; msg_struct_t region; - + msg_struct_t page; msg_struct_t media; msg_struct_t smil_text; @@ -1350,11 +1551,11 @@ int _messages_save_mms_data(messages_message_s *msg) char *filepath = NULL; CHECK_NULL(msg); - + mms_data = msg_create_struct(MSG_STRUCT_MMS); if (NULL == mms_data) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_create_message failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_create_message failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); return MESSAGES_ERROR_OPERATION_FAILED; } @@ -1397,35 +1598,35 @@ int _messages_save_mms_data(messages_message_s *msg) if (NULL == image) { - msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); + msg_list_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"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, 100); msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 100); - msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); } else if (NULL == msg->text) { - msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); + msg_list_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Image", 5); 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, 100); msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 100); - msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); } else { - msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); + msg_list_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Image", 5); 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, 100); msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 50); msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); - - msg_mms_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); + + msg_list_add_item(mms_data, MSG_STRUCT_MMS_REGION, ®ion); msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"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, 50); @@ -1435,33 +1636,33 @@ int _messages_save_mms_data(messages_message_s *msg) } // Add Media - msg_mms_add_item(mms_data, MSG_STRUCT_MMS_PAGE, &page); + msg_list_add_item(mms_data, MSG_STRUCT_MMS_PAGE, &page); msg_set_int_value(page, MSG_MMS_PAGE_PAGE_DURATION_INT, 5440); if (NULL != image) { if (MESSAGES_MEDIA_IMAGE == image->media_type) { - msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_list_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_IMG); msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5); - msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MAX_IMAGE_PATH_LEN); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MSG_FILEPATH_LEN_MAX); } else if (MESSAGES_MEDIA_VIDEO == image->media_type) { - msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_list_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_VIDEO); msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5); - msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MAX_IMAGE_PATH_LEN); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)image->filepath, MSG_FILEPATH_LEN_MAX); } } if (NULL != audio) { - msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_list_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_AUDIO); msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Audio", 5); - msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)audio->filepath, MAX_IMAGE_PATH_LEN); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)audio->filepath, MSG_FILEPATH_LEN_MAX); } if (NULL != msg->text) @@ -1469,11 +1670,11 @@ int _messages_save_mms_data(messages_message_s *msg) ret = _messages_save_textfile(msg->text, &filepath); if (MESSAGES_ERROR_NONE == ret) { - msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &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, (char *)"Text", 4); - msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)filepath, MAX_IMAGE_PATH_LEN); - + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, (char *)filepath, MSG_FILEPATH_LEN_MAX); + 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, 0x000000); msg_set_int_value(smil_text, MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL); @@ -1492,20 +1693,20 @@ int _messages_save_mms_data(messages_message_s *msg) attach = g_slist_nth_data(msg->attachment_list, i); if (image != attach && audio != attach) { - msg_mms_add_item(mms_data, MSG_STRUCT_MMS_ATTACH, &mms_attach); - msg_set_str_value(mms_attach, MSG_MMS_ATTACH_FILEPATH_STR, (char *)attach->filepath, MAX_IMAGE_PATH_LEN); + msg_list_add_item(mms_data, MSG_STRUCT_MMS_ATTACH, &mms_attach); + msg_set_str_value(mms_attach, MSG_MMS_ATTACH_FILEPATH_STR, (char *)attach->filepath, MSG_FILEPATH_LEN_MAX); } } - + ret = msg_set_mms_struct(msg->msg_h, mms_data); if (MSG_SUCCESS != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_set_mms_struct failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_set_mms_struct failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); msg_release_struct(&mms_data); return MESSAGES_ERROR_OPERATION_FAILED; } - + msg_release_struct(&mms_data); return MESSAGES_ERROR_NONE; @@ -1517,23 +1718,23 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) int ret; int msg_id; int media_type; - char filepath[MAX_IMAGE_PATH_LEN]; - + char filepath[MSG_FILEPATH_LEN_MAX + 1]; + msg_struct_t new_msg_h; msg_struct_t sendOpt; - + msg_struct_t mms_data; - + msg_list_handle_t mms_page_list; msg_list_handle_t mms_media_list; msg_list_handle_t mms_attach_list; - - + + msg_struct_t mms_page; msg_struct_t mms_media; msg_struct_t mms_attach; - - messages_attachment_s *attach; + + messages_attachment_s *attach = NULL; CHECK_NULL(msg); @@ -1541,26 +1742,38 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) ret = msg_get_int_value(msg->msg_h, MSG_MESSAGE_ID_INT, &msg_id); if (MSG_SUCCESS != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_int_value(MSG_MESSAGE_ID_INT) failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_int_value(MSG_MESSAGE_ID_INT) failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); - return MESSAGES_ERROR_OPERATION_FAILED; + return MESSAGES_ERROR_OPERATION_FAILED; } // Load MMS_MESSAGE_DATA_S new_msg_h = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); + if (new_msg_h == NULL) { + return MESSAGES_ERROR_OPERATION_FAILED; + } + sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); + if (sendOpt == NULL) { + msg_release_struct(&new_msg_h); + return MESSAGES_ERROR_OPERATION_FAILED; + } + ret = msg_get_message(handle, msg_id, new_msg_h, sendOpt); if (MSG_SUCCESS != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_message failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_get_message failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); - return MESSAGES_ERROR_OPERATION_FAILED; + msg_release_struct(&sendOpt); + msg_release_struct(&new_msg_h); + return MESSAGES_ERROR_OPERATION_FAILED; } + msg_release_struct(&sendOpt); mms_data = msg_create_struct(MSG_STRUCT_MMS); if (NULL == mms_data) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_create_message failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_create_message failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); msg_release_struct(&new_msg_h); return MESSAGES_ERROR_OPERATION_FAILED; @@ -1569,7 +1782,7 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) ret = msg_get_mms_struct(new_msg_h, mms_data); if (MSG_SUCCESS != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_get_message_body failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : msg_mms_get_message_body failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); msg_release_struct(&mms_data); msg_release_struct(&new_msg_h); @@ -1577,7 +1790,7 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) } // Load Media, Text - msg_get_list_handle(mms_data, MSG_MMS_PAGE_LIST_HND, (void **)&mms_page_list); + msg_get_list_handle(mms_data, MSG_MMS_PAGE_LIST_HND, (void **)&mms_page_list); for (i=0; i < msg_list_length(mms_page_list); i++) { mms_page = (msg_struct_t)msg_list_nth_data(mms_page_list, i); @@ -1585,34 +1798,34 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) { continue; } - - msg_get_list_handle(mms_page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&mms_media_list); + + msg_get_list_handle(mms_page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&mms_media_list); for (j=0; j < msg_list_length(mms_media_list); j++) { - mms_media = (msg_struct_t)msg_list_nth_data(mms_media_list, i); + mms_media = (msg_struct_t)msg_list_nth_data(mms_media_list, j); if (NULL == mms_media) { continue; } - attach = (messages_attachment_s *)calloc(1, sizeof(messages_attachment_s)); - if (NULL == attach) - { - LOGW("[%s] OUT_OF_MEMORY(0x%08x) fail to create a 'attach'." - , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); - break; - } - msg_get_int_value(mms_media, MSG_MMS_MEDIA_TYPE_INT, &media_type); - msg_get_str_value(mms_media, MSG_MMS_MEDIA_FILEPATH_STR, filepath, MAX_IMAGE_PATH_LEN); - + msg_get_str_value(mms_media, MSG_MMS_MEDIA_FILEPATH_STR, filepath, MSG_FILEPATH_LEN_MAX); + if (MMS_SMIL_MEDIA_TEXT == media_type) { _messages_load_textfile(filepath, &msg->text); } else { - strncpy(attach->filepath, filepath, MAX_IMAGE_PATH_LEN); + attach = (messages_attachment_s *)calloc(1, sizeof(messages_attachment_s)); + if (NULL == attach) + { + LOGW("[%s] OUT_OF_MEMORY(0x%08x) fail to create a 'attach'." + , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); + break; + } + + strncpy(attach->filepath, filepath, MSG_FILEPATH_LEN_MAX); switch (media_type) { case MMS_SMIL_MEDIA_IMG: @@ -1650,17 +1863,20 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); break; } - msg_get_str_value(mms_attach, MSG_MMS_ATTACH_FILEPATH_STR, filepath, MAX_IMAGE_PATH_LEN); - strncpy(attach->filepath, filepath, MAX_IMAGE_PATH_LEN); + msg_get_str_value(mms_attach, MSG_MMS_ATTACH_FILEPATH_STR, filepath, MSG_FILEPATH_LEN_MAX); + strncpy(attach->filepath, filepath, MSG_FILEPATH_LEN_MAX); attach->media_type = _messages_get_media_type_from_filepath(attach->filepath); + + msg->attachment_list = g_slist_append(msg->attachment_list, attach); } + msg_release_struct(&mms_data); msg_release_struct(&new_msg_h); - return MESSAGES_ERROR_NONE; } + int _messages_save_textfile(const char *text, char **filepath) { FILE* file = NULL; @@ -1685,7 +1901,7 @@ int _messages_save_textfile(const char *text, char **filepath) } else { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : opening file for text of message failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : opening file for text of message failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); return MESSAGES_ERROR_OPERATION_FAILED; } @@ -1707,24 +1923,38 @@ int _messages_load_textfile(const char *filepath, char **text) if (NULL == file) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : opening file for text of message failed.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : opening file for text of message failed.", __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); return MESSAGES_ERROR_OPERATION_FAILED; } - fstat(fileno(file), &st); + if (fstat(fileno(file), &st) < 0) { + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : opening file for text of message failed. (fstat)", + __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); + fclose(file); + return MESSAGES_ERROR_OPERATION_FAILED; + } + if (NULL == *text) { *text = (char*)calloc(1, st.st_size + 1); + if (*text == NULL) { + fclose(file); + return MESSAGES_ERROR_OPERATION_FAILED; + } pos = *text; } else { len = strlen(*text); + *text = (char*)realloc(*text, len + st.st_size + 2); + if (*text == NULL) { + fclose(file); + return MESSAGES_ERROR_OPERATION_FAILED; + } (*text)[len] = '\n'; - *text = (char*)realloc(*text, len + st.st_size + 1); - pos = *text + len; + pos = *text + len + 1; } while(0 < (nread = fread(buf, 1, 1024, file))) @@ -1734,6 +1964,8 @@ int _messages_load_textfile(const char *filepath, char **text) } pos[0] = '\0'; + fclose(file); + return 0; } @@ -1749,7 +1981,7 @@ int _messages_get_media_type_from_filepath(const char *filepath) } // check the length of filepath len = strlen(filepath); - if (len < 5) + if (len < 5) { return MESSAGES_MEDIA_UNKNOWN; } @@ -1757,7 +1989,7 @@ int _messages_get_media_type_from_filepath(const char *filepath) // check extension of file file_ext = (char *)&filepath[len - 4]; - if(strncmp(file_ext,".jpg",4) !=0 && strncmp(file_ext,".gif",4) !=0 + if(strncmp(file_ext,".jpg",4) !=0 && strncmp(file_ext,".gif",4) !=0 && strncmp(file_ext,".bmp",4) !=0 && strncmp(file_ext,".png",4) !=0) { ret = MESSAGES_MEDIA_IMAGE; @@ -1847,7 +2079,7 @@ int _messages_error_converter(int err, const char *func, int line) switch(err) { case MSG_ERR_NULL_POINTER: - LOGE("[%s:%d] NULL_POINTER(0x%08x) : Error from internal Messaging F/W ret: %d.", + LOGE("[%s:%d] NULL_POINTER(0x%08x) : Error from internal Messaging F/W ret: %d.", func, line, MESSAGES_ERROR_INVALID_PARAMETER, err); return MESSAGES_ERROR_INVALID_PARAMETER; @@ -1857,32 +2089,59 @@ int _messages_error_converter(int err, const char *func, int line) return MESSAGES_ERROR_INVALID_PARAMETER; case -EINVAL: - LOGE("[%s:%d] EINVAL(0x%08x) : Error from internal Messaging F/W ret: %d.", + LOGE("[%s:%d] EINVAL(0x%08x) : Error from internal Messaging F/W ret: %d.", func, line, MESSAGES_ERROR_INVALID_PARAMETER, err); return MESSAGES_ERROR_INVALID_PARAMETER; case MSG_ERR_SERVER_NOT_READY: - LOGE("[%s:%d] SERVER_NOT_READY(0x%08x) : Error from internal Messaging F/W ret: %d.", + LOGE("[%s:%d] SERVER_NOT_READY(0x%08x) : Error from internal Messaging F/W ret: %d.", func, line, MESSAGES_ERROR_SERVER_NOT_READY, err); return MESSAGES_ERROR_SERVER_NOT_READY; case MSG_ERR_COMMUNICATION_ERROR: - LOGE("[%s:%d] OMMUNICATION_ERROR(0x%08x) : Error from internal Messaging F/W ret: %d.", + LOGE("[%s:%d] COMMUNICATION_ERROR(0x%08x) : Error from internal Messaging F/W ret: %d.", func, line, MESSAGES_ERROR_COMMUNICATION_WITH_SERVER_FAILED, err); return MESSAGES_ERROR_COMMUNICATION_WITH_SERVER_FAILED; case MSG_ERR_TRANSPORT_ERROR: - LOGE("[%s:%d] TRANSPORT_ERROR(0x%08x) : Error from internal Messaging F/W ret: %d.", + LOGE("[%s:%d] TRANSPORT_ERROR(0x%08x) : Error from internal Messaging F/W ret: %d.", func, line, MESSAGES_ERROR_SENDING_FAILED, err); return MESSAGES_ERROR_SENDING_FAILED; + case MSG_ERR_NO_SIM: + LOGE("[%s:%d] NO_SIM_CARD(0x%08x) : Error from internal Messaging F/W ret: %d.", + func, line, MESSAGES_ERROR_NO_SIM_CARD, err); + return MESSAGES_ERROR_NO_SIM_CARD; + + case MSG_ERR_DB_STEP: + LOGE("[%s:%d] NO_DATA(0x%08x) : Error from internal Messaging F/W ret: %d.", + func, line, MESSAGES_ERROR_NO_DATA, err); + return MESSAGES_ERROR_NO_DATA; + + case MSG_ERR_PERMISSION_DENIED: + return MESSAGES_ERROR_PERMISSION_DENIED; + case MSG_SUCCESS: return MESSAGES_ERROR_NONE; default: - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : Error from internal Messaging F/W ret: %d.", + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : Error from internal Messaging F/W ret: %d.", func, line, MESSAGES_ERROR_OPERATION_FAILED, err); return MESSAGES_ERROR_OPERATION_FAILED; } } + +int _messages_check_feature(char *feature_name) { + bool is_supported = false; + if (!system_info_get_platform_bool(feature_name, &is_supported)) { + if (!is_supported) { + LOGE("[%s] feature is disabled", feature_name); + return MESSAGES_ERROR_NOT_SUPPORTED; + } + } else { + LOGE("Error - Feature getting from System Info"); + return MESSAGES_ERROR_OPERATION_FAILED; + } + return MESSAGES_ERROR_NONE; +} |