Remove dynamic exceptions
[anna.git] / source / http / internal / EncodedBlock.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 <string.h>
10 #include <stdlib.h>
11
12 #include <anna/config/defines.hpp>
13 #include <anna/core/functions.hpp>
14 #include <anna/core/tracing/Logger.hpp>
15
16 #include <anna/http/internal/EncodedBlock.hpp>
17
18 using namespace std;
19 using namespace anna;
20
21 /*
22  * Esta clase va guardando los trozos del mensaje que recibe, hasta que llega el momento
23  * en que considera que el Bloque está comnpleto, y entonces lo pasa al bloque principal.
24  */
25 http::EncodedBlock::State::_v http::EncodedBlock::append(const DataBlock& chunk)
26 {
27   const int left = a_expectedSize - a_chunk.getSize();
28   State::_v result(State::Incomplete);
29
30   if(left >= chunk.getSize()) {
31     a_chunk += chunk;
32   } else if(left > 0) {
33     DataBlock tmp(chunk.getData(), left, false);
34     a_chunk += tmp;
35   }
36
37   if(a_chunk.getSize() == a_expectedSize) {
38     LOGDEBUG(
39       string msg("http::EncodedBlock | ");
40       msg += anna::functions::asString(chunk, 24);
41       Logger::debug(msg, ANNA_FILE_LOCATION);
42     );
43     *this += a_chunk;
44     a_chunk.clear();
45     a_expectedSize = -1;
46     result = State::Completed;
47   }
48
49   return result;
50 }