Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / example / http / buffer / main.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 <iostream>
10
11 #include <anna/core/core.hpp>
12
13 #include <anna/io/BinaryReader.hpp>
14
15 #include <anna/http/Transport.hpp>
16 #include <anna/http/Message.hpp>
17
18 using namespace std;
19
20 int main (int argc, const char** argv)
21 {
22    CommandLine& commandLine (CommandLine::instantiate ());
23    io::BinaryReader reader (32 * 1024);
24    DataBlock contain (true);
25    const DataBlock* block;
26    http::Transport transport;
27    const http::Message* message;
28
29    Logger::setLevel (Logger::Debug);
30    Logger::initialize ("ims_buffer", new TraceWriter ("file.trace", 4096000));
31    
32    try {
33       commandLine.add ("f", CommandLine::Argument::Mandatory, "Nombre del fichero a interpretar");
34
35       commandLine.initialize (argv, argc);
36       commandLine.verify ();
37
38       // Lee el contenido del fichero indicado y lo guarda en el buffer 
39       reader.open (commandLine.getValue ("f"));
40       while ((block = reader.fetch ()) != NULL)
41          contain += *block;
42
43       const char* buffer = contain.getData ();
44       const int length = contain.getSize ();
45
46       message = transport.externalDecode (buffer, length);
47
48       cout << message->asString () << endl;
49
50       for (http::Message::const_header_iterator ii = message->header_begin (), maxii = message->header_end (); ii != maxii; ii ++) 
51          cout << "\t" << http::Message::header (ii)->asString () << endl;
52       cout << functions::asString (message->getBody ()) << endl << endl;
53    }
54    catch (Exception& ex) {
55       cout << ex.asString () << endl << endl;
56    }
57    
58    return 0;
59 }