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