8 |
|
#include "Collector.hpp" |
9 |
|
#include "Publisher.hpp" |
10 |
|
|
11 |
+ |
#include <menes-api/exename.hpp> |
12 |
+ |
#include <menes-app/application.hpp> |
13 |
+ |
|
14 |
|
#include <algorithm> |
15 |
|
#include <cstring> |
16 |
|
#include <iterator> |
22 |
|
#include <unistd.h> |
23 |
|
} |
24 |
|
|
25 |
< |
int zoe(const std::vector<const char*> args) |
25 |
> |
struct ZoeCommand : public app::Application |
26 |
|
{ |
27 |
< |
Zoe::program = args[0]; |
25 |
< |
|
26 |
< |
for (int index(1); index < args.size(); ++index) |
27 |
> |
virtual int Run(const app::ArgumentList& args) |
28 |
|
{ |
29 |
< |
ext::String arg(args[index]); |
29 |
< |
Matcher matcher; |
29 |
> |
Zoe::program = api::GetExecutableName(); |
30 |
|
|
31 |
< |
if (arg == matcher("^-config=(.*)$")) |
32 |
< |
{ |
33 |
< |
Zoe::config = matcher[1]; |
34 |
< |
} |
35 |
< |
else if (arg == "-collector") |
36 |
< |
{ |
37 |
< |
if (!Zoe::collector) Zoe::collector = true; |
38 |
< |
} |
39 |
< |
else if (arg == "-publisher") |
40 |
< |
{ |
41 |
< |
if (!Zoe::publisher) Zoe::publisher = true; |
42 |
< |
} |
43 |
< |
else if (arg == "-color") |
44 |
< |
{ |
45 |
< |
if (!Zoe::color) Zoe::color = true; |
46 |
< |
} |
47 |
< |
else if (arg == "-D") |
31 |
> |
for (size_t index(0); index < args.GetSize(); ++index) |
32 |
|
{ |
33 |
< |
if (!Zoe::debug) Zoe::debug = true; |
34 |
< |
} |
51 |
< |
else Zoe::usage(); |
52 |
< |
} |
33 |
> |
ext::String arg(args[index]); |
34 |
> |
Matcher matcher; |
35 |
|
|
36 |
< |
Zoe zoe; |
37 |
< |
|
38 |
< |
return 0; |
39 |
< |
} |
36 |
> |
if (arg == matcher("^-config=(.*)$")) |
37 |
> |
{ |
38 |
> |
Zoe::config = matcher[1]; |
39 |
> |
} |
40 |
> |
else if (arg == "-collector") |
41 |
> |
{ |
42 |
> |
if (!Zoe::collector) Zoe::collector = true; |
43 |
> |
} |
44 |
> |
else if (arg == "-publisher") |
45 |
> |
{ |
46 |
> |
if (!Zoe::publisher) Zoe::publisher = true; |
47 |
> |
} |
48 |
> |
else if (arg == "-color") |
49 |
> |
{ |
50 |
> |
if (!Zoe::color) Zoe::color = true; |
51 |
> |
} |
52 |
> |
else if (arg == "-D") |
53 |
> |
{ |
54 |
> |
if (!Zoe::debug) Zoe::debug = true; |
55 |
> |
} |
56 |
> |
else Zoe::usage(); |
57 |
> |
} |
58 |
|
|
59 |
< |
int main(int argc, char* argv[]) |
60 |
< |
{ |
61 |
< |
std::vector<const char*> args(argv, argv + argc); |
59 |
> |
Zoe zoe; |
60 |
|
|
61 |
< |
return app::be::ThreadMain_(etl::BindAll(&zoe, args)); |
62 |
< |
} |
61 |
> |
return 0; |
62 |
> |
} |
63 |
> |
} zoe; |
64 |
|
|
65 |
|
Zoe::Zoe() |
66 |
|
{ |
74 |
|
} |
75 |
|
|
76 |
|
bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false), |
77 |
< |
Zoe::color(false); |
77 |
> |
Zoe::color(false); |
78 |
|
ext::String Zoe::program, Zoe::config("zoe.xml"); |
79 |
|
|
80 |
|
void Zoe::usage() |
99 |
|
|
100 |
|
uname(&system); |
101 |
|
|
102 |
< |
generator_.InsertAllLast(_S(" (") + system.sysname); |
102 |
> |
generator_.InsertAllLast(_R(" (") + system.sysname); |
103 |
|
} |
104 |
|
|
105 |
|
if (generator == agent) |
129 |
|
ext::Handle<xml::Document> document(xml::Parse(config)); |
130 |
|
ext::Handle<xml::Node> zoe(*document/"zoe"); |
131 |
|
|
132 |
< |
login = std::string(*zoe/"login"); |
133 |
< |
password = std::string(*zoe/"password"); |
134 |
< |
database.driver = std::string(*zoe/"database"/"driver"); |
135 |
< |
database.host = std::string(*zoe/"database"/"host"); |
136 |
< |
database.user = std::string(*zoe/"database"/"user"); |
132 |
> |
login = *zoe/"login"; |
133 |
> |
password = *zoe/"password"; |
134 |
> |
database.driver = *zoe/"database"/"driver"; |
135 |
> |
database.host = *zoe/"database"/"host"; |
136 |
> |
database.user = *zoe/"database"/"user"; |
137 |
|
|
138 |
|
if ((*zoe/"database"/"password").IsEmpty()) |
139 |
|
{ |
147 |
|
for (size_t index(std::strlen(password)); index > 0; --index) |
148 |
|
password[index - 1] = '\0'; |
149 |
|
} |
150 |
< |
else database.password = std::string(*zoe/"database"/"password"); |
150 |
> |
else database.password = *zoe/"database"/"password"; |
151 |
|
|
152 |
< |
database.db = std::string(*zoe/"database"/"db"); |
152 |
> |
database.db = *zoe/"database"/"db"; |
153 |
|
|
154 |
|
if (debug) cerr << "login = " << login << "\npassword = " |
155 |
|
<< std::string(password.GetSize(), '*') << "\ndatabase = {\n" |
156 |
< |
<< " driver = " << database.driver << "\n host=" << database.host |
156 |
> |
<< " driver = " << database.driver << "\n host = " << database.host |
157 |
|
<< "\n user = " << database.user << '\n' |
158 |
|
<< " password = " << std::string(database.password.GetSize(), '*') |
159 |
|
<< "\n db = " << database.db << "\n}\n"; |
160 |
|
|
161 |
< |
std::string link(*zoe/"link"); |
161 |
> |
ext::String link(*zoe/"link"); |
162 |
|
xml::NodeSet buddies(*zoe/"buddy"); |
163 |
|
|
164 |
|
for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End(); |
166 |
|
{ |
167 |
|
Buddy buddy_(**buddy/"login", **buddy/"rss", **buddy/"atom", |
168 |
|
!(**buddy/"link").IsEmpty() ? **buddy/"link" : (link |
169 |
< |
+ std::string(**buddy/"login") + ".html")); |
169 |
> |
+ ext::String(**buddy/"login") + ".html")); |
170 |
|
|
171 |
|
this->buddies.insert(buddy_); |
172 |
|
} |
193 |
|
|
194 |
|
void Zoe::initialize() |
195 |
|
{ |
196 |
< |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, |
196 |
> |
ext::Handle<dbi::Driver> driver(dbi::GetDriver(database.driver)); |
197 |
> |
ext::Handle<dbi::Connection> db(driver->Connect(database.host, |
198 |
|
database.user, database.password, database.db)); |
199 |
|
ext::Handle<dbi::ResultSet> buddies(db->Execute("SELECT * FROM buddies")); |
200 |
|
std::set<Buddy> buddies_; |