libubus: Check if remove callback exists before call it
[project/ubus.git] / libubus-obj.c
index c35e075..bdb2e03 100644 (file)
@@ -27,7 +27,8 @@ ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr,
                return;
 
        s = container_of(obj, struct ubus_subscriber, obj);
-       s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET]));
+       if (s->remove_cb)
+               s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET]));
 }
 
 static void
@@ -48,6 +49,7 @@ ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
        struct ubus_request_data req = {};
        int method;
        int ret;
+       bool no_reply = false;
 
        if (!obj) {
                ret = UBUS_STATUS_NOT_FOUND;
@@ -59,6 +61,9 @@ ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
                goto send;
        }
 
+       if (attrbuf[UBUS_ATTR_NO_REPLY])
+               no_reply = blob_get_int8(attrbuf[UBUS_ATTR_NO_REPLY]);
+
        req.peer = hdr->peer;
        req.seq = hdr->seq;
        req.object = obj->id;
@@ -77,7 +82,7 @@ found:
        ret = obj->methods[method].handler(ctx, obj, &req,
                                           blob_data(attrbuf[UBUS_ATTR_METHOD]),
                                           attrbuf[UBUS_ATTR_DATA]);
-       if (req.deferred)
+       if (req.deferred || no_reply)
                return;
 
 send: