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

  1. #include "util.h"
  2. #include "mmdf.h"
  3. #include "ph.h"
  4.  
  5. /*
  6.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  7.  *     
  8.  *
  9.  *     Copyright (C) 1979,1980,1981  University of Delaware
  10.  *     
  11.  *     Department of Electrical Engineering
  12.  *     University of Delaware
  13.  *     Newark, Delaware  19711
  14.  *
  15.  *     Phone:  (302) 738-1163
  16.  *     
  17.  *     
  18.  *     This program module was developed as part of the University
  19.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  20.  *     
  21.  *     Acquisition, use, and distribution of this module and its listings
  22.  *     are subject restricted to the terms of a license agreement.
  23.  *     Documents describing systems using this module must cite its source.
  24.  *
  25.  *     The above statements must be retained with all copies of this
  26.  *     program and may not be removed without the consent of the
  27.  *     University of Delaware.
  28.  *     
  29.  *
  30.  *     version  -1    David H. Crocker    March   1979
  31.  *     version   0    David H. Crocker    April   1980
  32.  *     version  v7    David H. Crocker    May     1981
  33.  *     version   1    David H. Crocker    October 1981
  34.  *
  35.  */
  36. /*  CH_PHONE:  deliver-to-phone transmission                            */
  37. /*                                                                      */
  38.  
  39. /*  Jun 81  D. Crocker      Add d2p_nadrs mechanism to send no msg text
  40.  *                          when there are not valid addresses
  41.  *  Jul 81  D. Crocker      Change state variable values, for more robust
  42.  *                          state diagrams, to avoid hang with Deliver
  43.  */
  44.  
  45.  
  46. #include "ch.h"
  47. #include "chan.h"
  48. #include "phs.h"
  49. #include "ap.h"
  50.  
  51. extern struct ll_struct  *logptr;
  52. extern Chan *curchan;
  53. extern char *strdup();
  54. extern char *ap_p2s();
  55. extern int  ap_outtype;
  56. extern char *supportaddr;
  57. extern char *mmdflogin;
  58.  
  59. /*#define RUNALON   */
  60.  
  61. LOCVAR int numadrs;                    /* number of valid addresses          */
  62. LOCVAR char *sender = (char *)NULL;    /* return address for message         */
  63. LOCVAR char *adr    = (char *)NULL;    /* recipient address                  */
  64. LOCVAR struct rp_construct
  65.                 rp_hend  =
  66. {
  67.     RP_NOOP, 'e', 'n', 'd', ' ', 'o', 'f', ' ', 'h', 'o', 's', 't', ' ',
  68.     'i', 'g', 'n', 'o', 'r', 'e', 'd', '\0'
  69. },
  70.     rp_kild =
  71. {
  72.     RP_DHST, 'n', 'o', ' ', 'v', 'a', 'l', 'i', 'd', ' ', 'a', 'd', 'd',
  73.     'r', 'e', 's', 's', 'e', 's', '\0'
  74. };
  75.  
  76. char ph_state = SND_RINIT;  /* state of processing current msg    */
  77.  
  78.  
  79. qu2ph_send (chname)                 /* overall mngmt for batch of msgs    */
  80.     char chname[];                /* name of channel we are             */
  81. {
  82.     short     result;
  83.     char    info[LINESIZE],
  84.             sendbuf[ADDRSIZE];
  85.  
  86.     if (rp_isbad (result = qu_pkinit ()))
  87.     return (result);
  88.  
  89.     if (rp_isbad (result = ph_sbinit ()))
  90.     {
  91.     printx ("remote site refuses to receive mail.\n");
  92.     fflush (stdout);
  93.     return (result);
  94.     }
  95.  
  96.     ph_state = SND_ABORT;
  97.     for(;;){
  98.     AP_ptr  loctree, domtree, routree, sendtree;
  99.     AP_ptr  ap_s2tree(), ap_normalize();
  100.  
  101.     result = qu_rinit (info, sendbuf, curchan->ch_apout);
  102.     if(rp_gval(result) == RP_NS){
  103.         qu_rend();
  104.         continue;
  105.     }
  106.     if(rp_gval(result) == RP_DONE)
  107.         break;
  108.  
  109.     if (rp_gval(result) == RP_FIO)        /* Can't open message file */
  110.         continue;
  111.     else if (rp_gval(result) != RP_OK)    /* Some other error */
  112.         break;
  113.  
  114.     if (sender != (char *)NULL){
  115.         free (sender);
  116.         sender = NULL;
  117.     }
  118.  
  119.     if ( sendbuf[0] == '\0' ||
  120.         (sendtree = ap_s2tree( sendbuf )) == (AP_ptr) NOTOK) {
  121.         printx("return address unparseable, using Orphanage\n");
  122.         fflush(stdout);
  123.         if ((sendtree = ap_s2tree( supportaddr )) == (AP_ptr) NOTOK) {
  124.             printx("Orphanage unparseable, using MMDF\n");
  125.             fflush(stdout);
  126.         } else
  127.         if ((sendtree = ap_s2tree( mmdflogin )) == (AP_ptr) NOTOK) {
  128.             result = RP_PARM;
  129.             qu_rend();
  130.             goto bugout;
  131.         }
  132.     }
  133.     ap_outtype = curchan -> ch_apout;
  134.     sendtree = ap_normalize (curchan -> ch_lname,
  135.             curchan  -> ch_ldomain, sendtree, curchan);
  136.     if(sendtree == (AP_ptr)MAYBE){
  137.         result = RP_NS;
  138.         qu_rend();
  139.         goto bugout;
  140.     }
  141.     ap_t2parts (sendtree, (AP_ptr *)0, (AP_ptr *)0, &loctree,
  142.             &domtree, &routree);
  143.     sender = ap_p2s ((AP_ptr)0, (AP_ptr)0, loctree, domtree, routree);
  144.     if(sender == (char *)MAYBE){
  145.         result = RP_NS;
  146.         qu_rend();
  147.         goto bugout;
  148.     }
  149.     ap_sqdelete( sendtree, (AP_ptr) 0 );
  150.     ap_free( sendtree );
  151.  
  152.     ph_state = SND_RDADR;
  153.     if (rp_isbad (result = ph_winit (chname, info, sender)))
  154.         return (result);      /* ready to process a message         */
  155.  
  156.     if (rp_isbad (result = q2p_admng ()))
  157.         return (result);      /* send the address list              */
  158.     
  159.     if (rp_gval (result) != RP_DONE)
  160.         break;          /* catch protocol errors              */
  161.  
  162.     if (rp_isbad (result = q2p_txmng ()))
  163.         return (result);      /* send the message text              */
  164.  
  165.     qu_rend();
  166.     }
  167.     qu_rend();
  168.  
  169.     if (rp_gval (result) != RP_DONE)
  170.     {
  171.     ll_log (logptr, LLOGTMP, "not DONE (%s)", rp_valstr (result));
  172.     return (RP_RPLY);      /* catch protocol errors              */
  173.     }
  174.  
  175. bugout:
  176.     ph_state = SND_ABORT;
  177.     qu_pkend ();                  /* done getting messages              */
  178.     if (rp_isbad (result = ph_sbend ())) {
  179.                   /* done sending messages              */
  180.     printx ("bad ending for outgoing submission... ");
  181.     fflush (stdout);
  182.     }
  183.     return (result);
  184. }
  185. /* */
  186.  
  187. LOCFUN
  188.     q2p_admng ()              /* send address list                  */
  189. {
  190.     struct rp_bufstruct thereply;
  191.     short     result;
  192.     char    host[ADDRSIZE];
  193.     char    adrbuf[ADDRSIZE];
  194.  
  195.     AP_ptr  loctree, domtree, routree, adrtree;
  196.     AP_ptr  ap_s2tree(), ap_normalize();
  197.  
  198.     for (numadrs = 0; ; )         /* reset for each new messages        */
  199.     {                             /* we already have and adr            */
  200.     ph_state = SND_ABORT;
  201.     result = qu_radr (host, adrbuf);
  202.     if (rp_isbad (result))
  203.         return (result);      /* get address from Deliver           */
  204.  
  205.     if (rp_gval (result) == RP_HOK)
  206.     {                         /* no-op the sub-list indication      */
  207.         qu_wrply ((struct rp_bufstruct *) &rp_hend, rp_conlen (rp_hend));
  208.         continue;
  209.     }
  210.  
  211.     if (rp_gval (result) == RP_DONE)
  212.         break;          /* end of address list                */
  213.         
  214.     if (adr != (char *)NULL)
  215.         free (adr);
  216.  
  217.     if ( (adrtree = ap_s2tree(adrbuf)) == (AP_ptr) NOTOK)  {
  218.         adr = strdup( adrbuf );
  219.     } else {
  220.         ap_outtype = curchan -> ch_apout;
  221.         adrtree = ap_normalize (curchan -> ch_lname,
  222.                 curchan  -> ch_ldomain, adrtree, curchan);
  223.         if(adrtree == (AP_ptr)MAYBE){
  224.         result = RP_NS;
  225.         goto bugout;
  226.         }
  227.         ap_t2parts (adrtree, (AP_ptr *)0, (AP_ptr *)0, &loctree,
  228.             &domtree, &routree);
  229.         adr = ap_p2s ((AP_ptr)0, (AP_ptr)0, loctree, domtree, routree);
  230.         if(adr == (char *)MAYBE){
  231.         result = RP_NS;
  232.         goto bugout;
  233.         }
  234.         ap_sqdelete( adrtree, (AP_ptr) 0 );
  235.         ap_free( adrtree );
  236.     }
  237.         
  238.     ph_state = SND_ARPLY;
  239.     if (rp_isbad (result = ph_wadr (host, adr, &thereply)))
  240.         return (result);      /* give to remote site & get reply    */
  241.  
  242. bugout:
  243.     switch (rp_gval (thereply.rp_val))
  244.     {              /* was address acceptable?            */
  245.         case RP_AOK:       /* address ok, text not yet sent      */
  246.         numadrs++;
  247.         ph_state = SND_ABORT;
  248.         qu_wrply (&thereply, rp_structlen(thereply));
  249.         break;
  250.  
  251.         case RP_NO:       /* remaining acceptible responses     */
  252.         thereply.rp_val = RP_NDEL;
  253.         case RP_NS:
  254.         case RP_USER: 
  255.         case RP_NDEL: 
  256.         case RP_AGN: 
  257.         case RP_NOOP: 
  258.         ph_state = SND_ABORT;
  259.         qu_wrply (&thereply, rp_structlen(thereply));
  260.         break;
  261.  
  262.         default:           /* responses which force abort        */
  263.         if (rp_isbad (thereply.rp_val))
  264.             return (thereply.rp_val);
  265.         return (RP_RPLY);
  266.     }
  267.     }
  268.     ph_state = SND_TRPLY;
  269.     return (ph_waend ());        /* tell remote of address list end    */
  270. }
  271. /* */
  272.  
  273. LOCFUN
  274.     q2p_txmng ()              /* send message text                  */
  275. {
  276.     struct rp_bufstruct thereply;
  277.     int     len;
  278.     short   result;
  279.     char    buffer[BUFSIZ];
  280.  
  281. /*  if no addressees have been accepted, don't bother sending the text */
  282.     if (numadrs == 0)    
  283.     {
  284.     qu_wrply ((struct rp_bufstruct *) &rp_kild, rp_conlen (rp_kild));
  285.     return (RP_DONE);
  286.     }
  287.  
  288.     if (rp_isbad( ph_wtinit() ))
  289.         return (RP_RPLY);
  290.     printx ("sending...:");
  291.     fflush (stdout);
  292.  
  293.     len = sizeof(buffer);
  294.     for (qu_rtinit (0L);
  295.         (rp_gval (result = qu_rtxt (buffer, &len))) == RP_OK; )
  296.     {
  297.         printx (".");         /* to show watcher we're working      */
  298.         fflush (stdout);
  299.         if (rp_isbad (result = ph_wtxt (buffer, len)))
  300.         return (result);                         
  301.         if (rp_gval (result) != RP_OK)
  302.         return (RP_RPLY);
  303.     len = sizeof(buffer);
  304.     }
  305.     printx (" ");             /* keep it pretty                     */
  306.     fflush (stdout);
  307.  
  308.     if (rp_isbad (result))
  309.         return (result);
  310.     if (rp_gval (result) != RP_DONE)
  311.         return (RP_RPLY);         /* didn't get it all across?          */
  312.  
  313.     if (rp_isbad (result = ph_wtend (&thereply)))
  314.         return (result);          /* flag end of message                */
  315.     
  316.     switch (rp_gval (thereply.rp_val))
  317.     {                      /* was text acceptable?               */
  318.         case RP_OK: 
  319.             thereply.rp_val = RP_MOK;
  320.         case RP_MOK:               /* text was accepted                  */
  321.             qu_wrply (&thereply, rp_structlen(thereply));
  322.             break;
  323.     
  324.         case RP_NO:               /* remaining acceptible responses     */
  325.             thereply.rp_val = RP_NDEL;
  326.         case RP_NDEL: 
  327.         case RP_AGN: 
  328.         case RP_NOOP: 
  329.             qu_wrply (&thereply, rp_structlen(thereply));
  330.             thereply.rp_val = RP_OK;
  331.             break;                /* don't abort process                */
  332.     
  333.         default:               /* responses which force abort        */
  334.             if (rp_isbad (thereply.rp_val))
  335.                 return (thereply.rp_val);
  336.             return (RP_RPLY);
  337.     }
  338.     return (thereply.rp_val);     /* just quote remote                  */
  339. }
  340.