A library used by many OpenWrt projects as a planned D-Bus replacement
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 lines
2.6 KiB

  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. #ifndef __UBUSD_H
  14. #define __UBUSD_H
  15. #include <libubox/list.h>
  16. #include <libubox/uloop.h>
  17. #include <libubox/blobmsg.h>
  18. #include "ubus_common.h"
  19. #include "ubusd_id.h"
  20. #include "ubusd_obj.h"
  21. #include "ubusmsg.h"
  22. #include "ubusd_acl.h"
  23. #define UBUSD_CLIENT_BACKLOG 32
  24. #define UBUS_OBJ_HASH_BITS 4
  25. extern struct blob_buf b;
  26. struct ubus_msg_buf {
  27. uint32_t refcount; /* ~0: uses external data buffer */
  28. struct ubus_msghdr hdr;
  29. struct blob_attr *data;
  30. int fd;
  31. int len;
  32. };
  33. struct ubus_client {
  34. struct ubus_id id;
  35. struct uloop_fd sock;
  36. struct blob_buf b;
  37. uid_t uid;
  38. gid_t gid;
  39. char *user;
  40. char *group;
  41. struct list_head objects;
  42. struct ubus_msg_buf *tx_queue[UBUSD_CLIENT_BACKLOG];
  43. unsigned int txq_cur, txq_tail, txq_ofs;
  44. struct ubus_msg_buf *pending_msg;
  45. struct ubus_msg_buf *retmsg;
  46. int pending_msg_offset;
  47. int pending_msg_fd;
  48. struct {
  49. struct ubus_msghdr hdr;
  50. struct blob_attr data;
  51. } hdrbuf;
  52. };
  53. struct ubus_path {
  54. struct list_head list;
  55. const char name[];
  56. };
  57. extern const char *ubusd_acl_dir;
  58. struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
  59. void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub);
  60. void ubus_msg_free(struct ubus_msg_buf *ub);
  61. struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
  62. struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
  63. void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
  64. void ubusd_proto_free_client(struct ubus_client *cl);
  65. void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub,
  66. uint8_t type);
  67. typedef struct ubus_msg_buf *(*event_fill_cb)(void *priv, const char *id);
  68. void ubusd_event_init(void);
  69. void ubusd_event_cleanup_object(struct ubus_object *obj);
  70. void ubusd_send_obj_event(struct ubus_object *obj, bool add);
  71. int ubusd_send_event(struct ubus_client *cl, const char *id,
  72. event_fill_cb fill_cb, void *cb_priv);
  73. void ubusd_acl_init(void);
  74. void ubusd_monitor_init(void);
  75. void ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send);
  76. void ubusd_monitor_disconnect(struct ubus_client *cl);
  77. #endif