mirror of
https://salsa.debian.org/ha-team/libqb
synced 2026-08-12 13:04:57 +00:00
map: enforce uniqueness of the notifiers based on (func,key,event,userdata)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
parent
2d92af61c5
commit
e01b79883a
@ -269,7 +269,9 @@ hashtable_notify_add(qb_map_t * m, const char *key,
|
||||
for (list = head->next; list != head; list = list->next) {
|
||||
f = qb_list_entry(list, struct qb_map_notifier, list);
|
||||
|
||||
if (f->events == events && f->callback == fn) {
|
||||
if (f->events == events &&
|
||||
f->user_data == user_data &&
|
||||
f->callback == fn) {
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,6 +241,7 @@ skiplist_notify_add(qb_map_t * m, const char *key,
|
||||
struct skiplist *t = (struct skiplist *)m;
|
||||
struct qb_map_notifier *f;
|
||||
struct skiplist_node *n;
|
||||
struct qb_list_head *list;
|
||||
|
||||
if (key) {
|
||||
n = skiplist_lookup(t, key);
|
||||
@ -248,6 +249,17 @@ skiplist_notify_add(qb_map_t * m, const char *key,
|
||||
n = t->header;
|
||||
}
|
||||
if (n) {
|
||||
for (list = n->notifier_head.next;
|
||||
list != &n->notifier_head; list = list->next) {
|
||||
f = qb_list_entry(list, struct qb_map_notifier, list);
|
||||
|
||||
if (f->events == events &&
|
||||
f->callback == fn &&
|
||||
f->user_data == user_data) {
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
f = malloc(sizeof(struct qb_map_notifier));
|
||||
if (f == NULL) {
|
||||
return -errno;
|
||||
|
||||
12
lib/trie.c
12
lib/trie.c
@ -309,6 +309,7 @@ trie_notify_add(qb_map_t * m, const char *key,
|
||||
struct trie *t = (struct trie *)m;
|
||||
struct qb_map_notifier *f;
|
||||
struct trie_node *n;
|
||||
struct qb_list_head *list;
|
||||
|
||||
if (key) {
|
||||
n = trie_lookup(t, key, QB_TRUE);
|
||||
@ -316,6 +317,17 @@ trie_notify_add(qb_map_t * m, const char *key,
|
||||
n = t->header;
|
||||
}
|
||||
if (n) {
|
||||
for (list = n->notifier_head.next;
|
||||
list != &n->notifier_head; list = list->next) {
|
||||
f = qb_list_entry(list, struct qb_map_notifier, list);
|
||||
|
||||
if (f->events == events &&
|
||||
f->callback == fn &&
|
||||
f->user_data == user_data) {
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
f = malloc(sizeof(struct qb_map_notifier));
|
||||
if (f == NULL) {
|
||||
return -errno;
|
||||
|
||||
@ -313,6 +313,15 @@ test_map_notifications_basic(qb_map_t *m)
|
||||
QB_MAP_NOTIFY_REPLACED|
|
||||
QB_MAP_NOTIFY_RECURSIVE));
|
||||
ck_assert_int_eq(i, -ENOENT);
|
||||
|
||||
/* test uniquess */
|
||||
qb_map_put(m, "fred", "null");
|
||||
i = qb_map_notify_add(m, "fred", my_map_notification,
|
||||
QB_MAP_NOTIFY_REPLACED, m);
|
||||
ck_assert_int_eq(i, 0);
|
||||
i = qb_map_notify_add(m, "fred", my_map_notification,
|
||||
QB_MAP_NOTIFY_REPLACED, m);
|
||||
ck_assert_int_eq(i, -EEXIST);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Loading…
Reference in New Issue
Block a user