From: amit.dhiman Date: Tue, 18 Feb 2014 07:13:20 +0000 (+0530) Subject: Updated source code from tizen 2.2.1 git branch X-Git-Tag: accepted/tizen/common/20140429.091538~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d36436c54b2c0c0aef8f9a60d484d7daca85bd76;p=platform%2Fcore%2Fapi%2Furl-download.git Updated source code from tizen 2.2.1 git branch [customer] OPEN [issue#] N/A [problem] Updated the source code by using base of tizen 2.2.1 git branch [cause] N/A [solution] N/A Change-Id: I79facc02c20e59138288312143338c0ecb497f5a Signed-off-by: amit.dhiman --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8254b93..e0003a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ INCLUDE_DIRECTORIES(${INC_DIR}) SET(requires "dlog capi-base-common download-provider-interface") MESSAGE(STATUS "PACKAGES : ${requires}") -SET(pc_requires "capi-base-common capi-appfw-application") +SET(pc_requires "capi-base-common bundle") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${requires}) @@ -22,7 +22,7 @@ FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") IF("${ARCH}" STREQUAL "arm") @@ -44,12 +44,8 @@ SET_TARGET_PROPERTIES(${fw_name} PROPERTIES VERSION ${VERSION}) SET_TARGET_PROPERTIES(${fw_name} PROPERTIES SOVERSION ${VERSION_MAJOR}) INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) -INSTALL( - DIRECTORY ${INC_DIR}/ DESTINATION include/web - FILES_MATCHING - PATTERN "*_private.h" EXCLUDE - PATTERN "${INC_DIR}/*.h" - ) +INSTALL(FILES ${INC_DIR}/download.h DESTINATION include/web/) +INSTALL(FILES ${INC_DIR}/download_doc.h DESTINATION include/web/) SET(PC_NAME ${fw_name}) SET(PC_REQUIRED ${pc_requires}) @@ -73,10 +69,10 @@ IF(UNIX) ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) ADD_CUSTOM_COMMAND( - DEPENDS clean + DEPENDS clean COMMENT "distribution clean" COMMAND find - ARGS . + ARGS . -not -name config.cmake -and \( -name tester.c -or -name Testing -or diff --git a/capi-web-url-download.manifest b/capi-web-url-download.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/capi-web-url-download.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/include/download.h b/include/download.h index a893cc9..a3c4f7d 100755 --- a/include/download.h +++ b/include/download.h @@ -18,6 +18,11 @@ #define __TIZEN_WEB_DOWNLOAD_H__ #include +#include + +#ifndef DEPRECATED + #define DEPRECATED __attribute__((deprecated)) +#endif #ifdef __cplusplus extern "C" @@ -30,11 +35,6 @@ extern "C" */ /** - * @brief Name for download service operation. Download Manager application is launched. - */ -#define SERVICE_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download" - -/** * @brief Enumeration of error code for URL download */ typedef enum @@ -46,6 +46,7 @@ typedef enum DOWNLOAD_ERROR_CONNECTION_TIMED_OUT = TIZEN_ERROR_CONNECTION_TIME_OUT, /**< Http session time-out */ DOWNLOAD_ERROR_NO_SPACE = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE, /**< No space left on device */ DOWNLOAD_ERROR_FIELD_NOT_FOUND = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Specified field not found */ + DOWNLOAD_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ DOWNLOAD_ERROR_INVALID_STATE = TIZEN_ERROR_WEB_CLASS | 0x21, /**< Invalid state */ DOWNLOAD_ERROR_CONNECTION_FAILED = TIZEN_ERROR_WEB_CLASS | 0x22, /**< Connection failed */ DOWNLOAD_ERROR_INVALID_URL = TIZEN_ERROR_WEB_CLASS | 0x24, /**< Invalid URL */ @@ -87,13 +88,39 @@ typedef enum typedef enum { DOWNLOAD_NETWORK_DATA_NETWORK, /**< Download is available through data network */ - DOWNLOAD_NETWORK_WIFI, /**< Download is available through Wi-Fi */ + DOWNLOAD_NETWORK_WIFI, /**< Download is available through WiFi */ DOWNLOAD_NETWORK_WIFI_DIRECT, /**< Download is available through WiFi-Direct */ - DOWNLOAD_NETWORK_ALL /**< Download is available through either data network or Wi-Fi */ + DOWNLOAD_NETWORK_ALL /**< Download is available through either data network or WiFi */ } download_network_type_e ; /** + * @brief Enumerations of notification type when client want to register + * @see #download_set_notification_type() + * @see #download_get_notification_type() + */ +typedef enum +{ + DOWNLOAD_NOTIFICATION_TYPE_NONE = 0, /**< Do not register notification */ + DOWNLOAD_NOTIFICATION_TYPE_COMPLETE_ONLY, /**< For success state and failed state */ + DOWNLOAD_NOTIFICATION_TYPE_ALL /**< For ongoing state, success state and failed state */ +} download_notification_type_e; + + +/** + * @brief Enumerations of the type about notification bundle which client want to set when registering notification + * @see #download_set_notification_bundle() + * @see #download_get_notification_bundle() + */ +typedef enum +{ + DOWNLOAD_NOTIFICATION_BUNDLE_TYPE_ONGOING = 0, /**< For bundle for failed and ongoing notification */ + DOWNLOAD_NOTIFICATION_BUNDLE_TYPE_COMPLETE, /**< For bundle for completed notification */ + DOWNLOAD_NOTIFICATION_BUNDLE_TYPE_FAILED /**< For bundle for failed notification*/ +} download_notification_bundle_type_e; + + +/** * @brief Called when the download status is changed. * * @param [in] download The download id @@ -123,15 +150,14 @@ typedef void (*download_progress_cb) (int download_id, unsigned long long receiv /** * @brief Creates a download id. * - * @remarks The @a download must be released with download_destroy() by you.\n - * The g_type_init() should be called when creating a main loop by user side. \n - * Because the libsoup, which is http stack library of download module, use gobject internally. + * @remarks The @a download is released with download_destroy() by client.\n * @param [out] download A download id to be newly created on success * @return 0 on success, otherwise a negative error value. * @retval #DOWNLOAD_ERROR_NONE Successful * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DOWNLOAD_ERROR_OUT_OF_MEMORY Out of memory * @retval #DOWNLOAD_ERROR_IO_ERROR Internal I/O error + * @retval #DOWNLOAD_ERROR_QUEUE_FULL Full of queue from download server * @post The download state will be #DOWNLOAD_STATE_READY * @see download_destroy() */ @@ -210,7 +236,7 @@ int download_set_network_type(int download_id, download_network_type_e net_type) /** - * @brief Gets the netowork type for the downloaded file + * @brief Gets the network type for the downloaded file * * @param [in] download The download id * @param [out] net_type The network type which is defined by client. @@ -288,7 +314,7 @@ int download_set_file_name(int download_id, const char *file_name); /** * @brief Gets the name which is set by user. * - * @details If user do not set any name, it retruns NULL. + * @details If user do not set any name, it returns NULL. * * @remarks The @a file_name must be released with free() by you. * @param [in] download The download id @@ -305,12 +331,12 @@ int download_get_file_name(int download_id, char **file_name); /** * @brief Sets the option value to register notification messages by download service module. - * @details The tree types of notification message can be posted. Those are completion, failed and ongoing type. + * @details The three types of notification message can be posted. Those are completion, failed and ongoing type. * When the notification message of failed and ongoing types from the notification tray, \n * the client application which call this API will be launched. \n * * @remarks The extra param should be set together (See download_set_notification_extra_param()). \n - * The downloading and failed notification can be registerd only if the extra param for noticiation message is set. \n + * The downloading and failed notification can be registered only if the extra param for notification message is set. \n * If it is not, the client application can not know who request to launch itself. \n * It should be necessary to understand the action operation of notification click event. * @remarks If the competition notification message is selected from the notification tray,\n @@ -326,24 +352,40 @@ int download_get_file_name(int download_id, char **file_name); * @pre The state must be #DOWNLOAD_STATE_READY, #DOWNLOAD_STATE_FAILED, #DOWNLOAD_STATE_CANCELED * @see download_get_notification() * @see service_get_operation() + * @deprecated This API can be replaced with download_set_notification_type() + @code + int ret = 0; + //ret = download_set_notification(id, true); + ret = download_set_notification_type(id, DOWNLOAD_NOTIFICATION_TYPE_ALL); + //ret = download_set_notification(id, false); + ret = download_set_notification_type(id, DOWNLOAD_NOTIFICATION_TYPE_NONE); + @endcode */ -int download_set_notification(int download_id, bool enable); +DEPRECATED int download_set_notification(int download_id, bool enable); /** * @brief Gets the option value to register notification messages by download service module. * @param[in] download The download id - * @param[out] enable The boolean type. The true or false value is retruned + * @param[out] enable The boolean type. The true or false value is returned * @return 0 on success, otherwise a negative error value. * @retval #DOWNLOAD_ERROR_NONE Successful * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID * @see download_set_notification() + * @deprecated This API can be replaced with download_get_notification_type() + @code + int ret = 0; + bool val = 0; + download_notification_type_e type; + //ret = download_get_notification(id, &val); + ret = download_get_notification_type(id, &type); + @endcode */ -int download_get_notification(int download_id, bool *enable); +DEPRECATED int download_get_notification(int download_id, bool *enable); /** * @brief Sets the extra param data which pass by application service data when notification message is clicked - * @details When client set the extra param data for ongoing notificaiton action, \n + * @details When client set the extra param data for ongoing notification action, \n * it can get the data through service_get_extra_data() when client application is launched by notification action. * * @remarks This function should be called before downloading (See download_start()) @@ -358,8 +400,21 @@ int download_get_notification(int download_id, bool *enable); * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID * @see download_get_notification_extra_param() * @see download_remove_notification_extra_param() - */ -int download_add_notification_extra_param(int download_id, const char *key, const char **values, const unsigned int length); + * @deprecated This API can be replaced with download_set_notification_bundle() + @code + #include + int ret = 0; + // char *value[1] = ("12345",}; + //ret = download_add_notification_extra_param(id, "specific_id", value[0], 1); + bundle *b = bundle_create(); + char buff[MAX_BUF_LEN] = {0,}; + appsvc_set_pkgname(b, "com.samsung.test-app"); + appsvc_add_data(b, "specific_id", "12345"); + ret = download_set_notification_bundle(id, DOWNLOAD_NOTIFICATION_BUNDLE_TYPE_ALL, b); + bundle_free(b); + @endcode + */ +DEPRECATED int download_add_notification_extra_param(int download_id, const char *key, const char **values, const unsigned int length); /** * @brief Remove the extra param data which pass by application service data when notification message is clicked @@ -375,7 +430,7 @@ int download_add_notification_extra_param(int download_id, const char *key, cons * @see download_add_notification_extra_param() * @see download_get_notification_extra_param() */ -int download_remove_notification_extra_param(int download_id, const char *key); +DEPRECATED int download_remove_notification_extra_param(int download_id, const char *key); /** * @brief Gets the extra param value to set by download_set_notification_extra_param @@ -389,7 +444,7 @@ int download_remove_notification_extra_param(int download_id, const char *key); * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID * @see download_set_notification_extra_param() */ -int download_get_notification_extra_param(int download_id, const char *key, char ***values, unsigned int *length); +DEPRECATED int download_get_notification_extra_param(int download_id, const char *key, char ***values, unsigned int *length); /** * @brief Gets the absolute path to save the downloaded file @@ -438,14 +493,14 @@ int download_get_mime_type(int download_id, char **mime_type); * If it is not, user do not receive the download result in case the client process is not alive. * @remarks The default value is false. * @param[in] download The download id - * @param[in] enable The boolean value for auto download which is defined by clinet. + * @param[in] enable The boolean value for auto download which is defined by client. * @return 0 on success, otherwise a negative error value. * @retval #DOWNLOAD_ERROR_NONE Successful * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID * @pre The state must be #DOWNLOAD_STATE_READY, #DOWNLOAD_STATE_FAILED, #DOWNLOAD_STATE_CANCELED * @see download_get_auto_download() - * @see download_set_ongoing_notification() + * @see download_set_notification() * @see download_set_notification_extra_param() * */ @@ -456,7 +511,7 @@ int download_set_auto_download(int download_id, bool enable); * @brief Gets the value of option for auto download. * * @param [in] download The download id - * @param [out] enable The boolean value for auto download which is defined by clinet. + * @param [out] enable The boolean value for auto download which is defined by client. * @return 0 on success, otherwise a negative error value. * @retval #DOWNLOAD_ERROR_NONE Successful * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter @@ -637,6 +692,7 @@ int download_unset_progress_cb(int download_id); * @retval #DOWNLOAD_ERROR_URL Invalid URL * @retval #DOWNLOAD_ERROR_DESTINATION Invalid destination * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @retval #DOWNLOAD_ERROR_QUEUE_FULL Full of queue from download server * @pre The download state must be #DOWNLOAD_STATE_READY, #DOWNLOAD_STATE_PAUSED, #DOWNLOAD_STATE_CANCELED, #DOWNLOAD_STATE_FAILED. * @post The download state will be #DOWNLOAD_STATE_QUEUED or #DOWNLOAD_STATE_DOWNLOADING * @see download_set_url() @@ -670,7 +726,7 @@ int download_pause(int download_id); * @brief Cancel the download, asynchronously. * * @details This function cancels the running download and its state will be #DOWNLOAD_STATE_READY - * @remarks The cancelled download can be restarted with download_start(). + * @remarks The canceled download can be restarted with download_start(). * @param [in] download The download id * @return 0 on success, otherwise a negative error value. * @retval #DOWNLOAD_ERROR_NONE Successful @@ -720,7 +776,7 @@ int download_get_temp_path(int download_id, char **temp_path); /** * @brief Gets the content name for downloading a file. * - * @details This can be defined with referense of HTTP response header data. + * @details This can be defined with reference of HTTP response header data. * The content name can be received when HTTP response header is received. * * @param [in] download The download id @@ -792,6 +848,151 @@ int download_get_error(int download_id, download_error_e *error); int download_get_http_status(int download_id, int *http_status); /** + * @brief Sets bundle data to register notification messages. + * @details The three types of notification message can be posted. Those are completion, failed and ongoing type. + * + * @remarks When the notification message is clicked, the action is decided by bundle data. \n + * If the bundle data is not set, the following default operation is executed when the notification message is clicked. \n + * 1) Download completed state : The viewer application is executed according to extension name of downloaded content. \n + * 2) Download failed state and ongoing state : The client application is executed. \n + * @remarks This function should be called before starting download. + * @remarks The bundle data MUST BE FREED by client when it is not used any more. + * @param[in] download The download id + * @param[in] type The enumeration type. See #download_notification_bundle_type_e. + * @param[in] bundle The bundle pointer value. + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @pre The state must be #DOWNLOAD_STATE_READY, #DOWNLOAD_STATE_FAILED, #DOWNLOAD_STATE_CANCELED + * @see download_set_notification_type() + * @see download_get_notification_bundle() + */ +int download_set_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle *b); + +/** + * @brief Get the bundle data to register notification messages which is set in download_set_notification_bundle(). + * + * @details When the notification message is clicked, the action is decided by bundle data. \n + * @param[in] download The download id + * @param[in] type The enumeration type. See #download_notification_bundle_type_e. + * @param[out] bundle The bundle pointer value. + * @remarks The bundle data MUST BE FREED by client when it is not used any more. + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @retval #DOWNLOAD_ERROR_NO_DATA the bundle have not been set + * @see download_set_notification_bundle() + */ +int download_get_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle **b); + +/** + * @brief Set the title of notification. + * + * @details When registering notification, the title is displayed at title area of notification message + * + * @param [in] download The download id + * @param [in] title The title for displaying to user + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @pre If the notification option is not enable, this title is not shown to user + * @see #download_set_notification_type() + * @see #download_get_notification_title() + */ +int download_set_notification_title(int download_id, const char *title); + +/** + * @brief Gets the title of notification when set in #download_set_notification_title() + * + * @details When registering notification, the title is displayed at title area of notification message + * + * @param [in] download The download id + * @param [out] title The title for displaying to user + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @retval #DOWNLOAD_ERROR_NO_DATA the title have not been set + * @pre It can get the title value before calling this API. + * @see #download_set_notification_title() + */ +int download_get_notification_title(int download_id, char **title); + +/** + * @brief Set the description of notification. + * + * @details When registering notification, the description is displayed at description area of notification message + * + * @param [in] download The download id + * @param [in] description The description for displaying to user + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @pre If the notification option is not enable, this description is not shown to user + * @see #download_set_notification_type() + * @see #download_get_notification_description() + */ +int download_set_notification_description(int download_id, const char *description); + +/** + * @brief Gets the description of notification when set in #download_set_notification_description() + * + * @details When registering notification, the description is displayed at description area of notification message + * + * @param [in] download The download id + * @param [out] description The description for displaying to user + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @retval #DOWNLOAD_ERROR_NO_DATA the description have not been set + * @pre It can get the title value before calling this API. + * @see #download_set_notification_description() + */ +int download_get_notification_description(int download_id, char **description); + +/** + * @brief Sets the option value to register notification messages. + * @details The three types of notification message can be posted. Those are completion, failed and ongoing type. + * + * @remarks When the notification message is clicked, the action is decided by bundle data from download_set_notification_bundle(). \n + * If the bundle data is not set, the following default operation is executed when the notification message is clicked. \n + * 1) Download completed state : The viewer application is executed according to extension name of downloaded content. \n + * 2) Download failed state and ongoing state : The client application is executed. \n + * @remarks The default type is #DOWNLOAD_NOTIFICATION_TYPE_NONE. + * @remarks This function should be called before starting download. + * @param[in] download The download id + * @param[in] type The enumeration type. See #download_notification_type_e. + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @pre The state must be #DOWNLOAD_STATE_READY, #DOWNLOAD_STATE_FAILED, #DOWNLOAD_STATE_CANCELED + * @see download_set_notification_bundle() + * @see download_get_notification_type() + */ +int download_set_notification_type(int download_id, download_notification_type_e type); + +/** + * @brief Get the option value to register notification messages which is set in download_set_notification_type(). + * + * @remarks When the notification message is clicked, the action is decided by bundle data from download_set_notification_bundle(). \n + * @remarks The default type is #DOWNLOAD_NOTIFICATION_TYPE_NONE. + * @param[in] download The download id + * @param[out] type The enumeration type. See #download_notification_type_e. + * @return 0 on success, otherwise a negative error value. + * @retval #DOWNLOAD_ERROR_NONE Successful + * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND No Download ID + * @see download_set_notification_type() + */ +int download_get_notification_type(int download_id, download_notification_type_e *type); + +/** * @} */ diff --git a/include/download_doc.h b/include/download_doc.h new file mode 100755 index 0000000..13ab995 --- /dev/null +++ b/include/download_doc.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __TIZEN_WEB_DOWNLOAD_DOC_H__ +#define __TIZEN_WEB_DOWNLOAD_DOC_H__ + +/** + * @ingroup CAPI_WEB_FRAMEWORK + * @defgroup CAPI_WEB_DOWNLOAD_MODULE Download + * @brief The DOWNLOAD API provides functions to create and manage one or more download requests. + * + * @section CAPI_WEB_DOWNLOAD_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_WEB_DOWNLOAD_MODULE_OVERVIEW Overview + * The DOWNLOAD API provides functions to create and manage one or more download requests. + * + * Major features : + * - After getting download_id from download_create(), other APIs use download_id as parameter. + * - Even if the device is off, download_id is available for 48 hours if user did't call download_destroy(). + * - support the callback that called whenever changed the status of download. + * - Even if the client process is terminated, download is going on. + * If wanna stop a download, download_cancel() or download_destroy() should be called. + * + */ + +#endif /* __TIZEN_WEB_DOWNLOAD_DOC_H__ */ diff --git a/packaging/capi-web-url-download.changes b/packaging/capi-web-url-download.changes deleted file mode 100644 index e81d9c4..0000000 --- a/packaging/capi-web-url-download.changes +++ /dev/null @@ -1,173 +0,0 @@ -* Tue May 21 2013 Rusty Lynch accepted/tizen/20130520.100838@80b0e2a -- fix rpmlint errors - -* Tue May 7 2013 Kwangmin Bang -- add new network type (DOWNLOAD_NETWORK_WIFI_DIRECT) - -* Tue Mar 19 2013 Kwangmin Bang -- new API : download_get_http_header_field_list - -* Tue Mar 05 2013 Jungki Kwak -- Changes APIs for notification extra list -- Use download-provider-interface library - -* Sat Feb 23 2013 Kwangmin Bang -- do not close the socket in Interrupted System Call - -* Mon Feb 18 2013 Kwangmin Bang -- use invalid pointer -- return wrong state in _download_change_dp_state() - -* Thu Jan 31 2013 Kwangmin Bang -- support new state of provider - -* Tue Jan 29 2013 Jungki Kwak -- Check invalid download id when set the callback -- Create new slot when set callback for the request exist only in provider - -* Mon Jan 28 2013 Kwangmin Bang -- simple launch provider without dbus interface -- Modify the name of license and add notice file -- refer wrong address after free - -* Tue Jan 08 2013 Jungki Kwak -- Update doxygen comments -- Add soversion to shared library file -- Remove unnecessary dependency and configuration -- Removed deprecated APIs - -* Fri Dec 21 2012 Kwangmin Bang -- Remove duplicated dlog message -- Modify license information at spec file -- Support ECHO command - -* Fri Dec 14 2012 Kwangmin Bang -- Resolve prevent defect -- Remove old source codes -- Add missed boiler plate -- the limitation of the number of download ID which can be created at same time -- Update comments about state -- Update comments - -* Fri Nov 30 2012 Kwangmin Bang -- support DBUS-activation -- [Prevent Defect] The same expression occurs on both sides of an operator - -* Tue Nov 27 2012 Jungki Kwak -- Remove deprecated APIs -- Add an error code about download id -- Change the name of notification API -- Add APIs for notification extra param -- Update comments and add some error code - -* Fri Nov 16 2012 Jungki Kwak -- Three APIs will be deprecated -- Operands don't affect result -- Add new CAPIs to register notification message -- Add to add, get and remove http header values -- Modify comments for getting file name -- send pid from client when no support SO_PEERCRED - -* Thu Nov 01 2012 Kwangmin Bang -- prevent duplicated event thread -- print dlog message with thread id -- enhance mutex for event thread - -* Wed Oct 31 2012 Jungki Kwak -- enhance mutex for event thread - -* Mon Oct 29 2012 Kwangmin Bang -- fix the defects found by prevent tool -- Thread Safe APIs -- increase the timeout of socket -- do not disconnect socket in case of timeout - -* Thu Oct 24 2012 Kwangmin Bang -- fix prevent defects -- Remove TCs about removed API -- arrange the usage of mutex for IPC - -* Tue Oct 23 2012 Kwangmin Bang -- check IPC connection at the head of All APIs -- use write API instead of send API -- apply sending timeout for socket - -* Mon Oct 22 2012 Jungki Kwak -- Resolve the lockup when client app is crashed -- Prevent the crash by calling url_download_destory twice -- Remove memory leak code by fixing of clients - -* Fri Oct 19 2012 Kwangmin Bang -- wrapping Handle based CAPI to ID based CAPI -- Call the progress callback when total size of the content is zero. - -* Fri Oct 12 2012 Jungki Kwak -- Fix the crash when clear invalid socket from FD_SET -- Install LICENSE file. - -* Fri Sep 21 2012 Jungki Kwak -- Apply a default manifest file. - -* Mon Sep 18 2012 Kwangmin Bang -- fix the crash by referring invalid handle -- Add function to release headers -- Add exception code when fail to reconnect socket -- add license -- fix the error and warning of spec file - -* Fri Sep 07 2012 Kwangmin Bang -- fix timeout thread can run exactly - -* Thu Sep 06 2012 Kwangmin Bang -- check the state before clear socket -- add limitation in already completed state -- add checking INVALID_STATE error - -* Tue Sep 04 2012 Jungki Kwak -- Remove unused code which is base on libdownload-agent -- Change the name of application operation -- Add exception handling for non requestid -- Call clear_provider after getting the state -- url_download_get_state return IO error -- Resolve prevent defects - -* Mon Sep 03 2012 Kwangmin Bang -- stop the download even if no socket or callback -- pause/resume the download even if no socket or callback -- calling stopped callback in error case -- request STOP for free after finished download - -* Thu Aug 30 2012 Kwangmin Bang -- maxfd should be updated before created event thread - -* Thu Aug 30 2012 Kwangmin Bang -- remove duplicated call for creating socket -- fix the crash regarding pthread_kill -- allow to call url_download_stop in case of PAUSED state - -* Mon Aug 27 2012 Kwangmin Bang -- one thread model for event -- get state info from download-provider even if no connection -- fix the bug take a long time to receive first event - -* Tue Aug 22 2012 Jungki Kwak -- Enhance the exception handling in event thread -- Resolve a bug about state -- Add to pass service handle data to download daemon - -* Mon Aug 17 2012 Jungki Kwak -- Resolve a bug when getting a state -- Add error case for invalid id - -* Mon Aug 16 2012 Jungki Kwak -- Add new APIs for notification function -- The TC is changed due to change of url_download_start -- When unseting the callback function, the callback should be initialized although the error is happened. -- It remove the stop function when is called twice when destroying handle -- Add pc requries for app.h - -* Mon Aug 08 2012 Jungki Kwak -- Change requestid to INTEGER from String - -* Mon Aug 06 2012 Jungki Kwak -- The base model is changed to download provider daemon diff --git a/packaging/capi-web-url-download.manifest b/packaging/capi-web-url-download.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/capi-web-url-download.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/capi-web-url-download.spec b/packaging/capi-web-url-download.spec index 62f84fc..335c3cc 100755 --- a/packaging/capi-web-url-download.spec +++ b/packaging/capi-web-url-download.spec @@ -1,15 +1,15 @@ Name: capi-web-url-download Summary: CAPI for content download with web url -Version: 1.0.2 -Release: 5 +Version: 1.1.1 +Release: 0 Group: Development/Libraries License: Apache License, Version 2.0 URL: https://review.tizen.org/git/?p=platform/core/api/url-download.git;a=summary Source0: %{name}-%{version}.tar.gz -Source1001: capi-web-url-download.manifest BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(download-provider-interface) BuildRequires: cmake @@ -26,9 +26,13 @@ CAPI for content downloading with web url (development files) %prep %setup -q -cp %{SOURCE1001} . %build +%if 0%{?tizen_build_binary_release_type_eng} +export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE" +export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE" +%endif %cmake . make %{?jobs:-j%jobs} @@ -43,15 +47,17 @@ mkdir -p %{buildroot}/usr/share/license %postun -p /sbin/ldconfig %files -%manifest %{name}.manifest %defattr(-,root,root,-) +%manifest capi-web-url-download.manifest %{_libdir}/libcapi-web-url-download.so.* /usr/share/license/%{name} %files devel -%manifest %{name}.manifest %defattr(-,root,root,-) %manifest capi-web-url-download.manifest %{_libdir}/libcapi-web-url-download.so %{_libdir}/pkgconfig/capi-web-url-download.pc %{_includedir}/web/download.h +%{_includedir}/web/download_doc.h + +%changelog diff --git a/src/download-wrapping.c b/src/download-wrapping.c index 94b7fd2..d309120 100755 --- a/src/download-wrapping.c +++ b/src/download-wrapping.c @@ -93,6 +93,10 @@ int download_get_network_type(int download_id, { TRACE_INFO(""); + if (net_type == NULL) { + TRACE_ERROR("Parameter NULL Check"); + return DOWNLOAD_ERROR_INVALID_PARAMETER; + } int network_type = DOWNLOAD_ADAPTOR_NETWORK_ALL; int ret = dp_interface_get_network_type(download_id, &network_type); if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE) @@ -125,27 +129,20 @@ int download_get_file_name(int download_id, char **file_name) return dp_interface_get_file_name(download_id, file_name); } -int download_set_ongoing_notification(int download_id, bool enable) -{ - return download_set_notification(download_id, enable); -} - int download_set_notification(int download_id, bool enable) { TRACE_INFO(""); return dp_interface_set_notification(download_id, (int)enable); } -int download_get_ongoing_notification(int download_id, bool *enable) -{ - return download_get_notification(download_id, enable); -} - int download_get_notification(int download_id, bool *enable) { int is_set = 0; - TRACE_INFO(""); + if (enable == NULL) { + TRACE_ERROR("Parameter NULL Check"); + return DOWNLOAD_ERROR_INVALID_PARAMETER; + } int ret = dp_interface_get_notification(download_id, &is_set); if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE) *enable = (bool)is_set; @@ -244,8 +241,11 @@ int download_unset_progress_cb(int download_id) int download_get_state(int download_id, download_state_e *state) { int statecode = 0; - TRACE_INFO(""); + if (state == NULL) { + TRACE_ERROR("Parameter NULL Check"); + return DOWNLOAD_ERROR_INVALID_PARAMETER; + } int ret = dp_interface_get_state(download_id, &statecode); if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE) *state = statecode; @@ -286,8 +286,11 @@ int download_set_auto_download(int download_id, bool enable) int download_get_auto_download(int download_id, bool *enable) { int is_set = 0; - TRACE_INFO(""); + if (enable == NULL) { + TRACE_ERROR("Parameter NULL Check"); + return DOWNLOAD_ERROR_INVALID_PARAMETER; + } int ret = dp_interface_get_auto_download(download_id, &is_set); if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE) *enable = (bool)is_set; @@ -297,8 +300,11 @@ int download_get_auto_download(int download_id, bool *enable) int download_get_error(int download_id, download_error_e *error) { int errorcode = 0; - TRACE_INFO(""); + if (error == NULL) { + TRACE_ERROR("Parameter NULL Check"); + return DOWNLOAD_ERROR_INVALID_PARAMETER; + } int ret = dp_interface_get_error(download_id, &errorcode); if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE) *error = errorcode; @@ -311,3 +317,59 @@ int download_get_http_status(int download_id, int *http_status) return dp_interface_get_http_status(download_id, http_status); } +int download_set_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle *b) +{ + TRACE_INFO(""); + return dp_interface_set_notification_bundle(download_id, (int)type, b); +} + +int download_get_notification_bundle(int download_id, download_notification_bundle_type_e type, bundle **b) +{ + TRACE_INFO(""); + return dp_interface_get_notification_bundle(download_id, (int)type, b); +} + +int download_set_notification_title(int download_id, const char *title) +{ + TRACE_INFO(""); + return dp_interface_set_notification_title(download_id, title); +} + +int download_get_notification_title(int download_id, char **title) +{ + TRACE_INFO(""); + return dp_interface_get_notification_title(download_id, title); +} + +int download_set_notification_description(int download_id, const char *description) +{ + TRACE_INFO(""); + return dp_interface_set_notification_description(download_id, description); +} + +int download_get_notification_description(int download_id, char **description) +{ + TRACE_INFO(""); + return dp_interface_get_notification_description(download_id, description); +} + +int download_set_notification_type(int download_id, download_notification_type_e type) +{ + TRACE_INFO(""); + return dp_interface_set_notification_type(download_id, (int)type); +} + +int download_get_notification_type(int download_id, download_notification_type_e *type) +{ + int noti_type = 0; + TRACE_INFO(""); + if (type == NULL) { + TRACE_ERROR("Parameter NULL Check"); + return DOWNLOAD_ERROR_INVALID_PARAMETER; + } + int ret = dp_interface_get_notification_type(download_id, ¬i_type); + if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE) + *type = (download_notification_type_e)noti_type; + return ret; +} + diff --git a/src/download.c b/src/download.c deleted file mode 100755 index 47cca05..0000000 --- a/src/download.c +++ /dev/null @@ -1,2790 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#ifdef DP_DBUS_ACTIVATION -#include -#endif - -#ifdef DP_ECHO_TEST -#include -#endif - -#define DP_CHECK_PROVIDER_STATUS do {\ - if (__check_ipc_status(g_download_ipc->cmd_socket) < 0) {\ - pthread_mutex_unlock((&g_download_ipc->mutex));\ - pthread_mutex_unlock(&g_download_mutex);\ - if (errno != EAGAIN && errno != EINTR)\ - _disconnect_from_provider();\ - return DOWNLOAD_ERROR_IO_ERROR;\ - }\ -} while(0) - -#define MAX_DOWNLOAD_HANDLE 5 - -#define DEBUG_MSG -//#define DEBUG_PRINTF - -#ifdef DEBUG_MSG -#ifdef DEBUG_PRINTF -#include -#define TRACE_ERROR(format, ARG...) \ -{ \ -fprintf(stderr,"[URL_DOWNLOAD][%s:%d] "format"\n", __FUNCTION__, __LINE__, ##ARG); \ -} -#define TRACE_STRERROR(format, ARG...) \ -{ \ -fprintf(stderr,"[URL_DOWNLOAD][%s:%d] "format" [%s]\n", __FUNCTION__, __LINE__, ##ARG, strerror(errno)); \ -} -#define TRACE_INFO(format, ARG...) \ -{ \ -fprintf(stderr,"[URL_DOWNLOAD][%s:%d] "format"\n", __FUNCTION__, __LINE__, ##ARG); \ -} -#else -#include -#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); \ -} -#endif -#else -#define TRACE_DEBUG_MSG(format, ARG...) ; -#endif - -// define type -typedef struct { - // send command * get return value. - int cmd_socket; - // getting event from download-provider - int event_socket; - pthread_mutex_t mutex; // lock before using, unlock after using -} download_ipc_info; - -typedef struct { - download_state_changed_cb state; - void *state_user_data; - download_progress_cb progress; - void *progress_user_data; -} download_cb_info; - -typedef struct { - int id; - download_cb_info callback; -} download_slots; - -typedef struct { - int index; - dp_event_info *event; -} download_event_info; - -// declare the variables -download_ipc_info *g_download_ipc = NULL; -download_slots g_download_slots[MAX_DOWNLOAD_HANDLE]; -static pthread_mutex_t g_download_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_t g_download_event_thread_pid = 0; - -#ifdef DP_DBUS_ACTIVATION -/* DBUS Activation */ -static int _launch_download_provider_service(void) -{ - DBusConnection *connection = NULL; - DBusError dbus_error; - - dbus_error_init(&dbus_error); - - connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error); - if (connection == NULL) { - TRACE_ERROR("[ERROR] dbus_bus_get"); - if (dbus_error_is_set(&dbus_error)) { - TRACE_ERROR("[DBUS] dbus_bus_get: %s", dbus_error.message); - dbus_error_free(&dbus_error); - } - return -1; - } - - dbus_uint32_t result = 0; - if (dbus_bus_start_service_by_name - (connection, - DP_DBUS_SERVICE_DBUS, 0, &result, &dbus_error) == FALSE) { - if (dbus_error_is_set(&dbus_error)) { - TRACE_ERROR("[DBUS] dbus_bus_start_service_by_name: %s", - dbus_error.message); - dbus_error_free(&dbus_error); - } - dbus_connection_unref(connection); - return -1; - } - if (result == DBUS_START_REPLY_ALREADY_RUNNING) { - TRACE_INFO("DBUS_START_REPLY_ALREADY_RUNNING [%d]", result); - } else if (result == DBUS_START_REPLY_SUCCESS) { - TRACE_INFO("DBUS_START_REPLY_SUCCESS [%d]", result); - } - dbus_connection_unref(connection); - return 0; -} -#endif - -//////////// defines functions ///////////////// - -int _download_change_dp_errorcode(int errorcode) -{ - switch (errorcode) - { - case DP_ERROR_NONE : - return DOWNLOAD_ERROR_NONE; - case DP_ERROR_INVALID_PARAMETER : - return DOWNLOAD_ERROR_INVALID_PARAMETER; - case DP_ERROR_OUT_OF_MEMORY : - return DOWNLOAD_ERROR_OUT_OF_MEMORY; - case DP_ERROR_IO_ERROR : - return DOWNLOAD_ERROR_IO_ERROR; - case DP_ERROR_NETWORK_UNREACHABLE : - return DOWNLOAD_ERROR_NETWORK_UNREACHABLE; - case DP_ERROR_NO_SPACE : - return DOWNLOAD_ERROR_NO_SPACE; - case DP_ERROR_FIELD_NOT_FOUND : - return DOWNLOAD_ERROR_FIELD_NOT_FOUND; - case DP_ERROR_INVALID_STATE : - return DOWNLOAD_ERROR_INVALID_STATE; - case DP_ERROR_CONNECTION_FAILED : - return DOWNLOAD_ERROR_CONNECTION_TIMED_OUT; - case DP_ERROR_INVALID_URL : - return DOWNLOAD_ERROR_INVALID_URL; - case DP_ERROR_INVALID_DESTINATION : - return DOWNLOAD_ERROR_INVALID_DESTINATION; - case DP_ERROR_QUEUE_FULL : - return DOWNLOAD_ERROR_QUEUE_FULL; - case DP_ERROR_ALREADY_COMPLETED : - return DOWNLOAD_ERROR_ALREADY_COMPLETED; - case DP_ERROR_FILE_ALREADY_EXISTS : - return DOWNLOAD_ERROR_FILE_ALREADY_EXISTS; - case DP_ERROR_TOO_MANY_DOWNLOADS : - return DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS; - case DP_ERROR_NO_DATA : - return DOWNLOAD_ERROR_NO_DATA; - case DP_ERROR_UNHANDLED_HTTP_CODE : - return DOWNLOAD_ERROR_UNHANDLED_HTTP_CODE; - case DP_ERROR_CANNOT_RESUME : - return DOWNLOAD_ERROR_CANNOT_RESUME; - case DP_ERROR_ID_NOT_FOUND : - return DOWNLOAD_ERROR_ID_NOT_FOUND; - case DP_ERROR_UNKNOWN : - return DOWNLOAD_ERROR_INVALID_STATE; - default: - break; - } - return DOWNLOAD_ERROR_NONE; -} - -int _download_change_dp_state(int state) -{ - switch (state) - { - case DP_STATE_READY: - return DOWNLOAD_STATE_READY; - case DP_STATE_CONNECTING: - return DOWNLOAD_STATE_QUEUED; - case DP_STATE_QUEUED : - return DOWNLOAD_STATE_QUEUED; - case DP_STATE_DOWNLOADING: - return DOWNLOAD_STATE_DOWNLOADING; - case DP_STATE_PAUSE_REQUESTED : - return DOWNLOAD_STATE_DOWNLOADING; - case DP_STATE_PAUSED : - return DOWNLOAD_STATE_PAUSED; - case DP_STATE_COMPLETED : - return DOWNLOAD_STATE_COMPLETED; - case DP_STATE_CANCELED : - return DOWNLOAD_STATE_CANCELED; - case DP_STATE_FAILED : - return DOWNLOAD_STATE_FAILED; - default: - break; - } - return DOWNLOAD_STATE_NONE; -} - -void _download_print_str_state(int state) -{ - switch (state) - { - case DOWNLOAD_STATE_READY: - TRACE_INFO("DOWNLOAD_STATE_READY"); - break; - case DOWNLOAD_STATE_DOWNLOADING: - TRACE_INFO("DOWNLOAD_STATE_DOWNLOADING"); - break; - case DOWNLOAD_STATE_QUEUED : - TRACE_INFO("DOWNLOAD_STATE_QUEUED"); - break; - case DOWNLOAD_STATE_PAUSED : - TRACE_INFO("DOWNLOAD_STATE_PAUSED"); - break; - case DOWNLOAD_STATE_COMPLETED : - TRACE_INFO("DOWNLOAD_STATE_COMPLETED"); - break; - case DOWNLOAD_STATE_CANCELED : - TRACE_INFO("DOWNLOAD_STATE_CANCELED"); - break; - case DOWNLOAD_STATE_FAILED : - TRACE_INFO("DOWNLOAD_STATE_FAILED"); - break; - default: - TRACE_INFO("Unknown state (%d)", state); - break; - } -} - -int _get_my_slot_index(int download_id) -{ - int i = 0; - // search same info in array. - for (; i < MAX_DOWNLOAD_HANDLE; i++) - if (g_download_slots[i].id == download_id) - return i; - return -1; -} - -int _get_empty_slot_index() -{ - int i = 0; - for (; i < MAX_DOWNLOAD_HANDLE; i++) - if (g_download_slots[i].id <= 0) - return i; - return -1; -} - -int _ipc_read_custom_type(int fd, void *value, size_t type_size) -{ - if (fd < 0) { - TRACE_ERROR("[CHECK SOCKET]"); - return -1; - } - - if (read(fd, value, type_size) < 0) { - TRACE_STRERROR("[CRITICAL] read"); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return -1; - } - return 0; -} - -int _download_ipc_read_int(int fd) -{ - if (fd < 0) { - TRACE_ERROR("[CHECK SOCKET]"); - return -1; - } - - int value = -1; - if (read(fd, &value, sizeof(int)) < 0) { - TRACE_STRERROR("[CRITICAL] read"); - // for debugging. - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return -1; - } - - TRACE_INFO(" %d", value); - return value; -} - -// keep the order/ unsigned , str -char* _ipc_read_string(int fd) -{ - unsigned length = 0; - char *str = NULL; - - if (fd < 0) { - TRACE_ERROR("[CHECK FD]"); - return NULL; - } - - // read flexible URL from client. - if (read(fd, &length, sizeof(unsigned)) < 0) { - TRACE_STRERROR("failed to read length [%d]", length); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return NULL; - } - if (length < 1 || length > DP_MAX_STR_LEN) { - TRACE_ERROR("[STRING LEGNTH] [%d]", length); - return NULL; - } - str = (char *)calloc((length + 1), sizeof(char)); - if (!str) { - TRACE_STRERROR("[CRITICAL] allocation"); - return NULL; - } - if (read(fd, str, length * sizeof(char)) < 0) { - TRACE_STRERROR("failed to read string"); - free(str); - str = NULL; - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return NULL; - } - str[length] = '\0'; - return str; -} - -download_error_e _download_ipc_read_return(int fd) -{ - download_error_e errorcode = DOWNLOAD_ERROR_NONE; - dp_error_type error_info = DP_ERROR_NONE; - - if (fd < 0) { - TRACE_ERROR("[CHECK SOCKET]"); - return DOWNLOAD_ERROR_IO_ERROR; - } - - if (read(fd, &error_info, sizeof(dp_error_type)) < 0) { - TRACE_STRERROR("[CRITICAL] read"); - // maybe, download-provider was crashed. - // for debugging. - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO - ("[EAGAIN] Resource temporarily unavailable errno [%d]", - errno); - } else if (errno == EINTR) { - TRACE_ERROR("[EINTR] Interrupted System Call"); - } else { - TRACE_INFO("errno [%d]", errno); - } - return DOWNLOAD_ERROR_IO_ERROR; - } - - errorcode = _download_change_dp_errorcode(error_info); - TRACE_INFO("return : %d", errorcode); - return errorcode; -} - -dp_event_info* _download_ipc_read_event(int fd) -{ - if (fd < 0) { - TRACE_ERROR("[CHECK SOCKET]"); - return NULL; - } - - dp_event_info *event = - (dp_event_info *) calloc(1, sizeof(dp_event_info)); - if (event == NULL) { - TRACE_ERROR("[CHECK ALLOCATION]"); - return NULL; - } - if (read(fd, event, sizeof(dp_event_info)) < 0) { - TRACE_STRERROR("[CRITICAL] read"); - free(event); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return NULL; - } - - TRACE_INFO("EVENT INFO (ID : %d state : %d error : %d)", - event->id, event->state, event->err); - return event; -} - -int _ipc_send_int(int fd, int value) -{ - if (fd < 0) { - TRACE_ERROR("[CHECK FD] [%d]", fd); - return -1; - } - - if (fd >= 0 && write(fd, &value, sizeof(int)) < 0) { - TRACE_STRERROR("send"); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return -1; - } - return 0; -} - -// keep the order/ unsigned , str -int _ipc_send_string(int fd, const char *str) -{ - unsigned length = 0; - - if (fd < 0) { - TRACE_ERROR("[CHECK FD]"); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (!str) { - TRACE_ERROR("[CHECK STRING]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - length = strlen(str); - if (length < 1) { - TRACE_ERROR("[CHECK LENGTH]"); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (fd >= 0 && write(fd, &length, sizeof(unsigned)) < 0) { - TRACE_STRERROR("send"); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return DOWNLOAD_ERROR_IO_ERROR; - } - if (fd >= 0 && write(fd, str, length * sizeof(char)) < 0) { - TRACE_STRERROR("send"); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return DOWNLOAD_ERROR_IO_ERROR; - } - return DOWNLOAD_ERROR_NONE; -} - -int _download_ipc_send_command(int fd, int id, dp_command_type cmd) -{ - if (fd < 0) { - TRACE_ERROR("[CHECK SOCKET]"); - return DOWNLOAD_ERROR_IO_ERROR; - } - - dp_command command; - command.id = id; - command.cmd = cmd; - if (fd >= 0 && write(fd, &command, sizeof(dp_command)) < 0) { - TRACE_STRERROR("[CRITICAL] send"); - if (errno == EPIPE) { - TRACE_INFO("[EPIPE] Broken Pipe errno [%d]", errno); - } else if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] Resource temporarily unavailable errno [%d]", errno); - } else { - TRACE_INFO("errno [%d]", errno); - } - return DOWNLOAD_ERROR_IO_ERROR; - } - return DOWNLOAD_ERROR_NONE; -} - -download_error_e _send_simple_cmd(int id, dp_command_type cmd ) -{ - TRACE_INFO(""); - - if (cmd <= DP_CMD_NONE) { - TRACE_ERROR("[CHECK COMMAND] (%d)", cmd); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, id, cmd) != DOWNLOAD_ERROR_NONE) { - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - return errorcode; -} - -int __create_socket() -{ - TRACE_INFO(""); - int sockfd = -1; - struct timeval tv_timeo = { 2, 500000 }; //2.5 second - - struct sockaddr_un clientaddr; - if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - TRACE_STRERROR("[CRITICAL] socket system error"); - return -1; - } - - if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv_timeo, - sizeof( tv_timeo ) ) < 0) { - TRACE_STRERROR("[CRITICAL] setsockopt SO_SNDTIMEO"); - close(sockfd); - return -1; - } - if (setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv_timeo, - sizeof( tv_timeo ) ) < 0) { - TRACE_STRERROR("[CRITICAL] setsockopt SO_SNDTIMEO"); - close(sockfd); - return -1; - } - - bzero(&clientaddr, sizeof clientaddr); - clientaddr.sun_family = AF_UNIX; - memset(clientaddr.sun_path, 0x00, sizeof(clientaddr.sun_path)); - strncpy(clientaddr.sun_path, DP_IPC, strlen(DP_IPC)); - clientaddr.sun_path[strlen(DP_IPC)] = '\0'; - if (connect(sockfd, - (struct sockaddr*)&clientaddr, sizeof(clientaddr)) < 0) { - close(sockfd); - return -1; - } - TRACE_INFO("sockfd [%d]", sockfd); - return sockfd; -} - -int _disconnect_from_provider() -{ - TRACE_INFO(""); - if (g_download_ipc != NULL) { - shutdown(g_download_ipc->cmd_socket, 0); - close(g_download_ipc->cmd_socket); - g_download_ipc->cmd_socket= -1; - shutdown(g_download_ipc->event_socket, 0); - close(g_download_ipc->event_socket); - g_download_ipc->event_socket = -1; - pthread_mutex_destroy((&g_download_ipc->mutex)); - free(g_download_ipc); - g_download_ipc = NULL; - - if (g_download_event_thread_pid > 0) { - TRACE_INFO("STOP event thread"); - pthread_cancel(g_download_event_thread_pid); - g_download_event_thread_pid = 0; - TRACE_INFO("OK terminate event thread"); - } - } - return DOWNLOAD_ERROR_NONE; -} - -#ifdef DP_ECHO_TEST -// clear read buffer. call in head of API before calling IPC_SEND -static void __clear_read_buffer(int fd) -{ - long i; - long unread_count; - char tmp_char; - - // FIONREAD : Returns the number of bytes immediately readable - if (ioctl(fd, FIONREAD, &unread_count) >= 0) { - if (unread_count > 0) { - TRACE_INFO("[CLEAN] garbage packet[%ld]", unread_count); - for ( i = 0; i < unread_count; i++) { - if (read(fd, &tmp_char, sizeof(char)) < 0) { - TRACE_STRERROR("[CHECK] read"); - break; - } - } - } - } -} -#endif - -// ask to provider before sending a command. -// if provider wait in some commnad, can not response immediately -// capi will wait in read block. -// after asking, call clear_read_buffer. -static int __check_ipc_status(int fd) -{ -#ifdef DP_ECHO_TEST - // echo from provider - download_error_e errorcode = _send_simple_cmd(-1, DP_CMD_ECHO); - if (errorcode != DOWNLOAD_ERROR_NONE) { - TRACE_INFO("[ECHO] [%d]", errorcode); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno == EAGAIN) { - TRACE_INFO("[EAGAIN] provider is busy"); - } else { - TRACE_INFO("[CRITICAL] Broken Socket"); - } - return -1; - } - } - __clear_read_buffer(fd); -#endif - return 0; -} - -// listen ASYNC state event, no timeout -void *_download_event_manager(void *arg) -{ - int maxfd, index; - fd_set rset, read_fdset; - dp_event_info *eventinfo = NULL; - - if (g_download_ipc == NULL || g_download_ipc->event_socket < 0) { - TRACE_STRERROR("[CRITICAL] IPC NOT ESTABILISH"); - return 0; - } - - // deferred wait to cencal until next function called. - // ex) function : select, read in this thread - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); - - TRACE_INFO("FD [%d]", g_download_ipc->event_socket); - - maxfd = g_download_ipc->event_socket; - FD_ZERO(&read_fdset); - FD_SET(g_download_ipc->event_socket, &read_fdset); - - while(g_download_ipc != NULL - && g_download_ipc->event_socket >= 0) { - rset = read_fdset; - if (select((maxfd + 1), &rset, 0, 0, 0) < 0) { - TRACE_STRERROR("[CRITICAL] select"); - break; - } - - if (g_download_event_thread_pid <=0 - || pthread_self() != g_download_event_thread_pid) { - TRACE_ERROR - ("[CRITICAL] [CHECK TID] SELF ID [%d] Global ID (%d)", - pthread_self(), g_download_event_thread_pid); - // another thread may work. just terminate - return 0; - } - - pthread_mutex_lock(&g_download_mutex); - if (g_download_ipc == NULL - || g_download_ipc->event_socket < 0) { - TRACE_ERROR("[CRITICAL] IPC BROKEN Ending Event Thread"); - pthread_mutex_unlock(&g_download_mutex); - // disconnected by main thread. just terminate - return 0; - } - - if (FD_ISSET(g_download_ipc->event_socket, &rset) > 0) { - // read state info from socket - eventinfo = - _download_ipc_read_event(g_download_ipc->event_socket); - if (!eventinfo || eventinfo->id <= 0) { - // failed to read from socket // ignore this status - if (eventinfo) - free(eventinfo); - TRACE_STRERROR("[CRITICAL] Can not read Event packet"); - pthread_mutex_unlock(&g_download_mutex); - if (errno != EAGAIN && errno != EINTR) // if not timeout. end thread - break; - continue; - } - index = _get_my_slot_index(eventinfo->id); - if (index < 0) { - TRACE_ERROR - ("[CRITICAL] not found slot for [%d]", - eventinfo->id); - free(eventinfo); - pthread_mutex_unlock(&g_download_mutex); - continue; - } - - pthread_mutex_unlock(&g_download_mutex); - - // begin protect callback sections - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - - if (eventinfo->state == DP_STATE_DOWNLOADING - && eventinfo->received_size > 0) { - if (g_download_slots[index].callback.progress) { - // progress event - TRACE_INFO("ID %d progress callback %p", - eventinfo->id, - g_download_slots[index].callback.progress ); - g_download_slots[index].callback.progress - (eventinfo->id, eventinfo->received_size, - g_download_slots[index].callback.progress_user_data); - } - } else { - if (g_download_slots[index].callback.state) { - // state event - TRACE_INFO("ID %d state callback %p", - eventinfo->id, - g_download_slots[index].callback.state ); - g_download_slots[index].callback.state - (eventinfo->id, - _download_change_dp_state(eventinfo->state), - g_download_slots[index].callback.state_user_data); - } - } - free(eventinfo); - - // end protect callback sections - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); - continue; - } - pthread_mutex_unlock(&g_download_mutex); - } // while - - FD_ZERO(&read_fdset); - - TRACE_INFO("Terminate Event Thread"); - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO("Disconnect All Connection"); - g_download_event_thread_pid = 0; // set 0 to not call pthread_cancel - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return 0; -} - - -int _connect_to_provider() -{ - TRACE_INFO(""); - if (g_download_ipc == NULL) { - #ifdef DP_DBUS_ACTIVATION - if (_launch_download_provider_service() < 0) { - TRACE_ERROR("[DBUS IO] _launch_download_provider_service"); - return DOWNLOAD_ERROR_IO_ERROR; - } - #endif - g_download_ipc = - (download_ipc_info *) calloc(1, sizeof(download_ipc_info)); - } - - if (g_download_ipc != NULL) { - - int connect_retry = 3; - g_download_ipc->cmd_socket = -1; - while(g_download_ipc->cmd_socket < 0 && connect_retry-- > 0) { - g_download_ipc->cmd_socket = __create_socket(); - if (g_download_ipc->cmd_socket < 0) - usleep(50000); - } - if (g_download_ipc->cmd_socket < 0) { - TRACE_STRERROR("[CRITICAL] connect system error"); - free(g_download_ipc); - g_download_ipc = NULL; - return DOWNLOAD_ERROR_IO_ERROR; - } - // send a command - if (_ipc_send_int(g_download_ipc->cmd_socket, - DP_CMD_SET_COMMAND_SOCKET) < 0) { - close(g_download_ipc->cmd_socket); - free(g_download_ipc); - g_download_ipc = NULL; - return DOWNLOAD_ERROR_IO_ERROR; - } - #ifndef SO_PEERCRED - // send PID. Not support SO_PEERCRED - if (_ipc_send_int(g_download_ipc->cmd_socket, get_pid()) < 0) { - close(g_download_ipc->cmd_socket); - free(g_download_ipc); - g_download_ipc = NULL; - return DOWNLOAD_ERROR_IO_ERROR; - } - #endif - g_download_ipc->event_socket = __create_socket(); - if (g_download_ipc->event_socket < 0) { - TRACE_STRERROR("[CRITICAL] connect system error"); - close(g_download_ipc->cmd_socket); - free(g_download_ipc); - g_download_ipc = NULL; - return DOWNLOAD_ERROR_IO_ERROR; - } - // send a command - if (_ipc_send_int(g_download_ipc->event_socket, - DP_CMD_SET_EVENT_SOCKET) < 0) { - close(g_download_ipc->cmd_socket); - close(g_download_ipc->event_socket); - free(g_download_ipc); - g_download_ipc = NULL; - return DOWNLOAD_ERROR_IO_ERROR; - } - #ifndef SO_PEERCRED - // send PID. Not support SO_PEERCRED - if (_ipc_send_int - (g_download_ipc->event_socket, get_pid()) < 0) { - close(g_download_ipc->cmd_socket); - close(g_download_ipc->event_socket); - free(g_download_ipc); - g_download_ipc = NULL; - return DOWNLOAD_ERROR_IO_ERROR; - } - #endif - - int ret = pthread_mutex_init((&g_download_ipc->mutex), NULL); - if (ret != 0) { - TRACE_STRERROR("ERR:pthread_mutex_init FAIL with %d.", ret); - _disconnect_from_provider(); - return DOWNLOAD_ERROR_IO_ERROR; - } - - if (g_download_event_thread_pid <= 0) { - // create thread here ( getting event_socket ) - pthread_attr_t thread_attr; - if (pthread_attr_init(&thread_attr) != 0) { - TRACE_STRERROR("[CRITICAL] pthread_attr_init"); - _disconnect_from_provider(); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (pthread_attr_setdetachstate(&thread_attr, - PTHREAD_CREATE_DETACHED) != 0) { - TRACE_STRERROR("[CRITICAL] pthread_attr_setdetachstate"); - _disconnect_from_provider(); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (pthread_create(&g_download_event_thread_pid, - &thread_attr, - _download_event_manager, - g_download_ipc) != 0) { - TRACE_STRERROR("[CRITICAL] pthread_create"); - _disconnect_from_provider(); - return DOWNLOAD_ERROR_IO_ERROR; - } - } - } - return DOWNLOAD_ERROR_NONE; -} - -download_error_e _check_connections() -{ - int ret = 0; - if (g_download_ipc == NULL) - if ((ret = _connect_to_provider()) != DOWNLOAD_ERROR_NONE) - return ret; - if (g_download_ipc == NULL || g_download_ipc->cmd_socket < 0) { - TRACE_ERROR("[CHECK IPC]"); - return DOWNLOAD_ERROR_IO_ERROR; - } - return DOWNLOAD_ERROR_NONE; -} - - - -/////////////////////// APIs ///////////////////////////////// - -int download_create(int *download_id) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - int t_download_id = 0; - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - int index = _get_empty_slot_index(); - if (index < 0) { - TRACE_ERROR - ("[ERROR] TOO_MANY_DOWNLOADS[%d]", MAX_DOWNLOAD_HANDLE); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS; - } - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(-1, DP_CMD_CREATE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - // getting state with ID from provider. - t_download_id = _download_ipc_read_int(g_download_ipc->cmd_socket); - if (t_download_id < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - TRACE_INFO("ID : %d", t_download_id); - - *download_id = t_download_id; - g_download_slots[index].id = t_download_id; - pthread_mutex_unlock((&g_download_ipc->mutex)); - - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_destroy(int download_id) -{ - int index = -1; - int errorcode = DOWNLOAD_ERROR_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - index = _get_my_slot_index(download_id); - if (index >= 0) { - g_download_slots[index].id = 0; - g_download_slots[index].callback.state = NULL; - g_download_slots[index].callback.state_user_data = NULL; - g_download_slots[index].callback.progress = NULL; - g_download_slots[index].callback.progress_user_data = NULL; - } - errorcode = _send_simple_cmd(download_id, DP_CMD_DESTROY); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - // after getting errorcode, send FREE to provider. - TRACE_INFO("Request to Free the memory for ID : %d", download_id); - // send again DP_CMD_FREE with ID. - errorcode = _download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_FREE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_start(int download_id) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_START); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_pause(int download_id) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_PAUSE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_cancel(int download_id) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_CANCEL); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - - -int download_set_url(int download_id, const char *url) -{ - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (!url) { - TRACE_ERROR("[CHECK url]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - TRACE_INFO(""); - pthread_mutex_lock(&g_download_mutex); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_SET_URL) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_string(g_download_ipc->cmd_socket, url) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - - -int download_get_url(int download_id, char **url) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_URL); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting state with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *url = value; - TRACE_INFO("ID : %d url : %s", download_id, *url); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_set_network_type(int download_id, - download_network_type_e net_type) -{ - int network_type = DP_NETWORK_TYPE_ALL; - - if (net_type == DOWNLOAD_NETWORK_WIFI) - network_type = DP_NETWORK_TYPE_WIFI; - else if (net_type == DOWNLOAD_NETWORK_DATA_NETWORK) - network_type = DP_NETWORK_TYPE_DATA_NETWORK; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_NETWORK_TYPE) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, network_type) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_get_network_type(int download_id, - download_network_type_e *net_type) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - int network_type = DP_NETWORK_TYPE_ALL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_NETWORK_TYPE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - network_type = _download_ipc_read_int(g_download_ipc->cmd_socket); - if (network_type < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - if (network_type == DP_NETWORK_TYPE_WIFI) - *net_type = DOWNLOAD_NETWORK_WIFI; - else if (network_type == DP_NETWORK_TYPE_DATA_NETWORK) - *net_type = DOWNLOAD_NETWORK_DATA_NETWORK; - else - *net_type = DOWNLOAD_NETWORK_ALL; - - TRACE_INFO("ID : %d network_type : %d", download_id, *net_type); - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_set_destination(int download_id, const char *path) -{ - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (!path) { - TRACE_ERROR("[CHECK PATH]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_SET_DESTINATION) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_string(g_download_ipc->cmd_socket, path) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - - -int download_get_destination(int download_id, char **path) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = - _send_simple_cmd(download_id, DP_CMD_GET_DESTINATION); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting string with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *path = value; - TRACE_INFO("ID : %d path : %s", download_id, *path); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_set_file_name(int download_id, const char *file_name) -{ - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (!file_name) { - TRACE_ERROR("[CHECK file_name]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_SET_FILENAME) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_string(g_download_ipc->cmd_socket, file_name) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_get_file_name(int download_id, char **file_name) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = - _send_simple_cmd(download_id, DP_CMD_GET_FILENAME); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting string with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *file_name = value; - TRACE_INFO("ID : %d file_name : %s", download_id, *file_name); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_set_ongoing_notification(int download_id, bool enable) -{ - return download_set_notification(download_id, enable); -} - -int download_set_notification(int download_id, bool enable) -{ - int value = enable; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_NOTIFICATION) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, value) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - -} - -int download_get_ongoing_notification(int download_id, bool *enable) -{ - return download_get_notification(download_id, enable); -} - -int download_get_notification(int download_id, bool *enable) -{ - int value = 0; - int errorcode = DOWNLOAD_ERROR_NONE; - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_NOTIFICATION); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - value = _download_ipc_read_int(g_download_ipc->cmd_socket); - if (value < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *enable = value; - TRACE_INFO("ID : %d auto download : %d", download_id, *enable); - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; - -} - -int download_get_downloaded_file_path(int download_id, char **path) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = - _send_simple_cmd(download_id, DP_CMD_GET_SAVED_PATH); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting string with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *path = value; - TRACE_INFO("ID : %d path : %s", download_id, *path); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_set_notification_extra_param(int download_id, char *key, char *value) -{ - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (!key || !value) { - TRACE_ERROR("[CHECK param]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - TRACE_INFO(""); - pthread_mutex_lock(&g_download_mutex); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_SET_EXTRA_PARAM) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_string(g_download_ipc->cmd_socket, key) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - if (_ipc_send_string(g_download_ipc->cmd_socket, value) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_get_notification_extra_param(int download_id, char **key, char **value) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *key_str = NULL; - char *value_str = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_EXTRA_PARAM); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting state with ID from provider. - key_str = _ipc_read_string(g_download_ipc->cmd_socket); - if (key_str == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - value_str = _ipc_read_string(g_download_ipc->cmd_socket); - if (value_str == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - free(key_str); - return DOWNLOAD_ERROR_IO_ERROR; - } - - *key = key_str; - *value = value_str; - TRACE_INFO("ID : %d key : %s value : %s", download_id, *key, *value); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_add_http_header_field(int download_id, const char *field, - const char *value) -{ - download_error_e errorcode = DOWNLOAD_ERROR_NONE; - TRACE_INFO(""); - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (!field || !value) { - TRACE_ERROR("[CHECK field or value]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_SET_HTTP_HEADER) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - if (_ipc_send_string(g_download_ipc->cmd_socket, field) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - if (_ipc_send_string(g_download_ipc->cmd_socket, value) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_get_http_header_field(int download_id, - const char *field, char **value) -{ - download_error_e errorcode = DOWNLOAD_ERROR_NONE; - char *str = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - if (!field || !value) { - TRACE_ERROR("[CHECK field or value]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_GET_HTTP_HEADER) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR && errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - if (_ipc_send_string(g_download_ipc->cmd_socket, field) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode != DOWNLOAD_ERROR_NONE) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - // getting string with ID from provider. - str = _ipc_read_string(g_download_ipc->cmd_socket); - if (str == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *value = str; - TRACE_INFO("ID : %d field:%s value: %s", download_id, field, *value); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_remove_http_header_field(int download_id, - const char *field) -{ - download_error_e errorcode = DOWNLOAD_ERROR_NONE; - - TRACE_INFO(""); - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (!field) { - TRACE_ERROR("[CHECK field]"); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send commnad with ID - if (_download_ipc_send_command - (g_download_ipc->cmd_socket, download_id, DP_CMD_DEL_HTTP_HEADER) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_string(g_download_ipc->cmd_socket, field) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - - return errorcode; -} - -int download_set_state_changed_cb(int download_id, - download_state_changed_cb callback, void* user_data) -{ - int index = -1; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (callback == NULL) { - download_unset_state_changed_cb(download_id); - return DOWNLOAD_ERROR_NONE; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - // turn on state_cb flag of provider - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // send create command. - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_STATE_CALLBACK) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - download_unset_state_changed_cb(download_id); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, 1) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - download_unset_state_changed_cb(download_id); - return DOWNLOAD_ERROR_IO_ERROR; - } - - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - download_unset_state_changed_cb(download_id); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_NONE) { - // search same info in array. - index = _get_my_slot_index(download_id); - if (index < 0) { - index = _get_empty_slot_index(); - if (index < 0) { - TRACE_ERROR - ("[ERROR] TOO_MANY_DOWNLOADS[%d]", MAX_DOWNLOAD_HANDLE); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS; - } - g_download_slots[index].id = download_id; - } - g_download_slots[index].callback.state = callback; - g_download_slots[index].callback.state_user_data = user_data; - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_unset_state_changed_cb(int download_id) -{ - int index = -1; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - index = _get_my_slot_index(download_id); - if (index >= 0) { - g_download_slots[index].callback.state = NULL; - g_download_slots[index].callback.state_user_data = NULL; - } - // turn off state_cb flag of provider - // send create command. - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_STATE_CALLBACK) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, 0) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_set_progress_cb(int download_id, - download_progress_cb callback, void *user_data) -{ - int index = -1; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - if (callback == NULL) { - download_unset_progress_cb(download_id); - return DOWNLOAD_ERROR_NONE; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - // turn on progress_cb flag of provider - // send create command. - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_PROGRESS_CALLBACK) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - download_unset_progress_cb(download_id); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, 1) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - download_unset_progress_cb(download_id); - return DOWNLOAD_ERROR_IO_ERROR; - } - - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - download_unset_progress_cb(download_id); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_NONE) { - // search same info in array. - index = _get_my_slot_index(download_id); - if (index < 0) { - index = _get_empty_slot_index(); - if (index < 0) { - TRACE_ERROR - ("[ERROR] TOO_MANY_DOWNLOADS[%d]", MAX_DOWNLOAD_HANDLE); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS; - } - g_download_slots[index].id = download_id; - } - - g_download_slots[index].callback.progress = callback; - g_download_slots[index].callback.progress_user_data = user_data; - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_unset_progress_cb(int download_id) -{ - int index = -1; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - index = _get_my_slot_index(download_id); - if (index >= 0) { - g_download_slots[index].callback.progress = NULL; - g_download_slots[index].callback.progress_user_data = NULL; - } - // turn off progress_cb flag of provider - // send create command. - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_PROGRESS_CALLBACK) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, 0) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_get_state(int download_id, download_state_e *state) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - dp_state_type dp_state = DP_STATE_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_STATE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting state with ID from provider. - if (_ipc_read_custom_type(g_download_ipc->cmd_socket, - &dp_state, sizeof(dp_state_type)) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *state = _download_change_dp_state(dp_state); - TRACE_INFO("ID : %d state : %d", download_id, *state); - _download_print_str_state(*state); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_get_temp_path(int download_id, char **temp_path) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = - _send_simple_cmd(download_id, DP_CMD_GET_TEMP_SAVED_PATH); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting string with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *temp_path = value; - TRACE_INFO("ID : %d temp_path : %s", download_id, *temp_path); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_get_content_name(int download_id, char **content_name) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_CONTENT_NAME); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting string with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *content_name = value; - TRACE_INFO("ID : %d content_name : %s", download_id, *content_name); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_get_content_size(int download_id, - unsigned long long *content_size) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_TOTAL_FILE_SIZE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR && errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - // getting content_size from provider. - errorcode = _ipc_read_custom_type(g_download_ipc->cmd_socket, - content_size, sizeof(unsigned long long)); - if (errorcode < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - TRACE_INFO("ID : %d content_size %lld", download_id, *content_size); - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_get_mime_type(int download_id, char **mime_type) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - char *value = NULL; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_MIME_TYPE); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting state with ID from provider. - value = _ipc_read_string(g_download_ipc->cmd_socket); - if (value == NULL) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *mime_type = value; - TRACE_INFO("ID : %d mime_type : %s", download_id, *mime_type); - // it need to free - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_set_auto_download(int download_id, bool enable) -{ - int value = enable; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - if (_download_ipc_send_command(g_download_ipc->cmd_socket, - download_id, DP_CMD_SET_AUTO_DOWNLOAD) - != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - if (_ipc_send_int(g_download_ipc->cmd_socket, value) < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - // return from provider. - download_error_e errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; -} - -int download_get_auto_download(int download_id, bool *enable) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - int value = 0; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_AUTO_DOWNLOAD); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - - value = _download_ipc_read_int(g_download_ipc->cmd_socket); - if (value < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *enable = (bool)value; - TRACE_INFO("ID : %d auto download : %d", download_id, *enable); - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_get_error(int download_id, download_error_e *error) -{ - download_error_e errorcode = DOWNLOAD_ERROR_NONE; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_ERROR); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting errorcode from provider. - errorcode = - _download_ipc_read_return(g_download_ipc->cmd_socket); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - TRACE_ERROR("[CHECK IO] (%d)", download_id); - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - *error = errorcode; - TRACE_INFO("ID : %d error : %d", download_id, *error); - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} - -int download_get_http_status(int download_id, int *http_status) -{ - int errorcode = DOWNLOAD_ERROR_NONE; - int status = 0; - - if (download_id <= 0) { - TRACE_ERROR("[CHECK ID] (%d)", download_id); - return DOWNLOAD_ERROR_INVALID_PARAMETER; - } - - pthread_mutex_lock(&g_download_mutex); - TRACE_INFO(""); - - if (_check_connections() != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - - pthread_mutex_lock((&g_download_ipc->mutex)); - - DP_CHECK_PROVIDER_STATUS; - - errorcode = _send_simple_cmd(download_id, DP_CMD_GET_HTTP_STATUS); - if (errorcode != DOWNLOAD_ERROR_NONE) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errorcode == DOWNLOAD_ERROR_IO_ERROR) { - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - } - pthread_mutex_unlock(&g_download_mutex); - return errorcode; - } - // getting int from provider. - status = _download_ipc_read_int(g_download_ipc->cmd_socket); - if (status < 0) { - pthread_mutex_unlock((&g_download_ipc->mutex)); - if (errno != EAGAIN && errno != EINTR) - _disconnect_from_provider(); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_IO_ERROR; - } - *http_status = status; - TRACE_INFO("ID : %d http_status : %d", download_id, *http_status); - pthread_mutex_unlock((&g_download_ipc->mutex)); - pthread_mutex_unlock(&g_download_mutex); - return DOWNLOAD_ERROR_NONE; -} -