14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#ifndef NET_TOOLS_BALSA_BALSA_VISITOR_INTERFACE_H_ 64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define NET_TOOLS_BALSA_BALSA_VISITOR_INTERFACE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <cstddef> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BalsaFrame; 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BalsaHeaders; 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// By default the BalsaFrame instantiates a class derived from this interface 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// which does absolutely nothing. If you'd prefer to have interesting 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// functionality execute when any of the below functions are called by the 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BalsaFrame, then you should subclass it, and set an instantiation of your 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// subclass as the current visitor for the BalsaFrame class using 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BalsaFrame::set_visitor(). 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BalsaVisitorInterface { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~BalsaVisitorInterface() {} 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is how the BalsaFrame passes you the raw input which it knows to 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be a part of the body. To be clear, every byte of the Balsa which isn't 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // part of the header (or its framing), or trailers will be passed through 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this function. This includes data as well as chunking framing. 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // input - contains the bytes available for read. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // size - contains the number of bytes it is safe to read from input. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessBodyInput(const char *input, size_t size) = 0; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is like ProcessBodyInput, but it will only include those parts of 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the body which would be stored by a program such as wget, i.e. the bytes 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // indicating chunking (it will have been omitted). Trailers will not be 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // passed in through this function-- they'll be passed in through 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ProcessTrailers. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // input - contains the bytes available for read. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // size - contains the number of bytes it is safe to read from input. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessBodyData(const char *input, size_t size) = 0; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // BalsaFrame passes the raw header data through this function. This is 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not cleaned up in any way. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // input - contains the bytes available for read. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // size - contains the number of bytes it is safe to read from input. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessHeaderInput(const char *input, size_t size) = 0; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // BalsaFrame passes the raw trailer data through this function. This is 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not cleaned up in any way. Note that trailers only occur in a message 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if there was a chunked encoding, and not always then. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // input - contains the bytes available for read. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // size - contains the number of bytes it is safe to read from input. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessTrailerInput(const char *input, size_t size) = 0; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Since the BalsaFrame already has to parse the headers in order to 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // determine proper framing, it might as well pass the parsed and 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cleaned-up results to whatever might need it. This function exists for 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that purpose-- parsed headers are passed into this function. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // headers - contains the parsed headers in the order in which 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // they occured in the header. 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessHeaders(const BalsaHeaders& headers) = 0; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the first line of the message is parsed, in this case, for a 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request. 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // line_input - pointer to the beginning of the first line string. 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // line_length - length of the first line string. (i.e. the numer of 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bytes it is safe to read from line_ptr) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // method_input - pointer to the beginning of the method string 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // method_length - length of the method string (i.e. the number 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of bytes it is safe to read from method_input) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request_uri_input - pointer to the beginning of the request uri 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // string. 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request_uri_length - length of the method string (i.e. the number 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of bytes it is safe to read from method_input) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // version_input - pointer to the beginning of the version string. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // version_length - length of the version string (i.e. the number 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of bytes it i ssafe to read from version_input) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessRequestFirstLine(const char* line_input, 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t line_length, 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* method_input, 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t method_length, 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* request_uri_input, 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t request_uri_length, 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* version_input, 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t version_length) = 0; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the first line of the message is parsed, in this case, for a 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // line_input - pointer to the beginning of the first line string. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // line_length - length of the first line string. (i.e. the numer of 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bytes it is safe to read from line_ptr) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // version_input - pointer to the beginning of the version string. 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // version_length - length of the version string (i.e. the number 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of bytes it i ssafe to read from version_input) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // status_input - pointer to the beginning of the status string 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // status_length - length of the status string (i.e. the number 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of bytes it is safe to read from status_input) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reason_input - pointer to the beginning of the reason string 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reason_length - length of the reason string (i.e. the number 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of bytes it is safe to read from reason_input) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessResponseFirstLine(const char *line_input, 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t line_length, 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *version_input, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t version_length, 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *status_input, 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t status_length, 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *reason_input, 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t reason_length) = 0; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when a chunk length is parsed. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chunk length - the length of the next incoming chunk. 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessChunkLength(size_t chunk_length) = 0; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // BalsaFrame passes the raw chunk extension data through this function. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The data is not cleaned up at all, use 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // BalsaFrame::ProcessChunkExtentions to get the parsed and cleaned up 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chunk extensions. 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // input - contains the bytes available for read. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // size - contains the number of bytes it is safe to read from input. 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProcessChunkExtensions(const char* input, size_t size) = 0; 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the header is framed and processed. 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void HeaderDone() = 0; 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the message is framed and processed. 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void MessageDone() = 0; 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when an error is detected while parsing the header. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // framer - the framer in which an error occured. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void HandleHeaderError(BalsaFrame* framer) = 0; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when something meriting a warning is detected while 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // parsing the header. 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // framer - the framer in which an error occured. 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void HandleHeaderWarning(BalsaFrame* framer) = 0; 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when an error is detected while parsing a chunk. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // framer - the framer in which an error occured. 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void HandleChunkingError(BalsaFrame* framer) = 0; 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Summary: 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when an error is detected while handling the entity-body. 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Currently, this can only be called when there is an error 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // with the BytesSpliced() function, but in the future other interesting 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // errors could occur. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Arguments: 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // framer - the framer in which an error occured. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void HandleBodyError(BalsaFrame* framer) = 0; 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif // NET_TOOLS_BALSA_BALSA_VISITOR_INTERFACE_H_ 181