From ecad346d67761cb3d308b6e4231bef785bb64c73 Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sat, 24 Oct 2015 16:23:17 +0900 Subject: tizen 2.4 release --- CMakeLists.txt | 2 +- include/email.h | 1 + packaging/capi-messaging-email.spec | 13 +- src/email.c | 271 ++++++++++++++++++++---------------- 4 files changed, 165 insertions(+), 122 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ea16db..3e1e6ca 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog glib-2.0 dbus-1 capi-base-common email-service") +SET(dependents "dlog glib-2.0 capi-base-common email-service") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) diff --git a/include/email.h b/include/email.h index fa6164d..529a750 100755 --- a/include/email.h +++ b/include/email.h @@ -227,6 +227,7 @@ int email_remove_all_attachments(email_h email); * @retval #EMAILS_ERROR_NONE Successful * @retval #EMAILS_ERROR_COMMUNICATION_WITH_SERVER_FAILED Communication with server failed. * @retval #EMAILS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EMAIL_ERROR_PERMISSION_DENIED Permission deny * * @pre An email message handle is created using email_create_message(). * diff --git a/packaging/capi-messaging-email.spec b/packaging/capi-messaging-email.spec index 1819491..2ccb5de 100755 --- a/packaging/capi-messaging-email.spec +++ b/packaging/capi-messaging-email.spec @@ -1,14 +1,21 @@ Name: capi-messaging-email Summary: Email library in Tizen Native API -Version: 0.1.24 +Version: 0.1.23 Release: 3 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz + +%if "%{?tizen_profile_name}" == "wearable" +ExcludeArch: %{arm} %ix86 x86_64 +%endif + +%if "%{?tizen_profile_name}" == "tv" +ExcludeArch: %{arm} %ix86 x86_64 +%endif + BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(dbus-1) -BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(email-service) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-appfw-application) diff --git a/src/email.c b/src/email.c index 537f459..2a9288e 100755 --- a/src/email.c +++ b/src/email.c @@ -17,20 +17,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -38,16 +33,21 @@ #define LOG_TAG "CAPI_EMAIL" #define EM_SAFE_STRDUP(s) \ - ({\ - char* _s = (char*)s;\ - (_s)? strdup(_s) : NULL;\ - }) +({\ + char* _s = (char*)s;\ + (_s)? strdup(_s) : NULL;\ +}) #define EM_SAFE_STRLEN(s) \ - ({\ - char* _s = (char*)s;\ - (_s)? strlen(_s) : 0;\ - }) +({\ + char* _s = (char*)s;\ + (_s)? strlen(_s) : 0;\ +}) + +#define FILE_PATH "/opt/usr/media/.email/capimail.txt" +#define TMP_PATH "/opt/usr/media/.email" + +static guint g_dbus_return_id = 0; typedef struct { email_message_sent_cb callback; @@ -57,9 +57,10 @@ typedef struct { GSList *gEmailcbList= NULL; -DBusConnection* connection=NULL; +GDBusConnection* connection=NULL; //------------- Utility Or Miscellaneous void _email_add_dbus_filter(void); +void _email_remove_dbus_filter(void); int _email_error_converter(int err, const char *func, int line); int _email_copy_handle(email_s **dst_handle, email_s *src_handle); void _email_free_cb_context(email_cb_context *cbcontext); @@ -106,8 +107,6 @@ int email_create_message(email_h *msg) free(msg_s); return EMAILS_ERROR_OUT_OF_MEMORY; } - - } else { @@ -127,8 +126,8 @@ int email_create_message(email_h *msg) return CONVERT_ERROR(ret); } - ret = email_get_account(default_account_id, GET_FULL_DATA, &account); - if(ret!=EMAIL_ERROR_NONE) { + ret = email_get_account(default_account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account); + if (ret!=EMAIL_ERROR_NONE) { SECURE_SLOGE("[%s] email_get_account failed : [%d]",__FUNCTION__, ret); if (account) { email_free_account(&account, 1); @@ -247,22 +246,28 @@ int email_set_body (email_h msg, const char *body) LOGD("START\n"); int len; - if (msg == NULL) - { + if (msg == NULL) { SECURE_SLOGE("[%s] INVALID_PARAMETER(0x%08x) : msg is null.", __FUNCTION__, EMAILS_ERROR_INVALID_PARAMETER); return EMAILS_ERROR_INVALID_PARAMETER; } email_s* msg_s = (email_s* )msg; - - FILE* file = NULL; - - file = fopen("/tmp/capimail.txt", "w"); + if (!g_file_test(TMP_PATH, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + if (g_mkdir(TMP_PATH, 0775) == -1) { + SECURE_SLOGE("[%s] OPERATION_FAILED(0x%08x) : Create directory failed.", __FUNCTION__, EMAILS_ERROR_OPERATION_FAILED); + return EMAILS_ERROR_OPERATION_FAILED; + } - if (file != NULL) - { + if (g_chmod(TMP_PATH, 0775) == -1) { + SECURE_SLOGE("[%s] OPERATION_FAILED(0x%08x) : Change permission failed.", __FUNCTION__, EMAILS_ERROR_OPERATION_FAILED); + return EMAILS_ERROR_OPERATION_FAILED; + } + } + + file = fopen(FILE_PATH, "w"); + if (file != NULL) { fputs(body, file); fclose(file); } else { @@ -270,22 +275,20 @@ int email_set_body (email_h msg, const char *body) return EMAILS_ERROR_OPERATION_FAILED; } - msg_s->mail->file_path_plain =(char *)calloc(1,sizeof(char)*strlen("/tmp/capimail.txt")+1); + len = strlen(FILE_PATH) + 1; - if(msg_s->mail->file_path_plain == NULL) { + msg_s->mail->file_path_plain = (char *)calloc(1, sizeof(char) * len); + if (msg_s->mail->file_path_plain == NULL) { SECURE_SLOGE("[%s] OUT_OF_MEMORY(0x%08x) : fail to allocate body(plain).", __FUNCTION__, EMAILS_ERROR_OUT_OF_MEMORY); return EMAILS_ERROR_OUT_OF_MEMORY; } - len =strlen("/tmp/capimail.txt")+1; - snprintf(msg_s->mail->file_path_plain,len,"%s","/tmp/capimail.txt"); + snprintf(msg_s->mail->file_path_plain, len, "%s", FILE_PATH); LOGD("END\n"); return EMAILS_ERROR_NONE; } - - int email_add_recipient (email_h msg, email_recipient_type_e type, const char *address) { LOGD("START\n"); @@ -593,8 +596,6 @@ int email_send_message (email_h msg, bool save_to_sentbox) email_s *msg_s = (email_s *)msg; - _email_add_dbus_filter(); - ret=email_send_mail(msg_s->mail->mail_id, &handle); ret=CONVERT_ERROR(ret); @@ -679,6 +680,15 @@ int email_set_message_sent_cb (email_h handle, email_message_sent_cb cb, void *u email_cb_context *cbcontext = (email_cb_context *)calloc(1, sizeof(email_cb_context)); if (cbcontext == NULL) { SECURE_SLOGE("[%s] calloc failed", __FUNCTION__); + if (msg_s) { + if (msg_s->mail) + email_free_mail_data(&msg_s->mail, 1); + + if (msg_s->mbox) + email_free_mailbox(&msg_s->mbox, 1); + + free(msg_s); + } ret = EMAIL_ERROR_OUT_OF_MEMORY; return ret; } @@ -693,6 +703,9 @@ int email_set_message_sent_cb (email_h handle, email_message_sent_cb cb, void *u gEmailcbList = g_slist_append(gEmailcbList, cbcontext); + /* Set the dbus filter */ + _email_add_dbus_filter(); + LOGD("END\n"); return EMAILS_ERROR_NONE; } @@ -731,6 +744,9 @@ int email_unset_message_sent_cb (email_h msg) } } + /* Remove the dbus filter */ + _email_remove_dbus_filter(); + LOGD("END\n"); return EMAILS_ERROR_NONE; } @@ -766,6 +782,7 @@ int _email_error_converter(int err, const char *func, int line) SECURE_SLOGE("[%s:%d] IPC_SOCKET_FAILURE(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAILS_ERROR_COMMUNICATION_WITH_SERVER_FAILED,err); return EMAILS_ERROR_COMMUNICATION_WITH_SERVER_FAILED; + case EMAIL_ERROR_NO_SMACK_RULE : case EMAIL_ERROR_PERMISSION_DENIED : SECURE_SLOGE("[%s:%d] PERMISSION_DENIED(0x%08x) : Error from Email F/W. ret: (0x%08x) ", func, line, EMAILS_ERROR_PERMISSION_DENIED,err); return EMAILS_ERROR_PERMISSION_DENIED; @@ -781,72 +798,83 @@ int _email_error_converter(int err, const char *func, int line) LOGD("END\n"); } -DBusHandlerResult _monitorSendStatusCb(DBusConnection *connection, DBusMessage *message, void *user_data) +static void _monitorSendStatusCb(GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer data) { LOGD("START\n"); - DBusError error; + int status = 0; + int account_id = 0; + char *file_id = NULL; + int mail_id = 0; + int error_code = 0; + email_cb_context *cbContext = NULL; - if(dbus_message_is_signal(message, "User.Email.NetworkStatus", "email")) - { - dbus_error_init(&error); - - int status=0; - int accountid=0; - char* fileid=NULL; - int mailid=0; - int errorcode=0; - if(dbus_message_get_args(message, &error, - DBUS_TYPE_INT32, &status, - DBUS_TYPE_INT32, &accountid, - DBUS_TYPE_STRING, &fileid, - DBUS_TYPE_INT32, &mailid, - DBUS_TYPE_INT32, &errorcode, - DBUS_TYPE_INVALID)) - { - SECURE_LOGD("status:[%d], account_id:[%d], file_id:[%s], mail_id:[%d], error_code:[%d]", status, accountid, fileid, mailid, errorcode); - cbContext = _email_search_callback_by_emailid(mailid); - if (cbContext == NULL) { - SECURE_LOGD("no callback matched!\n"); - }else{ - SECURE_LOGD("Address : [%p]\n", cbContext->callback); - switch (status) { - case NOTI_SEND_START: - break; - - case NOTI_SEND_FAIL: - - switch(errorcode) - { - case EMAIL_ERROR_NO_SIM_INSERTED: - case EMAIL_ERROR_FLIGHT_MODE: - case EMAIL_ERROR_SMTP_SEND_FAILURE: - case EMAIL_ERROR_NO_SUCH_HOST: - case EMAIL_ERROR_CONNECTION_FAILURE: - case EMAIL_ERROR_CONNECTION_BROKEN: - case EMAIL_ERROR_INVALID_SERVER: - case EMAIL_ERROR_NO_RESPONSE: - - break; - - default: - break; - } - - cbContext->callback((email_h)cbContext->handle,(email_sending_e)EMAIL_SENDING_FAILED ,cbContext->user_data); - break; - - case NOTI_SEND_FINISH: - cbContext->callback((email_h)cbContext->handle,(email_sending_e)EMAIL_SENDING_SUCCEEDED ,cbContext->user_data); - break; - - } - } + if (strncasecmp(interface_name, "USER.EMAIL.NETWORKSTATUS", strlen("USER.EMAIL.NETWORKSTATUS")) && + strncasecmp(sender_name, "EMAIL", strlen("EMAIL"))) { + LOGE("Invalid interface : [%s]", interface_name); + return; + } + + g_variant_get(parameters, "(iisii)", + &status, + &account_id, + &file_id, + &mail_id, + &error_code); + + SECURE_LOGD("status:[%d], account_id:[%d], file_id:[%s], mail_id:[%d], error_code:[%d]", + status, + account_id, + file_id, + mail_id, + error_code); + + cbContext = _email_search_callback_by_emailid(mail_id); + if (cbContext == NULL) { + SECURE_LOGD("no callback matched!\n"); + } else { + SECURE_LOGD("Address : [%p]\n", cbContext->callback); + switch (status) { + case NOTI_SEND_START: + break; + + case NOTI_SEND_FAIL: + switch(error_code) + { + case EMAIL_ERROR_NO_SIM_INSERTED: + case EMAIL_ERROR_FLIGHT_MODE: + case EMAIL_ERROR_SMTP_SEND_FAILURE: + case EMAIL_ERROR_NO_SUCH_HOST: + case EMAIL_ERROR_CONNECTION_FAILURE: + case EMAIL_ERROR_CONNECTION_BROKEN: + case EMAIL_ERROR_INVALID_SERVER: + case EMAIL_ERROR_NO_RESPONSE: + break; + + default: + break; } + + cbContext->callback((email_h)cbContext->handle, + (email_sending_e)EMAIL_SENDING_FAILED, + cbContext->user_data); + break; + + case NOTI_SEND_FINISH: + cbContext->callback((email_h)cbContext->handle, + (email_sending_e)EMAIL_SENDING_SUCCEEDED, + cbContext->user_data); + break; + } } - LOGD("END\n"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + LOGE("END\n"); } void _email_add_dbus_filter(void) @@ -854,34 +882,41 @@ void _email_add_dbus_filter(void) LOGD("START\n"); if (connection != NULL) - return; + return; - DBusError error; - - dbus_error_init(&error); + GError *error = NULL; - connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (NULL == connection) { - SECURE_SLOGE("dbus_bus_get failed"); + SECURE_SLOGE("g_bus_get_sync failed : [%s]", error->message); + g_error_free(error); return; } LOGD("connection [%p]", connection); - char *rule = "type='signal',interface='User.Email.NetworkStatus'"; - LOGD("Signal match rule: %s", rule); - dbus_bus_add_match(connection, rule, &error); - - if (dbus_error_is_set(&error)) { - LOGD("Cannot add D-BUS match rule, cause: %s", error.message); - dbus_error_free(&error); - return; + g_dbus_return_id = g_dbus_connection_signal_subscribe(connection, + NULL, + "User.Email.NetworkStatus", + "email", + "/User/Email/NetworkStatus", + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + _monitorSendStatusCb, + NULL, + NULL); + if (g_dbus_return_id == -1) { + LOGE("g_dbus_connection_signal_subscribe failed"); } - dbus_connection_setup_with_g_main(connection, NULL); - - dbus_connection_add_filter(connection, _monitorSendStatusCb, NULL, NULL); + LOGE("END\n"); +} - LOGD("END\n"); +void _email_remove_dbus_filter(void) +{ + g_dbus_connection_signal_unsubscribe(connection, g_dbus_return_id); + g_object_unref(connection); + connection = NULL; + g_dbus_return_id = 0; } int _email_copy_mail_data(email_mail_data_t **dst_mail_data, email_mail_data_t *src_mail_data) -- cgit v1.2.3