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.
17 #ifndef _Download_Agent_Http_Msg_Handler_H
18 #define _Download_Agent_Http_Msg_Handler_H
20 #include "download-agent-type.h"
22 #define HTTP_FIELD_UAGENT "User-Agent"
23 #define HTTP_FIELD_HOST "Host"
24 #define HTTP_FIELD_UAPROF "X-Wap-Profile"
25 #define HTTP_FIELD_CONTENT_LENGTH "Content-Length"
26 #define HTTP_FIELD_CONTENT_TYPE "Content-Type"
27 #define HTTP_FIELD_IF_MATCH "If-Match"
28 #define HTTP_FIELD_RANGE "Range"
29 #define HTTP_FIELD_IF_RANGE "If-Range"
30 #define HTTP_FIELD_ACCEPT_LANGUAGE "Accept-Language"
31 #define HTTP_FIELD_ACCEPT_CHARSET "Accept-Charset"
33 typedef struct _http_header_options_t http_header_options_t;
34 struct _http_header_options_t{
38 http_header_options_t *next;
41 typedef struct _http_header_t http_header_t;
42 struct _http_header_t{
45 http_header_options_t *options;
47 char *raw_value; // raw string including options
65 typedef http_header_t *http_msg_iter_t;
69 http_msg_request_t *http_msg_request;
70 http_msg_response_t *http_msg_response;
74 da_result_t http_msg_request_create(http_msg_request_t **http_msg_request);
75 void http_msg_request_destroy(http_msg_request_t **http_msg_request);
77 da_result_t http_msg_request_set_method(http_msg_request_t *http_msg_request, const char *method);
78 da_result_t http_msg_request_get_method(http_msg_request_t *http_msg_request, const char **method);
80 da_result_t http_msg_request_set_url(http_msg_request_t *http_msg_request, const char *url);
81 da_result_t http_msg_request_get_url(http_msg_request_t *http_msg_request, const char **url);
83 da_result_t http_msg_request_set_body(http_msg_request_t *http_msg_request, const char *body);
84 da_result_t http_msg_request_get_body(http_msg_request_t *http_msg_request, const char **body);
86 da_result_t http_msg_request_add_field(http_msg_request_t *http_msg_request, const char *field, const char *value);
89 da_result_t http_msg_response_create(http_msg_response_t **http_msg_response);
90 void http_msg_response_destroy(http_msg_response_t **http_msg_response);
92 da_result_t http_msg_response_set_status_code(http_msg_response_t *http_msg_response, int status_code);
93 da_result_t http_msg_response_get_status_code(http_msg_response_t *http_msg_response, int *status_code);
95 da_result_t http_msg_response_add_field(http_msg_response_t *http_msg_response, const char *field, const char *value);
97 /* Caution! Caller must free memory for every "char** out_xxx" for followings */
98 da_bool_t http_msg_response_get_content_type(http_msg_response_t *http_msg_response, char **out_type);
99 void http_msg_response_set_content_type(http_msg_response_t *http_msg_response, const char *in_type);
101 da_bool_t http_msg_response_get_content_length(http_msg_response_t *http_msg_response, unsigned long long *out_length);
102 da_bool_t http_msg_response_get_content_disposition(http_msg_response_t *http_msg_response, char **out_disposition, char **out_file_name);
103 da_bool_t http_msg_response_get_ETag(http_msg_response_t *http_msg_response, char **out_value);
104 da_bool_t http_msg_response_get_date(http_msg_response_t *http_msg_response, char **out_value);
105 da_bool_t http_msg_response_get_location(http_msg_response_t *http_msg_response, char **out_value);
106 // should be refactored later
107 da_result_t http_msg_response_get_boundary(http_msg_response_t *http_msg_response, char **out_val);
110 da_result_t http_msg_request_get_iter(http_msg_request_t *http_msg_request, http_msg_iter_t *http_msg_iter);
111 da_result_t http_msg_response_get_iter(http_msg_response_t *http_msg_response, http_msg_iter_t *http_msg_iter);
113 // should remove later
114 da_bool_t http_msg_get_field_with_iter(http_msg_iter_t *http_msg_iter, char **field, char **value);
115 da_bool_t http_msg_get_header_with_iter(http_msg_iter_t *http_msg_iter, char **out_field, http_header_t **out_header);
117 char *get_http_response_header_raw(http_msg_response_t *http_msg_response);
119 da_bool_t extract_attribute_from_header(char *szHeadStr, const char *szFindStr, char **ppRtnValue);
120 #endif // _Download_Agent_Http_Msg_Handler_H