This repository was archived by the owner on Sep 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrippy.cpp
More file actions
55 lines (43 loc) · 1.31 KB
/
rippy.cpp
File metadata and controls
55 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "rippy.hpp"
#include <memory>
#pragma comment(lib, "Ws2_32.lib")
#include "HTTPRequest.hpp"
void rippyTask(LinkBuffer& lb, const rippyConfig& config)
{
std::cout << "thread (" << std::this_thread::get_id() << ") started.\n";
std::string link = lb.getNext();
try {
http::Request request(link);
const auto response = request.send("GET");
std::cout << std::string{response.body.begin(), response.body.end()} << '\n'; // print the result
// save to response.txt (create if not exists, overwrite if exists)
std::ofstream responseFile("response.txt", std::ios::out | std::ios::trunc);
responseFile << std::string{response.body.begin(), response.body.end()};
responseFile.close();
}
catch (const std::exception& e)
{
std::cerr << "Request failed, error: " << e.what() << '\n';
}
}
// linkbuffer definitions
void LinkBuffer::addToQueue(std::string_view link)
{
// add to unvisited_links
unvisited_links.push(link.data());
}
std::string LinkBuffer::getNext()
{
// get the next link from the queue
std::string link = unvisited_links.front();
unvisited_links.pop();
return link;
}
size_t LinkBuffer::visitedSize()
{
return visited_links.size();
}
size_t LinkBuffer::queueSize()
{
return unvisited_links.size();
}