67 socklen_t namelen =
sizeof(sa);
68 int port, nbytes, flags = 0;
75 ioctl(fd->
fd, FIONREAD, &nbytes);
114 getpeername(fd->
fd, (
struct sockaddr *) &sa, &namelen);
117 log_write(s2s->
log, LOG_NOTICE,
"[%d] [%s, port=%d] incoming connection", fd->
fd, (
char *) data, port);
249 if (in->
key != NULL) {
254 free((
void*)in->
key);
257 in->
key = strdup(s->
id);
283 if(strncmp(
"result",
NAD_ENAME(nad, 0), 6) == 0) {
288 if(strncmp(
"verify",
NAD_ENAME(nad, 0), 6) == 0) {
322 log_debug(
ZONE,
"they sent us a non-jabber looking packet, dropping it");
330 log_debug(
ZONE,
"missing or invalid from on incoming packet, attr is %d", attr);
336 log_write(in->
s2s->
log, LOG_NOTICE,
"received a packet not from a whitelisted domain %s, dropping it", from->
domain);
348 if (in->
fd != NULL) {
369 log_debug(
ZONE,
"missing or invalid from on db result packet");
376 log_debug(
ZONE,
"missing or invalid to on db result packet");
384 log_write(in->
s2s->
log, LOG_NOTICE,
"[%d] [%s, port=%d] received dialback auth request for route '%s'", in->
fd->
fd, in->
ip, in->
port, rkey);
388 log_write(in->
s2s->
log, LOG_NOTICE,
"[%d] [%s, port=%d] route '%s' is already valid: sending valid", in->
fd->
fd, in->
ip, in->
port, rkey);
410 log_write(in->
s2s->
log, LOG_NOTICE,
"[%d] [%s, port=%d] no dialback key given with db result packet", in->
fd->
fd, in->
ip, in->
port, rkey);
418 log_debug(
ZONE,
"requesting verification for route %s", rkey);
459 char *id, *dbkey, *type;
463 log_debug(
ZONE,
"missing or invalid from on db verify packet");
470 log_debug(
ZONE,
"missing or invalid to on db verify packet");
494 id = (
char *) malloc(
sizeof(
char) * (
NAD_AVAL_L(nad, attr) + 1));
502 log_debug(
ZONE,
"valid dialback key %s, verify succeeded", dbkey);
505 log_debug(
ZONE,
"invalid dialback key %s, verify failed", dbkey);
509 log_write(in->
s2s->
log, LOG_NOTICE,
"[%d] [%s, port=%d] checking dialback verification from %s: sending %s", in->
fd->
fd, in->
ip, in->
port, from->
domain, type);
532 int elem, attr, ns, sns;
538 log_debug(
ZONE,
"missing or invalid from on incoming packet");
557 log_write(in->
s2s->
log, LOG_NOTICE,
"[%d] [%s, port=%d] dropping packet on unvalidated route: '%s'", in->
fd->
fd, in->
ip, in->
port, rkey);
569 log_debug(
ZONE,
"incoming packet on valid route, preparing it for the router");
589 if(ns >= 0 || nad->
elems[0].
ns < 0) {
591 for(elem = 0; elem < nad->
ecur; elem++)
#define INET6_ADDRSTRLEN
maximum length of the string representation of an IPv6 address
struct nad_elem_st * elems
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
unsigned int packet_count
char ip[INET6_ADDRSTRLEN+1]
#define NAD_CDATA_L(N, E)
#define sx_nad_write(s, nad)
jid_t jid_new(const char *id, int len)
make a new jid
jqueue_t dead
list of sx_t on the way out
void nad_append_cdata(nad_t nad, const char *cdata, int len, int depth)
append new cdata to the last elem
void log_write(log_t log, int level, const char *msgfmt,...)
error info for event_ERROR
xht in_accept
incoming conns prior to stream initiation (key is ip/port)
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
int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
bring a new namespace into scope
void sx_server_init(sx_t s, unsigned int flags)
xht states
states of outgoing dialbacks (key is local/remote)
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
void nad_wrap_elem(nad_t nad, int elem, int ns, const char *name)
wrap an element with another element
long long int packet_count
packet counter
#define SX_COMPRESS_OFFER
#define mio_read(m, fd)
process read events for this fd
void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen)
create, update, or zap any matching attr on this elem
#define MIO_ERROR
all MIO related routines should use those for error reporting
char * s2s_route_key(pool_t p, const char *local, const char *remote)
generate a local/remote route key
sx_env_t sx_env
sx environment
int sx_can_read(sx_t s)
we can read
int compression
enable Stream Compression
int stanza_size_limit
maximum stanza size
holds the state for a single stream
jid_t from
packet addressing (not used for routing)
int j_inet_getport(struct sockaddr_storage *sa)
get the port number out of a struct sockaddr_storage
char * s2s_db_key(pool_t p, const char *secret, const char *remote, const char *id)
generate a dialback key
packet summary data wrapper
#define NAD_ENAME_L(N, E)
void jqueue_push(jqueue_t q, void *data, int priority)
#define NAD_NURI_L(N, NS)
nad_t nad
nad of the entire packet
void jid_free(jid_t jid)
free a jid
int s2s_domain_in_whitelist(s2s_t s2s, const char *in_domain)
jqueue_t dead_conn
list of conn_t on the way out
void xhash_put(xht h, const char *key, void *val)
#define SX_SSL_STARTTLS_OFFER
xht states_time
time of the last state change (key is local/remote)
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
const char * local_secret
dialback secret
void xhash_zap(xht h, const char *key)
struct _sx_buf_st * sx_buf_t
utility: buffer
mio_fd_t server_fd
listening sockets
static void _in_verify(conn_t in, nad_t nad)
validate their key
#define mio_app(m, fd, app, arg)
re-set the app handler
static void _in_result(conn_t in, nad_t nad)
auth requests
int nad_find_namespace(nad_t nad, int elem, const char *uri, const char *prefix)
get a matching ns on this elem, both uri and optional prefix
static void _in_packet(conn_t in, nad_t nad)
they're trying to send us something
pool_t xhash_pool(xht h)
get our pool
const char * id
our id (hostname) with the router
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...
xht in
incoming conns (key is stream id)
void * xhash_get(xht h, const char *key)
#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
int require_tls
Apple security options.
static int _in_sx_callback(sx_t s, sx_event_t e, void *data, void *arg)
sx_event_t
things that can happen
int nad_find_attr(nad_t nad, int elem, int ns, const char *name, const char *val)
get a matching attr on this elem, both name and optional val
int out_packet(s2s_t s2s, pkt_t pkt)
send a packet out