home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / SENDBARK.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  10KB  |  353 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 Bob Hartman                   */
  14. /*                                                                          */
  15. /*                BinkleyTerm SEAdog Mail Session Routines                  */
  16. /*                                                                          */
  17. /*                                                                          */
  18. /*    For complete  details  of the licensing restrictions, please refer    */
  19. /*    to the License  agreement,  which  is published in its entirety in    */
  20. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  21. /*                                                                          */
  22. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  23. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  24. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  25. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  26. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  27. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  28. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  29. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  30. /*                                                                          */
  31. /*                                                                          */
  32. /* You can contact Bit Bucket Software Co. at any one of the following      */
  33. /* addresses:                                                               */
  34. /*                                                                          */
  35. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  36. /* P.O. Box 460398                AlterNet 7:491/0                          */
  37. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  38. /*                                Internet f491.n343.z1.fidonet.org         */
  39. /*                                                                          */
  40. /* Please feel free to contact us at any time to share your comments about  */
  41. /* our software and/or licensing policies.                                  */
  42. /*                                                                          */
  43. /*--------------------------------------------------------------------------*/
  44.  
  45. /* Include this file before any other includes or defines! */
  46.  
  47. #include "includes.h"
  48.  
  49. #define rb_plus "rb+"
  50.  
  51. void SEA_sendreq ()
  52. {
  53.    char fname[80];
  54.    char reqf[80];
  55.    char *reqtime = " 0";
  56.    char *p, *name, *pw;
  57.    char *updtime;
  58.    FILE *fp;
  59.    char *HoldName;
  60.    ADDR tmp;
  61.  
  62.  
  63.    HoldName = HoldAreaNameMunge(&called_addr);
  64.  
  65.    tmp = called_addr;
  66.  
  67.    /* For a point, massage the address to get the right .REQ filename */
  68.  
  69.    if (tmp.Point != 0)
  70.       {
  71.       tmp.Node  = tmp.Point;
  72.       tmp.Point = 0;
  73.       tmp.Net   = (pvtnet > 0) ? (unsigned int) pvtnet : 0;
  74.       }        
  75.  
  76.    (void) sprintf (fname,
  77.             "%s%s.REQ",
  78.             HoldName, Hex_Addr_Str (&tmp));
  79.  
  80.    /* If we have file requests, then do them */
  81.    if (!dexists (fname))
  82.       {
  83.       status_line (MSG_TXT(M_NO_OUT_REQUESTS));
  84.       }
  85.    else
  86.       {
  87.       status_line (MSG_TXT(M_OUT_REQUESTS));
  88.       /* Open the .REQ file */
  89.       if ((fp = fopen (fname, "rt")) == NULL)
  90.          {
  91.          (void) Bark_Request (CURRENT.sc_Inbound, NULL, NULL, NULL);
  92.          return;
  93.          }
  94.  
  95.       /* As long as we do not have EOF, read the request */
  96.       while ((fgets (reqf, 79, fp) != NULL) && (CARRIER))
  97.          {
  98.          /* Properly format the request */
  99.  
  100.          /* First get rid of the trailing junk */
  101.  
  102.          p = reqf + strlen (reqf) - 1;
  103.          while ((p >= reqf) && (isspace (*p)))
  104.             *p-- = '\0';
  105.  
  106.          /* Now get rid of the beginning junk */
  107.  
  108.          p = reqf;
  109.          while ((*p) && (isspace (*p)))
  110.             p++;
  111.  
  112.          /* This is where the name starts */
  113.          name = p;
  114.  
  115.          /* If the first char is ; then ignore the line */
  116.          if (*name == ';')
  117.             continue;
  118.  
  119.          /* Now get to where the name ends */
  120.          while ((*p) && (!isspace (*p)))
  121.             p++;
  122.  
  123.          updtime = reqtime;             /* Default to request        */
  124.          pw = p;                        /* This is or will be a null */
  125. req_scan:
  126.          if (*p)
  127.             {
  128.             *p++ = '\0';
  129.  
  130.             while ((*p) && (*p != '!') && (*p != '-') && (*p != '+'))
  131.                p++;
  132.  
  133.             /* Check for a password */
  134.  
  135.             if (*p == '!')
  136.                {
  137.                *p = ' ';
  138.                pw = p++;
  139.  
  140.                /* Now get to where the password ends */
  141.  
  142.                while ((*p) && (!isspace (*p)))
  143.                   p++;
  144.                goto req_scan;
  145.                }
  146.  
  147.             /* Try for an update request */
  148.  
  149.             if (*p == '+')
  150.                {
  151.                *p = ' ';
  152.                updtime = p++;
  153.  
  154.                /* Now get to where the update time ends */
  155.  
  156.                while ((*p) && (!isspace (*p)))
  157.                   p++;
  158.  
  159.                *p = '\0';
  160.  
  161.                /* Request time is last thing we care about on line, so
  162.                   we just drop out of the loop after finding it.
  163.                 */
  164.                }
  165.  
  166.             /* Note: since SEAdog doesn't do "backdate" requests, all we
  167.                have to do if we see a '-' is to do a full request. Hence
  168.                we only process a '+' here.
  169.              */
  170.  
  171.             }
  172.  
  173.          if (Bark_Request (CURRENT.sc_Inbound, name, pw, updtime))
  174.             continue;
  175.          }
  176.       (void) fclose (fp);
  177.       (void) unlink (fname);
  178.       status_line (MSG_TXT(M_END_OUT_REQUESTS));
  179.       }
  180.  
  181.    /* Finish the file requests off */
  182.    (void) Bark_Request (CURRENT.sc_Inbound, NULL, NULL, NULL);
  183.  
  184. }
  185.  
  186. int SBInit (BARKARGSP, int);
  187. int SBEnd (BARKARGSP, int);
  188. int SBSendBark (BARKARGSP);
  189. int SBAskFile (BARKARGSP);
  190. int SBRcvFile (BARKARGSP);
  191. int SBNxtFile (BARKARGSP);
  192.  
  193. STATES Bark_Sender[] = {
  194.    { "SBInit", SBInit },
  195.    { "SBEnd", SBEnd },
  196.    { "SB0", SBSendBark },
  197.    { "SB1", SBAskFile },
  198.    { "SB2", SBRcvFile },
  199.    { "SB3", SBNxtFile },
  200. };
  201.  
  202. void Build_Bark_Packet (BARKARGSP args)
  203. {
  204.    char *p, *q;
  205.    unsigned int crc;
  206.  
  207.    p = args->barkpacket;
  208.    *p++ = ACK;
  209.    crc = 0;
  210.    q = args->filename;
  211.    while (*q)
  212.       {
  213.       *p++ = *q;
  214.       crc = xcrc (crc, (byte) (*q));
  215.       ++q;
  216.       }
  217.    q = args->barktime;
  218.    while (*q)
  219.       {
  220.       *p++ = *q;
  221.       crc = xcrc (crc, (byte) (*q));
  222.       ++q;
  223.       }
  224.    q = args->barkpw;
  225.    while (*q)
  226.       {
  227.       *p++ = *q;
  228.       crc = xcrc (crc, (byte) (*q));
  229.       ++q;
  230.       }
  231.  
  232.    *p++ = ETX;
  233.    *p++ = (char) (crc & 0xff);
  234.    *p++ = (char) (crc >> 8);
  235.  
  236.    args->barklen = (int) (p - args->barkpacket);
  237. }
  238.  
  239.  
  240. int SBInit (BARKARGSP args, int start_state)
  241. {
  242.    XON_DISABLE ();
  243.    happy_compiler = args->tries;  /* Makes the compiler happy! */
  244.    return (start_state);
  245. }
  246.  
  247. int SBEnd (BARKARGSP args, int cur_state)
  248. {
  249.    happy_compiler = args->tries;  /* Makes the compiler happy! */
  250.    return (cur_state);
  251. }
  252.  
  253. int SBSendBark (BARKARGSP args)
  254. {
  255.    if ((args->filename != NULL) && (args->filename[0] != '\0'))
  256.       {
  257.       status_line ("%s '%s' %s%s", MSG_TXT(M_MAKING_FREQ), args->filename, (*(args->barkpw)) ? "with password" : "", args->barkpw);
  258.       args->tries = 0;
  259.       Build_Bark_Packet (args);
  260.       return (SB1);
  261.       }
  262.    else
  263.       {
  264.       SENDBYTE (ETB);
  265.  
  266.       /* Delay one second */
  267.       big_pause (1);
  268.  
  269.       return (SUCCESS);
  270.       }
  271. }
  272.  
  273. int SBAskFile (BARKARGSP args)
  274. {
  275.    SENDCHARS (args->barkpacket, args->barklen, 1);
  276.    return (SB2);
  277. }
  278.  
  279. int SBRcvFile (BARKARGSP args)
  280. {
  281.    int c;
  282.    int ret;
  283.  
  284.    ret = SB2;
  285.    while (CARRIER && (ret == SB2))
  286.       {
  287.       c = TIMED_READ (10);
  288.  
  289.       if (c == ACK)
  290.          {
  291.          (void) Batch_Receive (args->inbound);
  292.          ret = SB3;
  293.          break;
  294.          }
  295.  
  296.       if (args->tries > 5)
  297.          {
  298. /* Report transfer failed */
  299.          SENDBYTE (ETB);
  300.          ret = SENDBLOCK_ERR;
  301.          break;
  302.          }
  303.  
  304.       CLEAR_INBOUND ();
  305.       ++(args->tries);
  306.       ret = SB1;
  307.       }
  308.  
  309.    if (!CARRIER)
  310.       return (CARRIER_ERR);
  311.    else
  312.       return (ret);
  313. }
  314.  
  315. int SBNxtFile (BARKARGSP args)
  316. {
  317.    int c;
  318.    long SB3Timer;
  319.  
  320.    SB3Timer = timerset (4500);
  321.    happy_compiler = args->tries;  /* Makes the compiler happy! */
  322.  
  323.    while (CARRIER && !timeup (SB3Timer))
  324.       {
  325.       if ((unsigned int)(c = TIMED_READ (5)) == 0xffff)
  326.          {
  327.          SENDBYTE (SUB);
  328.          continue;
  329.          }
  330.  
  331.       if (c == ENQ)
  332.          return (SUCCESS);
  333.       }
  334.  
  335.    if (CARRIER)
  336.       return (CARRIER_ERR);
  337.    else
  338.       return (TIME_ERR);
  339. }
  340.  
  341. int Bark_Request (char *where, char *filename, char *pw, char *updtime)
  342. {
  343.    BARKARGS bark;
  344.  
  345.    bark.inbound = where;
  346.    bark.filename = filename;
  347.    bark.barkpw = pw;
  348.    bark.barktime = updtime;
  349.    return (state_machine (Bark_Sender, &bark, SB0));
  350. }
  351.  
  352.  
  353.