aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--maple/maple.cc100
-rw-r--r--maple/maple.hh1
2 files changed, 54 insertions, 47 deletions
diff --git a/maple/maple.cc b/maple/maple.cc
index 259110f..df39e05 100644
--- a/maple/maple.cc
+++ b/maple/maple.cc
@@ -39,53 +39,8 @@ auto main() -> int {
std::string titan_token;
size_t titan_max_size = 0;
- // Check if the user is want to support Titan
- {
- char *titan_environment = std::getenv("TITAN");
-
- if (titan_environment == nullptr) {
- titan = false;
- } else {
- std::string valid_titan_environment(titan_environment);
-
- std::transform(
- valid_titan_environment.begin(),
- valid_titan_environment.end(),
- valid_titan_environment.begin(),
- [](unsigned char c) -> int { return std::tolower(c); }
- );
-
- if (valid_titan_environment == "true" || valid_titan_environment == "1") {
- char *unvalidated_titan_token = std::getenv("TITAN_TOKEN");
- char *unvalidated_titan_max_size = std::getenv("TITAN_MAX_SIZE");
-
- if (unvalidated_titan_token == nullptr) {
- titan_token = "";
- } else {
- titan_token = std::string(unvalidated_titan_token);
- }
-
- if (unvalidated_titan_max_size == nullptr) {
- titan_max_size = 1024;
-
- std::cout << "no TITAN_MAX_SIZE set, defaulting to 1024" << std::endl;
- } else {
- try {
- titan_max_size = static_cast<size_t>(
- std::stoi(unvalidated_titan_max_size)
- );
- } catch (...) {
- maple::exit_with(
- "TITAN_MAX_SIZE could not be interpreted as an integer",
- false
- );
- }
- }
-
- titan = true;
- }
- }
- }
+ // Check if the user is want to support Titan and set it up
+ maple::setup_environment(titan, titan_token, titan_max_size);
// Try a graceful shutdown when a SIGINT is detected
signal(SIGINT, [](int signal_) -> void {
@@ -296,4 +251,55 @@ namespace maple {
std::exit(EXIT_FAILURE);
}
+
+ auto setup_environment(
+ bool &titan,
+ std::string &titan_token,
+ size_t &titan_max_size
+ ) -> void {
+ char *titan_environment = std::getenv("TITAN");
+
+ if (titan_environment == nullptr) {
+ titan = false;
+ } else {
+ std::string valid_titan_environment(titan_environment);
+
+ std::transform(
+ valid_titan_environment.begin(),
+ valid_titan_environment.end(),
+ valid_titan_environment.begin(),
+ [](unsigned char c) -> int { return std::tolower(c); }
+ );
+
+ if (valid_titan_environment == "true" || valid_titan_environment == "1") {
+ char *unvalidated_titan_token = std::getenv("TITAN_TOKEN");
+ char *unvalidated_titan_max_size = std::getenv("TITAN_MAX_SIZE");
+
+ if (unvalidated_titan_token == nullptr) {
+ titan_token = "";
+ } else {
+ titan_token = std::string(unvalidated_titan_token);
+ }
+
+ if (unvalidated_titan_max_size == nullptr) {
+ titan_max_size = 1024;
+
+ std::cout << "no TITAN_MAX_SIZE set, defaulting to 1024" << std::endl;
+ } else {
+ try {
+ titan_max_size = static_cast<size_t>(
+ std::stoi(unvalidated_titan_max_size)
+ );
+ } catch (...) {
+ maple::exit_with(
+ "TITAN_MAX_SIZE could not be interpreted as an integer",
+ false
+ );
+ }
+ }
+
+ titan = true;
+ }
+ }
+ }
}
diff --git a/maple/maple.hh b/maple/maple.hh
index b212f13..e192459 100644
--- a/maple/maple.hh
+++ b/maple/maple.hh
@@ -28,6 +28,7 @@ namespace maple {
static SSL_CTX *ssl_context;
auto exit_with[[noreturn]](const char *, bool) -> void;
+ auto setup_environment(bool &, std::string &, size_t &) -> void;
}
#endif // MAPLE_HH