29 int len, ns, elem, attr, i;
106 log_write(s2s->
log, LOG_NOTICE,
"connection to router established");
135 if(
NAD_NURI_L(nad,
NAD_ENS(nad, 0)) != strlen(
uri_STREAMS) || strncmp(
uri_STREAMS,
NAD_NURI(nad,
NAD_ENS(nad, 0)), strlen(
uri_STREAMS)) != 0 ||
NAD_ENAME_L(nad, 0) != 8 || strncmp(
"features",
NAD_ENAME(nad, 0), 8) != 0) {
136 log_debug(
ZONE,
"got a non-features packet on an unauth'd stream, dropping");
152 log_write(s2s->
log, LOG_NOTICE,
"unable to establish encrypted session with router");
170 if(
NAD_NURI_L(nad,
NAD_ENS(nad, 0)) != strlen(
uri_COMPONENT) || strncmp(
uri_COMPONENT,
NAD_NURI(nad,
NAD_ENS(nad, 0)), strlen(
uri_COMPONENT)) != 0 ||
NAD_ENAME_L(nad, 0) != 4 || strncmp(
"bind",
NAD_ENAME(nad, 0), 4)) {
171 log_debug(
ZONE,
"got a packet from router, but we're not online, dropping");
189 if(s2s->server_fd == NULL) {
190 log_write(s2s->log, LOG_ERR,
"[%s, port=%d] failed to listen", s2s->local_ip, s2s->local_port);
193 log_write(s2s->log, LOG_NOTICE,
"[%s, port=%d] listening for connections", s2s->local_ip, s2s->local_port);
199 log_write(s2s->
log, LOG_NOTICE,
"ready for connections", s2s->
id);
229 log_debug(
ZONE,
"dropping unknown or invalid packet for s2s component proper");
299 ioctl(fd->
fd, FIONREAD, &nbytes);
313 log_write(s2s->
log, LOG_NOTICE,
"connection to router closed");
struct _stanza_error_st _stanza_errors[]
if you change these, reflect your changes in the defines in util.h
nad_t nad_new(void)
create a new nad
int nad_append_attr(nad_t nad, int ns, const char *name, const char *val)
attach new attr to the last elem
sx_t router
router's conn
#define sx_nad_write(s, nad)
const char * local_ip
ip/port to listen on
int s2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg)
jid_t jid_new(const char *id, int len)
make a new jid
int nad_find_attr(nad_t nad, unsigned int elem, int ns, const char *name, const char *val)
get a matching attr on this elem, both name and optional val
int started
this is true if we've connected to the router at least once
void nad_set_attr(nad_t nad, unsigned int elem, int ns, const char *name, const char *val, int vallen)
create, update, or zap any matching attr on this elem
void log_write(log_t log, int level, const char *msgfmt,...)
error info for event_ERROR
int s2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg)
our master callback
int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
bring a new namespace into scope
mio_action_t
these are the actions and a handler type assigned by the applicaiton using mio
int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
create a new elem on the list
void nad_free(nad_t nad)
free that nad
#define mio_read(m, fd)
process read events for this fd
#define MIO_ERROR
all MIO related routines should use those for error reporting
int sx_can_read(sx_t s)
we can read
holds the state for a single stream
jid_t from
packet addressing (not used for routing)
int online
true if we're bound in the router
packet summary data wrapper
#define NAD_ENAME_L(N, E)
#define NAD_NURI_L(N, NS)
nad_t nad
nad of the entire packet
#define stanza_err_BAD_REQUEST
#define mio_listen(m, port, sourceip, app, arg)
for creating a new listen socket in this mio (returns new fd or <0)
nad_t stanza_tofrom(nad_t nad, int elem)
flip the to and from attributes on this elem
int in_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg)
struct pkt_st * pkt_t
packet summary data wrapper
#define stanza_err_REMOTE_SERVER_NOT_FOUND
const char * router_pemfile
nad_t stanza_error(nad_t nad, int elem, int err)
error the packet
struct _sx_buf_st * sx_buf_t
utility: buffer
mio_fd_t server_fd
listening sockets
JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, const char *appname, const char *mech, const char *user, const char *pass)
trigger for client auth
int nad_find_elem(nad_t nad, unsigned int elem, int ns, const char *name, int depth)
locate the next elem at a given depth with an optional matching name
sig_atomic_t s2s_lost_router
const char * router_private_key_password
const char * id
our id (hostname) with the router
#define mio_close(m, fd)
request that mio close this fd
#define mio_write(m, fd)
mio should try the write action on this fd now
sx_event_t
things that can happen
int out_packet(s2s_t s2s, pkt_t pkt)
send a packet out
int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, const char *pemfile, const char *private_key_password)
int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope