+static int ubusd_handle_add_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
+{
+ struct ubus_object *obj, *target;
+
+ if (!attr[UBUS_ATTR_OBJID] || !attr[UBUS_ATTR_TARGET])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID]));
+ if (!obj)
+ return UBUS_STATUS_NOT_FOUND;
+
+ if (cl != obj->client)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ target = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_TARGET]));
+ if (!target)
+ return UBUS_STATUS_NOT_FOUND;
+
+ if (cl == target->client)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ if (!target->path.key) {
+ if (strcmp(target->client->user, cl->user) && strcmp(target->client->group, cl->group))
+ return UBUS_STATUS_NOT_FOUND;
+ } else if (ubusd_acl_check(cl, target->path.key, NULL, UBUS_ACL_SUBSCRIBE)) {
+ return UBUS_STATUS_NOT_FOUND;
+ }
+
+ ubus_subscribe(obj, target);
+ return 0;
+}
+
+static int ubusd_handle_remove_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
+{
+ struct ubus_object *obj;
+ struct ubus_subscription *s;
+ uint32_t id;
+
+ if (!attr[UBUS_ATTR_OBJID] || !attr[UBUS_ATTR_TARGET])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID]));
+ if (!obj)
+ return UBUS_STATUS_NOT_FOUND;
+
+ if (cl != obj->client)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ id = blob_get_u32(attr[UBUS_ATTR_TARGET]);
+ list_for_each_entry(s, &obj->target_list, target_list) {
+ if (s->target->id.id != id)
+ continue;
+
+ ubus_unsubscribe(s);
+ return 0;
+ }
+
+ return UBUS_STATUS_NOT_FOUND;
+}
+