1: /* netmail.c - queue mail for the network server */
   2: 
   3: /* LINTLIBRARY */
   4: 
   5: #include "../h/strings.h"
   6: #include <stdio.h>
   7: #include "../zotnet/mts.h"
   8: 
   9: 
  10: #define NOTOK   (-1)
  11: #define OK  0
  12: 
  13: #define NBYTES  8
  14: 
  15: 
  16: static int  files = 0;
  17: 
  18: static char hex[] = "0123456789ABCDEF";
  19: 
  20: static  union {
  21:     char    nbytes[NBYTES];
  22: 
  23:     struct {
  24:     long    clock;
  25:     short   pid;
  26:     short   id;
  27:     }       stamp;
  28: }       template;
  29: 
  30: static char quefil[BUFSIZ];
  31: static char wrkfil[BUFSIZ];
  32: static FILE * fp;
  33: 
  34: 
  35: long    time ();
  36: char   *cdate (), *ctime ();
  37: 
  38: /*  */
  39: 
  40: int     nm_init (user, clock)
  41: register char   *user;
  42: register long   *clock;
  43: {
  44:     quefile (quefil, wrkfil);
  45: 
  46:     (void) unlink (wrkfil);
  47:     if ((fp = fopen (wrkfil, "w")) == NULL)
  48:     return NOTOK;
  49:     (void) chmod (wrkfil, 0600);
  50: 
  51:     fprintf (fp, "%s %s\n", user, cdate (clock));
  52: 
  53:     return OK;
  54: }
  55: 
  56: 
  57: int     nm_wadr (mbox, host)
  58: register char   *mbox,
  59:             *host;
  60: {
  61:     fprintf (fp, "/%s %s\n", host, mbox);
  62: 
  63:     return OK;
  64: }
  65: 
  66: 
  67: int     nm_waend () {
  68:     putc ('\n', fp);
  69: 
  70:     return OK;
  71: }
  72: 
  73: 
  74: int     nm_wtxt (buffer, cnt)
  75: register char   *buffer;
  76: register int     cnt;
  77: {
  78:     if (fwrite (buffer, sizeof *buffer, cnt, fp) != cnt)
  79:     return NOTOK;
  80: 
  81:     return OK;
  82: }
  83: 
  84: 
  85: int     nm_wtend () {
  86:     (void) fclose (fp);
  87:     if (link (wrkfil, quefil) == NOTOK || unlink (wrkfil) == NOTOK)
  88:     return NOTOK;
  89: 
  90:     return OK;
  91: }
  92: 
  93: /*  */
  94: 
  95: static  quefile (que, lnk)
  96: register char   *que,
  97:             *lnk;
  98: {
  99:     register char  *p,
 100:                    *q;
 101:     char    buffer[BUFSIZ];
 102: 
 103:     template.stamp.pid = getpid ();
 104:     template.stamp.id = files++;
 105:     if (files >= 256) {
 106:     files = 0;
 107:     sleep (1);
 108:     }
 109:     (void) time (&template.stamp.clock);
 110: 
 111:     p = buffer;
 112:     for (q = template.nbytes; q < &template.nbytes[NBYTES]; q++) {
 113:     *p++ = hex[(*q >> 4) & 0xf];
 114:     *p++ = hex[(*q) & 0xf];
 115:     }
 116:     *p = NULL;
 117: 
 118:     (void) sprintf (que, "%s/%s", Mailqdir, buffer);
 119:     (void) sprintf (lnk, "%s/%s", TMailqdir, buffer);
 120: }
 121: 
 122: /*  */
 123: 
 124: static char   *cdate (clock)
 125: register long   *clock;
 126: {
 127:     char   *cp;
 128: 
 129:     cp = ctime (clock);
 130:     cp[1] = cp[8];
 131:     cp[2] = cp[9];
 132:     cp[3] = '-';
 133:     cp[7] = '-';
 134:     cp[8] = cp[22];
 135:     cp[9] = cp[23];
 136:     cp[10] = '@';
 137:     cp[19] = NULL;
 138: 
 139:     return cp + 1;
 140: }

Defined functions

cdate defined in line 124; used 2 times
nm_init defined in line 40; never used
nm_wadr defined in line 57; never used
nm_waend defined in line 67; never used
nm_wtend defined in line 85; never used
nm_wtxt defined in line 74; never used
quefile defined in line 95; used 1 times
  • in line 44

Defined variables

files defined in line 16; used 3 times
hex defined in line 18; used 2 times
quefil defined in line 30; used 2 times
wrkfil defined in line 31; used 6 times

Defined macros

NBYTES defined in line 13; used 2 times
NOTOK defined in line 10; used 5 times
OK defined in line 11; used 5 times
Last modified: 1986-04-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 828
Valid CSS Valid XHTML 1.0 Strict