From d9bb874591c63f2efbfc1c4c953934251c700e9f Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 20 Mar 2023 03:32:00 +0100 Subject: Send response on quota exceeded So far, slcl would just close the connection with a client when the Content-Length of an incoming request exceeded the user quota, without any meaningful information given back to the user. Now, slcl responds with a HTML file with meaningful information about the error. Limitations: - While this commits has been successfully tested on ungoogled-chromium, LibreWolf (and I assume Firefox and any other derivates too) does not seem to receive the response from the server. - However, this issue only occurred during local testing, but not on remote instances. --- main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 6e461b3..89edae3 100644 --- a/main.c +++ b/main.c @@ -610,7 +610,8 @@ static int check_quota(const struct auth *const a, const char *const username, } static int check_length(const unsigned long long len, - const struct http_cookie *const c, void *const user) + const struct http_cookie *const c, struct http_response *const r, + void *const user) { struct auth *const a = user; const char *const username = c->field; @@ -623,7 +624,16 @@ static int check_length(const unsigned long long len, return -1; } else if (has_quota) - return check_quota(a, username, len, quota); + { + int res = check_quota(a, username, len, quota); + + if (res < 0) + fprintf(stderr, "%s: check_quota failed\n", __func__); + else if (res > 0 && page_quota_exceeded(r, len, quota) < 0) + return -1; + + return res; + } return 0; } -- cgit v1.2.3