// Zoe AIM Away Message RSS Feed Generator // // Seth King and Douglas Thrift // // $Id$ #include "AwayMessage.hpp" #include "Collector.hpp" #include "Stamp.hpp" #include extern "C" { #include #include } Collector::Collector(const ext::String& login, ext::String& password, const std::set& buddies, const Database& database, bool start) : login(login), password(password), buddies(buddies), database(database), start(start), prompted(false) { if (start) { if (password.IsEmpty()) prompt(); collector.Spawn(etl::Bind<0>(&Collector::collect, this)); } } int Collector::collect() { cerr << bright << green << "Collector::collect()\n" << reset; net::Oscar::Session session; net::Oscar::AuthTool auth(session); net::Oscar::BuddyTool buddy(session); net::Oscar::ChatTool chat(session); net::Oscar::IcbmTool icbm(session); net::Oscar::InfoTool info(session); auth.Login(login, password); if (prompted) password.Clear(); this->buddy = &buddy; this->icbm = &icbm; this->info = &info; buddy.OnOnline += etl::Bind<0>(&Collector::status, this); icbm.OnReceive += etl::Bind<0>(&Collector::receive, this); net::Oscar::StringSet buddies; for (std::set::const_iterator buddy(this->buddies.begin()); buddy != this->buddies.end(); ++buddy) buddies.Insert(*buddy); buddy.Insert(buddies); icbm.RequestParams(); net::Oscar::Capabilities capabilities; capabilities.Insert(net::Oscar::ChatCapability); info.SetProfile(ext::String("I am Zoe. :-*", "<" + ext::String("font face=\"Tahoma\" size=3>Mommy told me not to talk t") + "o strangers. O:-)", capabilities); // figure out whether or not we logged in while (true) sleep(Minute(1)); } void Collector::prompt() { if (!prompted) prompted = true; ext::String prompt(login + "'s AIM Password: "); char* password(getpass(prompt.NullTerminate())); this->password = password; for (size_t index(std::strlen(password)); index > 0; --index) password[index - 1] = '\0'; } void Collector::status(const net::Oscar::UserInfo& user) { Buddy buddy(*buddies.find(user)); AwayMessage message(buddy, *info); if (!ext::String(message).IsEmpty()) // XXX { cerr << bright << red << "Collector::status(" << blue << buddy << red << ", " << reset << message << bright << red << ")\n" << reset; ext::Handle db(dbi::Connect(database.driver, database.host, database.user, database.password, database.db)); db->Execute("INSERT INTO messages (stamp, message, id) VALUES ('" + message.getStamp() + "', '" + db->Escape(message) + "', '" + buddy.getId() + "')"); } } void Collector::receive(const ext::String& buddy, const ext::String& message) { cerr << bright << red << "Collector::receive(" << blue << Buddy(buddy) << red << ", " << reset << message << bright << red << ")\n" << reset; if (buddies.find(buddy) != buddies.end()) { Stamp stamp; sleep(1); icbm->Simple(buddy, stamp); } else { sleep(1); icbm->Simple(buddy, ext::String("Mommy to") + "ld me not to talk to strangers. O:-)"); } }