Removing unnecessary HTML link for feature/privilege
[platform/core/api/url-download.git] / src / download-wrapping.c
index 0afada1..4506d90 100755 (executable)
@@ -7,44 +7,17 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
-#include <system_info.h>
 
-#include <dlog.h>
 #include <download.h>
+#include <download_private.h>
 #include <download-provider-interface.h>
 
-#define DEBUG_MSG
-#ifdef DEBUG_MSG
-#include <dlog.h>
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "TIZEN_N_URL_DOWNLOAD"
-#define TRACE_ERROR(format, ARG...)  \
-{ \
-LOGE(format, ##ARG); \
-}
-#define TRACE_STRERROR(format, ARG...)  \
-{ \
-LOGE(format" [%s]", ##ARG, strerror(errno)); \
-}
-#define TRACE_INFO(format, ARG...)  \
-{ \
-LOGI(format, ##ARG); \
-}
-#else
-#define TRACE_DEBUG_MSG(format, ARG...) ;
-#endif
-
-#define TELEPHONY_FEATURE      "tizen.org/feature/network.telephony"
-#define WIFI_FEATURE                   "tizen.org/feature/network.wifi"
-#define WIFI_DIRECT_FEATURE    "tizen.org/feature/network.wifi.direct"
-
 /////////////////////// APIs /////////////////////////////////
 
 int download_create(int *download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (download_id == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_create(download_id);
@@ -53,24 +26,28 @@ int download_create(int *download_id)
 int download_destroy(int download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_destroy(download_id);
 }
 
 int download_start(int download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_start(download_id);
 }
 
 int download_pause(int download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_pause(download_id);
 }
 
 int download_cancel(int download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_cancel(download_id);
 }
 
@@ -78,6 +55,7 @@ int download_cancel(int download_id)
 int download_set_url(int download_id, const char *url)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (url == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_url(download_id, url);
@@ -87,6 +65,7 @@ int download_set_url(int download_id, const char *url)
 int download_get_url(int download_id, char **url)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (url == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_url(download_id, url);
@@ -96,42 +75,15 @@ int download_set_network_type(int download_id,
                                                download_network_type_e net_type)
 {
        TRACE_INFO("");
-
-       int bIsTelephonyFeatureSupported = 0;
-       int bIsWifiFeatureSupported = 0;
-       int bIsWifiDirectFeatureSupported = 0;
-
-       system_info_get_platform_bool (TELEPHONY_FEATURE, &bIsTelephonyFeatureSupported);
-       system_info_get_platform_bool (WIFI_FEATURE, &bIsWifiFeatureSupported);
-       system_info_get_platform_bool (WIFI_DIRECT_FEATURE, &bIsWifiDirectFeatureSupported);
-
-       switch (net_type)
-       {
-               case DOWNLOAD_NETWORK_DATA_NETWORK:
-                       if ( !bIsTelephonyFeatureSupported )
-                       {
-                               return DOWNLOAD_ERROR_NOT_SUPPORTED;
-                       }
-                       break;
-               case DOWNLOAD_NETWORK_WIFI:
-                       if ( !bIsWifiFeatureSupported )
-                       {
-                               return DOWNLOAD_ERROR_NOT_SUPPORTED;
-                       }
-                       break;
-               case DOWNLOAD_NETWORK_WIFI_DIRECT:
-                       if ( !bIsWifiDirectFeatureSupported )
-                       {
-                               return DOWNLOAD_ERROR_NOT_SUPPORTED;
-                       }
-                       break;
-               case DOWNLOAD_NETWORK_ALL:
-                       if ( !bIsTelephonyFeatureSupported && !bIsWifiFeatureSupported && !bIsWifiDirectFeatureSupported )
-                       {
-                               return DOWNLOAD_ERROR_NOT_SUPPORTED;
-                       }
-                       break;
-       }
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       if (net_type == DOWNLOAD_NETWORK_DATA_NETWORK)
+               CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+       else if (net_type == DOWNLOAD_NETWORK_WIFI)
+               CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       else if (net_type == DOWNLOAD_NETWORK_WIFI_DIRECT)
+                CHECK_FEATURE_SUPPORTED(WIFI_DIRECT_FEATURE);
+       else if (net_type == DOWNLOAD_NETWORK_ALL)
+               CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, WIFI_DIRECT_FEATURE);
 
        return dp_interface_set_network_type(download_id, (int)net_type);
 }
@@ -140,6 +92,7 @@ int download_get_network_type(int download_id,
                                                        download_network_type_e *net_type)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
 
        if (net_type == NULL) {
                TRACE_ERROR("Parameter NULL Check");
@@ -155,6 +108,7 @@ int download_get_network_type(int download_id,
 int download_set_network_bonding(int download_id, bool enable)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_set_network_bonding(download_id, (int)enable);
 }
 
@@ -162,6 +116,7 @@ int download_get_network_bonding(int download_id, bool *enable)
 {
        int is_set = 0;
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (enable == NULL) {
                TRACE_ERROR("Parameter NULL Check");
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
@@ -175,6 +130,7 @@ int download_get_network_bonding(int download_id, bool *enable)
 int download_set_destination(int download_id, const char *path)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (path == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_destination(download_id, path);
@@ -184,6 +140,7 @@ int download_set_destination(int download_id, const char *path)
 int download_get_destination(int download_id, char **path)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (path == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_destination(download_id, path);
@@ -192,6 +149,7 @@ int download_get_destination(int download_id, char **path)
 int download_set_file_name(int download_id, const char *file_name)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (file_name == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_file_name(download_id, file_name);
@@ -200,6 +158,7 @@ int download_set_file_name(int download_id, const char *file_name)
 int download_get_file_name(int download_id, char **file_name)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (file_name == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_file_name(download_id, file_name);
@@ -208,6 +167,7 @@ int download_get_file_name(int download_id, char **file_name)
 int download_get_downloaded_file_path(int download_id, char **path)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (path == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_downloaded_file_path(download_id, path);
@@ -217,6 +177,7 @@ int download_add_http_header_field(int download_id, const char *field,
        const char *value)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (field == NULL || value == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return
@@ -227,6 +188,7 @@ int download_get_http_header_field(int download_id,
        const char *field, char **value)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (field == NULL || value == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return
@@ -237,6 +199,7 @@ int download_get_http_header_field_list(int download_id, char ***fields,
        int *length)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (fields == NULL || length == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_http_header_field_list(download_id, fields,
@@ -247,6 +210,7 @@ int download_remove_http_header_field(int download_id,
        const char *field)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (field == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_remove_http_header_field(download_id, field);
@@ -257,6 +221,7 @@ int download_set_state_changed_cb(int download_id,
        download_state_changed_cb callback, void* user_data)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_set_state_changed_cb(download_id,
                (dp_interface_state_changed_cb)callback, user_data);
 }
@@ -264,6 +229,7 @@ int download_set_state_changed_cb(int download_id,
 int download_unset_state_changed_cb(int download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_unset_state_changed_cb(download_id);
 }
 
@@ -272,6 +238,7 @@ int download_set_progress_cb(int download_id,
        download_progress_cb callback, void *user_data)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_set_progress_cb(download_id,
                        (dp_interface_progress_cb)callback, user_data);
 }
@@ -279,6 +246,7 @@ int download_set_progress_cb(int download_id,
 int download_unset_progress_cb(int download_id)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_unset_progress_cb(download_id);
 }
 
@@ -286,6 +254,7 @@ int download_get_state(int download_id, download_state_e *state)
 {
        int statecode = 0;
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (state == NULL) {
                TRACE_ERROR("Parameter NULL Check");
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
@@ -299,6 +268,7 @@ int download_get_state(int download_id, download_state_e *state)
 int download_get_temp_path(int download_id, char **temp_path)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (temp_path == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_temp_path(download_id, temp_path);
@@ -307,6 +277,7 @@ int download_get_temp_path(int download_id, char **temp_path)
 int download_get_content_name(int download_id, char **content_name)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (content_name == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_content_name(download_id, content_name);
@@ -316,6 +287,7 @@ int download_get_content_size(int download_id,
        unsigned long long *content_size)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (content_size == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_content_size(download_id, content_size);
@@ -324,6 +296,7 @@ int download_get_content_size(int download_id,
 int download_get_mime_type(int download_id, char **mime_type)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (mime_type == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_mime_type(download_id, mime_type);
@@ -332,6 +305,7 @@ int download_get_mime_type(int download_id, char **mime_type)
 int download_set_auto_download(int download_id, bool enable)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_set_auto_download(download_id, (int)enable);
 }
 
@@ -339,6 +313,7 @@ int download_get_auto_download(int download_id, bool *enable)
 {
        int is_set = 0;
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (enable == NULL) {
                TRACE_ERROR("Parameter NULL Check");
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
@@ -353,6 +328,7 @@ int download_get_error(int download_id, download_error_e *error)
 {
        int errorcode = 0;
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (error == NULL) {
                TRACE_ERROR("Parameter NULL Check");
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
@@ -366,6 +342,7 @@ int download_get_error(int download_id, download_error_e *error)
 int download_get_http_status(int download_id, int *http_status)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (http_status == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_http_status(download_id, http_status);
@@ -374,6 +351,7 @@ int download_get_http_status(int download_id, int *http_status)
 int download_set_notification_app_control(int download_id, download_notification_app_control_type_e type, app_control_h handle)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (handle == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_notification_service_handle(download_id, (int)type, handle);
@@ -382,14 +360,16 @@ int download_set_notification_app_control(int download_id, download_notification
 int download_get_notification_app_control(int download_id, download_notification_app_control_type_e type, app_control_h *handle)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (handle == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
-       return dp_interface_get_notification_service_handle(download_id, (int)type, handle);
+       return dp_interface_get_notification_service_handle(download_id, (int)type, (void **)handle);
 }
 
 int download_set_notification_title(int download_id, const char *title)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (title == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_notification_title(download_id, title);
@@ -398,6 +378,7 @@ int download_set_notification_title(int download_id, const char *title)
 int download_get_notification_title(int download_id, char **title)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (title == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_notification_title(download_id, title);
@@ -406,6 +387,7 @@ int download_get_notification_title(int download_id, char **title)
 int download_set_notification_description(int download_id, const char *description)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (description == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_notification_description(download_id, description);
@@ -414,6 +396,7 @@ int download_set_notification_description(int download_id, const char *descripti
 int download_get_notification_description(int download_id, char **description)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (description == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_notification_description(download_id, description);
@@ -422,6 +405,7 @@ int download_get_notification_description(int download_id, char **description)
 int download_set_notification_type(int download_id, download_notification_type_e type)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_set_notification_type(download_id, (int)type);
 }
 
@@ -429,6 +413,7 @@ int download_get_notification_type(int download_id, download_notification_type_e
 {
        int noti_type = 0;
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (type == NULL) {
                TRACE_ERROR("Parameter NULL Check");
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
@@ -442,6 +427,7 @@ int download_get_notification_type(int download_id, download_notification_type_e
 int download_get_etag(int download_id, char **etag)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (etag == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_get_etag(download_id, etag);
@@ -450,7 +436,15 @@ int download_get_etag(int download_id, char **etag)
 int download_set_temp_file_path(int download_id, char *path)
 {
        TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        if (path == NULL)
                return DOWNLOAD_ERROR_INVALID_PARAMETER;
        return dp_interface_set_temp_file_path(download_id, path);
 }
+
+int download_set_verify_host(int download_id, bool enable)
+{
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       return dp_interface_set_verify_host(download_id, (int)enable);
+}