jabberd2  2.3.4
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 #define SX_WEBSOCKET_WRAPPER (1<<6)
37 #define SX_SSL_MAGIC (0x01)
38 
39 
41 /* prefix 0x0. is taken by sx core errors in sx.h */
42 #define SX_ERR_SSL (0x010)
43 #define SX_ERR_STARTTLS_FAILURE (0x011)
44 
45 #define SX_ERR_COMPRESS (0x020)
46 #define SX_ERR_COMPRESS_FAILURE (0x021)
47 
48 
49 #define SX_CONN_EXTERNAL_ID_MAX_COUNT 8
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 
56 /* SSL plugin */
57 #ifdef HAVE_SSL
58 
59 #include <openssl/md5.h>
60 #include <openssl/ssl.h>
61 #include <openssl/err.h>
62 #include <openssl/x509v3.h>
63 
64 
66 JABBERD2_API int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args);
67 
69 JABBERD2_API int sx_ssl_server_addcert(sx_plugin_t p, const char *name, const char *pemfile, const char *cachain, int mode, const char *private_key_password, const char *ciphers);
70 
72 JABBERD2_API int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, const char *pemfile, const char *private_key_password);
73 
74 /* previous states */
75 #define SX_SSL_STATE_NONE (0)
76 #define SX_SSL_STATE_WANT_READ (1)
77 #define SX_SSL_STATE_WANT_WRITE (2)
78 #define SX_SSL_STATE_ERROR (3)
79 
81 typedef struct _sx_ssl_conn_st {
82  /* id and ssf for sasl external auth */
83  char *external_id[SX_CONN_EXTERNAL_ID_MAX_COUNT];
84 
85  SSL *ssl;
86 
87  BIO *wbio, *rbio;
88 
89  jqueue_t wq;
90 
91  int last_state;
92 
93  char *pemfile;
94 
95  char *private_key_password;
96 } *_sx_ssl_conn_t;
97 
98 #endif /* HAVE_SSL */
99 
100 
101 /* SASL plugin */
102 
104 JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args);
105 
107 typedef int (*sx_sasl_callback_t)(int cb, void *arg, void **res, sx_t s, void *cbarg);
108 
109 /* callbacks */
110 #define sx_sasl_cb_GET_REALM (0x00)
111 #define sx_sasl_cb_GET_PASS (0x01)
112 #define sx_sasl_cb_CHECK_PASS (0x02)
113 #define sx_sasl_cb_CHECK_AUTHZID (0x03)
114 #define sx_sasl_cb_GEN_AUTHZID (0x04)
115 #define sx_sasl_cb_CHECK_MECH (0x05)
116 
117 /* error codes */
118 #define sx_sasl_ret_OK (0)
119 #define sx_sasl_ret_FAIL (1)
120 
122 JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, const char *appname, const char *mech, const char *user, const char *pass);
123 
124 /* for passing auth data to callback */
125 typedef struct sx_sasl_creds_st {
126  const char *authnid;
127  const char *realm;
128  const char *authzid;
129  const char *pass;
130 } *sx_sasl_creds_t;
131 
132 
133 /* Stream Compression plugin */
134 #ifdef HAVE_LIBZ
135 
136 #include <zlib.h>
137 
139 JABBERD2_API int sx_compress_init(sx_env_t env, sx_plugin_t p, va_list args);
140 
141 /* allocation chunk for decompression */
142 #define SX_COMPRESS_CHUNK 16384
143 
145 typedef struct _sx_compress_conn_st {
146  /* zlib streams for deflate() and inflate() */
147  z_stream wstrm, rstrm;
148 
149  /* buffers for compressed and decompressed data */
150  sx_buf_t wbuf, rbuf;
151 
152 } *_sx_compress_conn_t;
153 
154 #endif /* HAVE_LIBZ */
155 
156 
157 /* Stanza Acknowledgements plugin */
159 JABBERD2_API int sx_ack_init(sx_env_t env, sx_plugin_t p, va_list args);
160 
161 /* websocket wrapper plugin */
162 //#ifdef USE_WEBSOCKET
163 #include <http_parser.h>
164 #include <util/util.h>
165 
166 JABBERD2_API int sx_websocket_init(sx_env_t env, sx_plugin_t p, va_list args);
167 
169 typedef enum {
171  websocket_HEADERS, /* parsing HTTP headers */
172  websocket_ACTIVE, /* active websocket connection */
173  websocket_CLOSING /* shutdown in progress */
175 
177 typedef struct _sx_websocket_conn_st {
178  http_parser parser;
184  void *frame;
186 //#endif
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 
193 #endif /* INCL_SX_PLUGINS_H */
Definition: sx.h:113
#define JABBERD2_API
Definition: mio.h:39
an environment
Definition: sx.h:378
int sx_ssl_server_addcert(sx_plugin_t p, const char *name, const char *pemfile, const char *cachain, int mode, const char *password, const char *ciphers)
args: name, pemfile, cachain, mode
Definition: ssl.c:953
a plugin
Definition: sx.h:343
JABBERD2_API int sx_ack_init(sx_env_t env, sx_plugin_t p, va_list args)
init function
Definition: ack.c:107
const char * authnid
Definition: plugins.h:126
holds the state for a single stream
Definition: sx.h:252
int(* sx_sasl_callback_t)(int cb, void *arg, void **res, sx_t s, void *cbarg)
the callback function
Definition: plugins.h:107
_sx_websocket_state_t state
Definition: plugins.h:179
struct sx_sasl_creds_st * sx_sasl_creds_t
JABBERD2_API int sx_websocket_init(sx_env_t env, sx_plugin_t p, va_list args)
args: none
Definition: websocket.c:573
const char * authzid
Definition: plugins.h:128
const char * realm
Definition: plugins.h:127
_sx_websocket_state_t
websocket state
Definition: plugins.h:169
JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args)
init function
Definition: sasl.c:855
JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, const char *appname, const char *mech, const char *user, const char *pass)
trigger for client auth
Definition: sasl.c:908
int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args)
args: name, pemfile, cachain, mode
Definition: ssl.c:904
int sx_compress_init(sx_env_t env, sx_plugin_t p, va_list args)
args: none
Definition: compress.c:328
const char * pass
Definition: plugins.h:129
pool - base node for a pool.
Definition: pool.h:80
struct _sx_websocket_conn_st * _sx_websocket_conn_t
a single conn
a single conn
Definition: plugins.h:177
#define SX_CONN_EXTERNAL_ID_MAX_COUNT
Definition: plugins.h:49
int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, const char *pemfile, const char *private_key_password)
Definition: ssl.c:1116
http_parser parser
Definition: plugins.h:178