8 |
|
|
9 |
|
Person::Person(const string& sn) : name("Unknown Person") |
10 |
|
{ |
11 |
< |
#ifdef __FreeBSD__ |
12 |
< |
if (db.empty()) configure(); |
13 |
< |
#else |
14 |
< |
if (file.empty()) configure(); |
15 |
< |
#endif |
11 |
> |
if (driver.empty()) configure(); |
12 |
|
if (!sn.empty()) query(sn); |
13 |
|
} |
14 |
|
|
15 |
< |
#ifdef __FreeBSD__ |
20 |
< |
string Person::user, Person::db; |
21 |
< |
#else |
22 |
< |
string Person::file; |
23 |
< |
vector<string> Person::args(1, "smersh"); |
24 |
< |
string Person::separator, Person::begin, Person::end; |
25 |
< |
#endif |
15 |
> |
string Person::driver, Person::host, Person::user, Person::password, Person::db; |
16 |
|
|
17 |
|
void Person::configure() |
18 |
|
{ |
19 |
|
ext::Handle<xml::Document> document(xml::Parse("smersh.xml")); |
20 |
|
ext::Handle<xml::Node> smersh(*document/"smersh"); |
21 |
|
|
22 |
< |
#ifdef __FreeBSD__ |
22 |
> |
driver = *smersh/"driver"; |
23 |
> |
host = *smersh/"host"; |
24 |
|
user = *smersh/"user"; |
25 |
+ |
password = *smersh/"password"; |
26 |
|
db = *smersh/"db"; |
27 |
|
|
28 |
< |
if (debug) cerr << "user = " << user << "\ndb = " << db << '\n'; |
29 |
< |
#else |
30 |
< |
file = *smersh/"command"/"file"; |
39 |
< |
|
40 |
< |
xml::NodeSet nodes(*smersh/"command"/"arg"); |
41 |
< |
|
42 |
< |
for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End(); |
43 |
< |
++node) args.push_back(**node); |
44 |
< |
|
45 |
< |
separator = *smersh/"separator"; |
46 |
< |
begin = *smersh/"begin"; |
47 |
< |
end = *smersh/"end"; |
48 |
< |
|
49 |
< |
if (debug) |
50 |
< |
{ |
51 |
< |
cerr << "file = " << file << '\n' |
52 |
< |
<< "args = {\n"; |
53 |
< |
|
54 |
< |
for (vector<string>::size_type index(0); index < args.size(); ++index) |
55 |
< |
{ |
56 |
< |
cerr << " [" << index << "] = " << args[index] << '\n'; |
57 |
< |
} |
58 |
< |
|
59 |
< |
cerr << "}\n" |
60 |
< |
<< "separator = " << separator << '\n' |
61 |
< |
<< "begin = " << begin << '\n' |
62 |
< |
<< "end = " << end << '\n'; |
63 |
< |
} |
64 |
< |
#endif |
28 |
> |
if (debug) cerr << "driver = " << driver << "\nhost = " << host << '\n' |
29 |
> |
<< "user = " << user << "\npassword = " << password << "\ndb = " << db |
30 |
> |
<< '\n'; |
31 |
|
} |
32 |
|
|
33 |
|
void Person::query(const string& sn) |
34 |
|
{ |
35 |
< |
#ifdef __FreeBSD__ |
36 |
< |
ext::Handle<dbi::Connection> db(dbi::Connect(user, this->db)); |
35 |
> |
ext::Handle<dbi::Connection> db(dbi::Connect(driver, host, user, password, |
36 |
> |
this->db)); |
37 |
|
ext::Handle<dbi::ResultSet> people(db->Execute(string("SELECT name FROM pe") |
38 |
|
+ "ople, peopleaimmap, aim WHERE people.id=pid AND aid=aim.id AND sn=LO" |
39 |
|
+ "WER(\'" + sn + "\')")); |
48 |
|
|
49 |
|
multiple.push_back(person); |
50 |
|
} |
85 |
– |
#else |
86 |
– |
vector<string> args(Person::args); |
87 |
– |
|
88 |
– |
args.push_back(string("SELECT name FROM people, peopleaimmap, aim WHERE p") |
89 |
– |
+ "eople.id=pid AND aid=aim.id AND sn=LOWER(\'" + sn + "\');"); |
90 |
– |
|
91 |
– |
ipstream sql(file, args); |
92 |
– |
bool first(true); |
93 |
– |
Matcher separator(this->separator), heading(begin + "\\s*name\\s*" + end), |
94 |
– |
matcher(begin + "(.*)" + end); |
95 |
– |
|
96 |
– |
do |
97 |
– |
{ |
98 |
– |
string line; |
99 |
– |
|
100 |
– |
getline(sql, line); |
101 |
– |
|
102 |
– |
if (debug) cerr << "line = " << line << '\n'; |
103 |
– |
|
104 |
– |
if (line == separator) continue; |
105 |
– |
else if (line == heading) continue; |
106 |
– |
else if (line == matcher) |
107 |
– |
{ |
108 |
– |
if (first) |
109 |
– |
{ |
110 |
– |
name = matcher[1]; |
111 |
– |
first = false; |
112 |
– |
} |
113 |
– |
else |
114 |
– |
{ |
115 |
– |
Person person; |
116 |
– |
|
117 |
– |
person.name = matcher[1]; |
118 |
– |
|
119 |
– |
multiple.push_back(person); |
120 |
– |
} |
121 |
– |
} |
122 |
– |
else break; |
123 |
– |
} |
124 |
– |
while (sql.good()); |
125 |
– |
#endif |
51 |
|
} |