1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/functions.hpp>
11 #include <anna/http/Transport.hpp>
12 #include <anna/http/Message.hpp>
14 #include <anna/http/parser/Abstract.hpp>
15 #include <anna/http/parser/WaitMessage.hpp>
16 #include <anna/http/parser/ReadHeader.hpp>
17 #include <anna/http/parser/WaitEndOfHeader.hpp>
18 #include <anna/http/parser/WaitChunkSize.hpp>
19 #include <anna/http/parser/ReadChunkSize.hpp>
20 #include <anna/http/parser/ReadChunkData.hpp>
21 #include <anna/http/parser/ReadChunkTrailers.hpp>
29 WaitMessage st_waitMessage;
30 ReadHeader st_readHeader;
31 WaitEndOfHeader st_waitEndOfHeader;
32 WaitChunkSize st_waitChunkSize;
33 ReadChunkSize st_readChunkSize;
34 ReadChunkData st_readChunkData;
35 ReadChunkTrailers st_readChunkTrailers;
37 anna_assign_enum(parser::Abstract::ClassType) = {
38 "WaitMessage", "ReadHeader", "WaitEndOfHeader",
39 "WaitChunkSize", "ReadChunkSize", "ReadChunkData", "ReadChunkTrailers", NULL
44 string http::parser::Abstract::asString() const
46 string result("http::parser::Abstract { ");
47 result += ClassType::asCString(a_classType);
48 return result += " }";
53 void http::parser::Abstract::setState(http::Transport& transport, const http::parser::Abstract::ClassType::_v classType)
56 * Se repite el Wait-Message para llenar el hueco de ClassType::None
58 static Abstract* status [] = {
59 &st_waitMessage, &st_readHeader, &st_waitEndOfHeader,
60 &st_waitChunkSize, &st_readChunkSize, &st_readChunkData, &st_readChunkTrailers
62 transport.setParserState(status [classType]);
66 void http::parser::Abstract::appendExtraParameter(http::Message* message, const std::string& extraParameter)
68 message->appendExtraParameter(extraParameter);
72 * Es acumulativo, porque cuando se invoca a
73 * http::parser::ReadChunkData::processLine (http::Transport& transport, const DataBlock& dataBlock, const http::Token& line)
74 * desde http::Transport::calculeSize no se pasa el dataBlock real (con el mensaje completo),
75 * 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
76 * principio del mensaje;
79 void http::parser::Abstract::setLastChunkedByte(http::Transport& transport, const int lastChunkedByte)
81 transport.a_lastChunkedByte += lastChunkedByte;
84 // Sólo se puede usar en caso de Mensajes Transfer-encoding: chunked
86 const DataBlock& http::parser::Abstract::getFullMessage(http::Transport& transport)
88 return *transport.a_fullMessage;