forked from jabberd2/jabberd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.h
248 lines (194 loc) · 6.35 KB
/
router.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* jabberd - Jabber Open Source Server
* Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
* Ryan Eatmon, Robert Norris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
*/
/*! \mainpage jabberd - Jabber Open Source Server
*
* \section intro Introduction
*
* The jabberd project aims to provide an open-source server
* implementation of the Jabber protocols for instant messaging
* and XML routing. The goal of this project is to provide a
* scalable, reliable, efficient and extensible server that
* provides a complete set of features and is up to date with
* the latest protocol revisions.
*
* The project web page:\n
* http://jabberd2.xiaoka.com/
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "sx/sx.h"
#include "mio/mio.h"
#include "util/util.h"
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
typedef struct router_st *router_t;
typedef struct component_st *component_t;
typedef struct routes_st *routes_t;
typedef struct alias_st *alias_t;
typedef struct acl_s *acl_t;
struct acl_s {
int error;
char *redirect;
int redirect_len;
char *what;
char *from;
char *to;
char *dump;
int log;
acl_t next;
};
struct router_st {
/** our id */
const char *id;
/** config */
config_t config;
/** user table */
xht users;
time_t users_load;
/** user table */
acl_t filter;
time_t filter_load;
/** logging */
log_t log;
/** log data */
log_type_t log_type;
const char *log_facility;
const char *log_ident;
/** how we listen for stuff */
const char *local_ip;
int local_port;
const char *local_secret;
const char *local_pemfile;
const char *local_private_key_password;
const char *local_ciphers;
/** max file descriptors */
int io_max_fds;
/** access controls */
access_t access;
/** connection rates */
int conn_rate_total;
int conn_rate_seconds;
int conn_rate_wait;
xht conn_rates;
/** default byte rates (karma) */
int byte_rate_total;
int byte_rate_seconds;
int byte_rate_wait;
/** sx environment */
sx_env_t sx_env;
sx_plugin_t sx_ssl;
sx_plugin_t sx_sasl;
/** managed io */
mio_t mio;
/** listening socket */
mio_fd_t fd;
/** time checks */
int check_interval;
int check_keepalive;
time_t next_check;
/** attached components, key is 'ip:port', var is component_t */
xht components;
/** valid routes, key is route name (packet "to" address), var is component_t */
xht routes;
/** default route, only one */
const char *default_route;
/** log sinks, key is route name, var is component_t */
xht log_sinks;
/** configured aliases */
alias_t aliases;
/** access control lists */
xht aci;
/** list of sx_t waiting to be cleaned up */
jqueue_t dead;
/** list of mio_fd_t waiting to be closed */
jqueue_t closefd;
/** list of routes_t waiting to be cleaned up */
jqueue_t deadroutes;
/** simple message logging */
int message_logging_enabled;
const char *message_logging_file;
};
/** a single component */
struct component_st {
router_t r;
/** file descriptor */
mio_fd_t fd;
/** remote ip and port */
char ip[INET6_ADDRSTRLEN];
int port;
/** ip:port pair */
char ipport[INET6_ADDRSTRLEN + 6];
/** our stream */
sx_t s;
/** rate limits */
rate_t rate;
int rate_log;
/** valid routes to this component, key is route name */
xht routes;
/** true if this is an old component:accept stream */
int legacy;
/** throttle queue */
jqueue_t tq;
/** timestamps for idle timeouts */
time_t last_activity;
};
/** route types */
typedef enum {
route_SINGLE = 0x00, /**< single component route */
route_MULTI_TO = 0x10, /**< multi component route - route by 'to' */
route_MULTI_FROM = 0x11, /**< multi component route - route by 'from' */
} route_type_t;
struct routes_st
{
const char *name;
route_type_t rtype;
component_t *comp;
int ncomp;
};
struct alias_st {
const char *name;
const char *target;
alias_t next;
};
int router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
void router_sx_handshake(sx_t s, sx_buf_t buf, void *arg);
xht aci_load(router_t r);
void aci_unload(xht aci);
int aci_check(xht acls, const char *type, const char *name);
int user_table_load(router_t r);
void user_table_unload(router_t r);
int filter_load(router_t r);
void filter_unload(router_t r);
int filter_packet(router_t r, nad_t nad);
int message_log(nad_t nad, router_t r, const char *msg_from, const char *msg_to);
void routes_free(routes_t routes);
/* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
union xhashv
{
void **val;
char **char_val;
component_t *comp_val;
rate_t *rt_val;
};