diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-12-14 13:42:10 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-12-14 13:42:10 +0100 |
commit | 7cd33a8e3a64a2b181fe9722b599302b62c7147c (patch) | |
tree | 15c87e41e6909f46b472744b89002b0904b5495c /libubus-sub.c | |
parent | 0fccce4445b1961451ce3d99a99c1c0defbd4490 (diff) | |
download | ubus-7cd33a8e3a64a2b181fe9722b599302b62c7147c.tar.gz |
libubus: reduce code duplication and add stack depth protection for unsubscribe/notify callbacks
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'libubus-sub.c')
-rw-r--r-- | libubus-sub.c | 44 |
1 files changed, 1 insertions, 43 deletions
diff --git a/libubus-sub.c b/libubus-sub.c index ccb4d95..8ffb018 100644 --- a/libubus-sub.c +++ b/libubus-sub.c @@ -25,7 +25,7 @@ static int ubus_subscriber_cb(struct ubus_context *ctx, struct ubus_object *obj, return 0; } -static const struct ubus_method watch_method = { +const struct ubus_method watch_method __hidden = { .name = NULL, .handler = ubus_subscriber_cb, }; @@ -66,45 +66,3 @@ int ubus_unsubscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint return __ubus_subscribe_request(ctx, &obj->obj, id, UBUS_MSG_UNSUBSCRIBE); } -void __hidden ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr) -{ - struct ubus_subscriber *s; - struct blob_attr **attrbuf; - struct ubus_object *obj; - uint32_t objid; - - attrbuf = ubus_parse_msg(hdr->data); - if (!attrbuf[UBUS_ATTR_OBJID] || !attrbuf[UBUS_ATTR_TARGET]) - return; - - objid = blob_get_u32(attrbuf[UBUS_ATTR_OBJID]); - obj = avl_find_element(&ctx->objects, &objid, obj, avl); - if (!obj) - return; - - if (obj->methods != &watch_method) - return; - - s = container_of(obj, struct ubus_subscriber, obj); - s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET])); -} - -void __hidden ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr) -{ - struct blob_attr **attrbuf; - struct ubus_object *obj; - uint32_t objid; - - attrbuf = ubus_parse_msg(hdr->data); - if (!attrbuf[UBUS_ATTR_OBJID] || !attrbuf[UBUS_ATTR_ACTIVE]) - return; - - objid = blob_get_u32(attrbuf[UBUS_ATTR_OBJID]); - obj = avl_find_element(&ctx->objects, &objid, obj, avl); - if (!obj) - return; - - obj->has_subscribers = blob_get_u8(attrbuf[UBUS_ATTR_ACTIVE]); - if (obj->subscribe_cb) - obj->subscribe_cb(ctx, obj); -} |