PublicIP: error out if non-http protocol is specified

This commit is contained in:
李通洲
2024-03-21 11:01:23 +08:00
parent 79ae650c58
commit 5e7baa9d0a
+10 -1
View File
@@ -20,7 +20,16 @@ void ffPreparePublicIp(FFPublicIpOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY host = ffStrbufCreateCopy(&options->url);
ffStrbufSubstrAfterFirstS(&host, "://");
uint32_t hostStartIndex = ffStrbufFirstIndexS(&host, "://");
if (hostStartIndex < host.length)
{
if (hostStartIndex != 4 || !ffStrbufStartsWithIgnCaseS(&host, "http"))
{
fputs("Error: only http: protocol is supported. Use `Command` module with `curl` if needed\n", stderr);
exit(1);
}
ffStrbufSubstrAfter(&host, hostStartIndex + (strlen("://") - 1));
}
uint32_t pathStartIndex = ffStrbufFirstIndexC(&host, '/');
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();