DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T t

⟦b437877da⟧ TextFile

    Length: 4200 (0x1068)
    Types: TextFile
    Names: »timeout.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Chans/timeout/timeout.c« 

TextFile

/* timeout.c: message timeout channel */

# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Chans/timeout/RCS/timeout.c,v 5.0 90/09/20 15:54:47 pp Exp Locker: pp $";
# endif

/*
 * $Header: /cs/research/pp/hubris/pp-beta/Chans/timeout/RCS/timeout.c,v 5.0 90/09/20 15:54:47 pp Exp Locker: pp $
 *
 * $Log:	timeout.c,v $
 * Revision 5.0  90/09/20  15:54:47  pp
 * rcsforce : 5.0 public release
 * 
 */



#include "head.h"
#include "dbase.h"
#include "qmgr.h"
#include "q.h"
#include "dr.h"
#include "prm.h"


extern char     *mquedir;
extern char     *quedfldir;
extern CHAN     *ch_nm2struct();
extern void	sys_init(), rd_end(), err_abrt();
CHAN            *mychan;

static struct type_Qmgr_DeliveryStatus *process ();
static int initialise ();
static void dirinit ();
static struct type_Qmgr_DeliveryStatus *new_DeliveryStatus();
static int security_check ();
static ADDR *get_address ();

/* \f

 */
/* main routine */

main (argc, argv)
int     argc;
char    **argv;
{
	sys_init(argv[0]);
	dirinit ();
#ifdef PP_DEBUG
	if (argc>1 && (strcmp(argv[1],"debug") == 0))
		debug_channel_control(argc,argv,initialise,process,NULLIFP);
	else
#endif
		channel_control (argc, argv, initialise, process,NULLIFP);
}

/* \f

 */
/* routine to move to correct place in file system */

static void dirinit ()
{
	if (chdir (quedfldir) < 0)
		err_abrt (RP_LIO, " Unable to change directory to '%s'",
			  quedfldir);
}

/* \f

 */
/* channel initialise routine */

static int initialise (arg)
struct type_Qmgr_Channel *arg;
{
	char *name;

	name = qb2str(arg);

	if ((mychan = ch_nm2struct(name)) == NULLCHAN) {
		PP_OPER(NULLCP,
			("Chans/timeout : Channel '%s' not known",name));
		if (name != NULL) free(name);
		return NOTOK;
	}

	/* check if a timeout channel */
	if (name != NULL) free(name);
	return OK;
}

/* \f

 */
/* routine called to clean do timeout out */

static struct type_Qmgr_DeliveryStatus *process (arg)
struct type_Qmgr_ProcMsg *arg;
{
	struct prm_vars prm;
	Q_struct        que;
	ADDR            *sender;
	ADDR            *recips;
	int             rcount;
	char            *this_msg;
	ADDR            *adr;

	prm_init (&prm);
	q_init (&que);

	sender = NULLADDR;
	recips = NULLADDR;

	delivery_init(arg->users);
	delivery_setall(int_Qmgr_status_messageFailure);

	if (security_check(arg) != TRUE)
		return deliverystate;

	/* ok-timeout message */
	this_msg = qb2str (arg->qid);

	PP_LOG(LLOG_NOTICE,
	       ("timing out msg %s", this_msg));

	if (rp_isbad(rd_msg(this_msg,&prm,&que,&sender,&recips,&rcount))) {
		PP_LOG(LLOG_EXCEPTIONS,
		       ("Chans/timeout rd_msg err: '%s'",this_msg));
		rd_end();
		/* free all storage used */
		if (this_msg != NULL) free(this_msg);
		q_free (&que);

		return deliverystate;
	}

	for (adr = que.Raddress; adr; adr = adr -> ad_next)
		if (adr -> ad_status == AD_STAT_PEND) 
			set_1dr(&que, adr -> ad_no,
				DRR_UNABLE_TO_TRANSFER,
				DRD_MAX_TIME_EXPIRED,
				NULLCP);
	if (arg->users != NULL
	    && (adr = get_address(arg->users->RecipientId->parm, &que)) != 0
	    && !rp_isbad(wr_q2dr(&que, this_msg)))
		 delivery_set(adr -> ad_no, int_Qmgr_status_negativeDR);
	else
		delivery_set(adr -> ad_no, int_Qmgr_status_messageFailure);

	/* unlock file */
	rd_end();


	/* free all storage used */
	if (this_msg != NULL) free(this_msg);
	q_free (&que);

	return deliverystate;
}

/* \f

 */
/* routine to check if allo<wed to timeout this message */
static int security_check (msg)
struct type_Qmgr_ProcMsg *msg;
{
	char *msg_file = NULL, *msg_chan = NULL;
	int result;

	result = TRUE;
	msg_file = qb2str (msg->qid);
	msg_chan = qb2str (msg->channel);

	if ((mychan == NULLCHAN) || (strcmp(msg_chan,mychan->ch_name) !=0)) {
		PP_LOG(LLOG_EXCEPTIONS,
		       ("Chans/timeout channel err: '%s'",msg_chan));
		result = FALSE;
	}
	if (msg_file != NULL) free(msg_file);
	if (msg_chan != NULL) free(msg_chan);
	return result;
}

/* routine to extract the required address from the Q_struct */
static ADDR *get_address (usr, que)
int             usr;
Q_struct        *que;
{
	ADDR *ix;

	if (usr == 0)
		/* originator */
		return que->Oaddress;

	ix = que->Raddress;
	while ((ix != 0) && (--usr > 0))
		ix = ix->ad_next;

	return ix;
}