PublicIp: add option to set public IP server URL

This commit is contained in:
李通洲
2022-09-29 14:22:40 +08:00
parent e289db184c
commit c72c6c4a27
7 changed files with 35 additions and 1 deletions
+23 -1
View File
@@ -9,7 +9,29 @@ static int sockfd;
void ffPreparePublicIp(FFinstance* instance)
{
sockfd = ffNetworkingSendHttpRequest("ipinfo.io", "/ip", instance->config.publicIpTimeout);
if(instance->config.publicIpUrl.length == 0)
sockfd = ffNetworkingSendHttpRequest("ipinfo.io", "/ip", instance->config.publicIpTimeout);
else
{
FFstrbuf host;
ffStrbufInitCopy(&host, &instance->config.publicIpUrl);
ffStrbufSubstrAfterFirstS(&host, "://");
uint32_t pathStartIndex = ffStrbufFirstIndexC(&host, '/');
FFstrbuf path;
ffStrbufInit(&path);
if(pathStartIndex != host.length)
{
ffStrbufAppendNS(&path, pathStartIndex, host.chars + (host.length - pathStartIndex));
host.length = pathStartIndex;
host.chars[pathStartIndex] = '\0';
}
sockfd = ffNetworkingSendHttpRequest(host.chars, path.length == 0 ? "/" : path.chars, instance->config.publicIpTimeout);
ffStrbufDestroy(&path);
ffStrbufDestroy(&host);
}
}
void ffPrintPublicIp(FFinstance* instance)