예제 #1
0
파일: uxpoll.c 프로젝트: gdh1995/putty
void pollwrap_clear(pollwrapper *pw)
{
    pw->nfd = 0;
    for (pollwrap_fdtopos *f2p;
         (f2p = delpos234(pw->fdtopos, 0)) != NULL ;)
        sfree(f2p);
}
예제 #2
0
/**
 * check for expired connections
 */
void xj_worker_check_jcons(xj_wlist jwl, xj_jcon_pool jcp, int ltime, fd_set *pset)
{
    int i;
    xj_jconf jcf;

    for(i = 0; i < jcp->len && main_loop; i++)
    {
        if(jcp->ojc[i] == NULL)
            continue;
        if(jcp->ojc[i]->jkey->flag==XJ_FLAG_OPEN &&
                jcp->ojc[i]->expire > ltime)
            continue;

#ifdef XJ_EXTRA_DEBUG
        DBG("XJAB:xj_worker:%d: connection expired for <%.*s> \n",
            _xj_pid, jcp->ojc[i]->jkey->id->len, jcp->ojc[i]->jkey->id->s);
#endif
        xj_send_sip_msgz(_PADDR(jwl), jcp->ojc[i]->jkey->id, &jab_gw_name,
                         XJ_DMSG_INF_JOFFLINE, NULL);
#ifdef XJ_EXTRA_DEBUG
        DBG("XJAB:xj_worker:%d: connection's close flag =%d\n",
            _xj_pid, jcp->ojc[i]->jkey->flag);
#endif
        // CLEAN JAB_WLIST
        xj_wlist_del(jwl, jcp->ojc[i]->jkey, _xj_pid);

        // looking for open conference rooms
#ifdef XJ_EXTRA_DEBUG
        DBG("XJAB:xj_worker:%d: having %d open conferences\n",
            _xj_pid, jcp->ojc[i]->nrjconf);
#endif
        while(jcp->ojc[i]->nrjconf > 0)
        {
            if((jcf=delpos234(jcp->ojc[i]->jconf,0))!=NULL)
            {
                // get out of room
                xj_jcon_jconf_presence(jcp->ojc[i],jcf, "unavailable", NULL);
                xj_jconf_free(jcf);
            }
            jcp->ojc[i]->nrjconf--;
        }

        // send offline presence to all subscribers
        if(jcp->ojc[i]->plist)
        {
#ifdef XJ_EXTRA_DEBUG
            DBG("XJAB:xj_worker:%d: sending 'terminated' status to SIP"
                " subscriber\n", _xj_pid);
#endif
            xj_pres_list_notifyall(jcp->ojc[i]->plist,
                                   XJ_PS_TERMINATED);
        }
        FD_CLR(jcp->ojc[i]->sock, pset);
        xj_jcon_disconnect(jcp->ojc[i]);
        xj_jcon_free(jcp->ojc[i]);
        jcp->ojc[i] = NULL;
    }
}
예제 #3
0
파일: x11fwd.c 프로젝트: rdebath/sgt
static char *x11_verify(unsigned long peer_ip, int peer_port,
			struct X11Auth *auth, char *proto,
			unsigned char *data, int dlen)
{
    if (strcmp(proto, x11_authnames[auth->fakeproto]) != 0)
	return "wrong authentication protocol attempted";
    if (auth->fakeproto == X11_MIT) {
        if (dlen != auth->fakelen)
            return "MIT-MAGIC-COOKIE-1 data was wrong length";
        if (memcmp(auth->fakedata, data, dlen) != 0)
            return "MIT-MAGIC-COOKIE-1 data did not match";
    }
    if (auth->fakeproto == X11_XDM) {
	unsigned long t;
	time_t tim;
	int i;
	struct XDMSeen *seen, *ret;

        if (dlen != 24)
            return "XDM-AUTHORIZATION-1 data was wrong length";
	if (peer_port == -1)
            return "cannot do XDM-AUTHORIZATION-1 without remote address data";
	des_decrypt_xdmauth(auth->fakedata+9, data, 24);
        if (memcmp(auth->fakedata, data, 8) != 0)
            return "XDM-AUTHORIZATION-1 data failed check"; /* cookie wrong */
	if (GET_32BIT_MSB_FIRST(data+8) != peer_ip)
            return "XDM-AUTHORIZATION-1 data failed check";   /* IP wrong */
	if ((int)GET_16BIT_MSB_FIRST(data+12) != peer_port)
            return "XDM-AUTHORIZATION-1 data failed check";   /* port wrong */
	t = GET_32BIT_MSB_FIRST(data+14);
	for (i = 18; i < 24; i++)
	    if (data[i] != 0)	       /* zero padding wrong */
		return "XDM-AUTHORIZATION-1 data failed check";
	tim = time(NULL);
	if (abs(t - tim) > XDM_MAXSKEW)
	    return "XDM-AUTHORIZATION-1 time stamp was too far out";
	seen = snew(struct XDMSeen);
	seen->time = t;
	memcpy(seen->clientid, data+8, 6);
	assert(auth->xdmseen != NULL);
	ret = add234(auth->xdmseen, seen);
	if (ret != seen) {
	    sfree(seen);
	    return "XDM-AUTHORIZATION-1 data replayed";
	}
	/* While we're here, purge entries too old to be replayed. */
	for (;;) {
	    seen = index234(auth->xdmseen, 0);
	    assert(seen != NULL);
	    if (t - seen->time <= XDM_MAXSKEW)
		break;
	    sfree(delpos234(auth->xdmseen, 0));
	}
    }
예제 #4
0
파일: x11fwd.c 프로젝트: rdebath/sgt
void x11_free_auth(void *authv)
{
    struct X11Auth *auth = (struct X11Auth *)authv;
    struct XDMSeen *seen;

    if (auth->xdmseen != NULL) {
	while ((seen = delpos234(auth->xdmseen, 0)) != NULL)
	    sfree(seen);
	freetree234(auth->xdmseen);
    }
    sfree(auth);
}
예제 #5
0
파일: timing.c 프로젝트: chemhack/putty
/*
 * Call to run any timers whose time has reached the present.
 * Returns the time (in ticks) expected until the next timer after
 * that triggers.
 */
int run_timers(long anow, long *next)
{
    struct timer *first;

    init_timers();

    now = GETTICKCOUNT();

    while (1) {
	first = (struct timer *)index234(timers, 0);

	if (!first)
	    return FALSE;	       /* no timers remaining */

	if (find234(timer_contexts, first->ctx, NULL) == NULL) {
	    /*
	     * This timer belongs to a context that has been
	     * expired. Delete it without running.
	     */
	    delpos234(timers, 0);
	    sfree(first);
	} else if (first->now - now <= 0 ||
	           now - (first->when_set - 10) < 0) {
	    /*
	     * This timer is active and has reached its running
	     * time. Run it.
	     */
	    delpos234(timers, 0);
	    first->fn(first->ctx, first->now);
	    sfree(first);
	} else {
	    /*
	     * This is the first still-active timer that is in the
	     * future. Return how long it has yet to go.
	     */
	    *next = first->now;
	    return TRUE;
	}
    }
}
예제 #6
0
void delpostest(int i) {
    int index = i;
    void *elem = array[i], *ret;

    /* i points to the right element */
    while (i < arraylen-1) {
	array[i] = array[i+1];
	i++;
    }
    arraylen--;			       /* delete elem from array */

    if (tree->cmp)
	ret = del234(tree, elem);
    else
	ret = delpos234(tree, index);

    if (ret != elem) {
	error("del returned %p, expected %p", ret, elem);
    }

    verify();
}
예제 #7
0
/**
 * send disconnected info to all SIP users associated with worker idx
 * and clean the entries from wlist
 */
int xj_wlist_clean_jobs(xj_wlist jwl, int idx, int fl)
{
    xj_jkey p;
    if(jwl==NULL || idx < 0 || idx >= jwl->len || !jwl->workers[idx].sip_ids)
        return -1;
    lock_set_get(jwl->sems, idx);
    while((p=(xj_jkey)delpos234(jwl->workers[idx].sip_ids, 0))!=NULL)
    {
        if(fl)
        {
#ifdef XJ_EXTRA_DEBUG
            DBG("XJAB:xj_wlist_send_info: sending disconnect message"
                " to <%.*s>\n",	p->id->len, p->id->s);
#endif
            xj_send_sip_msgz(_PADDR(jwl), p->id, &jab_gw_name,
                             XJ_DMSG_INF_DISCONNECTED, NULL);
        }
        jwl->workers[idx].nr--;
        xj_jkey_free_p(p);
    }
    lock_set_release(jwl->sems, idx);
    return 0;
}
예제 #8
0
/**
 * free the allocated memory space of a JABBER connection
 */
int xj_jcon_free(xj_jcon jbc)
{
	xj_jconf jcf;
	
	if(jbc == NULL)
		return -1;

#ifdef XJ_EXTRA_DEBUG
	DBG("XJAB:xj_jcon_free: -----START-----\n");
#endif
	//if(jbc->sock != -1)
	//	jb_disconnect(jbc);

	if(jbc->hostname != NULL)
		_M_FREE(jbc->hostname);
	if(jbc->stream_id != NULL)
		_M_FREE(jbc->stream_id);
	
	if(jbc->resource != NULL)
		_M_FREE(jbc->resource);
#ifdef XJ_EXTRA_DEBUG
	DBG("XJAB:xj_jcon_free: %d conferences\n", jbc->nrjconf);
#endif
	while(jbc->nrjconf > 0)
	{
		if((jcf=delpos234(jbc->jconf,0))!=NULL)
			xj_jconf_free(jcf);
		jbc->nrjconf--;
	}
	xj_pres_list_free(jbc->plist);
	_M_FREE(jbc);
#ifdef XJ_EXTRA_DEBUG
	DBG("XJAB:xj_jcon_free: -----END-----\n");
#endif
	return 0;
}
예제 #9
0
파일: timing.c 프로젝트: AbelTian/filezilla
/*
 * Call to run any timers whose time has reached the present.
 * Returns the time (in ticks) expected until the next timer after
 * that triggers.
 */
int run_timers(long anow, long *next)
{
    struct timer *first;

    init_timers();

#ifdef TIMING_SYNC
    /*
     * In this ifdef I put some code which deals with the
     * possibility that `anow' disagrees with GETTICKCOUNT by a
     * significant margin. Our strategy for dealing with it differs
     * depending on platform, because on some platforms
     * GETTICKCOUNT is more likely to be right whereas on others
     * `anow' is a better gold standard.
     */
    {
	long tnow = GETTICKCOUNT();

	if (tnow + TICKSPERSEC/50 - anow < 0 ||
	    anow + TICKSPERSEC/50 - tnow < 0
	    ) {
#if defined TIMING_SYNC_ANOW
	    /*
	     * If anow is accurate and the tick count is wrong,
	     * this is likely to be because the tick count is
	     * derived from the system clock which has changed (as
	     * can occur on Unix). Therefore, we resolve this by
	     * inventing an offset which is used to adjust all
	     * future output from GETTICKCOUNT.
	     * 
	     * A platform which defines TIMING_SYNC_ANOW is
	     * expected to have also defined this offset variable
	     * in (its platform-specific adjunct to) putty.h.
	     * Therefore we can simply reference it here and assume
	     * that it will exist.
	     */
	    tickcount_offset += anow - tnow;
#elif defined TIMING_SYNC_TICKCOUNT
	    /*
	     * If the tick count is more likely to be accurate, we
	     * simply use that as our time value, which may mean we
	     * run no timers in this call (because we got called
	     * early), or alternatively it may mean we run lots of
	     * timers in a hurry because we were called late.
	     */
	    anow = tnow;
#else
/*
 * Any platform which defines TIMING_SYNC must also define one of the two
 * auxiliary symbols TIMING_SYNC_ANOW and TIMING_SYNC_TICKCOUNT, to
 * indicate which measurement to trust when the two disagree.
 */
#error TIMING_SYNC definition incomplete
#endif
	}
    }
#endif

    now = anow;

    while (1) {
	first = (struct timer *)index234(timers, 0);

	if (!first)
	    return FALSE;	       /* no timers remaining */

	if (find234(timer_contexts, first->ctx, NULL) == NULL) {
	    /*
	     * This timer belongs to a context that has been
	     * expired. Delete it without running.
	     */
	    delpos234(timers, 0);
	    sfree(first);
	} else if (first->now - now <= 0) {
	    /*
	     * This timer is active and has reached its running
	     * time. Run it.
	     */
	    delpos234(timers, 0);
	    first->fn(first->ctx, first->now);
	    sfree(first);
	} else {
	    /*
	     * This is the first still-active timer that is in the
	     * future. Return how long it has yet to go.
	     */
	    *next = first->now;
	    return TRUE;
	}
    }
}