ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/WinXPFAQPoll/Account.cpp
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (16 years, 9 months ago) by douglas
File size: 6429 byte(s)
Log Message:
Rearranged everything else.

File Contents

# Content
1 /* ============================================================================
2 * Douglas Thrift's Web Contact License
3 *
4 * Copyright (C) 2002, Douglas Thrift. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. The end-user documentation included with the redistribution, if any, must
17 * include the following acknowledgment:
18 *
19 * "This product includes software developed by Douglas Thrift
20 * (http://computers.douglasthrift.net/webcontact.html)."
21 *
22 * Alternately, this acknowledgment may appear in the software itself, if
23 * and wherever such third-party acknowledgments normally appear.
24 *
25 * 4. The names "Douglas Thrift" and "Douglas Thrift's Web Contact" must not be
26 * used to endorse or promote products derived from this software without
27 * specific prior written permission. For written permission, please visit
28 * http://www.douglasthrift.net/contact.html for contact information.
29 *
30 * 5. Products derived from this software may not be called "Douglas Thrift's
31 * Web Contact", nor may "Douglas Thrift's Web Contact" appear in their
32 * name, without prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
35 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
40 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * ============================================================================
45 */
46 // Windows XP FAQ Poll
47 //
48 // Douglas Thrift
49 //
50 // Account.cpp
51
52 #include "Account.h"
53
54 istream& operator>>(istream& is, Account& account)
55 {
56 string line;
57 getline(is, line);
58 if (line == "<account>")
59 {
60 do
61 {
62 getline(is, line);
63 if (line.find(" <host>") == 0)
64 {
65 unsigned start = line.find("<host>") + 6;
66 unsigned finish = line.find("</host>", start);
67
68 string host = line.substr(start, finish - start);
69
70 entities(host, "&lt;", '<');
71 entities(host, "&gt;", '>');
72 entities(host, "&amp;", '&');
73
74 account.setHost(host);
75 }
76 else if (line.find(" <port>") == 0)
77 {
78 unsigned start = line.find("<port>") + 6;
79 unsigned finish = line.find("</port>", start);
80
81 string port = line.substr(start, finish - start);
82
83 account.setPort(strtoul(port.c_str(), 0, 0));
84 }
85 else if (line.find(" <login>") == 0)
86 {
87 unsigned start = line.find("<login>") + 7;
88 unsigned finish = line.find("</login>", start);
89
90 string login = line.substr(start, finish - start);
91
92 entities(login, "&lt;", '<');
93 entities(login, "&gt;", '>');
94 entities(login, "&amp;", '&');
95
96 account.setLogin(login);
97 }
98 else if (line.find(" <name>") == 0)
99 {
100 unsigned start = line.find("<name>") + 6;
101 unsigned finish = line.find("</name>", start);
102
103 string name = line.substr(start, finish - start);
104
105 entities(name, "&lt;", '<');
106 entities(name, "&gt;", '>');
107 entities(name, "&amp;", '&');
108
109 account.setName(name);
110 }
111 else if (line.find(" <email>") == 0)
112 {
113 unsigned start = line.find("<email>") + 7;
114 unsigned finish = line.find("</email>", start);
115
116 string email = line.substr(start, finish - start);
117
118 entities(email, "&lt;", '<');
119 entities(email, "&gt;", '>');
120 entities(email, "&amp;", '&');
121
122 account.setEmail(email);
123 }
124 else if (line.find(" <password>") == 0)
125 {
126 unsigned start = line.find("<password>") + 10;
127 unsigned finish = line.find("</password>", start);
128
129 string password = line.substr(start, finish - start);
130
131 entities(password, "&lt;", '<');
132 entities(password, "&gt;", '>');
133 entities(password, "&amp;", '&');
134
135 account.setPassword(password);
136 }
137 else if (line.find(" <mailbox>") == 0)
138 {
139 unsigned start = line.find("<mailbox>") + 9;
140 unsigned finish = line.find("</mailbox>", start);
141
142 string mailbox = line.substr(start, finish - start);
143
144 entities(mailbox, "&lt;", '<');
145 entities(mailbox, "&gt;", '>');
146 entities(mailbox, "&amp;", '&');
147
148 account.setMailbox(mailbox);
149 }
150 }
151 while (line != "</account>");
152 }
153
154 return is;
155 }
156
157 ostream& operator<<(ostream& os, Account& account)
158 {
159 string host = account.getHost();
160
161 entities(host, '&', "&amp;");
162 entities(host, '<', "&lt;");
163 entities(host, '>', "&gt;");
164
165 os << "<account>\n" << " <host>" << host << "</host>\n";
166
167 if (account.getPort() != 143)
168 {
169 os << " <port>" << account.getPort() << "</port>\n";
170 }
171
172 string login = account.getLogin();
173
174 entities(login, '&', "&amp;");
175 entities(login, '<', "&lt;");
176 entities(login, '>', "&gt;");
177
178 os << " <login>" << login << "</login>\n";
179
180 string name = account.getName();
181
182 entities(name, '&', "&amp;");
183 entities(name, '<', "&lt;");
184 entities(name, '>', "&gt;");
185
186 os << " <name>" << name << "</name>\n";
187
188 string email = account.getEmail();
189
190 entities(email, '&', "&amp;");
191 entities(email, '<', "&lt;");
192 entities(email, '>', "&gt;");
193
194 os << " <email>" << email << "</email>\n";
195
196 if (account.getPassword() != "")
197 {
198 string password = account.getPassword();
199
200 entities(password, '&', "&amp;");
201 entities(password, '<', "&lt;");
202 entities(password, '>', "&gt;");
203
204 os << " <password>" << password << "</password>\n";
205 }
206
207 if (account.getMailbox() != "INBOX")
208 {
209 string mailbox = account.getMailbox();
210
211 entities(mailbox, '&', "&amp;");
212 entities(mailbox, '<', "&lt;");
213 entities(mailbox, '>', "&gt;");
214
215 os << " <mailbox>" << mailbox << "</mailbox>\n";
216 }
217
218 os << "</account>";
219
220 return os;
221 }