X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=ubusd_proto.c;h=bdb022c5091b620462a4f2774b6afbd717402d94;hp=1bf6249507f9990d97ea7e79f7cc83a79945c81f;hb=d2f9e766ffc818610262d44e0cb02b1f73d71a1f;hpb=cb1feedb5e1388d7aea8bddef1284690c590874f diff --git a/ubusd_proto.c b/ubusd_proto.c index 1bf6249..bdb022c 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -69,6 +69,37 @@ static int ubusd_send_pong(struct ubus_client *cl, struct ubus_msg_buf *ub, stru return 0; } +static int ubusd_handle_remove_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr) +{ + struct ubus_object *obj; + + if (!attr[UBUS_ATTR_OBJID]) + return UBUS_STATUS_INVALID_ARGUMENT; + + obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID])); + if (!obj) + return UBUS_STATUS_NOT_FOUND; + + if (obj->client != cl) + return UBUS_STATUS_PERMISSION_DENIED; + + blob_buf_init(&b, 0); + blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id); + + /* check if we're removing the object type as well */ + if (obj->type && obj->type->refcount == 1) + blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id); + + ubusd_free_object(obj); + + ub = ubus_reply_from_blob(ub, true); + if (!ub) + return UBUS_STATUS_NO_DATA; + + ubus_msg_send(cl, ub, true); + return 0; +} + static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr) { struct ubus_object *obj; @@ -232,6 +263,7 @@ error: static const ubus_cmd_cb handlers[__UBUS_MSG_LAST] = { [UBUS_MSG_PING] = ubusd_send_pong, [UBUS_MSG_ADD_OBJECT] = ubusd_handle_add_object, + [UBUS_MSG_REMOVE_OBJECT] = ubusd_handle_remove_object, [UBUS_MSG_LOOKUP] = ubusd_handle_lookup, [UBUS_MSG_INVOKE] = ubusd_handle_invoke, [UBUS_MSG_STATUS] = ubusd_handle_response,