4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
+ |
#include "AwayMessage.hpp" |
8 |
|
#include "Collector.hpp" |
9 |
+ |
#include "Stamp.hpp" |
10 |
|
|
11 |
|
#include <cstring> |
12 |
+ |
|
13 |
+ |
extern "C" |
14 |
+ |
{ |
15 |
|
#include <pwd.h> |
16 |
|
#include <unistd.h> |
17 |
+ |
} |
18 |
|
|
19 |
|
Collector::Collector(const ext::String& login, ext::String& password, const |
20 |
< |
std::set<Buddy>& buddies, bool start) : login(login), password(password), |
21 |
< |
buddies(buddies), start(start), prompted(false) |
20 |
> |
std::set<Buddy>& buddies, const Database& database, bool start) : |
21 |
> |
login(login), password(password), buddies(buddies), database(database), |
22 |
> |
start(start), prompted(false) |
23 |
|
{ |
24 |
|
if (start) |
25 |
|
{ |
31 |
|
|
32 |
|
int Collector::collect() |
33 |
|
{ |
34 |
< |
cerr << "Collector::collect()\n"; |
34 |
> |
cerr << bright << green << "Collector::collect()\n" << reset; |
35 |
|
|
36 |
|
net::Oscar::Session session; |
37 |
|
net::Oscar::AuthTool auth(session); |
46 |
|
|
47 |
|
this->buddy = &buddy; |
48 |
|
this->icbm = &icbm; |
49 |
+ |
this->info = &info; |
50 |
|
|
51 |
< |
// buddy.OnOnline += etl::Bind<0>(&Collector::status, this); |
52 |
< |
icbm.OnReceive += etl::Bind<0>(&Collector::reply, this); |
51 |
> |
buddy.OnOnline += etl::Bind<0>(&Collector::status, this); |
52 |
> |
icbm.OnReceive += etl::Bind<0>(&Collector::receive, this); |
53 |
|
|
54 |
|
net::Oscar::StringSet buddies; |
55 |
|
|
78 |
|
|
79 |
|
this->password = password; |
80 |
|
|
81 |
< |
for (size_t index(strlen(password)); index > 0; --index) password[index - |
82 |
< |
1] = '\0'; |
81 |
> |
for (size_t index(std::strlen(password)); index > 0; --index) |
82 |
> |
password[index - 1] = '\0'; |
83 |
|
} |
84 |
|
|
85 |
< |
void Collector::reply(const Buddy& buddy, const ext::String& message) |
85 |
> |
void Collector::status(const net::Oscar::UserInfo& user) |
86 |
> |
{ |
87 |
> |
Buddy buddy(*buddies.find(user)); |
88 |
> |
AwayMessage message(buddy, *info); |
89 |
> |
|
90 |
> |
if (!ext::String(message).IsEmpty()) // XXX |
91 |
> |
{ |
92 |
> |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, |
93 |
> |
database.host, database.user, database.password, database.db)); |
94 |
> |
|
95 |
> |
db->Execute("INSERT INTO messages (stamp, message, id) VALUES ('" + |
96 |
> |
message.getStamp() + "', '" + db->Escape(message) + "', '" + |
97 |
> |
buddy.getId() + "')"); |
98 |
> |
} |
99 |
> |
} |
100 |
> |
|
101 |
> |
void Collector::receive(const ext::String& buddy, const ext::String& message) |
102 |
|
{ |
103 |
|
if (buddies.find(buddy) != buddies.end()) |
104 |
|
{ |
105 |
< |
// |
105 |
> |
Stamp stamp; |
106 |
> |
|
107 |
> |
sleep(1); |
108 |
> |
|
109 |
> |
icbm->Simple(buddy, stamp); |
110 |
|
} |
111 |
|
else |
112 |
|
{ |