home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts314b4 / b_wazoo.c < prev    next >
C/C++ Source or Header  |  1992-12-29  |  8KB  |  293 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-90, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                            */
  12. /*                                                                            */
  13. /*                        BinkleyTerm "WaZOO" Processor                        */
  14. /*                                                                            */
  15. /*                                                                            */
  16. /*      For complete    details  of the licensing restrictions, please refer    */
  17. /*      to the License  agreement,  which  is published in its entirety in    */
  18. /*      the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  19. /*                                                                            */
  20. /*      USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*      BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*      THIS    AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,    OR IF YOU DO    */
  23. /*      NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*      SOFTWARE CO.    AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*      SHOULD YOU  PROCEED TO USE THIS FILE    WITHOUT HAVING    ACCEPTED THE    */
  26. /*      TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*      AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.        */
  28. /*                                                                            */
  29. /*                                                                            */
  30. /* You can contact Bit Bucket Software Co. at any one of the following        */
  31. /* addresses:                                                                */
  32. /*                                                                            */
  33. /* Bit Bucket Software Co.          FidoNet  1:104/501, 1:132/491, 1:141/491    */
  34. /* P.O. Box 460398                  AlterNet 7:491/0                            */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                  Internet f491.n132.z1.fidonet.org         */
  37. /*                                                                            */
  38. /* Please feel free to contact us at any time to share your comments about    */
  39. /* our software and/or licensing policies.                                    */
  40. /*                                                                            */
  41. /*                                                                            */
  42. /*    This module is based largely on a similar module in OPUS-CBCS V1.03b.    */
  43. /*    The original work is (C) Copyright 1987, Wynn Wagner III. The original    */
  44. /*    author has graciously allowed us to use his code in this work.            */
  45. /*                                                                            */
  46. /*--------------------------------------------------------------------------*/
  47.  
  48. #include <stdio.h>
  49. #include <signal.h>
  50. #include <ctype.h>
  51. #include <conio.h>
  52. #include <string.h>
  53. #include <stdlib.h>
  54. #ifdef __TOS__
  55. #include <ext.h>
  56. #else
  57. #include <sys\types.h>
  58. #include <sys\stat.h>
  59. #endif
  60. #include <time.h>
  61.  
  62. #include "bink.h"
  63. #include "msgs.h"
  64. #include "com.h"
  65. #include "session.h"
  66. #include "zmodem.h"
  67. #include "wazoo.h"
  68.  
  69. /*--------------------------------------------------------------------------*/
  70. /* WaZOO                                                                    */
  71. /*--------------------------------------------------------------------------*/
  72.  
  73. void WaZOO (int originator)
  74. {
  75.    int stat;
  76.    int i = 0;
  77.    char j[100];
  78.    char k[100];
  79.  
  80.    /*--------------------------------------------------------------------*/
  81.    /* Initialize WaZOO                                                     */
  82.    /*--------------------------------------------------------------------*/
  83.    stat =
  84.       made_request =
  85.       got_arcmail =
  86.       got_packet = 0;
  87.  
  88.    Netmail_Session = 1;
  89.  
  90.    isOriginator = originator;
  91.  
  92.    if (originator &&
  93.       ((remote_addr.Zone != called_addr.Zone) ||
  94.        (remote_addr.Net != called_addr.Net) ||
  95.        (remote_addr.Node != called_addr.Node) ||
  96.        (remote_addr.Point != called_addr.Point)))
  97.     {
  98.         /* Do NOT say this message if the node is a host
  99.          * or a region-Node
  100.          */
  101.         if ((called_addr.Node != 0) && (called_addr.Net >= 100))
  102.         {
  103.             sprintf (k, "%s", Pretty_Addr_Str (&remote_addr));
  104.             sprintf (j, msgtxt[M_CALLED], Pretty_Addr_Str (&called_addr), k);
  105.             status_line (j);
  106.         }
  107.     }
  108.        else
  109.     {
  110.         called_addr = remote_addr;
  111.     }
  112.  
  113.    if (!CARRIER)
  114.       return;
  115.  
  116.    /* Try Janus first */
  117.    if ((((unsigned) remote_capabilities) & DOES_IANUS) && ((janus_baud >= cur_baud) || (janus_OK)))
  118.       {
  119.       status_line ("%s Janus", msgtxt[M_WAZOO_METHOD]);
  120.       Janus ();
  121.       goto endwazoo;
  122.       }
  123.  
  124.  
  125.    /* See if we can both do ZEDZAP */
  126.    if ((remote_capabilities & ZED_ZAPPER) && (!no_zapzed))
  127.       {
  128.       status_line ("%s ZedZap", msgtxt[M_WAZOO_METHOD]);
  129.       remote_capabilities &= ~ZED_ZIPPER;
  130.       }
  131.    else if ((remote_capabilities & ZED_ZIPPER) && (!no_zapzed))
  132.       {
  133.       status_line ("%s ZedZip", msgtxt[M_WAZOO_METHOD]);
  134.       remote_capabilities &= ~ZED_ZAPPER;
  135.       }
  136.    else
  137.       {
  138.       status_line ("%s DietIFNA", msgtxt[M_WAZOO_METHOD]);
  139.       if (originator)
  140.          {
  141.          FTSC_sender (1);
  142.          }
  143.       else
  144.          {
  145.          FTSC_receiver (1);
  146.          }
  147.       goto endwazoo;
  148.       }
  149.  
  150.     blklen = 0;
  151.  
  152.    /*--------------------------------------------------------------------*/
  153.    /* ORIGINATOR: send/receive/send                                      */
  154.    /*--------------------------------------------------------------------*/
  155.    if (originator)
  156.       {
  157.  
  158.       send_WaZOO ();
  159.       if (!CARRIER)
  160.          goto endwazoo;
  161.       if (!get_Zmodem (CurrentNetFiles, NULL))
  162.          goto endwazoo;
  163.  
  164.       if (!CARRIER)
  165.          goto endwazoo;
  166.       stat = respond_to_file_requests (i, WaZOO_callback);
  167. #if 0    /* !!! this is what is causing delay before hangup probably! */
  168.       if (stat)
  169. #endif
  170.          Send_Zmodem (NULL, NULL, ((stat) ? END_BATCH : NOTHING_TO_DO), DO_WAZOO);
  171.       mail_finished = 1;
  172.       }
  173.  
  174.    /*--------------------------------------------------------------------*/
  175.    /* CALLED SYSTEM: receive/send/receive                                 */
  176.    /*--------------------------------------------------------------------*/
  177.    else
  178.       {
  179.       if (!get_Zmodem (CurrentNetFiles, NULL))
  180.          goto endwazoo;
  181.       if (!CARRIER)
  182.          goto endwazoo;
  183.       send_WaZOO ();
  184.       if (!CARRIER || !made_request)
  185.          goto endwazoo;
  186.       get_Zmodem (CurrentNetFiles, NULL);
  187.       }
  188.  
  189. endwazoo:
  190.    status_line (msgtxt[M_WAZOO_END]);
  191.  
  192. }                                                 /* wazoo */
  193.  
  194. /*--------------------------------------------------------------------------*/
  195. /* RESPOND TO FILE REQUEST                                                    */
  196. /*--------------------------------------------------------------------------*/
  197.  
  198. int respond_to_file_requests (int f_sent, int (*callback)(char *))
  199. {
  200.     char req[80];
  201.     struct stat buf;
  202.     FILE *fp;
  203.     int np;
  204.     byte *s;
  205.     char *folder;
  206.     int phase;
  207.  
  208.     int nfiles = f_sent;
  209.                                                 /* this is for callback */
  210.     time_t thetime;
  211.  
  212.     time(&thetime);
  213.     freq_accum.startTime = (long) thetime;
  214.  
  215.     if (!(matrix_mask & TAKE_REQ))
  216.         goto done;
  217.  
  218.     if(CurrentOKFile == NULL)
  219.         goto done;
  220.  
  221.     for (np = 0; np <= ALIAS_CNT; np++)
  222.     {
  223.         if (alias[np].ad.Net == 0)
  224.             break;
  225.  
  226.         for(phase = 0; phase < 3; phase++)
  227.         {
  228.             if(phase == 0)
  229.                 folder = DEFAULT.sc_Inbound;
  230.             else
  231.             if(phase == 1)
  232.             {
  233.                 folder = KNOWN.sc_Inbound;
  234.                 if(folder == DEFAULT.sc_Inbound)
  235.                     continue;
  236.             }
  237.             else
  238.             if(phase == 2)
  239.             {
  240.                 folder = PROT.sc_Inbound;
  241.                 if(folder == KNOWN.sc_Inbound)
  242.                     continue;
  243.             }
  244.  
  245.             sprintf (req, request_template, folder, Hex_Addr_Str(&alias[np].ad));
  246.  
  247.  
  248.             if (!stat (req, &buf))
  249.             {
  250.                 if ((fp = fopen (req, read_ascii)) == NULL)
  251.                 {
  252.                     got_error (msgtxt[M_OPEN_MSG], req);
  253.                     unlink(req);
  254.                     goto done;
  255.                 }
  256.  
  257.                 while (!feof (fp))
  258.                 {
  259.                     req[0] = 0;
  260.                     if (fgets (req, 79, fp) == NULL)
  261.                         break;
  262.  
  263.                     /* ; as the first char is a comment */
  264.                     if (req[0] == ';')
  265.                         continue;
  266.  
  267.                     /* Get rid of the newline at the end */
  268.                     s = (byte *) (req + strlen (req) - 1);
  269.                     while ((s >= (byte *) req) && *s && isspace (*s))
  270.                         *s-- = '\0';
  271.  
  272.                     if (req[0] == '\0')
  273.                         continue;
  274.  
  275.                     if ((nfiles = n_frproc (req, nfiles, callback)) < 0)
  276.                         break;
  277.                 }
  278.  
  279.                 sprintf (req, request_template, folder, Hex_Addr_Str(&alias[np].ad));
  280.                 fclose (fp);
  281.  
  282.                 /* Note that Opus does not delete this file, but we should I think */
  283.                 unlink (req);
  284.                 /* once we have satisfied a request, we can get out of here */
  285.                 break;
  286.             }
  287.         }    /* phase */
  288.     }
  289.  
  290. done:
  291.     return nfiles;
  292. }
  293.