62 |
|
} |
63 |
|
#endif // _WIN32 |
64 |
|
|
65 |
– |
begin = 0; |
65 |
|
length = 0; |
66 |
|
chunked = false; |
67 |
|
} |
239 |
|
|
240 |
|
HttpHandler& HttpHandler::getline(string& line, char endline) |
241 |
|
{ |
242 |
< |
int end = page.find(endline, begin); |
243 |
< |
int newline = page.find('\n', begin); |
242 |
> |
unsigned end = page.find(endline); |
243 |
> |
unsigned newline = page.find('\n'); |
244 |
|
|
245 |
|
if (newline < end || end == string::npos) |
246 |
|
{ |
247 |
|
end = newline; |
248 |
|
} |
249 |
|
|
250 |
< |
line = page.substr(begin, end - begin); |
251 |
< |
|
253 |
< |
if (end == string::npos) |
254 |
< |
{ |
255 |
< |
begin = end; |
256 |
< |
} |
257 |
< |
else |
258 |
< |
{ |
259 |
< |
begin = end + 1; |
260 |
< |
} |
250 |
> |
line = page.substr(0, end); |
251 |
> |
page.erase(0, (end == string::npos ? end : end + 1)); |
252 |
|
|
253 |
|
return *this; |
254 |
|
} |
255 |
|
|
265 |
– |
bool HttpHandler::good() |
266 |
– |
{ |
267 |
– |
bool answer = true; |
268 |
– |
|
269 |
– |
if (begin >= page.length()) |
270 |
– |
{ |
271 |
– |
answer = false; |
272 |
– |
} |
273 |
– |
else if (begin == string::npos) |
274 |
– |
{ |
275 |
– |
answer = false; |
276 |
– |
} |
277 |
– |
|
278 |
– |
return answer; |
279 |
– |
} |
280 |
– |
|
256 |
|
void HttpHandler::clear() |
257 |
|
{ |
258 |
|
closesocket(http); |
260 |
|
type = ""; |
261 |
|
length = 0; |
262 |
|
location = ""; |
288 |
– |
begin = 0; |
263 |
|
page = ""; |
264 |
|
chunked = false; |
265 |
|
} |
278 |
|
|
279 |
|
if (recv(http, buffer, bytes, 0) == SOCKET_ERROR) |
280 |
|
{ |
281 |
< |
error(program + ": Revc"); |
281 |
> |
error(program + ": Recv"); |
282 |
|
exit(1); |
283 |
|
} |
284 |
|
|
288 |
|
} |
289 |
|
else |
290 |
|
{ |
291 |
< |
// |
291 |
> |
unsigned chunk; |
292 |
> |
|
293 |
> |
do |
294 |
> |
{ |
295 |
> |
chunk = strtoul(getline().c_str(), 0, 16); |
296 |
> |
|
297 |
> |
unsigned left = chunk; |
298 |
> |
|
299 |
> |
while (left > 0) |
300 |
> |
{ |
301 |
> |
memset(buffer, 0, BUFSIZ + 1); |
302 |
> |
|
303 |
> |
unsigned bytes = left > BUFSIZ ? BUFSIZ : left; |
304 |
> |
|
305 |
> |
if (recv(http, buffer, bytes, 0) == SOCKET_ERROR) |
306 |
> |
{ |
307 |
> |
error(program + ": Recv"); |
308 |
> |
exit(1); |
309 |
> |
} |
310 |
> |
|
311 |
> |
page += buffer; |
312 |
> |
left -= bytes; |
313 |
> |
} |
314 |
> |
|
315 |
> |
getline(); |
316 |
> |
length += chunk; |
317 |
> |
} |
318 |
> |
while (chunk > 0); |
319 |
|
} |
320 |
|
|
321 |
< |
cerr << "\n[" << page << "]\n"; |
321 |
> |
for (unsigned index = 0; index < page.length(); index++) |
322 |
> |
{ |
323 |
> |
if (page[index] == '\r' && (index + 1 < page.length()) ? page[index + |
324 |
> |
1] == '\n' : false) |
325 |
> |
{ |
326 |
> |
page.erase(index, 1); |
327 |
> |
} |
328 |
> |
else if (page[index] == '\r') |
329 |
> |
{ |
330 |
> |
page[index] = '\n'; |
331 |
> |
} |
332 |
> |
} |
333 |
|
} |
334 |
|
|
335 |
|
void HttpHandler::putline(const string line) |