jabberd2  2.2.16
router/router.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 
00036 #ifdef HAVE_CONFIG_H
00037 # include <config.h>
00038 #endif
00039 
00040 #include "sx/sx.h"
00041 #include "mio/mio.h"
00042 #include "util/util.h"
00043 
00044 #ifdef HAVE_SIGNAL_H
00045 # include <signal.h>
00046 #endif
00047 #ifdef HAVE_SYS_STAT_H
00048 # include <sys/stat.h>
00049 #endif
00050 
00051 typedef struct router_st    *router_t;
00052 typedef struct component_st *component_t;
00053 typedef struct routes_st    *routes_t;
00054 typedef struct alias_st     *alias_t;
00055 
00056 typedef struct acl_s *acl_t;
00057 struct acl_s {
00058     int error;
00059     char *redirect;
00060     int redirect_len;
00061     char *what;
00062     char *from;
00063     char *to;
00064     int log;
00065     acl_t next;
00066 };
00067 
00068 struct router_st {
00070     char                *id;
00071 
00073     config_t            config;
00074 
00076     xht                 users;
00077     time_t              users_load;
00078 
00080     acl_t               filter;
00081     time_t              filter_load;
00082 
00084     log_t               log;
00085 
00087     log_type_t          log_type;
00088     char                *log_facility;
00089     char                *log_ident;
00090 
00092     char                *local_ip;
00093     int                 local_port;
00094     char                *local_secret;
00095     char                *local_pemfile;
00096 
00098     int                 io_max_fds;
00099 
00101     access_t            access;
00102 
00104     int                 conn_rate_total;
00105     int                 conn_rate_seconds;
00106     int                 conn_rate_wait;
00107 
00108     xht                 conn_rates;
00109 
00111     int                 byte_rate_total;
00112     int                 byte_rate_seconds;
00113     int                 byte_rate_wait;
00114 
00116     sx_env_t            sx_env;
00117     sx_plugin_t         sx_ssl;
00118     sx_plugin_t         sx_sasl;
00119 
00121     mio_t               mio;
00122 
00124     mio_fd_t            fd;
00125 
00127     int                 check_interval;
00128     int                 check_keepalive;
00129 
00130     time_t              next_check;
00131 
00133     xht                 components;
00134 
00136     xht                 routes;
00137 
00139     char                *default_route;
00140 
00142     xht                 log_sinks;
00143 
00145     alias_t             aliases;
00146 
00148     xht                 aci;
00149 
00151     jqueue_t            dead;
00152 
00154     jqueue_t            closefd;
00155 
00157     jqueue_t            deadroutes;
00158 
00160     int message_logging_enabled;
00161     char *message_logging_file;
00162 };
00163 
00165 struct component_st {
00166     router_t            r;
00167 
00169     mio_fd_t            fd;
00170 
00172     char                ip[INET6_ADDRSTRLEN];
00173     int                 port;
00174 
00176     char                ipport[INET6_ADDRSTRLEN + 6];
00177 
00179     sx_t                s;
00180 
00182     rate_t              rate;
00183     int                 rate_log;
00184 
00186     xht                 routes;
00187 
00189     int                 legacy;
00190 
00192     jqueue_t            tq;
00193 
00195     time_t              last_activity;
00196 };
00197 
00199 typedef enum {
00200     route_SINGLE = 0x00,         
00201     route_MULTI_TO = 0x10,       
00202     route_MULTI_FROM = 0x11,     
00203 } route_type_t;
00204 
00205 struct routes_st
00206 {
00207     char                *name;
00208     route_type_t        rtype;
00209     component_t         *comp;
00210     int                 ncomp;
00211 };
00212 
00213 struct alias_st {
00214     char                *name;
00215     char                *target;
00216 
00217     alias_t             next;
00218 };
00219 
00220 int     router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
00221 void    router_sx_handshake(sx_t s, sx_buf_t buf, void *arg);
00222 
00223 xht     aci_load(router_t r);
00224 void    aci_unload(xht aci);
00225 int     aci_check(xht acls, const char *type, const char *name);
00226 
00227 int     user_table_load(router_t r);
00228 void    user_table_unload(router_t r);
00229 
00230 int     filter_load(router_t r);
00231 void    filter_unload(router_t r);
00232 int     filter_packet(router_t r, nad_t nad);
00233 
00234 int     message_log(nad_t nad, router_t r, const unsigned char *msg_from, const unsigned char *msg_to);
00235 
00236 void routes_free(routes_t routes);
00237 
00238 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
00239 union xhashv
00240 {
00241   void **val;
00242   char **char_val;
00243   component_t *comp_val;
00244   rate_t *rt_val;
00245 };