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

Annotation of /trunk/Include/wptHTTP.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 312 - (hide annotations)
Sun May 13 09:43:33 2007 UTC (17 years, 9 months ago) by twoaday
File MIME type: text/plain
File size: 2845 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26