14 #include <arpa/inet.h>
130 blob_buf_init(&
b, 0);
151 blob_buf_init(&
b, 0);
163 int all_cnt = 0, cnt = 0;
169 blob_buf_init(&
b, 0);
179 blobmsg_add_blob(&
b, m->
data);
183 blob_nest_end(&
b, s);
206 struct blob_attr **attr,
220 obj = avl_first_element(&
path, obj,
path);
222 avl_for_element_range(obj, avl_last_element(&
path, obj,
path), obj,
path) {
243 len = strlen(objpath);
244 if (objpath[len - 1] !=
'*') {
245 obj = avl_find_element(&
path, objpath, obj,
path);
255 obj = avl_find_ge_element(&
path, objpath, obj,
path);
259 while (!strncmp(objpath, obj->
path.key, len)) {
262 if (obj == avl_last_element(&
path, obj,
path))
264 obj = avl_next_element(obj,
path);
288 struct blob_attr **attr;
296 int *retmsg_data = blob_data(blob_data(retmsg->
data));
301 *retmsg_data = htonl(ret);
310 struct blob_attr *
data)
348 blob_buf_init(&
b, 0);
361 bool no_reply =
false;
379 blob_buf_init(&
b, 0);
382 list_for_each_entry(s, &obj->subscribers, list) {
385 blob_nest_end(&
b, c);
392 list_for_each_entry(s, &obj->subscribers, list) {
393 blob_buf_init(&
b, 0);
454 if (!target || !target->
client)
460 if (!target->
path.key) {
517 int *retmsg_data = blob_data(blob_data(retmsg->
data));
544 *retmsg_data = htonl(ret);
550 struct blob_buf *
b = &cl->
b;
552 blob_buf_init(&cl->
b, 0);
568 cl = calloc(1,
sizeof(*cl));
604 list_for_each_entry_safe(obj, tmp, &cl->
objects,
list) {
609 blob_buf_free(&cl->
b);
617 bool active = !list_empty(&obj->subscribers);
620 blob_buf_init(&
b, 0);
637 blob_buf_init(&
b, 0);
int(* cb)(struct ubus_context *ctx, int argc, char **argv)
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)
struct ubus_msg_buf * msg
struct ubus_msg_buf * retmsg
struct list_head cmd_queue
struct list_head tx_queue
const struct ubus_method * methods
struct ubus_object_type * type
struct list_head subscribers target_list
struct ubus_client * client
int(* recv_msg)(struct ubus_client *client, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
struct ubus_object * target
struct list_head list target_list
struct ubus_object * subscriber
void ubus_msg_free(struct ubus_msg_buf *ub)
struct ubus_msg_buf * ubus_msg_new(void *data, int len, bool shared)
void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
int ubusd_acl_init_client(struct ubus_client *cl, int fd)
int ubusd_acl_check(struct ubus_client *cl, const char *obj, const char *method, enum ubusd_acl_type type)
void ubusd_acl_free_client(struct ubus_client *cl)
void ubus_init_id_tree(struct avl_tree *tree)
bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id, uint32_t val)
static void ubus_free_id(struct avl_tree *tree, struct ubus_id *id)
static struct ubus_id * ubus_find_id(struct avl_tree *tree, uint32_t id)
struct ubus_object * ubusd_create_object(struct ubus_client *cl, struct blob_attr **attr)
void ubusd_free_object(struct ubus_object *obj)
static struct ubus_object * ubusd_find_object(uint32_t objid)
static void __constructor ubusd_proto_init(void)
static struct ubus_msg_buf * ubus_msg_from_blob(bool shared)
static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX]
static void ubusd_forward_invoke(struct ubus_client *cl, struct ubus_object *obj, const char *method, struct ubus_msg_buf *ub, struct blob_attr *data)
struct ubus_client * ubusd_proto_new_client(int fd, uloop_fd_handler cb)
static struct blob_attr * attrbuf[UBUS_ATTR_MAX]
static int ubusd_handle_notify(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
static struct avl_tree clients
static int ubus_client_cmd_queue_add(struct ubus_client *cl, struct ubus_msg_buf *msg, struct ubus_object *obj)
static int ubusd_proto_init_retmsg(struct ubus_client *cl)
void ubus_notify_unsubscribe(struct ubus_subscription *s)
static int ubusd_send_pong(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
static const ubus_cmd_cb handlers[__UBUS_MSG_LAST]
int ubusd_cmd_lookup(struct ubus_client *cl, struct ubus_client_cmd *cmd)
static int ubusd_handle_add_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
static bool ubusd_send_hello(struct ubus_client *cl)
static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj)
static int ubusd_handle_response(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
static int ubusd_handle_remove_watch(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)
static void ubus_msg_close_fd(struct ubus_msg_buf *ub)
static int ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
void ubus_notify_subscription(struct ubus_object *obj)
void ubusd_proto_free_client(struct ubus_client *cl)
static struct ubus_msg_buf * ubus_reply_from_blob(struct ubus_msg_buf *ub, bool shared)
static void ubus_msg_init(struct ubus_msg_buf *ub, uint8_t type, uint16_t seq, uint32_t peer)
int(* ubus_cmd_cb)(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
struct blob_attr ** ubus_parse_msg(struct blob_attr *msg, size_t len)
void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub, uint8_t type)
void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub)
static int __ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr, struct ubus_client_cmd *cmd)
static struct ubus_client * ubusd_get_client_by_id(uint32_t id)
@ UBUS_STATUS_INVALID_ARGUMENT
@ UBUS_STATUS_INVALID_COMMAND
@ UBUS_STATUS_PERMISSION_DENIED
@ UBUS_STATUS_UNKNOWN_ERROR