~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/nwg/shl/HttpProto.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
12
// - special damages arising in any way out of the use of this software.     -
13
13
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2007 amaury darsch                                   -
 
14
// - copyright (c) 1999-2011 amaury darsch                                   -
15
15
// ---------------------------------------------------------------------------
16
16
 
17
17
#ifndef  AFNIX_HTTPPROTO_HPP
21
21
#include "Plist.hpp"
22
22
#endif
23
23
 
24
 
#ifndef  AFNIX_BUFFER_HPP
25
 
#include "Buffer.hpp"
 
24
#ifndef  AFNIX_BLOCKBUFFER_HPP
 
25
#include "BlockBuffer.hpp"
26
26
#endif
27
27
 
28
28
namespace afnix {
29
29
 
30
30
  /// the HttpProto class is a base class that ease the deployement of the
31
31
  /// http protocol. The base class is built with a property list which is
32
 
  /// used to define the message header. The class alo defines the write
 
32
  /// used to define the message header. The class also defines the write
33
33
  /// methods which are used to write a message either on an output stream
34
34
  /// or into a buffer.
35
35
  /// @author amaury darsch
36
36
 
37
37
  class HttpProto : public virtual Object {
38
38
  public:
39
 
    /// map a http status code
 
39
    /// the protocol object type
 
40
    enum t_ptyp {
 
41
      HTTP_SERVER, // protocol server side
 
42
      HTTP_CLIENT  // protocol client side
 
43
    };
 
44
 
 
45
    /// the header field
 
46
    enum t_hfld {
 
47
      HEAD_ACPT, // Accept
 
48
      HEAD_ACHS, // Accept-Charset
 
49
      HEAD_AENC, // Accept-Encoding
 
50
      HEAD_ALNG, // Accept-Language
 
51
      HEAD_ARNG, // Accept-Ranges
 
52
      HEAD_BAGE, // Age
 
53
      HEAD_ALOW, // Allow
 
54
      HEAD_AUTH, // Authorization
 
55
      HEAD_CCTL, // Cache-Control
 
56
      HEAD_CONN, // Connection
 
57
      HEAD_CENC, // Content-Encoding
 
58
      HEAD_CLNG, // Content-Language
 
59
      HEAD_CLEN, // Content-Length
 
60
      HEAD_CLOC, // Content-Location
 
61
      HEAD_CMD5, // Content-MD5
 
62
      HEAD_CRNG, // Content-Range
 
63
      HEAD_CTYP, // Content-Type
 
64
      HEAD_DATE, // Date
 
65
      HEAD_ETAG, // ETag
 
66
      HEAD_EXPT, // Expect
 
67
      HEAD_EXPR, // Expires
 
68
      HEAD_FROM, // From
 
69
      HEAD_HOST, // Host
 
70
      HEAD_IFMT, // If-Match
 
71
      HEAD_IFMS, // If-Modified-Since
 
72
      HEAD_IFNM, // If-None-Match
 
73
      HEAD_IFRG, // If-Range
 
74
      HEAD_IFUS, // If-Unmodified-Since
 
75
      HEAD_LMOD, // Last-Modified
 
76
      HEAD_MLOC, // Location
 
77
      HEAD_MFWD, // Max-Forwards
 
78
      HEAD_PRGM, // Pragma
 
79
      HEAD_PXTH, // Proxy-Authenticate
 
80
      HEAD_PXAT, // Proxy-Authorization
 
81
      HEAD_BRNG, // Range
 
82
      HEAD_REFR, // Referer
 
83
      HEAD_RAFT, // Retry-After
 
84
      HEAD_SERV, // Server
 
85
      HEAD_BDTE, // TE
 
86
      HEAD_TRLR, // Trailer
 
87
      HEAD_TENC, // Transfer-Encoding
 
88
      HEAD_UPGR, // Upgrade
 
89
      HEAD_UAGT, // User-Agent
 
90
      HEAD_VARY, // Vary
 
91
      HEAD_RVIA, // Via
 
92
      HEAD_WRNG, // Warning
 
93
      HEAD_WWWA, // WWW-Authenticate
 
94
      HEAD_COK0, // Set-Cookie
 
95
      HEAD_COK1  // Set-Cookie2
 
96
    };
 
97
 
 
98
    /// @return the default http version
 
99
    static String getxdef (void);
 
100
 
 
101
    /// map a header field to a string
 
102
    /// @param hflg the header field to map
 
103
    static String hfldtos (const t_hfld hfld);
 
104
 
 
105
    /// map a http status code to a string
40
106
    /// @param code the code to map
41
 
    static String mapcode (const long code);
 
107
    static String codetos (const long code);
42
108
 
43
109
  protected:
44
 
    /// the http plist
45
 
    Plist d_head;
 
110
    /// the protocol version
 
111
    String d_vers;
 
112
    /// the protocol type
 
113
    t_ptyp d_ptyp;
 
114
    /// the http header list
 
115
    Plist  d_head;
46
116
 
47
117
  public:
48
 
    /// set a header property
 
118
    /// create a default http protocol
 
119
    HttpProto (void);
 
120
 
 
121
    /// create a default http protocol by type
 
122
    /// @param ptyp the protocol type
 
123
    HttpProto (const t_ptyp ptyp);
 
124
 
 
125
    /// copy construct this http protocol
 
126
    /// @param that the object to copy
 
127
    HttpProto (const HttpProto& that);
 
128
 
 
129
    /// assign a http protocol to this one
 
130
    /// @param that the object to assign
 
131
    HttpProto& operator = (const HttpProto& that);
 
132
 
 
133
    /// reset this protocol object
 
134
    virtual void reset (void);
 
135
 
 
136
    /// parse an input stream
 
137
    /// @param is the input stream to parse
 
138
    virtual void parse (InputStream& is) =0;
 
139
 
 
140
    /// set the protocol version
 
141
    /// @param vers the version to set
 
142
    virtual void setvers (const String& vers);
 
143
 
 
144
    /// @return the protocol version
 
145
    virtual String getvers (void) const;
 
146
 
 
147
    /// @return the header length
 
148
    virtual long hlength (void) const;
 
149
    
 
150
    /// @return true if a header property exists
 
151
    virtual bool hexists (const String& name) const;
 
152
 
 
153
    /// @return true if a header property exists by field
 
154
    virtual bool hexists (const t_hfld hfld) const;
 
155
    
 
156
    /// set a header property by name and litteral
49
157
    /// @param name the property name
50
158
    /// @param lval the property value
51
 
    virtual void sethead (const String& name, const Literal& pval);
 
159
    virtual void hset (const String& name, const Literal& pval);
 
160
 
 
161
    /// set a header property by field and litteral
 
162
    /// @param hfld the header field
 
163
    /// @param lval the property value
 
164
    virtual void hset (const t_hfld hfld, const Literal& pval);
 
165
 
 
166
    /// @return a header property by index
 
167
    virtual Property* hget (const long index) const;
 
168
 
 
169
    /// @return a header property by name
 
170
    virtual Property* hfind (const String& name) const;
 
171
 
 
172
    /// @return a header property by field
 
173
    virtual Property* hfind (const t_hfld hfld) const;
 
174
 
 
175
    /// @return a header property by name or throw an exception
 
176
    virtual Property* hlookup (const String& name) const;
 
177
    
 
178
    /// @return a header property by field or throw an exception
 
179
    virtual Property* hlookup (const t_hfld hfld) const;
 
180
 
 
181
    /// @return a header property value by name
 
182
    virtual String hmap (const String& name) const;
 
183
 
 
184
    /// @return a header property value by field
 
185
    virtual String hmap (const t_hfld hfld) const;
 
186
 
 
187
    /// @return true if the media type is defined
 
188
    virtual bool ismedia (void) const;
 
189
 
 
190
    /// @return the response media type
 
191
    virtual String getmedia (void) const;
 
192
 
 
193
    /// @return true if the encoding mode is defined
 
194
    virtual bool isemod (void) const;
 
195
 
 
196
    /// @return the response encoding mode
 
197
    virtual String getemod (void) const;
 
198
 
 
199
    /// @return true if the content length is defined
 
200
    virtual bool isclen (void) const;
 
201
 
 
202
    /// @return the header content length
 
203
    virtual long getclen (void) const;
 
204
 
 
205
    /// get the content string
 
206
    /// @param is the input stream to parse
 
207
    virtual String getcstr (InputStream& is);
 
208
 
 
209
    /// parse a header from an input stream 
 
210
    /// @param is the input stream to parse
 
211
    virtual void hparse (InputStream& is);
52
212
 
53
213
    /// write the http header to an output stream
54
214
    /// @param os the output stream
55
 
    virtual void write (Output& os) const;
 
215
    virtual void write (OutputStream& os) const;
56
216
 
57
217
    /// write the http header to a buffer
58
218
    /// @param buf the target buffer