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