2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <curl/curl.h>
22 #include "download-agent-http-msg-handler.h"
23 #include "download-agent-debug.h"
24 #include "download-agent-encoding.h"
26 // '.' and ';' are request from Vodafone
27 #define IS_TERMINATING_CHAR(c) (((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20))
28 #define IS_TERMINATING_CHAR_EX(c) (((c) == '"') || ((c) == ';') || ((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20))
29 #define IS_URI_TERMINATING_CHAR(c) (((c) == '\0') || ((c) == 0x0d) || ((c) == 0x0a) || ((c) == 0x20))
33 WITHOUT_PARSING_OPTION
36 static da_ret_t __http_header_add_field(http_header_t **head,
37 const char *field, const char *value, enum parsing_type type);
38 static void __http_header_destroy_all_field(http_header_t **head);
39 static da_bool_t __get_http_header_for_field(
40 http_msg_response_t *http_msg_response, const char *in_field,
41 http_header_t **out_header);
42 static void __exchange_header_value(http_header_t *header,
43 const char *in_raw_value);
44 static http_header_options_t *__create_http_header_option(const char *field,
46 static void __http_header_destroy_all_option(http_header_options_t **head);
47 static da_bool_t __get_http_header_option_for_field(
48 http_header_options_t *header_option, const char *in_field,
50 static http_header_options_t *__parsing_N_create_option_str(char *org_str);
51 static http_header_options_t *__parsing_options(char *org_str);
52 static void __parsing_raw_value(http_header_t *http_header);
54 da_ret_t http_msg_request_create(http_msg_request_t **http_msg_request)
56 http_msg_request_t *temp_http_msg_request = NULL;
60 temp_http_msg_request = (http_msg_request_t *)calloc(1,
61 sizeof(http_msg_request_t));
62 if (!temp_http_msg_request) {
63 *http_msg_request = NULL;
64 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
65 return DA_ERR_FAIL_TO_MEMALLOC;
68 temp_http_msg_request->http_method = NULL;
69 temp_http_msg_request->url = NULL;
70 temp_http_msg_request->head = NULL;
71 temp_http_msg_request->http_body = NULL;
73 *http_msg_request = temp_http_msg_request;
74 DA_LOGV("http_msg_request: %x", (unsigned int)(*http_msg_request));
79 void http_msg_request_destroy(http_msg_request_t **http_msg_request)
81 http_msg_request_t *temp_http_msg_request = *http_msg_request;
85 if (temp_http_msg_request) {
86 if (temp_http_msg_request->http_method) {
87 free(temp_http_msg_request->http_method);
88 temp_http_msg_request->http_method = NULL;
90 if (temp_http_msg_request->url) {
91 free(temp_http_msg_request->url);
92 temp_http_msg_request->url = NULL;
94 if (temp_http_msg_request->http_body) {
95 free(temp_http_msg_request->http_body);
96 temp_http_msg_request->http_body = NULL;
98 __http_header_destroy_all_field(&(temp_http_msg_request->head));
99 free(*http_msg_request);
100 *http_msg_request = NULL;
104 da_ret_t http_msg_request_set_url(http_msg_request_t *http_msg_request,
109 if (!http_msg_request) {
110 DA_LOGE("http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT");
111 return DA_ERR_INVALID_ARGUMENT;
115 DA_LOGE("url is NULL; DA_ERR_INVALID_ARGUMENT");
116 return DA_ERR_INVALID_URL;
119 http_msg_request->url = strdup(url);
120 DA_SECURE_LOGI("http url[%s]", http_msg_request->url);
124 da_ret_t http_msg_request_get_url(http_msg_request_t *http_msg_request,
129 if (!http_msg_request) {
130 DA_LOGE("http_msg_request is NULL; DA_ERR_INVALID_ARGUMENT");
131 return DA_ERR_INVALID_ARGUMENT;
134 if (http_msg_request->url) {
135 *url = http_msg_request->url;
139 return DA_ERR_INVALID_ARGUMENT;
143 da_ret_t http_msg_request_add_field(http_msg_request_t *http_msg_request,
144 const char *field, const char *value)
148 if (!http_msg_request) {
149 DA_LOGE("Check NULL! : http_msg_request");
150 return DA_ERR_INVALID_ARGUMENT;
153 return __http_header_add_field(&(http_msg_request->head), field, value, WITHOUT_PARSING_OPTION);
156 da_ret_t http_msg_response_create(http_msg_response_t **http_msg_response)
158 http_msg_response_t *temp_http_msg_response = NULL;
162 temp_http_msg_response = (http_msg_response_t *)calloc(1,
163 sizeof(http_msg_response_t));
164 if (!temp_http_msg_response) {
165 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
166 return DA_ERR_FAIL_TO_MEMALLOC;
168 temp_http_msg_response->status_code = 0;
169 temp_http_msg_response->head = NULL;
170 *http_msg_response = temp_http_msg_response;
175 void http_msg_response_destroy(http_msg_response_t **http_msg_response)
177 http_msg_response_t *temp_http_msg_response = *http_msg_response;
180 if (temp_http_msg_response) {
181 __http_header_destroy_all_field(&(temp_http_msg_response->head));
182 free(*http_msg_response);
183 *http_msg_response = DA_NULL;
187 da_ret_t http_msg_response_add_field(http_msg_response_t *http_msg_response,
188 const char *field, const char *value)
192 if (!http_msg_response) {
193 DA_LOGE("DA_ERR_INVALID_ARGUMENT");
194 return DA_ERR_INVALID_ARGUMENT;
196 return __http_header_add_field(&(http_msg_response->head), field, value, WITH_PARSING_OPTION);
199 da_ret_t __http_header_add_field(http_header_t **head,
200 const char *field, const char *value, enum parsing_type type)
202 http_header_t *pre = NULL;
203 http_header_t *cur = NULL;
205 //DA_SECURE_LOGD("[%s][%s]", field, value);
210 /* Replace default value with user wanted value
211 * Remove the value which is stored before and add a new value.
213 if (cur->field && cur->raw_value &&
214 strncasecmp(cur->field, field, strlen(field)) == 0) {
215 DA_SECURE_LOGD("Remove value for replacement [%s][%s]", cur->field, cur->raw_value);
220 if (cur->raw_value) {
221 free(cur->raw_value);
222 cur->raw_value = NULL;
228 cur = (http_header_t *)calloc(1, sizeof(http_header_t));
230 cur->field = strdup(field);
231 cur->raw_value = strdup(value);
235 if (type == WITHOUT_PARSING_OPTION) {
236 cur->value = strdup(value);
239 __parsing_raw_value(cur);
247 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
248 return DA_ERR_FAIL_TO_MEMALLOC;
254 void __http_header_destroy_all_field(http_header_t **head)
256 http_header_t *pre = NULL;
257 http_header_t *cur = NULL;
264 cur->field = DA_NULL;
268 cur->value = DA_NULL;
270 if (cur->raw_value) {
271 free(cur->raw_value);
272 cur->raw_value = DA_NULL;
274 __http_header_destroy_all_option(&(cur->options));
276 cur->options = DA_NULL;
284 http_header_options_t *__create_http_header_option(const char *field,
287 http_header_options_t *option = NULL;
289 option = (http_header_options_t *)calloc(1,
290 sizeof(http_header_options_t));
293 option->field = strdup(field);
295 option->value = strdup(value);
301 void __http_header_destroy_all_option(http_header_options_t **head)
303 http_header_options_t *pre = NULL;
304 http_header_options_t *cur = NULL;
312 DA_SECURE_LOGD("field= %s", cur->field);
314 cur->field = DA_NULL;
318 cur->value = DA_NULL;
327 da_ret_t http_msg_request_get_iter(http_msg_request_t *http_msg_request,
328 http_msg_iter_t *http_msg_iter)
332 if (!http_msg_request) {
333 DA_LOGE("DA_ERR_INVALID_ARGUMENT");
334 return DA_ERR_INVALID_ARGUMENT;
337 *http_msg_iter = http_msg_request->head;
342 da_ret_t http_msg_response_get_iter(http_msg_response_t *http_msg_response,
343 http_msg_iter_t *http_msg_iter)
345 if (!http_msg_response) {
346 DA_LOGE("DA_ERR_INVALID_ARGUMENT");
347 return DA_ERR_INVALID_ARGUMENT;
350 *http_msg_iter = http_msg_response->head;
354 da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter,
355 char **out_field, char **out_value)
357 http_header_t *cur = *http_msg_iter;
360 *out_field = cur->field;
361 *out_value = cur->value;
362 *http_msg_iter = cur->next;
369 da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter,
370 char **out_field, http_header_t **out_header)
372 http_header_t *cur = *http_msg_iter;
375 *out_field = cur->field;
377 *http_msg_iter = cur->next;
384 http_header_options_t *__parsing_N_create_option_str(char *org_str)
386 char *option_field = NULL;
387 char *option_value = NULL;
388 int option_field_len = 0;
389 int option_value_len = 0;
390 char *org_pos = NULL;
392 char *working_str = NULL;
393 char *working_pos = NULL;
394 char *working_pos_field_start = NULL;
395 char *working_pos_value_start = NULL;
396 da_bool_t is_inside_quotation = DA_FALSE;
397 da_bool_t is_working_for_field = DA_TRUE;
399 http_header_options_t *option = NULL;
406 org_str_len = strlen(org_str);
407 if (org_str_len <= 0)
410 working_str = (char *)calloc(1, org_str_len + 1);
415 working_pos_field_start = working_pos = working_str;
417 for (i = 0; i < org_str_len; i++) {
419 is_inside_quotation = !is_inside_quotation;
420 if (is_inside_quotation) {
421 // Leave anything including blank if it is inside of double quotation mark.
422 *working_pos = *org_pos;
423 is_working_for_field ? option_field_len++
424 : option_value_len++;
428 if (*org_pos == ' ') {
430 } else if (*org_pos == '=') {
431 if (is_working_for_field) {
432 is_working_for_field = DA_FALSE;
433 working_pos_value_start = working_pos;
437 *working_pos = *org_pos;
438 is_working_for_field ? option_field_len++
439 : option_value_len++;
446 if (option_field_len > 0 && working_pos_field_start) {
447 option_field = (char *)calloc(1, option_field_len + 1);
449 strncpy(option_field, working_pos_field_start,
452 if (option_value_len > 0 && working_pos_value_start) {
453 option_value = (char *)calloc(1, option_value_len + 1);
455 strncpy(option_value, working_pos_value_start,
460 working_pos = working_str = NULL;
463 DA_SECURE_LOGD("option_field = [%s], option_value = [%s]",
464 option_field ? option_field : "",
465 option_value ? option_value : "");
467 if (option_field || option_value) {
468 option = __create_http_header_option(
469 option_field, option_value);
482 http_header_options_t *__parsing_options(char *org_str)
484 da_ret_t ret = DA_RESULT_OK;
485 http_header_options_t *head = NULL;
486 http_header_options_t *pre = NULL;
487 http_header_options_t *cur = NULL;
489 int wanted_str_len = 0;
490 char *wanted_str = NULL;
491 char *wanted_str_start = NULL;
492 char *wanted_str_end = NULL;
493 char *cur_pos = NULL;
500 /* Do Not use strtok(). It's not thread safe. */
501 // DA_SECURE_LOGD("org_str = %s", org_str);
506 wanted_str_start = cur_pos;
507 wanted_str_end = strchr(cur_pos, ';');
508 if (wanted_str_end) {
509 cur_pos = wanted_str_end + 1;
511 wanted_str_end = org_str + strlen(org_str);
514 wanted_str_len = wanted_str_end - wanted_str_start;
515 wanted_str = (char *)calloc(1, wanted_str_len + 1);
517 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
518 ret = DA_ERR_FAIL_TO_MEMALLOC;
521 strncpy(wanted_str, wanted_str_start, wanted_str_len);
523 // DA_SECURE_LOGD("wanted_str = [%s]", wanted_str);
524 cur = __parsing_N_create_option_str(wanted_str);
537 if (ret != DA_RESULT_OK)
538 __http_header_destroy_all_option(&head);
542 void __parsing_raw_value(http_header_t *http_header_field)
544 char *raw_value = NULL;
545 char *option_str_start = NULL;
546 char *trimed_value = NULL;
547 int trimed_value_len = 0;
548 char *trimed_value_start = NULL;
549 char *trimed_value_end = NULL;
551 raw_value = http_header_field->raw_value;
552 // DA_SECURE_LOGD("raw_value = [%s]", raw_value);
557 trimed_value_start = raw_value;
558 trimed_value_end = strchr(raw_value, ';');
559 if (!trimed_value_end) {
561 http_header_field->value = strdup(raw_value);
562 http_header_field->options = NULL;
568 trimed_value_len = trimed_value_end - trimed_value_start;
569 trimed_value = (char *)calloc(1, trimed_value_len + 1);
571 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
574 strncpy(trimed_value, trimed_value_start, trimed_value_len);
575 http_header_field->value = trimed_value;
577 // for option parsing
578 option_str_start = trimed_value_end + 1;
579 http_header_field->options = __parsing_options(option_str_start);
582 http_header_options_t *cur = NULL;
583 cur = http_header_field->options;
585 // DA_SECURE_LOGD("field = [%s], value = [%s]", cur->field, cur->value);
590 da_bool_t __get_http_header_option_for_field(
591 http_header_options_t *header_option, const char *in_field,
594 http_header_options_t *cur = NULL;
598 if (!header_option) {
599 DA_LOGE("input header_option is NULL.");
606 if (!strncasecmp(cur->field, in_field, strlen(cur->field)) &&
608 DA_SECURE_LOGD("[%s][%s]", cur->field, cur->value);
609 *out_value = cur->value;
619 da_bool_t __get_http_header_for_field(http_msg_response_t *http_msg_response,
620 const char *in_field, http_header_t **out_header)
622 http_msg_iter_t http_msg_iter = DA_NULL;
623 http_header_t *header = NULL;
628 http_msg_response_get_iter(http_msg_response, &http_msg_iter);
629 while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) {
630 if (field && header && !strncasecmp(field, in_field, strlen(field))) {
631 //DA_SECURE_LOGD("[%s][%s]", field, header->value);
632 *out_header = header;
640 da_bool_t __get_http_req_header_for_field(http_msg_request_t *http_msg_request,
641 const char *in_field, http_header_t **out_header)
643 http_msg_iter_t http_msg_iter = DA_NULL;
644 http_header_t *header = NULL;
649 http_msg_request_get_iter(http_msg_request, &http_msg_iter);
650 while (http_msg_get_header_with_iter(&http_msg_iter, &field, &header)) {
651 if (field && header && !strncasecmp(field, in_field, strlen(field))) {
652 //DA_SECURE_LOGD("[%s][%s]", field, header->value);
653 *out_header = header;
661 void __exchange_header_value(http_header_t *header, const char *in_raw_value)
665 if (!header || !in_raw_value)
668 __http_header_destroy_all_option(&(header->options));
672 header->value = DA_NULL;
674 if (header->raw_value)
675 free(header->raw_value);
676 header->raw_value = strdup(in_raw_value);
678 __parsing_raw_value(header);
681 da_bool_t http_msg_response_get_content_type(
682 http_msg_response_t *http_msg_response, char **out_type)
684 da_bool_t b_ret = DA_FALSE;
685 http_header_t *header = NULL;
689 b_ret = __get_http_header_for_field(http_msg_response,
690 HTTP_FIELD_CONTENT_TYPE, &header);
692 DA_LOGV("no Content-Type");
696 *out_type = strdup(header->value);
701 void http_msg_response_set_content_type(http_msg_response_t *http_msg_response,
704 da_bool_t b_ret = DA_FALSE;
705 http_header_t *header = NULL;
709 if (!http_msg_response || !in_type)
712 b_ret = __get_http_header_for_field(http_msg_response,
713 HTTP_FIELD_CONTENT_TYPE, &header);
715 if (header->raw_value && !strcmp(header->raw_value, in_type))
718 DA_SECURE_LOGD("exchange Content-Type to [%s] from [%s]", in_type, header->value);
719 __exchange_header_value(header, in_type);
721 __http_header_add_field(&(http_msg_response->head),
722 HTTP_FIELD_CONTENT_TYPE, in_type, WITH_PARSING_OPTION);
726 da_bool_t http_msg_response_get_content_length(
727 http_msg_response_t *http_msg_response, da_size_t *out_length)
729 da_bool_t b_ret = DA_FALSE;
730 http_header_t *header = NULL;
734 b_ret = __get_http_header_for_field(http_msg_response,
735 HTTP_FIELD_CONTENT_LENGTH, &header);
737 DA_LOGV("no Content-Length");
742 *out_length = atoll(header->value);
747 da_bool_t http_msg_response_get_content_disposition(
748 http_msg_response_t *http_msg_response, http_msg_t *http_msg, char **out_disposition,
749 char **out_file_name)
751 da_bool_t b_ret = DA_FALSE;
752 http_header_t *header = NULL;
753 char *file_name = NULL;
754 char *wanted_str = NULL;
755 char *wanted_str_start = NULL;
756 char *wanted_str_end = NULL;
757 char *decoded_str = NULL;
758 int wanted_str_len = 0;
762 b_ret = __get_http_header_for_field(http_msg_response,
763 HTTP_FIELD_CONTENT_DISPOSITION, &header);
765 DA_LOGV("no Content-Disposition");
769 *out_disposition = strdup(header->value);
773 b_ret = __get_http_header_option_for_field(header->options, "filename",
776 DA_LOGV("no option");
780 // eliminate double quotation mark if it exists on derived value
781 wanted_str_start = strchr(file_name, '"');
782 if (!wanted_str_start) {
783 *out_file_name = strdup(file_name);
786 // DA_SECURE_LOGD("wanted_str_start = [%s]", wanted_str_start);
788 wanted_str_end = strchr(wanted_str_start, '"');
789 if (wanted_str_end) {
790 wanted_str_len = wanted_str_end - wanted_str_start;
791 wanted_str = (char*)calloc(1, wanted_str_len + 1);
793 DA_LOGE("DA_ERR_FAIL_TO_MEMALLOC");
796 strncpy(wanted_str, wanted_str_start, wanted_str_len);
798 b_ret = is_base64_encoded_word(wanted_str);
800 DA_LOGV("It's base64 encoded-word string");
801 if (DA_RESULT_OK == decode_base64_encoded_str(
802 wanted_str, &decoded_str)) {
803 DA_SECURE_LOGD("base64 decoded str = [%s]", decoded_str);
805 wanted_str = decoded_str;
808 DA_LOGV("Fail to base64 decode. Just use un-decoded string.");
811 DA_LOGV("It's NOT base64 encoded-word string");
814 if (http_msg->curl) {
815 decoded_str = curl_easy_unescape(http_msg->curl, wanted_str, wanted_str_len, NULL);
817 CURL* handle = curl_easy_init();
818 decoded_str = curl_easy_unescape(handle, wanted_str, wanted_str_len, NULL);
819 curl_easy_cleanup(handle);
822 /* If it is url encoded string */
825 DA_SECURE_LOGD("Url decoded str = [%s]", decoded_str);
826 file_name = strdup(decoded_str);
827 NULL_CHECK_AND_FREE(wanted_str);
828 curl_free(decoded_str);
831 *out_file_name = file_name;
834 DA_LOGE("Fail to url decode.");
835 NULL_CHECK_AND_FREE(wanted_str);
836 *out_file_name = NULL;
840 DA_LOGE("Not matched \" !");
846 da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response, char **out_value)
848 da_bool_t b_ret = DA_FALSE;
849 http_header_t *header = NULL;
853 b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_ETAG,
860 *out_value = strdup(header->value);
865 da_bool_t http_msg_response_get_cache_control(http_msg_response_t *http_msg_response, char **out_value)
867 da_bool_t b_ret = DA_FALSE;
868 http_header_t *header = NULL;
871 DA_LOGE("[NULL CHECK] out_value");
875 b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_CACHE_CONTROL,
878 DA_LOGV("no cache-control");
883 *out_value = strdup(header->value);
890 da_bool_t http_msg_response_get_last_modified(http_msg_response_t *http_msg_response, char **out_value)
892 da_bool_t b_ret = DA_FALSE;
893 http_header_t *header = NULL;
896 DA_LOGE("[NULL CHECK] out_value");
900 b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_LAST_MODIFIED,
903 DA_LOGV("no last-modified");
907 *out_value = strdup(header->value);
915 da_bool_t http_msg_response_get_RAF_mode(http_msg_response_t *http_msg_response,
918 da_bool_t b_ret = DA_FALSE;
919 http_header_t *header = NULL;
923 b_ret = __get_http_header_for_field(http_msg_response, HTTP_FIELD_RAF_MODE,
926 DA_LOGV("no RAF mode");
930 *out_value = strdup(header->value);
936 da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response,
939 da_bool_t b_ret = DA_FALSE;
940 http_header_t *header = NULL;
944 b_ret = __get_http_header_for_field(http_msg_response,
945 HTTP_FIELD_DATA, &header);
951 *out_value = strdup(header->value);
956 da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response,
959 da_bool_t b_ret = DA_FALSE;
960 http_header_t *header = NULL;
964 b_ret = __get_http_header_for_field(http_msg_response,
965 HTTP_FIELD_LOCATION, &header);
967 DA_LOGV("no Location");
971 *out_value = strdup(header->value);
976 da_bool_t http_msg_response_get_transfer_encoding(http_msg_response_t *http_msg_response,
979 da_bool_t b_ret = DA_FALSE;
980 http_header_t *header = NULL;
984 b_ret = __get_http_header_for_field(http_msg_response,
985 HTTP_FIELD_TRANSFER_ENCODING, &header);
987 DA_LOGE("no Transfer-Encoding");
991 *out_value = strdup(header->value);
996 char *__stristr(const char *long_str, const char *find_str)
1000 int length_find = 0;
1001 char *ret_ptr = NULL;
1002 char *org_ptr = NULL;
1003 char *look_ptr = NULL;
1005 if (long_str == NULL || find_str == NULL) {
1006 DA_LOGE("INVALID ARGUMENT");
1010 length_long = strlen(long_str);
1011 length_find = strlen(find_str);
1013 org_ptr = (char*)calloc(1, length_long + 1);
1015 if (org_ptr == NULL) {
1016 DA_LOGE("INVALID ARGUMENT");
1020 look_ptr = (char*)calloc(1, length_find + 1);
1022 if (look_ptr == NULL) {
1023 DA_LOGE("INVALID ARGUMENT");
1028 while (i < length_long) {
1029 if (isalpha(long_str[i]) != 0) {
1030 if (isupper(long_str[i]) != 0)
1031 org_ptr[i] = long_str[i];
1033 org_ptr[i] = toupper(long_str[i]);
1035 org_ptr[i] = long_str[i];
1042 while (i < length_find) {
1043 if (isalpha(find_str[i]) != 0) {
1044 if (isupper(find_str[i]) != 0)
1045 look_ptr[i] = find_str[i];
1047 look_ptr[i] = toupper(find_str[i]);
1049 look_ptr[i] = find_str[i];
1054 ret_ptr = strstr(org_ptr, look_ptr);
1061 i = ret_ptr - org_ptr;
1067 return (char*)(long_str + i);
1070 /* This is not used. But it can be needed if there is no http header parser at http library.*/
1071 da_bool_t extract_attribute_from_header(
1073 const char *szFindStr,
1076 char *pValuePos = NULL;
1080 int need_to_end_quataion_mark = 0;
1082 if (szHeadStr == DA_NULL || szFindStr == DA_NULL) {
1083 DA_LOGE("INVALID ARGUMENT");
1086 if (strlen(szHeadStr) <= 0 || strlen(szFindStr) <= 0) {
1087 DA_LOGE("INVALID ARGUMENT");;
1091 if (ppRtnValue == NULL)
1094 pValuePos = __stristr(szHeadStr, (char*)szFindStr);
1095 if (pValuePos == NULL) {
1100 index = strlen(szFindStr);
1102 while (pValuePos[index] != ':' && pValuePos[index] != '=') {
1105 if (pValuePos[index] == '\0')
1112 while (pValuePos[index] == ' ')
1115 /* jump quatation mark */
1116 while (pValuePos[index] == '"') {
1117 need_to_end_quataion_mark = 1;
1123 /* Find the end of data.
1124 * terminate character list does not contain ';' in case of URI
1126 if (0 == strncasecmp(szFindStr, HTTP_FIELD_LOCATION, strlen(HTTP_FIELD_LOCATION))) {
1127 while (DA_FALSE == IS_URI_TERMINATING_CHAR(pValuePos[index]))
1129 } else if (need_to_end_quataion_mark) {
1130 while (DA_FALSE == IS_TERMINATING_CHAR_EX(pValuePos[index]))
1133 while (DA_FALSE == IS_TERMINATING_CHAR(pValuePos[index]))
1137 strLen = index - startPos;
1140 DA_LOGE(" strLen is < 1");
1144 *ppRtnValue = (char*)calloc(1, sizeof(char) * (strLen + 1));
1146 if (*ppRtnValue == NULL) {
1147 DA_LOGE(" *ppRtnValue is NULL");
1151 strncpy(*ppRtnValue, pValuePos + startPos, strLen);
1152 *(*ppRtnValue + strLen) = '\0';
1163 da_bool_t http_msg_request_get_if_range(http_msg_request_t *http_msg_request,
1166 da_bool_t b_ret = DA_FALSE;
1167 http_header_t *header = NULL;
1171 b_ret = __get_http_req_header_for_field(http_msg_request, HTTP_FIELD_IF_RANGE,
1174 DA_LOGV("no If Range");
1178 *out_value = strdup(header->value);
1183 da_bool_t http_msg_request_get_range(http_msg_request_t *http_msg_request,
1186 da_bool_t b_ret = DA_FALSE;
1187 http_header_t *header = NULL;
1191 b_ret = __get_http_req_header_for_field(http_msg_request, HTTP_FIELD_RANGE,
1194 DA_LOGV("no Range");
1198 *out_value = strdup(header->value);