⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addrsbr.c.orig

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 ORIG
📖 第 1 页 / 共 2 页
字号:
/* addrsbr.c - parse addresses 822-style */#include "../h/mh.h"#include "../h/addrsbr.h"#include "../zotnet/mf.h"#include <stdio.h>#ifdef	BERK#include <ctype.h>#endif	BERK/* High level parsing of addresses:   The routines in zotnet/mf/mf.c parse the syntactic representations of   addresses.  The routines in sbr/addrsbr.c associate semantics with those   addresses.     If #ifdef BERK is in effect, the routines in mf.c aren't called and only   the most rudimentary syntax parse is done.  The parse is not 822-conformant.   This causes problems as there is no semantics associated with the address   at all--it's just a string. (the author of the BERK code disagrees with   the preceding, of course.  BERK solves problems for incoming mail   because it will accept damn near any address.  BERK was intended to be   used when spost is the interface to the mail delivery system which means   all outgoing address interpretation is left to sendmail.  It is possible,   though unlikely, for BERK address parsing to interact poorly with    "post". - van@monet.berkeley.edu).   Instead, if #ifdef DUMB is in effect, a full 822-style parser is called   for syntax recongition.  This breaks each address into its components.   Note however that no semantics are assumed about the parts or their   totality.  This means that implicit hostnames aren't made explicit,   and explicit hostnames aren't expanded to their "official" represenations.   If neither BERK nor DUMB is in effect, then this module does some   high-level thinking about what the addresses are.  If #ifdef MF is in   effect, then MH will deduce UUCP-style addressing masquerading as   822-style addresses.   1. for MMDF systems:	string%<uucp>@<local>	->	string   2. for non-MMDF systems:	string@host.<uucp>	->	host!string   3. for any system, an address interpreted relative to the local host:	string@<uucp>		->	string   For cases (1) and (3) above, the leftmost host is extracted.  If it's not   present, the local host is used.  If #ifdef MF is not in effect or the   tests above fail, the address is considered to be a real 822-style address.   If an explicit host is not present, then MH checks for a bang to indicate   an explicit UUCP-style address.  If so, this is noted.  If not, the host is   defaulted, typically to the local host.  The lack of an explict host is   also noted.   If an explicit 822-style host is present, then MH checks to see if it   can expand this to the official name for the host.  If the hostname is   unknown, the address is so typed.   To summarize, when we're all done, here's what MH knows about the address:   BERK	-	type: 	local		nohost:	set if no '@' or '!' in mailbox		text:	exact copy of address		mbox:	lowercase version of mailbox   DUMB	-	type:	local, uucp, or network		host:	not locally defaulted, not explicitly expanded		everything else   other -	type:	local, uucp, network, unknown		everything else *//*  */#if	!defined(DUMB) && defined(SENDMTS) && !defined(BANG)#define	MF#define	UucpChan()	"UUCP"#endif	MF#ifdef	BERKstatic char *err = NULL;static char adrtext[BUFSIZ];#else	not BERKstatic int  ingrp = 0;static char *pers = NULL;static char *mbox = NULL;static char *host = NULL;static char *route = NULL;static char *grp = NULL;static char *note = NULL;static char err[BUFSIZ];#endif	not BERKstatic char adr[BUFSIZ];char   *getusr ();#ifdef	WPint	do_wp = 0;#ifdef	BERKchar   *wp_expand ();#endif#endif/*  */char   *getname (addrs)register char   *addrs;{#ifdef	BERK    /*     * Berkeley uses a very simple parser since Sendmail does all the work.     * The only thing that does address parsing if BERK is defined is the     * routine "ismybox" used by "scan" & "repl" to identify the current     * users maildrop.     *     * This routine does essentially the same address interpretation as the     * routine "prescan" in "sendmail".  The intent is that MH should      * make minimum assumptions about address forms since it doesn't     * have access to the information in the sendmail config file     * (God forbid that anything but sendmail has to deal with a sendmail     * config file) and, therefore, hasn't the faintest idea of what will     * or won't be a legal address.     *     * Since this parse is only used by "ismybox" and repl, it just does     * two things: split multiple addr on a line into separate addresses and      * locate the "mailbox" portion of an address.  The parse uses rfc-822     * metacharacters and quoting but is much less restrictive that rfc-822.     * In detail, `,' or eos terminate addresses.  "Empty" addresses     * (e.g., `,,') are ignored.  Double quote ("), backslash, left & right     * paren and left and right angle brackets are metacharacters.  Left &     * right parens must balance as must left & right angle brackets.  Any     * metacharacter may be escaped by preceding it with a backslash.     * Any text between parens is considered a comment and ignored (i.e.,     * only `(', `)' and `\' are metacharacters following a `(').  Text     * between double quotes is considered escaped (i.e., only `"' and     * `\' are metacharacters following a `"').  The `mailbox' portion     * of an address is the non-comment text between angle-brackets if     * the address contains any angle brackets.  Otherwise, it is all the     * non-comment text.  Blanks, tabs & newlines will not be included     * in the mailbox portion of an address unless they are escaped.     *//* Scanner states */#define NORMAL	(0<<8)#define QS	(1<<8)	/* in quoted string */#define COM	(2<<8)	/* in comment (...) */#define ERR	(3<<8)	/* found an error */#define EOA	(4<<8)	/* end of address */    static char *saved_addr = NULL;	/* saved address line ptr */    static char *adr_ptr = NULL;	/* where to start looking for					   next address on line */    register char *nxtout = adr;	/* where to put next character of					   `mailbox' part of address */    register char c;    register int state = NORMAL;    register char *adrcopy = adrtext;	/* where to put next character of					   address */    register int lbcnt = 0;		/* number of unmatched "(" */    register int lpcnt = 0;		/* number of unmatched "<" */    err = NULL;    if (! addrs) {	adr_ptr = NULL;	return NULL;    }    if (adr_ptr)	addrs = adr_ptr;    else	addrs = saved_addr = getcpy(addrs ? addrs : "");    /* skip any leading whitespace or commas. */    while ( (c = *addrs++) == ',' || isspace(c))	;    #ifdef	WP    if (do_wp && c == '<' && *addrs == '<') {	register char  *cp,		       *dp,		       *ep;	if (cp = index (++addrs, '>')) {	    *++cp = NULL;	    if (dp = wp_expand (addrs, NULLCP)) {		*(addrs - 1) = NULL;		ep = concat (saved_addr, dp, cp, NULLCP);		addrs = ep + strlen (saved_addr);		while ((c = *addrs++) == ',' || isspace (c))		    continue;		free (saved_addr);		saved_addr = ep;		free (dp);	    }	    else {		err = "unable to expand WhitePages query";		(void) strcpy (adrtext, addrs);		addrs = cp;		goto out;	    }	    	}    }#endif    *nxtout = *adrcopy = '\0';    while (state != EOA) {	*adrcopy++ = c;	if (state != COM)/* PJS: Why lower-case the address???	    *nxtout++ = isupper (c) ? tolower (c) : c;*/	    *nxtout++ = c;	switch (state+c) {	case NORMAL+'\n':	/* discard newlines */	case QS+'\n':	case COM+'\n':	case ERR+'\n':	    --nxtout;	    --adrcopy;	    break;	case NORMAL+' ':	/* skip unquoted whitespace */	case NORMAL+'\t':	    --nxtout;	    break;	case NORMAL+'"':	/* start quoted string */	    state = QS;	    break;	case QS+'"':		/* end quoted string */	    state = NORMAL;	    break;	case NORMAL+'<':	    nxtout = adr;	/* start over accumulating address */	    lbcnt++;	    break;	case NORMAL+'>':	    --lbcnt;	    if (lbcnt < 0) {		state = ERR;		err = "extra >";	    } else		*(nxtout-1) = '\0';	    break;	case NORMAL+'(':	    state = COM;	    --nxtout;	case COM+'(':	    lpcnt++;	    break;	case COM+')':	    --lpcnt;	    if (lpcnt < 0) {		state = ERR;		err = "extra )";	    } else if (lpcnt == 0)		state = NORMAL;	    break;	case NORMAL+'\\':	case QS+'\\':	case COM+'\\':	    if ((c = *addrs++) == '\n' || c == '\0') {		state = EOA;		err = "illegal \\";	    }	    *adrcopy++ = c;/* PJS: Why lower-case the address???	    *nxtout++ = isupper (c) ? tolower (c) : c;*/	    *nxtout++ = c;	    break;	case NORMAL+',':	case ERR+',':	case NORMAL+'\0':	case ERR+'\0':	    state = EOA;	    if (lbcnt)		err = "missing >";	    break;	case COM+'\0':	    state = EOA;	    err = "missing )";	    if (nxtout == adr)		nxtout++;	    break;	case QS+'\0':	    state = EOA;	    err = "missing \"";	    break;	}	if (c != '\0')	    c = *addrs++;    }    /*     * at this point adr contains the `mailbox' part of the address     * in lower case & minus any comment or unquoted whitespace.     * adrtext contains an exact copy of the address and     * addr points to where we should start scanning next time.     */    *(nxtout-1) = *(adrcopy-1) = '\0';#ifdef	WPout: ;#endif    if (*adr && !err) {	adr_ptr = addrs-1;#ifndef	WP	return adrtext;#endif    } else {	free (saved_addr);	adr_ptr = NULL;#ifndef	WP	return NULL;#endif    }#ifdef	WP    return adrtext;#endif#else	not BERK    register struct adrx *ap;    pers = mbox = host = route = grp = note = NULL;    err[0] = NULL;    if ((ap = getadrx (addrs ? addrs : "")) == NULL)	return NULL;    (void) strcpy (adr, ap -> text);    pers = ap -> pers;    mbox = ap -> mbox;    host = ap -> host;    route = ap -> path;    grp = ap -> grp;    ingrp = ap -> ingrp;    note = ap -> note;    if (ap -> err && *ap -> err)	(void) strcpy (err, ap -> err);    return adr;#endif	not BERK}/*  */#ifdef	BERK/* ARGSUSED */#endif	BERKstruct mailname *getm (str, dfhost, dftype, wanthost, eresult)register char   *str,		*eresult;char   *dfhost;int     dftype,	wanthost;{#ifndef	BERK    register char   *pp;#ifndef	DUMB    register char   *dp;#endif	not DUMB#ifdef	MF    char   *up = UucpChan ();#endif	MF#endif	not BERK    register struct mailname *mp;    if (err && err[0]) {	if (eresult)	    (void) strcpy (eresult, err);	else	    if (wanthost == AD_HOST)		admonish (NULLCP, "bad address '%s' - %s", str, err);	return NULL;    }#ifdef	BERK    if (str == NULL || *str == '\0') {#else 	not BERK    if (pers == NULL	    && mbox == NULL && host == NULL && route == NULL	    && grp == NULL) {#endif	not BERK	if (eresult)	    (void) strcpy (eresult, "null address");	else	    if (wanthost == AD_HOST)		admonish (NULLCP, "null address '%s'", str);	return NULL;    }#ifndef	BERK    if (mbox == NULL && grp == NULL) {	if (eresult)	    (void) strcpy (eresult, "no mailbox in address");	else	    if (wanthost == AD_HOST)		admonish (NULLCP, "no mailbox in address '%s'", str);	return NULL;    }    if (dfhost == NULL) {	dfhost = LocalName ();	dftype = LOCALHOST;    }#endif	not BERK    mp = (struct mailname  *) calloc ((unsigned) 1, sizeof *mp);    if (mp == NULL) {	if (eresult)	   (void) strcpy (eresult, "insufficient memory to represent address");	else	    if (wanthost == AD_HOST)		adios (NULLCP, "insufficient memory to represent address");	return NULL;    }    mp -> m_next = NULL;    mp -> m_text = getcpy (str);#ifdef	BERK    mp -> m_type = LOCALHOST;    mp -> m_mbox = getcpy (adr);    if (!index (adr, '@') && !index (adr, '!'))	mp -> m_nohost = 1;#else	not BERK    if (pers)	mp -> m_pers = getcpy (pers);    if (mbox == NULL) {	mp -> m_type = BADHOST;	mp -> m_nohost = 1;	mp -> m_ingrp = ingrp;	mp -> m_gname = getcpy (grp);	if (note)	    mp -> m_note = getcpy (note);	return mp;    }/*  */    if (host) {#ifdef MF#ifdef	MMDFMTS	if (up && uleq (host, LocalName ())		&& (pp = rindex (mbox, '%'))		&& uleq (up, pp + 1)) {/* uucpaddr%<uucp>@<local> */	    *pp = NULL;	    goto get_uucp;	}#else	not MMDFMTS	if (up && (pp = index (host, '.')) 		&& uleq (up, pp + 1)) {/* uucpaddr@host.<uucp> */	    *pp = NULL;	    mp -> m_host = getcpy (host);	    mp -> m_mbox = getcpy (mbox);	    mp -> m_type = UUCPHOST;	    goto got_host;	}#endif	not MMDFMTS	if (up && uleq (dfhost, LocalName ())		&& uleq (up, host)) {/* uucpaddr@<uucp> [local] */	    if (pp = index (mbox, '!')) {		*pp++ = NULL;		mp -> m_host = getcpy (mbox);		mp -> m_mbox = getcpy (pp);	    }	    else {		mp -> m_host = getcpy (SystemName ());		mp -> m_mbox = getcpy (mbox);	    }	    mp -> m_type = UUCPHOST;	    goto got_host;	}#endif	MF	mp -> m_mbox = getcpy (mbox);	mp -> m_host = getcpy (host);    }    else {	if (pp = index (mbox, '!')) {	    *pp++ = NULL;	    mp -> m_mbox = getcpy (pp);	    mp -> m_host = getcpy (mbox);	    mp -> m_type = UUCPHOST;	}	else {	    mp -> m_nohost = 1;	    mp -> m_mbox = getcpy (mbox);#ifdef	DUMB	    if (route == NULL && dftype == LOCALHOST) {		mp -> m_host = NULLCP;		mp -> m_type = dftype;	    }	    else#endif	DUMB	    {		mp -> m_host = route ? NULLCP : getcpy (dfhost);		mp -> m_type = route ? NETHOST : dftype;	    }	}	goto got_host;    }/*  */    if (wanthost == AD_NHST)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -