home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_WAZOO.C < prev    next >
C/C++ Source or Header  |  1991-10-17  |  10KB  |  274 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. #include <sys\types.h>
  55. #include <sys\stat.h>
  56.  
  57.  
  58. #define WAZOO_SECTION
  59. #define MATRIX_SECTION
  60.  
  61. #include "com.h"
  62. #include "xfer.h"
  63. #include "zmodem.h"
  64. #include "keybd.h"
  65. #include "sbuf.h"
  66. #include "sched.h"
  67. #include "externs.h"
  68. #include "prototyp.h"
  69.  
  70.  
  71. extern int WaZOO_callback (char *);
  72.  
  73. /*--------------------------------------------------------------------------*/
  74. /* WaZOO                                                                    */
  75. /*--------------------------------------------------------------------------*/
  76. void WaZOO (originator)
  77. int originator;
  78. {
  79.    int stat;
  80.    int ok;            /* CML */
  81.    int i = 0;
  82.    char j[100];
  83.    char k[100];
  84.    
  85.    /*--------------------------------------------------------------------*/
  86.    /* Initialize WaZOO                                                   */
  87.    /*--------------------------------------------------------------------*/
  88.    stat =
  89.       made_request =
  90.       got_arcmail =
  91.       got_packet = 0;
  92.  
  93.    Netmail_Session = 1;
  94.  
  95.    isOriginator = originator;
  96.  
  97.    if (originator &&
  98.       ((remote_addr.Zone != called_addr.Zone) ||
  99.        (remote_addr.Net != called_addr.Net) ||
  100.        (remote_addr.Node != called_addr.Node)))
  101.       {
  102.       sprintf (k, "%s", Full_Addr_Str (&remote_addr));
  103.       sprintf (j, msgtxt[M_CALLED], Full_Addr_Str (&called_addr), k);
  104.       status_line (j);
  105.       }
  106.    else
  107.       {
  108.       called_addr.Zone = remote_addr.Zone;
  109.       called_addr.Net = remote_addr.Net;
  110.       called_addr.Node = remote_addr.Node;
  111.       }
  112.  
  113.    if (!CARRIER)
  114.       return;
  115.  
  116.    /* Try Janus first */
  117.     ok = 0;
  118.     if ((unsigned)remote_capabilities & DOES_IANUS)
  119.         {
  120.         if (lock_baud)                /* CML */
  121.             {
  122.             if ((actual_baud >= janus_baud) || janus_OK)
  123.                 ++ok;
  124.             }
  125.         else if ((btypes[baud].rate_value >= janus_baud) || janus_OK)
  126.                 ++ok;
  127.         }
  128.  
  129.    if (ok)
  130.       {
  131.       status_line ("%s Janus", msgtxt[M_WAZOO_METHOD]);
  132.       Janus ();
  133.       goto endwazoo;
  134.       }
  135.  
  136.  
  137.    /* See if we can both do ZEDZAP */
  138.    if ((remote_capabilities & ZED_ZAPPER) && (!no_zapzed))
  139.       {
  140.       status_line ("%s ZedZap", msgtxt[M_WAZOO_METHOD]);
  141.       remote_capabilities &= ~ZED_ZIPPER;
  142.       }
  143.    else if ((remote_capabilities & ZED_ZIPPER) && (!no_zapzed))
  144.       {
  145.       status_line ("%s ZedZip", msgtxt[M_WAZOO_METHOD]);
  146.       remote_capabilities &= ~ZED_ZAPPER;
  147.       }
  148.    else
  149.       {
  150.       status_line ("%s DietIFNA", msgtxt[M_WAZOO_METHOD]);
  151.       if (originator)
  152.          {
  153.          FTSC_sender (1);
  154.          }
  155.       else
  156.          {
  157.          (void) FTSC_receiver (1);
  158.          }
  159.       goto endwazoo;
  160.       }
  161.  
  162.  
  163.    /*--------------------------------------------------------------------*/
  164.    /* ORIGINATOR: send/receive/send                                      */
  165.    /*--------------------------------------------------------------------*/
  166.    if (originator)
  167.       {
  168.  
  169.       (void) send_WaZOO ();
  170.       if (!CARRIER)
  171.          goto endwazoo;
  172.       if (!get_Zmodem (CurrentNetFiles, NULL))
  173.          goto endwazoo;
  174.  
  175.       if (!CARRIER)
  176.          goto endwazoo;
  177.       stat = respond_to_file_requests (i, WaZOO_callback);
  178.       if (stat)
  179.          Send_Zmodem (NULL, NULL, ((stat) ? END_BATCH : NOTHING_TO_DO), DO_WAZOO);
  180.       mail_finished = 1;
  181.       }
  182.  
  183.    /*--------------------------------------------------------------------*/
  184.    /* CALLED SYSTEM: receive/send/receive                                */
  185.    /*--------------------------------------------------------------------*/
  186.    else
  187.       {
  188.       if (!get_Zmodem (CurrentNetFiles, NULL))
  189.          goto endwazoo;
  190.       if (!CARRIER)
  191.          goto endwazoo;
  192.       (void) send_WaZOO ();
  193.       if (!CARRIER || !made_request)
  194.          goto endwazoo;
  195.       get_Zmodem (CurrentNetFiles, NULL);
  196.       }
  197.  
  198. endwazoo:
  199.    status_line (msgtxt[M_WAZOO_END]);
  200.  
  201. }                                                /* wazoo */
  202.  
  203. /*--------------------------------------------------------------------------*/
  204. /* RESPOND TO FILE REQUEST                                                  */
  205. /*--------------------------------------------------------------------------*/
  206. int respond_to_file_requests (f_sent, callback)
  207. int f_sent;
  208. int (*callback)(char *);
  209. {
  210.    char req[80];
  211.    struct stat buf;
  212.    int n_frproc (char *, int, int (*)(char *));
  213.    int nfiles = 0;
  214.    FILE *fp;
  215.    int np;
  216.    byte *s;
  217.    int fsent;
  218.  
  219.    fsent = f_sent;                              /* copy into local var  */
  220.                                                 /* this is for callback */
  221.    if (!(matrix_mask & TAKE_REQ))
  222.       goto done;
  223.  
  224.    for (np = 0; np <= ALIAS_CNT; np++)
  225.       {
  226.       if (alias[np].Net == 0)
  227.          break;
  228.  
  229.       (void) sprintf (req, request_template, CurrentNetFiles, Hex_Addr_Str (&(alias[np])));
  230.  
  231.       if (!stat (req, &buf))
  232.          {
  233.          if ((fp = fopen (req, read_ascii)) == NULL)
  234.             {
  235.             (void) got_error (msgtxt[M_OPEN_MSG], req);
  236.             goto done;
  237.             }
  238.  
  239.          while (!feof (fp))
  240.             {
  241.             req[0] = 0;
  242.             if (fgets (req, 79, fp) == NULL)
  243.                break;
  244.  
  245.             /* ; as the first char is a comment */
  246.             if (req[0] == ';')
  247.                continue;
  248.  
  249.             /* Get rid of the newline at the end */
  250.             s = (byte *) (req + strlen (req) - 1);
  251.             while ((s >= (byte *) req) && isspace (*s))
  252.                *s-- = '\0';
  253.  
  254.             if (req[0] == '\0')
  255.                continue;
  256.  
  257.             if ((nfiles = n_frproc (req, nfiles, callback)) < 0)
  258.                break;
  259.             }
  260.  
  261.          (void) sprintf (req, request_template, CurrentNetFiles, Hex_Addr_Str (&(alias[np])));
  262.          (void) fclose (fp);
  263.  
  264.          /* Note that Opus does not delete this file, but we should I think */
  265.          (void) unlink (req);
  266.          /* once we have satisfied a request, we can get out of here */
  267.          break;
  268.          }
  269.       }
  270.  
  271. done:
  272.    return fsent;
  273. }
  274.