jabberd2  2.2.16
c2s/c2s.h
Go to the documentation of this file.
00001 /*
00002  * jabberd - Jabber Open Source Server
00003  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
00004  *                    Ryan Eatmon, Robert Norris
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 #ifdef HAVE_CONFIG_H
00022 # include <config.h>
00023 #endif
00024 
00025 #include <expat.h>
00026 
00027 #include "mio/mio.h"
00028 #include "sx/sx.h"
00029 #include "util/util.h"
00030 
00031 #ifdef HAVE_SIGNAL_H
00032 # include <signal.h>
00033 #endif
00034 #ifdef HAVE_SYS_STAT_H
00035 # include <sys/stat.h>
00036 #endif
00037 
00038 #ifdef _WIN32
00039   #ifdef _USRDLL
00040     #define DLLEXPORT  __declspec(dllexport)
00041     #define C2S_API    __declspec(dllimport)
00042   #else
00043     #define DLLEXPORT  __declspec(dllimport)
00044     #define C2S_API    __declspec(dllexport)
00045   #endif
00046 #else
00047   #define DLLEXPORT
00048   #define C2S_API
00049 #endif
00050 
00051 /* forward declarations */
00052 typedef struct host_st      *host_t;
00053 typedef struct c2s_st       *c2s_t;
00054 typedef struct bres_st      *bres_t;
00055 typedef struct sess_st      *sess_t;
00056 typedef struct authreg_st   *authreg_t;
00057 
00059 struct bres_st {
00061     jid_t               jid;
00063     char                c2s_id[44], sm_id[41];
00065     char                sm_request[41];
00066 
00067     bres_t              next;
00068 };
00069 
00074 struct sess_st {
00075     c2s_t               c2s;
00076 
00077     mio_fd_t            fd;
00078 
00079     char                skey[44];
00080 
00081     char                *smcomp; /* sm component servicing this session */
00082 
00083     char                *ip;
00084     int                 port;
00085 
00086     sx_t                s;
00087 
00089     host_t              host;
00090 
00091     rate_t              rate;
00092     int                 rate_log;
00093 
00094     rate_t              stanza_rate;
00095     int                 stanza_rate_log;
00096 
00097     time_t              last_activity;
00098     unsigned int        packet_count;
00099 
00100     /* count of bound resources */
00101     int                 bound;
00102     /* list of bound jids */
00103     bres_t              resources;
00104 
00105     int                 active;
00106 
00107     /* session related packet waiting for sm response */
00108     nad_t               result;
00109 
00110     int                 sasl_authd;     /* 1 = they did a sasl auth */
00111 };
00112 
00113 /* allowed mechanisms */
00114 #define AR_MECH_TRAD_PLAIN      (1<<0)
00115 #define AR_MECH_TRAD_DIGEST     (1<<1)
00116 
00117 struct host_st {
00119     char                *realm;
00120 
00122     char                *host_pemfile;
00123 
00125     char                *host_cachain;
00126 
00128     int                 host_verify_mode;
00129 
00131     int                 host_require_starttls;
00132 
00134     int                 ar_register_enable;
00135     char                *ar_register_instructions;
00136     char                *ar_register_oob;
00137     int                 ar_register_password;
00138 
00139 };
00140 
00141 struct c2s_st {
00143     char                *id;
00144 
00146     char                *router_ip;
00147     int                 router_port;
00148     char                *router_user;
00149     char                *router_pass;
00150     char                *router_pemfile;
00151 
00153     mio_t               mio;
00154 
00156     xht                 sessions;
00157 
00159     sx_env_t            sx_env;
00160     sx_plugin_t         sx_ssl;
00161     sx_plugin_t         sx_sasl;
00162 
00164     sx_t                router;
00165     mio_fd_t            fd;
00166 
00168     mio_fd_t            server_fd;
00169 #ifdef HAVE_SSL
00170     mio_fd_t            server_ssl_fd;
00171 #endif
00172 
00174     config_t            config;
00175 
00177     log_t               log;
00178 
00180     log_type_t          log_type;
00181     char                *log_facility;
00182     char                *log_ident;
00183 
00185     long long int       packet_count;
00186     char                *packet_stats;
00187 
00189     int                 retry_init;
00190     int                 retry_lost;
00191     int                 retry_sleep;
00192     int                 retry_left;
00193 
00195     char                *local_ip;
00196 
00198     int                 local_port;
00199 
00201     int                 local_ssl_port;
00202 
00204     char                *local_pemfile;
00205 
00207     char                *local_cachain;
00208 
00210     int                 local_verify_mode;
00211 
00213     char                *http_forward;
00214 
00216     char                *pbx_pipe;
00217     int                 pbx_pipe_fd;
00218     mio_fd_t            pbx_pipe_mio_fd;
00219 
00221     xht                 stream_redirects;
00222 
00224     int                 io_max_fds;
00225 
00227     int                 compression;
00228 
00230     int                 io_check_interval;
00231     int                 io_check_idle;
00232     int                 io_check_keepalive;
00233 
00234     time_t              next_check;
00235 
00237     char                *ar_module_name;
00238     authreg_t           ar;
00239 
00241     int                 ar_mechanisms;
00242     int                 ar_ssl_mechanisms;
00243     
00245     int                 conn_rate_total;
00246     int                 conn_rate_seconds;
00247     int                 conn_rate_wait;
00248 
00249     xht                 conn_rates;
00250 
00252     int                 byte_rate_total;
00253     int                 byte_rate_seconds;
00254     int                 byte_rate_wait;
00255 
00257     int                 stanza_rate_total;
00258     int                 stanza_rate_seconds;
00259     int                 stanza_rate_wait;
00260 
00262     int                 stanza_size_limit;
00263 
00265     access_t            access;
00266 
00268     jqueue_t            dead;
00269 
00271     jqueue_t            dead_sess;
00272 
00274     int                 started;
00275 
00277     int                 online;
00278 
00280     xht                 hosts;
00281     host_t              vhost;
00282 
00284     xht                 sm_avail;
00285 };
00286 
00287 extern sig_atomic_t c2s_lost_router;
00288 
00289 C2S_API int             c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
00290 C2S_API int             c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
00291 
00292 C2S_API void            sm_start(sess_t sess, bres_t res);
00293 C2S_API void            sm_end(sess_t sess, bres_t res);
00294 C2S_API void            sm_create(sess_t sess, bres_t res);
00295 C2S_API void            sm_delete(sess_t sess, bres_t res);
00296 C2S_API void            sm_packet(sess_t sess, bres_t res, nad_t nad);
00297 
00298 C2S_API int             bind_init(sx_env_t env, sx_plugin_t p, va_list args);
00299 
00300 C2S_API void            c2s_pbx_init(c2s_t c2s);
00301 
00302 struct authreg_st
00303 {
00304     c2s_t       c2s;
00305 
00307     void        *private;
00308 
00310     int         (*user_exists)(authreg_t ar, char *username, char *realm);
00311 
00313     int         (*get_password)(authreg_t ar, char *username, char *realm, char password[257]);
00314 
00316     int         (*check_password)(authreg_t ar, char *username, char *realm, char password[257]);
00317 
00319     int         (*set_password)(authreg_t ar, char *username, char *realm, char password[257]);
00320 
00322     int         (*create_user)(authreg_t ar, char *username, char *realm);
00323     int         (*delete_user)(authreg_t ar, char *username, char *realm);
00324 
00325     void        (*free)(authreg_t ar);
00326 
00327     /* Additions at the end - to preserve offsets for existing modules */
00328 
00330     int               (*user_authz_allowed)(authreg_t ar, char *username, char *realm, char *requested_user);
00331 };
00332 
00334 C2S_API authreg_t   authreg_init(c2s_t c2s, char *name);
00335 
00337 C2S_API void        authreg_free(authreg_t ar);
00338 
00340 typedef int (*ar_module_init_fn)(authreg_t);
00341 
00343 C2S_API int         authreg_process(c2s_t c2s, sess_t sess, nad_t nad);
00344 
00345 /*
00346 int     authreg_user_exists(authreg_t ar, char *username, char *realm);
00347 int     authreg_get_password(authreg_t ar, char *username, char *realm, char password[257]);
00348 int     authreg_check_password(authreg_t ar, char *username, char *realm, char password[257]);
00349 int     authreg_set_password(authreg_t ar, char *username, char *realm, char password[257]);
00350 int     authreg_create_user(authreg_t ar, char *username, char *realm);
00351 int     authreg_delete_user(authreg_t ar, char *username, char *realm);
00352 void    authreg_free(authreg_t ar);
00353 */
00354 
00355 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
00356 union xhashv
00357 {
00358   void **val;
00359   char **char_val;
00360   sess_t *sess_val;
00361 };
00362 
00363 // Data for stream redirect errors
00364 typedef struct stream_redirect_st
00365 {
00366     char *to_address;
00367     char *to_port;
00368 } *stream_redirect_t;
00369