Remove dynamic exceptions
[anna.git] / source / http / parser / Abstract.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #include <anna/core/functions.hpp>
10
11 #include <anna/http/Transport.hpp>
12 #include <anna/http/Message.hpp>
13
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>
22
23 using namespace std;
24 using namespace anna;
25
26 namespace anna {
27 namespace http {
28 namespace parser {
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;
36 }
37 anna_assign_enum(parser::Abstract::ClassType) = {
38   "WaitMessage", "ReadHeader", "WaitEndOfHeader",
39   "WaitChunkSize", "ReadChunkSize", "ReadChunkData", "ReadChunkTrailers", NULL
40 };
41 }
42 }
43
44 string http::parser::Abstract::asString() const
45 {
46   string result("http::parser::Abstract { ");
47   result += ClassType::asCString(a_classType);
48   return result += " }";
49 }
50
51
52 /*static*/
53 void http::parser::Abstract::setState(http::Transport& transport, const http::parser::Abstract::ClassType::_v classType)
54 {
55   /*
56    * Se repite el Wait-Message para llenar el hueco de ClassType::None
57    */
58   static Abstract* status [] =  {
59     &st_waitMessage, &st_readHeader, &st_waitEndOfHeader,
60     &st_waitChunkSize, &st_readChunkSize, &st_readChunkData, &st_readChunkTrailers
61   };
62   transport.setParserState(status [classType]);
63 }
64
65 /*static*/
66 void http::parser::Abstract::appendExtraParameter(http::Message* message, const std::string& extraParameter)
67 {
68   message->appendExtraParameter(extraParameter);
69 }
70
71 /*
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;
77  */
78 /*static*/
79 void http::parser::Abstract::setLastChunkedByte(http::Transport& transport, const int lastChunkedByte)
80 {
81   transport.a_lastChunkedByte += lastChunkedByte;
82 }
83
84 // Sólo se puede usar en caso de Mensajes Transfer-encoding: chunked
85 /*static*/
86 const DataBlock& http::parser::Abstract::getFullMessage(http::Transport& transport)
87 {
88   return *transport.a_fullMessage;
89 }
90
91