home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / OS2 / BSRCP240.ZIP / B_SESSIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-22  |  10.0 KB  |  421 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.  
  70. void b_session (was_initiator)
  71. int was_initiator;
  72. {
  73.    int i;
  74.    ADDR tmp;
  75.  
  76.    tmp.Zone = 0;
  77.    tmp.Net = 0;
  78.    tmp.Node = 0;
  79.    tmp.Point = 0;
  80.    tmp.Domain = NULL;
  81.    CurrentNetFiles = DEFAULT.sc_Inbound;
  82.  
  83.    mail_finished = 0;
  84.  
  85.    time (&etm);
  86.  
  87.    freq_accum.bytes = 0L;
  88.    freq_accum.files = 0;
  89.  
  90.    if (un_attended && fullscreen) {
  91.       do_ready (msgtxt[M_READY_CONNECT]);
  92.    }
  93.  
  94.    /* Remove the old .REQ and .RSP files */
  95.  
  96.    for (i = 0; i < 10; i++) {
  97.  
  98.       if (alias[i].Net == 0)
  99.          break;
  100.       (void) sprintf (junk, "%s%s.REQ", CurrentNetFiles, Hex_Addr_Str (&(alias[i])));
  101.       (void) unlink (junk);
  102.  
  103.       (void) sprintf (junk, "%s.RSP", Hex_Addr_Str (&(alias[i])));
  104.       (void) unlink (junk);
  105.    }
  106.  
  107.    remote_capabilities = 0;
  108.    (void) flag_file (SET_SESSION_FLAG, &called_addr, 0);
  109.    if (was_initiator) {
  110.  
  111. /*
  112.  *      OUTBOUND -- meaning call was made by us.
  113.  */
  114.  
  115.       last_type (1, &remote_addr);
  116.       if (Whack_CR ()) {
  117.          return;
  118.       }
  119.  
  120.       switch (i = CallerSendSync()) {
  121.  
  122.          case 1:
  123.             FTSC_sender (0);
  124.             break;
  125.  
  126.          case 2:
  127.             if (YooHoo_Sender ()) {              /* Send Hello packet,     */
  128.                WaZOO (1);
  129.             }
  130.             break;
  131.  
  132.          default:
  133.             break;
  134.  
  135.       } /* end switch */
  136.  
  137.    } else {
  138.  
  139. /*
  140.  *      INBOUND -- meaning we were connected to by another system.
  141.  */
  142.  
  143.       switch (i = CalledRecvSync()) {
  144.  
  145.          case 1:                                 /* ESCape or Timeout     */
  146.             if (CARRIER && !mail_only) {
  147.                last_type (3, &tmp);
  148.                (void) flag_file (CLEAR_SESSION_FLAG, &called_addr, 0);
  149.                BBSexit ();
  150.             }
  151.             break;
  152.  
  153.          case 2:                                 /* FTSC Netmail Session */
  154.             if (CARRIER) {
  155.                tmp.Zone = -1000;
  156.                last_type (2, &tmp);
  157.                tmp.Zone = 0;
  158.                ++hist.mail_calls;
  159.                if (un_attended && fullscreen)
  160.                    {
  161.                    sb_move (historywin, HIST_MAIL_ROW, HIST_COL);
  162.                    (void) sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  163.                    sb_puts (historywin, (unsigned char *) junk);
  164.                    sb_show ();
  165.                    }
  166.                (void) FTSC_receiver (0);
  167.             }
  168.             break;
  169.  
  170.          case 3:                                 /* WaZOO Netmail Session*/
  171.             if (YooHoo_Receiver ()) {
  172.                last_type (1, &remote_addr);
  173.                ++hist.mail_calls;
  174.                if (un_attended && fullscreen)
  175.                   {
  176.                   sb_move (historywin, HIST_MAIL_ROW, HIST_COL);
  177.                   (void) sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  178.                   sb_puts (historywin, (unsigned char *) junk);
  179.                   }
  180.                WaZOO (0);                         /* do WaZOO!!!          */
  181.             }
  182.             break;
  183.  
  184.          default:
  185.             if ((i >= 5) && (i < (5 + num_ext_mail))) { /*See if ext mail*/
  186.                if (CARRIER) {
  187.                   last_type (4, &tmp);
  188.                   (void) flag_file (CLEAR_SESSION_FLAG, &called_addr, 0);
  189.                   UUCPexit (lev_ext_mail[i-5]);
  190.                }
  191.             }
  192.             break;
  193.  
  194.       } /* end switch */
  195.  
  196.    } /* end if (was_initiator) */
  197.  
  198.    (void) flag_file (CLEAR_SESSION_FLAG, &called_addr, 0);
  199.    return;
  200. }
  201.  
  202.  
  203. void b_init () {
  204.    got_arcmail = got_packet = got_mail = sent_mail = 0;
  205.    remote_addr.Zone = remote_addr.Net = remote_addr.Node = remote_addr.Point = 0;
  206.    remote_addr.Domain = NULL;
  207.    Netmail_Session = remote_capabilities = mail_finished = 0;
  208.    CurrentNetFiles = DEFAULT.sc_Inbound;
  209. }
  210.  
  211.  
  212. /*
  213.  * Send banner-type lines to remote. Since strange modems like Courier HST
  214.  * have a propensity for thinking they are connected when talking to a dial
  215.  * tone (but do leave CTS down just to screw us up) we have to use a timeout
  216.  * to figure out if we are in trouble, and if so, we drop DTR to make the
  217.  * bogus carrier go away.
  218.  *
  219.  * This routine is used in modules B_BBS.C and RECVSYNC.C, both of which
  220.  * are called from this module only.
  221.  *
  222.  */
  223.  
  224. int SendBanner (string)
  225. char *string;
  226. {
  227.    long t1;
  228.    register char c;
  229.  
  230.    t1 = timerset (600);                         /* 60 seconds max to put out
  231.                                                  * banner */
  232.  
  233.    while (!timeup (t1) && CARRIER) {
  234.  
  235.       if (got_ESC ())                            /* Manual abort?     */
  236.             break;                                /* Use failure logic */
  237.  
  238.       if (!OUT_FULL ()) {
  239.  
  240.          c = *string++;
  241.          if (!c || c == 0x1a)                    /* Test for end      */
  242.             return (1);                         /* Yes, success      */
  243.          SENDBYTE ((unsigned char) c);
  244.       }
  245.    }
  246.  
  247.    /*
  248.     * If we get here we had trouble. Drop DTR now to hopefully get out of
  249.     * this trouble. Flush outbound. Pause for 1 second.
  250.     */
  251.  
  252.    DTR_OFF ();
  253.    CLEAR_OUTBOUND ();
  254.  
  255.    timer (10);
  256.  
  257.    CLEAR_INBOUND ();
  258.  
  259.    return (0);
  260. }
  261.  
  262.  
  263. int flag_file (function, address, do_stat)
  264. int function;
  265. ADDR *address;
  266. int do_stat;
  267. {
  268.  
  269.    FILE *fptr;
  270.    char *HoldName;
  271.    static ADDR last_set;
  272.    char flagname[128];
  273.    char tmpname[128];
  274.  
  275.    if (!TaskNumber)
  276.       return (FALSE);
  277.  
  278.    HoldName = HoldAreaNameMunge (address);
  279.  
  280.    switch (function)
  281.       {
  282.       case INITIALIZE:
  283.       last_set.Zone = -1;
  284.       break;
  285.  
  286.       case SET_SESSION_FLAG:
  287.       /* At the start of a session, set up the task number */
  288.       if (flag_dir)
  289.          {
  290.          sprintf (flagname, "%sTask.%d",
  291.                                flag_dir, TaskNumber);
  292.          fptr = fopen (flagname, "wb");
  293.          fclose (fptr);
  294.          }
  295.       return (FALSE);
  296.  
  297.       case CLEAR_SESSION_FLAG:
  298.       /* At the end of a session, delete the task file */
  299.       if (flag_dir)
  300.          {
  301.          sprintf (flagname, "%sTask.%d",
  302.                                flag_dir, TaskNumber);
  303.          unlink (flagname);
  304.          }
  305.       return (FALSE);
  306.  
  307.       case TEST_AND_SET:
  308.  
  309.    /*
  310.     * First see if we already HAVE this lock! If so, return now.
  311.     *
  312.     */
  313.  
  314.       if (memcmp (&last_set, address, sizeof (ADDR)) == 0)
  315.          return (FALSE);
  316.  
  317.    /*
  318.     * Check for the INMAIL.$$$ file.
  319.     *
  320.     */
  321.  
  322.       if (flag_dir != NULL)
  323.          {
  324.          sprintf (tmpname, "%sINMAIL.$$$",flag_dir);
  325.  
  326.          if ((fptr = fopen (tmpname, "rb")) != NULL)
  327.             {
  328.             fclose (fptr);
  329.             if (!CARRIER)
  330.                if (do_stat)
  331.                   status_line (":Other Node Processing Mail");
  332.             return (TRUE);
  333.             }
  334.          }
  335.  
  336.    /*
  337.     * Next create a file using a temporary name.
  338.     *
  339.     */
  340.  
  341.       sprintf (tmpname, "%sBINK%04x.BSY",HoldName,TaskNumber);
  342.       fptr = fopen (tmpname, "wb");
  343.       if (fptr == NULL)
  344.          {
  345.          if (do_stat)
  346.             status_line (msgtxt[M_FAILED_CREATE_FLAG],tmpname);
  347.          return (TRUE);
  348.          }
  349.       fclose (fptr);
  350.  
  351.    /*
  352.     * Now the test&set. Attempt to rename the file.
  353.     * If we succeed, we have the lock. If we do not,
  354.     * delete the temp file.
  355.     *
  356.     */
  357.  
  358.       sprintf (flagname, "%s%04x%04x.BSY",
  359.                             HoldName, address->Net,address->Node);
  360.       if (!rename (tmpname, flagname))
  361.          {
  362.          if (do_stat)
  363.             status_line (msgtxt[M_CREATED_FLAGFILE],flagname);
  364.          memcpy (&last_set, address, sizeof (ADDR));
  365.          return (FALSE);
  366.          }
  367.       if (do_stat)
  368.          status_line (msgtxt[M_THIS_ADDRESS_LOCKED], Full_Addr_Str (address));
  369.       unlink (tmpname);
  370.       return (TRUE);
  371.  
  372.       case CLEAR_FLAG:
  373.  
  374.    /*
  375.     * Make sure we need to clear something.
  376.     * Zone should be something other than -1 if that's the case.
  377.     *
  378.     */
  379.       if (last_set.Zone == -1)
  380.          return (TRUE);
  381.  
  382.    /*
  383.     * Next compare what we want to clear with what we think we have.
  384.     *
  385.     */
  386.  
  387.       if (memcmp (&last_set, address, sizeof (ADDR)) != 0)
  388.          {
  389.          if (do_stat)
  390.             status_line (msgtxt[M_BAD_CLEAR_FLAGFILE],
  391.                             Full_Addr_Str (address));
  392.          return (TRUE);
  393.          }
  394.    /*
  395.     * We match. Unlink the flag file. If we're successful, jam a -1
  396.     * into our saved Zone.
  397.     *
  398.     */
  399.  
  400.       sprintf (flagname, "%s%04x%04x.BSY",
  401.                             HoldName, address->Net,address->Node);
  402.       if (!unlink (flagname))
  403.          {
  404.          if (do_stat)
  405.             status_line (msgtxt[M_CLEARED_FLAGFILE], flagname);
  406.          last_set.Zone = -1;
  407.          return (TRUE);
  408.          }
  409.  
  410.       if (do_stat)
  411.          status_line (msgtxt[M_FAILED_CLEAR_FLAG],flagname);
  412.       return (FALSE);
  413.  
  414.       default:
  415.       break;
  416.       }
  417.  
  418.    return (TRUE);
  419. }
  420.  
  421.