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 main(int argc, char* argv[]) |
25 |
> |
struct ZoeCommand : public app::Application |
26 |
|
{ |
27 |
< |
Zoe::program = argv[0]; |
25 |
< |
|
26 |
< |
for (int index(1); index < argc; ++index) |
27 |
> |
virtual int Run(const app::ArgumentList& args) |
28 |
|
{ |
29 |
< |
ext::String arg(argv[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") |
31 |
> |
for (size_t index(0); index < args.GetSize(); ++index) |
32 |
|
{ |
33 |
< |
if (!Zoe::publisher) Zoe::publisher = true; |
33 |
> |
ext::String arg(args[index]); |
34 |
> |
Matcher matcher; |
35 |
> |
|
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 |
|
} |
43 |
– |
else if (arg == "-color") |
44 |
– |
{ |
45 |
– |
if (!Zoe::color) Zoe::color = true; |
46 |
– |
} |
47 |
– |
else if (arg == "-D") |
48 |
– |
{ |
49 |
– |
if (!Zoe::debug) Zoe::debug = true; |
50 |
– |
} |
51 |
– |
else |
52 |
– |
{ |
53 |
– |
cerr << "Usage: " << Zoe::program << " [-config=config] " |
54 |
– |
"[-collector] [-publisher] [-color] [-D]\n"; |
58 |
|
|
59 |
< |
return 1; |
57 |
< |
} |
58 |
< |
} |
59 |
< |
|
60 |
< |
Zoe zoe; |
59 |
> |
Zoe zoe; |
60 |
|
|
61 |
< |
return 0; |
62 |
< |
} |
61 |
> |
return 0; |
62 |
> |
} |
63 |
> |
} zoe; |
64 |
|
|
65 |
|
Zoe::Zoe() |
66 |
|
{ |
67 |
+ |
if (!(collector || publisher)) usage(); |
68 |
+ |
|
69 |
|
configure(); |
70 |
|
initialize(); |
71 |
|
|
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() |
81 |
+ |
{ |
82 |
+ |
cerr << "Usage: " << Zoe::program << " [-config=config] [-collector] " |
83 |
+ |
"[-publisher] [-color] [-D]\n"; |
84 |
+ |
|
85 |
+ |
exit(1); |
86 |
+ |
} |
87 |
+ |
|
88 |
|
ext::String Zoe::generator(Generator generator) |
89 |
|
{ |
90 |
|
ext::String generator_(generator == all || generator == agent ? "Zoe" : ""); |
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(); |
165 |
|
++buddy) |
166 |
|
{ |
167 |
|
Buddy buddy_(**buddy/"login", **buddy/"rss", **buddy/"atom", |
168 |
< |
!(**buddy/"link").IsEmpty() ? **buddy/"link" : link); |
168 |
> |
!(**buddy/"link").IsEmpty() ? **buddy/"link" : (link |
169 |
> |
+ ext::String(**buddy/"login") + ".html")); |
170 |
|
|
171 |
|
this->buddies.insert(buddy_); |
172 |
|
} |
186 |
|
cerr << "}\n"; |
187 |
|
} |
188 |
|
|
178 |
– |
if (!collector && !publisher) { collector = true; publisher = true; } |
179 |
– |
|
189 |
|
if (debug) cerr << "collector = " << lexical_cast<ext::String>(collector) |
190 |
|
<< "\npublisher = " << lexical_cast<ext::String>(publisher) |
191 |
|
<< "\ncolor = " << lexical_cast<ext::String>(color) << '\n'; |
200 |
|
|
201 |
|
while (buddies->MoveNext()) |
202 |
|
{ |
203 |
< |
Buddy buddy(*this->buddies.find(buddies->GetString("buddy"))); |
203 |
> |
if (this->buddies.find(buddies->GetString("buddy")) != this->buddies.end()) |
204 |
> |
{ |
205 |
> |
Buddy buddy(*this->buddies.find(buddies->GetString("buddy"))); |
206 |
|
|
207 |
< |
buddy.setId(lexical_cast<ext::Uuid>(buddies->GetString("id"))); |
208 |
< |
buddies_.insert(buddy); |
207 |
> |
buddy.setId(lexical_cast<ext::Uuid>(buddies->GetString("id"))); |
208 |
> |
buddies_.insert(buddy); |
209 |
> |
} |
210 |
|
} |
211 |
|
|
212 |
|
std::vector<Buddy> difference; |