diff options
author | Seungbae Shin <seungbae.shin@samsung.com> | 2022-09-02 03:53:43 +0900 |
---|---|---|
committer | Seungbae Shin <seungbae.shin@samsung.com> | 2022-09-02 16:01:35 +0900 |
commit | a6a2f407fa8357e45484299a3276cfc71a6030c3 (patch) | |
tree | a5957c0250a5e02bd796f26cf49089801ce63fb9 | |
parent | 5e9aa84d991fc4aa143f033c236726902cbd398a (diff) | |
download | mediatransporter-a6a2f407fa8357e45484299a3276cfc71a6030c3.tar.gz mediatransporter-a6a2f407fa8357e45484299a3276cfc71a6030c3.tar.bz2 mediatransporter-a6a2f407fa8357e45484299a3276cfc71a6030c3.zip |
[0.0.5] Add required feature and privilege check
For MediaTransporterBase:
- http://tizen.org/feature/network.wifi
- http://tizen.org/feature/network.telephony
- http://tizen.org/feature/network.ethernet
- http://tizen.org/privilege/internet
For MediaSourceBinCamera:
- http://tizen.org/feature/camera
- http://tizen.org/privilege/camera
For MediaSourceBinMic:
- http://tizen.org/feature/microphone
- http://tizen.org/privilege/recorder
Change-Id: Ib3b35ef56fe980bb18ae88cc22356ec11215da85
-rw-r--r-- | include/MediaTransporterReceiver.h | 3 | ||||
-rw-r--r-- | include/MediaTransporterUtil.h | 6 | ||||
-rw-r--r-- | packaging/capi-media-transporter.spec | 2 | ||||
-rw-r--r-- | src/MediaSourceBinAudioTest.cpp | 1 | ||||
-rw-r--r-- | src/MediaSourceBinCamera.cpp | 5 | ||||
-rw-r--r-- | src/MediaSourceBinMic.cpp | 5 | ||||
-rw-r--r-- | src/MediaSourceBinVideoTest.cpp | 1 | ||||
-rw-r--r-- | src/MediaTransporter.cpp | 4 | ||||
-rw-r--r-- | src/MediaTransporterUtil.cpp | 35 |
9 files changed, 34 insertions, 28 deletions
diff --git a/include/MediaTransporterReceiver.h b/include/MediaTransporterReceiver.h index 924df8a..4aba2ec 100644 --- a/include/MediaTransporterReceiver.h +++ b/include/MediaTransporterReceiver.h @@ -49,8 +49,9 @@ public: void unsetNoMoreTrackCallback(); void setVideoPacketCallback(void* handle, mtprPacketCallback callback, void* userData); - void setAudioPacketCallback(void* handle, mtprPacketCallback callback, void* userData); void unsetVideoPacketCallback(); + + void setAudioPacketCallback(void* handle, mtprPacketCallback callback, void* userData); void unsetAudioPacketCallback(); void setDisplay(std::shared_ptr<MediaTransporterDisplay> display); diff --git a/include/MediaTransporterUtil.h b/include/MediaTransporterUtil.h index f59b4b3..838d3ea 100644 --- a/include/MediaTransporterUtil.h +++ b/include/MediaTransporterUtil.h @@ -34,9 +34,9 @@ const std::string MTPR_PRIVILEGE_INTERNET = "http://tizen.org/privilege/internet const std::string MTPR_PRIVILEGE_CAMERA = "http://tizen.org/privilege/camera"; const std::string MTPR_PRIVILEGE_RECORDER = "http://tizen.org/privilege/recorder"; -void throw_if_not_privileged(const std::string& privilege); -void throw_if_feature_not_supported(const std::string& feature); -void throw_if_network_features_not_supported(); +void throwIfNotPrivileged(const std::string& privilege); +void throwIfFeatureNotSupported(const std::string& feature); +void throwIfNetworkFeaturesNotSupported(); } // util } // namespace diff --git a/packaging/capi-media-transporter.spec b/packaging/capi-media-transporter.spec index 1ea299f..8bff4b8 100644 --- a/packaging/capi-media-transporter.spec +++ b/packaging/capi-media-transporter.spec @@ -1,6 +1,6 @@ Name: capi-media-transporter Summary: A Media Transporter library in Tizen Native API -Version: 0.0.4 +Version: 0.0.5 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/MediaSourceBinAudioTest.cpp b/src/MediaSourceBinAudioTest.cpp index 145aad0..91369d1 100644 --- a/src/MediaSourceBinAudioTest.cpp +++ b/src/MediaSourceBinAudioTest.cpp @@ -26,7 +26,6 @@ using namespace tizen_media_transporter; MediaSourceBinAudioTest::MediaSourceBinAudioTest(bundle* params) { - // privilege check parseSourceParam(params); } diff --git a/src/MediaSourceBinCamera.cpp b/src/MediaSourceBinCamera.cpp index 1143a5b..0d66f1a 100644 --- a/src/MediaSourceBinCamera.cpp +++ b/src/MediaSourceBinCamera.cpp @@ -18,6 +18,7 @@ #include "MediaTransporterLog.h" #include "MediaTransporterException.h" #include "MediaTransporterParseIni.h" +#include "MediaTransporterUtil.h" #include <algorithm> @@ -26,7 +27,9 @@ using namespace tizen_media_transporter; MediaSourceBinCamera::MediaSourceBinCamera(bundle* params) { - // privilege check + util::throwIfFeatureNotSupported(util::MTPR_FEATURE_CAMERA); + util::throwIfNotPrivileged(util::MTPR_PRIVILEGE_CAMERA); + parseSourceParam(params); } diff --git a/src/MediaSourceBinMic.cpp b/src/MediaSourceBinMic.cpp index 45bfa91..4ea6af1 100644 --- a/src/MediaSourceBinMic.cpp +++ b/src/MediaSourceBinMic.cpp @@ -18,6 +18,7 @@ #include "MediaTransporterLog.h" #include "MediaTransporterException.h" #include "MediaTransporterParseIni.h" +#include "MediaTransporterUtil.h" #include <sound_manager_internal.h> #include <pulse/proplist.h> @@ -29,7 +30,9 @@ using namespace tizen_media_transporter; MediaSourceBinMic::MediaSourceBinMic(bundle* params) { - // privilege check + util::throwIfFeatureNotSupported(util::MTPR_FEATURE_MICROPHONE); + util::throwIfNotPrivileged(util::MTPR_PRIVILEGE_RECORDER); + parseSourceParam(params); } diff --git a/src/MediaSourceBinVideoTest.cpp b/src/MediaSourceBinVideoTest.cpp index 972775c..179d7f6 100644 --- a/src/MediaSourceBinVideoTest.cpp +++ b/src/MediaSourceBinVideoTest.cpp @@ -26,7 +26,6 @@ using namespace tizen_media_transporter; MediaSourceBinVideoTest::MediaSourceBinVideoTest(bundle* params) { - // privilege check parseSourceParam(params); } diff --git a/src/MediaTransporter.cpp b/src/MediaTransporter.cpp index 123c820..87a007a 100644 --- a/src/MediaTransporter.cpp +++ b/src/MediaTransporter.cpp @@ -7,6 +7,7 @@ #include "MediaTransporterException.h" #include "MediaTransporterSender.h" #include "MediaTransporterReceiver.h" +#include "MediaTransporterUtil.h" #include "MediaSourceBinMic.h" #include <cassert> @@ -26,6 +27,9 @@ int mtpr_create(mtpr_connection_type_e type, mtpr_h* mtpr) RET_VAL_IF(!handle, MTPR_ERROR_INVALID_OPERATION, "Failed to allocate handle!!!"); try { + util::throwIfNetworkFeaturesNotSupported(); + util::throwIfNotPrivileged(util::MTPR_PRIVILEGE_INTERNET); + handle->base = std::unique_ptr<MediaTransporterBase>( MediaTransporterFactory::create(static_cast<mtprConnectionType>(type))); RET_ERR_IF_INVALID_INSTANCE(handle->base); diff --git a/src/MediaTransporterUtil.cpp b/src/MediaTransporterUtil.cpp index cc103df..550460b 100644 --- a/src/MediaTransporterUtil.cpp +++ b/src/MediaTransporterUtil.cpp @@ -16,6 +16,7 @@ #include "MediaTransporterUtil.h" #include "MediaTransporterException.h" +#include "MediaTransporterLog.h" #include <stdio.h> #include <unistd.h> @@ -23,14 +24,15 @@ #include <cynara-client.h> #include <sys/smack.h> #include <system_info.h> +#include <glib.h> + using namespace tizen_media_transporter; -void util::throw_if_not_privileged(const std::string& privilege) +void util::throwIfNotPrivileged(const std::string& privilege) { - // int ret = MTPR_ERROR_NONE; - cynara *cynara_h; - char *smack_label = nullptr; + cynara* cynara_h = nullptr; + g_autofree char* smack_label = nullptr; try { if (cynara_initialize(&cynara_h, NULL) != CYNARA_API_SUCCESS) @@ -43,28 +45,23 @@ void util::throw_if_not_privileged(const std::string& privilege) char uid[10]; snprintf(uid, sizeof(uid), "%d", getuid()); - //LOG_DEBUG("smack_label[%s] uid[%s]\n", smack_label, uid); - int cynara_ret = cynara_check(cynara_h, smack_label, "", uid, privilege.c_str()); - if (cynara_ret != CYNARA_API_ACCESS_ALLOWED) { - //LOG_ERROR("NOT ALLOWED, privilege[%s], cynara_ret[%d]", privilege, cynara_ret); + if (cynara_check(cynara_h, smack_label, "", uid, privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) throw MediaTransporterException(MTPR_ERROR_PERMISSION_DENIED, "[" + privilege + "] is NOT ALLOWED"); - } - //LOG_INFO("ALLOWED, privilege[%s]", privilege); } catch (const MediaTransporterException& e) { - free(smack_label); if (cynara_h) cynara_finish(cynara_h); throw; } - free(smack_label); cynara_finish(cynara_h); + + LOG_INFO("privilege[%s] allowed", privilege.c_str()); } -void util::throw_if_feature_not_supported(const std::string& feature) +void util::throwIfFeatureNotSupported(const std::string& feature) { bool supported = false; @@ -74,17 +71,17 @@ void util::throw_if_feature_not_supported(const std::string& feature) if (!supported) throw MediaTransporterException(MTPR_ERROR_NOT_SUPPORTED, - "[" + feature + "] is not supported"); + "[" + feature + "] not supported"); - //LOG_INFO("feature[%s] is supported", feature); + LOG_INFO("feature[%s] supported", feature.c_str()); } -void util::throw_if_network_features_not_supported() +void util::throwIfNetworkFeaturesNotSupported() { try { - throw_if_feature_not_supported(MTPR_FEATURE_NETWORK_WIFI); - throw_if_feature_not_supported(MTPR_FEATURE_NETWORK_TELE); - throw_if_feature_not_supported(MTPR_FEATURE_NETWORK_ETH); + throwIfFeatureNotSupported(MTPR_FEATURE_NETWORK_WIFI); + throwIfFeatureNotSupported(MTPR_FEATURE_NETWORK_TELE); + throwIfFeatureNotSupported(MTPR_FEATURE_NETWORK_ETH); } catch (const MediaTransporterException& e) { throw MediaTransporterException(MTPR_ERROR_NOT_SUPPORTED, e.what()); } |