balsa_visitor_interface.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_TOOLS_FLIP_SERVER_BALSA_VISITOR_INTERFACE_H_
6#define NET_TOOLS_FLIP_SERVER_BALSA_VISITOR_INTERFACE_H_
7#pragma once
8
9#include <cstddef>
10
11namespace net {
12
13class BalsaFrame;
14class BalsaHeaders;
15
16// By default the BalsaFrame instantiates a class derived from this interface
17// which does absolutely nothing. If you'd prefer to have interesting
18// functionality execute when any of the below functions are called by the
19// BalsaFrame, then you should subclass it, and set an instantiation of your
20// subclass as the current visitor for the BalsaFrame class using
21// BalsaFrame::set_visitor().
22class BalsaVisitorInterface {
23 public:
24  virtual ~BalsaVisitorInterface() {}
25
26  // Summary:
27  //   This is how the BalsaFrame passes you the raw input which it knows to
28  //   be a part of the body. To be clear, every byte of the Balsa which isn't
29  //   part of the header (or it's framing), or trailers will be passed through
30  //   this function.  This includes data as well as chunking framing.
31  // Arguments:
32  //   input - contains the bytes available for read.
33  //   size - contains the number of bytes it is safe to read from input.
34  virtual void ProcessBodyInput(const char *input, size_t size) = 0;
35
36  // Summary:
37  //   This is like ProcessBodyInput, but it will only include those parts of
38  //   the body which would be stored by a program such as wget, i.e. the bytes
39  //   indicating chunking (it will have been omitted). Trailers will not be
40  //   passed in through this function-- they'll be passed in through
41  //   ProcessTrailers.
42  // Arguments:
43  //  input - contains the bytes available for read.
44  //  size - contains the number of bytes it is safe to read from input.
45  virtual void ProcessBodyData(const char *input, size_t size) = 0;
46
47  // Summary:
48  //   BalsaFrame passes the raw header data through this function. This is
49  //   not cleaned up in any way.
50  // Arguments:
51  //  input - contains the bytes available for read.
52  //  size - contains the number of bytes it is safe to read from input.
53  virtual void ProcessHeaderInput(const char *input, size_t size) = 0;
54
55  // Summary:
56  //   BalsaFrame passes the raw trailer data through this function. This is
57  //   not cleaned up in any way.  Note that trailers only occur in a message
58  //   if there was a chunked encoding, and not always then.
59  //
60  // Arguments:
61  //  input - contains the bytes available for read.
62  //  size - contains the number of bytes it is safe to read from input.
63  virtual void ProcessTrailerInput(const char *input, size_t size) = 0;
64
65  // Summary:
66  //   Since the BalsaFrame already has to parse the headers in order to
67  //   determine proper framing, it might as well pass the parsed and
68  //   cleaned-up results to whatever might need it.  This function exists for
69  //   that purpose-- parsed headers are passed into this function.
70  // Arguments:
71  //   headers - contains the parsed headers in the order in which
72  //             they occured in the header.
73  virtual void ProcessHeaders(const BalsaHeaders& headers) = 0;
74
75  // Summary:
76  //   Called when the first line of the message is parsed, in this case, for a
77  //   request.
78  // Arguments:
79  //   line_input - pointer to the beginning of the first line string.
80  //   line_length - length of the first line string. (i.e. the numer of
81  //                 bytes it is safe to read from line_ptr)
82  //   method_input - pointer to the beginning of the method string
83  //   method_length - length of the method string (i.e. the number
84  //                   of bytes it is safe to read from method_input)
85  //   request_uri_input - pointer to the beginning of the request uri
86  //                       string.
87  //   request_uri_length - length of the method string (i.e. the number
88  //                        of bytes it is safe to read from method_input)
89  //   version_input - pointer to the beginning of the version string.
90  //   version_length - length of the version string (i.e. the number
91  //                    of bytes it i ssafe to read from version_input)
92  virtual void ProcessRequestFirstLine(const char* line_input,
93                                       size_t line_length,
94                                       const char* method_input,
95                                       size_t method_length,
96                                       const char* request_uri_input,
97                                       size_t request_uri_length,
98                                       const char* version_input,
99                                       size_t version_length) = 0;
100
101  // Summary:
102  //   Called when the first line of the message is parsed, in this case, for a
103  //   response.
104  // Arguments:
105  //   line_input - pointer to the beginning of the first line string.
106  //   line_length - length of the first line string. (i.e. the numer of
107  //                 bytes it is safe to read from line_ptr)
108  //   version_input - pointer to the beginning of the version string.
109  //   version_length - length of the version string (i.e. the number
110  //                    of bytes it i ssafe to read from version_input)
111  //   status_input - pointer to the beginning of the status string
112  //   status_length - length of the status string (i.e. the number
113  //                   of bytes it is safe to read from status_input)
114  //   reason_input - pointer to the beginning of the reason string
115  //   reason_length - length of the reason string (i.e. the number
116  //                   of bytes it is safe to read from reason_input)
117  virtual void ProcessResponseFirstLine(const char *line_input,
118                                        size_t line_length,
119                                        const char *version_input,
120                                        size_t version_length,
121                                        const char *status_input,
122                                        size_t status_length,
123                                        const char *reason_input,
124                                        size_t reason_length) = 0;
125
126  // Called when a chunk length is parsed.
127  // Arguments:
128  //   chunk length - the length of the next incoming chunk.
129  virtual void ProcessChunkLength(size_t chunk_length) = 0;
130
131  // Summary:
132  //   BalsaFrame passes the raw chunk extension data through this function.
133  //   The data is not cleaned up at all, use
134  //   BalsaFrame::ProcessChunkExtentions to get the parsed and cleaned up
135  //   chunk extensions.
136  //
137  // Arguments:
138  //  input - contains the bytes available for read.
139  //  size - contains the number of bytes it is safe to read from input.
140  virtual void ProcessChunkExtensions(const char* input, size_t size) = 0;
141
142  // Summary:
143  //   Called when the header is framed and processed.
144  virtual void HeaderDone() = 0;
145
146  // Summary:
147  //   Called when the message is framed and processed.
148  virtual void MessageDone() = 0;
149
150  // Summary:
151  //   Called when an error is detected while parsing the header.
152  // Arguments:
153  //   framer - the framer in which an error occured.
154  virtual void HandleHeaderError(BalsaFrame* framer) = 0;
155
156  // Summary:
157  //   Called when something meriting a warning is detected while
158  //   parsing the header.
159  // Arguments:
160  //   framer - the framer in which an error occured.
161  virtual void HandleHeaderWarning(BalsaFrame* framer) = 0;
162
163  // Summary:
164  //   Called when an error is detected while parsing a chunk.
165  // Arguments:
166  //   framer - the framer in which an error occured.
167  virtual void HandleChunkingError(BalsaFrame* framer) = 0;
168
169  // Summary:
170  //   Called when an error is detected while handling the entity-body.
171  //   Currently, this can only be called when there is an error
172  //   with the BytesSpliced() function, but in the future other interesting
173  //   errors could occur.
174  // Arguments:
175  //   framer - the framer in which an error occured.
176  virtual void HandleBodyError(BalsaFrame* framer) = 0;
177};
178
179}  // namespace net
180
181#endif  // NET_TOOLS_FLIP_SERVER_BALSA_VISITOR_INTERFACE_H_
182
183