diff --git a/src/motd.cpp b/src/motd.cpp index 8ad0b9caa..2fbef9526 100644 --- a/src/motd.cpp +++ b/src/motd.cpp @@ -23,7 +23,7 @@ static const char *szMotdCachePath() return ""; const char *homedir = pw->pw_dir; sdsMotdCachePath = sdsnew(homedir); - sdsMotdCachePath = sdscat(sdsMotdCachePath, "/.keydb-cli-motd"); + sdsMotdCachePath = sdscat(sdsMotdCachePath, motd_cache_file); return sdsMotdCachePath; } static size_t motd_write_callback(void *ptr, size_t size, size_t nmemb, sds *str) @@ -101,6 +101,17 @@ extern "C" char *fetchMOTD(int cache) sdsfree(str); str = NULL; } + else + { + long response_code; + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); + if ((response_code / 100) != 2) + { + // An error code not in the 200s implies an error + sdsfree(str); + str = NULL; + } + } /* always cleanup */ curl_easy_cleanup(curl); diff --git a/src/motd.h b/src/motd.h index 31479c9b2..c57e63726 100644 --- a/src/motd.h +++ b/src/motd.h @@ -1,6 +1,7 @@ #pragma once extern const char *motd_url; +extern const char *motd_cache_file; #ifdef __cplusplus extern "C" { diff --git a/src/redis-cli.c b/src/redis-cli.c index ab9ff2896..6bcba8297 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -97,6 +97,7 @@ int spectrum_palette_size; int g_fInCrash = 0; const char *motd_url = "http://api.keydb.dev/motd/motd_cli.txt"; +const char *motd_cache_file = "/.keydb-cli-motd"; /*------------------------------------------------------------------------------ * Utility functions diff --git a/src/server.cpp b/src/server.cpp index c07e3d59e..7b72a804f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -66,6 +66,7 @@ int g_fTestMode = false; const char *motd_url = "http://api.keydb.dev/motd/motd_server.txt"; +const char *motd_cache_file = "/.keydb-server-motd"; /* Our shared "common" objects */