1 |
// Represent |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "Hexadecimal.hpp" |
8 |
|
9 |
#include <menes-api/environment.hpp> |
10 |
#include <menes-app/simple.hpp> |
11 |
|
12 |
struct Environment |
13 |
{ |
14 |
ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } } |
15 |
} env; |
16 |
|
17 |
int Main(const app::Options& options) |
18 |
{ |
19 |
Represent represent; |
20 |
|
21 |
return 0; |
22 |
} |
23 |
|
24 |
Represent::Represent() |
25 |
{ |
26 |
parse(); |
27 |
|
28 |
api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush; |
29 |
|
30 |
xml::TextWriter xhtml(api::Cout); |
31 |
xml::ScopeElement table(xhtml, "table"); |
32 |
|
33 |
{ |
34 |
xml::ScopeElement tr(xhtml, "tr"); |
35 |
ext::String headings[] = { "Type", "Data Representation", "Storage" }; |
36 |
|
37 |
_foru (index, 0, sizeof (headings) / sizeof (ext::String)) |
38 |
{ |
39 |
xml::ScopeElement th(xhtml, "th"); |
40 |
|
41 |
xhtml.OutputText(headings[index]); |
42 |
} |
43 |
} |
44 |
} |
45 |
|
46 |
void Represent::parse() |
47 |
{ |
48 |
ext::String query(env.get("QUERY_STRING")); |
49 |
|
50 |
if (env.get("REQUEST_METHOD") == "POST") |
51 |
{ |
52 |
ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH"))); |
53 |
|
54 |
api::Cin.ReadFully(content.Begin(), content.GetSize()); |
55 |
|
56 |
query = content; |
57 |
} |
58 |
|
59 |
ext::Vector<ext::String> pairs(query.Split('&')); |
60 |
|
61 |
_foreach (ext::Vector<ext::String>, pair, pairs) |
62 |
{ |
63 |
ext::String::ConstIterator equal(pair->FindFirst('=')); |
64 |
ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End()); |
65 |
|
66 |
cgi.insert(std::pair<std::string, std::string>(name, value)); |
67 |
} |
68 |
} |