mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
PublicIp: add option to set public IP server URL
This commit is contained in:
parent
e289db184c
commit
c72c6c4a27
@ -217,6 +217,7 @@ __fastfetch_completion()
|
||||
"--set"
|
||||
"--set-keyless"
|
||||
"--player-name"
|
||||
"--public-ip-url"
|
||||
"--public-ip-timeout"
|
||||
"--os-key"
|
||||
"--os-format"
|
||||
|
@ -243,6 +243,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffStrbufInit(&instance->config.localIpNamePrefix);
|
||||
|
||||
instance->config.publicIpTimeout = 0;
|
||||
ffStrbufInit(&instance->config.publicIpUrl);
|
||||
|
||||
ffStrbufInitA(&instance->config.osFile, 0);
|
||||
|
||||
|
@ -151,6 +151,12 @@
|
||||
# Default is "-"
|
||||
#--separator-string -
|
||||
|
||||
# Public IP URL option:
|
||||
# Sets the URL of public IP detection server to be used.
|
||||
# Only HTTP protocol is supported, and the value should not contain "http://" prefix.
|
||||
# Default is "ipinfo.io/ip".
|
||||
#--public-ip-url "ipinfo.io/ip"
|
||||
|
||||
# Public IP timeout option:
|
||||
# Sets the time to wait for the public ip server to respond.
|
||||
# Must be a positive integer.
|
||||
|
@ -103,6 +103,7 @@ Module specific options:
|
||||
--localip-show-loop <?value>: Show loop back addresses (127.0.0.1) in local ip module. Default is false
|
||||
--localip-name-prefix <str>: Show ips with given name prefix only. Default is empty
|
||||
--public-ip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
|
||||
--public-ip-url: The URL of public IP detection server to be used.
|
||||
--player-name: The name of the player to use
|
||||
--gl <value>: Sets the opengl context creation library to use. Must be auto, egl, glx or osmesa. Default is auto
|
||||
|
||||
|
@ -1291,6 +1291,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.osFile);
|
||||
else if(strcasecmp(key, "--player-name") == 0)
|
||||
optionParseString(key, value, &instance->config.playerName);
|
||||
else if(strcasecmp(key, "--public-ip-url") == 0)
|
||||
optionParseString(key, value, &instance->config.publicIpUrl);
|
||||
else if(strcasecmp(key, "--public-ip-timeout") == 0)
|
||||
instance->config.publicIpTimeout = optionParseUInt32(key, value);
|
||||
else if(strcasecmp(key, "--gl") == 0)
|
||||
|
@ -174,6 +174,7 @@ typedef struct FFconfig
|
||||
bool localIpShowIpV6;
|
||||
FFstrbuf localIpNamePrefix;
|
||||
|
||||
FFstrbuf publicIpUrl;
|
||||
uint32_t publicIpTimeout;
|
||||
|
||||
FFstrbuf osFile;
|
||||
|
@ -9,7 +9,29 @@ static int sockfd;
|
||||
|
||||
void ffPreparePublicIp(FFinstance* instance)
|
||||
{
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user