mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 18:50:29 +01:00
systemd: add nm_sd_http_url_is_valid() to access internal http_url_is_valid()
This commit is contained in:
parent
ce282fa3f7
commit
468c2e01ab
3 changed files with 61 additions and 15 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#include "hexdecoct.h"
|
#include "hexdecoct.h"
|
||||||
#include "hostname-util.h"
|
#include "hostname-util.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
|
#include "web-util.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
@ -94,3 +95,40 @@ gboolean nm_sd_hostname_is_valid (const char *s, bool allow_trailing_dot)
|
||||||
{
|
{
|
||||||
return hostname_is_valid (s, allow_trailing_dot);
|
return hostname_is_valid (s, allow_trailing_dot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_http_url_is_valid (const char *url)
|
||||||
|
{
|
||||||
|
if ( !url
|
||||||
|
|| !url[0])
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (NM_STR_HAS_PREFIX (url, "http://"))
|
||||||
|
url += NM_STRLEN ("http://");
|
||||||
|
else if (NM_STR_HAS_PREFIX (url, "https://"))
|
||||||
|
url += NM_STRLEN ("https://");
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!url[0])
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return !NM_STRCHAR_ANY (url, ch, (guchar) ch >= 128u);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
nm_sd_http_url_is_valid (const char *url)
|
||||||
|
{
|
||||||
|
gboolean v;
|
||||||
|
|
||||||
|
/* http_url_is_valid() is part of our API, as we use it to validate connection
|
||||||
|
* properties. That means, it's behavior must remain stable (or only change
|
||||||
|
* with care).
|
||||||
|
*
|
||||||
|
* Thus, reimplement it, and make sure that our implementation agrees. */
|
||||||
|
v = _http_url_is_valid (url);
|
||||||
|
nm_assert (v == http_url_is_valid (url));
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,4 +34,8 @@ int nm_sd_dns_name_to_wire_format (const char *domain,
|
||||||
int nm_sd_dns_name_is_valid (const char *s);
|
int nm_sd_dns_name_is_valid (const char *s);
|
||||||
gboolean nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot);
|
gboolean nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot);
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
gboolean nm_sd_http_url_is_valid (const char *url);
|
||||||
|
|
||||||
#endif /* __NM_SD_UTILS_SHARED_H__ */
|
#endif /* __NM_SD_UTILS_SHARED_H__ */
|
||||||
|
|
|
||||||
|
|
@ -24,21 +24,25 @@ bool http_etag_is_valid(const char *etag) {
|
||||||
}
|
}
|
||||||
#endif /* NM_IGNORED */
|
#endif /* NM_IGNORED */
|
||||||
|
|
||||||
bool http_url_is_valid(const char *url) {
|
/* NM: we use http_url_is_valid() for our own code, and it must not
|
||||||
const char *p;
|
* change behavior. If a re-import results in a merge-conflict, you must
|
||||||
|
* ensure that it does not change behavior, and possibly do something
|
||||||
if (isempty(url))
|
* about that. */
|
||||||
return false;
|
/**/ bool http_url_is_valid(const char *url) {
|
||||||
|
/**/ const char *p;
|
||||||
p = STARTSWITH_SET(url, "http://", "https://");
|
/**/
|
||||||
if (!p)
|
/**/ if (isempty(url))
|
||||||
return false;
|
/**/ return false;
|
||||||
|
/**/
|
||||||
if (isempty(p))
|
/**/ p = STARTSWITH_SET(url, "http://", "https://");
|
||||||
return false;
|
/**/ if (!p)
|
||||||
|
/**/ return false;
|
||||||
return ascii_is_valid(p);
|
/**/
|
||||||
}
|
/**/ if (isempty(p))
|
||||||
|
/**/ return false;
|
||||||
|
/**/
|
||||||
|
/**/ return ascii_is_valid(p);
|
||||||
|
/**/ }
|
||||||
|
|
||||||
#if 0 /* NM_IGNORED */
|
#if 0 /* NM_IGNORED */
|
||||||
bool documentation_url_is_valid(const char *url) {
|
bool documentation_url_is_valid(const char *url) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue