int _s2s_check_conn_routes(s2s_t s2s, conn_t conn, const char *direction) { char *rkey; int rkeylen; conn_state_t state; time_t now, dialback_time; now = time(NULL); if(xhash_iter_first(conn->states)) do { /* retrieve state in a separate operation, as sizeof(int) != sizeof(void *) on 64-bit platforms, so passing a pointer to state in xhash_iter_get is unsafe */ xhash_iter_get(conn->states, (const char **) &rkey, &rkeylen, NULL); state = (conn_state_t) xhash_getx(conn->states, rkey, rkeylen); if (state == conn_INPROGRESS) { dialback_time = (time_t) xhash_getx(conn->states_time, rkey, rkeylen); if(now > dialback_time + s2s->check_queue) { log_write(s2s->log, LOG_NOTICE, "[%d] [%s, port=%d] dialback for %s route '%.*s' timed out", conn->fd->fd, conn->ip, conn->port, direction, rkeylen, rkey); xhash_zapx(conn->states, rkey, rkeylen); xhash_zapx(conn->states_time, rkey, rkeylen); /* stream error */ sx_error(conn->s, stream_err_CONNECTION_TIMEOUT, "dialback timed out"); /* close connection as per XMPP/RFC3920 */ sx_close(conn->s); /* indicate that we closed the connection */ return 0; } } } while(xhash_iter_next(conn->states)); /* all ok */ return 1; }
static void _router_route_unbind_walker(const char *key, int keylen, void *val, void *arg) { component_t comp = (component_t) arg; char * local_key; xhash_zapx(comp->r->log_sinks, key, keylen); local_key = (char *) malloc(keylen + 1); memcpy(local_key, key, keylen); local_key[keylen] = 0; _route_remove(comp->r->routes, local_key, comp); xhash_zapx(comp->routes, key, keylen); if(comp->r->default_route != NULL && strlen(comp->r->default_route) == keylen && strncmp(key, comp->r->default_route, keylen) == 0) { log_write(comp->r->log, LOG_NOTICE, "[%.*s] default route offline", keylen, key); free((void*)(comp->r->default_route)); comp->r->default_route = NULL; } log_write(comp->r->log, LOG_NOTICE, "[%.*s] offline", keylen, key); /* deadvertise name */ if(xhash_getx(comp->r->routes, key, keylen) == NULL) _router_advertise(comp->r, local_key, comp, 1); free(local_key); }
void xhash_zap(xht h, const char *key) { if(h == NULL || key == NULL) return; xhash_zapx(h,key,strlen(key)); }