Skip to content

Commit f2b7566

Browse files
committed
fixes 1-3
1 parent 632f09c commit f2b7566

File tree

8 files changed

+402
-9
lines changed

8 files changed

+402
-9
lines changed

CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,33 @@ find_package(OpenSSL)
1313

1414
if(Boost_FOUND)
1515
include_directories(${Boost_INCLUDE_DIRS})
16-
add_executable(cpp_search_qt_creator main.cpp Crowler.h Crowler.cpp root_certificates.hpp
16+
add_executable(crowler
17+
main.cpp
18+
Crowler.h Crowler.cpp
19+
root_certificates.hpp
1720
DbManager.h DbManager.cpp
1821
Searcher.h Searcher.cpp
1922
SafeQueue.h SafeQueue.cpp
2023
IniParser.h IniParser.cpp
2124
exceptions.h
22-
config.ini)
25+
constants.h
26+
)
27+
add_executable(http_server
28+
http_server_small.cpp
29+
DbManager.h DbManager.cpp
30+
Searcher.h Searcher.cpp
31+
IniParser.h IniParser.cpp
32+
constants.h
33+
)
2334
add_subdirectory(./libpqxx-7.9.0 libpqxx-build)
24-
target_compile_features(cpp_search_qt_creator PRIVATE cxx_std_17)
25-
target_link_libraries(cpp_search_qt_creator ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto pqxx)# "${PQXX_LIBRARIES}")
35+
target_compile_features(crowler PRIVATE cxx_std_17)
36+
target_compile_features(http_server PRIVATE cxx_std_17)
37+
target_link_libraries(crowler ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto pqxx)# "${PQXX_LIBRARIES}")
38+
target_link_libraries(http_server ${Boost_LIBRARIES} pqxx)
2639
endif()
2740

2841
include(GNUInstallDirs)
29-
install(TARGETS cpp_search_qt_creator
42+
install(TARGETS crowler
3043
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
3144
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
3245
)

Crowler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ std::string Crowler::download(std::string url)
9292
// Make the connection on the IP address we get from a lookup
9393
beast::get_lowest_layer(stream).connect(results);
9494

95+
if (!SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
96+
{
97+
boost::system::error_code ec{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() };
98+
throw boost::system::system_error{ ec };
99+
}
100+
95101
// Perform the SSL handshake
96102
stream.handshake(ssl::stream_base::client);
97103

@@ -174,7 +180,7 @@ void Crowler::savePresencesToDb(std::vector<std::string> words, std::string url)
174180

175181
void Crowler::processStartPage()
176182
{
177-
IniParser parser("/Users/tkvitko/c/netology/cpp_diploma/cpp_search_qt_creator/config.ini"); // не хочет работать с "./config.ini"
183+
IniParser parser(CONFIG_PATH);
178184
std::string url = parser.get_value<std::string>("Crowler.startPage");
179185
unsigned short depth = parser.get_value<unsigned short>("Crowler.recursionDepth");
180186
addToCrowlingQueue(url, depth);

DbManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DbManager::DbManager()
88
{
99

10-
IniParser parser("/Users/tkvitko/c/netology/cpp_diploma/cpp_search_qt_creator/config.ini"); // не хочет работать с "./config.ini"
10+
IniParser parser(CONFIG_PATH);
1111
std::string host = parser.get_value<std::string>("Db.host");
1212
std::string port = parser.get_value<std::string>("Db.port");
1313
std::string dbname = parser.get_value<std::string>("Db.name");

DbManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string>
55
#include <pqxx/pqxx>
66
#include <iostream>
7+
#include "constants.h"
78

89

910
struct WordPresence {

IniParser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class IniParser {
9191
template <>
9292
float get_value(std::string value_path);
9393

94+
template <>
95+
unsigned short get_value(std::string value_path);
96+
9497
};
9598

9699
#endif // INIPARSER_H

Searcher.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ std::vector<std::string> Searcher::processSearchRequest(std::vector<std::string>
77
{
88
// получение ресурсов из базы данных для ответа на запрос
99

10-
DbManager dbManager = DbManager();
11-
std::vector<std::string> result = dbManager.getSortedUrlsByWords(words);
10+
std::vector<std::string> result;
11+
try {
12+
DbManager dbManager = DbManager();
13+
result = dbManager.getSortedUrlsByWords(words);
14+
} catch (std::exception const& e) {
15+
std::cout << e.what() << std::endl;
16+
}
1217
return result;
1318
}

constants.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef CONSTANTS_H
2+
#define CONSTANTS_H
3+
4+
#include <string>
5+
6+
const std::string CONFIG_PATH = "/Users/tkvitko/c/netology/cpp_diploma/cpp_search_qt_creator/config.ini"; // не хочет работать с "./config.ini"
7+
8+
#endif // CONSTANTS_H

0 commit comments

Comments
 (0)