home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume16
/
deliver
/
part02
/
dest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-14
|
2KB
|
119 lines
/* $Header: dest.c,v 1.2 88/08/30 16:12:40 network Exp $
*
* Operations on the list of mail destinations.
*
* $Log: dest.c,v $
* Revision 1.2 88/08/30 16:12:40 network
* Use savestr() instead of strdup().
*
* Revision 1.1 88/06/06 09:38:29 chip
* Initial revision
*
*/
#include "deliver.h"
/*
* Local data.
*/
static DEST deadhead = { &deadhead, &deadhead };
#define HEADPTR (&deadhead)
/*----------------------------------------------------------------------
* Add a new destination to the list (unless it already exists).
* Return pointer to DEST.
*/
DEST *
dest(name, mailbox)
char *name;
char *mailbox;
{
DEST *d;
DCLASS class;
if (strchr(name, '!'))
class = CL_UUCP;
else if (mailbox)
class = CL_MBOX;
else
class = CL_USER;
for (d = HEADPTR->next; d != HEADPTR; d = d->next)
{
if (d->class != class)
continue;
if (strcmp(d->name, name) != 0)
continue;
/*
* If this destination has a named mailbox, then
* test it for equality as well.
*/
if (class == CL_MBOX
&& strcmp(d->mailbox, mailbox) != 0)
continue;
/*
* Like, gnarly, dude! It's already in the chain!
*/
return d;
}
/*
* The given dest isn't in the list, so we have to add it.
*/
d = (DEST *) zalloc(sizeof(DEST));
d->class = class;
d->state = ST_WORKING;
d->name = copystr(name);
if (class == CL_MBOX)
d->mailbox = copystr(mailbox);
if (class != CL_UUCP
&& name_context(name) == NULL)
{
d->state = ST_ERROR;
d->error = "No such user";
}
d->prev = HEADPTR->prev;
d->next = HEADPTR;
d->prev->next = d;
d->next->prev = d;
return d;
}
/*----------------------------------------------------------------------
* Return pointer to first DEST in the list.
*/
DEST *
first_dest()
{
if (HEADPTR->next != HEADPTR)
return HEADPTR->next;
return NULL;
}
/*----------------------------------------------------------------------
* Return pointer to next DEST in the list, or NULL.
*/
DEST *
next_dest(d)
DEST *d;
{
if (d && (d = d->next) != HEADPTR)
return d;
return NULL;
}