📄 address.c
字号:
if ((hostp->hstatus == phantom) && ( hostp->realname == NULL ))
return input;
/*--------------------------------------------------------------------*/
/* If we already chased this chain, return result to caller */
/*--------------------------------------------------------------------*/
if (hostp->aliased)
{
if ( hostp->realname == NULL )
{
printmsg(0,"Alias table loop detected with host %s",
hostp->hostname);
}
return hostp->realname;
} /* if */
hostp->aliased = TRUE; /* Prevent limitless recursion */
/*--------------------------------------------------------------------*/
/* Determine next host in the chain */
/*--------------------------------------------------------------------*/
if ( hostp->realname == NULL) /* End of the line? */
hostp->realname = hostp->hostname;
else
hostp->realname = HostAlias(hostp->realname);
/*--------------------------------------------------------------------*/
/* Announce our results */
/*--------------------------------------------------------------------*/
printmsg( 5 , "HostAlias: \"%s\" is alias of \"%s\"",
input,
hostp->realname);
return hostp->realname;
} /* HostAlias */
/*--------------------------------------------------------------------*/
/* H o s t P a t h */
/* */
/* Determine the path to a host */
/*--------------------------------------------------------------------*/
char *HostPath( char *input, char *best)
{
struct HostTable *hostp;
hostp = checkname( input );
/*--------------------------------------------------------------------*/
/* If nothing else to look at, return original data to caller */
/*--------------------------------------------------------------------*/
if (hostp == BADHOST)
return best;
if (hostp->hstatus == gatewayed) /* Gatewayed? */
return hostp->hostname; /* Yes --> Use name for path */
/*--------------------------------------------------------------------*/
/* If we already chased this chain, return result to caller */
/*--------------------------------------------------------------------*/
if (hostp->routed)
{
if ( hostp->via == NULL )
{
if ( hostp->aliased &&
! equali(hostp->hostname,hostp->realname))
hostp->via = best;
else {
printmsg(0,"Routing table loop discovered at host %s",
hostp->hostname);
panic();
}
} /* if ( hostp->via == NULL ) */
return hostp->via;
} /* if (hostp->routed) */
hostp->routed = TRUE; /* Prevent limitless recursion */
/*--------------------------------------------------------------------*/
/* Determine next host in the chain */
/*--------------------------------------------------------------------*/
if ( hostp->via == NULL )
{
char *alias = HostAlias( hostp->hostname );
if (equal(hostp->hostname,alias))
{
if (hostp->hstatus == localhost) /* Ourself? */
hostp->via = E_nodename; /* Yes --> Deliver local */
else if ( checkreal( hostp->hostname ) == BADHOST )
/* Unknown system? */
hostp->via = best; /* Yes --> Use default */
else
hostp->via = hostp->hostname; /* Known --> route to it */
} /* if ( hostp->via == NULL ) */
else
hostp->via = HostPath( alias, best);
} /* if ( hostp->via == NULL ) */
hostp->via = HostPath( hostp->via, best );
printmsg( 5 ,"HostPath: \"%s\" routed via \"%s\"", input, hostp->via);
return hostp->via;
} /* HostPath */
/*--------------------------------------------------------------------*/
/* E x t r a c t A d d r e s s */
/* */
/* Returns the user name (if available and requested or */
/* E-mail address of the user */
/*--------------------------------------------------------------------*/
char *ExtractAddress(char *result,
const char *input ,
FULLNAME fullname)
{
char *nonblank = NULL;
char *column = (char *) input;
char name[BUFSIZ]; /* User full name */
char *nameptr = name;
char addr[BUFSIZ]; /* User e-mail address */
char *addrptr = addr;
char state = 'A'; /* State = skip whitespace */
char newstate = 'A'; /* Next state to process */
int bananas = 0; /* No () being processed now */
int len;
boolean quoted = FALSE;
/*--------------------------------------------------------------------*/
/* Begin loop to copy the input field into the address and or the */
/* user name. We will begin by copying both (ignoring whitespace */
/* for addresses) because we won't know if the input field is an */
/* address or a name until we hit either a special character of */
/* some sort. */
/*--------------------------------------------------------------------*/
while ((*column != '\0') && (state != ','))
{
switch (state) {
case 'A':
if (isspace(*column)) /* Found first non-blank? */
break; /* No --> keep looking */
nonblank = column;
state = 'B';
/* ... and fall through */
case 'B':
case ')':
newstate = *column;
switch(*column) {
case '(':
bananas++;
break;
case '"':
break;
case '<':
addrptr = addr; /* Start address over */
nameptr = name; /* Start name over again */
column = nonblank - 1;
/* Re-scan in new state */
newstate = '>'; /* Proc all-non <> as name */
break; /* Begin addr over again */
case ',':
break; /* Terminates address */
case '>':
case ')':
printmsg(0,"Invalid RFC-822 address: %s",nonblank);
panic(); /* Ooops, funky address */
break;
default:
newstate = state; /* stay in this state */
if (!isspace(*column))
*(addrptr++) = *column;
} /* switch(*column) */
break;
case '<': if (*column == '>')
newstate = '>';
else if (!isspace(*column))
*(addrptr++) = *column;
break;
case '>': if (*column == '<')
newstate = '<';
else switch( *column )
{
case ')':
if (quoted)
*(nameptr++) = *column;
else
bananas--;
break;
case '(':
if (quoted)
*(nameptr++) = *column;
else
bananas++;
break;
case '"':
if (bananas == 0)
{
quoted = !quoted;
break;
}
/* else fall through */
default:
*(nameptr++) = *column;
} /* switch */
break;
case '(': if (*column == '(')
++bananas;
else if (*column == ')')
{
if (--bananas == 0)
{
newstate = ')';
break;
}
}
else
*(nameptr++) = *column;
break;
case '"': if (*column == '"')
newstate = ')';
else
*(nameptr++) = *column;
break;
default: panic();
/* Logic error, bad state */
break;
} /* switch (state) */
state = newstate;
column++;
} /* while */
/*--------------------------------------------------------------------*/
/* Verify we retrieved an address */
/*--------------------------------------------------------------------*/
if (state == 'A')
{
printmsg(0, "ExtractAddress: Could not find address in \"%s\"",
column);
panic();
}
/*--------------------------------------------------------------------*/
/* Fill in the results for the caller */
/*--------------------------------------------------------------------*/
*addrptr = '\0';
*nameptr = '\0';
*result = '\0';
len = strlen( addr );
if ((fullname == ADDRESSONLY) ||
((fullname == FULLADDRESS) && (state == 'B')))
{
if ( len >= MAXADDR )
{
printmsg(0,"ExtractAddress: Address exceeds %d characters: %s",
MAXADDR, addr );
panic();
}
strcpy(result,addr); /* Return the full address */
}
else if (state != 'B')
{
while (--nameptr >= name)
{
if (isspace(*nameptr))
*nameptr = '\0';
else
break;
}
/*--------------------------------------------------------------------*/
/* Strip leading blanks from the address */
/*--------------------------------------------------------------------*/
nameptr = name;
while (isspace(*nameptr))
nameptr++;
if ( strlen( nameptr ) >= MAXADDR )
{
printmsg(0,"ExtractAddress: Truncating name %s" , nameptr);
nameptr[ MAXADDR - 1 ] = '\0';
}
if ( fullname == FULLADDRESS )
{
if ( len >= (MAXADDR-6) )
{
printmsg(0,"ExtractAddress: Address exceeds %d characters: %s",
MAXADDR-6, addr );
panic();
}
nameptr[ MAXADDR - len - 6] = '\0';
sprintf( result , "\"%s\" <%s>", nameptr, addr );
}
else
strncpy(result,nameptr, MAXADDR);
} /* else */
printmsg(4,"ExtractAddress: %s into <%s> \"%s\"",
nonblank,addr,(fullname) ? result : name);
/*--------------------------------------------------------------------*/
/* Return the position of the next address, if any, to the caller */
/*--------------------------------------------------------------------*/
if ( *column == '\0')
return NULL;
else
return column + 1;
} /*ExtractAddress*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -