summaryrefslogtreecommitdiff
path: root/src/agent/include/download-agent-dl-info-util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/include/download-agent-dl-info-util.h')
-rw-r--r--src/agent/include/download-agent-dl-info-util.h294
1 files changed, 294 insertions, 0 deletions
diff --git a/src/agent/include/download-agent-dl-info-util.h b/src/agent/include/download-agent-dl-info-util.h
new file mode 100644
index 0000000..f17715d
--- /dev/null
+++ b/src/agent/include/download-agent-dl-info-util.h
@@ -0,0 +1,294 @@
+/*
+ * Download Agent
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jungki Kwak <jungki.kwak@samsung.com>, Keunsoon Lee <keunsoon.lee@samsung.com>
+ *
+ * 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.
+ *
+ * @file download-agent-dl-info-util.h
+ * @brief
+ * @author Keunsoon Lee(keunsoon.lee@samsung.com)
+ ***/
+
+#ifndef _Download_Agent_Dl_Info_Util_H
+#define _Download_Agent_Dl_Info_Util_H
+
+#include "download-agent-type.h"
+#include "download-agent-http-queue.h"
+#include "download-agent-utils-dl-req-id-history.h"
+
+#define DA_MAX_DOWNLOAD_ID DA_MAX_DOWNLOAD_REQ_AT_ONCE
+#define DA_MAX_TYPE_COUNT 10
+
+#define DOWNLOAD_NOTIFY_LIMIT (1024*32) //bytes
+extern pthread_mutex_t mutex_download_state[];
+
+typedef enum {
+ DOWNLOAD_STATE_IDLE = 0,
+ DOWNLOAD_STATE_NEW_DOWNLOAD = 20, /* stage */
+
+ DOWNLOAD_STATE_READY_TO_INSTAL = 55, /* stage */
+
+ DOWNLOAD_STATE_FINISH = 60, /* stage */
+
+ DOWNLOAD_STATE_PAUSED = 70, /* http */
+ DOWNLOAD_STATE_CANCELED, /* http */
+
+} download_state_t;
+
+typedef enum {
+ HTTP_STATE_READY_TO_DOWNLOAD = 0,
+ HTTP_STATE_REDIRECTED = 1,
+ HTTP_STATE_DOWNLOAD_REQUESTED = 2,
+ HTTP_STATE_DOWNLOAD_STARTED = 3,
+ HTTP_STATE_DOWNLOADING = 4,
+ HTTP_STATE_DOWNLOAD_FINISH = 5,
+ HTTP_STATE_REQUEST_CANCEL = 6,
+ HTTP_STATE_REQUEST_PAUSE = 7,
+ HTTP_STATE_REQUEST_RESUME = 8,
+ HTTP_STATE_CANCELED = 9,
+ HTTP_STATE_PAUSED = 10,
+ HTTP_STATE_RESUMED = 11,
+ HTTP_STATE_ABORTED = 12,
+
+} http_state_t;
+
+typedef struct _client_input_basic_t {
+ char *req_url;
+ char **user_request_header;
+ int user_request_header_count;
+} client_input_basic_t;
+
+
+typedef struct _client_input_t {
+ void *user_data;
+ char *install_path;
+ char *file_name;
+ client_input_basic_t client_input_basic;
+} client_input_t;
+
+typedef struct _download_thread_input {
+ int download_id;
+ client_input_t *client_input;
+} download_thread_input;
+
+typedef struct _source_info_basic_t {
+ int dl_id;
+ char *url;
+ char **user_request_header;
+ int user_request_header_count;
+} source_info_basic_t;
+
+typedef struct _source_info_t {
+ union _source_info_type {
+ source_info_basic_t *source_info_basic;
+ } source_info_type;
+} source_info_t;
+
+#define GET_SOURCE_TYPE(SOURCE) ((SOURCE)->source_type)
+#define GET_SOURCE_BASIC(SOURCE) ((SOURCE)->source_info_type.source_info_basic)
+#define GET_SOURCE_BASIC_URL(SOURCE) (GET_SOURCE_BASIC(SOURCE)->url)
+
+typedef struct _req_dl_info {
+ http_info_t http_info;
+
+ /* This is just pointer assignment from stage source info. */
+ char *destination_url;
+ /* The location url is assigned here in case of redirection.
+ * At this time, the pointer should be freed. */
+ char *location_url;
+ char **user_request_header;
+ int user_request_header_count;
+
+ http_state_t http_state;
+ pthread_mutex_t mutex_http_state;
+
+ da_result_t result;
+ /*************** will be depreciated ***********************/
+ /* ToDo : previous http_info should be saved in case of pause */
+ char *content_type_from_header; /* calloced in set hdr fiels on download info */
+ int content_len_from_header;
+ char *etag_from_header;
+
+ unsigned long int downloaded_data_size;
+
+ int invloved_transaction_id;
+} req_dl_info;
+
+#define GET_REQUEST_HTTP_RESULT(REQUEST) (REQUEST->result)
+#define GET_REQUEST_HTTP_TRANS_ID(REQUEST) (REQUEST->invloved_transaction_id)
+#define GET_REQUEST_HTTP_REQ_URL(REQUEST) (REQUEST->destination_url)
+#define GET_REQUEST_HTTP_REQ_LOCATION(REQUEST) (REQUEST->location_url)
+#define GET_REQUEST_HTTP_USER_REQUEST_HEADER(REQUEST) (REQUEST->user_request_header)
+#define GET_REQUEST_HTTP_USER_REQUEST_HEADER_COUNT(REQUEST) (REQUEST->user_request_header_count)
+#define GET_REQUEST_HTTP_HDR_ETAG(REQUEST) (REQUEST->etag_from_header)
+#define GET_REQUEST_HTTP_HDR_CONT_TYPE(REQUEST) (REQUEST->content_type_from_header)
+#define GET_REQUEST_HTTP_HDR_CONT_LEN(REQUEST) (REQUEST->content_len_from_header)
+#define GET_REQUEST_HTTP_CONTENT_OFFSET(REQUEST)(REQUEST->downloaded_data_size)
+#define GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE) (GET_STAGE_TRANSACTION_INFO(STAGE)->mutex_http_state)
+#define GET_HTTP_STATE_ON_STAGE(STAGE) (GET_STAGE_TRANSACTION_INFO(STAGE)->http_state)
+#define CHANGE_HTTP_STATE(STATE,STAGE) {\
+ _da_thread_mutex_lock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE)));\
+ GET_HTTP_STATE_ON_STAGE(STAGE) = STATE;\
+ DA_LOG_CRITICAL(Default, "Changed http_state to - [%d] ", GET_HTTP_STATE_ON_STAGE(STAGE));\
+ _da_thread_mutex_unlock(&(GET_REQUEST_HTTP_MUTEX_HTTP_STATE(STAGE)));\
+}
+
+typedef struct _file_info {
+ void *file_handle;
+ char *pure_file_name;
+ char *extension;
+ char *file_name_tmp; /* malloced in make file info. */
+ char *file_name_final; /* malloced in set_file_path_for_final_saving */
+ char *content_type; /* malloced in make file info. */
+ char *add_to_buffer;
+ unsigned int file_size; /* http header's Content-Length has higher priority than DD's <size> */
+ unsigned int total_bytes_written_to_file; /* current written file size */
+ unsigned int bytes_written_to_file;
+ unsigned int current_buffer_len;
+} file_info;
+
+#define GET_CONTENT_STORE_PURE_FILE_NAME(FILE_CNTXT) (FILE_CNTXT)->pure_file_name
+#define GET_CONTENT_STORE_EXTENSION(FILE_CNTXT) (FILE_CNTXT)->extension
+#define GET_CONTENT_STORE_TMP_FILE_NAME(FILE_CNTXT) (FILE_CNTXT)->file_name_tmp
+#define GET_CONTENT_STORE_ACTUAL_FILE_NAME(FILE_CNTXT) (FILE_CNTXT)->file_name_final
+#define GET_CONTENT_STORE_FILE_HANDLE(FILE_CNTXT) (FILE_CNTXT)->file_handle
+#define GET_CONTENT_STORE_FILE_SIZE(FILE_CNTXT) (FILE_CNTXT)->file_size
+#define GET_CONTENT_STORE_CURRENT_FILE_SIZE(FILE_CNTXT) (FILE_CNTXT)->total_bytes_written_to_file
+#define IS_CONTENT_STORE_FILE_BYTES_WRITTEN_TO_FILE(FILE_CNTXT) (FILE_CNTXT)->bytes_written_to_file
+#define GET_CONTENT_STORE_FILE_BUFFER(FILE_CNTXT) (FILE_CNTXT)->add_to_buffer
+#define GET_CONTENT_STORE_FILE_BUFF_LEN(FILE_CNTXT) ((FILE_CNTXT)->current_buffer_len)
+#define GET_CONTENT_STORE_CONTENT_TYPE(FILE_CNTXT) (FILE_CNTXT)->content_type
+
+typedef struct _stage_info {
+ int dl_id;
+ source_info_t dl_request;
+ req_dl_info dl_tansaction_context;
+ file_info dl_content_storage;
+ struct _stage_info *next_stage_info;
+} stage_info;
+
+#define GET_STAGE_DL_ID(STAGE) ((STAGE)->dl_id)
+#define GET_STAGE_SOURCE_INFO(STAGE) (&((STAGE)->dl_request))
+#define GET_STAGE_TRANSACTION_INFO(STAGE) (&((STAGE)->dl_tansaction_context))
+#define GET_STAGE_CONTENT_STORE_INFO(STAGE) (&((STAGE)->dl_content_storage))
+#define GET_STAGE_INSTALLATION_INFO(STAGE) (&((STAGE)->post_dl_context))
+
+typedef struct _download_info_t {
+ da_bool_t is_using;
+ int download_id;
+ int dl_req_id;
+ pthread_t active_dl_thread_id;
+ download_state_t state;
+ stage_info *download_stage_data;
+ da_state cur_da_state;
+ queue_t queue;
+ // FIXME have client_input itself, not to have each of them
+ char *user_install_path;
+ char *user_file_name;
+ void *user_data;
+} download_info_t;
+
+#define GET_DL_THREAD_ID(ID) (download_mgr.download_info[ID].active_dl_thread_id)
+#define GET_DL_STATE_ON_ID(ID) (download_mgr.download_info[ID].state)
+#define GET_DL_STATE_ON_STAGE(STAGE) (GET_DL_STATE_ON_ID(GET_STAGE_DL_ID(STAGE)))
+#define GET_DL_CURRENT_STAGE(ID) (download_mgr.download_info[ID].download_stage_data)
+#define GET_DL_REQ_ID(ID) (download_mgr.download_info[ID].dl_req_id)
+#define GET_DL_DA_STATE(ID) (download_mgr.download_info[ID].cur_da_state)
+#define GET_DL_QUEUE(ID) &(download_mgr.download_info[ID].queue)
+#define GET_DL_USER_INSTALL_PATH(ID) (download_mgr.download_info[ID].user_install_path)
+#define GET_DL_USER_FILE_NAME(ID) (download_mgr.download_info[ID].user_file_name)
+#define GET_DL_USER_DATA(ID) (download_mgr.download_info[ID].user_data)
+#define IS_THIS_DL_ID_USING(ID) (download_mgr.download_info[ID].is_using)
+
+#define CHANGE_DOWNLOAD_STATE(STATE,STAGE) {\
+ _da_thread_mutex_lock (&mutex_download_state[GET_STAGE_DL_ID(STAGE)]);\
+ GET_DL_STATE_ON_STAGE(STAGE) = STATE;\
+ DA_LOG_CRITICAL(Default, "Changed download_state to - [%d] ", GET_DL_STATE_ON_STAGE(STAGE));\
+ _da_thread_mutex_unlock (&mutex_download_state[GET_STAGE_DL_ID(STAGE)]);\
+ }
+
+typedef enum {
+ STATE_WATCHER_TYPE_NONE = 0,
+ STATE_WATCHER_TYPE_CANCEL,
+ STATE_WATCHER_TYPE_SUSPEND,
+ STATE_WATCHER_TYPE_RESUME
+} state_watcher_type_t;
+
+typedef struct _state_watcher_t {
+ state_watcher_type_t type;
+ unsigned short state_watching_bitmap;
+ da_bool_t is_progressing_to_all;
+ pthread_mutex_t mutex;
+} state_watcher_t;
+
+typedef struct _default_http_hdr_info_t {
+ char *user_agent_string;
+} default_http_hdr_info_t;
+
+#define GET_USER_AGENT (download_mgr.default_hdr_info->user_agent_string)
+
+typedef struct _download_mgr_t {
+ da_bool_t is_init;
+ download_info_t download_info[DA_MAX_DOWNLOAD_ID];
+ default_http_hdr_info_t *default_hdr_info;
+ state_watcher_t state_watcher;
+
+ /* FIXME: This is temporary solution to prevent crash on following case;
+ * 1) OMA download(that is, DA's libsoup is using) is on progressing on Browser
+ * 2) User push END hard key
+ * 3) da_deinit() is called. - on UI thread
+ * 4) cancel_download(all) is called.
+ * 5) plugin-libsoup.c calls soup_session_cancel_message().
+ * 6) da_deinit() is finished and process is over.
+ * 7) soup's callback for soup_session_cancel_message() is trying to be called - on UI thread
+ * 8) Browser crashed because the callback address is no longer exist.
+ *
+ * Here is a temporary solution;
+ * If cancel is from da_deinit(), plugin-libsoup.c will not call soup_session_cancel_message().
+ * So, append following variable to recognize this.
+ **/
+ //da_bool_t is_progressing_deinit;
+
+ dl_req_id_history_t dl_req_id_history;
+} download_mgr_t;
+
+extern download_mgr_t download_mgr;
+
+da_result_t init_download_mgr();
+da_result_t deinit_download_mgr(void);
+
+void init_download_info(int download_id);
+void destroy_download_info(int download_id);
+
+void *Add_new_download_stage(int download_id);
+void remove_download_stage(int download_id, stage_info *in_stage);
+
+void empty_stage_info(stage_info *in_stage);
+
+void clean_up_client_input_info(client_input_t *client_input);
+
+da_result_t get_available_download_id(da_handle_t *available_id);
+da_result_t get_download_id_for_dl_req_id(da_handle_t dl_req_id , da_handle_t* download_id);
+da_bool_t is_valid_dl_ID(int download_id);
+
+void state_watcher_flag_ON_for_download_id(state_watcher_t *state_watcher,
+ int download_id);
+void state_watcher_flag_OFF_for_download_id(state_watcher_t *state_watcher,
+ int download_id);
+da_bool_t state_watcher_need_redirect_Q(int download_id);
+void state_watcher_redirect_state(int download_id, da_state state, int err);
+
+#endif /* _Download_Agent_Dl_Info_Util_H */