jabberd2  2.2.17
plugins.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002-2007 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris, Tomasz Sterna
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 #ifndef INCL_SX_PLUGINS_H
22 #define INCL_SX_PLUGINS_H
23 
25 #define SX_SSL_WRAPPER (1<<0)
26 #define SX_SSL_STARTTLS_OFFER (1<<1)
27 #define SX_SSL_STARTTLS_REQUIRE (1<<2)
29 #define SX_SASL_OFFER (1<<3)
31 #define SX_COMPRESS_WRAPPER (1<<4)
32 #define SX_COMPRESS_OFFER (1<<5)
33 
34 
36 #define SX_SSL_MAGIC (0x01)
37 
38 
40 /* prefix 0x0. is taken by sx core errors in sx.h */
41 #define SX_ERR_SSL (0x010)
42 #define SX_ERR_STARTTLS_FAILURE (0x011)
43 
44 #define SX_ERR_COMPRESS (0x020)
45 #define SX_ERR_COMPRESS_FAILURE (0x021)
46 
47 
48 #define SX_CONN_EXTERNAL_ID_MAX_COUNT 8
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 /* SSL plugin */
56 #ifdef HAVE_SSL
57 
58 #include <openssl/md5.h>
59 #include <openssl/ssl.h>
60 #include <openssl/err.h>
61 #include <openssl/x509v3.h>
62 
63 
65 JABBERD2_API int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args);
66 
68 JABBERD2_API int sx_ssl_server_addcert(sx_plugin_t p, char *name, char *pemfile, char *cachain, int mode);
69 
71 JABBERD2_API int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, char *pemfile);
72 
73 /* previous states */
74 #define SX_SSL_STATE_NONE (0)
75 #define SX_SSL_STATE_WANT_READ (1)
76 #define SX_SSL_STATE_WANT_WRITE (2)
77 #define SX_SSL_STATE_ERROR (3)
78 
80 typedef struct _sx_ssl_conn_st {
81  /* id and ssf for sasl external auth */
82  char *external_id[SX_CONN_EXTERNAL_ID_MAX_COUNT];
83 
84  SSL *ssl;
85 
86  BIO *wbio, *rbio;
87 
88  jqueue_t wq;
89 
90  int last_state;
91 
92  char *pemfile;
93 } *_sx_ssl_conn_t;
94 
95 #endif /* HAVE_SSL */
96 
97 
98 /* SASL plugin */
99 
101 JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args);
102 
104 typedef int (*sx_sasl_callback_t)(int cb, void *arg, void **res, sx_t s, void *cbarg);
105 
106 /* callbacks */
107 #define sx_sasl_cb_GET_REALM (0x00)
108 #define sx_sasl_cb_GET_PASS (0x01)
109 #define sx_sasl_cb_CHECK_PASS (0x02)
110 #define sx_sasl_cb_CHECK_AUTHZID (0x03)
111 #define sx_sasl_cb_GEN_AUTHZID (0x04)
112 #define sx_sasl_cb_CHECK_MECH (0x05)
113 
114 /* error codes */
115 #define sx_sasl_ret_OK (0)
116 #define sx_sasl_ret_FAIL (1)
117 
119 JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, char *appname, char *mech, char *user, char *pass);
120 
121 /* for passing auth data to callback */
122 typedef struct sx_sasl_creds_st {
123  const char *authnid;
124  const char *realm;
125  const char *authzid;
126  const char *pass;
127 } *sx_sasl_creds_t;
128 
129 
130 /* Stream Compression plugin */
131 #ifdef HAVE_LIBZ
132 
133 #include <zlib.h>
134 
136 JABBERD2_API int sx_compress_init(sx_env_t env, sx_plugin_t p, va_list args);
137 
138 /* allocation chunk for decompression */
139 #define SX_COMPRESS_CHUNK 16384
140 
142 typedef struct _sx_compress_conn_st {
143  /* zlib streams for deflate() and inflate() */
144  z_stream wstrm, rstrm;
145 
146  /* buffers for compressed and decompressed data */
147  sx_buf_t wbuf, rbuf;
148 
149 } *_sx_compress_conn_t;
150 
151 #endif /* HAVE_LIBZ */
152 
153 
154 #ifdef ENABLE_EXPERIMENTAL
155 
156 /* Stanza Acknowledgements plugin */
158 JABBERD2_API int sx_ack_init(sx_env_t env, sx_plugin_t p, va_list args);
159 
160 /* My IP Address plugin */
162 JABBERD2_API int sx_address_init(sx_env_t env, sx_plugin_t p, va_list args);
163 
164 #endif /* ENABLE_EXPERIMENTAL */
165 
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 
172 #endif /* INCL_SX_PLUGINS_H */