/[winpt]/trunk/Include/wptHTTP.h
ViewVC logotype

Contents of /trunk/Include/wptHTTP.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 182 - (show annotations)
Tue Mar 14 11:02:32 2006 UTC (18 years, 11 months ago) by twoaday
File MIME type: text/plain
File size: 2957 byte(s)


1 /* wptHttp.h - Generic HTTP code
2 * Copyright (C) 2004, 2005, 2006 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 /* HTTP status codes. */
25 enum http_statcode_t {
26 HTTP_STAT_NONE = 0,
27 HTTP_STAT_200 = 200, /* OK */
28 HTTP_STAT_201 = 201, /* Created */
29 HTTP_STAT_301 = 301, /* Moved Permanently */
30 HTTP_STAT_302 = 302, /* Moved Temporarily */
31 HTTP_STAT_400 = 400, /* Bad Request */
32 HTTP_STAT_401 = 401, /* Unauthorized */
33 HTTP_STAT_403 = 403, /* Forbidden */
34 HTTP_STAT_404 = 404, /* Not Found */
35 HTTP_STAT_405 = 405, /* Method Not Allowed */
36 };
37
38
39 /* HTTP header list. */
40 struct http_head_s {
41 struct http_head_s * next;
42 int flags;
43 char d[1];
44 };
45 typedef struct http_head_s *http_head_t;
46
47 class wHTTP {
48 public:
49 /* HTTP methods. */
50 enum { HTTP_GET, HTTP_HEAD, HTTP_PUT, HTTP_POST };
51
52 private:
53 http_head_t req_headers;
54 http_head_t resp_headers;
55 int fd;
56 int statcode;
57 char *host;
58 int port;
59 char *url;
60 int nleft;
61 int method;
62 int ver;
63
64 private:
65 void reset (void);
66 int parseResponse (int *statcode);
67 int connect (const char *host, int port);
68 int isDataAvailable (int fd);
69 int readLine (char *buf, unsigned int nbuf, int nonblock, int *nn, int *eof);
70 void addHeader (http_head_t *root, const char *val);
71 bool findHeader (http_head_t root,
72 const char *name, const char **val);
73 int parseHeaders (http_head_t *r_head);
74
75 int extractHostInfo (const char *url, char **host, char **new_url);
76 int sendRequest (const char *host, int port, const char *url);
77
78 public:
79 wHTTP ();
80 wHTTP (const char *url);
81 wHTTP (const char *host, int port, const char *url);
82 ~wHTTP ();
83
84 void setVersion (int ver);
85 int getStatusCode (void);
86 unsigned int getContentLength (void);
87 const char *getContentType (void);
88
89 int addRequestHeader (const char *name, const char *val);
90 int addRequestHeader (const char *name, unsigned int val);
91
92 int write (const void *buf, unsigned int buflen);
93 int read (void *buf, unsigned int buflen);
94 int readData (FILE *out);
95
96 int get (const char *url);
97 int head (const char *url);
98 };
99
100 #endif /* WPT_HTTP_H */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26