jabberd2  2.2.17
sm.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 drvify
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 
29 #ifdef HAVE_CONFIG_H
30  #include <config.h>
31 #endif
32 
33 #include "sx/sx.h"
34 #include "mio/mio.h"
35 #include "util/util.h"
36 #include "storage/storage.h"
37 
38 #ifdef HAVE_SIGNAL_H
39  #include <signal.h>
40 #endif
41 #ifdef HAVE_SYS_STAT_H
42  #include <sys/stat.h>
43 #endif
44 
45 #ifdef _WIN32
46  #ifdef _USRDLL
47  #define DLLEXPORT __declspec(dllexport)
48  #define SM_API __declspec(dllimport)
49  #else
50  #define DLLEXPORT __declspec(dllimport)
51  #define SM_API __declspec(dllexport)
52  #endif
53 #else
54  #define DLLEXPORT
55  #define SM_API
56 #endif
57 
58 /* forward declarations */
59 typedef struct sm_st *sm_t;
60 typedef struct user_st *user_t;
61 typedef struct sess_st *sess_t;
62 typedef struct aci_st *aci_t;
63 typedef struct mm_st *mm_t;
64 
65 /* namespace uri strings */
66 #include "util/uri.h"
67 
68 /* indexed known namespace values */
69 #define ns_AUTH (1)
70 #define ns_REGISTER (2)
71 #define ns_ROSTER (3)
72 #define ns_AGENTS (4)
73 #define ns_DELAY (5)
74 #define ns_BROWSE (6)
75 #define ns_EVENT (7)
76 #define ns_GATEWAY (8)
77 #define ns_EXPIRE (9)
78 #define ns_SEARCH (10)
79 #define ns_DISCO (11)
80 #define ns_DISCO_ITEMS (12)
81 #define ns_DISCO_INFO (13)
82 
83 #define ns_AMP (14)
84 #define ns_AMP_ERRORS (15)
85 #define ns_AMP_ACTION_DROP (16)
86 #define ns_AMP_ACTION_ERROR (17)
87 #define ns_AMP_ACTION_NOTIFY (18)
88 #define ns_AMP_CONDITION_DELIVER (19)
89 #define ns_AMP_CONDITION_EXPIREAT (20)
90 #define ns_AMP_CONDITION_MATCHRESOURCE (21)
91 
93 typedef enum {
94  pkt_NONE = 0x00,
95  pkt_MESSAGE = 0x10,
99  pkt_PRESENCE = 0x20,
102  pkt_S10N = 0x40,
103  pkt_S10N_ED = 0x41,
104  pkt_S10N_UN = 0x42,
105  pkt_S10N_UNED = 0x44,
106  pkt_IQ = 0x80,
107  pkt_IQ_SET = 0x81,
108  pkt_IQ_RESULT = 0x82,
109  pkt_SESS = 0x100,
110  pkt_SESS_END = 0x101,
111  pkt_SESS_CREATE = 0x102,
112  pkt_SESS_DELETE = 0x104,
114  pkt_SESS_MASK = 0x10f,
115  pkt_ERROR = 0x200
116 } pkt_type_t;
117 
119 typedef enum {
120  route_NONE = 0x00,
121  route_UNICAST = 0x10,
123  route_ADV = 0x20,
124  route_ADV_UN = 0x21,
125  route_ERROR = 0x40
126 } route_type_t;
127 
129 typedef struct pkt_st {
130  sm_t sm;
132  sess_t source;
142  int ns;
144  int pri;
147 } *pkt_t;
148 
150 typedef struct item_st {
153  char *name;
155  char **groups;
157  int ngroups;
159  int to, from;
161  int ask;
163  int ver;
164 } *item_t;
165 
167 struct sm_st {
168  char *id;
170  char *router_ip;
172  char *router_user;
173  char *router_pass;
200  char *log_facility;
201  char *log_ident;
208  storage_t st;
210  mm_t mm;
214  char signature[2048];
215  int siglen;
217  int started;
219  int online;
228 };
229 
231 struct user_st {
234  sm_t sm;
240  sess_t sessions;
241  sess_t top;
242  int available;
244  time_t active;
246  void **module_data;
247 };
248 
250 struct sess_st {
253  user_t user;
257  char c2s[1024];
259  char sm_id[41];
260  char c2s_id[44];
264  int available;
265  int pri;
266  int fake;
271  void **module_data;
273  sess_t next;
274 };
275 
276 extern sig_atomic_t sm_lost_router;
277 
278 /* functions */
279 SM_API xht aci_load(sm_t sm);
280 SM_API int aci_check(xht acls, char *type, jid_t jid);
281 SM_API void aci_unload(xht acls);
282 
283 SM_API int sm_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
284 SM_API int sm_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
285 SM_API void sm_timestamp(time_t t, char timestamp[18]);
286 SM_API void sm_c2s_action(sess_t dest, char *action, char *target);
287 SM_API void sm_signature(sm_t sm, char *str);
288 
289 SM_API int sm_register_ns(sm_t sm, char *uri);
290 SM_API void sm_unregister_ns(sm_t sm, char *uri);
291 SM_API int sm_get_ns(sm_t sm, char *uri);
292 
293 SM_API int sm_storage_rate_limit(sm_t sm, const char *owner);
294 
295 SM_API void dispatch(sm_t sm, pkt_t pkt);
296 
297 SM_API pkt_t pkt_error(pkt_t pkt, int err);
299 SM_API pkt_t pkt_dup(pkt_t pkt, const char *to, const char *from);
300 SM_API pkt_t pkt_new(sm_t sm, nad_t nad);
301 SM_API void pkt_free(pkt_t pkt);
302 SM_API pkt_t pkt_create(sm_t sm, const char *elem, const char *type, const char *to, const char *from);
303 SM_API void pkt_id(pkt_t src, pkt_t dest);
304 SM_API void pkt_id_new(pkt_t pkt);
305 SM_API void pkt_delay(pkt_t pkt, time_t t, const char *from);
306 
307 SM_API void pkt_router(pkt_t pkt);
308 SM_API void pkt_sess(pkt_t pkt, sess_t sess);
309 
310 SM_API int pres_trust(user_t user, jid_t jid);
311 SM_API void pres_roster(sess_t sess, item_t item);
312 SM_API void pres_update(sess_t sess, pkt_t pres);
313 SM_API void pres_error(sess_t sess, jid_t jid);
314 SM_API void pres_deliver(sess_t sess, pkt_t pres);
315 SM_API void pres_in(user_t user, pkt_t pres);
316 SM_API void pres_probe(user_t user);
317 
318 SM_API void sess_route(sess_t sess, pkt_t pkt);
319 SM_API sess_t sess_start(sm_t sm, jid_t jid);
320 SM_API void sess_end(sess_t sess);
321 SM_API sess_t sess_match(user_t user, char *resource);
322 
323 SM_API user_t user_load(sm_t sm, jid_t jid);
324 SM_API void user_free(user_t user);
325 SM_API int user_create(sm_t sm, jid_t jid);
326 SM_API void user_delete(sm_t sm, jid_t jid);
327 
328 SM_API void feature_register(sm_t sm, char *feature);
329 SM_API void feature_unregister(sm_t sm, char *feature);
330 
331 
332 /* driver module manager */
333 
335 typedef enum {
338 } mod_ret_t;
339 
341 typedef enum {
356 } mod_chain_t;
357 
358 typedef struct module_st *module_t;
360 
362 struct mm_st {
363  sm_t sm;
367  int nindex;
370  mod_instance_t *sess_start; int nsess_start;
372  mod_instance_t *sess_end; int nsess_end;
374  mod_instance_t *in_sess; int nin_sess;
376  mod_instance_t *in_router; int nin_router;
378  mod_instance_t *out_sess; int nout_sess;
380  mod_instance_t *out_router; int nout_router;
382  mod_instance_t *pkt_sm; int npkt_sm;
384  mod_instance_t *pkt_user; int npkt_user;
386  mod_instance_t *pkt_router; int npkt_router;
388  mod_instance_t *user_load; int nuser_load;
390  mod_instance_t *user_create; int nuser_create;
392  mod_instance_t *user_delete; int nuser_delete;
394  mod_instance_t *disco_extend; int ndisco_extend;
396  mod_instance_t *user_unload; int nuser_unload;
397 };
398 
400 struct module_st {
401  mm_t mm;
403  char *name;
405  int index;
409  void *handle;
413  int init;
415  void *private;
417  int (*sess_start)(mod_instance_t mi, sess_t sess);
418  void (*sess_end)(mod_instance_t mi, sess_t sess);
420  mod_ret_t (*in_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt);
421  mod_ret_t (*in_router)(mod_instance_t mi, pkt_t pkt);
423  mod_ret_t (*out_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt);
424  mod_ret_t (*out_router)(mod_instance_t mi, pkt_t pkt);
426  mod_ret_t (*pkt_sm)(mod_instance_t mi, pkt_t pkt);
427  mod_ret_t (*pkt_user)(mod_instance_t mi, user_t user, pkt_t pkt);
429  mod_ret_t (*pkt_router)(mod_instance_t mi, pkt_t pkt);
431  int (*user_load)(mod_instance_t mi, user_t user);
432  int (*user_unload)(mod_instance_t mi, user_t user);
434  int (*user_create)(mod_instance_t mi, jid_t jid);
435  void (*user_delete)(mod_instance_t mi, jid_t jid);
437  void (*disco_extend)(mod_instance_t mi, pkt_t pkt);
439  void (*free)(module_t mod);
440 };
441 
444  sm_t sm;
446  module_t mod;
448  int seq;
452  char *arg;
453 };
454 
456 SM_API mm_t mm_new(sm_t sm);
458 SM_API void mm_free(mm_t mm);
459 
461 SM_API int mm_sess_start(mm_t mm, sess_t sess);
463 SM_API void mm_sess_end(mm_t mm, sess_t sess);
464 
466 SM_API mod_ret_t mm_in_sess(mm_t mm, sess_t sess, pkt_t pkt);
468 SM_API mod_ret_t mm_in_router(mm_t mm, pkt_t pkt);
469 
471 SM_API mod_ret_t mm_out_sess(mm_t mm, sess_t sess, pkt_t pkt);
473 SM_API mod_ret_t mm_out_router(mm_t mm, pkt_t pkt);
474 
476 SM_API mod_ret_t mm_pkt_sm(mm_t mm, pkt_t pkt);
478 SM_API mod_ret_t mm_pkt_user(mm_t mm, user_t user, pkt_t pkt);
479 
481 SM_API mod_ret_t mm_pkt_router(mm_t mm, pkt_t pkt);
482 
484 SM_API int mm_user_load(mm_t mm, user_t user);
485 
487 SM_API int mm_user_unload(mm_t mm, user_t user);
488 
490 SM_API int mm_user_create(mm_t mm, jid_t jid);
492 SM_API void mm_user_delete(mm_t mm, jid_t jid);
493 
495 SM_API void mm_disco_extend(mm_t mm, pkt_t pkt);