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