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 25 by douglas, 2004-07-17T16:29:02-07:00 vs.
Revision 37 by douglas, 2004-07-22T16:00:52-07:00

# Line 16 | Line 16 | extern "C"
16   #include <unistd.h>
17   }
18  
19 < Collector::Collector(const ext::String& login, ext::String& password, const
20 <        std::set<Buddy>& buddies, const Database& database, bool start) :
21 <        login(login), password(password), buddies(buddies), database(database),
19 > Collector::Collector(const ext::String& login, ext::String& password, const     std::set<Buddy>& buddies,
20 >        const Database& database, bool start) : login(login), password(password), buddies(buddies), database(database),
21          start(start), prompted(false)
22   {
23          if (start)
# Line 31 | Line 30 | Collector::Collector(const ext::String&
30  
31   int Collector::collect()
32   {
33 <        cerr << bright << green << "Collector::collect()\n" << reset;
33 >        cerr << bright << green << "Started collector daemon.\n" << reset;
34  
35          net::Oscar::Session session;
36          net::Oscar::AuthTool auth(session);
# Line 53 | Line 52 | int Collector::collect()
52  
53          net::Oscar::StringSet buddies;
54  
55 <        for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy !=
56 <                this->buddies.end(); ++buddy) buddies.Insert(*buddy);
55 >        for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != this->buddies.end(); ++buddy)
56 >                buddies.Insert(*buddy);
57  
58          buddy.Insert(buddies);
60        icbm.RequestParams();
59  
60          net::Oscar::Capabilities capabilities;
61  
62          capabilities.Insert(net::Oscar::ChatCapability);
63 <        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);
63 >        info.SetProfile("<font face=\"Tahoma\" size=2>I am <a href=\"http://computers.douglasthrift.net/zoe.xml\">Zoe</a>."
64 >                "</font> :-*", "<font face=\"Tahoma\" size=2>Mommy told me not to talk to strangers.</font> O:-)", capabilities);
65  
66          // figure out whether or not we logged in
67  
68 <        while (true) sleep(60);
68 >        while (true) sleep(Minute(1));
69   }
70  
71   void Collector::prompt()
# Line 78 | Line 77 | void Collector::prompt()
77  
78          this->password = password;
79  
80 <        for (size_t index(std::strlen(password)); index > 0; --index)
82 <                password[index - 1] = '\0';
80 >        for (size_t index(std::strlen(password)); index > 0; --index) password[index - 1] = '\0';
81   }
82  
83   void Collector::status(const net::Oscar::UserInfo& user)
84   {
87        Stamp stamp;
85          Buddy buddy(*buddies.find(user));
86 +        AwayMessage message(buddy, *info);
87  
88 <        cerr << red << ext::String(stamp) << ' ' << blue << ext::String(buddy)
89 <                << '\n' << reset;
88 >        if (!ext::String(message).IsEmpty()) // XXX
89 >        {
90 >                ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, database.user, database.password,
91 >                        database.db));
92 >                ext::Handle<dbi::ResultSet> previous(db->Execute("SELECT message FROM messages "
93 >                        "WHERE stamp=(SELECT MAX(stamp) FROM messages WHERE id='"
94 >                        + lexical_cast<ext::String>(buddy.getId()) + "') AND id='"
95 >                        + lexical_cast<ext::String>(buddy.getId()) + "'"));
96 >
97 >                if (previous->MoveNext())
98 >                {
99 >                        if (ext::String(message) == previous->GetString("message")) return;
100 >                }
101 >
102 >                db->Execute("INSERT INTO messages (stamp, message, id) VALUES ('"
103 >                        + ext::String(message.getStamp()) + "', '" + db->Escape(message)
104 >                        + "', '" + lexical_cast<ext::String>(buddy.getId()) + "')");
105 >
106 >                cerr << bright << red << "Collected away message from " << blue << buddy
107 >                        << red << ".\n" << reset;
108 >        }
109   }
110  
111   void Collector::receive(const ext::String& buddy, const ext::String& message)
112   {
113 +        if (Zoe::debug) cerr << "buddy = " << Buddy(buddy) << "\nmessage = "
114 +                << message << '\n';
115 +
116          if (buddies.find(buddy) != buddies.end())
117          {
118 <                Stamp stamp;
118 >                Buddy buddy_(*buddies.find(buddy));
119                  
120                  sleep(1);
121  
122 <                icbm->Simple(buddy, stamp);
122 >                icbm->Simple(buddy, ext::String(buddy_) + " = {\n   rss = "
123 >                        + buddy_.getRss() + "\n   atom = " + buddy_.getAtom() + "\n}");
124          }
125          else
126          {
127                  sleep(1);
128  
129 <                icbm->Simple(buddy, "<font size=3>Mommy told me not to talk to strangers. O:-)");
129 >                icbm->Simple(buddy, "<font face=\"Tahoma\" size=2>Mommy told me not to "
130 >                        "talk to strangers.</font> O:-)");
131          }
132   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines