cgmnlm

colorful gemini line mode browser
git clone https://git.clttr.info/cgmnlm.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 33495e8dd86139cafade2888227e37b1572d18ea
parent 05d112b7d347b737bdac503ea05292db3347f2a8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 20 Sep 2020 16:47:19 -0400

Detect attempts to use non-gemini URLs

Diffstat:
Minclude/gmni.h | 1+
Msrc/client.c | 19+++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/gmni.h b/include/gmni.h @@ -8,6 +8,7 @@ enum gemini_result { GEMINI_OK, GEMINI_ERR_OOM, GEMINI_ERR_INVALID_URL, + GEMINI_ERR_NOT_GEMINI, GEMINI_ERR_RESOLVE, GEMINI_ERR_CONNECT, GEMINI_ERR_SSL, diff --git a/src/client.c b/src/client.c @@ -104,11 +104,24 @@ gemini_request(const char *url, struct gemini_options *options, if (!uri) { return GEMINI_ERR_OOM; } + + enum gemini_result res = GEMINI_OK; if (curl_url_set(uri, CURLUPART_URL, url, 0) != CURLUE_OK) { - return GEMINI_ERR_INVALID_URL; + res = GEMINI_ERR_INVALID_URL; + goto cleanup; + } + + char *scheme; + if (curl_url_get(uri, CURLUPART_SCHEME, &scheme, 0) != CURLUE_OK) { + res = GEMINI_ERR_INVALID_URL; + goto cleanup; + } else { + if (strcmp(scheme, "gemini") != 0) { + res = GEMINI_ERR_NOT_GEMINI; + goto cleanup; + } } - enum gemini_result res = GEMINI_OK; if (options && options->ssl_ctx) { resp->ssl_ctx = options->ssl_ctx; SSL_CTX_up_ref(options->ssl_ctx); @@ -226,6 +239,8 @@ gemini_strerr(enum gemini_result r, struct gemini_response *resp) return "Out of memory"; case GEMINI_ERR_INVALID_URL: return "Invalid URL"; + case GEMINI_ERR_NOT_GEMINI: + return "Not a gemini URL"; case GEMINI_ERR_RESOLVE: return gai_strerror(resp->status); case GEMINI_ERR_CONNECT: