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