summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortastytea2020-01-06 15:33:48 +0100
committertastytea2020-01-06 16:38:09 +0100
commitf01ec3eee0bf004e88d08a8b7f2b3bd0b6440522 (patch)
tree83dc043c93a8970814558437d77ba7cf7bd2d7f7
parentf195c5bcef69a093b93fa9b1e3f5294bad7c6e14 (diff)
downloadmastodonpp-f01ec3eee0bf004e88d08a8b7f2b3bd0b6440522.tar
mastodonpp-f01ec3eee0bf004e88d08a8b7f2b3bd0b6440522.tar.gz
mastodonpp-f01ec3eee0bf004e88d08a8b7f2b3bd0b6440522.zip
Set User-Agent.
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/curl_wrapper.cpp11
2 files changed, 13 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e6d20ee..cdb651b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,7 +4,7 @@ find_package(CURL REQUIRED)
# Write version in header.
configure_file ("version.hpp.in"
- "${PROJECT_BINARY_DIR}/version.hpp" @ONLY)
+ "${CMAKE_CURRENT_BINARY_DIR}/version.hpp" @ONLY)
add_library(${PROJECT_NAME})
@@ -19,7 +19,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
target_include_directories(${PROJECT_NAME}
PRIVATE
- "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>" # version.hpp
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" # version.hpp
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp
index b4b9dde..996f5fb 100644
--- a/src/curl_wrapper.cpp
+++ b/src/curl_wrapper.cpp
@@ -17,8 +17,10 @@
#include "curl_wrapper.hpp"
#include "exceptions.hpp"
#include "log.hpp"
+#include "version.hpp"
#include <cstdint>
+#include <cstring>
namespace mastodonpp
{
@@ -180,6 +182,15 @@ void CURLWrapper::setup_curl()
throw CURLException{code, "Failed to set write data",
_curl_buffer_error};
}
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ code = curl_easy_setopt(_connection, CURLOPT_USERAGENT,
+ string("mastorss/").append(version).c_str());
+ if (code != CURLE_OK)
+ {
+ throw CURLException{code, "Failed to set User-Agent",
+ _curl_buffer_error};
+ }
}
} // namespace mastodonpp