Remove dynamic exceptions
[anna.git] / example / core / genLogon / 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 <functional>
12
13 #include <anna/core/core.hpp>
14
15 #include <anna/xml/Node.hpp>
16 #include <anna/xml/Compiler.hpp>
17
18 #include <anna/app/Application.hpp>
19
20 #include <anna/core/util/Encoder.hpp>
21
22 class Test : public app::Application {
23 public:
24    Test ();
25    
26    void initialize () noexcept(false);
27    
28 private:
29    void  run () noexcept(false);      
30 };
31
32 using namespace std;
33
34 int main (int argc, const char** argv)
35 {
36    CommandLine& commandLine (CommandLine::instantiate ());
37    Test test;
38
39    try {
40       commandLine.initialize (argv, argc);
41       commandLine.verify ();
42
43       test.start ();
44    }
45    catch (Exception& ex) {
46       cout << ex.asString () << endl;
47    }
48    
49    return 0;
50 }
51
52 Test::Test () : 
53    app::Application ("GenerateLogOn", "Database login encrypt keys generator", "1.0.0")
54 {
55    CommandLine& commandLine (CommandLine::instantiate ());
56       
57    commandLine.add ("user", CommandLine::Argument::Mandatory, "User name"); 
58    commandLine.add ("pwd", CommandLine::Argument::Mandatory, "Password");
59    commandLine.add ("v", CommandLine::Argument::Optional, "Show original key in output file", false);
60 }
61
62 void Test::initialize () 
63    noexcept(false)
64 {
65    Encoder::initialize ();
66 }
67
68 void Test::run () 
69    noexcept(false)
70 {
71    CommandLine& commandLine (CommandLine::instantiate ());
72
73    string user (commandLine.getValue ("user"));
74    string password (commandLine.getValue ("pwd"));
75    const bool verbose = commandLine.exists ("v");
76
77    Encoder encoder;
78    xml::Node root ("Logon");
79
80    const EncodedData& euser = encoder.encode (user);
81
82    xml::Node* node = root.createChild ("User");
83
84    if (verbose)
85       node->createAttribute ("PlainText", user);
86
87    euser.asXML (node);
88
89    const EncodedData& epassword = encoder.encode (password);
90
91    node = root.createChild ("Password");
92
93    if (verbose)
94       node->createAttribute ("PlainText", password);
95
96    epassword.asXML (node);
97
98    xml::Compiler xmlCompiler;
99
100    cerr << xmlCompiler.apply (&root) << endl << endl;
101 }
102