jabberd2
2.2.16
|
00001 /* 00002 * jabberd - Jabber Open Source Server 00003 * Copyright (c) 2002-2007 Jeremie Miller, Thomas Muldowney, 00004 * Ryan Eatmon, Robert Norris, Tomasz Sterna 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 00019 */ 00020 00021 #ifndef INCL_SX_PLUGINS_H 00022 #define INCL_SX_PLUGINS_H 00023 00025 #define SX_SSL_WRAPPER (1<<0) 00026 #define SX_SSL_STARTTLS_OFFER (1<<1) 00027 #define SX_SSL_STARTTLS_REQUIRE (1<<2) 00029 #define SX_SASL_OFFER (1<<3) 00031 #define SX_COMPRESS_WRAPPER (1<<4) 00032 #define SX_COMPRESS_OFFER (1<<5) 00033 00034 00036 #define SX_SSL_MAGIC (0x01) 00037 00038 00040 /* prefix 0x0. is taken by sx core errors in sx.h */ 00041 #define SX_ERR_SSL (0x010) 00042 #define SX_ERR_STARTTLS_FAILURE (0x011) 00043 00044 #define SX_ERR_COMPRESS (0x020) 00045 #define SX_ERR_COMPRESS_FAILURE (0x021) 00046 00047 00048 #define SX_CONN_EXTERNAL_ID_MAX_COUNT 8 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 00055 /* SSL plugin */ 00056 #ifdef HAVE_SSL 00057 00058 #include <openssl/md5.h> 00059 #include <openssl/ssl.h> 00060 #include <openssl/err.h> 00061 #include <openssl/x509v3.h> 00062 00063 00065 JABBERD2_API int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args); 00066 00068 JABBERD2_API int sx_ssl_server_addcert(sx_plugin_t p, char *name, char *pemfile, char *cachain, int mode); 00069 00071 JABBERD2_API int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, char *pemfile); 00072 00073 /* previous states */ 00074 #define SX_SSL_STATE_NONE (0) 00075 #define SX_SSL_STATE_WANT_READ (1) 00076 #define SX_SSL_STATE_WANT_WRITE (2) 00077 #define SX_SSL_STATE_ERROR (3) 00078 00080 typedef struct _sx_ssl_conn_st { 00081 /* id and ssf for sasl external auth */ 00082 char *external_id[SX_CONN_EXTERNAL_ID_MAX_COUNT]; 00083 00084 SSL *ssl; 00085 00086 BIO *wbio, *rbio; 00087 00088 jqueue_t wq; 00089 00090 int last_state; 00091 00092 char *pemfile; 00093 } *_sx_ssl_conn_t; 00094 00095 #endif /* HAVE_SSL */ 00096 00097 00098 /* SASL plugin */ 00099 00101 JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args); 00102 00104 typedef int (*sx_sasl_callback_t)(int cb, void *arg, void **res, sx_t s, void *cbarg); 00105 00106 /* callbacks */ 00107 #define sx_sasl_cb_GET_REALM (0x00) 00108 #define sx_sasl_cb_GET_PASS (0x01) 00109 #define sx_sasl_cb_CHECK_PASS (0x02) 00110 #define sx_sasl_cb_CHECK_AUTHZID (0x03) 00111 #define sx_sasl_cb_GEN_AUTHZID (0x04) 00112 #define sx_sasl_cb_CHECK_MECH (0x05) 00113 00114 /* error codes */ 00115 #define sx_sasl_ret_OK (0) 00116 #define sx_sasl_ret_FAIL (1) 00117 00119 JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, char *appname, char *mech, char *user, char *pass); 00120 00121 /* for passing auth data to callback */ 00122 typedef struct sx_sasl_creds_st { 00123 const char *authnid; 00124 const char *realm; 00125 const char *authzid; 00126 const char *pass; 00127 } *sx_sasl_creds_t; 00128 00129 00130 /* Stream Compression plugin */ 00131 #ifdef HAVE_LIBZ 00132 00133 #include <zlib.h> 00134 00136 JABBERD2_API int sx_compress_init(sx_env_t env, sx_plugin_t p, va_list args); 00137 00138 /* allocation chunk for decompression */ 00139 #define SX_COMPRESS_CHUNK 16384 00140 00142 typedef struct _sx_compress_conn_st { 00143 /* zlib streams for deflate() and inflate() */ 00144 z_stream wstrm, rstrm; 00145 00146 /* buffers for compressed and decompressed data */ 00147 sx_buf_t wbuf, rbuf; 00148 00149 } *_sx_compress_conn_t; 00150 00151 #endif /* HAVE_LIBZ */ 00152 00153 00154 #ifdef ENABLE_EXPERIMENTAL 00155 00156 /* Stanza Acknowledgements plugin */ 00158 JABBERD2_API int sx_ack_init(sx_env_t env, sx_plugin_t p, va_list args); 00159 00160 /* My IP Address plugin */ 00162 JABBERD2_API int sx_address_init(sx_env_t env, sx_plugin_t p, va_list args); 00163 00164 #endif /* ENABLE_EXPERIMENTAL */ 00165 00166 00167 #ifdef __cplusplus 00168 } 00169 #endif 00170 00171 00172 #endif /* INCL_SX_PLUGINS_H */