home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / YOOHOO.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  19KB  |  596 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. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                     BinkleyTerm "YooHoo" Processor                       */
  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.250.    */
  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:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.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.  
  47. /* Include this file before any other includes or defines! */
  48.  
  49. #include "includes.h"
  50.  
  51. int Send_Hello_Packet (int);
  52. int Recv_Hello_Packet (int);
  53.  
  54. /*--------------------------------------------------------------------------*/
  55. /* YOOHOO SENDER    (used when I am the CALLING system)                     */
  56. /*--------------------------------------------------------------------------*/
  57. int YooHoo_Sender (void)
  58. {
  59.    char *sptr;
  60.  
  61.    if (un_attended && fullscreen)
  62.       {
  63.       sb_move (file_hWnd, 2, 2);
  64.       FlLnModeSet( FILE_LN_2, 0 );
  65.       sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 ), "YooHoo" );
  66.       sb_show ();
  67.       }
  68.    else
  69.       {
  70.       set_xy ("YooHoo ");
  71.       }
  72.  
  73.    /*--------------------------------------------------------------------*/
  74.    /* Clean up any mess that may be around                               */
  75.    /*--------------------------------------------------------------------*/
  76.    CLEAR_OUTBOUND ();
  77.    CLEAR_INBOUND ();
  78.    XON_DISABLE ();
  79.  
  80.    if (!Send_Hello_Packet (1))
  81.       sptr = MSG_TXT(M_HE_HUNG_UP);
  82.  
  83.    else
  84.       {
  85.       if (TIMED_READ (30) == YOOHOO)
  86.          return Recv_Hello_Packet (1);
  87.  
  88.       status_line ("!No YOOHOO/2U2");
  89.       sptr = IDUNNO_msg;
  90.       }
  91.  
  92.    status_line (sptr);
  93.    return (0);
  94. }
  95.  
  96. /*--------------------------------------------------------------------------*/
  97. /* YOOHOO RECEIVER  (Used when I am the CALLED system)                      */
  98. /*--------------------------------------------------------------------------*/
  99.  
  100. int YooHoo_Receiver (void)
  101. {
  102.    int i;
  103.    int c;
  104.  
  105.    if (un_attended && fullscreen)
  106.       {
  107.       sb_move (file_hWnd, 2, 2);
  108.       FlLnModeSet( FILE_LN_2, 0 );
  109.       sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 ), "YooHoo" );
  110.       sb_show ();
  111.       }
  112.    else
  113.       {
  114.       set_xy ("YooHoo ");
  115.       }
  116.  
  117.    /*--------------------------------------------------------------------*/
  118.    /* Clean up any mess that may be around                               */
  119.    /*--------------------------------------------------------------------*/
  120.    CLEAR_OUTBOUND ();
  121.    CLEAR_INBOUND ();
  122.    XON_DISABLE ();
  123.  
  124.    if (Recv_Hello_Packet(0) == 0)
  125.       return (0);
  126.  
  127.    for (i = 0; (CARRIER) && (i < 10); i++)
  128.       {
  129.       if ((c = TIMED_READ (10)) == ENQ)
  130.          {
  131.          if ((i = Send_Hello_Packet (0)) == 0)
  132.             b_init ();
  133.          return (i);
  134.          }
  135.  
  136.       if (c > 0)
  137.          {
  138.          (void) printf ("[%x] ", c);
  139.  
  140.          /* Delay one second, then try again */
  141.          big_pause (1);
  142.  
  143.          CLEAR_INBOUND ();
  144.          }
  145.  
  146.       SENDBYTE (YOOHOO);
  147.       }
  148.  
  149.    status_line (MSG_TXT(M_FUBAR_MSG));
  150.    b_init ();
  151.    return (0);
  152.  
  153. }                                                /* YooHoo Receiver */
  154.  
  155. /*--------------------------------------------------------------------------*/
  156. /* SEND HELLO PACKET                                                        */
  157. /*--------------------------------------------------------------------------*/
  158. int Send_Hello_Packet (int Sender)
  159. {
  160.    int i;
  161.    struct _Hello Hello;
  162.    char *sptr;
  163.    long response_timer;
  164.    word crc;
  165.    word num_errs = 0;
  166.    word can_do_domain = 0;
  167.    char junkbuff[128];
  168.  
  169.    /*--------------------------------------------------------------------*/
  170.    /* Setup HELLO structure                                              */
  171.    /*--------------------------------------------------------------------*/
  172.    (void) memset ((char *) &Hello, 0, sizeof (struct _Hello));
  173.  
  174.    Hello.signal = 'o';
  175.    Hello.hello_version = 1;
  176.  
  177.    Hello.product = PRDCT_CODE;
  178.    Hello.product_maj = BINK_MAJVERSION;
  179.    Hello.product_min = BINK_MINVERSION;
  180.  
  181.    (void) strncpy (Hello.sysop, sysop, 19);
  182.    Hello.sysop[19] = '\0';
  183.  
  184.    Hello.my_zone = alias[assumed].Zone;
  185.    if ((pvtnet >= 0) && (Sender) &&
  186.        ((called_addr.Zone == boss_addr.Zone) || (called_addr.Zone == 0) || (boss_addr.Zone == 0)) &&
  187.        (called_addr.Net == boss_addr.Net) && (called_addr.Node == boss_addr.Node) &&
  188.        ((called_addr.Domain == boss_addr.Domain) || (boss_addr.Domain == NULL) || (called_addr.Domain == NULL)))
  189.       {
  190.       Hello.my_net = boss_addr.Net;
  191.       Hello.my_node = boss_addr.Node;
  192.       Hello.my_point = alias[assumed].Node;
  193.       }
  194.    else
  195.       {
  196.       Hello.my_net = alias[assumed].Net;
  197.       Hello.my_node = alias[assumed].Node;
  198.       Hello.my_point = alias[assumed].Point;
  199.       }
  200. /*
  201.  * If we are the calling system, turn on all our capabilities.
  202.  * If we are the called system, choose from the set that the
  203.  * caller gave us, and only send the one we prefer.
  204.  */
  205.    can_do_domain = (my_addr.Domain != NULL) ? DO_DOMAIN : 0;
  206.    if (!Sender)
  207.       {
  208.       can_do_domain = remote_capabilities & can_do_domain;
  209.       if (remote_capabilities & my_capabilities & DOES_IANUS)
  210.          Hello.capabilities = DOES_IANUS;
  211.       else if (remote_capabilities & my_capabilities & ZED_ZAPPER)
  212.          Hello.capabilities = ZED_ZAPPER;
  213.       else if (remote_capabilities & my_capabilities & ZED_ZIPPER)
  214.          Hello.capabilities = ZED_ZIPPER;
  215.       else if (remote_capabilities & my_capabilities & Y_DIETIFNA)
  216.          Hello.capabilities = Y_DIETIFNA;
  217.       }
  218.    else Hello.capabilities = my_capabilities;
  219.  
  220.    (void) strncpy (Hello.my_name, system_name, 58);
  221.    Hello.my_name[58] = '\0';
  222.    Hello.capabilities |= can_do_domain;
  223.    if (can_do_domain && (alias[assumed].Domain != NULL))
  224.       {
  225.       if (strlen (system_name) + strlen (alias[assumed].Domain) > 57)
  226.          {
  227.          Hello.my_name[57 - strlen (alias[assumed].Domain)] = '\0';
  228.          }
  229.       sptr = Hello.my_name + strlen (Hello.my_name) + 1;
  230.       (void) strcpy (sptr, alias[assumed].Domain);
  231.       }
  232.  
  233.    if (n_getpassword (&remote_addr))
  234.       {
  235.       (void) strncpy ((char *)Hello.my_password, remote_password, 8);
  236.       }
  237.  
  238.    if ((matrix_mask & TAKE_REQ) &&
  239.        ((!Sender) || (on_our_nickel)))
  240.       Hello.capabilities |= WZ_FREQ;
  241.  
  242.    /*--------------------------------------------------------------------*/
  243.    /* Disable handshaking and ^C/^K handling                             */
  244.    /*--------------------------------------------------------------------*/
  245.    XON_DISABLE ();
  246.  
  247.    /*--------------------------------------------------------------------*/
  248.    /* Send the packet.                                                   */
  249.    /* Load outbound buffer quickly, and get modem busy sending.          */
  250.    /*--------------------------------------------------------------------*/
  251.  
  252. xmit_packet:
  253.  
  254.    SENDBYTE (0x1f);
  255.  
  256.    sptr = (char *) (&Hello);
  257.    SENDCHARS (sptr, 128, 1);
  258.  
  259.    /*--------------------------------------------------------------------*/
  260.    /* Calculate CRC while modem is sending its buffer                    */
  261.    /*--------------------------------------------------------------------*/
  262.    for (crc = i = 0; i < 128; i++)
  263.       {
  264.       crc = xcrc (crc, (byte) sptr[i]);
  265.       }
  266.  
  267.    CLEAR_INBOUND ();
  268.  
  269.    SENDBYTE ((unsigned char) (crc >> 8));
  270.    SENDBYTE ((unsigned char) (crc & 0xff));
  271.  
  272.    response_timer = timerset (4000);
  273.  
  274.    while (!timeup(response_timer) && CARRIER)
  275.       {
  276.       if (!CHAR_AVAIL ())
  277.          {
  278.          if (got_ESC ())
  279.             {
  280.             LOWER_DTR ();
  281.             sptr  = MSG_TXT(M_KBD_MSG);
  282.             goto no_response;
  283.             }
  284.          time_release ();
  285.          continue;
  286.          }   
  287.  
  288.       switch (i = TIMED_READ (0))
  289.          {
  290.          case ACK:
  291.             return (1);
  292.  
  293.          case '?':
  294.             status_line (MSG_TXT(M_DRATS));
  295.  
  296.          case ENQ:
  297.             if (++num_errs == 10)
  298.                 {
  299.                 sptr = MSG_TXT(M_FUBAR_MSG);
  300.                 goto no_response;
  301.                 }
  302.             goto xmit_packet;
  303.  
  304.          default:
  305.             if (i > 0)                   /* Could just be line noise */
  306.                {
  307.                }
  308.             break;
  309.          }
  310.       }
  311.  
  312.    if (!CARRIER)
  313.       sptr = MSG_TXT(M_NO_CARRIER);
  314.    else
  315.       {
  316.       (void) sprintf (junkbuff, "!%s",MSG_TXT(M_TIMEOUT));
  317.       sptr = junkbuff;
  318.       }
  319.  
  320. no_response:
  321.  
  322.    status_line (sptr);
  323.    return (0);
  324.  
  325. }                                                /* Send Hello */
  326.  
  327.  
  328. /*--------------------------------------------------------------------------*/
  329. /* RECEIVE HELLO PACKET                                                     */
  330. /*--------------------------------------------------------------------------*/
  331. int Recv_Hello_Packet (int Sender)
  332. {
  333.    int i;
  334.    int c;
  335.    int j;
  336.    struct _Hello Hello;
  337.    char *sptr, *p;
  338.    byte num_errs = 0;
  339.    word crc;
  340.    word lsb;
  341.    word msb;
  342.    long master_timeout, hello_timeout;
  343.    char junkbuff[128];
  344.    ADDR his_boss;
  345.  
  346.    sptr = NULL;
  347.  
  348.    /*--------------------------------------------------------------------*/
  349.    /* Get the Hello structure                                            */
  350.    /*--------------------------------------------------------------------*/
  351.  
  352. /* big_pause (1);  */                           /* Wait for quiet. */
  353.    
  354.    if (un_attended && fullscreen)
  355.       {
  356.       sb_move (file_hWnd, 2, 2);
  357.       FlLnModeSet( FILE_LN_2, 0 );
  358.       sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 ), "YooHoo/2U2" );
  359.       sb_show ();
  360.       }
  361.    else
  362.       {
  363.       set_xy ("YooHoo/2U2 ");
  364.       }
  365.  
  366.    SENDBYTE (ENQ);                               /* Let the other system know
  367.                                                   * we heard YooHoo. */
  368.  
  369.    master_timeout = timerset (12000);   /* No more than 2 mins! */
  370.  
  371. watch_for_header:
  372.  
  373.    for (;;)
  374.       {
  375.       if (sptr)
  376.          {
  377.          status_line (sptr);
  378.          sptr = NULL;
  379.          }
  380.  
  381.       if ((c = TIMED_READ (20)) == 0x1f)
  382.          break;
  383.  
  384.       if (got_ESC ())
  385.          {
  386.          sptr = MSG_TXT(M_KBD_MSG);
  387.          goto receive_failed;
  388.          }
  389.  
  390.       if (!CARRIER)
  391.          {
  392.          sptr = MSG_TXT(M_NO_CARRIER);
  393.          goto receive_failed;
  394.          }
  395.  
  396.       if (timeup(master_timeout))
  397.          goto timeout;
  398.  
  399.       if (c >= 0)                               /* noise? */
  400.          {
  401.          hello_timeout = timerset (1000);       /* Look for up to 10 secs  */
  402.          while (((c = PEEKBYTE ()) >= 0) && (c != 0x1f) && (CARRIER))
  403.             {
  404.             if (timeup(hello_timeout))
  405.                break;
  406.             (void) MODEM_IN ();                 /* Eat non-YooHoo chars    */
  407.             }
  408.  
  409.          if (c != 0x1f)                         /* If we didn't get YooHoo */
  410.             {
  411.             CLEAR_INBOUND ();                   /* Throw out what we have  */
  412.             SENDBYTE (ENQ);                     /* Start over with ENQ     */
  413.             }
  414.          }
  415.  
  416.       }                         /* while */
  417.  
  418.  
  419. /*receive_packet:*/
  420.  
  421.    sptr = (char *) (&Hello);
  422.  
  423.    hello_timeout = timerset (3000);
  424.  
  425.    for (i = 0, crc = 0; i < 128; i++)
  426.       {
  427.  
  428.       while (PEEKBYTE () < 0)
  429.          {
  430.          if (timeup (master_timeout) || timeup (hello_timeout))
  431.             goto timeout;
  432.         
  433.          if (got_ESC ())
  434.             {
  435.             sptr = MSG_TXT(M_KBD_MSG);
  436.             goto receive_failed;
  437.             }
  438.  
  439.          if (!CARRIER)
  440.             {
  441.             sptr = MSG_TXT(M_NO_CARRIER);
  442.             goto receive_failed;
  443.             }
  444.  
  445.          time_release ();
  446.    }
  447.  
  448.       c = TIMED_READ (0);
  449.  
  450.       sptr[i] = (char) c;
  451.       crc = xcrc (crc, (byte) c);
  452.       }
  453.  
  454.    if (!CARRIER)
  455.       {
  456.       sptr = MSG_TXT(M_NO_CARRIER);
  457.       goto receive_failed;
  458.       }
  459.  
  460.    if (((int)(msb = TIMED_READ (10)) < 0) || ((int)(lsb = TIMED_READ (10)) < 0))
  461.       {
  462.       sptr = MSG_TXT(M_SHRT_MSG);
  463.       goto hello_error;
  464.       }
  465.  
  466.    if (((msb << 8) | lsb) == crc)
  467.       goto process_hello;
  468.  
  469.    (void) sprintf (junkbuff, "!%s", MSG_TXT(M_CRC_MSG));
  470.    sptr = junkbuff;
  471.  
  472. hello_error:
  473.  
  474.    if (timeup(master_timeout))
  475.       goto timeout;
  476.  
  477.    if ((num_errs++) > 10)
  478.       {
  479.       sptr = MSG_TXT(M_FUBAR_MSG);
  480.       goto receive_failed;
  481.       }
  482.  
  483.    CLEAR_INBOUND ();
  484.    SENDBYTE ('?');
  485.    goto watch_for_header;
  486.  
  487. process_hello:
  488.  
  489.   /* The idea for removing junk characters came from Holger Schurig */
  490.   /* Get rid of junk characters */
  491.   for (p = Hello.my_name; *p != '\0'; p++)
  492.     if (*p < ' ')
  493.       *p = ' ';
  494.  
  495.   /* Get rid of junk characters */
  496.   for (p = Hello.sysop; *p != '\0'; p++)
  497.     if (*p < ' ')
  498.       *p = ' ';
  499.  
  500.    remote_addr.Zone = Hello.my_zone;
  501.    remote_addr.Net = Hello.my_net;
  502.    remote_addr.Node = Hello.my_node;
  503.    remote_addr.Point = Hello.my_point;
  504.    if ((Hello.capabilities & DO_DOMAIN) && (my_addr.Domain != NULL))
  505.       {
  506.       remote_addr.Domain = find_domain (&(Hello.my_name[strlen (Hello.my_name) + 1]));
  507.       }
  508.    else
  509.       remote_addr.Domain = NULL;
  510.  
  511.  
  512.    if (strlen (Hello.my_name) > 42)
  513.       Hello.my_name[42] = '\0';
  514.  
  515.    Hello.sysop[19] = '\0';
  516.  
  517.    remote_capabilities = Hello.capabilities;
  518.  
  519.    his_boss = remote_addr;
  520.    his_boss.Point = 0;
  521.  
  522.    if (nodefind (&his_boss, 0) && !remote_addr.Zone)
  523.       remote_addr.Zone = found_zone;
  524.  
  525.    (void) sprintf (junkbuff, "*%s (%s)",
  526.             Hello.my_name,
  527.             Full_Addr_Str (&remote_addr));
  528.    status_line (junkbuff);
  529.  
  530.    if ((pvtnet >= 0) &&
  531.        ((remote_addr.Zone == alias[assumed].Zone) || (remote_addr.Zone == 0)) &&
  532.        (remote_addr.Net == boss_addr.Net) && (remote_addr.Node == boss_addr.Node) &&
  533.        (remote_addr.Point > 0))
  534.       {
  535.       remote_addr.Net = pvtnet;
  536.       remote_addr.Node = Hello.my_point;
  537.       remote_addr.Point = 0;
  538.       }
  539.  
  540.    log_product (Hello.product, Hello.product_maj, Hello.product_min);
  541.  
  542. #ifdef MILQ
  543.    if ( isMILQUE == Hello.product )
  544.      UsePaths = TRUE;
  545.    if ( UsePaths )
  546.      status_line( " Paths Will Be Used" );
  547. #endif
  548.  
  549.    if (Hello.sysop[0])
  550.       status_line (":Sysop: %s", Hello.sysop);
  551.  
  552.    if ((pvtnet >= 0) && (remote_addr.Point > 0))
  553.       {
  554.       remote_addr.Point = 0;
  555.       remote_addr.Node = (unsigned int) -1;
  556.       }
  557.  
  558.    if (n_getpassword (&remote_addr))
  559.       {
  560.       if ((j = n_password ((char *)Hello.my_password, remote_password)) != 0)
  561.          {
  562.          if ((j == 1) || ((j == 2) && (!Sender)))
  563.             {
  564.             LOWER_DTR ();                            /* He'll never get it right */
  565.             timer (2);                             /* Wait two secs */
  566.             sptr = NULL;                           /* Already logged something */
  567.             goto receive_failed;
  568.             }
  569.          else
  570.             {
  571.             status_line (MSG_TXT(M_PASSWORD_OVERRIDE));
  572.             }
  573.          }
  574.       }
  575.  
  576.    CLEAR_INBOUND ();
  577.  
  578.    SENDBYTE (ACK);
  579.    SENDBYTE (YOOHOO);
  580.  
  581.    return (1);
  582.  
  583. timeout:
  584.  
  585.    (void) sprintf (junkbuff, "!%s",MSG_TXT(M_TIMEOUT));
  586.    sptr = junkbuff;
  587.  
  588. receive_failed:
  589.  
  590.    status_line (sptr);
  591.    b_init ();
  592.    return (0);
  593. }                                               /* Recv Hello */
  594.  
  595. /* END OF FILE: yoohoo.c */
  596.