Ubus
OpenWrt system message/RPC bus.
ubusd.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2014 Felix Fietkau <nbd@openwrt.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2.1
6  * as published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  */
13 
14 #ifndef __UBUSD_H
15 #define __UBUSD_H
16 
17 #include <libubox/list.h>
18 #include <libubox/uloop.h>
19 #include <libubox/blobmsg.h>
20 #include "ubus_common.h"
21 #include "ubusd_id.h"
22 #include "ubusd_obj.h"
23 #include "ubusmsg.h"
24 #include "ubusd_acl.h"
25 
26 #define UBUS_OBJ_HASH_BITS 4
27 #define UBUS_CLIENT_MAX_TXQ_LEN UBUS_MAX_MSGLEN
28 
29 extern struct blob_buf b;
30 
31 struct ubus_msg_buf {
32  uint32_t refcount; /* ~0: uses external data buffer */
33  struct ubus_msghdr hdr;
34  struct blob_attr *data;
35  int fd;
36  int len;
37 };
38 
40  struct list_head list;
41  struct ubus_msg_buf *msg;
42 };
43 
45  struct list_head list;
46  struct ubus_msg_buf *msg;
47  struct ubus_object *obj;
48 };
49 
50 struct ubus_client {
51  struct ubus_id id;
52  struct uloop_fd sock;
53  struct blob_buf b;
54 
55  uid_t uid;
56  gid_t gid;
57  char *user;
58  char *group;
59 
60  struct list_head objects;
61 
62  struct list_head cmd_queue;
63  struct list_head tx_queue;
64  unsigned int txq_ofs;
65  unsigned int txq_len;
66 
71  struct {
72  struct ubus_msghdr hdr;
73  struct blob_attr data;
74  } hdrbuf;
75 };
76 
77 struct ubus_path {
78  struct list_head list;
79  const char name[];
80 };
81 
82 extern const char *ubusd_acl_dir;
83 
84 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
85 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub);
86 ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset);
87 void ubus_msg_free(struct ubus_msg_buf *ub);
88 void ubus_msg_list_free(struct ubus_msg_buf_list *ubl);
89 struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len);
90 
91 struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
92 void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
93 void ubusd_proto_free_client(struct ubus_client *cl);
94 void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub,
95  uint8_t type);
96 int ubusd_cmd_lookup(struct ubus_client *cl, struct ubus_client_cmd *cmd);
97 
98 typedef struct ubus_msg_buf *(*event_fill_cb)(void *priv, const char *id);
99 void ubusd_event_init(void);
100 void ubusd_event_cleanup_object(struct ubus_object *obj);
101 void ubusd_send_obj_event(struct ubus_object *obj, bool add);
102 int ubusd_send_event(struct ubus_client *cl, const char *id,
103  event_fill_cb fill_cb, void *cb_priv);
104 
105 void ubusd_acl_init(void);
106 
107 void ubusd_monitor_init(void);
108 void ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send);
109 void ubusd_monitor_disconnect(struct ubus_client *cl);
110 
111 #endif
int(* cb)(struct ubus_context *ctx, int argc, char **argv)
Definition: cli.c:581
struct ubus_object * obj
Definition: ubusd.h:47
struct ubus_msg_buf * msg
Definition: ubusd.h:46
struct list_head list
Definition: ubusd.h:45
unsigned int txq_len
Definition: ubusd.h:65
struct ubus_msg_buf * retmsg
Definition: ubusd.h:68
char * user
Definition: ubusd.h:57
struct blob_buf b
Definition: ubusd.h:53
struct ubus_id id
Definition: ubusd.h:51
struct ubus_msghdr hdr
Definition: ubusd.h:72
unsigned int txq_ofs
Definition: ubusd.h:64
int pending_msg_fd
Definition: ubusd.h:70
gid_t gid
Definition: ubusd.h:56
struct ubus_msg_buf * pending_msg
Definition: ubusd.h:67
struct list_head cmd_queue
Definition: ubusd.h:62
struct list_head tx_queue
Definition: ubusd.h:63
char * group
Definition: ubusd.h:58
struct ubus_client::@7 hdrbuf
uid_t uid
Definition: ubusd.h:55
int pending_msg_offset
Definition: ubusd.h:69
struct list_head objects
Definition: ubusd.h:60
struct blob_attr data
Definition: ubusd.h:73
struct uloop_fd sock
Definition: ubusd.h:52
struct ubus_msg_buf * msg
Definition: ubusd.h:41
struct list_head list
Definition: ubusd.h:40
struct blob_attr * data
Definition: ubusd.h:34
struct ubus_msghdr hdr
Definition: ubusd.h:33
uint32_t refcount
Definition: ubusd.h:32
int fd
Definition: ubusd.h:35
int len
Definition: ubusd.h:36
struct list_head list
Definition: ubusd.h:78
const char name[]
Definition: ubusd.h:79
void ubusd_event_init(void)
Definition: ubusd_event.c:266
void ubusd_monitor_init(void)
void ubus_msg_free(struct ubus_msg_buf *ub)
Definition: ubusd.c:67
const char * ubusd_acl_dir
Definition: ubusd_acl.c:71
struct ubus_client * ubusd_proto_new_client(int fd, uloop_fd_handler cb)
Definition: ubusd_proto.c:564
void ubusd_send_obj_event(struct ubus_object *obj, bool add)
Definition: ubusd_event.c:259
struct ubus_msg_buf * ubus_msg_new(void *data, int len, bool shared)
Definition: ubusd.c:39
int ubusd_cmd_lookup(struct ubus_client *cl, struct ubus_client_cmd *cmd)
Definition: ubusd_proto.c:285
void ubusd_acl_init(void)
Definition: ubusd_acl.c:568
int ubusd_send_event(struct ubus_client *cl, const char *id, event_fill_cb fill_cb, void *cb_priv)
Definition: ubusd_event.c:140
void ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send)
Definition: ubusd_monitor.c:77
void ubus_msg_list_free(struct ubus_msg_buf_list *ubl)
Definition: ubusd.c:136
void ubusd_event_cleanup_object(struct ubus_object *obj)
Definition: ubusd_event.c:36
struct blob_buf b
Definition: ubusd_proto.c:19
struct ubus_msg_buf *(* event_fill_cb)(void *priv, const char *id)
Definition: ubusd.h:98
void ubusd_proto_free_client(struct ubus_client *cl)
Definition: ubusd_proto.c:600
void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
Definition: ubusd.c:162
struct blob_attr ** ubus_parse_msg(struct blob_attr *msg, size_t len)
Definition: libubus-io.c:46
void ubusd_monitor_disconnect(struct ubus_client *cl)
Definition: ubusd_monitor.c:65
void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub, uint8_t type)
Definition: ubusd_proto.c:78
void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub)
Definition: ubusd_proto.c:512
ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset)
Definition: ubusd.c:83
uint8_t type
Definition: ubusmsg.h:1