1 |
douglas |
13 |
// Zoe AIM Away Message RSS Feed Generator |
2 |
|
|
// |
3 |
|
|
// Seth King and Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
douglas |
21 |
#include "AwayMessage.hpp" |
8 |
douglas |
13 |
#include "Collector.hpp" |
9 |
douglas |
21 |
#include "Stamp.hpp" |
10 |
douglas |
13 |
|
11 |
douglas |
16 |
#include <cstring> |
12 |
douglas |
21 |
|
13 |
|
|
extern "C" |
14 |
|
|
{ |
15 |
douglas |
15 |
#include <pwd.h> |
16 |
|
|
#include <unistd.h> |
17 |
douglas |
21 |
} |
18 |
douglas |
15 |
|
19 |
|
|
Collector::Collector(const ext::String& login, ext::String& password, const |
20 |
douglas |
21 |
std::set<Buddy>& buddies, const Database& database, bool start) : |
21 |
|
|
login(login), password(password), buddies(buddies), database(database), |
22 |
|
|
start(start), prompted(false) |
23 |
douglas |
13 |
{ |
24 |
douglas |
15 |
if (start) |
25 |
|
|
{ |
26 |
|
|
if (password.IsEmpty()) prompt(); |
27 |
|
|
|
28 |
douglas |
20 |
collector.Spawn(etl::Bind<0>(&Collector::collect, this)); |
29 |
douglas |
15 |
} |
30 |
douglas |
13 |
} |
31 |
douglas |
15 |
|
32 |
douglas |
20 |
int Collector::collect() |
33 |
douglas |
15 |
{ |
34 |
|
|
cerr << "Collector::collect()\n"; |
35 |
|
|
|
36 |
|
|
net::Oscar::Session session; |
37 |
|
|
net::Oscar::AuthTool auth(session); |
38 |
|
|
net::Oscar::BuddyTool buddy(session); |
39 |
|
|
net::Oscar::ChatTool chat(session); |
40 |
|
|
net::Oscar::IcbmTool icbm(session); |
41 |
|
|
net::Oscar::InfoTool info(session); |
42 |
|
|
|
43 |
|
|
auth.Login(login, password); |
44 |
|
|
|
45 |
douglas |
18 |
if (prompted) password.Clear(); |
46 |
|
|
|
47 |
douglas |
17 |
this->buddy = &buddy; |
48 |
|
|
this->icbm = &icbm; |
49 |
douglas |
16 |
|
50 |
douglas |
19 |
// buddy.OnOnline += etl::Bind<0>(&Collector::status, this); |
51 |
|
|
icbm.OnReceive += etl::Bind<0>(&Collector::reply, this); |
52 |
douglas |
16 |
|
53 |
douglas |
20 |
net::Oscar::StringSet buddies; |
54 |
douglas |
15 |
|
55 |
douglas |
20 |
for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != |
56 |
|
|
this->buddies.end(); ++buddy) buddies.Insert(*buddy); |
57 |
douglas |
15 |
|
58 |
douglas |
20 |
buddy.Insert(buddies); |
59 |
douglas |
15 |
icbm.RequestParams(); |
60 |
|
|
|
61 |
|
|
net::Oscar::Capabilities capabilities; |
62 |
|
|
|
63 |
|
|
capabilities.Insert(net::Oscar::ChatCapability); |
64 |
douglas |
20 |
info.SetProfile("<font size=3>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "<font size=3>Mommy told me not to talk to strangers.</font> O:-)", capabilities); |
65 |
douglas |
15 |
|
66 |
|
|
// figure out whether or not we logged in |
67 |
|
|
|
68 |
douglas |
16 |
while (true) sleep(60); |
69 |
douglas |
15 |
} |
70 |
|
|
|
71 |
|
|
void Collector::prompt() |
72 |
|
|
{ |
73 |
douglas |
18 |
if (!prompted) prompted = true; |
74 |
|
|
|
75 |
douglas |
16 |
ext::String prompt(login + "'s AIM Password: "); |
76 |
|
|
char* password(getpass(prompt.NullTerminate())); |
77 |
douglas |
15 |
|
78 |
|
|
this->password = password; |
79 |
|
|
|
80 |
douglas |
21 |
for (size_t index(std::strlen(password)); index > 0; --index) |
81 |
|
|
password[index - 1] = '\0'; |
82 |
douglas |
15 |
} |
83 |
douglas |
16 |
|
84 |
douglas |
20 |
void Collector::reply(const Buddy& buddy, const ext::String& message) |
85 |
douglas |
16 |
{ |
86 |
douglas |
20 |
if (buddies.find(buddy) != buddies.end()) |
87 |
|
|
{ |
88 |
|
|
// |
89 |
|
|
} |
90 |
|
|
else |
91 |
|
|
{ |
92 |
|
|
sleep(1); |
93 |
|
|
|
94 |
|
|
icbm->Simple(buddy, "<font size=3>Mommy told me not to talk to strangers. O:-)"); |
95 |
|
|
} |
96 |
douglas |
16 |
} |