mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 22:48:01 +02:00
cloud-setup: add nmcs_utils_uri_complete_interned() for constructing URI for _ec2_base()
This commit is contained in:
parent
78adf4796e
commit
c6fefce8a4
3 changed files with 17 additions and 16 deletions
|
|
@ -665,6 +665,20 @@ nmcs_utils_uri_build_concat_v(const char *base, const char **components, gsize n
|
||||||
return nm_str_buf_finalize(&strbuf, NULL);
|
return nm_str_buf_finalize(&strbuf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
nmcs_utils_uri_complete_interned(const char *uri)
|
||||||
|
{
|
||||||
|
gs_free char *s = NULL;
|
||||||
|
|
||||||
|
if (nm_str_is_empty(uri))
|
||||||
|
return NULL;
|
||||||
|
if (NM_STR_HAS_PREFIX(uri, "http://") || NM_STR_HAS_PREFIX(uri, "https://") || strchr(uri, '/'))
|
||||||
|
return g_intern_string(uri);
|
||||||
|
|
||||||
|
s = g_strconcat("http://", uri, NULL);
|
||||||
|
return g_intern_string(s);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,8 @@ char *nmcs_utils_uri_build_concat_v(const char *base, const char **components, g
|
||||||
#define nmcs_utils_uri_build_concat(base, ...) \
|
#define nmcs_utils_uri_build_concat(base, ...) \
|
||||||
nmcs_utils_uri_build_concat_v(base, ((const char *[]){__VA_ARGS__}), NM_NARG(__VA_ARGS__))
|
nmcs_utils_uri_build_concat_v(base, ((const char *[]){__VA_ARGS__}), NM_NARG(__VA_ARGS__))
|
||||||
|
|
||||||
|
const char *nmcs_utils_uri_complete_interned(const char *uri);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
gboolean nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip,
|
gboolean nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip,
|
||||||
|
|
|
||||||
|
|
@ -29,22 +29,7 @@ again:
|
||||||
* This is mainly for testing, it's not usually supposed to be configured.
|
* This is mainly for testing, it's not usually supposed to be configured.
|
||||||
* Consider this private API! */
|
* Consider this private API! */
|
||||||
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2_HOST"));
|
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2_HOST"));
|
||||||
|
base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_EC2_BASE);
|
||||||
if (!nm_str_is_empty(base)) {
|
|
||||||
if (NM_STR_HAS_PREFIX(base, "http://") || NM_STR_HAS_PREFIX(base, "https://")
|
|
||||||
|| strchr(base, '/'))
|
|
||||||
base = g_intern_string(base);
|
|
||||||
else {
|
|
||||||
gs_free char *s = NULL;
|
|
||||||
|
|
||||||
s = g_strconcat("http://", base, NULL);
|
|
||||||
base = g_intern_string(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nm_str_is_empty(base))
|
|
||||||
base = NM_EC2_BASE;
|
|
||||||
|
|
||||||
nm_assert(!NM_STR_HAS_SUFFIX(base, "/"));
|
|
||||||
|
|
||||||
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
||||||
goto again;
|
goto again;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue