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

Diff of /trunk/Include/wptHTTP.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 37 by werner, Thu Oct 27 19:12:40 2005 UTC revision 312 by twoaday, Sun May 13 09:43:33 2007 UTC
# Line 1  Line 1 
1  /* wptHttp.h - Generic HTTP code  /* wptHTTP.h - Generic network code for HTTP access
2   *      Copyright (C) 2004, 2005 Timo Schulz   *      Copyright (C) 2004, 2005, 2006, 2007 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   * General Public License for more details.   * General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
15   */   */
   
16  #ifndef WPT_HTTP_H  #ifndef WPT_HTTP_H
17  #define WPT_HTTP_H  #define WPT_HTTP_H
18    
 #ifdef __cplusplus  
 extern "C" {  
 #endif  
   
 /* HTTP methods. */  
 enum http_types_t {  
     HTTP_NONE = 0,  
     HTTP_GET,  
     HTTP_POST,  
 };  
   
19  /* HTTP status codes. */  /* HTTP status codes. */
20  enum http_statcode_t {  enum http_statcode_t {
21      HTTP_STAT_NONE = 0,      HTTP_STAT_NONE = 0,
22      HTTP_STAT_200 = 200,  /* OK */      HTTP_STAT_200 = 200,  /* OK */
23        HTTP_STAT_201 = 201,  /* Created */
24      HTTP_STAT_301 = 301,  /* Moved Permanently */      HTTP_STAT_301 = 301,  /* Moved Permanently */
25      HTTP_STAT_302 = 302,  /* Moved Temporarily */      HTTP_STAT_302 = 302,  /* Moved Temporarily */
26      HTTP_STAT_400 = 400,  /* Bad Request */      HTTP_STAT_400 = 400,  /* Bad Request */
27        HTTP_STAT_401 = 401,  /* Unauthorized */
28      HTTP_STAT_403 = 403,  /* Forbidden */      HTTP_STAT_403 = 403,  /* Forbidden */
29      HTTP_STAT_404 = 404,  /* Not Found */      HTTP_STAT_404 = 404,  /* Not Found */
30      HTTP_STAT_405 = 405,  /* Method Not Allowed */      HTTP_STAT_405 = 405,  /* Method Not Allowed */
31  };  };
32    
33    
34  /* HTTP header list. */  /* HTTP header list. */
35  struct http_head_s {  struct http_head_s {
36      struct http_head_s * next;      struct http_head_s *next;
     int flags;  
37      char d[1];      char d[1];
38  };  };
39  typedef struct http_head_s * http_head_t;  typedef struct http_head_s *http_head_t;
40    
41  /* HTTP handle. */  class NetHTTP {
42  struct http_hd_s {  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      int fd;      int fd;
50      http_head_t head;        int statcode;
51  };      char *host;
52  typedef struct http_hd_s * http_hd_t;      int port;
53        char *url;
54        int nleft;
55        int method;
56        int ver;
57        int error;
58    
59    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    
70        int extractHostInfo (const char *url, char **host, char **new_url);
71        int sendRequest (const char *host, int port, const char *url);
72    
73    public:
74        NetHTTP ();
75        NetHTTP (const char *url);
76        NetHTTP (const char *host, int port, const char *url);
77        ~NetHTTP ();
78        
79        void setVersion (int ver);
80        int getErrorCode (void);
81        int getStatusCode (void);
82        unsigned int getContentLength (void);
83        const char *getContentType (void);
84    
85        int addRequestHeader (const char *name, const char *val);
86        int addRequestHeader (const char *name, unsigned int val);
87        
88        int open (const char *url);
89        int write (const void *buf, unsigned int buflen);
90        int read (void *buf, unsigned int buflen);
91        int readData (FILE *out);
92    
93  /* HTTP request. */      int get (const char *url);
94  struct http_req_s {      int head (const char *url);
     int type;  
     http_head_t head;  
     char * url;    
95  };  };
 typedef struct http_req_s * http_req_t;  
   
 int http_send_request (const char * host, int port, const char* url,  
                        http_hd_t * r_hd);  
 int http_send_request2 (const char * url, http_hd_t * r_hd);  
 int http_parse_response (http_hd_t hd, int * statcode);  
 int http_parse_data (http_hd_t hd, FILE * out);  
 int http_hd_new (http_hd_t * hd);  
 void http_hd_free (http_hd_t hd);  
 int http_req_new (http_req_t * ctx);  
 void http_req_free (http_req_t ctx);  
 int http_parse_request (http_hd_t hd, http_req_t * r_req);  
   
 #ifdef __cplusplus  
 }  
 #endif  
96    
97  #endif /* WPT_HTTP_H */  #endif /* WPT_HTTP_H */

Legend:
Removed from v.37  
changed lines
  Added in v.312

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26