]>
Commit | Line | Data |
---|---|---|
18f8bd28 CP |
1 | /* |
2 | nterfacer | |
3 | Copyright (C) 2004 Chris Porter. | |
4 | */ | |
5 | ||
6 | #ifndef __nterfacer_H | |
7 | #define __nterfacer_H | |
8 | ||
6bc02131 | 9 | #include <sys/types.h> |
18f8bd28 CP |
10 | #include <netinet/in.h> |
11 | ||
8186335d CP |
12 | #include "../lib/sstring.h" |
13 | ||
18f8bd28 CP |
14 | #include "esockets.h" |
15 | #include "library.h" | |
d68699b4 | 16 | #include "acls.h" |
18f8bd28 CP |
17 | |
18 | #define BF_OK 0x00 | |
19 | #define BF_OVER 0xFF | |
f435bd22 | 20 | #define BF_UNLOADED 0xFE |
18f8bd28 CP |
21 | |
22 | #define SS_IDLE 0x00 | |
23 | #define SS_VERSIONED 0x01 | |
24 | #define SS_AUTHENTICATED 0x02 | |
25 | ||
26 | #define NTERFACER_PORT 2438 | |
27 | ||
28 | #define MAX_ARGS 100 | |
29 | ||
80d91dd6 | 30 | #define PROTOCOL_VERSION "4" |
18f8bd28 CP |
31 | #define ANTI_FULL_VERSION "service_link " PROTOCOL_VERSION |
32 | ||
a690fb9f CP |
33 | struct rline; |
34 | ||
35 | typedef int (*handler_function)(struct rline *ri, int argc, char **argv); | |
2a6be5fe | 36 | typedef void (*rline_callback)(int failed, int linec, char **linev, void *tag); |
a690fb9f | 37 | |
18f8bd28 CP |
38 | typedef struct handler { |
39 | sstring *command; | |
40 | int args; /* MINIMUM ARGUMENTS */ | |
a690fb9f | 41 | handler_function function; |
18f8bd28 | 42 | struct handler *next; |
504f62c7 | 43 | void *service; |
18f8bd28 CP |
44 | } handler; |
45 | ||
46 | typedef struct service_node { | |
47 | sstring *name; | |
48 | struct handler *handlers; | |
49 | struct service_node *next; | |
50 | } service_node; | |
51 | ||
52 | typedef struct rline { | |
53 | struct handler *handler; | |
54 | int id; | |
55 | struct service_node *service; | |
56 | char buf[MAX_BUFSIZE]; | |
57 | char *curpos; | |
58 | struct rline *next; | |
59 | void *tag; | |
e5a7c318 | 60 | rline_callback callback; |
18f8bd28 CP |
61 | struct esocket *socket; |
62 | } rline; | |
63 | ||
64 | typedef struct permitted { | |
65 | sstring *hostname; | |
66 | sstring *password; | |
67 | in_addr_t ihost; | |
d68699b4 | 68 | struct acls *acls; |
18f8bd28 CP |
69 | } permitted; |
70 | ||
71 | typedef struct sconnect { | |
72 | int status; | |
1ac1d43c CP |
73 | char response[32 * 2 + 1], challenge[32 * 2 + 1]; |
74 | unsigned char iv[16]; | |
18f8bd28 | 75 | struct permitted *permit; |
1ac1d43c | 76 | unsigned char ournonce[16]; |
18f8bd28 CP |
77 | } sconnect; |
78 | ||
79 | extern struct nterface_auto_log *nrl; | |
80 | ||
18f8bd28 CP |
81 | struct service_node *register_service(char *name); |
82 | struct handler *register_handler(struct service_node *service, char *command, int args, handler_function fp); | |
83 | void deregister_service(struct service_node *service); | |
504f62c7 | 84 | void deregister_handler(struct handler *hp); |
18f8bd28 CP |
85 | int respond(struct rline *li, int argc, ...); |
86 | int error_respond(struct rline *li, int error_code, char *format, ...); | |
87 | ||
bb4b25ee CP |
88 | int ri_append(struct rline *li, char *format, ...) __attribute__ ((format (printf, 2, 3))); |
89 | int ri_error(struct rline *li, int error_code, char *format, ...) __attribute__ ((format (printf, 3, 4))); | |
18f8bd28 CP |
90 | int ri_final(struct rline *li); |
91 | ||
92 | int load_permits(void); | |
93 | int setup_listening_socket(void); | |
94 | ||
95 | void nterfacer_accept_event(struct esocket *socket); | |
96 | void nterfacer_disconnect_event(struct esocket *socket); | |
97 | int nterfacer_line_event(struct esocket *socket, char *newline); | |
d68699b4 | 98 | int nterfacer_new_rline(char *line, struct esocket *socket, int *number, struct permitted *permit); |
18f8bd28 CP |
99 | struct sconnect *find_sconnect_from_fd(int fd); |
100 | ||
e5a7c318 CP |
101 | void *nterfacer_sendline(char *service, char *command, int argc, char **argv, rline_callback callback, void *tag); |
102 | void nterfacer_freeline(void *arg); | |
18f8bd28 | 103 | |
e5a7c318 | 104 | #endif |