Tizen 2.1 base
[platform/framework/web/download-provider.git] / src / agent / include / download-agent-http-msg-handler.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef _Download_Agent_Http_Msg_Handler_H
18 #define _Download_Agent_Http_Msg_Handler_H
19
20 #include "download-agent-type.h"
21
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"
32
33 typedef struct _http_header_options_t http_header_options_t;
34 struct _http_header_options_t{
35         char *field;
36         char *value;
37
38         http_header_options_t *next;
39 };
40
41 typedef struct _http_header_t http_header_t;
42 struct _http_header_t{
43         char *field;
44         char *value;
45         http_header_options_t *options;
46
47         char *raw_value; // raw string including options
48
49         http_header_t *next;
50 };
51
52 typedef struct{
53         char *http_method;
54         char *url;
55         http_header_t *head;
56         char *http_body;
57 }http_msg_request_t;
58
59
60 typedef struct{
61         int status_code;
62         http_header_t *head;
63 }http_msg_response_t;
64
65 typedef http_header_t *http_msg_iter_t;
66
67
68 typedef struct{
69         http_msg_request_t *http_msg_request;
70         http_msg_response_t *http_msg_response;
71 }http_info_t;
72
73
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);
76
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);
79
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);
82
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);
85
86 da_result_t http_msg_request_add_field(http_msg_request_t *http_msg_request, const char *field, const char *value);
87
88
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);
91
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);
94
95 da_result_t http_msg_response_add_field(http_msg_response_t *http_msg_response, const char *field, const char *value);
96
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);
100
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);
108
109
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);
112
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);
116
117 char *get_http_response_header_raw(http_msg_response_t *http_msg_response);
118
119 da_bool_t extract_attribute_from_header(char *szHeadStr, const char *szFindStr, char **ppRtnValue);
120 #endif // _Download_Agent_Http_Msg_Handler_H