home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_SESSIO.C < prev    next >
Text File  |  1991-10-17  |  11KB  |  444 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. /*                  This module was written by Vince Perriello                */
  14. /*                                                                            */
  15. /*                                                                            */
  16. /*                     BinkleyTerm Mail Session Initiator                     */
  17. /*                                                                            */
  18. /*                                                                            */
  19. /*      For complete    details  of the licensing restrictions, please refer    */
  20. /*      to the License  agreement,  which  is published in its entirety in    */
  21. /*      the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  22. /*                                                                            */
  23. /*      USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*      BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*      THIS    AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,    OR IF YOU DO    */
  26. /*      NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*      SOFTWARE CO.    AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*      SHOULD YOU  PROCEED TO USE THIS FILE    WITHOUT HAVING    ACCEPTED THE    */
  29. /*      TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*      AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.        */
  31. /*                                                                            */
  32. /*                                                                            */
  33. /* You can contact Bit Bucket Software Co. at any one of the following        */
  34. /* addresses:                                                                */
  35. /*                                                                            */
  36. /* Bit Bucket Software Co.          FidoNet  1:104/501, 1:132/491, 1:141/491    */
  37. /* P.O. Box 460398                  AlterNet 7:491/0                            */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                  Internet f491.n132.z1.fidonet.org         */
  40. /*                                                                            */
  41. /* Please feel free to contact us at any time to share your comments about    */
  42. /* our software and/or licensing policies.                                    */
  43. /*                                                                            */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. #include <stdio.h>
  47. #ifdef __TURBOC__
  48. #include <mem.h>
  49. #else
  50. #include <memory.h>
  51. #endif
  52. #include <time.h>
  53.  
  54. #define WAZOO_SECTION
  55. #define MATRIX_SECTION
  56.  
  57. #include "com.h"
  58. #include "xfer.h"
  59. #include "zmodem.h"
  60. #include "keybd.h"
  61. #include "sbuf.h"
  62. #include "sched.h"
  63. #include "externs.h"
  64. #include "prototyp.h"
  65. #include "defines.h"
  66.  
  67. extern int CallerSendSync (void);
  68. extern int CalledRecvSync (void);
  69. extern void pascal com_direct(unsigned char c);        /* CML */
  70.  
  71. void b_session (was_initiator)
  72. int was_initiator;
  73. {
  74.    int i;
  75.    ADDR tmp;
  76.  
  77.    tmp.Zone = 0;
  78.    tmp.Net = 0;
  79.    tmp.Node = 0;
  80.    tmp.Point = 0;
  81.    tmp.Domain = NULL;
  82.    CurrentNetFiles = DEFAULT.sc_Inbound;
  83.  
  84.    mail_finished = 0;
  85.  
  86.    time (&etm);
  87.  
  88.    freq_accum.bytes = 0L;
  89.    freq_accum.files = 0;
  90.  
  91.    if (un_attended && fullscreen) {
  92.       do_ready (msgtxt[M_READY_CONNECT]);
  93.    }
  94.  
  95.    /* Remove the old .REQ and .RSP files */
  96.  
  97.    for (i = 0; i < 10; i++) {
  98.  
  99.       if (alias[i].Net == 0)
  100.          break;
  101.       (void) sprintf (junk, "%s%s.REQ", CurrentNetFiles, Hex_Addr_Str (&(alias[i])));
  102.       (void) unlink (junk);
  103.  
  104.       (void) sprintf (junk, "%s.RSP", Hex_Addr_Str (&(alias[i])));
  105.       (void) unlink (junk);
  106.    }
  107.  
  108.    remote_capabilities = 0;
  109.    (void) flag_file (SET_SESSION_FLAG, &called_addr, 0);
  110.    if (was_initiator) {
  111.  
  112. /*
  113.  *      OUTBOUND -- meaning call was made by us.
  114.  */
  115.  
  116.     if (limit_baud)                    /* CML - if my nickel, don't pay for a screwed up connect */
  117.         {
  118.         int ok = 1;
  119.  
  120.         if (lock_baud)
  121.             {
  122.             if (limit_baud > actual_baud)
  123.                 ok = 0;
  124.             }
  125.         else if (limit_baud > btypes[baud].rate_value)
  126.             ok = 0;
  127.  
  128.         if (!ok)
  129.             {
  130.             status_line("!Baudrate of connect is below LimitBaud.");
  131.             bad_call(&called_addr,1);    /* set up a bad call file : Carrier Unsuccessful */
  132.             mdm_hangup ();
  133.             return;
  134.             }
  135.         }
  136.  
  137.       last_type (1, &remote_addr);
  138.       if (Whack_CR ()) {
  139.          return;
  140.       }
  141.  
  142.       switch (i = CallerSendSync()) {
  143.  
  144.          case 1:
  145.             FTSC_sender (0);
  146.             break;
  147.  
  148.          case 2:
  149.             if (YooHoo_Sender ()) {              /* Send Hello packet,     */
  150.                WaZOO (1);
  151.             }
  152.             break;
  153.  
  154.          default:
  155.             break;
  156.  
  157.       } /* end switch */
  158.  
  159.    } else {
  160.  
  161. /*
  162.  *      INBOUND -- meaning we were connected to by another system.
  163.  */
  164.  
  165.       switch (i = CalledRecvSync()) {
  166.  
  167.          case 1:                                 /* ESCape or Timeout     */
  168.             if (CARRIER && !mail_only) {
  169.                last_type (3, &tmp);
  170.                (void) flag_file (CLEAR_SESSION_FLAG, &called_addr, 0);
  171.                BBSexit ();
  172.             }
  173.             break;
  174.  
  175.          case 2:                                 /* FTSC Netmail Session */
  176.             if (CARRIER) {
  177.                tmp.Zone = -1000;
  178.                last_type (2, &tmp);
  179.                tmp.Zone = 0;
  180.                ++hist.mail_calls;
  181.                if (un_attended && fullscreen)
  182.                    {
  183.                    sb_move (historywin, HIST_MAIL_ROW, HIST_COL);
  184.                    (void) sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  185.                    sb_puts (historywin, (unsigned char *) junk);
  186.                    sb_show ();
  187.                    }
  188.                (void) FTSC_receiver (0);
  189.             }
  190.             break;
  191.  
  192.          case 3:                                 /* WaZOO Netmail Session*/
  193.             if (YooHoo_Receiver ()) {
  194.                last_type (1, &remote_addr);
  195.                ++hist.mail_calls;
  196.                if (un_attended && fullscreen)
  197.                   {
  198.                   sb_move (historywin, HIST_MAIL_ROW, HIST_COL);
  199.                   (void) sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  200.                   sb_puts (historywin, (unsigned char *) junk);
  201.                   }
  202.                WaZOO (0);                         /* do WaZOO!!!          */
  203.             }
  204.             break;
  205.  
  206.          default:
  207.             if ((i >= 5) && (i < (5 + num_ext_mail))) { /*See if ext mail*/
  208.                if (CARRIER) {
  209.                   last_type (4, &tmp);
  210.                   (void) flag_file (CLEAR_SESSION_FLAG, &called_addr, 0);
  211.                   UUCPexit (lev_ext_mail[i-5]);
  212.                }
  213.             }
  214.             break;
  215.  
  216.       } /* end switch */
  217.  
  218.    } /* end if (was_initiator) */
  219.  
  220.    (void) flag_file (CLEAR_SESSION_FLAG, &called_addr, 0);
  221.    return;
  222. }
  223.  
  224.  
  225. void b_init () {
  226.    got_arcmail = got_packet = got_mail = sent_mail = 0;
  227.    remote_addr.Zone = remote_addr.Net = remote_addr.Node = remote_addr.Point = 0;
  228.    remote_addr.Domain = NULL;
  229.    Netmail_Session = remote_capabilities = mail_finished = 0;
  230.    CurrentNetFiles = DEFAULT.sc_Inbound;
  231. }
  232.  
  233.  
  234. /*
  235.  * Send banner-type lines to remote. Since strange modems like Courier HST
  236.  * have a propensity for thinking they are connected when talking to a dial
  237.  * tone (but do leave CTS down just to screw us up) we have to use a timeout
  238.  * to figure out if we are in trouble, and if so, we drop DTR to make the
  239.  * bogus carrier go away.
  240.  *
  241.  * This routine is used in modules B_BBS.C and RECVSYNC.C, both of which
  242.  * are called from this module only.
  243.  *
  244.  */
  245.  
  246. int SendBanner (string)
  247. char *string;
  248. {
  249.    long t1;
  250.    register char c;
  251.  
  252.    t1 = timerset (600);                         /* 60 seconds max to put out banner */
  253.  
  254.    while (!timeup (t1) && CARRIER) {
  255.  
  256.       if (got_ESC ())                            /* Manual abort?     */
  257.             break;                                /* Use failure logic */
  258.  
  259.       if (!OUT_FULL ()) {
  260.  
  261.          c = *string++;
  262.          if (!c || c == 0x1a)                    /* Test for end      */
  263.             return (1);                         /* Yes, success      */
  264.          com_direct(c);                    /* com_direct is CML's */
  265.  
  266.       }
  267.    }
  268.  
  269.    /*
  270.     * If we get here we had trouble. Drop DTR now to hopefully get out of
  271.     * this trouble. Flush outbound. Pause for 1 second.
  272.     */
  273.  
  274.    DTR_OFF ();
  275.    CLEAR_OUTBOUND ();
  276.  
  277.    timer (10);
  278.  
  279.    CLEAR_INBOUND ();
  280.  
  281.    return (0);
  282. }
  283.  
  284.  
  285. int flag_file (function, address, do_stat)
  286. int function;
  287. ADDR *address;
  288. int do_stat;
  289. {
  290.  
  291.    FILE *fptr;
  292.    char *HoldName;
  293.    static ADDR last_set;
  294.    char flagname[128];
  295.    char tmpname[128];
  296.  
  297.    if (!TaskNumber)
  298.       return (FALSE);
  299.  
  300.    HoldName = HoldAreaNameMunge (address);
  301.  
  302.    switch (function)
  303.       {
  304.       case INITIALIZE:
  305.       last_set.Zone = -1;
  306.       break;
  307.  
  308.       case SET_SESSION_FLAG:
  309.       /* At the start of a session, set up the task number */
  310.       if (flag_dir)
  311.          {
  312.          sprintf (flagname, "%sTask.%d",
  313.                                flag_dir, TaskNumber);
  314.          fptr = fopen (flagname, "wb");
  315.          fclose (fptr);
  316.          }
  317.       return (FALSE);
  318.  
  319.       case CLEAR_SESSION_FLAG:
  320.       /* At the end of a session, delete the task file */
  321.       if (flag_dir)
  322.          {
  323.          sprintf (flagname, "%sTask.%d",
  324.                                flag_dir, TaskNumber);
  325.          unlink (flagname);
  326.          }
  327.       return (FALSE);
  328.  
  329.       case TEST_AND_SET:
  330.  
  331.    /*
  332.     * First see if we already HAVE this lock! If so, return now.
  333.     *
  334.     */
  335.  
  336.       if (memcmp (&last_set, address, sizeof (ADDR)) == 0)
  337.          return (FALSE);
  338.  
  339.    /*
  340.     * Check for the INMAIL.$$$ file.
  341.     *
  342.     */
  343.  
  344.       if (flag_dir != NULL)
  345.          {
  346.          sprintf (tmpname, "%sINMAIL.$$$",flag_dir);
  347.  
  348.          if ((fptr = fopen (tmpname, "rb")) != NULL)
  349.             {
  350.             fclose (fptr);
  351.             if (!CARRIER)
  352.                if (do_stat)
  353.                   status_line (":Other Node Processing Mail");
  354.             return (TRUE);
  355.             }
  356.          }
  357.  
  358.    /*
  359.     * Next create a file using a temporary name.
  360.     *
  361.     */
  362.  
  363.       sprintf (tmpname, "%sBINK%04x.BSY",HoldName,TaskNumber);
  364.       fptr = fopen (tmpname, "wb");
  365.       if (fptr == NULL)
  366.          {
  367.          if (do_stat)
  368.             status_line (msgtxt[M_FAILED_CREATE_FLAG],tmpname);
  369.          return (TRUE);
  370.          }
  371.       fclose (fptr);
  372.  
  373.    /*
  374.     * Now the test&set. Attempt to rename the file.
  375.     * If we succeed, we have the lock. If we do not,
  376.     * delete the temp file.
  377.     *
  378.     */
  379.  
  380.       sprintf (flagname, "%s%04x%04x.BSY",
  381.                             HoldName, address->Net,address->Node);
  382.       if (!rename (tmpname, flagname))
  383.          {
  384.          if (do_stat)
  385.             status_line (msgtxt[M_CREATED_FLAGFILE],flagname);
  386.          memcpy (&last_set, address, sizeof (ADDR));
  387.          return (FALSE);
  388.          }
  389.       if (do_stat)
  390.          status_line (msgtxt[M_THIS_ADDRESS_LOCKED], Full_Addr_Str (address));
  391.       unlink (tmpname);
  392.       return (TRUE);
  393.  
  394.       case CLEAR_FLAG:
  395.  
  396.    /*
  397.     * Make sure we need to clear something.
  398.     * Zone should be something other than -1 if that's the case.
  399.     *
  400.     */
  401.       if (last_set.Zone == -1)
  402.          return (TRUE);
  403.  
  404.    /*
  405.     * Next compare what we want to clear with what we think we have.
  406.     *
  407.     */
  408.  
  409.       if (memcmp (&last_set, address, sizeof (ADDR)) != 0)
  410.          {
  411.          if (do_stat)
  412.             status_line (msgtxt[M_BAD_CLEAR_FLAGFILE],
  413.                             Full_Addr_Str (address));
  414.          return (TRUE);
  415.          }
  416.    /*
  417.     * We match. Unlink the flag file. If we're successful, jam a -1
  418.     * into our saved Zone.
  419.     *
  420.     */
  421.  
  422.       sprintf (flagname, "%s%04x%04x.BSY",
  423.                             HoldName, address->Net,address->Node);
  424.       if (!unlink (flagname))
  425.          {
  426.          if (do_stat)
  427.             status_line (msgtxt[M_CLEARED_FLAGFILE], flagname);
  428.          last_set.Zone = -1;
  429.          return (TRUE);
  430.          }
  431.  
  432.       if (do_stat)
  433.          status_line (msgtxt[M_FAILED_CLEAR_FLAG],flagname);
  434.       return (FALSE);
  435.  
  436.       default:
  437.       break;
  438.       }
  439.  
  440.    return (TRUE);
  441. }
  442.  
  443. 
  444.