summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2012-09-19 10:36:07 -0400
committerDan Winship <danw@gnome.org>2012-09-26 12:14:37 -0400
commit74b6b9c768338ce3cd58d781fd837e6abbf3e209 (patch)
treeea6caf2d507453ae4f1dd39b18f9e3122b076c08
parent77c90d3f360f9a270a9a027d6b146791e2a0686a (diff)
libnm-util: move nm_utils_is_uuid() here
This is useful outside the daemon too, so move it into libnm-utils.
-rw-r--r--libnm-util/libnm-util.ver1
-rw-r--r--libnm-util/nm-setting-connection.c19
-rw-r--r--libnm-util/nm-utils.c27
-rw-r--r--libnm-util/nm-utils.h2
-rw-r--r--src/NetworkManagerUtils.c17
-rw-r--r--src/NetworkManagerUtils.h2
6 files changed, 30 insertions, 38 deletions
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 7507dff0..98de7d05 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -520,6 +520,7 @@ global:
nm_utils_ip6_routes_from_gvalue;
nm_utils_ip6_routes_to_gvalue;
nm_utils_is_empty_ssid;
+ nm_utils_is_uuid;
nm_utils_rsa_key_encrypt;
nm_utils_same_ssid;
nm_utils_security_type_get_type;
diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c
index b247a60f..77aff4fa 100644
--- a/libnm-util/nm-setting-connection.c
+++ b/libnm-util/nm-setting-connection.c
@@ -24,7 +24,6 @@
*/
#include <string.h>
-#include <ctype.h>
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-param-spec-specialized.h"
@@ -629,22 +628,6 @@ find_setting_by_name (gconstpointer a, gconstpointer b)
}
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
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting);
@@ -669,7 +652,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
NM_SETTING_CONNECTION_UUID);
return FALSE;
- } else if (!validate_uuid (priv->uuid)) {
+ } else if (!nm_utils_is_uuid (priv->uuid)) {
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c
index 1b04bd75..f88f1392 100644
--- a/libnm-util/nm-utils.c
+++ b/libnm-util/nm-utils.c
@@ -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
*
* 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;
}
+
+/**
+ * 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);
+}
diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h
index 28514864..ef4b875d 100644
--- a/libnm-util/nm-utils.h
+++ b/libnm-util/nm-utils.h
@@ -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_is_uuid (const char *str);
+
G_END_DECLS
#endif /* NM_UTILS_H */
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index c222c3e3..5dcc02ff 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -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 *
nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id)
{
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index 1ee40689..057ad283 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -90,8 +90,6 @@ void nm_utils_complete_generic (NMConnection *connection,
const char *preferred,
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);
#endif /* NETWORK_MANAGER_UTILS_H */