1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #include <anna/core/functions.hpp>
39 #include <anna/http/Transport.hpp>
40 #include <anna/http/Message.hpp>
42 #include <anna/http/parser/Abstract.hpp>
43 #include <anna/http/parser/WaitMessage.hpp>
44 #include <anna/http/parser/ReadHeader.hpp>
45 #include <anna/http/parser/WaitEndOfHeader.hpp>
46 #include <anna/http/parser/WaitChunkSize.hpp>
47 #include <anna/http/parser/ReadChunkSize.hpp>
48 #include <anna/http/parser/ReadChunkData.hpp>
49 #include <anna/http/parser/ReadChunkTrailers.hpp>
57 WaitMessage st_waitMessage;
58 ReadHeader st_readHeader;
59 WaitEndOfHeader st_waitEndOfHeader;
60 WaitChunkSize st_waitChunkSize;
61 ReadChunkSize st_readChunkSize;
62 ReadChunkData st_readChunkData;
63 ReadChunkTrailers st_readChunkTrailers;
65 anna_assign_enum(parser::Abstract::ClassType) = {
66 "WaitMessage", "ReadHeader", "WaitEndOfHeader",
67 "WaitChunkSize", "ReadChunkSize", "ReadChunkData", "ReadChunkTrailers", NULL
72 string http::parser::Abstract::asString() const
74 string result("http::parser::Abstract { ");
75 result += ClassType::asCString(a_classType);
76 return result += " }";
81 void http::parser::Abstract::setState(http::Transport& transport, const http::parser::Abstract::ClassType::_v classType)
84 * Se repite el Wait-Message para llenar el hueco de ClassType::None
86 static Abstract* status [] = {
87 &st_waitMessage, &st_readHeader, &st_waitEndOfHeader,
88 &st_waitChunkSize, &st_readChunkSize, &st_readChunkData, &st_readChunkTrailers
90 transport.setParserState(status [classType]);
94 void http::parser::Abstract::appendExtraParameter(http::Message* message, const std::string& extraParameter)
96 message->appendExtraParameter(extraParameter);
100 * Es acumulativo, porque cuando se invoca a
101 * http::parser::ReadChunkData::processLine (http::Transport& transport, const DataBlock& dataBlock, const http::Token& line)
102 * desde http::Transport::calculeSize no se pasa el dataBlock real (con el mensaje completo),
103 * sino que se le pasa el trozo de chunk. Y el cálculo del tamaño de chunk se hace como diferencia de su ubicación al
104 * principio del mensaje;
107 void http::parser::Abstract::setLastChunkedByte(http::Transport& transport, const int lastChunkedByte)
109 transport.a_lastChunkedByte += lastChunkedByte;
112 // Sólo se puede usar en caso de Mensajes Transfer-encoding: chunked
114 const DataBlock& http::parser::Abstract::getFullMessage(http::Transport& transport)
116 return *transport.a_fullMessage;