ubus: use network order in ubus message header fields
[project/ubus.git] / libubus.h
index c891829..07239d6 100644 (file)
--- a/libubus.h
+++ b/libubus.h
@@ -158,6 +158,7 @@ struct ubus_context {
        int stack_depth;
 
        void (*connection_lost)(struct ubus_context *ctx);
+       void (*monitor_cb)(struct ubus_context *ctx, uint32_t seq, struct blob_attr *data);
 
        struct ubus_msghdr_buf msgbuf;
        uint32_t msgbuf_data_len;
@@ -171,11 +172,19 @@ struct ubus_object_data {
        struct blob_attr *signature;
 };
 
+struct ubus_acl_key {
+       const char *user;
+       const char *group;
+       const char *object;
+};
+
 struct ubus_request_data {
        uint32_t object;
        uint32_t peer;
        uint16_t seq;
 
+       struct ubus_acl_key acl;
+
        /* internal use */
        bool deferred;
        int fd;
@@ -231,6 +240,12 @@ void ubus_free(struct ubus_context *ctx);
 /* call this only for struct ubus_context pointers initialised by ubus_connect_ctx() */
 void ubus_shutdown(struct ubus_context *ctx);
 
+static inline void ubus_auto_shutdown(struct ubus_auto_conn *conn)
+{
+       uloop_timeout_cancel(&conn->timer);
+       ubus_shutdown(&conn->ctx);
+}
+
 const char *ubus_strerror(int error);
 
 static inline void ubus_add_uloop(struct ubus_context *ctx)
@@ -282,6 +297,34 @@ ubus_unregister_subscriber(struct ubus_context *ctx, struct ubus_subscriber *obj
 int ubus_subscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id);
 int ubus_unsubscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id);
 
+int __ubus_monitor(struct ubus_context *ctx, const char *type);
+
+static inline int ubus_monitor_start(struct ubus_context *ctx)
+{
+       return __ubus_monitor(ctx, "add");
+}
+
+static inline int ubus_monitor_stop(struct ubus_context *ctx)
+{
+       return __ubus_monitor(ctx, "remove");
+}
+
+
+/* ----------- acl ----------- */
+
+struct acl_object {
+       struct ubus_acl_key key;
+       struct avl_node avl;
+       struct blob_attr *acl;
+};
+
+extern struct avl_tree acl_objects;
+int ubus_register_acl(struct ubus_context *ctx);
+
+#define acl_for_each(o, m) \
+       if ((m)->object && (m)->user && (m)->group) \
+               avl_for_element_range(avl_find_ge_element(&acl_objects, m, o, avl), avl_find_le_element(&acl_objects, m, o, avl), o, avl)
+
 /* ----------- rpc ----------- */
 
 /* invoke a method on a specific object */
@@ -301,6 +344,7 @@ static inline void ubus_defer_request(struct ubus_context *ctx,
                                      struct ubus_request_data *req,
                                      struct ubus_request_data *new_req)
 {
+    (void) ctx;
     memcpy(new_req, req, sizeof(*req));
     req->deferred = true;
 }
@@ -308,6 +352,7 @@ static inline void ubus_defer_request(struct ubus_context *ctx,
 static inline void ubus_request_set_fd(struct ubus_context *ctx,
                                       struct ubus_request_data *req, int fd)
 {
+    (void) ctx;
     req->fd = fd;
 }