-
Notifications
You must be signed in to change notification settings - Fork 587
/
Admin.h
73 lines (64 loc) · 2.83 KB
/
Admin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Admin_H
#define Admin_H
#include "benc/Dict.h"
#include "exception/ExceptionHandler.h"
#include "memory/Allocator.h"
#include "util/Log.h"
#include <event2/event.h>
#include <stdbool.h>
#define Admin_FUNCTION(name) void (* name)(Dict* input, void* context, String* txid)
struct Admin;
struct Admin_FunctionArg
{
char* name;
char* type;
bool required;
};
/**
* @param arguments an array of struct Admin_FunctionArg specifying what functions are available
* and of those, which are required.
* Example C code:
* struct Admin_FunctionArg adma[2] = {
* { .name = "password", .required = 1, .type = "String" },
* { .name = "authType", .required = 0, .type = "Int" }
* };
* Admin_registerFunction("AuthorizedPasswords_add", add, context, true, adma, admin);
*/
void Admin_registerFunctionWithArgCount(char* name,
Admin_FUNCTION(callback),
void* callbackContext,
bool needsAuth,
struct Admin_FunctionArg* arguments,
int argCount,
struct Admin* admin);
#define Admin_registerFunction(name, cb, ctx, needsAuth, args, admin) \
Admin_registerFunctionWithArgCount( \
name, cb, ctx, needsAuth, args, (sizeof(args) / sizeof(struct Admin_FunctionArg)), admin)
void Admin_sendMessage(Dict* message, String* txid, struct Admin* admin);
struct Admin* Admin_new(struct sockaddr_storage* addr,
int addrLen,
String* password,
char* user,
struct event_base* eventBase,
struct ExceptionHandler* eh,
struct Log* logger,
struct Allocator* allocator);
void Admin_getConnectInfo(struct sockaddr_storage** addrPtr,
int* addrLenPtr,
String** passwordPtr,
struct Admin* admin);
#endif