+enum {
+ EVMSG_ID,
+ EVMSG_DATA,
+ EVMSG_LAST,
+};
+
+static struct blobmsg_policy ev_policy[] = {
+ [EVMSG_ID] = { .name = "id", .type = BLOBMSG_TYPE_STRING },
+ [EVMSG_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
+};
+
+static struct ubus_msg_buf *
+ubusd_create_event_from_msg(void *priv, const char *id)
+{
+ struct blob_attr *msg = priv;
+
+ blob_buf_init(&b, 0);
+ blob_put_int32(&b, UBUS_ATTR_OBJID, 0);
+ blob_put_string(&b, UBUS_ATTR_METHOD, id);
+ blob_put(&b, UBUS_ATTR_DATA, blobmsg_data(msg), blobmsg_data_len(msg));
+
+ return ubus_msg_new(b.head, blob_raw_len(b.head), true);
+}
+
+static int ubusd_forward_event(struct ubus_client *cl, struct blob_attr *msg)
+{
+ struct blob_attr *data;
+ struct blob_attr *attr[EVMSG_LAST];
+ const char *id;
+
+ blobmsg_parse(ev_policy, EVMSG_LAST, attr, blob_data(msg), blob_len(msg));
+ if (!attr[EVMSG_ID] || !attr[EVMSG_DATA])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ id = blobmsg_data(attr[EVMSG_ID]);
+ data = attr[EVMSG_DATA];
+
+ if (!strncmp(id, "ubus.", 5))
+ return UBUS_STATUS_PERMISSION_DENIED;
+
+ return ubusd_send_event(cl, id, ubusd_create_event_from_msg, data);
+}
+