X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.h;h=54e7d481b0496e719f2f567b664a2619c82a3b16;hp=08dac49d2e74c2906e68897ca5b856ff5404df99;hb=619f3a160de4f417226b69039538882787b3811c;hpb=7b79b6226e737e28aafb4e9b668b86b5f180314b diff --git a/libubus.h b/libubus.h index 08dac49..54e7d48 100644 --- a/libubus.h +++ b/libubus.h @@ -66,32 +66,44 @@ typedef void (*ubus_connect_handler_t)(struct ubus_context *ctx); .methods = _methods \ } -#define __UBUS_METHOD_NOARG(_name, _handler) \ +#define __UBUS_METHOD_NOARG(_name, _handler, _tags) \ .name = _name, \ - .handler = _handler + .handler = _handler, \ + .tags = _tags -#define __UBUS_METHOD(_name, _handler, _policy) \ - __UBUS_METHOD_NOARG(_name, _handler), \ +#define __UBUS_METHOD(_name, _handler, _policy, _tags) \ + __UBUS_METHOD_NOARG(_name, _handler, _tags), \ .policy = _policy, \ .n_policy = ARRAY_SIZE(_policy) #define UBUS_METHOD(_name, _handler, _policy) \ - { __UBUS_METHOD(_name, _handler, _policy) } + { __UBUS_METHOD(_name, _handler, _policy, 0) } + +#define UBUS_METHOD_TAG(_name, _handler, _policy, _tags)\ + { __UBUS_METHOD(_name, _handler, _policy, _tags) } #define UBUS_METHOD_MASK(_name, _handler, _policy, _mask) \ { \ - __UBUS_METHOD(_name, _handler, _policy),\ + __UBUS_METHOD(_name, _handler, _policy, 0),\ .mask = _mask \ } #define UBUS_METHOD_NOARG(_name, _handler) \ - { __UBUS_METHOD_NOARG(_name, _handler) } + { __UBUS_METHOD_NOARG(_name, _handler, 0) } + +#define UBUS_METHOD_TAG_NOARG(_name, _handler, _tags) \ + { __UBUS_METHOD_NOARG(_name, _handler, _tags) } + +#define UBUS_TAG_STATUS BIT(0) +#define UBUS_TAG_ADMIN BIT(1) +#define UBUS_TAG_PRIVATE BIT(2) struct ubus_method { const char *name; ubus_handler_t handler; unsigned long mask; + unsigned long tags; const struct blobmsg_policy *policy; int n_policy; }; @@ -146,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; @@ -159,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; @@ -270,6 +291,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 */