1
0

Admin.h 2.9 KB

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