summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-03-07 20:09:45 +0100
committerAotrix <[email protected]>2025-03-07 20:09:45 +0100
commit4afb11fa72abab1e71580afb40d40f7a5a15edf9 (patch)
tree73721896ddec088166a8be530e7cf81db16656bc
parent672a39e969b0764ddd0839573c92fc662669f79f (diff)
added token regex
-rw-r--r--src/main.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index dbc9f8e..1fcbbe4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,11 +1,10 @@
-#include <algorithm>
#include <cctype>
+#include <cstdlib>
#include <curl/curl.h>
#include <curl/easy.h>
-#include <format>
#include <iostream>
#include <pqxx/pqxx>
-#include <string_view>
+#include <regex>
const pqxx::result execute_query(pqxx::work &transaction,
std::string_view query) {
@@ -72,10 +71,22 @@ std::string get_valid_token() {
"MrMkhVMNdOeqPL4Q4XVQAsRPR14J7Yq6");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
"grant_type=client_credentials");
- curl_easy_perform(curl);
+ CURLcode result_code;
+ result_code = curl_easy_perform(curl);
curl_easy_cleanup(curl);
+ if (result_code != CURLE_OK) {
+ std::cerr << "ERROR: token request failed" << std::endl;
+ std::exit(EXIT_FAILURE);
+ }
}
+ // FIXME: token_regex is not valid
+ std::regex token_regex("access_token:\"(\\w+)\"");
std::cout << output << std::endl;
+ auto token_it =
+ std::sregex_iterator(output.begin(), output.end(), token_regex);
+ std::smatch token = *token_it;
+ std::string token_str = token.str();
+ std::cout << std::format("Token trouvé: {}", token_str) << std::endl;
return "";
}