jabberd2  2.2.17
c2s.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include <expat.h>
26 
27 #include "mio/mio.h"
28 #include "sx/sx.h"
29 #include "util/util.h"
30 
31 #ifdef HAVE_SIGNAL_H
32 # include <signal.h>
33 #endif
34 #ifdef HAVE_SYS_STAT_H
35 # include <sys/stat.h>
36 #endif
37 
38 #ifdef _WIN32
39  #ifdef _USRDLL
40  #define DLLEXPORT __declspec(dllexport)
41  #define C2S_API __declspec(dllimport)
42  #else
43  #define DLLEXPORT __declspec(dllimport)
44  #define C2S_API __declspec(dllexport)
45  #endif
46 #else
47  #define DLLEXPORT
48  #define C2S_API
49 #endif
50 
51 /* forward declarations */
52 typedef struct host_st *host_t;
53 typedef struct c2s_st *c2s_t;
54 typedef struct bres_st *bres_t;
55 typedef struct sess_st *sess_t;
56 typedef struct authreg_st *authreg_t;
57 
59 struct bres_st {
63  char c2s_id[44], sm_id[41];
65  char sm_request[41];
66 
67  bres_t next;
68 };
69 
74 struct sess_st {
75  c2s_t c2s;
76 
78 
79  char skey[44];
80 
81  char *smcomp; /* sm component servicing this session */
82 
83  char *ip;
84  int port;
85 
87 
89  host_t host;
90 
92  int rate_log;
93 
96 
97  time_t last_activity;
98  unsigned int packet_count;
99 
100  /* count of bound resources */
101  int bound;
102  /* list of bound jids */
103  bres_t resources;
104 
105  int active;
106 
107  /* session related packet waiting for sm response */
109 
110  int sasl_authd; /* 1 = they did a sasl auth */
111 };
112 
113 /* allowed mechanisms */
114 #define AR_MECH_TRAD_PLAIN (1<<0)
115 #define AR_MECH_TRAD_DIGEST (1<<1)
116 
117 struct host_st {
119  char *realm;
120 
123 
126 
129 
132 
138 
139 };
140 
141 struct c2s_st {
143  char *id;
144 
146  char *router_ip;
148  char *router_user;
149  char *router_pass;
151 
154 
157 
162 
166 
169 #ifdef HAVE_SSL
170  mio_fd_t server_ssl_fd;
171 #endif
172 
175 
178 
182  char *log_ident;
183 
185  long long int packet_count;
187 
193 
195  char *local_ip;
196 
199 
202 
205 
208 
211 
214 
216  char *pbx_pipe;
219 
222 
225 
228 
233 
234  time_t next_check;
235 
238  authreg_t ar;
239 
243 
248 
250 
255 
260 
263 
266 
269 
272 
274  int started;
275 
277  int online;
278 
281  host_t vhost;
282 
285 };
286 
287 extern sig_atomic_t c2s_lost_router;
288 
289 C2S_API int c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
290 C2S_API int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
291 
292 C2S_API void sm_start(sess_t sess, bres_t res);
293 C2S_API void sm_end(sess_t sess, bres_t res);
294 C2S_API void sm_create(sess_t sess, bres_t res);
295 C2S_API void sm_delete(sess_t sess, bres_t res);
296 C2S_API void sm_packet(sess_t sess, bres_t res, nad_t nad);
297 
298 C2S_API int bind_init(sx_env_t env, sx_plugin_t p, va_list args);
299 
300 C2S_API void c2s_pbx_init(c2s_t c2s);
301 
303 {
304  c2s_t c2s;
305 
307  void *private;
308 
310  int (*user_exists)(authreg_t ar, char *username, char *realm);
311 
313  int (*get_password)(authreg_t ar, char *username, char *realm, char password[257]);
314 
316  int (*check_password)(authreg_t ar, char *username, char *realm, char password[257]);
317 
319  int (*set_password)(authreg_t ar, char *username, char *realm, char password[257]);
320 
322  int (*create_user)(authreg_t ar, char *username, char *realm);
323  int (*delete_user)(authreg_t ar, char *username, char *realm);
324 
325  void (*free)(authreg_t ar);
326 
327  /* Additions at the end - to preserve offsets for existing modules */
328 
330  int (*user_authz_allowed)(authreg_t ar, char *username, char *realm, char *requested_user);
331 };
332 
334 C2S_API authreg_t authreg_init(c2s_t c2s, char *name);
335 
337 C2S_API void authreg_free(authreg_t ar);
338 
340 typedef int (*ar_module_init_fn)(authreg_t);
341 
343 C2S_API int authreg_process(c2s_t c2s, sess_t sess, nad_t nad);
344 
345 /*
346 int authreg_user_exists(authreg_t ar, char *username, char *realm);
347 int authreg_get_password(authreg_t ar, char *username, char *realm, char password[257]);
348 int authreg_check_password(authreg_t ar, char *username, char *realm, char password[257]);
349 int authreg_set_password(authreg_t ar, char *username, char *realm, char password[257]);
350 int authreg_create_user(authreg_t ar, char *username, char *realm);
351 int authreg_delete_user(authreg_t ar, char *username, char *realm);
352 void authreg_free(authreg_t ar);
353 */
354 
355 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
356 union xhashv
357 {
358  void **val;
359  char **char_val;
360  sess_t *sess_val;
361 };
362 
363 // Data for stream redirect errors
364 typedef struct stream_redirect_st
365 {
366  char *to_address;
367  char *to_port;
369