summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Kukawka <danny.kukawka@web.de>2006-08-31 18:53:09 +0200
committerDanny Kukawka <danny.kukawka@web.de>2006-08-31 18:53:09 +0200
commitcf4fa80cc891f9a254b3d47fd98eea834503a473 (patch)
tree7fc48a36ac98d8fe7fa2d0abc657bf94741e462f
parentbacb7b433d27381efd490b6e8bd6a3be4a8e6e92 (diff)
add support for attribute 'empty' for strlist to <match> tag
Added support for attribute 'empty' for type 'strlist' (currently only for type 'string') within the <match> tag of fdi-files. This should allow such kind of constructs: [...] <remove key="info.callouts.add" type="strlist">blah</remove> <match key="info.callouts.add" empty="true"> <remove key="info.callouts.add"></remove> </match> [...]
-rw-r--r--doc/spec/hal-spec-fdi-files.xml4
-rw-r--r--hald/device.c20
-rw-r--r--hald/device.h3
-rw-r--r--hald/device_info.c25
4 files changed, 43 insertions, 9 deletions
diff --git a/doc/spec/hal-spec-fdi-files.xml b/doc/spec/hal-spec-fdi-files.xml
index ba4f1af1..07411ad2 100644
--- a/doc/spec/hal-spec-fdi-files.xml
+++ b/doc/spec/hal-spec-fdi-files.xml
@@ -89,7 +89,7 @@
</listitem>
<listitem>
<para>
- <literal>empty</literal> - can only be used on string properties
+ <literal>empty</literal> - can only be used on string or strlist properties
with 'true' and 'false'.
The semantics for 'true' is to match only when the string is non-empty.
</para>
@@ -203,7 +203,7 @@
The <literal>&#60;remove&#62;</literal>, directive require only a key and can be used with all keys.
For <literal>strlist</literal> there is additionally a special syntax to remove a item from the
string list. For example to remove item 'bla' from property 'foo.bar':
- <literal>&#60;remove key="foo.bar" type="strlist"&#62;bla&#60;/merge&#62;</literal>
+ <literal>&#60;remove key="foo.bar" type="strlist"&#62;bla&#60;/remove&#62;</literal>
</para>
<para>
Device Information files are stored in the following standard hierachy with the following default
diff --git a/hald/device.c b/hald/device.c
index a1d91f76..ea7cf082 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -1294,3 +1294,23 @@ hal_device_property_strlist_remove (HalDevice *device,
return TRUE;
}
+
+gboolean
+hal_device_property_strlist_is_empty (HalDevice *device,
+ const char *key)
+{
+ GSList *strlist;
+
+ if ( hal_device_has_property (device, key)) {
+ strlist = hal_device_property_get_strlist (device, key);
+ if (strlist == NULL )
+ return TRUE;
+
+ if (g_slist_length (strlist) > 0)
+ return FALSE;
+ else
+ return TRUE;
+ }
+ return FALSE;
+}
+
diff --git a/hald/device.h b/hald/device.h
index 590ee037..c31353f6 100644
--- a/hald/device.h
+++ b/hald/device.h
@@ -173,7 +173,8 @@ gboolean hal_device_property_strlist_add (HalDevice *device,
gboolean hal_device_property_strlist_remove (HalDevice *device,
const char *key,
const char *value);
-
+gboolean hal_device_property_strlist_is_empty (HalDevice *device,
+ const char *key);
gboolean hal_device_property_remove (HalDevice *device,
const char *key);
diff --git a/hald/device_info.c b/hald/device_info.c
index 5803719a..b181321e 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -460,19 +460,32 @@ handle_match (ParsingContext * pc, const char **attr)
return TRUE;
}
} else if (strcmp (attr[2], "empty") == 0) {
+ int type;
dbus_bool_t is_empty = TRUE;
dbus_bool_t should_be_empty = TRUE;
+
if (strcmp (attr[3], "false") == 0)
should_be_empty = FALSE;
- if (hal_device_property_get_type (d, prop_to_check) != HAL_PROPERTY_TYPE_STRING)
+ type = hal_device_property_get_type (d, prop_to_check);
+ switch (type) {
+ case HAL_PROPERTY_TYPE_STRING:
+ if (hal_device_has_property (d, prop_to_check))
+ if (strlen (hal_device_property_get_string (d, prop_to_check)) > 0)
+ is_empty = FALSE;
+ break;
+ case HAL_PROPERTY_TYPE_STRLIST:
+ if (hal_device_has_property (d, prop_to_check))
+ if (!hal_device_property_strlist_is_empty(d, prop_to_check))
+ is_empty = FALSE;
+ break;
+ default:
+ /* explicit fallthrough */
return FALSE;
-
- if (hal_device_has_property (d, prop_to_check))
- if (strlen (hal_device_property_get_string (d, prop_to_check)) > 0)
- is_empty = FALSE;
-
+ break;
+ }
+
if (should_be_empty) {
if (is_empty)
return TRUE;