|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T w
Length: 5722 (0x165a)
Types: TextFile
Names: »wr_q2dr.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z«
└─⟦e5a54fb17⟧
└─⟦this⟧ »pp-5.0/Lib/io/wr_q2dr.c«
/* wr_q2dr.c: write out a Delivery Notification struct from the error info
/* held in the queue and address structures */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/io/RCS/wr_q2dr.c,v 5.0 90/09/20 16:07:20 pp Exp Locker: pp $";
# endif
/*
* $Header: /cs/research/pp/hubris/pp-beta/Lib/io/RCS/wr_q2dr.c,v 5.0 90/09/20 16:07:20 pp Exp Locker: pp $
*
* $Log: wr_q2dr.c,v $
* Revision 5.0 90/09/20 16:07:20 pp
* rcsforce : 5.0 public release
*
*/
#include "head.h"
#include "q.h"
#include "dr.h"
#include <sys/file.h>
#include "list_bpt.h"
#include <sys/time.h>
extern char *dr_file;
extern char *loc_dom_mta;
extern void or_myinit();
/* -- local routines -- */
int wr_dr_info();
int wr_q2dr();
static void set_successful_supplementary();
/* --------------------- Begin Routines -------------------------------- */
int wr_q2dr (qp, msg_id)
register Q_struct *qp;
char *msg_id;
{
FILE *fp;
ADDR *ap;
char *fname = NULL,
buf[FILNSIZE],
odir[FILNSIZE];
int retval=NOTOK,
dr_file_no = -1,
dr_required = FALSE;
extern char *mquedir;
(void) sprintf (odir, "%s/%s", mquedir, msg_id);
PP_DBG (("Lib/io/wr_q2dr (dir=%s)", odir));
/* open a DR file (dr.999) name is determined by recip */
for (ap=qp->Raddress, retval=OK; ap != NULLADDR && retval == OK; ap=ap->ad_next)
if (ap->ad_status == AD_STAT_DRREQUIRED) {
dr_required = TRUE;
dr_file_no = ap->ad_no;
(void) sprintf (&buf[0], "%s%d", dr_file, dr_file_no);
fname = multcat (odir, "/", &buf[0], NULLCP);
if (access (fname, F_OK) == NOTOK)
break;
retval = NOTOK;
PP_LOG (LLOG_EXCEPTIONS,
("Lib/io/wr_q2dr (file %s exists)", fname));
}
if (ap == NULLADDR && dr_required == FALSE) return (RP_OK);
if (retval == NOTOK) {
PP_LOG (LLOG_FATAL, ("Lib/io/wr_q2dr (dr required but first file in use)"));
return (RP_BAD);
}
PP_DBG (("Lib/io/wr_q2dr (opening %s)", fname));
if ((fp = fopen (fname, "w")) == NULLFILE) {
PP_LOG (LLOG_FATAL,
("Lib/io/wr_q2dr (unable to open %s)", fname));
return (RP_FIO);
}
retval = wr_dr_info (fp, qp, dr_file_no, FALSE);
(void) fclose(fp);
if (chmod(fname, 0666) != 0)
PP_SLOG(LLOG_EXCEPTIONS, fname,
("chmod failed"));
if (retval == NOTOK) return (RP_FIO);
return (RP_OK);
}
/* --------------------- Begin Routines -------------------------------- */
int wr_dr_info (fp, qp, dr_file_no, from_submit) /* Creates a DR for output */
FILE *fp;
register Q_struct *qp;
int dr_file_no;
int from_submit;
{
ADDR *ap;
time_t time();
int retval;
DRmpdu DeliveryReport, *dr;
Rrinfo *nxt, *new;
Report *rep;
char buf[LINESIZE];
PP_DBG (("Lib/io/wr_dr_info()"));
/* -- Initialize -- */
dr_init (dr = &DeliveryReport);
or_myinit(); /* in case */
/* -- set MPDUid -- */
dr -> dr_mpduid = (MPDUid *) smalloc (sizeof (*dr->dr_mpduid));
bzero ((char*) dr->dr_mpduid, sizeof (*dr->dr_mpduid));
MPDUid_new (dr -> dr_mpduid);
/* -- set Trace -- */
trace_add (&dr -> dr_trace, trace_new());
trace_add(&dr -> dr_subject_intermediate_trace, trace_dup(qp -> trace));
for (ap = qp->Raddress; ap != NULLADDR; ap = ap->ad_next)
if (ap->ad_status == AD_STAT_DRREQUIRED) {
if (ap -> ad_no == dr_file_no)
ap->ad_status = AD_STAT_DRWRITTEN;
else ap -> ad_status = AD_STAT_DONE;
new = (Rrinfo *) smalloc (sizeof (*new));
bzero ((char *)new, sizeof (*new));
if (dr -> dr_recip_list != NULL) {
for (nxt = dr->dr_recip_list; nxt -> rr_next;
nxt = nxt->rr_next)
continue;
nxt -> rr_next = new;
}
else
dr -> dr_recip_list = new;
new -> rr_recip = ap -> ad_no;
new -> rr_arrival = utcdup (qp -> queuetime);
rep = &new -> rr_report;
switch (ap->ad_reason) {
case DRR_NO_REASON:
rep->rep_type = DR_REP_SUCCESS;
rep->rep.rep_dinfo.del_time = utcnow();
rep->rep.rep_dinfo.del_type = 1;
(void) set_successful_supplementary
(ap, qp->msgtype, from_submit, &buf[0]);
new -> rr_supplementary = strdup (buf);
break;
default:
rep->rep_type = DR_REP_FAILURE;
rep->rep.rep_ndinfo.nd_rcode = ap->ad_reason;
rep->rep.rep_ndinfo.nd_dcode = ap->ad_diagnostic;
if (ap->ad_add_info != NULLCP)
new ->rr_supplementary =
strdup (ap->ad_add_info);
}
if (!from_submit && rp_isbad (retval = wr_ad_status(ap, ap -> ad_status)))
return retval;
}
retval = dr2txt (fp, &DeliveryReport);
dr_free (&DeliveryReport);
return (retval);
}
static void set_successful_supplementary (ap, msgtype, from_submit, msg_buf)
ADDR *ap;
int msgtype;
int from_submit;
char *msg_buf;
{
char tbuf1[LINESIZE];
if (!from_submit)
goto set_successful_supplementary_common;
if (msgtype != MT_PMPDU)
goto set_successful_supplementary_common;
sprintf (tbuf1,
"(Probe acknowledgement by the PP gateway at '%s')", loc_dom_mta);
if (ap->ad_outchan && ap->ad_outchan->li_chan &&
ap->ad_outchan->li_chan->ch_access == CH_MTS)
(void) sprintf (msg_buf,
"Delivered to '%s' %s", ap->ad_outchan->li_mta, tbuf1);
else
(void) sprintf (msg_buf,
"Relayed to '%s' %s", ap->ad_outchan->li_mta, tbuf1);
return;
set_successful_supplementary_common: ;
if (ap->ad_outchan && ap->ad_outchan->li_chan &&
ap->ad_outchan->li_chan->ch_access == CH_MTS)
(void) sprintf (msg_buf,
"Delivered to '%s'", ap->ad_outchan->li_mta);
else
(void) sprintf (msg_buf,
"Relayed to '%s'", ap->ad_outchan->li_mta);
return;
}