Logo Search packages:      
Sourcecode: hal version File versions

static dbus_bool_t handle_match ( ParsingContext pc,
const char **  attr 
) [static]

Called when the match element begins.

Parameters:
pc Parsing context
attr Attribute key/value pairs
Returns:
FALSE if the device in question didn't match the data in the attributes

Todo:
Check error condition

Todo:
Check error condition

Definition at line 312 of file device_info.c.

References ParsingContext::device, HAL_ERROR, and resolve_udiprop_path().

Referenced by start().

{
      char udi_to_check[256];
      char prop_to_check[256];
      const char *key;
      int num_attrib;
      HalDevice *d;

      for (num_attrib = 0; attr[num_attrib] != NULL; num_attrib++);

      if (num_attrib != 4)
            return FALSE;

      if (strcmp (attr[0], "key") != 0)
            return FALSE;
      key = attr[1];

      /* Resolve key paths like 'someudi/foo/bar/baz:prop.name' '@prop.here.is.an.udi:with.prop.name' */
      if (!resolve_udiprop_path (key,
                           pc->device->udi,
                           udi_to_check, sizeof (udi_to_check),
                           prop_to_check, sizeof (prop_to_check))) {
            HAL_ERROR (("Could not resolve keypath '%s' on udi '%s'", key, pc->device->udi));
            return FALSE;
      }

      d = hal_device_store_find (hald_get_gdl (), udi_to_check);
      if (d == NULL) {
            d = hal_device_store_find (hald_get_tdl (), udi_to_check);
      }
      if (d == NULL) {
            HAL_ERROR (("Could not find device with udi '%s'", udi_to_check));
            return FALSE;
      }
      

      if (strcmp (attr[2], "string") == 0) {
            const char *value;

            /* match string property */

            value = attr[3];

            /*HAL_INFO(("Checking that key='%s' is a string that "
              "equals '%s'", key, value)); */

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_STRING)
                  return FALSE;

            if (strcmp (hal_device_property_get_string (d, prop_to_check),
                      value) != 0)
                  return FALSE;

            /*HAL_INFO (("*** string match for key %s", key));*/
            return TRUE;
      } else if (strcmp (attr[2], "int") == 0) {
            dbus_int32_t value;

            /* match integer property */
            value = strtol (attr[3], NULL, 0);
            
            /** @todo Check error condition */

            /*HAL_INFO (("Checking that key='%s' is a int that equals %d", 
              key, value));*/

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_INT32)
                  return FALSE;

            if (hal_device_property_get_int (d, prop_to_check) != value) {
                  return FALSE;
            }

            return TRUE;
      } else if (strcmp (attr[2], "uint64") == 0) {
            dbus_uint64_t value;

            /* match integer property */
            value = strtoull (attr[3], NULL, 0);
            
            /** @todo Check error condition */

            /*HAL_INFO (("Checking that key='%s' is a int that equals %d", 
              key, value));*/

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_UINT64)
                  return FALSE;

            if (hal_device_property_get_uint64 (d, prop_to_check) != value) {
                  return FALSE;
            }

            return TRUE;
      } else if (strcmp (attr[2], "bool") == 0) {
            dbus_bool_t value;

            /* match string property */

            if (strcmp (attr[3], "false") == 0)
                  value = FALSE;
            else if (strcmp (attr[3], "true") == 0)
                  value = TRUE;
            else
                  return FALSE;

            /*HAL_INFO (("Checking that key='%s' is a bool that equals %s", 
              key, value ? "TRUE" : "FALSE"));*/

            if (hal_device_property_get_type (d, prop_to_check) != 
                DBUS_TYPE_BOOLEAN)
                  return FALSE;

            if (hal_device_property_get_bool (d, prop_to_check) != value)
                  return FALSE;

            /*HAL_INFO (("*** bool match for key %s", key));*/
            return TRUE;
      } else if (strcmp (attr[2], "exists") == 0) {
            dbus_bool_t should_exist = TRUE;

            if (strcmp (attr[3], "false") == 0)
                  should_exist = FALSE;

            if (should_exist) {
                  if (hal_device_has_property (d, prop_to_check))
                        return TRUE;
                  else
                        return FALSE;
            } else {
                  if (hal_device_has_property (d, prop_to_check))
                        return FALSE;
                  else
                        return TRUE;
            }
      } else if (strcmp (attr[2], "empty") == 0) {
            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) != DBUS_TYPE_STRING)
                  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;

            if (should_be_empty) {
                  if (is_empty)
                        return TRUE;
                  else
                        return FALSE;
            } else {
                  if (is_empty)
                        return FALSE;
                  else
                        return TRUE;
            }
      } else if (strcmp (attr[2], "is_ascii") == 0) {
            dbus_bool_t is_ascii = TRUE;
            dbus_bool_t should_be_ascii = TRUE;
            unsigned int i;
            const char *str;

            if (strcmp (attr[3], "false") == 0)
                  should_be_ascii = FALSE;

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_STRING)
                  return FALSE;

            is_ascii = TRUE;

            str = hal_device_property_get_string (d, prop_to_check);
            for (i = 0; str[i] != '\0'; i++) {
                  if (((unsigned char) str[i]) > 0x7f)
                        is_ascii = FALSE;
            }

            if (should_be_ascii) {
                  if (is_ascii)
                        return TRUE;
                  else
                        return FALSE;
            } else {
                  if (is_ascii)
                        return FALSE;
                  else
                        return TRUE;
            }
      } else if (strcmp (attr[2], "is_absolute_path") == 0) {
            const char *path = NULL;
            dbus_bool_t is_absolute_path = FALSE;
            dbus_bool_t should_be_absolute_path = TRUE;

            if (strcmp (attr[3], "false") == 0)
                  should_be_absolute_path = FALSE;

            /*HAL_INFO (("d->udi='%s', prop_to_check='%s'", d->udi, prop_to_check));*/

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_STRING)
                  return FALSE;

            if (hal_device_has_property (d, prop_to_check)) {
                  path = hal_device_property_get_string (d, prop_to_check);
                  if (g_path_is_absolute (path))
                        is_absolute_path = TRUE;
            }

            /*HAL_INFO (("is_absolute=%d, should_be=%d, path='%s'", is_absolute_path, should_be_absolute_path, path));*/


            if (should_be_absolute_path) {
                  if (is_absolute_path)
                        return TRUE;
                  else
                        return FALSE;
            } else {
                  if (is_absolute_path)
                        return FALSE;
                  else
                        return TRUE;
            }
      } else if (strcmp (attr[2], "contains") == 0) {
            const char *needle;
            dbus_bool_t contains = FALSE;

            needle = attr[3];

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_STRING)
                  return FALSE;

            if (hal_device_has_property (d, prop_to_check)) {
                  const char *haystack;

                  haystack = hal_device_property_get_string (d, prop_to_check);
                  if (needle != NULL && haystack != NULL && strstr (haystack, needle)) {
                        contains = TRUE;
                  }

            }
            return contains;
      } else if (strcmp (attr[2], "contains_ncase") == 0) {
            const char *needle;
            dbus_bool_t contains_ncase = FALSE;

            needle = attr[3];

            if (hal_device_property_get_type (d, prop_to_check) != DBUS_TYPE_STRING)
                  return FALSE;

            if (hal_device_has_property (d, prop_to_check)) {
                  char *needle_lowercase;
                  char *haystack_lowercase;

                  needle_lowercase   = g_utf8_strdown (needle, -1);
                  haystack_lowercase = g_utf8_strdown (hal_device_property_get_string (d, prop_to_check), -1);
                  if (needle_lowercase != NULL && haystack_lowercase != NULL && strstr (haystack_lowercase, needle_lowercase)) {
                        contains_ncase = TRUE;
                  }

                  g_free (needle_lowercase);
                  g_free (haystack_lowercase);
            }
            return contains_ncase;
      } else if (strcmp (attr[2], "compare_lt") == 0) {
            dbus_int64_t result;
            if (!match_compare_property (d, prop_to_check, attr[3], &result)) {
                  return FALSE;
            } else {
                  return result < 0;
            }
      } else if (strcmp (attr[2], "compare_le") == 0) {
            dbus_int64_t result;
            if (!match_compare_property (d, prop_to_check, attr[3], &result))
                  return FALSE;
            else
                  return result <= 0;
      } else if (strcmp (attr[2], "compare_gt") == 0) {
            dbus_int64_t result;
            if (!match_compare_property (d, prop_to_check, attr[3], &result))
                  return FALSE;
            else
                  return result > 0;
      } else if (strcmp (attr[2], "compare_ge") == 0) {
            dbus_int64_t result;
            if (!match_compare_property (d, prop_to_check, attr[3], &result))
                  return FALSE;
            else
                  return result >= 0;
      }
      
      return FALSE;
}


Generated by  Doxygen 1.6.0   Back to index