From 9244ee23fad71b6c48fc5c9387a1cdf84d350488 Mon Sep 17 00:00:00 2001 From: "seunggi.hong" Date: Fri, 3 Jul 2015 10:16:30 +0900 Subject: [PATCH] 3.0 Migration Change-Id: I720304894e0c0c55ab1c27ec250a4853c05f40da --- doc/messages_doc.h | 3 + include/messages_private.h | 10 +- include/messages_types.h | 8 - packaging/capi-messaging-messages.spec | 2 +- src/messages.c | 144 ++++--- src/messages_push.c | 503 ++++++++++++------------- test/messages_incoming_test.c | 39 +- test/messages_search_test.c | 37 +- test/messages_send_mms_test.c | 11 +- test/messages_send_sms_test.c | 7 +- 10 files changed, 409 insertions(+), 355 deletions(-) diff --git a/doc/messages_doc.h b/doc/messages_doc.h index e0f999a..229a018 100755 --- a/doc/messages_doc.h +++ b/doc/messages_doc.h @@ -43,6 +43,7 @@ * @section CAPI_MESSAGING_MESSAGES_MODULE_FEATURE Related Features * This API is related with the following features:\n * - http://tizen.org/feature/network.telephony\n + * - http://tizen.org/feature/network.telephony.sms\n * - http://tizen.org/feature/network.telephony.mms\n * * It is recommended to design feature related codes in your application for reliability.\n @@ -77,6 +78,7 @@ * @section CAPI_MESSAGING_MESSAGES_MMS_MODULE_FEATURE Related Features * This API is related with the following features:\n * - http://tizen.org/feature/network.telephony\n + * - http://tizen.org/feature/network.telephony.sms\n * - http://tizen.org/feature/network.telephony.mms\n * * It is recommended to design feature related codes in your application for reliability.\n @@ -109,6 +111,7 @@ * @section CAPI_MESSAGING_MESSAGES_PUSH_MODULE_FEATURE Related Features * This API is related with the following features:\n * - http://tizen.org/feature/network.telephony\n + * - http://tizen.org/feature/network.telephony.sms\n * * It is recommended to design feature related codes in your application for reliability.\n * diff --git a/include/messages_private.h b/include/messages_private.h index 53ac983..58953b8 100644 --- a/include/messages_private.h +++ b/include/messages_private.h @@ -17,6 +17,14 @@ #ifndef __TIZEN_MESSAGING_PRIVATE_H__ #define __TIZEN_MESSAGING_PRIVATE_H__ +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_MESSAGING" +#define DBG_MODE (1) + #ifdef __cplusplus extern "C" { @@ -59,7 +67,7 @@ typedef struct _messages_push_incoming_callback_s { #define MESSAGES_PRIVILEGE_READ "http://tizen.org/privilege/message.read" #define MESSAGES_PRIVILEGE_WRITE "http://tizen.org/privilege/message.write" -#define MESSAGES_TELEPHONY_FEATURE "http://tizen.org/feature/network.telephony" +#define MESSAGES_TELEPHONY_SMS_FEATURE "http://tizen.org/feature/network.telephony.sms" #define MESSAGES_TELEPHONY_MMS_FEATURE "http://tizen.org/feature/network.telephony.mms" #define ERROR_CONVERT(err) _messages_error_converter(err, __FUNCTION__, __LINE__); diff --git a/include/messages_types.h b/include/messages_types.h index 09a9c8a..4643298 100644 --- a/include/messages_types.h +++ b/include/messages_types.h @@ -19,14 +19,6 @@ #include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_MESSAGING" -#define DBG_MODE (1) - #ifdef __cplusplus extern "C" { diff --git a/packaging/capi-messaging-messages.spec b/packaging/capi-messaging-messages.spec index 05611fe..edc1417 100644 --- a/packaging/capi-messaging-messages.spec +++ b/packaging/capi-messaging-messages.spec @@ -5,7 +5,7 @@ Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -%if "%{?tizen_profile_name}" == "wearable" +%if "%{?profile}" == "tv" ExcludeArch: %{arm} %ix86 x86_64 %endif diff --git a/src/messages.c b/src/messages.c index 7e392d2..4d3f9ac 100644 --- a/src/messages.c +++ b/src/messages.c @@ -45,7 +45,7 @@ int _messages_check_feature(char *feature_name); int messages_open_service(messages_service_h *svc) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; messages_service_s *_svc; @@ -53,9 +53,9 @@ int messages_open_service(messages_service_h *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; } @@ -94,7 +94,7 @@ void _free_push_incoming_cb(messages_push_incoming_callback_s *cb) int messages_close_service(messages_service_h svc) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; @@ -122,7 +122,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; messages_message_s *_msg = NULL; @@ -192,7 +192,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; @@ -216,7 +216,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int msgType; int ret; @@ -265,7 +265,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; @@ -318,7 +318,7 @@ int messages_add_address(messages_message_h msg, const char *address, messages_r int messages_get_address_count(messages_message_h msg, int *count) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; msg_list_handle_t addr_list = NULL; @@ -341,10 +341,10 @@ int messages_get_address_count(messages_message_h msg, int *count) int messages_get_address(messages_message_h msg, int index, char **address, messages_recipient_type_e *type) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; - char _address[MAX_ADDRESS_VAL_LEN] = {0, }; + char _address[MAX_ADDRESS_VAL_LEN+1] = {0, }; int _type; int count; @@ -419,7 +419,7 @@ int messages_get_address(messages_message_h msg, int index, char **address, mess int messages_remove_all_addresses(messages_message_h msg) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; messages_message_s *_msg = (messages_message_s*)msg; @@ -440,7 +440,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); /* Privacy check */ int privacy_ret = privacy_checker_check_by_privilege(MESSAGES_PRIVILEGE_WRITE); @@ -544,7 +544,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; msg_folder_id_t folderId; @@ -584,6 +584,12 @@ 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) @@ -616,7 +622,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int i; int ret; @@ -635,6 +641,11 @@ int messages_search_message(messages_service_h service, // Set Condition 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)); @@ -653,17 +664,18 @@ int messages_search_message(messages_service_h service, 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(&listCond); + msg_release_list_struct(&msg_list); return ERROR_CONVERT(ret); } - msg_release_struct(&listCond); // 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; @@ -676,7 +688,11 @@ int messages_search_message(messages_service_h service, { LOGE("[%s:%d] OUT_OF_MEMORY(0x%08x) fail to create '_msg'." , __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; } @@ -715,7 +731,7 @@ int messages_search_message(messages_service_h service, int messages_free_message_array(messages_message_h *message_array) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int i=0; @@ -747,7 +763,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); /* Privacy check */ int privacy_ret = privacy_checker_check_by_privilege(MESSAGES_PRIVILEGE_READ); @@ -865,7 +881,7 @@ void _messages_incoming_mediator_cb(msg_handle_t handle, msg_struct_t msg, void int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_cb callback, void *user_data) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; @@ -884,12 +900,14 @@ int messages_set_message_incoming_cb(messages_service_h svc, messages_incoming_c return ret; } - ret = ERROR_CONVERT( - msg_reg_mms_conf_message_callback(_svc->service_h, &_messages_incoming_mediator_cb, NULL, (void*)_svc) - ); - if (MESSAGES_ERROR_NONE != ret) - { - return ret; + if (MESSAGES_ERROR_NONE == _messages_check_feature(MESSAGES_TELEPHONY_MMS_FEATURE)) { + ret = ERROR_CONVERT( + msg_reg_mms_conf_message_callback(_svc->service_h, &_messages_incoming_mediator_cb, NULL, (void*)_svc) + ); + if (MESSAGES_ERROR_NONE != ret) + { + return ret; + } } } @@ -902,7 +920,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; messages_service_s *_svc = (messages_service_s*)service; @@ -927,7 +945,7 @@ int messages_add_sms_listening_port(messages_service_h service, int port) int messages_unset_message_incoming_cb(messages_service_h svc) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); messages_service_s *_svc = (messages_service_s*)svc; @@ -942,7 +960,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int _port; @@ -965,7 +983,7 @@ int messages_get_message_port(messages_message_h msg, int *port) int messages_set_text(messages_message_h msg, const char *text) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int len; @@ -1023,10 +1041,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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_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; @@ -1088,7 +1106,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int _time; @@ -1111,7 +1129,7 @@ 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); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int _id; @@ -1135,7 +1153,7 @@ int messages_get_message_id(messages_message_h msg, int *msg_id) int messages_set_sim_id(messages_message_h msg, int sim_id) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; @@ -1155,7 +1173,7 @@ int messages_set_sim_id(messages_message_h msg, int sim_id) int messages_get_sim_id(messages_message_h msg, int *sim_id) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int _id; @@ -1179,7 +1197,7 @@ int messages_get_sim_id(messages_message_h msg, int *sim_id) int messages_search_message_by_id(messages_service_h service, int msg_id, messages_message_h *msg) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; msg_struct_t new_msg_h; @@ -1194,7 +1212,20 @@ int messages_search_message_by_id(messages_service_h service, int msg_id, messag 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) { @@ -1243,7 +1274,7 @@ int messages_search_message_by_id(messages_service_h service, int msg_id, messag int messages_get_mbox_type(messages_message_h msg, messages_message_box_e *mbox) { - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); int ret; int folder_id; @@ -1317,7 +1348,7 @@ 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; @@ -1701,7 +1732,7 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) msg_struct_t mms_media; msg_struct_t mms_attach; - messages_attachment_s *attach; + messages_attachment_s *attach = NULL; CHECK_NULL(msg); @@ -1716,7 +1747,16 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) // 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) { @@ -1766,14 +1806,6 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) 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, MSG_FILEPATH_LEN_MAX); @@ -1783,6 +1815,14 @@ int _messages_load_mms_data(messages_message_s *msg, msg_handle_t handle) } else { + 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) { @@ -1897,12 +1937,20 @@ int _messages_load_textfile(const char *filepath, char **text) 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'; pos = *text + len + 1; } diff --git a/src/messages_push.c b/src/messages_push.c index fce67f6..37b8bbc 100644 --- a/src/messages_push.c +++ b/src/messages_push.c @@ -1,253 +1,250 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_MESSAGING" - - -void _messages_push_incoming_mediator_cb(msg_handle_t handle, const char *push_header, const char *push_body, int push_body_len, void *user_param) -{ - messages_push_incoming_callback_s *_cb = (messages_push_incoming_callback_s *)user_param; - - if (_cb && _cb->callback) - { - ((messages_push_incoming_cb)_cb->callback)(push_header, push_body, push_body_len, _cb->user_data); - } -} - - - -int messages_push_add_incoming_cb(messages_service_h service, const char *app_id, - messages_push_incoming_cb callback, void *user_data) -{ - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); - - int ret; - messages_push_incoming_callback_s *_cb; - - messages_service_s *_svc = (messages_service_s *)service; - - CHECK_NULL(_svc); - CHECK_NULL(_svc->service_h); - CHECK_NULL(app_id); - CHECK_NULL(callback); - - _cb = (messages_push_incoming_callback_s *)malloc(sizeof(messages_push_incoming_callback_s)); - if (NULL == _cb) - { - LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create a '_cb'." - , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); - return MESSAGES_ERROR_OUT_OF_MEMORY; - } - - _cb->app_id = strdup(app_id); - _cb->callback = callback; - _cb->user_data = user_data; - - ret = msg_reg_push_message_callback(_svc->service_h, _messages_push_incoming_mediator_cb, app_id, (void*)_cb); - if (MSG_SUCCESS != ret) - { - if (_cb->app_id) { - free(_cb->app_id); - } - free(_cb); - return ERROR_CONVERT(ret); - } - - _svc->push_incoming_cb_list = g_slist_append(_svc->push_incoming_cb_list, _cb); - - return MESSAGES_ERROR_NONE; -} - -int messages_push_remove_incoming_cb(messages_service_h service, const char *app_id) -{ - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); - - int i; - messages_push_incoming_callback_s *_cb; - - messages_service_s *_svc = (messages_service_s *)service; - - CHECK_NULL(_svc); - CHECK_NULL(_svc->service_h); - CHECK_NULL(app_id); - - for (i=0; i < g_slist_length(_svc->push_incoming_cb_list); i++) - { - _cb = (messages_push_incoming_callback_s *)g_slist_nth_data(_svc->push_incoming_cb_list, i); - if (NULL != _cb && NULL != _cb->app_id) - { - if (!strcmp(_cb->app_id, app_id)) { - _cb->callback = NULL; - } - } - } - - return MESSAGES_ERROR_NONE; -} - - -int messages_push_register(messages_service_h service, const char *content_type, const char *app_id) -{ - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); - - int ret; - - msg_struct_t push_info; - char *pkg_name; - - messages_service_s *_svc = (messages_service_s *)service; - - CHECK_NULL(_svc); - CHECK_NULL(_svc->service_h); - CHECK_NULL(content_type); - CHECK_NULL(app_id); - - ret = app_get_id(&pkg_name); - if (APP_ERROR_NONE != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : app_get_id failed.", - __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); - return MESSAGES_ERROR_OPERATION_FAILED; - } - - push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)app_id, MAX_WAPPUSH_ID_LEN); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); - free(pkg_name); - - ret = msg_add_push_event(_svc->service_h, push_info); - msg_release_struct(&push_info); - if (MSG_SUCCESS != ret) - { - return ERROR_CONVERT(ret); - } - - return MESSAGES_ERROR_NONE; -} - -int messages_push_deregister(messages_service_h service, const char *content_type, const char *app_id) -{ - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); - - int ret; - - msg_struct_t push_info; - char *pkg_name; - - messages_service_s *_svc = (messages_service_s *)service; - - CHECK_NULL(_svc); - CHECK_NULL(_svc->service_h); - CHECK_NULL(content_type); - CHECK_NULL(app_id); - - ret = app_get_id(&pkg_name); - if (APP_ERROR_NONE != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : app_get_id failed.", - __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); - return MESSAGES_ERROR_OPERATION_FAILED; - } - - push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)app_id, MAX_WAPPUSH_ID_LEN); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); - free(pkg_name); - - ret = msg_delete_push_event(_svc->service_h, push_info); - msg_release_struct(&push_info); - if (MSG_SUCCESS != ret) - { - return ERROR_CONVERT(ret); - } - - return MESSAGES_ERROR_NONE; -} - -int messages_push_reregister(messages_service_h service, const char *content_type, const char *app_id, - const char *dst_content_type, const char *dst_app_id) -{ - CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_FEATURE); - - int ret; - - msg_struct_t push_info; - msg_struct_t dst_push_info; - char *pkg_name; - - messages_service_s *_svc = (messages_service_s *)service; - - CHECK_NULL(_svc); - CHECK_NULL(_svc->service_h); - CHECK_NULL(content_type); - CHECK_NULL(app_id); - CHECK_NULL(dst_content_type); - CHECK_NULL(dst_app_id); - - ret = app_get_id(&pkg_name); - if (APP_ERROR_NONE != ret) { - LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : app_get_id failed.", - __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); - return MESSAGES_ERROR_OPERATION_FAILED; - } - - push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)app_id, MAX_WAPPUSH_ID_LEN); - msg_set_str_value(push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); - - dst_push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); - msg_set_str_value(dst_push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)dst_content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); - msg_set_str_value(dst_push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)dst_app_id, MAX_WAPPUSH_ID_LEN); - msg_set_str_value(dst_push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); - free(pkg_name); - - ret = msg_update_push_event(_svc->service_h, push_info, dst_push_info); - msg_release_struct(&push_info); - msg_release_struct(&dst_push_info); - if (MSG_SUCCESS != ret) - { - return ERROR_CONVERT(ret); - } - - return MESSAGES_ERROR_NONE; -} - - - +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_MESSAGING" + + +void _messages_push_incoming_mediator_cb(msg_handle_t handle, const char *push_header, const char *push_body, int push_body_len, void *user_param) +{ + messages_push_incoming_callback_s *_cb = (messages_push_incoming_callback_s *)user_param; + + if (_cb && _cb->callback) + { + ((messages_push_incoming_cb)_cb->callback)(push_header, push_body, push_body_len, _cb->user_data); + } +} + + + +int messages_push_add_incoming_cb(messages_service_h service, const char *app_id, + messages_push_incoming_cb callback, void *user_data) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); + + int ret; + messages_push_incoming_callback_s *_cb; + + messages_service_s *_svc = (messages_service_s *)service; + + CHECK_NULL(_svc); + CHECK_NULL(_svc->service_h); + CHECK_NULL(app_id); + CHECK_NULL(callback); + + _cb = (messages_push_incoming_callback_s *)malloc(sizeof(messages_push_incoming_callback_s)); + if (NULL == _cb) + { + LOGE("[%s] OUT_OF_MEMORY(0x%08x) fail to create a '_cb'." + , __FUNCTION__, MESSAGES_ERROR_OUT_OF_MEMORY); + return MESSAGES_ERROR_OUT_OF_MEMORY; + } + + _cb->app_id = strdup(app_id); + _cb->callback = callback; + _cb->user_data = user_data; + + ret = msg_reg_push_message_callback(_svc->service_h, _messages_push_incoming_mediator_cb, app_id, (void*)_cb); + if (MSG_SUCCESS != ret) + { + if (_cb->app_id) { + free(_cb->app_id); + } + free(_cb); + return ERROR_CONVERT(ret); + } + + _svc->push_incoming_cb_list = g_slist_append(_svc->push_incoming_cb_list, _cb); + + return MESSAGES_ERROR_NONE; +} + +int messages_push_remove_incoming_cb(messages_service_h service, const char *app_id) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); + + int i; + messages_push_incoming_callback_s *_cb; + + messages_service_s *_svc = (messages_service_s *)service; + + CHECK_NULL(_svc); + CHECK_NULL(_svc->service_h); + CHECK_NULL(app_id); + + for (i=0; i < g_slist_length(_svc->push_incoming_cb_list); i++) + { + _cb = (messages_push_incoming_callback_s *)g_slist_nth_data(_svc->push_incoming_cb_list, i); + if (NULL != _cb && NULL != _cb->app_id) + { + if (!strcmp(_cb->app_id, app_id)) { + _cb->callback = NULL; + } + } + } + + return MESSAGES_ERROR_NONE; +} + + +int messages_push_register(messages_service_h service, const char *content_type, const char *app_id) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); + + int ret; + + msg_struct_t push_info; + char *pkg_name; + + messages_service_s *_svc = (messages_service_s *)service; + + CHECK_NULL(_svc); + CHECK_NULL(_svc->service_h); + CHECK_NULL(content_type); + CHECK_NULL(app_id); + + ret = app_get_id(&pkg_name); + if (APP_ERROR_NONE != ret) { + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : app_get_id failed.", + __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); + return MESSAGES_ERROR_OPERATION_FAILED; + } + + push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)app_id, MAX_WAPPUSH_ID_LEN); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); + free(pkg_name); + + ret = msg_add_push_event(_svc->service_h, push_info); + msg_release_struct(&push_info); + if (MSG_SUCCESS != ret) + { + return ERROR_CONVERT(ret); + } + + return MESSAGES_ERROR_NONE; +} + +int messages_push_deregister(messages_service_h service, const char *content_type, const char *app_id) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); + + int ret; + + msg_struct_t push_info; + char *pkg_name; + + messages_service_s *_svc = (messages_service_s *)service; + + CHECK_NULL(_svc); + CHECK_NULL(_svc->service_h); + CHECK_NULL(content_type); + CHECK_NULL(app_id); + + ret = app_get_id(&pkg_name); + if (APP_ERROR_NONE != ret) { + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : app_get_id failed.", + __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); + return MESSAGES_ERROR_OPERATION_FAILED; + } + + push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)app_id, MAX_WAPPUSH_ID_LEN); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); + free(pkg_name); + + ret = msg_delete_push_event(_svc->service_h, push_info); + msg_release_struct(&push_info); + if (MSG_SUCCESS != ret) + { + return ERROR_CONVERT(ret); + } + + return MESSAGES_ERROR_NONE; +} + +int messages_push_reregister(messages_service_h service, const char *content_type, const char *app_id, + const char *dst_content_type, const char *dst_app_id) +{ + CHECK_MESSAGES_SUPPORTED(MESSAGES_TELEPHONY_SMS_FEATURE); + + int ret; + + msg_struct_t push_info; + msg_struct_t dst_push_info; + char *pkg_name; + + messages_service_s *_svc = (messages_service_s *)service; + + CHECK_NULL(_svc); + CHECK_NULL(_svc->service_h); + CHECK_NULL(content_type); + CHECK_NULL(app_id); + CHECK_NULL(dst_content_type); + CHECK_NULL(dst_app_id); + + ret = app_get_id(&pkg_name); + if (APP_ERROR_NONE != ret) { + LOGE("[%s:%d] OPERATION_FAILED(0x%08x) : app_get_id failed.", + __FUNCTION__, __LINE__, MESSAGES_ERROR_OPERATION_FAILED); + return MESSAGES_ERROR_OPERATION_FAILED; + } + + push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)app_id, MAX_WAPPUSH_ID_LEN); + msg_set_str_value(push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); + + dst_push_info = msg_create_struct(MSG_STRUCT_PUSH_CONFIG_INFO); + msg_set_str_value(dst_push_info, MSG_PUSH_CONFIG_CONTENT_TYPE_STR, (char *)dst_content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN); + msg_set_str_value(dst_push_info, MSG_PUSH_CONFIG_APPLICATON_ID_STR, (char *)dst_app_id, MAX_WAPPUSH_ID_LEN); + msg_set_str_value(dst_push_info, MSG_PUSH_CONFIG_PACKAGE_NAME_STR, pkg_name, MSG_FILEPATH_LEN_MAX); + free(pkg_name); + + ret = msg_update_push_event(_svc->service_h, push_info, dst_push_info); + msg_release_struct(&push_info); + msg_release_struct(&dst_push_info); + if (MSG_SUCCESS != ret) + { + return ERROR_CONVERT(ret); + } + + return MESSAGES_ERROR_NONE; +} diff --git a/test/messages_incoming_test.c b/test/messages_incoming_test.c index 8339b5f..1df1871 100644 --- a/test/messages_incoming_test.c +++ b/test/messages_incoming_test.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -7,8 +8,8 @@ #define ERROR_CHECK(ret) \ if (MESSAGES_ERROR_NONE != ret) { \ - printf("%d: error, ret=%d \n", __LINE__, ret); \ - exit(1); \ + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "%d: error, ret=%d \n", __LINE__, ret); \ + return(0); \ } static GMainLoop *mainloop; @@ -29,51 +30,51 @@ void incoming_cb(messages_message_h msg, void *user_data) int i, nAddr; char *addr = NULL; time_t time; - struct tm *ptm; + struct tm ptm; - printf("Incoming Message\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Incoming Message\n"); messages_get_address_count(msg, &nAddr); for (i=0; i < nAddr; i++) { ret = messages_get_address(msg, i, &addr, NULL); if (MESSAGES_ERROR_NONE == ret) { - printf("Address[%d]: %s\n", i, addr); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Address[%d]: %s\n", i, addr); free(addr); } } ret = messages_get_text(msg, &text); if (MESSAGES_ERROR_NONE == ret) { - printf("Text: %s\n", text); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Text: %s\n", text); free(text); } else { - printf("%d: error, ret=%d\n", __LINE__, ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "%d: error, ret=%d\n", __LINE__, ret); } messages_get_message_type(msg, &msgType); switch(msgType) { case MESSAGES_TYPE_SMS: - printf("Type: SMS\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Type: SMS\n"); break; case MESSAGES_TYPE_MMS: - printf("Type: MMS\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Type: MMS\n"); break; default: - printf("Type: Unknown\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Type: Unknown\n"); break; } messages_get_time(msg, &time); - printf("Time: %d, %s", (int)time, ctime(&time)); - - ptm = gmtime(&time); - printf("gmtime test: %d.%d.%d %d:%d:%d \n", - ptm->tm_year, ptm->tm_mon, ptm->tm_mday, - ptm->tm_hour, ptm->tm_min, ptm->tm_sec - ); - - + char buf[50]; + if (ctime_r(&time, buf)) + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Time: %d, %s", (int)time, ctime_r(&time, buf)); + + gmtime_r(&time, &ptm); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "gmtime test: %d.%d.%d %d:%d:%d \n", + ptm.tm_year, ptm.tm_mon, ptm.tm_mday, + ptm.tm_hour, ptm.tm_min, ptm.tm_sec + ); } int main(int argc, char *argv[]) diff --git a/test/messages_search_test.c b/test/messages_search_test.c index bd157f8..25300fd 100644 --- a/test/messages_search_test.c +++ b/test/messages_search_test.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -17,46 +18,48 @@ bool _search_cb(messages_message_h msg, int index, int result_count, int total_c messages_get_message_type(msg, &msgType); - printf("=[%d/%d]==================================\n", index + 1, result_count); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "=[%d/%d]==================================\n", index + 1, result_count); messages_get_address_count(msg, &nAddr); for (i=0; i < nAddr; i++) { ret = messages_get_address(msg, i, &addr, NULL); if (MESSAGES_ERROR_NONE == ret) { - printf("Address[%d]: %s\n", i, addr); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Address[%d]: %s\n", i, addr); free(addr); } } ret = messages_get_text(msg, &text); if (MESSAGES_ERROR_NONE == ret) { - printf("Text: %s\n", text); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Text: %s\n", text); free(text); } if (MESSAGES_TYPE_SMS == msgType) { - printf("Type: SMS\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Type: SMS\n"); } else if (MESSAGES_TYPE_MMS == msgType) { - printf("Type: MMS\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Type: MMS\n"); ret = messages_mms_get_subject(msg, &text); if (MESSAGES_ERROR_NONE == ret) { - printf("Subject: %s\n", text); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Subject: %s\n", text); free(text); } ret = messages_mms_get_attachment_count(msg, &cnt); if (MESSAGES_ERROR_NONE == ret) { - printf("Attachments: %d\n", cnt); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Attachments: %d\n", cnt); } } else { - printf("Type: Unknown"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Type: Unknown"); } ret = messages_get_time(msg, &time); - printf("Time: %d, %s", (int)time, ctime(&time)); + char buf[50]; + if (ctime_r(&time, buf)) + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Time: %d, %s", (int)time, ctime_r(&time, buf)); ret = messages_get_mbox_type(msg, &mbox); - printf("MBOX: %d\n", mbox); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "MBOX: %d\n", mbox); return true; @@ -72,7 +75,7 @@ int main(int argc, char *argv[]) // open service ret = messages_open_service(&svc); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_open_service() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_open_service() = %d", ret); return 1; } @@ -81,19 +84,19 @@ int main(int argc, char *argv[]) NULL, NULL, 0, 0, _search_cb, NULL); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_foreach_message_from_db() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_foreach_message_from_db() = %d", ret); return 1; } - printf("===============================================\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "===============================================\n"); ret = messages_get_message_count(svc, MESSAGES_MBOX_INBOX, MESSAGES_TYPE_SMS, &count); - printf("INBOX: %d messages\n", count); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "INBOX: %d messages\n", count); ret = messages_get_message_count(svc, MESSAGES_MBOX_SENTBOX, MESSAGES_TYPE_SMS, &count); - printf("SENTBOX: %d messages\n", count); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "SENTBOX: %d messages\n", count); ret = messages_get_message_count(svc, MESSAGES_MBOX_OUTBOX, MESSAGES_TYPE_SMS, &count); - printf("OUTBOX: %d sms messages\n", count); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "OUTBOX: %d sms messages\n", count); ret = messages_get_message_count(svc, MESSAGES_MBOX_OUTBOX, MESSAGES_TYPE_MMS, &count); - printf("OUTBOX: %d mms messages\n", count); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "OUTBOX: %d mms messages\n", count); diff --git a/test/messages_send_mms_test.c b/test/messages_send_mms_test.c index c2c5583..a2ea509 100644 --- a/test/messages_send_mms_test.c +++ b/test/messages_send_mms_test.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -20,7 +21,7 @@ static void sig_quit(int signo) void _sent_cb(messages_sending_result_e result, void *user_data) { - printf("sending result=%d\n", (int)result); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "sending result=%d\n", (int)result); } int main(int argc, char *argv[]) @@ -38,14 +39,14 @@ int main(int argc, char *argv[]) // open service ret = messages_open_service(&svc); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_open_service() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_open_service() = %d", ret); return 1; } // create message ret = messages_create_message(MESSAGES_TYPE_MMS, &msg); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_create_message() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_create_message() = %d", ret); return 1; } @@ -57,12 +58,12 @@ int main(int argc, char *argv[]) // messages_mms_add_attachment(msg, MESSAGES_MEDIA_IMAGE, "/opt/etc/msg-service/P091120_104633.jpg"); messages_mms_add_attachment(msg, MESSAGES_MEDIA_IMAGE, "/opt/media/Images/image2.jpg"); - printf("Before Sending\n"); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "Before Sending\n"); // send message ret = messages_send_message(svc, msg, true, _sent_cb, NULL); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_send_message() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_send_message() = %d", ret); return 1; } diff --git a/test/messages_send_sms_test.c b/test/messages_send_sms_test.c index b324024..6d385d8 100644 --- a/test/messages_send_sms_test.c +++ b/test/messages_send_sms_test.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -19,14 +20,14 @@ int main(int argc, char *argv[]) // open service ret = messages_open_service(&svc); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_open_service() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_open_service() = %d", ret); return 1; } // create message ret = messages_create_message(MESSAGES_TYPE_SMS, &msg); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_create_message() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_create_message() = %d", ret); return 1; } @@ -36,7 +37,7 @@ int main(int argc, char *argv[]) // send message ret = messages_send_message(svc, msg, true, _sent_cb, NULL); if (MESSAGES_ERROR_NONE != ret) { - printf("error: messages_send_message() = %d", ret); + dlog_print(DLOG_DEBUG, "MESSAGE_TEST", "error: messages_send_message() = %d", ret); return 1; } -- 2.34.1