Add cache support
[platform/framework/web/download-provider.git] / agent / download-agent-http-msg-handler.c
index 92d54c3..4686809 100755 (executable)
@@ -461,7 +461,8 @@ http_header_options_t *__parsing_N_create_option_str(char *org_str)
        }
 
        DA_SECURE_LOGD("option_field = [%s], option_value = [%s]",
-                       option_field, option_value);
+                       option_field ? option_field : "",
+                       option_value ? option_value : "");
 
        if (option_field || option_value) {
                option = __create_http_header_option(
@@ -711,8 +712,7 @@ void http_msg_response_set_content_type(http_msg_response_t *http_msg_response,
        b_ret = __get_http_header_for_field(http_msg_response,
                        HTTP_FIELD_CONTENT_TYPE, &header);
        if (b_ret) {
-               if (header->raw_value && (!strncmp(header->raw_value, in_type,
-                                               strlen(header->raw_value))))
+               if (header->raw_value && !strcmp(header->raw_value, in_type))
                        return;
 
                DA_SECURE_LOGD("exchange Content-Type to [%s] from [%s]", in_type, header->value);
@@ -823,9 +823,7 @@ da_bool_t http_msg_response_get_content_disposition(
                        if (decoded_str) {
                                char* file_name;
                                DA_SECURE_LOGD("Url decoded str = [%s]", decoded_str);
-                               file_name = (char*)calloc(1, strlen(decoded_str) + 1);
-                               strncpy(file_name, decoded_str, strlen(decoded_str));
-
+                               file_name = strdup(decoded_str);
                                NULL_CHECK_AND_FREE(wanted_str);
                                curl_free(decoded_str);
                                decoded_str = NULL;
@@ -845,8 +843,7 @@ da_bool_t http_msg_response_get_content_disposition(
        }
 }
 
-da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response,
-               char **out_value)
+da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response, char **out_value)
 {
        da_bool_t b_ret = DA_FALSE;
        http_header_t *header = NULL;
@@ -865,6 +862,55 @@ da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response,
        return DA_TRUE;
 }
 
+da_bool_t http_msg_response_get_cache_control(http_msg_response_t *http_msg_response, char **out_value)
+{
+       da_bool_t b_ret = DA_FALSE;
+       http_header_t *header = NULL;
+
+       if (!out_value) {
+               DA_LOGE("[NULL CHECK] out_value");
+               return DA_FALSE;
+       }
+
+       b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_CACHE_CONTROL,
+                       &header);
+       if (!b_ret) {
+               DA_LOGV("no cache-control");
+               return DA_FALSE;
+       }
+
+       if (header->value)
+               *out_value = strdup(header->value);
+       else
+               return DA_FALSE;
+
+       return DA_TRUE;
+}
+
+da_bool_t http_msg_response_get_last_modified(http_msg_response_t *http_msg_response, char **out_value)
+{
+       da_bool_t b_ret = DA_FALSE;
+       http_header_t *header = NULL;
+
+       if (!out_value) {
+               DA_LOGE("[NULL CHECK] out_value");
+               return DA_FALSE;
+       }
+
+       b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_LAST_MODIFIED,
+                       &header);
+       if (!b_ret) {
+               DA_LOGV("no last-modified");
+               return DA_FALSE;
+       }
+       if (header->value)
+               *out_value = strdup(header->value);
+       else
+               return DA_FALSE;
+
+       return DA_TRUE;
+}
+
 #ifdef _RAF_SUPPORT
 da_bool_t http_msg_response_get_RAF_mode(http_msg_response_t *http_msg_response,
                char **out_value)