58 if((f = fopen(pidfile,
"w+")) == NULL) {
59 log_write(r->
log, LOG_ERR,
"couldn't open %s for writing: %s", pidfile, strerror(errno));
63 if(fprintf(f,
"%d", pid) < 0) {
64 log_write(r->
log, LOG_ERR,
"couldn't write to %s: %s", pidfile, strerror(errno));
71 log_write(r->
log, LOG_INFO,
"process id is %d, written to %s", pid, pidfile);
77 const char *str, *ip, *mask, *name, *target;
91 if(strcmp(str,
"file") == 0)
93 else if(strcmp(str,
"syslog") == 0)
145 if(str == NULL || strcmp(str,
"deny,allow") != 0)
153 for(i = 0; i < elem->
nvalues; i++)
156 mask =
j_attr((
const char **) elem->
attrs[i],
"mask");
162 mask =
"255.255.255.255";
171 for(i = 0; i < elem->
nvalues; i++)
174 mask =
j_attr((
const char **) elem->
attrs[i],
"mask");
180 mask =
"255.255.255.255";
189 for(i = 0; i < elem->
nvalues; i++) {
190 name =
j_attr((
const char **) elem->
attrs[i],
"name");
191 target =
j_attr((
const char **) elem->
attrs[i],
"target");
193 if(name == NULL || target == NULL)
216 static char buf[1024];
221 strcpy(buf,
"jabberd-router");
245 if(pass == NULL || strcmp(creds->
pass, pass) != 0)
262 if (strcasecmp((
char *)arg,
"DIGEST-MD5")==0)
297 JABBER_MAIN(
"jabberd2router",
"Jabber 2 Router",
"Jabber Open Source Server: Router", NULL)
306 const char *cli_id = 0;
309 time_t pool_time = 0;
313 umask((mode_t) 0027);
318 #ifdef HAVE_WINSOCK2_H 321 WORD wVersionRequested;
325 wVersionRequested = MAKEWORD( 2, 2 );
327 err = WSAStartup( wVersionRequested, &wsaData );
351 config_file = CONFIG_DIR
"/router.xml";
354 while((optchar = getopt(argc, argv,
"Dc:hi:?")) >= 0)
359 config_file = optarg;
365 printf(
"WARN: Debugging not enabled. Ignoring -D.\n");
371 case 'h':
case '?':
default:
373 "router - jabberd router (" VERSION
")\n" 374 "Usage: router <options>\n" 376 " -c <config> config file to use [default: " CONFIG_DIR
"/router.xml]\n" 377 " -i id Override <id> config element\n" 379 " -D Show debug output\n" 391 fputs(
"router: couldn't load config, aborting\n", stderr);
427 log_write(r->
log, LOG_ERR,
"failed to load SSL pemfile, SSL disabled");
434 log_write(r->
log, LOG_ERR,
"failed to initialise SASL context, aborting");
495 if(time(NULL) > pool_time + 60) {
497 pool_time = time(NULL);
528 if (1 > close_wait_max--)
break;
596 #ifdef HAVE_WINSOCK2_H sx_env_t sx_env
sx environment
jqueue_t closefd
list of mio_fd_t waiting to be closed
xht routes
valid routes, key is route name (packet "to" address), var is component_t
struct router_st * router_t
#define sx_sasl_cb_CHECK_MECH
xht aci
access control lists
static void router_signal_hup(int signum)
jqueue_t deadroutes
list of routes_t waiting to be cleaned up
int access_deny(access_t access, const char *ip, const char *mask)
static sig_atomic_t router_logrotate
int config_load_with_id(config_t c, const char *file, const char *id)
turn an xml file into a config hash
int filter_load(router_t r)
void config_free(config_t c)
cleanup
static void _router_pidfile(router_t r)
store the process id
mio_t mio_new(int maxfd)
create/free the mio subsytem
access_t access_new(int order)
#define mio_run(m, timeout)
give some cpu time to mio to check it's sockets, 0 is non-blocking
int jqueue_size(jqueue_t q)
void log_write(log_t log, int level, const char *msgfmt,...)
void routes_free(routes_t routes)
config_t config_new(void)
new config structure
static char * config_file
static void router_signal_usr1(int signum)
const char * local_private_key_password
access_t access
access controls
void sx_raw_write(sx_t s, const char *buf, int len)
app version
int j_atoi(const char *a, int def)
int message_logging_enabled
simple message logging
int xhash_iter_next(xht h)
sx_env_t sx_env_new(void)
void rate_free(rate_t rt)
char * config_get_attr(config_t c, const char *key, int num, const char *attr)
get an attr for this value
void jqueue_free(jqueue_t q)
time_t last_activity
timestamps for idle timeouts
void access_free(access_t access)
mio_fd_t fd
listening socket
#define MIO_ERROR
all MIO related routines should use those for error reporting
#define sx_sasl_cb_CHECK_AUTHZID
sx_plugin_t sx_env_plugin(sx_env_t env, sx_plugin_init_t init,...)
load a plugin into the environment
holds the state for a single stream
void set_debug_log_from_config(config_t c)
const char * local_pemfile
const char * local_ciphers
struct sx_sasl_creds_st * sx_sasl_creds_t
static void router_signal(int signum)
#define mio_listen(m, port, sourceip, app, arg)
for creating a new listen socket in this mio (returns new fd or <0)
static void router_signal_usr2(int signum)
jqueue_t dead
list of sx_t waiting to be cleaned up
alias_t aliases
configured aliases
int xhash_iter_get(xht h, const char **key, int *keylen, void **val)
int byte_rate_total
default byte rates (karma)
mio_fd_t fd
file descriptor
JABBER_MAIN("jabberd2c2s","Jabber 2 C2S","Jabber Open Source Server: Client to Server","jabberd2router\0")
jsighandler_t * jabber_signal(int signo, jsighandler_t *func)
void filter_unload(router_t r)
filter manager
int router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg)
JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args)
init function
config_elem_t config_get(config_t c, const char *key)
get the config element for this key
#define sx_sasl_cb_GET_REALM
#define mio_app(m, fd, app, arg)
re-set the app handler
void * jqueue_pull(jqueue_t q)
int xhash_iter_first(xht h)
iteration
static int _router_sx_sasl_callback(int cb, void *arg, void **res, sx_t s, void *cbarg)
const char * log_facility
jqueue_t jqueue_new(void)
xht log_sinks
log sinks, key is route name, var is component_t
int check_interval
time checks
void user_table_unload(router_t r)
void set_debug_flag(int v)
int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args)
args: name, pemfile, cachain, mode
int access_allow(access_t access, const char *ip, const char *mask)
static void _router_time_checks(router_t r)
static void _router_config_expand(router_t r)
pull values out of the config file
void * xhash_get(xht h, const char *key)
#define mio_close(m, fd)
request that mio close this fd
char * j_attr(const char **atts, const char *attr)
log_t log_new(log_type_t type, const char *ident, const char *facility)
int user_table_load(router_t r)
user table manager
const char * config_get_one(config_t c, const char *key, int num)
get config value n for this key
log_type_t log_type
log data
int conn_rate_total
connection rates
void sx_env_free(sx_env_t env)
const char * local_secret
int io_max_fds
max file descriptors
xht components
attached components, key is 'ip:port', var is component_t
struct alias_st * alias_t
#define sx_sasl_cb_CHECK_PASS
const char * local_ip
how we listen for stuff
const char * message_logging_file
#define sx_sasl_cb_GET_PASS
static sig_atomic_t router_shutdown
void aci_unload(xht aci)
unload aci table