home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / delay / qu2ds_send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  8.4 KB  |  371 lines

  1. /*
  2.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  3.  *
  4.  *     Copyright (C) 1979,1980,1981  University of Delaware
  5.  *
  6.  *     Department of Electrical Engineering
  7.  *     University of Delaware
  8.  *     Newark, Delaware  19711
  9.  *
  10.  *     Phone:  (302) 738-1163
  11.  *
  12.  *     This program module was developed as part of the University
  13.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  14.  *
  15.  *     Acquisition, use, and distribution of this module and its listings
  16.  *     are subject restricted to the terms of a license agreement.
  17.  *     Documents describing systems using this module must cite its source.
  18.  *
  19.  *     The above statements must be retained with all copies of this
  20.  *     program and may not be removed without the consent of the
  21.  *     University of Delaware.
  22.  *
  23.  *
  24.  *     version  -1    David H. Crocker    March   1979
  25.  *     version   0    David H. Crocker    April   1980
  26.  *     version  v7    David H. Crocker    May     1981
  27.  *     version   1    David H. Crocker    October 1981
  28.  *
  29.  */
  30. /*                SEND FROM DELIVER TO SUBMIT
  31.  *
  32.  *  Feb 83  Doug Kingston       Initial version of list processor
  33.  *  Nov 85  Phil Cockcroft      Hacked into a delay channel
  34.  *  Apr 86  Craig Partridge     Diddled for efficiency reasons
  35.  */
  36.  
  37. #include "util.h"
  38. #include "mmdf.h"
  39. #include "phs.h"
  40. #include "ch.h"
  41. #include "ap.h"
  42. #include "ns.h"
  43.  
  44. extern struct ll_struct   *logptr;
  45. extern Chan *chanptr;
  46.  
  47. extern char *rindex();
  48. extern char *strdup();
  49. extern char *multcat();
  50. extern char *blt();
  51.  
  52. LOCFUN qu2ds_each(), qu2ds_txtcpy();
  53.  
  54. LOCVAR int nadrs;
  55. LOCVAR char sender[ADDRSIZE];
  56.  
  57. LOCVAR struct rp_construct
  58.     rp_bdrem =
  59. {
  60.     RP_BHST, 'B', 'a', 'd', ' ', 'r', 'e', 's', 'p', 'o', 'n', 's', 'e',
  61.     ' ', 'f', 'r', 'o', 'm', ' ', 's', 'u', 'b', 'm', 'i', 't', '\0'
  62. },
  63.     rp_adr =
  64. {
  65.     RP_AOK, 'a', 'd', 'd', 'r', 'e', 's', 's', ' ', 'o', 'k', '\0'
  66. },
  67.     rp_gdtxt =
  68. {
  69.     RP_MOK, 't', 'e', 'x', 't', ' ', 's', 'e', 'n', 't', ' ', 'o', 'k', '\0'
  70. },
  71.     rp_nadr =
  72. {
  73.     RP_AGN, 'N', 'o', ' ', 'v', 'a', 'l', 'i', 'd', ' ', 
  74.     'a', 'd', 'r', 'e', 's', 's', 'e', 's', '\0'
  75. },
  76.     rp_noop =
  77. {
  78.     RP_NOOP, 's', 'u', 'b', '-', 'l', 'i', 's', ' ', 'n', 'o', 't', ' ',
  79.     's', 'p', 'e', 'c', 'i', 'a', 'l', '\0'
  80. };
  81.  
  82. /* */
  83.  
  84. qu2ds_send ()             /* overall mngmt for batch of msgs    */
  85. {
  86.     int        started = FALSE;
  87.     short       result;
  88.     char        info[LINESIZE];
  89.  
  90. #ifdef DEBUG
  91.     ll_log (logptr, LLOGBTR, "qu2ds_send ()");
  92. #endif
  93.  
  94.     if (rp_isbad (result = qu_pkinit ()))
  95.     return (result);
  96.  
  97.     /*
  98.      *  While there are messages to process ...
  99.      */
  100.     for(;;){                /* get initial info for new message   */
  101.     result = qu_rinit (info, sender, chanptr -> ch_apout);
  102.  
  103.     switch (rp_gval(result)) {
  104.  
  105.         case RP_NS:        /* keep plugging */
  106.         case RP_FIO:    /* couldn't open this message file */
  107.         qu_rend();
  108.         continue;
  109.  
  110.         case RP_OK:
  111.         break;
  112.  
  113.         default:
  114.         goto done;
  115.     }
  116.  
  117.     /* make sure we have a submit there */
  118.     if ((!started) && (rp_isbad(mm_init())  || rp_isbad(mm_sbinit()))) {
  119.         /* do we want to tell deliver what happened? */
  120.         goto done;
  121.     }
  122.     started = TRUE;
  123.         
  124.     /* now send message */
  125.     switch(rp_gval(result = qu2ds_each ())) {
  126.  
  127.         case RP_OK:        /* good! */
  128.         case RP_MECH:    /* bad queue file */
  129.         break;
  130.  
  131.         case RP_AGN:    /* submit was cranky */
  132.         started = FALSE;
  133.         break;
  134.  
  135.         case RP_NO:        /* deliver hassled us */
  136.         default:        /* something worse happened */
  137.         goto done;
  138.     }
  139.  
  140.     qu_rend();
  141.     }
  142.  
  143. done:
  144.     qu_rend();
  145.  
  146.     if (rp_gval (result) != RP_DONE)
  147.     {
  148.     ll_log (logptr, LLOGFAT, "not DONE (%s)", rp_valstr (result));
  149.     return (RP_RPLY);         /* catch protocol errors              */
  150.     }
  151.  
  152.     /* shut down submit nicely */
  153.     if (started) {
  154.     mm_sbend();
  155.     }
  156.  
  157.  
  158.     qu_pkend ();                  /* done getting messages              */
  159.     return (result);
  160. }
  161. /* */
  162.  
  163. LOCFUN
  164.     qu2ds_each ()             /* send copy of text per address      */
  165. {
  166.     struct rp_bufstruct thereply;
  167.     short   result;
  168.     int     len;
  169.     char    host[ADDRSIZE];
  170.     char    adr[ADDRSIZE];
  171.     char    *dchan, *dhost;
  172.     char    info[ADDRSIZE];
  173.     char    *index();
  174.     int     ndone = 0;
  175.  
  176. #ifdef DEBUG
  177.     ll_log (logptr, LLOGBTR, "qu2ds_each()");
  178. #endif
  179.  
  180.     nadrs = 0;
  181.  
  182.     /*
  183.      *  For every address in the message ...
  184.      */
  185.     while( 1 ) {
  186.     result = qu_radr (host, adr);
  187.     if (rp_isbad (result))
  188.         return (RP_NO);       /* deliver goofed */
  189.  
  190.     switch (rp_gval (result))
  191.     {
  192.         case RP_HOK:          /* end of sub-list */
  193.         qu_wrply ((RP_Buf *)&rp_noop, sizeof rp_noop);
  194.         break;
  195.  
  196.         case RP_DONE:         /* end of full address list           */
  197.         /* only send text if got some addresses done */
  198.         if(ndone != 0)
  199.             qu2ds_txtcpy(&thereply);
  200.         else 
  201.             blt((char *)&rp_nadr, (char *)&thereply, sizeof(rp_nadr));
  202.  
  203.         qu_wrply(&thereply, sizeof (thereply.rp_val)
  204.                     + strlen (thereply.rp_line));
  205.  
  206.         if(ndone == 0 || rp_isbad(thereply.rp_val)) {
  207.             mm_end(NOTOK);
  208.             return(RP_AGN);
  209.         }
  210.         return (RP_OK);         /* END for this message */
  211.  
  212.         default:            /* actually have an address */
  213.  
  214.         if (nadrs++ == 0)
  215.         {
  216.             if((dhost = index(host, '&')) != NULL){
  217.             *dhost++ = 0;
  218.             dchan = host;
  219.             if(*dchan == '\0'){ /* no channel must be local */
  220.                 dchan = 0;
  221.                 sprintf(info, "vmjlk%d*",NS_DELTIME);
  222.             }
  223.             else if(*dhost == '\0')
  224.                 sprintf(info, "vmjlk%d*",NS_DELTIME);
  225.             else
  226.             {
  227.                 /* reset the host as before
  228.                 * dchan is already set */
  229.                 sprintf(info, "vmjlh%s*k%d", dhost,NS_DELTIME);
  230.             }
  231.  
  232.             if (domsg)
  233.             strcat(info,"W");
  234. #ifdef DEBUG
  235.             ll_log (logptr, LLOGBTR, "d2s dchan = '%s' info = '%s'",
  236.                 dchan ? dchan : "NULL", info);
  237. #endif
  238.             } else {
  239. #ifdef DEBUG
  240.             ll_log (logptr, LLOGFAT, "Missing '&' in delay");
  241. #endif
  242.             return(RP_MECH);
  243.             }
  244.  
  245.             /* tell submit about this message */
  246.             if (rp_isbad (mm_winit (dchan, info, sender))
  247.               || rp_isbad (mm_rrply(&thereply, &len))) {
  248.             mm_end (NOTOK);
  249.             printx ("Error in submit startup\n");
  250.             fflush (stdout);
  251.             qu_wrply((RP_Buf *)&rp_bdrem, sizeof rp_bdrem);
  252.             return(RP_AGN);
  253.             }
  254.  
  255.             switch (rp_gbval (thereply.rp_val)) {
  256.             case RP_BNO:
  257.             case RP_BTNO:
  258.             mm_end (NOTOK);
  259.             printx ("Error in submit startup (%s)\n", thereply.rp_line);
  260.             fflush (stdout);
  261.             qu_wrply(&thereply, len);
  262.             return(RP_AGN);
  263.  
  264.             default:
  265.             break;
  266.             }
  267.  
  268.             if (rp_isbad (mm_wadr ("", adr))
  269.               || rp_isbad (mm_rrply(&thereply, &len))) {
  270.             mm_end (NOTOK);
  271.             printx ("Error in passing address\n");
  272.             fflush (stdout);
  273.             qu_wrply((RP_Buf *)&rp_bdrem, sizeof rp_bdrem);
  274.             return(RP_AGN);
  275.             }
  276.         } /* naddrs = 0 */
  277.         else
  278.         {
  279.             if (rp_isbad (mm_wadr ("", adr))
  280.                || rp_isbad (mm_rrply(&thereply, &len)))
  281.             {
  282.             mm_end (NOTOK);
  283.             printx ("Error in passing address\n");
  284.             fflush (stdout);
  285.             qu_wrply((RP_Buf *)&rp_bdrem, sizeof rp_bdrem);
  286.             return(RP_AGN);
  287.             }
  288.         }  /* naddrs != 0 */
  289.     } /* switch */
  290.  
  291.     switch (rp_gval (thereply.rp_val))
  292.     {                 /* was address acceptable?            */
  293.         case RP_AOK:
  294.         qu_wrply((RP_Buf *)&rp_adr, sizeof  rp_adr);
  295.         ndone++;
  296.         continue;
  297.  
  298.         case RP_NAUTH:    /* errg !! */
  299.         thereply.rp_val = RP_USER;
  300.         break;
  301.  
  302.         case RP_PARM:
  303.         case RP_USER:
  304.         case RP_NO:
  305.         case RP_NS:
  306.         break;    /* report failure and continue        */
  307.  
  308.         case RP_RPLY:
  309.         ll_log (logptr, LLOGTMP, "unusual return: (%s)%s",
  310.             rp_valstr (thereply.rp_val), thereply.rp_line);
  311.         break;
  312.     }
  313.     /* tell deliver about address */
  314.     qu_wrply (&thereply, len);
  315.     }
  316.     /* NOTREACHED */
  317. }
  318.  
  319. /* */
  320.  
  321. LOCFUN
  322.     qu2ds_txtcpy (rp)     /* copy the text of the message       */
  323. RP_Buf *rp;
  324. {
  325.     int       len;
  326.     short     result;
  327.     char      buffer[BUFSIZ];
  328.  
  329. #ifdef DEBUG
  330.     ll_log (logptr, LLOGBTR, "qu2ds_txtcpy()");
  331. #endif
  332.  
  333.     qu_rtinit (0L);
  334.  
  335.     if (rp_isbad (result = mm_waend())) {
  336.     blt ((char *)&rp_bdrem, (char *) rp, sizeof rp_bdrem);
  337.     return;
  338.     }
  339.  
  340.     printx ("sending...:");
  341.     fflush (stdout);
  342.  
  343.     len = sizeof(buffer);
  344.     while ((rp_gval (result = qu_rtxt (buffer, &len))) == RP_OK)
  345.     {
  346.     result = mm_wtxt (buffer, len);
  347.     if (rp_isbad (result))
  348.         break;
  349.     printx (".");
  350.     fflush (stdout);
  351.     if (rp_gval (result) != RP_OK) {
  352.         blt ((char *)&rp_bdrem, (char *) rp, sizeof rp_bdrem);
  353.         return;
  354.     }
  355.         len = sizeof(buffer);
  356.     }
  357.  
  358.     if (rp_isbad (result) || rp_gval (result) != RP_DONE) {
  359.     blt ((char *)&rp_bdrem, (char *) rp, sizeof rp_bdrem);
  360.     return;
  361.     }
  362.  
  363.     if (rp_isbad(mm_wtend()) || rp_isbad(mm_rrply(rp,&len))) {
  364.     rp->rp_val = RP_RPLY;
  365.     strcpy (rp->rp_line, "Unknown Problem");
  366.     return;
  367.     }
  368.     
  369.     blt ((char *)&rp_gdtxt, (char *)rp, sizeof rp_gdtxt);
  370. }
  371.