ubusd.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 UBUS_OBJ_HASH_BITS 4
  24. #define UBUS_CLIENT_MAX_TXQ_LEN UBUS_MAX_MSGLEN
  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_msg_buf_list {
  34. struct list_head list;
  35. struct ubus_msg_buf *msg;
  36. };
  37. struct ubus_client_cmd {
  38. struct list_head list;
  39. struct ubus_msg_buf *msg;
  40. struct ubus_object *obj;
  41. };
  42. struct ubus_client {
  43. struct ubus_id id;
  44. struct uloop_fd sock;
  45. struct blob_buf b;
  46. uid_t uid;
  47. gid_t gid;
  48. char *user;
  49. char *group;
  50. struct list_head objects;
  51. struct list_head cmd_queue;
  52. struct list_head tx_queue;
  53. unsigned int txq_ofs;
  54. unsigned int txq_len;
  55. struct ubus_msg_buf *pending_msg;
  56. struct ubus_msg_buf *retmsg;
  57. int pending_msg_offset;
  58. int pending_msg_fd;
  59. struct {
  60. struct ubus_msghdr hdr;
  61. struct blob_attr data;
  62. } hdrbuf;
  63. };
  64. struct ubus_path {
  65. struct list_head list;
  66. const char name[];
  67. };
  68. extern const char *ubusd_acl_dir;
  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);
  71. ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset);
  72. void ubus_msg_free(struct ubus_msg_buf *ub);
  73. void ubus_msg_list_free(struct ubus_msg_buf_list *ubl);
  74. struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len);
  75. struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb);
  76. void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub);
  77. void ubusd_proto_free_client(struct ubus_client *cl);
  78. void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub,
  79. uint8_t type);
  80. int ubusd_cmd_lookup(struct ubus_client *cl, struct ubus_client_cmd *cmd);
  81. typedef struct ubus_msg_buf *(*event_fill_cb)(void *priv, const char *id);
  82. void ubusd_event_init(void);
  83. void ubusd_event_cleanup_object(struct ubus_object *obj);
  84. void ubusd_send_obj_event(struct ubus_object *obj, bool add);
  85. int ubusd_send_event(struct ubus_client *cl, const char *id,
  86. event_fill_cb fill_cb, void *cb_priv);
  87. void ubusd_acl_init(void);
  88. void ubusd_monitor_init(void);
  89. void ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send);
  90. void ubusd_monitor_disconnect(struct ubus_client *cl);
  91. #endif