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

Contents of /trunk/Include/wptHTTP.h

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26