#include "download-agent-encoding.h"
// '.' and ';' are request from Vodafone
-#define IS_TERMINATING_CHAR(c) ( ((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20) )
-#define IS_TERMINATING_CHAR_EX(c) ( ((c) == '"') || ((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20) )
-#define IS_URI_TERMINATING_CHAR(c) ( ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20) )
+#define IS_TERMINATING_CHAR(c) (((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20))
+#define IS_TERMINATING_CHAR_EX(c) (((c) == '"') || ((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20))
+#define IS_URI_TERMINATING_CHAR(c) (((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20))
enum parsing_type {
WITH_PARSING_OPTION,
};
static da_ret_t __http_header_add_field(http_header_t **head,
- const char *field, const char *value, enum parsing_type type);
+ const char *field, const char *value, enum parsing_type type);
static void __http_header_destroy_all_field(http_header_t **head);
static da_bool_t __get_http_header_for_field(
- http_msg_response_t *http_msg_response, const char *in_field,
- http_header_t **out_header);
+ http_msg_response_t *http_msg_response, const char *in_field,
+ http_header_t **out_header);
static void __exchange_header_value(http_header_t *header,
- const char *in_raw_value);
+ const char *in_raw_value);
static http_header_options_t *__create_http_header_option(const char *field,
- const char *value);
+ const char *value);
static void __http_header_destroy_all_option(http_header_options_t **head);
static da_bool_t __get_http_header_option_for_field(
- http_header_options_t *header_option, const char *in_field,
- char **out_value);
+ http_header_options_t *header_option, const char *in_field,
+ char **out_value);
static http_header_options_t *__parsing_N_create_option_str(char *org_str);
static http_header_options_t *__parsing_options(char *org_str);
static void __parsing_raw_value(http_header_t *http_header);
{
http_msg_request_t *temp_http_msg_request = NULL;
-// DA_LOGV("");
+ // DA_LOGV("");
temp_http_msg_request = (http_msg_request_t *)calloc(1,
- sizeof(http_msg_request_t));
+ sizeof(http_msg_request_t));
if (!temp_http_msg_request) {
*http_msg_request = NULL;
DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
temp_http_msg_request->http_body = NULL;
*http_msg_request = temp_http_msg_request;
- DA_LOGV( "http_msg_request: %x", (unsigned int)(*http_msg_request));
+ DA_LOGV("http_msg_request: %x", (unsigned int)(*http_msg_request));
return DA_RESULT_OK;
}
}
da_ret_t http_msg_request_set_url(http_msg_request_t *http_msg_request,
- const char *url)
+ const char *url)
{
DA_LOGV("");
}
da_ret_t http_msg_request_get_url(http_msg_request_t *http_msg_request,
- const char **url)
+ const char **url)
{
DA_LOGV("");
}
da_ret_t http_msg_request_add_field(http_msg_request_t *http_msg_request,
- const char *field, const char *value)
+ const char *field, const char *value)
{
// DA_LOGV("");
DA_LOGV("");
temp_http_msg_response = (http_msg_response_t *)calloc(1,
- sizeof(http_msg_response_t));
+ sizeof(http_msg_response_t));
if (!temp_http_msg_response) {
DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
return DA_ERR_FAIL_TO_MEMALLOC;
}
da_ret_t http_msg_response_add_field(http_msg_response_t *http_msg_response,
- const char *field, const char *value)
+ const char *field, const char *value)
{
DA_LOGV("");
}
da_ret_t __http_header_add_field(http_header_t **head,
- const char *field, const char *value, enum parsing_type type)
+ const char *field, const char *value, enum parsing_type type)
{
http_header_t *pre = NULL;
http_header_t *cur = NULL;
pre = cur;
/* Replace default value with user wanted value
* Remove the value which is stored before and add a new value.
- */
+ */
if (cur->field && cur->raw_value &&
strncasecmp(cur->field, field, strlen(field)) == 0) {
DA_SECURE_LOGD("Remove value for replacement [%s][%s]", cur->field, cur->raw_value);
}
if (cur->raw_value) {
free(cur->raw_value);
- cur->raw_value= NULL;
+ cur->raw_value = NULL;
}
}
cur = cur->next;
}
http_header_options_t *__create_http_header_option(const char *field,
- const char *value)
+ const char *value)
{
http_header_options_t *option = NULL;
option = (http_header_options_t *)calloc(1,
- sizeof(http_header_options_t));
+ sizeof(http_header_options_t));
if (option) {
if (field)
option->field = strdup(field);
}
da_ret_t http_msg_request_get_iter(http_msg_request_t *http_msg_request,
- http_msg_iter_t *http_msg_iter)
+ http_msg_iter_t *http_msg_iter)
{
DA_LOGV("");
}
da_ret_t http_msg_response_get_iter(http_msg_response_t *http_msg_response,
- http_msg_iter_t *http_msg_iter)
+ http_msg_iter_t *http_msg_iter)
{
if (!http_msg_response) {
DA_LOGE("DA_ERR_INVALID_ARGUMENT");
}
da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter,
- char **out_field, char **out_value)
+ char **out_field, char **out_value)
{
http_header_t *cur = *http_msg_iter;
}
da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter,
- char **out_field, http_header_t **out_header)
+ char **out_field, http_header_t **out_header)
{
http_header_t *cur = *http_msg_iter;
option_field = (char *)calloc(1, option_field_len + 1);
if (option_field)
strncpy(option_field, working_pos_field_start,
- option_field_len);
+ option_field_len);
}
if (option_value_len > 0 && working_pos_value_start) {
option_value = (char *)calloc(1, option_value_len + 1);
if (option_value)
strncpy(option_value, working_pos_value_start,
- option_value_len);
+ option_value_len);
}
if (working_str) {
free(working_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(
- option_field, option_value);
+ option_field, option_value);
if (option_field) {
free(option_field);
option_field = NULL;
http_header_options_t *cur = NULL;
cur = http_header_field->options;
while (cur) {
-// DA_SECURE_LOGD("field = [%s], value = [%s]", cur->field, cur->value);
+ // DA_SECURE_LOGD("field = [%s], value = [%s]", cur->field, cur->value);
cur = cur->next;
}
}
da_bool_t __get_http_header_option_for_field(
- http_header_options_t *header_option, const char *in_field,
- char **out_value)
+ http_header_options_t *header_option, const char *in_field,
+ char **out_value)
{
http_header_options_t *cur = NULL;
}
da_bool_t __get_http_header_for_field(http_msg_response_t *http_msg_response,
- const char *in_field, http_header_t **out_header)
+ const char *in_field, http_header_t **out_header)
{
- http_msg_iter_t http_msg_iter;
+ http_msg_iter_t http_msg_iter = DA_NULL;
http_header_t *header = NULL;
char *field = NULL;
}
da_bool_t __get_http_req_header_for_field(http_msg_request_t *http_msg_request,
- const char *in_field, http_header_t **out_header)
+ const char *in_field, http_header_t **out_header)
{
- http_msg_iter_t http_msg_iter;
+ http_msg_iter_t http_msg_iter = DA_NULL;
http_header_t *header = NULL;
char *field = NULL;
}
da_bool_t http_msg_response_get_content_type(
- http_msg_response_t *http_msg_response, char **out_type)
+ http_msg_response_t *http_msg_response, char **out_type)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
}
void http_msg_response_set_content_type(http_msg_response_t *http_msg_response,
- const char *in_type)
+ const char *in_type)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
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);
}
da_bool_t http_msg_response_get_content_length(
- http_msg_response_t *http_msg_response, da_size_t *out_length)
+ http_msg_response_t *http_msg_response, da_size_t *out_length)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_header_for_field(http_msg_response,
HTTP_FIELD_CONTENT_LENGTH, &header);
if (!b_ret) {
- DA_LOGV( "no Content-Length");
+ DA_LOGV("no Content-Length");
return DA_FALSE;
}
}
da_bool_t http_msg_response_get_content_disposition(
- http_msg_response_t *http_msg_response, http_msg_t *http_msg, char **out_disposition,
- char **out_file_name)
+ http_msg_response_t *http_msg_response, http_msg_t *http_msg, char **out_disposition,
+ char **out_file_name)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_header_for_field(http_msg_response,
HTTP_FIELD_CONTENT_DISPOSITION, &header);
if (!b_ret) {
- DA_LOGV( "no Content-Disposition");
+ DA_LOGV("no Content-Disposition");
return DA_FALSE;
}
if (out_disposition)
return DA_FALSE;
b_ret = __get_http_header_option_for_field(header->options, "filename",
- &file_name);
+ &file_name);
if (!b_ret) {
- DA_LOGV( "no option");
+ DA_LOGV("no option");
return DA_FALSE;
}
if (b_ret) {
DA_LOGV("It's base64 encoded-word string");
if (DA_RESULT_OK == decode_base64_encoded_str(
- wanted_str, &decoded_str)) {
+ wanted_str, &decoded_str)) {
DA_SECURE_LOGD("base64 decoded str = [%s]", decoded_str);
free(wanted_str);
wanted_str = decoded_str;
DA_LOGV("It's NOT base64 encoded-word string");
}
- if(http_msg->curl){
+ if (http_msg->curl) {
decoded_str = curl_easy_unescape(http_msg->curl, wanted_str, wanted_str_len, NULL);
- }
- else{
+ } else{
CURL* handle = curl_easy_init();
decoded_str = curl_easy_unescape(handle, wanted_str, wanted_str_len, NULL);
curl_easy_cleanup(handle);
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;
*out_file_name = file_name;
return DA_TRUE;
- }
- else{
+ } else{
DA_LOGE("Fail to url decode.");
NULL_CHECK_AND_FREE(wanted_str);
*out_file_name = NULL;
}
}
-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;
b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_ETAG,
&header);
if (!b_ret) {
- DA_LOGV( "no ETag");
+ DA_LOGV("no ETag");
return DA_FALSE;
}
if (out_value)
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)
+ char **out_value)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_RAF_MODE,
&header);
if (!b_ret) {
- DA_LOGV( "no RAF mode");
+ DA_LOGV("no RAF mode");
return DA_FALSE;
}
if (out_value)
#endif
da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response,
- char **out_value)
+ char **out_value)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_header_for_field(http_msg_response,
HTTP_FIELD_DATA, &header);
if (!b_ret) {
- DA_LOGV( "no Date");
+ DA_LOGV("no Date");
return DA_FALSE;
}
if (out_value)
}
da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response,
- char **out_value)
+ char **out_value)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_header_for_field(http_msg_response,
HTTP_FIELD_LOCATION, &header);
if (!b_ret) {
- DA_LOGV( "no Location");
+ DA_LOGV("no Location");
+ return DA_FALSE;
+ }
+ if (out_value)
+ *out_value = strdup(header->value);
+
+ return DA_TRUE;
+}
+
+da_bool_t http_msg_response_get_transfer_encoding(http_msg_response_t *http_msg_response,
+ char **out_value)
+{
+ da_bool_t b_ret = DA_FALSE;
+ http_header_t *header = NULL;
+
+ DA_LOGV("");
+
+ b_ret = __get_http_header_for_field(http_msg_response,
+ HTTP_FIELD_TRANSFER_ENCODING, &header);
+ if (!b_ret) {
+ DA_LOGE("no Transfer-Encoding");
return DA_FALSE;
}
if (out_value)
while (i < length_long) {
if (isalpha(long_str[i]) != 0) {
- if (isupper(long_str[i]) != 0) {
+ if (isupper(long_str[i]) != 0)
org_ptr[i] = long_str[i];
- } else {
+ else
org_ptr[i] = toupper(long_str[i]);
- }
} else {
org_ptr[i] = long_str[i];
}
while (i < length_find) {
if (isalpha(find_str[i]) != 0) {
- if (isupper(find_str[i]) != 0) {
+ if (isupper(find_str[i]) != 0)
look_ptr[i] = find_str[i];
- } else {
+ else
look_ptr[i] = toupper(find_str[i]);
- }
} else {
look_ptr[i] = find_str[i];
}
/* This is not used. But it can be needed if there is no http header parser at http library.*/
da_bool_t extract_attribute_from_header(
- char *szHeadStr,
- const char *szFindStr,
- char **ppRtnValue)
+ char *szHeadStr,
+ const char *szFindStr,
+ char **ppRtnValue)
{
char *pValuePos = NULL;
int index = 0;
return DA_FALSE;
}
- if (ppRtnValue == NULL) {
+ if (ppRtnValue == NULL)
return DA_FALSE;
- }
pValuePos = __stristr(szHeadStr, (char*)szFindStr);
if (pValuePos == NULL) {
while (pValuePos[index] != ':' && pValuePos[index] != '=') {
index++;
- if (pValuePos[index] == '\0') {
+ if (pValuePos[index] == '\0')
return DA_FALSE;
- }
}
index++;
/* jump space */
- while (pValuePos[index] == ' ') {
+ while (pValuePos[index] == ' ')
index++;
- }
/* jump quatation mark */
while (pValuePos[index] == '"') {
startPos = index;
- /* Find the end of data. */
- if (0 == strncasecmp(szFindStr, HTTP_FIELD_LOCATION,
- strlen(HTTP_FIELD_LOCATION)))//terminate character list does not contain ';' in case of URI
- {
- while (DA_FALSE == IS_URI_TERMINATING_CHAR(pValuePos[index])) {
+ /* Find the end of data.
+ * terminate character list does not contain ';' in case of URI
+ */
+ if (0 == strncasecmp(szFindStr, HTTP_FIELD_LOCATION, strlen(HTTP_FIELD_LOCATION))) {
+ while (DA_FALSE == IS_URI_TERMINATING_CHAR(pValuePos[index]))
index++;
- }
} else if (need_to_end_quataion_mark) {
- while (DA_FALSE == IS_TERMINATING_CHAR_EX(pValuePos[index])) {
+ while (DA_FALSE == IS_TERMINATING_CHAR_EX(pValuePos[index]))
index++;
- }
} else {
- while (DA_FALSE == IS_TERMINATING_CHAR(pValuePos[index])) {
+ while (DA_FALSE == IS_TERMINATING_CHAR(pValuePos[index]))
index++;
- }
}
strLen = index - startPos;
}
da_bool_t http_msg_request_get_if_range(http_msg_request_t *http_msg_request,
- char **out_value)
+ char **out_value)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_req_header_for_field(http_msg_request, HTTP_FIELD_IF_RANGE,
&header);
if (!b_ret) {
- DA_LOGV( "no If Range");
+ DA_LOGV("no If Range");
return DA_FALSE;
}
if (out_value)
}
da_bool_t http_msg_request_get_range(http_msg_request_t *http_msg_request,
- char **out_value)
+ char **out_value)
{
da_bool_t b_ret = DA_FALSE;
http_header_t *header = NULL;
b_ret = __get_http_req_header_for_field(http_msg_request, HTTP_FIELD_RANGE,
&header);
if (!b_ret) {
- DA_LOGV( "no Range");
+ DA_LOGV("no Range");
return DA_FALSE;
}
if (out_value)