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

Comparing trunk/Zoe.cpp (file contents):
Revision 21 by douglas, 2004-07-16T23:37:41-07:00 vs.
Revision 34 by douglas, 2004-07-20T16:49:06-07:00

# Line 15 | Line 15
15   extern "C"
16   {
17   #include <pwd.h>
18 + #include <sys/utsname.h>
19   #include <unistd.h>
20   }
21  
21 enum Color { reset, bright, dim, underscore = 4, blink, reverse = 7, hidden,
22        black = 30, red, green, yellow, blue, magenta, cyan, white, _black = 40,
23        _red, _green, _yellow, _blue, _magenta, _cyan, _white };
24
25 inline std::ostream& operator<<(std::ostream& sout, Color color)
26 {
27        sout << "\033[" << unsigned(color) << 'm';
28
29        return sout;
30 }
31
22   int main(int argc, char* argv[])
23   {
24          Zoe::program = argv[0];
# Line 83 | Line 73 | Zoe::Zoe()
73   bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false);
74   ext::String Zoe::program, Zoe::config("zoe.xml");
75  
76 + ext::String Zoe::generator()
77 + {
78 +        utsname system;
79 +
80 +        uname(&system);
81 +
82 +        return _S("Zoe/0.9 (") + system.sysname + "; http://computers.douglasthrift.net/zoe.xml)";
83 + }
84 +
85   void Zoe::configure()
86   {
87          if (debug) cerr << "config = " << config << '\n';
# Line 98 | Line 97 | void Zoe::configure()
97  
98          if ((*zoe/"database"/"password").IsEmpty())
99          {
100 <                ext::String prompt(database.user + (!database.host.IsEmpty() ? "@" : "")
101 <                        + database.host + (!database.user.IsEmpty() ? "'s " : "") + "Databa"
103 <                        + "se Password: ");
100 >                ext::String prompt(database.user + (!database.host.IsEmpty() ? "@" : "") + database.host
101 >                        + (!database.user.IsEmpty() ? "'s " : "") + "Database Password: ");
102                  char* password(getpass(prompt.NullTerminate()));
103  
104                  database.password = password;
105  
106 <                for (size_t index(std::strlen(password)); index > 0; --index)
109 <                        password[index - 1] = '\0';
106 >                for (size_t index(std::strlen(password)); index > 0; --index) password[index - 1] = '\0';
107          }
108          else database.password = std::string(*zoe/"database"/"password");
109  
110          database.db = std::string(*zoe/"database"/"db");
111  
112 <        if (debug) cerr << "login = " << login << "\npassword = "
113 <                << std::string(password.GetSize(), '*') << "\ndatabase = {\n   driver ="
114 <                << ' ' << database.driver << "\n   host=" << database.host << "\n   use"
118 <                << "r = " << database.user << "\n   password = "
119 <                << std::string(database.password.GetSize(), '*') << "\n   db = "
120 <                << database.db << "\n}\n";
112 >        if (debug) cerr << "login = " << login << "\npassword = " << std::string(password.GetSize(), '*') << "\ndatabase = {\n"
113 >                << "   driver = " << database.driver << "\n   host=" << database.host << "\n   user = " << database.user << '\n'
114 >                << "   password = " << std::string(database.password.GetSize(), '*') << "\n   db = " << database.db << "\n}\n";
115  
116          xml::NodeSet buddies(*zoe/"buddy");
117  
118 <        for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End();
119 <                ++buddy) this->buddies.insert(Buddy(**buddy/"login", **buddy/"rss"));
118 >        for (xml::NodeSet::Iterator buddy(buddies.Begin()); buddy != buddies.End(); ++buddy)
119 >                this->buddies.insert(Buddy(**buddy/"login", **buddy/"rss"));
120  
121          if (debug)
122          {
123                  cerr << "buddies = {\n";
124  
125 <                for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy
126 <                        != this->buddies.end(); ++buddy) cerr << "   " << *buddy << '\n';
125 >                for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); buddy != this->buddies.end(); ++buddy)
126 >                        cerr << "   " << *buddy << " = " << buddy->getRss() << '\n';
127  
128                  cerr << "}\n";
129          }
# Line 146 | Line 140 | void Zoe::configure()
140  
141   void Zoe::initialize()
142   {
143 <        ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host,
144 <                database.user, database.password, database.db));
143 >        ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, database.user, database.password,
144 >                database.db));
145          ext::Handle<dbi::ResultSet> buddies(db->Execute("SELECT * FROM buddies"));
146          std::set<Buddy> buddies_;
147  
# Line 161 | Line 155 | void Zoe::initialize()
155  
156          std::vector<Buddy> difference;
157  
158 <        set_difference(this->buddies.begin(), this->buddies.end(), buddies_.begin(),
159 <                buddies_.end(), std::insert_iterator<std::vector<Buddy> >(difference,
166 <                difference.begin()));
158 >        set_difference(this->buddies.begin(), this->buddies.end(), buddies_.begin(), buddies_.end(),
159 >                std::insert_iterator<std::vector<Buddy> >(difference, difference.begin()));
160  
161 <        for (std::vector<Buddy>::iterator buddy(difference.begin()); buddy !=
169 <                difference.end(); ++buddy)
161 >        for (std::vector<Buddy>::iterator buddy(difference.begin()); buddy != difference.end(); ++buddy)
162          {
163                  ext::Uuid id;
164  
165                  api::Uuid::CreateSequential(id);
166  
167                  buddy->setId(id);
168 <                db->Execute("INSERT INTO buddies (id, buddy) VALUES ('" +
169 <                        lexical_cast<ext::String>(id) + "', '" + ext::String(*buddy) +
178 <                        "')");
168 >                db->Execute("INSERT INTO buddies (id, buddy) VALUES ('" + lexical_cast<ext::String>(id) + "', '"
169 >                        + ext::String(*buddy) + "')");
170                  
171                  buddies_.insert(*buddy);
172          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines