|
|
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 r
Length: 5573 (0x15c5)
Types: TextFile
Names: »rfc8222uu.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z«
└─⟦e5a54fb17⟧
└─⟦this⟧ »pp-5.0/Chans/uucp/rfc8222uu.c«
/* rfc8222uu.c: routine to convert from rfc822 style address to a
uucp style address via uucp chan table lookup - code adapted from mmdf
original */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Chans/uucp/RCS/rfc8222uu.c,v 5.0 90/09/20 15:55:21 pp Exp Locker: pp $";
# endif
/*
* $Header: /cs/research/pp/hubris/pp-beta/Chans/uucp/RCS/rfc8222uu.c,v 5.0 90/09/20 15:55:21 pp Exp Locker: pp $
*
* $Log: rfc8222uu.c,v $
* Revision 5.0 90/09/20 15:55:21 pp
* rcsforce : 5.0 public release
*
*/
#include "util.h"
#include "chan.h"
#include "ap.h"
#include "adr.h"
extern char *strdup();
extern CHAN *mychan;
extern char *uuxstr;
extern int ap_outtype;
static char nextnode[LINESIZE];
static char who[LINESIZE];
static char *MakeUucpFrom();
static int ScanUucpFrom();
int rfc8222uu(host, orig, into)
char *host,
*orig,
**into;
{
char *bangptr;
char linebuf[LINESIZE];
char *atp, *percentp, *lp;
AP_ptr loc_ptr, /* -- in case fake personal name needed -- */
group_ptr,
name_ptr,
dom_ptr,
route_ptr,
return_tree,
ap;
int aptypesav;
char adr[LINESIZE];
ap_outtype = AP_PARSE_733;
if ((ap = ap_s2t(orig)) == NULLAP)
{
PP_LOG(LLOG_EXCEPTIONS,
("Failure to parse address '%s'",orig));
return NOTOK;
}
return_tree = ap_t2p(ap, NULLAP, NULLAP, /*&group_ptr, &name_ptr,*/
&loc_ptr, &dom_ptr, NULLAP); /*&route_ptr);*/
lp = ap_p2s_nc(NULLAP, NULLAP, loc_ptr, dom_ptr, NULLAP); /*route_ptr);*/
atp = index(lp, '@');
if (atp != NULLCP)
*atp++ = '\0';
if (!lexequ(atp, host))
atp = NULLCP; /* don't make path-to-foo!foo.uucp!user */
percentp = rindex(lp, '%');
if (percentp != NULLCP) {
*percentp = '\0';
if (atp)
sprintf(adr, "%s!%s!%s", atp, ++percentp, lp);
else
sprintf(adr, "%s!%s", ++percentp, lp);
} else if (atp) {
sprintf(adr, "%s!%s", atp, lp);
} else
strcpy(adr,lp);
PP_TRACE(("address = '%s'",adr));
if (!isstr(host))
strcpy(who, adr);
else {
if (tb_k2val(mychan->ch_table, host, nextnode) == NOTOK) {
return NOTOK;
}
sprintf(who, nextnode, adr);
}
/* Extract first host name for destination */
if ((bangptr=index(who, '!')) != NULLCP)
{
/* at least one realy machine */
*bangptr++ = '\0';
strcpy(nextnode, who);
strcpy(who, bangptr);
} else strcpy(nextnode, "");
sprintf(linebuf, "%s %s!rmail \\(%s%s\\)",
uuxstr, nextnode, *who=='~' ? "\\\\" : "", who);
PP_TRACE(("Queuing UUCP mail for %s via %s...\n",
who, nextnode));
*into = strdup(linebuf);
return OK;
}
/* \f
*/
/* routine to create realfrom string */
char *
findfrom (sender)
char *sender;
{
int aptypesav;
char *adr;
register char *p;
AP_ptr ap;
AP_ptr local,
domain,
route;
/* SEK have axed looking at top of file. */
/* This may not be wise - but very much neater */
/* Delver has no business being given UUCP style messsages */
if ((ap = ap_s2t (sender)) == NULLAP)
{
PP_LOG(LLOG_EXCEPTIONS,
("Failure to parse address '%s'", sender));
return (strdup (sender));
}
ap = ap_normalize (ap, CH_USA_PREF);
if(ap == (AP_ptr)MAYBE)
return( (char *)MAYBE);
ap_t2p (ap, NULLAP, NULLAP, &local, &domain, &route);
aptypesav = ap_outtype;
ap_outtype = AP_PARSE_733;
adr = ap_p2s_nc (NULLAP, NULLAP, local, domain, route);
if(adr == (char *)MAYBE){
ap_outtype = aptypesav;
return(adr);
}
if (route == NULLAP)
{
p = multcat (mychan -> ch_name, ".",
mychan -> ch_mta, NULLCP);
if (lexequ (p, domain -> ap_obvalue))
{
free (adr);
adr = strdup (local -> ap_obvalue);
}
free (p);
}
PP_TRACE(("sender = '%s'", adr));
ap_outtype = aptypesav;
lowerfy(adr);
return(MakeUucpFrom(adr));
}
/*
* This added by pc (UKC) to generate correct 'From' lines with
* `!' separated routes for uucp sites
* the rules
* a@b -> b!a
* a%b@c -> c!b!a
* etc
* a%b%c%d%e@x -> x!e!d!c!b!a
* This is done by a call to a recursive routine which I hope is OK
*/
static
char *
MakeUucpFrom(adr)
char *adr;
{ char *new;
char *localname;
register char *site;
/*NOSTRICT*/
if ((new = malloc(strlen(adr)+1)) == (char *)0)
return ((char *)NOTOK);
/*
* Can we assume that this is a legal 733 address ?
* look for the first site
*/
site = rindex(adr, '@');
if (site)
{ *site++ = '\0';
/*
* some input channels (notably ni_niftp) will add the
* name of the local machine into this address
* so we look for it and delete it if found
*/
localname = multcat(mychan->ch_name, ".", mychan->ch_mta, 0);
/*
* if not the same then put back a % to let ScanUucpFrom work
*/
if (!lexequ (localname, site))
site[-1] = '%';
free(localname);
}
ScanUucpFrom(new, adr);
free(adr);
#ifdef DEBUG
PP_TRACE(("sender (From line) = '%s'", new));
#endif
return(new);
}
static int
ScanUucpFrom(new, adr)
register char *new;
register char *adr;
{ register char *site;
char *rindex();
/*
* This presumes that the address we are scanning is somewhat
* legal - but the @ has been replaced by a %
*/
site = rindex(adr, '%');
if (site == (char *)0)
{ (void) strcpy(new, adr);
return;
}
*site++ = '\0';
(void) strcpy(new, site);
new += strlen(site);
*new++ = '!';
*new = '\0';
ScanUucpFrom(new, adr);
}
int getrealfrom(orig, realfrom)
ADDR *orig;
char **realfrom;
{
if ((*realfrom = findfrom(orig->ad_r822adr)) != NULLCP)
return OK;
return NOTOK;
}
/*\f
*/
/*
* LOWERFY() - convert string to lower case
*/
lowerfy (strp)
char *strp;
{
while (*strp = uptolow (*strp))
strp++;
}