/[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 182 by twoaday, Tue Mar 14 11:02:32 2006 UTC
# Line 1  Line 1 
1  /* wptHttp.h - Generic HTTP code  /* wptHttp.h - Generic HTTP code
2   *      Copyright (C) 2004, 2005 Timo Schulz   *      Copyright (C) 2004, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 21  Line 21 
21  #ifndef WPT_HTTP_H  #ifndef WPT_HTTP_H
22  #define WPT_HTTP_H  #define WPT_HTTP_H
23    
 #ifdef __cplusplus  
 extern "C" {  
 #endif  
   
 /* HTTP methods. */  
 enum http_types_t {  
     HTTP_NONE = 0,  
     HTTP_GET,  
     HTTP_POST,  
 };  
   
24  /* HTTP status codes. */  /* HTTP status codes. */
25  enum http_statcode_t {  enum http_statcode_t {
26      HTTP_STAT_NONE = 0,      HTTP_STAT_NONE = 0,
27      HTTP_STAT_200 = 200,  /* OK */      HTTP_STAT_200 = 200,  /* OK */
28        HTTP_STAT_201 = 201,  /* Created */
29      HTTP_STAT_301 = 301,  /* Moved Permanently */      HTTP_STAT_301 = 301,  /* Moved Permanently */
30      HTTP_STAT_302 = 302,  /* Moved Temporarily */      HTTP_STAT_302 = 302,  /* Moved Temporarily */
31      HTTP_STAT_400 = 400,  /* Bad Request */      HTTP_STAT_400 = 400,  /* Bad Request */
32        HTTP_STAT_401 = 401,  /* Unauthorized */
33      HTTP_STAT_403 = 403,  /* Forbidden */      HTTP_STAT_403 = 403,  /* Forbidden */
34      HTTP_STAT_404 = 404,  /* Not Found */      HTTP_STAT_404 = 404,  /* Not Found */
35      HTTP_STAT_405 = 405,  /* Method Not Allowed */      HTTP_STAT_405 = 405,  /* Method Not Allowed */
36  };  };
37    
38    
39  /* HTTP header list. */  /* HTTP header list. */
40  struct http_head_s {  struct http_head_s {
41      struct http_head_s * next;      struct http_head_s * next;
42      int flags;      int flags;
43      char d[1];      char d[1];
44  };  };
45  typedef struct http_head_s * http_head_t;  typedef struct http_head_s *http_head_t;
46    
47  /* HTTP handle. */  class wHTTP {
48  struct http_hd_s {  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;      int fd;
56      http_head_t head;        int statcode;
57  };      char *host;
58  typedef struct http_hd_s * http_hd_t;      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  /* HTTP request. */      int get (const char *url);
97  struct http_req_s {      int head (const char *url);
     int type;  
     http_head_t head;  
     char * url;    
98  };  };
 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  
99    
100  #endif /* WPT_HTTP_H */  #endif /* WPT_HTTP_H */

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26