summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Szyndela <adrian.s@samsung.com>2019-01-16 12:30:22 +0100
committerAdrian Szyndela <adrian.s@samsung.com>2019-04-26 13:29:42 +0200
commit3486e0f48dfadf1b175e3796f0a65c0da231889b (patch)
treed0c41ed30f82de6ea2814e4ab08cb4125f26ad46
parent96991501954b0924bcd8712d3269c1f5188968bb (diff)
downloaddbus-3486e0f48dfadf1b175e3796f0a65c0da231889b.tar.gz
DBusString: extend with checking for starting with words
This extracts a few lines of code and adds it as a DBusString function that checks if a DBusString starts with words given with a C string and a word separator. In other words, it checks if: - a DBusString is a given C string, or - a DBusString starts with a given C string and the next character is a given word separator. It is used for matching names to prefixes when checking the policy. Signed-off-by: Adrian Szyndela <adrian.s@samsung.com> Change-Id: Ie39d33916863d950dde38d3b8b20c8a539217302
-rw-r--r--bus/policy.c12
-rw-r--r--dbus/dbus-string.c26
-rw-r--r--dbus/dbus-string.h4
3 files changed, 33 insertions, 9 deletions
diff --git a/bus/policy.c b/bus/policy.c
index c87bfecf..11d21bf0 100644
--- a/bus/policy.c
+++ b/bus/policy.c
@@ -1341,15 +1341,9 @@ bus_rules_check_can_own (DBusList *rules,
}
else if (rule->d.own.prefix)
{
- const char *data;
- char next_char;
- if (!_dbus_string_starts_with_c_str (service_name,
- rule->d.own.service_name))
- continue;
-
- data = _dbus_string_get_const_data (service_name);
- next_char = data[strlen (rule->d.own.service_name)];
- if (next_char != '\0' && next_char != '.')
+ if (!_dbus_string_starts_with_words_c_str (service_name,
+ rule->d.own.service_name,
+ '.'))
continue;
}
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 52c71c5b..d620067e 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -2238,6 +2238,32 @@ _dbus_string_starts_with_c_str (const DBusString *a,
}
/**
+ * Checks whether a string starts with the given C string, after which it ends or is separated from
+ * the rest by a given separator character.
+ *
+ * @param a the string
+ * @param c_str the C string
+ * @param word_separator the separator
+ * @returns #TRUE if string starts with it
+ */
+dbus_bool_t
+_dbus_string_starts_with_words_c_str (const DBusString *a,
+ const char *c_str,
+ char word_separator)
+{
+ char next_char;
+ const char *data;
+ _dbus_assert (c_str != NULL);
+
+ if (!_dbus_string_starts_with_c_str (a, c_str))
+ return FALSE;
+
+ data = _dbus_string_get_const_data (a);
+ next_char = data[strlen (c_str)];
+ return next_char == '\0' || next_char == word_separator;
+}
+
+/**
* Appends a two-character hex digit to a string, where the hex digit
* has the value of the given byte.
*
diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h
index 41e82ab9..7ac32d38 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -338,6 +338,10 @@ dbus_bool_t _dbus_string_starts_with_c_str (const DBusString *a,
dbus_bool_t _dbus_string_ends_with_c_str (const DBusString *a,
const char *c_str);
DBUS_PRIVATE_EXPORT
+dbus_bool_t _dbus_string_starts_with_words_c_str (const DBusString *a,
+ const char *c_str,
+ char word_separator);
+DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_pop_line (DBusString *source,
DBusString *dest);
DBUS_PRIVATE_EXPORT