home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_WAZOO.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  10KB  |  252 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-91, 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.250.    */
  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:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.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 this file before any other includes or defines! */
  49.  
  50. #include "includes.h"
  51.  
  52. extern int WaZOO_callback (char *);
  53. extern int WaZOO_time (long);
  54.  
  55. /*--------------------------------------------------------------------------*/
  56. /* WaZOO                                                                    */
  57. /*--------------------------------------------------------------------------*/
  58. void WaZOO (int originator)
  59. {
  60.    int stat;
  61.    int i = 0;
  62.    char j[200];
  63.    char k[100];
  64.    
  65.    /*--------------------------------------------------------------------*/
  66.    /* Initialize WaZOO                                                   */
  67.    /*--------------------------------------------------------------------*/
  68.    stat         =
  69.    made_request =
  70.    got_arcmail  =
  71.    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 (!CARRIER)
  91.       return;
  92.  
  93.    if (flag_file (TEST_AND_SET, &called_addr, 1))
  94.       goto endwazoo;
  95.  
  96.    /* Try Janus first */
  97.    if ((((unsigned) remote_capabilities) & DOES_IANUS) && ((janus_baud >= cur_baud.rate_value) || (janus_OK)))
  98.       {
  99.       status_line ("%s Janus", MSG_TXT(M_WAZOO_METHOD));
  100.       Janus ();
  101.       goto endwazoo;
  102.       }
  103.  
  104.  
  105.    /* See if we can both do ZEDZAP */
  106.    if ((remote_capabilities & ZED_ZAPPER) && (!no_zapzed))
  107.       {
  108.       status_line ("%s ZedZap", MSG_TXT(M_WAZOO_METHOD));
  109.       remote_capabilities &= ~ZED_ZIPPER;
  110.       }
  111.    else if ((remote_capabilities & ZED_ZIPPER) && (!no_zapzed))
  112.       {
  113.       status_line ("%s ZedZip", MSG_TXT(M_WAZOO_METHOD));
  114.       remote_capabilities &= ~ZED_ZAPPER;
  115.       }
  116.    else
  117.       {
  118.       status_line ("%s DietIFNA", MSG_TXT(M_WAZOO_METHOD));
  119.       if (originator)
  120.          {
  121.          FTSC_sender (1);
  122.          }
  123.       else
  124.          {
  125.          (void) FTSC_receiver (1);
  126.          }
  127.       goto endwazoo;
  128.       }
  129.  
  130.  
  131.    /*--------------------------------------------------------------------*/
  132.    /* ORIGINATOR: send/receive/send                                      */
  133.    /*--------------------------------------------------------------------*/
  134.    if (originator)
  135.       {
  136.  
  137.       (void) send_WaZOO ();
  138.       if (!CARRIER)
  139.          goto endwazoo;
  140.       if (!get_Zmodem (CURRENT.sc_Inbound, NULL))
  141.          goto endwazoo;
  142.  
  143.       if (!CARRIER)
  144.          goto endwazoo;
  145.       stat = respond_to_file_requests (i, WaZOO_callback, WaZOO_time);
  146.       if (stat)
  147.          (void) Send_Zmodem (NULL, NULL, ((stat) ? END_BATCH : NOTHING_TO_DO), DO_WAZOO);
  148.       mail_finished = 1;
  149.       }
  150.  
  151.    /*--------------------------------------------------------------------*/
  152.    /* CALLED SYSTEM: receive/send/receive                                */
  153.    /*--------------------------------------------------------------------*/
  154.    else
  155.       {
  156.       if (!get_Zmodem (CURRENT.sc_Inbound, NULL))
  157.          goto endwazoo;
  158.       if (!CARRIER)
  159.          goto endwazoo;
  160.       (void) send_WaZOO ();
  161.       if (!CARRIER || !made_request)
  162.          goto endwazoo;
  163.       (void) get_Zmodem (CURRENT.sc_Inbound, NULL);
  164.       }
  165.  
  166. endwazoo:
  167.    (void) flag_file (CLEAR_FLAG, &called_addr, 1);
  168.    status_line (MSG_TXT(M_WAZOO_END));
  169.  
  170. }                                                /* wazoo */
  171.  
  172. /*--------------------------------------------------------------------------*/
  173. /* RESPOND TO FILE REQUEST                                                  */
  174. /*--------------------------------------------------------------------------*/
  175. int respond_to_file_requests (int f_sent, 
  176.                               int (*callback)(char *), int (*calltime)(long))
  177. {
  178.    char req[80];
  179.    struct stat buf;
  180.    int nfiles = 0;
  181.    FILE *fp;
  182.    int np;
  183.    char *s;
  184.    int fsent;
  185.    ADDR foo;
  186.  
  187.    fsent = f_sent;                              /* copy into local var  */
  188.                                                 /* this is for callback */
  189.    if (!(matrix_mask & TAKE_REQ))
  190.       goto done;
  191.  
  192.    for (np = 0; np <= ALIAS_CNT; np++)
  193.       {
  194.       foo = alias[np];
  195.  
  196.       if (foo.Net == 0)
  197.          break;
  198.  
  199.    /* For a point, massage the address to get the right .REQ filename */
  200.  
  201.       if (foo.Point != 0)
  202.          {
  203.          foo.Node  = foo.Point;
  204.          foo.Point = 0;
  205.          foo.Net   = (pvtnet > 0) ? (unsigned int) pvtnet : 0;
  206.          }        
  207.  
  208.       (void) sprintf (req, request_template, CURRENT.sc_Inbound, Hex_Addr_Str (&foo));
  209.  
  210.       if (!stat (req, &buf))
  211.          {
  212.          if ((fp = fopen (req, read_ascii)) == NULL)
  213.             {
  214.             (void) got_error (MSG_TXT(M_OPEN_MSG), req);
  215.             goto done;
  216.             }
  217.  
  218.          while (!feof (fp))
  219.             {
  220.             req[0] = 0;
  221.             if (fgets (req, 79, fp) == NULL)
  222.                break;
  223.  
  224.             /* ; as the first char is a comment */
  225.             if (req[0] == ';')
  226.                continue;
  227.  
  228.             /* Get rid of the newline at the end */
  229.             s = (char *) (req + strlen (req) - 1);
  230.             while ((s >= req) && isspace (*s))
  231.                *s-- = '\0';
  232.  
  233.             if (req[0] == '\0')
  234.                continue;
  235.  
  236.             if ((nfiles = n_frproc (req, nfiles, callback, calltime)) < 0)
  237.                break;
  238.             }
  239.  
  240.          (void) fclose (fp);
  241.  
  242.          (void) sprintf (req, request_template, CURRENT.sc_Inbound, Hex_Addr_Str (&foo));
  243.          (void) unlink (req);
  244.          /* once we have satisfied a request, we can get out of here */
  245.          break;
  246.          }
  247.       }
  248.  
  249. done:
  250.    return fsent;
  251. }
  252.