home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / b_wazoo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  10.7 KB  |  351 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*                BinkleyTerm WaZOO/EMSI Sendmail Processor                 */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #ifdef HAVE_HYDRA
  49. #include "hydra.h"
  50. #endif
  51.  
  52. extern int WaZOO_callback (char *);
  53. extern int WaZOO_time (long);
  54.  
  55. /*--------------------------------------------------------------------------*/
  56. /* WaZOO/EMSI                                                               */
  57. /*--------------------------------------------------------------------------*/
  58. void 
  59. WaZOO (int originator)
  60. {
  61.     int iFstat;
  62.     int i = 0, akas = 0;
  63.     char j[200];
  64.     char k[100];
  65.     ADDR saved_addr;
  66.  
  67.     /*--------------------------------------------------------------------*/
  68.     /* Initialize WaZOO/EMSI                                              */
  69.     /*--------------------------------------------------------------------*/
  70.  
  71.     iFstat = made_request = got_arcmail = got_packet = 0;
  72.  
  73.     Netmail_Session = 1;
  74.  
  75.     isOriginator = originator;
  76.  
  77.     if (originator &&
  78.         ((remote_addr.Zone != called_addr.Zone)    ||
  79.         (remote_addr.Net != called_addr.Net)    ||
  80.         (remote_addr.Node != called_addr.Node)    ||
  81.         (remote_addr.Point != called_addr.Point)))
  82.     {
  83.         (void) sprintf (k, "%s", Full_Addr_Str (&remote_addr));
  84.         (void) sprintf (j, MSG_TXT (M_CALLED), Full_Addr_Str (&called_addr), k);
  85.         status_line (j);
  86.     }
  87.     else if (!originator)
  88.         called_addr = remote_addr;
  89.  
  90.     /* If we are using an external mail agent, call it now. */
  91.  
  92.     if (remote_pickup == -2)
  93.     {
  94.         num_rakas = akas = 1;
  95.         status_line (">External Mail Session");
  96.         remote_akas[0] = called_addr;
  97.         (void) send_WaZOO ();
  98.         goto end_WaZOO;
  99.     }
  100.  
  101.     /* We need to have DCD here. */
  102.  
  103.     if (!CARRIER)
  104.         return;
  105.  
  106.     saved_addr = called_addr;
  107.     switch (remote_pickup)
  108.     {
  109.     case -1:                    /* WaZOO Session */
  110.         akas = 1;
  111.         status_line (">WaZOO Session");
  112.         remote_akas[0] = called_addr;
  113.         break;
  114.  
  115.     case 1:
  116.         status_line (">EMSI, no pickup-all");
  117.         if (num_rakas >= 1)
  118.         {
  119.             akas = 1;
  120.             remote_akas[0] = called_addr;
  121.         }
  122.         break;
  123.  
  124.     case 2:
  125.         status_line (">EMSI, pickup-all");
  126.         akas = num_rakas;
  127.         break;
  128.  
  129.     default:
  130.         akas = 0;
  131.         break;
  132.     }
  133.  
  134.     /* Flag all AKA's received */
  135.  
  136.     for (i = 0; i < akas; i++)
  137.     {
  138.         status_line (">Setting flag_file for %s", Full_Addr_Str (&remote_akas[i]));
  139.         if (flag_file (TEST_AND_SET, &remote_akas[i], 1))
  140.         {
  141.             int n;
  142.  
  143.             status_line (">Failed to set flag_file for %s", Full_Addr_Str (&remote_akas[i]));
  144.  
  145.             /* Couldn't flag it, shift everything down one */
  146.  
  147.             akas--;
  148.             for (n = i + 1; n <= akas; n++)
  149.                 remote_akas[n - 1] = remote_akas[n];
  150.  
  151.             /* Do this loop again since we just replaced this remote_aka */
  152.             i--;
  153.  
  154.         }
  155.     }
  156.  
  157.     if (akas <= 0)
  158.         goto end_WaZOO;
  159.  
  160.     num_rakas = akas;
  161.  
  162.     /* Let's look into the BiDi protocols first */
  163.  
  164.     if (janus_baud >= cur_baud.rate_value || janus_OK)
  165.     {
  166.  
  167. #ifdef HAVE_HYDRA
  168.  
  169.         /* Because Hydra is chosen first by other mailers, we have
  170.            to do the same. But if we are the called system, we told
  171.            the other guy we couldn't do it. */
  172.  
  173.         if (!originator && (remote_capabilities & DOES_IANUS) && !no_janus)
  174.             remote_capabilities &= ~DOES_HYDRA;
  175.  
  176.         if (((unsigned) remote_capabilities & DOES_HYDRA) && !no_hydra)
  177.         {
  178.             status_line ("%s Hydra", MSG_TXT (M_WAZOO_METHOD));
  179.             remote_capabilities &= ~(ZED_ZIPPER | ZED_ZAPPER | DOES_IANUS);
  180.             saved_addr = called_addr;
  181.             hydra_init (hydra_options);
  182.             (void) send_WaZOO();
  183.             hydra_deinit();
  184.             called_addr = saved_addr;
  185.             goto end_WaZOO;
  186.         }
  187. #endif /* HAVE_HYDRA */
  188.  
  189.         /* Now let's try Janus */
  190.  
  191.         if (((unsigned) remote_capabilities & DOES_IANUS) && !no_janus)
  192.         {
  193.             status_line ("%s Janus", MSG_TXT (M_WAZOO_METHOD));
  194.             Janus ();
  195.             goto end_WaZOO;
  196.         }
  197.     }
  198.  
  199.     /* See if we can both do ZEDZAP */
  200.     if ((remote_capabilities & ZED_ZAPPER) && (!no_zapzed))
  201.     {
  202.         status_line ("%s ZedZap", MSG_TXT (M_WAZOO_METHOD));
  203.         remote_capabilities &= ~(ZED_ZIPPER | DOES_HYDRA | DOES_IANUS);
  204.     }
  205.     else if ((remote_capabilities & ZED_ZIPPER) && (!no_zapzed))
  206.     {
  207.         status_line ("%s ZedZip", MSG_TXT (M_WAZOO_METHOD));
  208.         remote_capabilities &= ~(ZED_ZAPPER | DOES_HYDRA | DOES_IANUS);
  209.     }
  210.     else
  211.     {
  212.         if (remote_pickup == -1)
  213.         {
  214.             status_line ("%s DietIFNA", MSG_TXT (M_WAZOO_METHOD));
  215.             if (originator)
  216.             {
  217.                 FTSC_sender (1);
  218.             }
  219.             else
  220.             {
  221.                 (void) FTSC_receiver (1);
  222.             }
  223.         }
  224.         goto end_WaZOO;
  225.     }
  226.  
  227.     /*--------------------------------------------------------------------*/
  228.     /* ORIGINATOR: send/receive/send                                      */
  229.     /*--------------------------------------------------------------------*/
  230.     if (originator)
  231.     {
  232.         (void) send_WaZOO ();
  233.         if (!CARRIER || no_pickup)
  234.             goto end_WaZOO;
  235.         if (!get_Zmodem (CURRENT.sc_Inbound, NULL))
  236.             goto end_WaZOO;
  237.  
  238.         if (!CARRIER)
  239.             goto end_WaZOO;
  240.         iFstat = respond_to_file_requests (0, WaZOO_callback, WaZOO_time);
  241.         if (iFstat)
  242.             (void) Send_Zmodem (NULL, NULL, ((iFstat) ? END_BATCH : NOTHING_TO_DO), DO_WAZOO);
  243.         mail_finished = 1;
  244.     }
  245.  
  246.     /*--------------------------------------------------------------------*/
  247.     /* CALLED SYSTEM: receive/send/receive                                */
  248.     /*--------------------------------------------------------------------*/
  249.     else
  250.     {
  251.         if (!get_Zmodem (CURRENT.sc_Inbound, NULL))
  252.             goto end_WaZOO;
  253.         if (!CARRIER)
  254.             goto end_WaZOO;
  255.         if (remote_pickup != 0)
  256.             (void) send_WaZOO ();
  257.         if (!CARRIER || !made_request)
  258.             goto end_WaZOO;
  259.         (void) get_Zmodem (CURRENT.sc_Inbound, NULL);
  260.     }
  261.  
  262. end_WaZOO:
  263.     called_addr = saved_addr;
  264.     for (i = 0; i < akas; i++)
  265.         flag_file (CLEAR_FLAG, &remote_akas[i], 1);
  266.     status_line (MSG_TXT (M_WAZOO_END));
  267.  
  268. }                                /* WaZOO */
  269.  
  270. /*--------------------------------------------------------------------------*/
  271. /* RESPOND TO FILE REQUEST                                                  */
  272. /*--------------------------------------------------------------------------*/
  273. int 
  274. respond_to_file_requests (int f_sent,
  275.     int (*callback) (char *), int (*calltime) (long))
  276. {
  277.     char req[80];
  278.     struct stat buf;
  279.     int nfiles = 0;
  280.     FILE *fp;
  281.     int np;
  282.     char *s;
  283.     int fsent;
  284.     ADDR foo;
  285.  
  286.     fsent = f_sent;                /* copy into local var  */
  287.     /* this is for callback */
  288.     if (!(matrix_mask & TAKE_REQ))
  289.         goto done;
  290.  
  291.     for (np = 0; np <= ALIAS_CNT; np++)
  292.     {
  293.         foo = alias[np];
  294.  
  295.         if (foo.Net == 0)
  296.             break;
  297.  
  298.         /* For a point, massage the address to get the right .REQ filename */
  299.  
  300.         if (foo.Point != 0)
  301.         {
  302.             foo.Node = foo.Point;
  303.             foo.Point = 0;
  304.             foo.Net = (pvtnet > 0) ? (unsigned int) pvtnet : 0;
  305.         }
  306.  
  307.         (void) sprintf (req, request_template, CURRENT.sc_Inbound, Hex_Addr_Str (&foo), TaskNumber);
  308.  
  309.         if (!stat (req, &buf))
  310.         {
  311.             if ((fp = fopen (req, read_ascii)) == NULL)
  312.             {
  313.                 (void) got_error (MSG_TXT (M_OPEN_MSG), req);
  314.                 goto done;
  315.             }
  316.  
  317.             while (!feof (fp))
  318.             {
  319.                 req[0] = 0;
  320.                 if (fgets (req, 79, fp) == NULL)
  321.                     break;
  322.  
  323.                 /* ; as the first char is a comment */
  324.                 if (req[0] == ';')
  325.                     continue;
  326.  
  327.                 /* Get rid of the newline at the end */
  328.                 s = (char *) (req + strlen (req) - 1);
  329.                 while ((s >= req) && isspace (*s))
  330.                     *s-- = '\0';
  331.  
  332.                 if (req[0] == '\0')
  333.                     continue;
  334.  
  335.                 if ((nfiles = n_frproc (req, nfiles, callback, calltime)) < 0)
  336.                     break;
  337.             }
  338.  
  339.             (void) fclose (fp);
  340.  
  341.             (void) sprintf (req, request_template, CURRENT.sc_Inbound, Hex_Addr_Str (&foo), TaskNumber);
  342.             (void) unlink (req);
  343.             /* once we have satisfied a request, we can get out of here */
  344.             break;
  345.         }
  346.     }
  347.  
  348. done:
  349.     return fsent;
  350. }
  351.