65 |
|
string title, description, text; |
66 |
|
vector<string> headings; |
67 |
|
|
68 |
< |
if (html(http)) |
68 |
> |
if (http.contentType().find("text/html") == 0) |
69 |
|
{ |
70 |
|
if (!process(http, url, title, description, text, headings)) return |
71 |
|
false; |
107 |
|
} |
108 |
|
else |
109 |
|
{ |
110 |
< |
bool knowSize = page->getSize() > 0; |
110 |
> |
// bool knowSize = page->getSize() > 0; |
111 |
|
|
112 |
|
string line; |
113 |
|
while (http.good()) |
116 |
|
|
117 |
|
text += line + "\n"; |
118 |
|
|
119 |
< |
if (!knowSize) page->setSize(page->getSize() + line.length() + 1); |
119 |
> |
// if (!knowSize) page->setSize(page->getSize() + line.length() + 1); |
120 |
|
} |
121 |
|
|
122 |
|
normalize(text); |
123 |
|
} |
124 |
|
|
125 |
+ |
page->setSize(http.contentLength()); |
126 |
|
page->setURL(url); |
127 |
|
page->setTitle(title); |
128 |
|
page->setDescription(description); |
143 |
|
description, string& text, vector<string>& headings) |
144 |
|
{ |
145 |
|
bool inHtml = false, inHead = false, inTitle = false, inBody = false, |
146 |
< |
inHeading = false, inComment = false, knowSize = page->getSize() > 0, |
147 |
< |
follow = true, answer = true; |
146 |
> |
inHeading = false, inComment = false, /*knowSize = page->getSize() > 0, |
147 |
> |
*/ follow = true, answer = true; |
148 |
|
unsigned startComment = 0, finishComment = 0; |
149 |
|
string line; |
150 |
|
while (http.good()) |
244 |
|
unsigned start = lowerTag.find("href=\"") + 6; |
245 |
|
unsigned finish = lowerTag.find('\"', start); |
246 |
|
|
247 |
< |
string fred = tag.substr(start, finish - start); |
248 |
< |
string link = getLink(fred, url); |
247 |
> |
string link = getLink(tag.substr(start, finish - |
248 |
> |
start), url); |
249 |
|
|
250 |
< |
if (link != "bad link") links.insert(link); |
250 |
> |
if (link != "") links.insert(link); |
251 |
|
} |
252 |
|
else if (lowerTag.find("href=") != string::npos) |
253 |
|
{ |
256 |
|
|
257 |
|
if (finish < close) |
258 |
|
{ |
259 |
< |
string fred = tag.substr(start, finish - start); |
260 |
< |
string link = getLink(fred, url); |
259 |
> |
string link = getLink(tag.substr(start, finish - |
260 |
> |
start), url); |
261 |
|
|
262 |
< |
if (link != "bad link") links.insert(link); |
262 |
> |
if (link != "") links.insert(link); |
263 |
|
} |
264 |
|
else |
265 |
|
{ |
266 |
< |
string fred = tag.substr(start, close - start); |
267 |
< |
string link = getLink(fred, url); |
266 |
> |
string link = getLink(tag.substr(start, close - |
267 |
> |
start), url); |
268 |
|
|
269 |
< |
if (link != "bad link") links.insert(link); |
269 |
> |
if (link != "") links.insert(link); |
270 |
|
} |
271 |
|
} |
272 |
|
} |
355 |
|
startComment = 0; |
356 |
|
finishComment = 0; |
357 |
|
|
358 |
< |
if (!knowSize) page->setSize(page->getSize() + line.length() + 1); |
358 |
> |
// if (!knowSize) page->setSize(page->getSize() + line.length() + 1); |
359 |
|
} |
360 |
|
|
361 |
|
return answer; |
362 |
|
} |
363 |
|
|
364 |
< |
bool Processor::html(HttpHandler& http) |
364 |
> |
/*bool Processor::html(HttpHandler& http) |
365 |
|
{ |
366 |
|
bool answer = false; |
367 |
|
|
390 |
|
} |
391 |
|
|
392 |
|
return answer; |
393 |
< |
} |
393 |
> |
}*/ |
394 |
|
|
395 |
< |
string Processor::getTag(string& line, unsigned open, unsigned close) |
395 |
> |
string Processor::getTag(const string& line, unsigned open, unsigned close) |
396 |
|
{ |
397 |
|
string tag = line.substr(open + 1, close - open - 1); |
398 |
|
|
399 |
|
return tag; |
400 |
|
} |
400 |
– |
|
401 |
– |
string Processor::getLink(string& link, URL& url) |
402 |
– |
{ |
403 |
– |
string hyperlink = "bad link"; |
404 |
– |
|
405 |
– |
if (link.find('#') != string::npos) |
406 |
– |
{ |
407 |
– |
unsigned pound = link.find('#'); |
408 |
– |
link.erase(pound); |
409 |
– |
} |
410 |
– |
|
411 |
– |
if (link.find("://") != string::npos) |
412 |
– |
{ |
413 |
– |
if (link.find("http://") == 0) hyperlink = link; |
414 |
– |
} |
415 |
– |
else if (link.find("mailto:") == 0) |
416 |
– |
{ |
417 |
– |
// do nothing we are not evil spammers! |
418 |
– |
} |
419 |
– |
else if (link.find("//") == 0) |
420 |
– |
{ |
421 |
– |
hyperlink = "http:" + link; |
422 |
– |
} |
423 |
– |
else if (link.find('/') == 0) |
424 |
– |
{ |
425 |
– |
hyperlink = url.getURL(); |
426 |
– |
|
427 |
– |
unsigned path = hyperlink.find('/', 7); |
428 |
– |
hyperlink.erase(path); |
429 |
– |
|
430 |
– |
hyperlink += link; |
431 |
– |
} |
432 |
– |
else if (link == "") |
433 |
– |
{ |
434 |
– |
// a blank link is useless |
435 |
– |
} |
436 |
– |
else |
437 |
– |
{ |
438 |
– |
hyperlink = url.getURL(); |
439 |
– |
string path = url.getPath(); |
440 |
– |
|
441 |
– |
unsigned cutoff = hyperlink.rfind(path); |
442 |
– |
hyperlink.erase(cutoff); |
443 |
– |
|
444 |
– |
unsigned dir = path.rfind('/') + 1; |
445 |
– |
path.erase(dir); |
446 |
– |
|
447 |
– |
while (link.find("../") == 0) |
448 |
– |
{ |
449 |
– |
unsigned dot = path.rfind('/') - 1; |
450 |
– |
unsigned up = path.rfind('/', dot) + 1; |
451 |
– |
|
452 |
– |
path.erase(up); |
453 |
– |
link.erase(0, 3); |
454 |
– |
} |
455 |
– |
while (link.find("./") == 0) |
456 |
– |
{ |
457 |
– |
link.erase(0, 2); |
458 |
– |
} |
459 |
– |
|
460 |
– |
hyperlink += path + link; |
461 |
– |
} |
462 |
– |
|
463 |
– |
return hyperlink; |
464 |
– |
} |