57 |
|
#ifdef _WIN32 |
58 |
|
if (WSAStartup(MAKEWORD(2, 0), &data) != 0) |
59 |
|
{ |
60 |
< |
error(program + ": WSAStartup()"); |
60 |
> |
error(program + ": WSAStartup"); |
61 |
|
exit(1); |
62 |
|
} |
63 |
|
#endif // _WIN32 |
133 |
|
|
134 |
|
putline(); |
135 |
|
|
136 |
+ |
string line = getline(); |
137 |
+ |
|
138 |
+ |
if (line.find("HTTP/") != 0) |
139 |
+ |
{ |
140 |
+ |
return answer; |
141 |
+ |
} |
142 |
+ |
|
143 |
+ |
unsigned dot = line.find('.'); |
144 |
+ |
unsigned space = line.find(' '); |
145 |
+ |
|
146 |
+ |
unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 0); |
147 |
+ |
unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(), 0, |
148 |
+ |
0); |
149 |
+ |
|
150 |
+ |
if (major > 1 || minor < 1) |
151 |
+ |
{ |
152 |
+ |
cerr << program << ": Potentially Incompatible Server: HTTP/" << major |
153 |
+ |
<< "." << minor << "\n"; |
154 |
+ |
|
155 |
+ |
return answer; |
156 |
+ |
} |
157 |
+ |
|
158 |
+ |
code response = code(strtoul(line.substr(space + 1).c_str(), 0, 0)); |
159 |
+ |
|
160 |
+ |
do |
161 |
+ |
{ |
162 |
+ |
line = getline(); |
163 |
+ |
} |
164 |
+ |
while (line != ""); |
165 |
+ |
|
166 |
+ |
switch (response) |
167 |
+ |
{ |
168 |
+ |
case ok: |
169 |
+ |
answer = true; |
170 |
+ |
break; |
171 |
+ |
case choices: |
172 |
+ |
break; |
173 |
+ |
case moved: |
174 |
+ |
break; |
175 |
+ |
case found: |
176 |
+ |
break; |
177 |
+ |
case notfound: |
178 |
+ |
break; |
179 |
+ |
case internal: |
180 |
+ |
break; |
181 |
+ |
default: |
182 |
+ |
break; |
183 |
+ |
} |
184 |
+ |
|
185 |
|
return answer; |
186 |
|
} |
187 |
|
|
227 |
|
|
228 |
|
void HttpHandler::clear() |
229 |
|
{ |
230 |
+ |
type = ""; |
231 |
+ |
length = 0; |
232 |
+ |
location = ""; |
233 |
|
begin = 0; |
234 |
|
page = ""; |
235 |
|
} |
244 |
|
} |
245 |
|
} |
246 |
|
|
247 |
+ |
string HttpHandler::getline() |
248 |
+ |
{ |
249 |
+ |
string line; |
250 |
+ |
char byte; |
251 |
+ |
|
252 |
+ |
do |
253 |
+ |
{ |
254 |
+ |
if (recv(http, &byte, 1, 0) == SOCKET_ERROR) |
255 |
+ |
{ |
256 |
+ |
error(program + ": Recv"); |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
if (byte != '\r' && byte != '\n') |
260 |
+ |
{ |
261 |
+ |
line += byte; |
262 |
+ |
} |
263 |
+ |
} |
264 |
+ |
while (byte != '\n'); |
265 |
+ |
|
266 |
+ |
return line; |
267 |
+ |
} |
268 |
+ |
|
269 |
|
void HttpHandler::error(const string prefix, bool host) |
270 |
|
{ |
271 |
|
#ifdef _WIN32 |