+struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb)
+{
+ struct ubus_client *cl;
+
+ cl = calloc(1, sizeof(*cl));
+ if (!cl)
+ return NULL;
+
+ INIT_LIST_HEAD(&cl->objects);
+ cl->sock.fd = fd;
+ cl->sock.cb = cb;
+
+ if (!ubus_alloc_id(&clients, &cl->id, 0))
+ goto free;
+
+ if (!ubusd_send_hello(cl))
+ goto delete;
+
+ return cl;
+
+delete:
+ ubus_free_id(&clients, &cl->id);
+free:
+ free(cl);
+ return NULL;
+}
+
+void ubusd_proto_free_client(struct ubus_client *cl)
+{
+ struct ubus_object *obj;
+
+ while (!list_empty(&cl->objects)) {
+ obj = list_first_entry(&cl->objects, struct ubus_object, list);
+ ubusd_free_object(obj);
+ }
+
+ ubus_free_id(&clients, &cl->id);
+}
+