Admin.h 2.9 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/addressable/AddrIface.h"
  18. #include "memory/Allocator.h"
  19. #include "util/log/Log.h"
  20. #include "util/events/EventBase.h"
  21. #include "util/Linker.h"
  22. Linker_require("admin/Admin.c")
  23. #include <stdbool.h>
  24. typedef void (* Admin_Function)
  25. (Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc);
  26. struct Admin
  27. {
  28. int unused;
  29. };
  30. struct Admin_FunctionArg
  31. {
  32. char* name;
  33. char* type;
  34. bool required;
  35. };
  36. #define Admin_MAX_REQUEST_SIZE 512
  37. // This must not exceed PipeInterface_MAX_MESSAGE_SIZE
  38. #define Admin_MAX_RESPONSE_SIZE 65536
  39. /**
  40. * @param arguments an array of struct Admin_FunctionArg specifying what functions are available
  41. * and of those, which are required.
  42. * Example C code:
  43. * Admin_registerFunction("AuthorizedPasswords_add", addPass, ctx, true,
  44. * ((struct Admin_FunctionArg[]) {
  45. * { .name = "password", .required = 1, .type = "String" },
  46. * { .name = "authType", .required = 0, .type = "Int" }
  47. * }), admin);
  48. */
  49. void Admin_registerFunctionWithArgCount(char* name,
  50. Admin_Function callback,
  51. void* callbackContext,
  52. bool needsAuth,
  53. struct Admin_FunctionArg* arguments,
  54. int argCount,
  55. struct Admin* admin);
  56. #define Admin_registerFunction(name, cb, ctx, needsAuth, args, admin) \
  57. Admin_registerFunctionWithArgCount( \
  58. name, cb, ctx, needsAuth, args, (sizeof(args) / sizeof(struct Admin_FunctionArg)), admin)
  59. #define Admin_registerFunctionNoArgs(name, cb, ctx, needsAuth, admin) \
  60. Admin_registerFunctionWithArgCount(name, cb, ctx, needsAuth, NULL, 0, admin)
  61. #define Admin_sendMessage_CHANNEL_CLOSED -1
  62. int Admin_sendMessage(Dict* message, String* txid, struct Admin* admin);
  63. struct Admin* Admin_new(AddrIface_t* ai,
  64. struct Log* logger,
  65. EventBase_t* eventBase,
  66. String* password);
  67. #endif