libnm-util: move nm_utils_is_uuid() here

This is useful outside the daemon too, so move it into libnm-utils.
This commit is contained in:
Dan Winship
2012-09-19 10:36:07 -04:00
parent 77c90d3f36
commit 74b6b9c768
6 changed files with 30 additions and 38 deletions

View File

@@ -520,6 +520,7 @@ global:
nm_utils_ip6_routes_from_gvalue; nm_utils_ip6_routes_from_gvalue;
nm_utils_ip6_routes_to_gvalue; nm_utils_ip6_routes_to_gvalue;
nm_utils_is_empty_ssid; nm_utils_is_empty_ssid;
nm_utils_is_uuid;
nm_utils_rsa_key_encrypt; nm_utils_rsa_key_encrypt;
nm_utils_same_ssid; nm_utils_same_ssid;
nm_utils_security_type_get_type; nm_utils_security_type_get_type;

View File

@@ -24,7 +24,6 @@
*/ */
#include <string.h> #include <string.h>
#include <ctype.h>
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dbus-glib-types.h" #include "nm-dbus-glib-types.h"
#include "nm-param-spec-specialized.h" #include "nm-param-spec-specialized.h"
@@ -628,22 +627,6 @@ find_setting_by_name (gconstpointer a, gconstpointer b)
return strcmp (nm_setting_get_name (setting), str); return strcmp (nm_setting_get_name (setting), str);
} }
static gboolean
validate_uuid (const char *uuid)
{
int i;
if (!uuid || !strlen (uuid))
return FALSE;
for (i = 0; i < strlen (uuid); i++) {
if (!isxdigit (uuid[i]) && (uuid[i] != '-'))
return FALSE;
}
return TRUE;
}
static gboolean static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error) verify (NMSetting *setting, GSList *all_settings, GError **error)
{ {
@@ -669,7 +652,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY, NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
NM_SETTING_CONNECTION_UUID); NM_SETTING_CONNECTION_UUID);
return FALSE; return FALSE;
} else if (!validate_uuid (priv->uuid)) { } else if (!nm_utils_is_uuid (priv->uuid)) {
g_set_error (error, g_set_error (error,
NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,

View File

@@ -2584,7 +2584,7 @@ nm_utils_hwaddr_ntoa (gconstpointer addr, int type)
} }
/** /**
* nm_utils_iface_name_valid: * nm_utils_iface_valid_name:
* @name: Name of interface * @name: Name of interface
* *
* This function is a 1:1 copy of the kernel's interface validation * This function is a 1:1 copy of the kernel's interface validation
@@ -2614,3 +2614,28 @@ nm_utils_iface_valid_name (const char *name)
return TRUE; return TRUE;
} }
/**
* nm_utils_is_uuid:
* @str: a string that might be a UUID
*
* Checks if @str is a UUID
*
* Returns: %TRUE if @str is a UUID, %FALSE if not
*/
gboolean
nm_utils_is_uuid (const char *str)
{
const char *p = str;
int num_dashes = 0;
while (*p) {
if (*p == '-')
num_dashes++;
else if (!isxdigit (*p))
return FALSE;
p++;
}
return (num_dashes == 4) && (p - str == 36);
}

View File

@@ -137,6 +137,8 @@ guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer);
gboolean nm_utils_iface_valid_name(const char *name); gboolean nm_utils_iface_valid_name(const char *name);
gboolean nm_utils_is_uuid (const char *str);
G_END_DECLS G_END_DECLS
#endif /* NM_UTILS_H */ #endif /* NM_UTILS_H */

View File

@@ -799,23 +799,6 @@ nm_utils_complete_generic (NMConnection *connection,
} }
} }
gboolean
nm_utils_is_uuid (const char *str)
{
const char *p = str;
int num_dashes = 0;
while (*p) {
if (*p == '-')
num_dashes++;
else if (!isxdigit (*p))
return FALSE;
p++;
}
return (num_dashes == 4) && (p - str == 36);
}
char * char *
nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id) nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id)
{ {

View File

@@ -90,8 +90,6 @@ void nm_utils_complete_generic (NMConnection *connection,
const char *preferred, const char *preferred,
gboolean default_enable_ipv6); gboolean default_enable_ipv6);
gboolean nm_utils_is_uuid (const char *str);
char *nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id); char *nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id);
#endif /* NETWORK_MANAGER_UTILS_H */ #endif /* NETWORK_MANAGER_UTILS_H */