From: taekeun.kang Date: Fri, 25 Nov 2016 08:45:27 +0000 (+0900) Subject: [Push] Set empty string to optional attributes of PushMessage X-Git-Tag: submit/tizen/20161128.110522^2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c0fc4a78fa66e0f517c14d51e8382139d71c449;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Push] Set empty string to optional attributes of PushMessage Change-Id: I516c5106de028bf8f95683573b73ba9fce4a1ebd Signed-off-by: taekeun.kang --- diff --git a/src/push/push_manager.cc b/src/push/push_manager.cc index 467e091b..84ec17a1 100644 --- a/src/push/push_manager.cc +++ b/src/push/push_manager.cc @@ -283,6 +283,10 @@ common::PlatformResult PushManager::getRegistrationId(std::string& id) { common::PlatformResult PushManager::getUnreadNotifications() { LoggerD("Enter"); + if (!m_handle) { + return LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Not connected with push service"); + } + int ret = push_service_request_unread_notification(m_handle); if (PUSH_SERVICE_ERROR_NONE != ret) { return LogAndCreateResult(PushManagerCommon::ConvertPushError_2_4(ret), "Failed to get unread notifications", diff --git a/src/push/push_manager_common.cc b/src/push/push_manager_common.cc index 5be62dab..863583e6 100644 --- a/src/push/push_manager_common.cc +++ b/src/push/push_manager_common.cc @@ -65,32 +65,43 @@ void PushManagerCommon::notificationToJson(push_service_notification_h noti, pic char* temp = nullptr; int ret = push_service_get_notification_data(noti, &temp); if (ret != PUSH_SERVICE_ERROR_NONE) { - LoggerE("Failed to get appData"); - return; + if (ret == PUSH_SERVICE_ERROR_NO_DATA) { + LoggerI("push_service_get_notification_data return PUSH_SERVICE_ERROR_NO_DATA"); + (*obj)["appData"] = picojson::value(""); + } else { + LoggerE("Failed to get appData"); + return; + } + } else { + (*obj)["appData"] = picojson::value(temp); + free(temp); } - (*obj)["appData"] = picojson::value(temp); - free(temp); char* fullMessage = nullptr; ret = push_service_get_notification_message(noti, &fullMessage); if (ret != PUSH_SERVICE_ERROR_NONE) { - LoggerE("Failed to get message"); - return; - } - (*obj)["message"] = picojson::value(fullMessage); - - // parse query string and find value for alertMessage - pcrecpp::StringPiece input(fullMessage); - pcrecpp::RE re("([^=]+)=([^&]*)&?"); - string key; - string value; - while (re.Consume(&input, &key, &value)) { - if (key == "alertMessage") { - (*obj)["alertMessage"] = picojson::value(value); - break; + if (ret == PUSH_SERVICE_ERROR_NO_DATA) { + LoggerI("push_service_get_notification_message return PUSH_SERVICE_ERROR_NO_DATA"); + (*obj)["message"] = picojson::value(""); + } else { + LoggerE("Failed to get message"); + return; + } + } else { + (*obj)["message"] = picojson::value(fullMessage); + // parse query string and find value for alertMessage + pcrecpp::StringPiece input(fullMessage); + pcrecpp::RE re("([^=]+)=([^&]*)&?"); + string key; + string value; + while (re.Consume(&input, &key, &value)) { + if (key == "alertMessage") { + (*obj)["alertMessage"] = picojson::value(value); + break; + } } + free(fullMessage); } - free(fullMessage); long long int date = -1; ret = push_service_get_notification_time(noti, &date); @@ -102,20 +113,31 @@ void PushManagerCommon::notificationToJson(push_service_notification_h noti, pic ret = push_service_get_notification_sender(noti, &temp); if (ret != PUSH_SERVICE_ERROR_NONE) { - LoggerE("Failed to get sender"); - return; + if (ret == PUSH_SERVICE_ERROR_NO_DATA) { + LoggerI("push_service_get_notification_sender return PUSH_SERVICE_ERROR_NO_DATA"); + (*obj)["sender"] = picojson::value(""); + } else { + LoggerE("Failed to get sender"); + return; + } + } else { + (*obj)["sender"] = picojson::value(temp); + free(temp); } - (*obj)["sender"] = picojson::value(temp); - free(temp); ret = push_service_get_notification_session_info(noti, &temp); if (ret != PUSH_SERVICE_ERROR_NONE) { - LoggerE("Failed to get session info"); - return; + if (ret == PUSH_SERVICE_ERROR_NO_DATA) { + LoggerI("push_service_get_notification_session_info return PUSH_SERVICE_ERROR_NO_DATA"); + (*obj)["sessionInfo"] = picojson::value(""); + } else { + LoggerE("Failed to get session info"); + return; + } + } else { + (*obj)["sessionInfo"] = picojson::value(temp); + free(temp); } - std::string session_info = temp; - (*obj)["sesionInfo"] = picojson::value(temp); - free(temp); ret = push_service_get_notification_request_id(noti, &temp); if (ret != PUSH_SERVICE_ERROR_NONE) { @@ -124,14 +146,6 @@ void PushManagerCommon::notificationToJson(push_service_notification_h noti, pic } (*obj)["requestId"] = picojson::value(temp); free(temp); - - int type; - ret = push_service_get_notification_type(noti, &type); - if (ret != PUSH_SERVICE_ERROR_NONE) { - LoggerE("Failed to get type"); - return; - } - (*obj)["type"] = picojson::value(static_cast(type)); } // 3.0 version errors mappings