]> jfr.im git - irc/quakenet/newserv.git/blob - nterface/nterfacer.h
r439@blue (orig r429): slug | 2006-02-23 13:39:37 +0000
[irc/quakenet/newserv.git] / nterface / nterfacer.h
1 /*
2 nterfacer
3 Copyright (C) 2004 Chris Porter.
4 */
5
6 #ifndef __nterfacer_H
7 #define __nterfacer_H
8
9 #include <sys/types.h>
10 #include <netinet/in.h>
11
12 #include "esockets.h"
13 #include "library.h"
14
15 #define BF_OK 0x00
16 #define BF_OVER 0xFF
17
18 #define SS_IDLE 0x00
19 #define SS_VERSIONED 0x01
20 #define SS_AUTHENTICATED 0x02
21
22 #define NTERFACER_PORT 2438
23
24 #define MAX_ARGS 100
25
26 #define PROTOCOL_VERSION "2"
27 #define ANTI_FULL_VERSION "service_link " PROTOCOL_VERSION
28
29 struct rline;
30
31 typedef int (*handler_function)(struct rline *ri, int argc, char **argv);
32
33 typedef struct handler {
34 sstring *command;
35 int args; /* MINIMUM ARGUMENTS */
36 handler_function function;
37 struct handler *next;
38 void *service;
39 } handler;
40
41 typedef struct service_node {
42 sstring *name;
43 struct handler *handlers;
44 struct service_node *next;
45 } service_node;
46
47 typedef struct rline {
48 struct handler *handler;
49 int id;
50 struct service_node *service;
51 char buf[MAX_BUFSIZE];
52 char *curpos;
53 struct rline *next;
54 void *tag;
55 struct esocket *socket;
56 } rline;
57
58 typedef struct permitted {
59 sstring *hostname;
60 sstring *password;
61 in_addr_t ihost;
62 } permitted;
63
64 typedef struct sconnect {
65 int status;
66 char response[20 * 2 + 1]; /* could store this in binary form but I really can't be assed */
67 struct permitted *permit;
68 unsigned char ournonce[NONCE_LEN];
69 } sconnect;
70
71 extern struct nterface_auto_log *nrl;
72
73 int accept_fd = -1;
74 struct permitted *permits;
75 int permit_count = 0;
76
77 struct service_node *register_service(char *name);
78 struct handler *register_handler(struct service_node *service, char *command, int args, handler_function fp);
79 void deregister_service(struct service_node *service);
80 void deregister_handler(struct handler *hp);
81 int respond(struct rline *li, int argc, ...);
82 int error_respond(struct rline *li, int error_code, char *format, ...);
83
84 int ri_append(struct rline *li, char *format, ...);
85 int ri_error(struct rline *li, int error_code, char *format, ...);
86 int ri_final(struct rline *li);
87
88 int load_permits(void);
89 int setup_listening_socket(void);
90
91 void nterfacer_accept_event(struct esocket *socket);
92 void nterfacer_disconnect_event(struct esocket *socket);
93 int nterfacer_line_event(struct esocket *socket, char *newline);
94 int nterfacer_new_rline(char *line, struct esocket *socket, int *number);
95 struct sconnect *find_sconnect_from_fd(int fd);
96
97 #endif
98