home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / deliver / part02 / dest.c < prev    next >
C/C++ Source or Header  |  1988-11-14  |  2KB  |  119 lines

  1. /* $Header: dest.c,v 1.2 88/08/30 16:12:40 network Exp $
  2.  *
  3.  * Operations on the list of mail destinations.
  4.  *
  5.  * $Log:    dest.c,v $
  6.  * Revision 1.2  88/08/30  16:12:40  network
  7.  * Use savestr() instead of strdup().
  8.  * 
  9.  * Revision 1.1  88/06/06  09:38:29  chip
  10.  * Initial revision
  11.  * 
  12.  */
  13.  
  14. #include "deliver.h"
  15.  
  16. /*
  17.  * Local data.
  18.  */
  19.  
  20. static  DEST    deadhead = { &deadhead, &deadhead };
  21. #define HEADPTR    (&deadhead)
  22.  
  23. /*----------------------------------------------------------------------
  24.  * Add a new destination to the list (unless it already exists).
  25.  * Return pointer to DEST.
  26.  */
  27.  
  28. DEST *
  29. dest(name, mailbox)
  30. char    *name;
  31. char    *mailbox;
  32. {
  33.     DEST    *d;
  34.     DCLASS   class;
  35.  
  36.     if (strchr(name, '!'))
  37.         class = CL_UUCP;
  38.     else if (mailbox)
  39.         class = CL_MBOX;
  40.     else
  41.         class = CL_USER;
  42.  
  43.     for (d = HEADPTR->next; d != HEADPTR; d = d->next)
  44.     {
  45.         if (d->class != class)
  46.             continue;
  47.  
  48.         if (strcmp(d->name, name) != 0)
  49.             continue;
  50.  
  51.         /*
  52.          * If this destination has a named mailbox, then
  53.          * test it for equality as well.
  54.          */
  55.  
  56.         if (class == CL_MBOX
  57.          && strcmp(d->mailbox, mailbox) != 0)
  58.             continue;
  59.  
  60.         /*
  61.          * Like, gnarly, dude!  It's already in the chain!
  62.          */
  63.  
  64.         return d;
  65.     }
  66.  
  67.     /*
  68.      * The given dest isn't in the list, so we have to add it.
  69.      */
  70.  
  71.     d = (DEST *) zalloc(sizeof(DEST));
  72.     d->class = class;
  73.     d->state = ST_WORKING;
  74.     d->name = copystr(name);
  75.     if (class == CL_MBOX)
  76.         d->mailbox = copystr(mailbox);
  77.  
  78.     if (class != CL_UUCP
  79.      && name_context(name) == NULL)
  80.     {
  81.         d->state = ST_ERROR;
  82.         d->error = "No such user";
  83.     }
  84.  
  85.     d->prev = HEADPTR->prev;
  86.     d->next = HEADPTR;
  87.     d->prev->next = d;
  88.     d->next->prev = d;
  89.  
  90.     return d;
  91. }
  92.  
  93. /*----------------------------------------------------------------------
  94.  * Return pointer to first DEST in the list.
  95.  */
  96.  
  97. DEST *
  98. first_dest()
  99. {
  100.     if (HEADPTR->next != HEADPTR)
  101.         return HEADPTR->next;
  102.  
  103.     return NULL;
  104. }
  105.  
  106. /*----------------------------------------------------------------------
  107.  * Return pointer to next DEST in the list, or NULL.
  108.  */
  109.  
  110. DEST *
  111. next_dest(d)
  112. DEST    *d;
  113. {
  114.     if (d && (d = d->next) != HEADPTR)
  115.         return d;
  116.  
  117.     return NULL;
  118. }
  119.