1
0

Admin.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Admin_H
  16. #define Admin_H
  17. #include "interface/Iface.h"
  18. #include "interface/addressable/AddrIface.h"
  19. #include "benc/Dict.h"
  20. #include "exception/Except.h"
  21. #include "memory/Allocator.h"
  22. #include "util/log/Log.h"
  23. #include "util/events/EventBase.h"
  24. #include "util/Linker.h"
  25. Linker_require("admin/Admin.c")
  26. #include <stdbool.h>
  27. typedef void (* Admin_Function)
  28. (Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc);
  29. struct Admin
  30. {
  31. int unused;
  32. };
  33. struct Admin_FunctionArg
  34. {
  35. char* name;
  36. char* type;
  37. bool required;
  38. };
  39. #define Admin_MAX_REQUEST_SIZE 512
  40. // This must not exceed PipeInterface_MAX_MESSAGE_SIZE
  41. #define Admin_MAX_RESPONSE_SIZE 65536
  42. /**
  43. * @param arguments an array of struct Admin_FunctionArg specifying what functions are available
  44. * and of those, which are required.
  45. * Example C code:
  46. * Admin_registerFunction("AuthorizedPasswords_add", addPass, ctx, true,
  47. * ((struct Admin_FunctionArg[]) {
  48. * { .name = "password", .required = 1, .type = "String" },
  49. * { .name = "authType", .required = 0, .type = "Int" }
  50. * }), admin);
  51. */
  52. void Admin_registerFunctionWithArgCount(char* name,
  53. Admin_Function callback,
  54. void* callbackContext,
  55. bool needsAuth,
  56. struct Admin_FunctionArg* arguments,
  57. int argCount,
  58. struct Admin* admin);
  59. #define Admin_registerFunction(name, cb, ctx, needsAuth, args, admin) \
  60. Admin_registerFunctionWithArgCount( \
  61. name, cb, ctx, needsAuth, args, (sizeof(args) / sizeof(struct Admin_FunctionArg)), admin)
  62. #define Admin_sendMessage_CHANNEL_CLOSED -1
  63. int Admin_sendMessage(Dict* message, String* txid, struct Admin* admin);
  64. struct Admin* Admin_new(AddrIface_t* ai,
  65. struct Log* logger,
  66. EventBase_t* eventBase,
  67. String* password);
  68. #endif