22 #include <stringprep.h> 69 if((f = fopen(pidfile,
"w+")) == NULL) {
70 log_write(sm->
log, LOG_ERR,
"couldn't open %s for writing: %s", pidfile, strerror(errno));
74 if(fprintf(f,
"%d", pid) < 0) {
75 log_write(sm->
log, LOG_ERR,
"couldn't write to %s: %s", pidfile, strerror(errno));
82 log_write(sm->
log, LOG_INFO,
"process id is %d, written to %s", pid, pidfile);
123 if(strcmp(str,
"file") == 0)
125 else if(strcmp(str,
"syslog") == 0)
164 for(i = 0; i < elem->
nvalues; i++) {
166 strncpy(
id, elem->
values[i], 1024);
168 if (stringprep_nameprep(
id, 1024) != 0) {
169 log_write(sm->
log, LOG_ERR,
"cannot stringprep id %s, aborting",
id);
185 if(errno == ECONNREFUSED)
197 JABBER_MAIN(
"jabberd2sm",
"Jabber 2 Session Manager",
"Jabber Open Source Server: Session Manager",
"jabberd2router\0")
203 time_t pool_time = 0;
205 const char *cli_id = 0;
208 umask((mode_t) 0027);
213 #ifdef HAVE_WINSOCK2_H 216 WORD wVersionRequested;
220 wVersionRequested = MAKEWORD( 2, 2 );
222 err = WSAStartup( wVersionRequested, &wsaData );
242 sm = (
sm_t) calloc(1,
sizeof(
struct sm_st));
250 while((optchar = getopt(argc, argv,
"Dc:hi:?")) >= 0)
261 printf(
"WARN: Debugging not enabled. Ignoring -D.\n");
267 case 'h':
case '?':
default:
269 "sm - jabberd session manager (" VERSION
")\n" 270 "Usage: sm <options>\n" 272 " -c <config> config file to use [default: " CONFIG_DIR
"/sm.xml]\n" 273 " -i id Override <id> config element\n" 275 " -D Show debug output\n" 287 fputs(
"sm: couldn't load config, aborting\n", stderr);
299 strncpy(
id, sm->
id, 1024);
300 id[
sizeof(id)-1] =
'\0';
301 if (stringprep_nameprep(
id, 1024) != 0) {
302 log_write(sm->
log, LOG_ERR,
"cannot stringprep id %s, aborting", sm->
id);
313 if (sm->
st == NULL) {
314 log_write(sm->
log, LOG_ERR,
"failed to initialise one or more storage drivers, aborting");
361 log_write(sm->
log, LOG_ERR,
"failed to load SSL pemfile, SSL disabled");
370 log_write(sm->
log, LOG_ERR,
"failed to initialise SASL context, aborting");
421 if(time(NULL) > pool_time + 60) {
423 pool_time = time(NULL);
444 storage_free(sm->
st);
469 #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)
if you change these, reflect your changes in the table in error.c
config_t config_new(void)
new config structure
static void _sm_hosts_expand(sm_t sm)
static char * config_file
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)
const char * router_ciphers
password for private key if pemfile key is encrypted
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)
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
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