home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / smphone / ph_slave.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-11  |  5.9 KB  |  240 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *     
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *     
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *     
  16.  *     
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *     
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *     
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /*
  36.  *  PHONENET SLAVE PROCESS
  37.  *
  38.  *  Handles telephone link & mail protocols, interfacing to MMDF for
  39.  *  submission and pickup, via the mm_ package.
  40.  *
  41.  *  One argument is required:  The name of the channel the caller is
  42.  *  claiming to come in from.  (It may be possible for one username to have
  43.  *  access to mail for more than one channel, so the caller must indicate
  44.  *  the channel of interest, for pickup.  However, Submit and/or Ch_PoBox
  45.  *  will verify the claim.)
  46.  *
  47.  *  Sep 81  D. Crocker      allow reading channel name as first input line
  48.  *  Nov 81  D. Crocker      commands case-insensitive
  49.  *  Apr 82  D. Crocker      check chan name; have llog hdr show chan char
  50.  *  Feb 84  D. Long        made full channel name show in llog hdr
  51.  *  Apr 84  D. Long         fixed phs_note call after pickup 
  52.  */
  53.  
  54. #include <signal.h>
  55. #include "ch.h"
  56. #include "phs.h"
  57.  
  58. #define CTIMEOUT    180    /* 3 minute timeout on response to channel prompt */
  59.  
  60. extern struct ll_struct    chanlog;
  61. extern char *logdfldir;
  62. struct ll_struct  *logptr = &chanlog;
  63.  
  64. extern jmp_buf timerest;           /* return location saved for timeout  */
  65. extern int     flgtrest;
  66.  
  67. char    ttyobuf[BUFSIZ];
  68. Chan    *curchan;
  69.  
  70. /*    MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN      */
  71.  
  72. main (argc, argv)
  73. int       argc;
  74. char   *argv[];
  75. {
  76.     extern char *dupfpath ();
  77.     char chaname[64];
  78.  
  79.     umask(0);
  80.  
  81.     setbuf (stdout, ttyobuf);
  82.     mmdf_init (argv[0]);
  83.  
  84.     siginit ();
  85.     if (argv[0][0] == '-')
  86.     {                             /* if login shell, ignore quit & int  */
  87.     signal (SIGINT, SIG_IGN);
  88.     signal (SIGQUIT, SIG_IGN);
  89.     }
  90.  
  91.     if (setjmp (timerest) != 0)   /* other side took too long; give up    */
  92.     {
  93.     flgtrest = FALSE;
  94.     err_abrt (RP_TIME, "Timeout");
  95.     }
  96.     else
  97.     flgtrest = TRUE;
  98.  
  99.     if (argc == 1)                /* channel name not specified as arg  */
  100.     {
  101.     s_alarm (CTIMEOUT);
  102.     printf ("channel: ");
  103.     fflush (stdout);
  104.     gets (chaname);           /* read it                            */
  105.     s_alarm (0);
  106.     }
  107.     else                          /* use the argument                   */
  108.     strcpy (chaname, argv[1]);
  109.  
  110.     ll_hdinit (logptr, chaname); /* which channel are we?    */
  111.  
  112.     if ((curchan = ch_nm2struct (chaname)) == (Chan *) NOTOK)
  113.     err_abrt (RP_PARM, "Channel '%s' is unknown", chaname);
  114.  
  115.     ph_slave (curchan);
  116. }
  117.  
  118. /*  *****************  SERVER/SLAVE MODE  ****************************** */
  119.  
  120. ph_slave (curchan)                /* service requests from caller       */
  121.     Chan *curchan;
  122. {
  123.     int       len;
  124.     short     retval;
  125.     char    linebuf[LINESIZE];
  126.     register char *ptr;
  127.  
  128.     ch_llinit (curchan);
  129.     if (rp_isbad (retval = ph_init (curchan)))
  130.     err_abrt (retval, "Error with initialization");
  131.                   /* set-up to service requests         */
  132.  
  133.     if (sl_pickup(curchan) == RP_OK)  /* RP_DONE means no TURN */
  134.     sl_send (curchan);
  135.  
  136.     ph_end (OK);
  137.     mm_end (OK);
  138.     exit (RP_DONE);
  139. }
  140. /* */
  141.  
  142. sl_send (curchan)               /* dm_slave delivery management     */
  143.     Chan *curchan;
  144. {
  145.     short     retval;
  146.  
  147. #ifdef DEBUG
  148.     ll_log (logptr, LLOGBTR, "[ Send ]");
  149. #endif
  150.  
  151.     if (rp_isbad (retval = mm2ph_send (curchan)))
  152.     err_abrt (retval, "mm2ph_send error");
  153.  
  154.     return(retval);
  155.  
  156. }
  157.  
  158. sl_pickup (curchan)               /* dm_slave pickup management         */
  159.     Chan *curchan;
  160. {
  161.     short     retval;
  162.  
  163. #ifdef DEBUG
  164.     ll_log (logptr, LLOGBTR, "[ Pickup ]");
  165. #endif
  166.  
  167.     phs_note (curchan, PHS_RESTRT);
  168.  
  169.     if (rp_isbad (retval = ph2mm_send (curchan)))
  170.     err_abrt (retval, "ph2mm_send error");
  171.  
  172.     phs_note (curchan, PHS_REEND);
  173.  
  174.     return(retval);
  175. }
  176.  
  177. /*  *************************  UTILITIES  ****************************** */
  178.  
  179. /* VARARGS2 */
  180.  
  181. err_abrt (code, fmt, b, c, d)
  182. int       code;
  183. char   *fmt,
  184.        *b,
  185.        *c,
  186.        *d;
  187. {
  188.     if (fmt != 0)
  189.     err_gen (code, fmt, b, c, d);
  190.  
  191.     ph_end (NOTOK);
  192.  
  193.     ll_log (logptr, LLOGFAT, "Ending [%s]", rp_valstr (code));
  194.  
  195.     ll_close (logptr);            /* put out "cycled" msg, if needed    */
  196.  
  197. #ifdef DEBUG
  198.     if (rp_gbval (code) == RP_BTNO && rp_gcval (code) == RP_CCON)
  199.     exit (code);          /* connection-related temp error      */
  200.  
  201.     abort ();
  202. #else
  203.     exit (code);
  204. #endif
  205. }
  206. /* */
  207.  
  208. /* VARARGS2 */
  209.  
  210. err_gen (code, fmt, b, c, d)      /* standard error processing          */
  211. int       code;                     /* see err_abrt, for explanation      */
  212. char   *fmt,
  213.        *b,
  214.        *c,
  215.        *d;
  216. {
  217.     extern int    errno;
  218.     char newfmt[LINESIZE];
  219.  
  220.     if (rp_isgood (code))      /* it wasn't an error                 */
  221.     return;
  222.  
  223.     printf (fmt, b, c, d);        /* the user what the problem is       */
  224.     putchar ('\n');
  225.     fflush (stdout);
  226.  
  227.     mm_end (NOTOK);
  228.     switch (code)          /* log the error?                     */
  229.     {
  230.     case RP_HUH:           /* not if it was a user error         */
  231.     case RP_PARM: 
  232.     case RP_USER: 
  233.         break;
  234.  
  235.     default: 
  236.         sprintf (newfmt, "%s%s", "err [ ABEND (%s) ] ", fmt);
  237.         ll_err (logptr, LLOGFAT, newfmt, rp_valstr (code), b, c, d);
  238.     }
  239. }
  240.