22 #include <stringprep.h>
46 log_write(sm->
log, LOG_NOTICE,
"HUP handled. reloading modules...");
86 if((f = fopen(pidfile,
"w+")) == NULL) {
87 log_write(sm->
log, LOG_ERR,
"couldn't open %s for writing: %s", pidfile, strerror(errno));
91 if(fprintf(f,
"%d", pid) < 0) {
92 log_write(sm->
log, LOG_ERR,
"couldn't write to %s: %s", pidfile, strerror(errno));
99 log_write(sm->
log, LOG_INFO,
"process id is %d, written to %s", pid, pidfile);
139 if(strcmp(str,
"file") == 0)
141 else if(strcmp(str,
"syslog") == 0)
180 for(i = 0; i < elem->
nvalues; i++) {
182 strncpy(
id, elem->
values[i], 1024);
184 if (stringprep_nameprep(
id, 1024) != 0) {
185 log_write(sm->
log, LOG_ERR,
"cannot stringprep id %s, aborting",
id);
201 if(errno == ECONNREFUSED)
213 JABBER_MAIN(
"jabberd2sm",
"Jabber 2 Session Manager",
"Jabber Open Source Server: Session Manager",
"jabberd2router\0")
219 time_t pool_time = 0;
221 const char *cli_id = 0;
224 umask((mode_t) 0027);
229 #ifdef HAVE_WINSOCK2_H
232 WORD wVersionRequested;
236 wVersionRequested = MAKEWORD( 2, 2 );
238 err = WSAStartup( wVersionRequested, &wsaData );
258 sm = (
sm_t) calloc(1,
sizeof(
struct sm_st));
266 while((optchar = getopt(argc, argv,
"Dc:hi:?")) >= 0)
277 printf(
"WARN: Debugging not enabled. Ignoring -D.\n");
283 case 'h':
case '?':
default:
285 "sm - jabberd session manager (" VERSION
")\n"
286 "Usage: sm <options>\n"
288 " -c <config> config file to use [default: " CONFIG_DIR
"/sm.xml]\n"
289 " -i id Override <id> config element\n"
291 " -D Show debug output\n"
303 fputs(
"sm: couldn't load config, aborting\n", stderr);
315 strncpy(
id, sm->
id, 1024);
316 id[
sizeof(id)-1] =
'\0';
317 if (stringprep_nameprep(
id, 1024) != 0) {
318 log_write(sm->
log, LOG_ERR,
"cannot stringprep id %s, aborting", sm->
id);
329 if (sm->
st == NULL) {
330 log_write(sm->
log, LOG_ERR,
"failed to initialise one or more storage drivers, aborting");
377 log_write(sm->
log, LOG_ERR,
"failed to load SSL pemfile, SSL disabled");
386 log_write(sm->
log, LOG_ERR,
"failed to initialise SASL context, aborting");
437 if(time(NULL) > pool_time + 60) {
439 pool_time = time(NULL);
460 storage_free(sm->
st);
485 #ifdef HAVE_WINSOCK2_H
const char * log_facility
syslog facility (local0 - local7)
data structures and prototypes for the session manager
int retry_init
number of times to try connecting to the router at startup
int config_load_with_id(config_t c, const char *file, const char *id)
turn an xml file into a config hash
const char * id
component id
static sig_atomic_t sm_shutdown
static void _sm_signal_usr1(int signum)
void config_free(config_t c)
cleanup
mio_t mio_new(int maxfd)
create/free the mio subsytem
#define mio_run(m, timeout)
give some cpu time to mio to check it's sockets, 0 is non-blocking
static void _sm_signal(int signum)
config_t config
config context
void log_write(log_t log, int level, const char *msgfmt,...)
void sm_c2s_action(sess_t dest, const char *action, const char *target)
send a new action route
sx_t sx_new(sx_env_t env, int tag, sx_callback_t cb, void *arg)
config_t config_new(void)
new config structure
static void _sm_hosts_expand(sm_t sm)
static char * config_file
holder for the config hash and nad
int j_atoi(const char *a, int def)
int xhash_iter_next(xht h)
static void _sm_pidfile(sm_t sm)
store the process id
mm_t mm_new(sm_t sm)
allocate a module manager instance, and loads the modules
xht sessions
pointers to all connected sessions (key is random sm id)
sx_env_t sx_env_new(void)
#define mio_connect(m, port, hostip, srcip, app, arg)
for creating a new socket connected to this ip:port (returns new fd or <0, use mio_read/write first) ...
sx_plugin_t sx_ssl
SX SSL plugin.
xht users
pointers to currently loaded users (key is user@domain)
static void _sm_signal_hup(int signum)
char * config_get_attr(config_t c, const char *key, int num, const char *attr)
get an attr for this value
#define MIO_ERROR
all MIO related routines should use those for error reporting
static void _sm_config_expand(sm_t sm)
pull values out of the config file
int retry_left
number of tries left before failure
void sess_end(sess_t sess)
sx_plugin_t sx_env_plugin(sx_env_t env, sx_plugin_init_t init,...)
load a plugin into the environment
sx_t router
SX of router connection.
xht xmlns_refcount
ref-counting for modules namespaces
void sx_client_init(sx_t s, unsigned int flags, const char *ns, const char *to, const char *from, const char *version)
int sm_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg)
void set_debug_log_from_config(config_t c)
storage_t st
storage subsystem
session manager global context
void xhash_put(xht h, const char *key, void *val)
static sig_atomic_t sm_logrotate
int sm_sx_callback(sx_t s, sx_event_t e, void *data, void *arg)
our master callback
log_type_t log_type
log type
const char * router_private_key_password
void mm_free(mm_t mm)
free a mm instance
int xhash_iter_get(xht h, const char **key, int *keylen, void **val)
void sm_signature(sm_t sm, const char *str)
this is gratuitous, but apache gets one, so why not?
const char * log_ident
log identifier
JABBER_MAIN("jabberd2c2s","Jabber 2 C2S","Jabber Open Source Server: Client to Server","jabberd2router\0")
jsighandler_t * jabber_signal(int signo, jsighandler_t *func)
const char * router_user
username to authenticate to the router as
void feature_register(sm_t sm, const char *feature)
register a feature
const char * router_pass
password to authenticate to the router with
sx_env_t sx_env
SX environment.
int retry_lost
number of times to try reconnecting to the router if the connection drops
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
There is one instance of this struct per user who is logged in to this c2s instance.
char signature[2048]
server signature
const char * router_ip
ip to connect to the router at
int xhash_iter_first(xht h)
iteration
mio_fd_t fd
file descriptor of router connection
static void _sm_signal_usr2(int signum)
const char * router_pemfile
name of file containing a SSL certificate & key for channel to the router
void set_debug_flag(int v)
mio_t mio
password for private key if pemfile key is encrypted
int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args)
args: name, pemfile, cachain, mode
sig_atomic_t sm_lost_router
int config_load(config_t c, const char *file)
turn an xml file into a config hash
pool_t xhash_pool(xht h)
get our pool
int retry_sleep
sleep interval between retries
char * pstrdup(pool_t p, const char *src)
XXX efficient: move this to const char * and then loop throug the existing heaps to see if src is wit...
#define mio_close(m, fd)
request that mio close this fd
xht acls
access control lists (key is list name, value is jid_t list)
char * j_attr(const char **atts, const char *attr)
log_t log_new(log_type_t type, const char *ident, const char *facility)
const char * config_get_one(config_t c, const char *key, int num)
get config value n for this key
xht xmlns
index of namespaces (for iq sub-namespace in pkt_t)
int query_rate_total
Database query rate limits.
void sx_env_free(sx_env_t env)
int router_port
port to connect to the router at
sx_plugin_t sx_sasl
SX SASL plugin.
static int _sm_router_connect(sm_t sm)
void aci_unload(xht aci)
unload aci table
xht features
feature index (key is feature string