|
|
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: 6598 (0x19c6)
Types: TextFile
Names: »rfc822_val.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z«
└─⟦e5a54fb17⟧
└─⟦this⟧ »pp-5.0/Lib/parse/rfc822_val.c«
/* rfc822_validate.c: validate a syntatic rfc 822 address */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/parse/RCS/rfc822_val.c,v 5.0 90/09/20 16:09:42 pp Exp Locker: pp $";
# endif
/*
* $Header: /cs/research/pp/hubris/pp-beta/Lib/parse/RCS/rfc822_val.c,v 5.0 90/09/20 16:09:42 pp Exp Locker: pp $
*
* $Log: rfc822_val.c,v $
* Revision 5.0 90/09/20 16:09:42 pp
* rcsforce : 5.0 public release
*
*/
#include "util.h"
#include "head.h"
#include "adr.h"
#include "ap.h"
#include "retcode.h"
/* -- externals -- */
extern char *loc_dom_site;
extern char *loc_dom_mta;
extern int all_domain_norm;
extern int topParse;
int rfc822_validate (ingroup, inname, inloc, indom, inroute,
ad, order_pref, full, rp)
AP_ptr ingroup,
inname,
inloc,
indom,
inroute;
ADDR *ad;
int order_pref;
int full;
RP_Buf *rp;
{
register AP_ptr ap,
hptr, /* -- the next host -- */
local = inloc,
domain = indom,
route = inroute;
LIST_RCHAN *rlp;
char *cp,
mta_key [LINESIZE],
official [LINESIZE],
*newlocsubdom = NULLCP,
tmp[BUFSIZ];
int retval;
int weAreTopParse = FALSE;
char *lsubdom = NULLCP;
PP_DBG (("Lib/parse/rfc822_validate (%s, %d)",
ad->ad_value, order_pref));
/* -- some debugging statements -- */
if (route)
PP_DBG (( "Lib/parse/rfc822_validate (route=%s, type=%d)",
route->ap_obvalue, route->ap_obtype));
/* SEK - should log ALL the route */
if (domain)
PP_DBG (( "Lib/parse/rfc822_validate (dom=%s, type=%d)",
domain->ap_obvalue, domain->ap_obtype));
if (local)
PP_DBG (( "Lib/parse/rfc822_validate (local=%s, type=%d)",
local->ap_obvalue, local->ap_obtype));
if (local == NULLAP) {
(void) sprintf(tmp,
"No local address in %s",
ad->ad_value);
ad->ad_parse_message = strdup(tmp);
return RP_BAD;
}
for (;;) {
/* -- find the component address to play with -- */
if (route != NULLAP) {
hptr = route;
for (;;) {
switch (route -> ap_ptrtype) {
case AP_PTR_NIL:
case AP_PTR_NXT:
/* -- no more route -- */
route = NULLAP;
break;
case AP_PTR_MORE:
route = route -> ap_next;
if (route == NULLAP)
break;
switch (route -> ap_obtype) {
case AP_DOMAIN_LITERAL:
case AP_DOMAIN:
break;
case AP_COMMENT:
continue;
default:
route = NULLAP;
break;
} /* -- switch -- */
} /* -- switch -- */
break; /* -- no route -- */
} /* -- for -- */
} /* -- if's then -- */
else if (domain != NULLAP) {
hptr = domain;
domain = NULLAP;
}
else {
char *cp = ap_p2s_nc (NULLAP, NULLAP,
local, NULLAP, NULLAP);
if (topParse == TRUE) {
weAreTopParse = TRUE;
topParse = FALSE;
}
retval = ad_local (cp, ad, rp,
lsubdom);
PP_DBG (("Lib/parse/rfc822_validate returned %d", retval));
if (weAreTopParse == TRUE) {
freeAliasList();
topParse = TRUE;
}
free (cp);
goto out2;
} /* -- if completed -- */
PP_DBG (( "Lib/parse/rfc822_validate (Doing dmn=%s, type=%d)",
hptr->ap_obvalue, hptr->ap_obtype));
/* -- a single domain reference is evaluated -- */
/* --- *** ---
Find an address for it. mta_key will contain the route
components, official will contain the official name of host
--- *** --- */
/* -- if us then skip -- */
if (lexequ (hptr->ap_obvalue, loc_dom_site) == 0
|| lexequ (hptr->ap_obvalue, loc_dom_mta) == 0) {
if (lsubdom) free (lsubdom);
lsubdom = NULLCP;
continue;
}
/* domain maybe not normalized ? */
if ((all_domain_norm == FALSE
&& ap_dmnormalize(hptr, order_pref) != OK)
|| tb_getdomain (hptr -> ap_obvalue, mta_key, official,
order_pref, &newlocsubdom) != OK)
{
/* -- Bad name, not known, and nowhere to send -- */
(void) strcpy (official, hptr -> ap_obvalue);
(void) sprintf (tmp,
"Unknown domain '%s'", hptr->ap_obvalue);
ad -> ad_parse_message = strdup(tmp);
retval = RP_BAD;
goto out;
}
if (newlocsubdom != NULLCP) {
/* sub domain of us */
if (lsubdom != NULLCP)
free (lsubdom);
lsubdom = newlocsubdom;
continue;
}
if (lexequ (mta_key, loc_dom_site) == 0)
if (lexequ (official, loc_dom_site) == 0) {
if (lsubdom) free (lsubdom);
lsubdom = NULLCP;
continue; /* an alias of us */
}
else {
(void) sprintf(tmp, "Loop error '%s' -> '%s'",
mta_key, official);
ad->ad_parse_message = strdup(tmp);
retval = parselose (rp, RP_BAD, "%s", tmp);
(void) strcpy (official, hptr -> ap_obvalue);
goto out;
}
/* -- look up the mta, if local then recurse -- */
if (ad->ad_outchan == NULLIST_RCHAN)
if (tb_getchan (mta_key, &ad->ad_outchan) != OK) {
(void) strcpy (official, hptr -> ap_obvalue);
(void) sprintf (tmp,
"No channel for '%s'", mta_key);
ad->ad_parse_message = strdup(tmp);
retval = parselose (rp, RP_BAD, "%s", tmp);
goto out;
}
/* --- *** ---
Go thru the list. if li_mta (i.e mta) is not set,
insert official. Finally add the list into the ad structure.
--- *** --- */
for (rlp=ad->ad_outchan; rlp; rlp = rlp->li_next)
if (rlp->li_mta == NULLCP)
rlp->li_mta = strdup (official);
break;
} /* -- for completed -- */
if (lsubdom) free (lsubdom);
lsubdom = NULLCP;
if (ad -> ad_outchan == NULL)
return RP_BAD;
retval = RP_AOK;
/* -- Add the official name onto the end of the address -- */
out:
if (domain == NULLAP)
domain = ap_new (AP_DOMAIN, official);
else if (lexequ (official, loc_dom_site) != 0) {
ap = ap_new (AP_DOMAIN, official);
if (route != NULLAP)
ap -> ap_ptrtype = AP_PTR_MORE;
ap -> ap_next = route;
route = ap;
}
/* -- convert back to a string -- */
if (full == OK)
cp = ap_p2s (ingroup, inname, local, domain, route);
else
cp = ap_p2s_nc (NULLAP, NULLAP, local, domain, route);
PP_DBG (("rfc822_parse/address = %s", cp));
/* -- Put the address into the ad structure -- */
if (ad->ad_r822adr) free(ad->ad_r822adr);
ad->ad_r822adr = cp;
out2: /* recursion, and so address filled */
if (lsubdom) free (lsubdom);
lsubdom = NULLCP;
ad->ad_parse_stat = retval;
if (domain != NULLAP) {
(void) ap_sqdelete (domain, NULLAP);
ap_free (domain);
}
if (route != NULLAP) {
(void) ap_sqdelete (route, NULLAP);
ap_free (route);
}
if (!rp_isbad(retval))
ad->ad_type = AD_822_TYPE;
PP_DBG(("Lib/parse/rfc822_validate returns %d", retval));
return (retval);
}