CMakeLists.txt: bump minimum cmake version
[project/ubus.git] / ubusd.h
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 UBUSD_CLIENT_BACKLOG 32
27 #define UBUS_OBJ_HASH_BITS 4
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
39 struct ubus_client {
40 struct ubus_id id;
41 struct uloop_fd sock;
42
43 uid_t uid;
44 gid_t gid;
45 char *user;
46 char *group;
47
48 struct list_head objects;
49
50 struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
51 unsigned int txq_cur, txq_tail, txq_ofs;
52
53 struct ubus_msg_buf *pending_msg;
54 int pending_msg_offset;
55 int pending_msg_fd;
56 struct {
57 struct ubus_msghdr hdr;
58 struct blob_attr data;
59 } hdrbuf;
60 };
61
62 struct ubus_path {
63 struct list_head list;
64 const char name[];
65 };
66
67 extern const char *ubusd_acl_dir;
68
69 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
70 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free);
71 void ubus_msg_free(struct ubus_msg_buf *ub);
72 struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
73
74 struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
75 void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
76 void ubusd_proto_free_client(struct ubus_client *cl);
77 void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub,
78 uint8_t type);
79
80 typedef struct ubus_msg_buf *(*event_fill_cb)(void *priv, const char *id);
81 void ubusd_event_init(void);
82 void ubusd_event_cleanup_object(struct ubus_object *obj);
83 void ubusd_send_obj_event(struct ubus_object *obj, bool add);
84 int ubusd_send_event(struct ubus_client *cl, const char *id,
85 event_fill_cb fill_cb, void *cb_priv);
86
87 void ubusd_acl_init(void);
88
89 void ubusd_monitor_init(void);
90 void ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send);
91 void ubusd_monitor_disconnect(struct ubus_client *cl);
92
93 #endif