match: check for currently owned names
authorKay Sievers <kay@vrfy.org>
Mon, 23 Dec 2013 23:13:41 +0000 (00:13 +0100)
committerKay Sievers <kay@vrfy.org>
Mon, 23 Dec 2013 23:13:41 +0000 (00:13 +0100)
connection.c
connection.h
match.c
metadata.c
metadata.h

index b51e9232c856a2e708d719fa2dad8b1ad0ba3110..0a9410b82ee6d87c031ea30179f82514289056b5 100644 (file)
@@ -1543,3 +1543,28 @@ exit_unref:
        kdbus_conn_unref(conn);
        return ret;
 }
+
+
+/**
+ * kdbus_conn_has_name() - check if a connection owns a name
+ * @conn:              Connection
+ * @name:              Well-know name to check for
+ *
+ * Returns true if the name is currently owned by the connection.
+ */
+bool kdbus_conn_has_name(struct kdbus_conn *conn, const char *name)
+{
+       struct kdbus_name_entry *e;
+       bool match = false;
+
+       mutex_lock(&conn->lock);
+       list_for_each_entry(e, &conn->names_list, conn_entry) {
+               if (strcmp(e->name, name) == 0) {
+                       match = true;
+                       break;
+               }
+       }
+       mutex_unlock(&conn->lock);
+
+       return match;
+}
index 6543fd50e08531364c58db6c59033e16eb68bc2d..37b4220e2bec230f5640fec012f507eeb8ab54d8 100644 (file)
@@ -92,4 +92,5 @@ int kdbus_conn_kmsg_list_send(struct kdbus_ep *ep,
                              struct list_head *kmsg_list);
 int kdbus_conn_move_messages(struct kdbus_conn *conn_dst,
                             struct kdbus_conn *conn_src);
+bool kdbus_conn_has_name(struct kdbus_conn *conn, const char *name);
 #endif
diff --git a/match.c b/match.c
index 160b09299ca33385aab00ea106eebc0364dda5a1..482acbba2049d75356c5f58dfe4a3237540a48cf 100644 (file)
--- a/match.c
+++ b/match.c
@@ -147,22 +147,7 @@ int kdbus_match_db_new(struct kdbus_match_db **db)
        return 0;
 }
 
-static inline
-bool kdbus_match_name(const char *haystack,
-                     size_t haystack_size,
-                     const char *needle)
-{
-       size_t i;
-
-       for (i = 0; i < haystack_size; i += strlen(haystack) + 1)
-               if (strcmp(haystack + i, needle) == 0)
-                       return true;
-
-       return false;
-}
-
-static inline
-bool kdbus_match_bloom(const u64 *filter, const u64 *mask,
+static bool kdbus_match_bloom(const u64 *filter, const u64 *mask,
                       const struct kdbus_conn *conn)
 {
        unsigned int i;
@@ -242,9 +227,7 @@ static bool kdbus_match_rules(const struct kdbus_match_entry *entry,
                                break;
 
                        case KDBUS_ITEM_NAME:
-                               if (!kdbus_match_name(kmsg->meta.src_names,
-                                                     kmsg->meta.src_names_len,
-                                                     r->name))
+                               if (!kdbus_conn_has_name(conn_src, r->name))
                                        return false;
 
                                break;
index 69d47904649dc2ee64858af40860efd90dc7cdbd..dd54a858a4c48f9a6f057d2337c5ffee6a4e9b6b 100644 (file)
@@ -163,7 +163,6 @@ static int kdbus_meta_append_src_names(struct kdbus_meta *meta,
                return 0;
 
        mutex_lock(&conn->lock);
-
        list_for_each_entry(e, &conn->names_list, conn_entry) {
                struct kdbus_item *item;
                size_t len;
@@ -183,7 +182,6 @@ static int kdbus_meta_append_src_names(struct kdbus_meta *meta,
                item->name.flags = e->flags;
                memcpy(item->name.name, e->name, len);
        }
-
        mutex_unlock(&conn->lock);
 
        return ret;
index beed7fadaebd09286a458213ede7d23d25d5b59b..5c111b5d42fc8db4b16ca6664a325a7bec1c8e9e 100644 (file)
@@ -20,8 +20,6 @@
  * @data:              Allocated buffer
  * @size:              Number of bytes used
  * @allocated_size:    Size of buffer
- * @src_names:         List of \0-separated well-known names
- * @src_names_len:     Length of list
  *
  * Used to collect and store connection metadata in a pre-compiled
  * buffer containing struct kdbus_item.
@@ -32,9 +30,6 @@ struct kdbus_meta {
        struct kdbus_item *data;
        size_t size;
        size_t allocated_size;
-
-       const char *src_names;
-       size_t src_names_len;
 };
 
 struct kdbus_conn;