OSDN Git Service

Experimental: support ipv6.
[ntch/develop.git] / src / inc / net / nt_http.h
1 /* Copyright 2013 Akira Ohta (akohta001@gmail.com)
2     This file is part of ntch.
3
4     The ntch is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8
9     The ntch is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with ntch.  If not, see <http://www.gnu.org/licenses/>.
16     
17 */
18 #ifndef _NT_HTTP_H_
19 #define _NT_HTTP_H_
20
21 #include "net/nt_cookie.h"
22
23 #define SSL_FLAG 1
24 #define GZIP_FLAG 2
25 #define CHUNKED_FLAG 4
26 #define RANGE_FLAG 8
27 #define SET_FLAG(a,b) ((a)->flags  |= (b))
28 #define CLR_FLAG(a,b) ((a)->flags  &= ~(b))
29 #define IS_SET_FLAG(a,b) ((a)->flags & (b))
30
31 #define HTTP_RESPONCE_HEADER_BUFFER_LEN  256
32
33 #define USER_AGENT "Monazilla/1.00 (monaweb/1.00) ntch for GNU/Linux"
34
35 #define CONTENT_TYPE_ZIP 1
36 #define CONTENT_TYPE_TEXT 2 
37
38 typedef struct tag_nt_http_header_t *nt_http_header_tp;
39 typedef struct tag_nt_http_header_t {
40         int port;
41         char *host;
42         char *param;
43         char *last_modified;
44         size_t fsize;
45         unsigned int flags;
46 }nt_http_header_t;
47
48
49 typedef struct tag_nt_http_response_header_t 
50         *nt_http_response_header_tp;
51 typedef struct tag_nt_http_response_header_t {
52         char    *status_text;
53         int             status_code;
54         char    *last_modified;
55         int     content_length;
56         int     flags;
57 }nt_http_response_header_t;
58
59 extern BOOL nt_http_post(const char *url, 
60                 const char *post_data,
61                 char *out_buf, size_t out_buf_len,
62                 const char *referer, const char *user_agent, 
63                 nt_link_tp headers, nt_cookie_tp cookiep);
64 extern int nt_http_post2(const char *url, 
65                 const char *post_data,
66                 char *out_buf, size_t out_buf_len,
67                 const char *referer, const char *user_agent, 
68                 nt_link_tp headers, nt_cookie_tp cookiep);
69 extern BOOL nt_http_get(const char *url, const char *out_path,
70                 const char *referer, const char *user_agent, 
71                 nt_link_tp headers, BOOL range, BOOL ignore_cache);
72 extern int nt_http_parse_response_header(int readfd,
73                 nt_http_response_header_tp responsep,
74                 nt_cookie_tp cookeip, const char *host);
75 extern int nt_http_parse_response_header2(
76                         const char *data, size_t data_len,
77                         nt_http_response_header_tp responsep);
78 extern nt_http_response_header_tp nt_http_alloc_response_header();
79 extern void nt_http_free_response_header(
80                 nt_http_response_header_tp responsep);
81 extern BOOL nt_http_save_response_header(const char *out_path,
82                 nt_http_response_header_tp responsep);
83 extern BOOL nt_parse_server_name_and_board_name(const wchar_t *url,
84         wchar_t *buf, size_t buf_size, wchar_t **server_name,
85         wchar_t **board_name);
86 extern wchar_t* nt_rid_sufix(const wchar_t *file_name);
87 extern BOOL nt_is_ipv6_addr(const char *addr, char **endp);
88 extern BOOL url_encode(const char *src, char *out_buf, size_t out_buf_len);
89 extern BOOL url_decode(const char *src, char *out_buf, size_t out_buf_len);
90 #endif /* _NT_HTTP_H_ */