hal: Branch 'origin'

Joe Marcus Clarke marcus at kemper.freedesktop.org
Tue Nov 28 18:47:40 PST 2006


 fdi/fdi.dtd        |    4 +
 hald/device_info.c |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 112 insertions(+), 1 deletion(-)

New commits:
diff-tree 88c3448a705e0f6bc23fce1ac5881caa87d6c26e (from 26771543399755085d885234c68ff4f9888015ab)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Nov 28 18:04:18 2006 +0000

    add prefix and suffix to the fdi attribute list
    
    Add prefix, prefix_ncase, suffix and suffix_ncase support to
    the fdi files, so we can do some efficient matches for the DMI data.
    The ncase variant is case insensitive.

diff --git a/fdi/fdi.dtd b/fdi/fdi.dtd
index 360d917..8a827f2 100644
--- a/fdi/fdi.dtd
+++ b/fdi/fdi.dtd
@@ -20,6 +20,10 @@
     is_absolute_path (false|true) #IMPLIED
     contains         CDATA #IMPLIED
     contains_ncase   CDATA #IMPLIED
+    prefix           CDATA #IMPLIED
+    prefix_ncase     CDATA #IMPLIED
+    suffix           CDATA #IMPLIED
+    suffix_ncase     CDATA #IMPLIED
     compare_lt       CDATA #IMPLIED
     compare_le       CDATA #IMPLIED
     compare_gt       CDATA #IMPLIED
diff --git a/hald/device_info.c b/hald/device_info.c
index d991aed..e6077f8 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -94,6 +94,10 @@ match_type {
 	MATCH_IS_ABS_PATH,
 	MATCH_CONTAINS,
 	MATCH_CONTAINS_NCASE,
+	MATCH_PREFIX,
+	MATCH_PREFIX_NCASE,
+	MATCH_SUFFIX,
+	MATCH_SUFFIX_NCASE,
 	MATCH_COMPARE_LT,
 	MATCH_COMPARE_LE,
 	MATCH_COMPARE_GT,
@@ -254,6 +258,14 @@ match_type get_match_type(const char *st
 		return MATCH_CONTAINS;
 	if (strcmp (str, "contains_ncase") == 0)
 		return MATCH_CONTAINS_NCASE;
+	if (strcmp (str, "prefix") == 0)
+		return MATCH_PREFIX;
+	if (strcmp (str, "prefix_ncase") == 0)
+		return MATCH_PREFIX_NCASE;
+	if (strcmp (str, "suffix") == 0)
+		return MATCH_SUFFIX;
+	if (strcmp (str, "suffix_ncase") == 0)
+		return MATCH_SUFFIX_NCASE;
 	if (strcmp (str, "compare_lt") == 0)
 		return MATCH_COMPARE_LT;
 	if (strcmp (str, "compare_le") == 0)
@@ -290,6 +302,14 @@ get_match_type_str (enum match_type type
 		return "contains";
 	case MATCH_CONTAINS_NCASE:
 		return "contains_ncase";
+	case MATCH_PREFIX:
+		return "prefix";
+	case MATCH_PREFIX_NCASE:
+		return "prefix_ncase";
+	case MATCH_SUFFIX:
+		return "suffix";
+	case MATCH_SUFFIX_NCASE:
+		return "suffix_ncase";
 	case MATCH_COMPARE_LT:
 		return "compare_lt";
 	case MATCH_COMPARE_LE:
@@ -694,11 +714,98 @@ handle_match (struct rule *rule, HalDevi
 					break;
 				}
 			}
-		} else
+		} else {
 			return FALSE;
+		}
 		return contains_ncase;
 	}
 
+	case MATCH_PREFIX:
+	{
+		dbus_bool_t prefix = FALSE;
+
+		if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_STRING) {
+			if (hal_device_has_property (d, prop_to_check)) {
+				const char *haystack;
+				haystack = hal_device_property_get_string (d, prop_to_check);
+				if (value != NULL && haystack != NULL &&
+				    g_str_has_prefix (haystack, value)) {
+					prefix = TRUE;
+				}
+			}
+		} else {
+			return FALSE;
+		}
+
+		return prefix;
+	}
+
+	case MATCH_PREFIX_NCASE:
+	{
+		dbus_bool_t prefix_ncase = FALSE;
+
+		if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_STRING) {
+			if (hal_device_has_property (d, prop_to_check)) {
+				char *value_lowercase;
+				char *haystack_lowercase;
+				value_lowercase   = g_utf8_strdown (value, -1);
+				haystack_lowercase = g_utf8_strdown (hal_device_property_get_string (d, prop_to_check), -1);
+				if (value_lowercase != NULL && haystack_lowercase != NULL &&
+				    g_str_has_prefix (haystack_lowercase, value_lowercase)) {
+					prefix_ncase = TRUE;
+				}
+				g_free (value_lowercase);
+				g_free (haystack_lowercase);
+			}
+		} else {
+			return FALSE;
+		}
+		return prefix_ncase;
+	}
+
+	case MATCH_SUFFIX:
+	{
+		dbus_bool_t suffix = FALSE;
+
+		if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_STRING) {
+			if (hal_device_has_property (d, prop_to_check)) {
+				const char *haystack;
+				haystack = hal_device_property_get_string (d, prop_to_check);
+				if (value != NULL && haystack != NULL &&
+				    g_str_has_suffix (haystack, value)) {
+					suffix = TRUE;
+				}
+			}
+		} else {
+			return FALSE;
+		}
+
+		return suffix;
+	}
+
+	case MATCH_SUFFIX_NCASE:
+	{
+		dbus_bool_t suffix_ncase = FALSE;
+
+		if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_STRING) {
+			if (hal_device_has_property (d, prop_to_check)) {
+				char *value_lowercase;
+				char *haystack_lowercase;
+				value_lowercase   = g_utf8_strdown (value, -1);
+				haystack_lowercase = g_utf8_strdown (hal_device_property_get_string (d, prop_to_check), -1);
+				if (value_lowercase != NULL && haystack_lowercase != NULL &&
+				    g_str_has_suffix (haystack_lowercase, value_lowercase)) {
+					suffix_ncase = TRUE;
+				}
+				g_free (value_lowercase);
+				g_free (haystack_lowercase);
+			}
+		} else {
+			return FALSE;
+		}
+		return suffix_ncase;
+	}
+
 	case MATCH_COMPARE_LT:
 	{
 		dbus_int64_t result;


More information about the hal-commit mailing list