foreseen

A text-based gemini browser with prefetching.
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

commit 8e35b8507e4f2ff8b58134b95669c99b2f2966ca
parent e34a8a49d16a1bf7353d5ed929e0a81e38b3a388
Author: Andrew Laack <andrew@laack.co>
Date:   Mon, 28 Sep 2026 09:56:16 -0500

Add page size limit (default 5mb)

Diffstat:
MTODO.txt | 4++++
Minclude/shared.hpp | 3+++
Msrc/gemini-client.cpp | 15++++++++++++++-
Msrc/main.cpp | 1-
4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -99,3 +99,7 @@ - what are those? - this is messed up too: - gemini://supernovas.space/gemlog/2023-08-19-gemini-page-counter.gmi + +--- + +- some sort of rpc thing to do language tranlsations diff --git a/include/shared.hpp b/include/shared.hpp @@ -10,3 +10,6 @@ const int maxWidth = 80; // max text width (left and right will be pa const int CACHE_SIZE = 500; // max number of elements in history cache and prefetch cache (500 for both) const int COLOR_LINK = 159; // color used for links const int COLOR_PREFORMATTED = 201; // color used for preformatted text regions + + // We guarantee responses can be at least the size limit, and at most 4096 additional bytes +const int RESPONSE_SIZE_LIMIT_MB = 5; diff --git a/src/gemini-client.cpp b/src/gemini-client.cpp @@ -5,6 +5,7 @@ #include <sys/time.h> #include "../include/gemini-client.hpp" #include "../include/site.hpp" +#include "../include/shared.hpp" #include <chrono> #include "../include/utils.hpp" #include "../include/errors.hpp" @@ -73,14 +74,23 @@ Site* GeminiClient::getNetworkedSite(Link link, std::string crtPath, std::string std::string response; char buf[4096]; int n; + + int sizeRemaining = RESPONSE_SIZE_LIMIT_MB * 1024 * 1024; + bool truncated = false; + while ((n = BIO_read(bio, buf, sizeof buf)) > 0) { response.append(buf, n); + + sizeRemaining -= n; + if(sizeRemaining <= 0) { + truncated = true; + break; + } } BIO_free_all(bio); SSL_CTX_free(ctx); - std::size_t nl = response.find('\n'); if (nl == std::string::npos) { return nullptr; @@ -91,6 +101,9 @@ Site* GeminiClient::getNetworkedSite(Link link, std::string crtPath, std::string end -= 1; } + // TODO: should we track when these are truncated? We have a variable for that + // but nothign about it in our site. + std::string status = response.substr(0, end); std::string body = response.substr(nl + 1); diff --git a/src/main.cpp b/src/main.cpp @@ -15,7 +15,6 @@ #define CTRL(c) ((c) & 037) #endif - int lowestPos(std::vector<std::pair<std::string, TextRender>>& strLs) { return (strLs.size() - (LINES - 2)) + 1; // this gives us two new lines at the end because the last line should contain a \n. }