85 |
|
#endif // _WIN32 |
86 |
|
} |
87 |
|
|
88 |
< |
bool HttpHandler::handle(URL &url, const string referer, bool head) |
88 |
> |
bool HttpHandler::handle(URL &url, const string& referer, bool head) |
89 |
|
{ |
90 |
|
bool answer(false); |
91 |
|
|
159 |
|
putline("Host: " + url.getAddress() + ':' + port.str()); |
160 |
|
} |
161 |
|
|
162 |
< |
if (referer != "") |
162 |
> |
if (!referer.empty()) |
163 |
|
{ |
164 |
|
putline("Referer: " + referer); |
165 |
|
} |
167 |
|
putline("Connection: close"); |
168 |
|
putline(); |
169 |
|
|
170 |
< |
code response; |
170 |
> |
Code response; |
171 |
|
string line; |
172 |
|
|
173 |
|
do |
176 |
|
|
177 |
|
if (line.find("HTTP/") != 0) return answer; |
178 |
|
|
179 |
< |
unsigned dot(line.find('.')), space(line.find(' ')), major, minor; |
179 |
> |
size_t dot(line.find('.')), space(line.find(' ')), major, minor; |
180 |
|
istringstream number(line.substr(5, dot - 5) + " " + line.substr(dot |
181 |
|
+ 1, space - dot - 1)); |
182 |
|
|
196 |
|
|
197 |
|
number >> response; |
198 |
|
|
199 |
< |
if (response < ok) do line = getline(); while (line != ""); |
199 |
> |
if (response < ok) do line = getline(); while (!line.empty()); |
200 |
|
} |
201 |
|
while (response < ok); |
202 |
|
|
204 |
|
{ |
205 |
|
line = getline(); |
206 |
|
|
207 |
< |
if (line != "") |
207 |
> |
if (!line.empty()) |
208 |
|
{ |
209 |
< |
unsigned colon(line.find(':')); |
209 |
> |
size_t colon(line.find(':')); |
210 |
|
string field(line.substr(0, colon)), value(line.substr(colon + 1)); |
211 |
|
|
212 |
|
while (isspace(value[0])) value.erase(0, 1); |
231 |
|
} |
232 |
|
} |
233 |
|
} |
234 |
< |
while (line != ""); |
234 |
> |
while (!line.empty()); |
235 |
|
|
236 |
|
switch (response) |
237 |
|
{ |
280 |
|
|
281 |
|
closesocket(http); |
282 |
|
|
283 |
– |
type = ""; |
283 |
|
length = 0; |
285 |
– |
location = ""; |
284 |
|
|
285 |
+ |
type.erase(); |
286 |
+ |
location.erase(); |
287 |
|
page.clear(); |
288 |
|
page.str(""); |
289 |
|
|
297 |
|
{ |
298 |
|
if (!chunked) |
299 |
|
{ |
300 |
< |
unsigned left(length); |
300 |
> |
size_t left(length); |
301 |
|
|
302 |
|
while (left > 0) |
303 |
|
{ |
304 |
|
memset(buffer, 0, BUFSIZ + 1); |
305 |
|
|
306 |
< |
unsigned bytes(left > BUFSIZ ? BUFSIZ : left); |
306 |
> |
size_t bytes(left > BUFSIZ ? BUFSIZ : left); |
307 |
|
long received; |
308 |
|
|
309 |
|
while (true) |
342 |
|
} |
343 |
|
else |
344 |
|
{ |
345 |
< |
unsigned chunk; |
345 |
> |
size_t chunk; |
346 |
|
|
347 |
|
do |
348 |
|
{ |
352 |
|
|
353 |
|
number >> chunk; |
354 |
|
|
355 |
< |
unsigned left(chunk); |
355 |
> |
size_t left(chunk); |
356 |
|
|
357 |
|
while (left > 0) |
358 |
|
{ |
359 |
|
memset(buffer, 0, BUFSIZ + 1); |
360 |
|
|
361 |
< |
unsigned bytes(left > BUFSIZ ? BUFSIZ : left); |
361 |
> |
size_t bytes(left > BUFSIZ ? BUFSIZ : left); |
362 |
|
long received; |
363 |
|
|
364 |
|
while (true) |
408 |
|
{ |
409 |
|
string page(this->page.str()); |
410 |
|
|
411 |
< |
for (unsigned index(0); index < page.length(); index++) |
411 |
> |
for (size_t index(0); index < page.length(); index++) |
412 |
|
{ |
413 |
|
if (page[index] == '\r' && (index + 1 < page.length()) ? |
414 |
|
page[index + 1] == '\n' : false) |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
< |
void HttpHandler::putline(const string line) |
428 |
> |
void HttpHandler::putline(const string& line) |
429 |
|
{ |
430 |
|
sprintf(buffer, "%s\r\n", line.c_str()); |
431 |
|
|
762 |
|
|
763 |
|
#ifndef _urandomdev_ |
764 |
|
int pid(getpid()), now(time(NULL)); |
765 |
< |
unsigned seed(now > pid ? now - pid : pid - now); |
765 |
> |
size_t seed(now > pid ? now - pid : pid - now); |
766 |
|
char* junk = new char[seed % 30 + 2]; |
767 |
|
|
768 |
|
junk[0] = pid; |
781 |
|
|
782 |
|
for (size_t index = 1; index < seed % 30 + 2; index++) |
783 |
|
{ |
784 |
< |
cerr << " [" << index << "] = " << unsigned(junk[index]) << "\n"; |
784 |
> |
cerr << " [" << index << "] = " << size_t(junk[index]) << "\n"; |
785 |
|
} |
786 |
|
|
787 |
|
cerr << "}\n"; |