1
0

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 <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Admin_H
  16. #define Admin_H
  17. #include "benc/Dict.h"
  18. #include "exception/Except.h"
  19. #include "interface/addressable/AddrInterface.h"
  20. #include "memory/Allocator.h"
  21. #include "util/log/Log.h"
  22. #include "util/UniqueName.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. 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_sendMessage_CHANNEL_CLOSED -1
  60. int Admin_sendMessage(Dict* message, String* txid, struct Admin* admin);
  61. struct Admin* Admin_new(struct AddrInterface* iface,
  62. struct Allocator* alloc,
  63. struct Log* logger,
  64. struct EventBase* eventBase,
  65. String* password);
  66. #else
  67. #include "util/UniqueName.h"
  68. #endif