1 |
/* wptHttp.h - Generic HTTP code |
2 |
* Copyright (C) 2004, 2005 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU General Public License |
8 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
10 |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#ifndef WPT_HTTP_H |
22 |
#define WPT_HTTP_H |
23 |
|
24 |
#ifdef __cplusplus |
25 |
extern "C" { |
26 |
#endif |
27 |
|
28 |
/* HTTP methods. */ |
29 |
enum http_types_t { |
30 |
HTTP_NONE = 0, |
31 |
HTTP_GET, |
32 |
HTTP_POST, |
33 |
}; |
34 |
|
35 |
/* HTTP status codes. */ |
36 |
enum http_statcode_t { |
37 |
HTTP_STAT_NONE = 0, |
38 |
HTTP_STAT_200 = 200, /* OK */ |
39 |
HTTP_STAT_301 = 301, /* Moved Permanently */ |
40 |
HTTP_STAT_302 = 302, /* Moved Temporarily */ |
41 |
HTTP_STAT_400 = 400, /* Bad Request */ |
42 |
HTTP_STAT_403 = 403, /* Forbidden */ |
43 |
HTTP_STAT_404 = 404, /* Not Found */ |
44 |
HTTP_STAT_405 = 405, /* Method Not Allowed */ |
45 |
}; |
46 |
|
47 |
/* HTTP header list. */ |
48 |
struct http_head_s { |
49 |
struct http_head_s * next; |
50 |
int flags; |
51 |
char d[1]; |
52 |
}; |
53 |
typedef struct http_head_s * http_head_t; |
54 |
|
55 |
/* HTTP handle. */ |
56 |
struct http_hd_s { |
57 |
int fd; |
58 |
http_head_t head; |
59 |
}; |
60 |
typedef struct http_hd_s * http_hd_t; |
61 |
|
62 |
/* HTTP request. */ |
63 |
struct http_req_s { |
64 |
int type; |
65 |
http_head_t head; |
66 |
char * url; |
67 |
}; |
68 |
typedef struct http_req_s * http_req_t; |
69 |
|
70 |
int http_send_request (const char * host, int port, const char* url, |
71 |
http_hd_t * r_hd); |
72 |
int http_send_request2 (const char * url, http_hd_t * r_hd); |
73 |
int http_parse_response (http_hd_t hd, int * statcode); |
74 |
int http_parse_data (http_hd_t hd, FILE * out); |
75 |
int http_hd_new (http_hd_t * hd); |
76 |
void http_hd_free (http_hd_t hd); |
77 |
int http_req_new (http_req_t * ctx); |
78 |
void http_req_free (http_req_t ctx); |
79 |
int http_parse_request (http_hd_t hd, http_req_t * r_req); |
80 |
|
81 |
#ifdef __cplusplus |
82 |
} |
83 |
#endif |
84 |
|
85 |
#endif /* WPT_HTTP_H */ |