๐Ÿ A very simple static Gemini server, now with Titan support!
cpp gemini titan gemini-protocol titan-protocol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(maple): move environment work to function

Fuwn 9a5a3aa8 dc8ce1e3

+54 -47
+53 -47
maple/maple.cc
··· 39 39 std::string titan_token; 40 40 size_t titan_max_size = 0; 41 41 42 - // Check if the user is want to support Titan 43 - { 44 - char *titan_environment = std::getenv("TITAN"); 45 - 46 - if (titan_environment == nullptr) { 47 - titan = false; 48 - } else { 49 - std::string valid_titan_environment(titan_environment); 50 - 51 - std::transform( 52 - valid_titan_environment.begin(), 53 - valid_titan_environment.end(), 54 - valid_titan_environment.begin(), 55 - [](unsigned char c) -> int { return std::tolower(c); } 56 - ); 57 - 58 - if (valid_titan_environment == "true" || valid_titan_environment == "1") { 59 - char *unvalidated_titan_token = std::getenv("TITAN_TOKEN"); 60 - char *unvalidated_titan_max_size = std::getenv("TITAN_MAX_SIZE"); 61 - 62 - if (unvalidated_titan_token == nullptr) { 63 - titan_token = ""; 64 - } else { 65 - titan_token = std::string(unvalidated_titan_token); 66 - } 67 - 68 - if (unvalidated_titan_max_size == nullptr) { 69 - titan_max_size = 1024; 70 - 71 - std::cout << "no TITAN_MAX_SIZE set, defaulting to 1024" << std::endl; 72 - } else { 73 - try { 74 - titan_max_size = static_cast<size_t>( 75 - std::stoi(unvalidated_titan_max_size) 76 - ); 77 - } catch (...) { 78 - maple::exit_with( 79 - "TITAN_MAX_SIZE could not be interpreted as an integer", 80 - false 81 - ); 82 - } 83 - } 84 - 85 - titan = true; 86 - } 87 - } 88 - } 42 + // Check if the user is want to support Titan and set it up 43 + maple::setup_environment(titan, titan_token, titan_max_size); 89 44 90 45 // Try a graceful shutdown when a SIGINT is detected 91 46 signal(SIGINT, [](int signal_) -> void { ··· 295 250 if (ssl) { ERR_print_errors_fp(stderr); } 296 251 297 252 std::exit(EXIT_FAILURE); 253 + } 254 + 255 + auto setup_environment( 256 + bool &titan, 257 + std::string &titan_token, 258 + size_t &titan_max_size 259 + ) -> void { 260 + char *titan_environment = std::getenv("TITAN"); 261 + 262 + if (titan_environment == nullptr) { 263 + titan = false; 264 + } else { 265 + std::string valid_titan_environment(titan_environment); 266 + 267 + std::transform( 268 + valid_titan_environment.begin(), 269 + valid_titan_environment.end(), 270 + valid_titan_environment.begin(), 271 + [](unsigned char c) -> int { return std::tolower(c); } 272 + ); 273 + 274 + if (valid_titan_environment == "true" || valid_titan_environment == "1") { 275 + char *unvalidated_titan_token = std::getenv("TITAN_TOKEN"); 276 + char *unvalidated_titan_max_size = std::getenv("TITAN_MAX_SIZE"); 277 + 278 + if (unvalidated_titan_token == nullptr) { 279 + titan_token = ""; 280 + } else { 281 + titan_token = std::string(unvalidated_titan_token); 282 + } 283 + 284 + if (unvalidated_titan_max_size == nullptr) { 285 + titan_max_size = 1024; 286 + 287 + std::cout << "no TITAN_MAX_SIZE set, defaulting to 1024" << std::endl; 288 + } else { 289 + try { 290 + titan_max_size = static_cast<size_t>( 291 + std::stoi(unvalidated_titan_max_size) 292 + ); 293 + } catch (...) { 294 + maple::exit_with( 295 + "TITAN_MAX_SIZE could not be interpreted as an integer", 296 + false 297 + ); 298 + } 299 + } 300 + 301 + titan = true; 302 + } 303 + } 298 304 } 299 305 }
+1
maple/maple.hh
··· 28 28 static SSL_CTX *ssl_context; 29 29 30 30 auto exit_with[[noreturn]](const char *, bool) -> void; 31 + auto setup_environment(bool &, std::string &, size_t &) -> void; 31 32 } 32 33 33 34 #endif // MAPLE_HH