6 |
|
|
7 |
|
#include "Collector.hpp" |
8 |
|
|
9 |
< |
Collector::Collector(const std::set<Buddy>& buddies) |
9 |
> |
#include <cstring> |
10 |
> |
#include <pwd.h> |
11 |
> |
#include <unistd.h> |
12 |
> |
|
13 |
> |
Collector::Collector(const ext::String& login, ext::String& password, const |
14 |
> |
std::set<Buddy>& buddies, bool start) : login(login), password(password), |
15 |
> |
start(start), prompted(false) |
16 |
> |
{ |
17 |
> |
if (start) |
18 |
> |
{ |
19 |
> |
if (password.IsEmpty()) prompt(); |
20 |
> |
|
21 |
> |
collector.Spawn(etl::BindAll(&Collector::collect, this, buddies)); |
22 |
> |
} |
23 |
> |
} |
24 |
> |
|
25 |
> |
int Collector::collect(const std::set<Buddy>& buddies) |
26 |
> |
{ |
27 |
> |
cerr << "Collector::collect()\n"; |
28 |
> |
|
29 |
> |
net::Oscar::Session session; |
30 |
> |
net::Oscar::AuthTool auth(session); |
31 |
> |
net::Oscar::BuddyTool buddy(session); |
32 |
> |
net::Oscar::ChatTool chat(session); |
33 |
> |
net::Oscar::IcbmTool icbm(session); |
34 |
> |
net::Oscar::InfoTool info(session); |
35 |
> |
|
36 |
> |
auth.Login(login, password); |
37 |
> |
|
38 |
> |
if (prompted) password.Clear(); |
39 |
> |
|
40 |
> |
this->buddy = &buddy; |
41 |
> |
this->icbm = &icbm; |
42 |
> |
|
43 |
> |
icbm.OnIncomingIcbm += etl::bind<0>(&Collector::reply, this); |
44 |
> |
|
45 |
> |
net::Oscar::StringSet buddies_; |
46 |
> |
|
47 |
> |
for (std::set<Buddy>::const_iterator buddy(buddies.begin()); buddy != |
48 |
> |
buddies.end(); ++buddy) buddies_.Insert(*buddy); |
49 |
> |
|
50 |
> |
buddy.Insert(buddies_); |
51 |
> |
icbm.RequestParams(); |
52 |
> |
|
53 |
> |
net::Oscar::Capabilities capabilities; |
54 |
> |
|
55 |
> |
capabilities.Insert(net::Oscar::ChatCapability); |
56 |
> |
info.SetProfile("<font size=3>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "", capabilities); |
57 |
> |
|
58 |
> |
// figure out whether or not we logged in |
59 |
> |
|
60 |
> |
while (true) sleep(60); |
61 |
> |
} |
62 |
> |
|
63 |
> |
void Collector::prompt() |
64 |
> |
{ |
65 |
> |
if (!prompted) prompted = true; |
66 |
> |
|
67 |
> |
ext::String prompt(login + "'s AIM Password: "); |
68 |
> |
char* password(getpass(prompt.NullTerminate())); |
69 |
> |
|
70 |
> |
this->password = password; |
71 |
> |
|
72 |
> |
for (size_t index(strlen(password)); index > 0; --index) password[index - |
73 |
> |
1] = '\0'; |
74 |
> |
} |
75 |
> |
|
76 |
> |
void Collector::reply(const ext::String& login, const ext::String& reply) |
77 |
|
{ |
78 |
< |
// |
78 |
> |
icbm->Simple(login, reply); |
79 |
|
} |