ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Collector.cpp
(Generate patch)

Comparing trunk/Collector.cpp (file contents):
Revision 15 by douglas, 2004-07-13T20:14:49-07:00 vs.
Revision 31 by douglas, 2004-07-20T00:11:56-07:00

# Line 4 | Line 4
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 <
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
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 <        start(start)
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          {
26                  if (password.IsEmpty()) prompt();
27  
28 <                collector.Spawn(etl::BindAll(&Collector::collect, this, buddies));
28 >                collector.Spawn(etl::Bind<0>(&Collector::collect, this));
29          }
30   }
31  
32 < int Collector::collect(const std::set<Buddy>& buddies)
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);
# Line 43 | Line 41 | int Collector::collect(const std::set<Bu
41          net::Oscar::InfoTool info(session);
42  
43          auth.Login(login, password);
46        password.Clear();
44  
45 <        net::Oscar::StringSet buddies_;
45 >        if (prompted) password.Clear();
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::receive, this);
53 >
54 >        net::Oscar::StringSet buddies;
55  
56 <        for (std::set<Buddy>::const_iterator buddy(buddies.begin()); buddy !=
57 <                buddies.end(); ++buddy) buddies_.Insert(*buddy);
56 >        for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy !=
57 >                this->buddies.end(); ++buddy) buddies.Insert(*buddy);
58  
59 <        buddy.Insert(buddies_);
59 >        buddy.Insert(buddies);
60          icbm.RequestParams();
61  
62          net::Oscar::Capabilities capabilities;
63  
64          capabilities.Insert(net::Oscar::ChatCapability);
65 <        info.SetProfile("<font size=3>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "", capabilities);
65 >        info.SetProfile(ext::String("<font face=\"Tahoma\" size=2>I am <a href=\"h")
66 >                + "ttp://computers.douglasthrift.net/zoe.xml\">Zoe</a>.</font> :-*", "<"
67 >                + ext::String("font face=\"Tahoma\" size=3>Mommy told me not to talk t")
68 >                + "o strangers.</font> O:-)", capabilities);
69  
70          // figure out whether or not we logged in
71  
72 <        while (true)
72 >        while (true) sleep(Minute(1));
73 > }
74 >
75 > void Collector::prompt()
76 > {
77 >        if (!prompted) prompted = true;
78 >
79 >        ext::String prompt(login + "'s AIM Password: ");
80 >        char* password(getpass(prompt.NullTerminate()));
81 >
82 >        this->password = password;
83 >
84 >        for (size_t index(std::strlen(password)); index > 0; --index)
85 >                password[index - 1] = '\0';
86 > }
87 >
88 > void Collector::status(const net::Oscar::UserInfo& user)
89 > {
90 >        Buddy buddy(*buddies.find(user));
91 >        AwayMessage message(buddy, *info);
92 >
93 >        if (!ext::String(message).IsEmpty()) // XXX
94          {
95 <                sleep(60);
95 >                cerr << bright << red << "Collector::status(" << blue << buddy << red
96 >                        << ", " << reset << message << bright << red << ")\n" << reset;
97 >
98 >                ext::Handle<dbi::Connection> db(dbi::Connect(database.driver,
99 >                        database.host, database.user, database.password, database.db));
100  
101 <                // collect
101 >                db->Execute("INSERT INTO messages (stamp, message, id) VALUES ('" +
102 >                        message.getStamp() + "', '" + db->Escape(message) + "', '" +
103 >                        buddy.getId() + "')");
104          }
105   }
106  
107 < void Collector::prompt()
107 > void Collector::receive(const ext::String& buddy, const ext::String& message)
108   {
109 <        char* password(getpass("Password: "));
109 >        cerr << bright << red << "Collector::receive(" << blue << Buddy(buddy)
110 >                << red << ", " << reset << message << bright << red << ")\n" << reset;
111  
112 <        this->password = password;
112 >        if (buddies.find(buddy) != buddies.end())
113 >        {
114 >                Stamp stamp;
115 >                
116 >                sleep(1);
117 >
118 >                icbm->Simple(buddy, stamp);
119 >        }
120 >        else
121 >        {
122 >                sleep(1);
123  
124 <        for (size_t index(0); index < PASS_MAX; ++index) password[index] = '\0';
124 >                icbm->Simple(buddy, ext::String("<font face=\"Tahoma\" size=2>Mommy to")
125 >                        + "ld me not to talk to strangers. O:-)");
126 >        }
127   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines