X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=ubusd_proto.c;h=bdb022c5091b620462a4f2774b6afbd717402d94;hp=2e84556495dd84cc35521df622a453b5de21c7d9;hb=d2f9e766ffc818610262d44e0cb02b1f73d71a1f;hpb=f6a6b0d492900b7a087a8a89d11fa5b94f4c5cb5 diff --git a/ubusd_proto.c b/ubusd_proto.c index 2e84556..bdb022c 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -58,18 +58,49 @@ bool ubusd_send_hello(struct ubus_client *cl) return false; ubus_msg_init(ub, UBUS_MSG_HELLO, 0, cl->id.id); - ubus_msg_send(cl, ub); + ubus_msg_send(cl, ub, true); return true; } static int ubusd_send_pong(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr) { ub->hdr.type = UBUS_MSG_DATA; - ubus_msg_send(cl, ubus_msg_ref(ub)); + ubus_msg_send(cl, ub, false); return 0; } -static int ubusd_handle_publish(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr) +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; @@ -86,7 +117,7 @@ static int ubusd_handle_publish(struct ubus_client *cl, struct ubus_msg_buf *ub, if (!ub) return UBUS_STATUS_NO_DATA; - ubus_msg_send(cl, ub); + ubus_msg_send(cl, ub, true); return 0; } @@ -111,7 +142,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru if (!ub) return; - ubus_msg_send(cl, ub); + ubus_msg_send(cl, ub, true); } static int ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr) @@ -169,7 +200,7 @@ static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub, if (!attr[UBUS_ATTR_METHOD] || !attr[UBUS_ATTR_OBJID]) return UBUS_STATUS_INVALID_ARGUMENT; - id = ubus_find_id(&objects, blob_get_int32(attr[UBUS_ATTR_OBJID])); + id = ubus_find_id(&objects, blob_get_u32(attr[UBUS_ATTR_OBJID])); if (!id) return UBUS_STATUS_NOT_FOUND; @@ -195,7 +226,7 @@ static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub, ub->hdr.type = UBUS_MSG_INVOKE; ub->hdr.peer = cl->id.id; - ubus_msg_send(obj->client, ub); + ubus_msg_send(obj->client, ub, true); return -1; } @@ -209,7 +240,7 @@ static int ubusd_handle_response(struct ubus_client *cl, struct ubus_msg_buf *ub (ub->hdr.type == UBUS_MSG_DATA && !attr[UBUS_ATTR_DATA])) goto error; - obj = ubusd_find_object(blob_get_int32(attr[UBUS_ATTR_OBJID])); + obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID])); if (!obj) goto error; @@ -220,8 +251,8 @@ static int ubusd_handle_response(struct ubus_client *cl, struct ubus_msg_buf *ub if (!cl) goto error; - ub->hdr.peer = blob_get_int32(attr[UBUS_ATTR_OBJID]); - ubus_msg_send(cl, ub); + ub->hdr.peer = blob_get_u32(attr[UBUS_ATTR_OBJID]); + ubus_msg_send(cl, ub, true); return -1; error: @@ -231,7 +262,8 @@ error: static const ubus_cmd_cb handlers[__UBUS_MSG_LAST] = { [UBUS_MSG_PING] = ubusd_send_pong, - [UBUS_MSG_PUBLISH] = ubusd_handle_publish, + [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, @@ -260,7 +292,7 @@ void ubusd_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub) ubus_msg_free(ub); *retmsg_data = htonl(ret); - ubus_msg_send(cl, ubus_msg_ref(retmsg)); + ubus_msg_send(cl, retmsg, false); } static void __init ubusd_proto_init(void)