home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts310b5 / sendbark.c < prev    next >
C/C++ Source or Header  |  1992-12-29  |  10KB  |  375 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 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.240.    */
  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:132/491, 1:141/491  */
  36. /* P.O. Box 460398                AlterNet 7:491/0                          */
  37. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  38. /*                                Internet f491.n132.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. #ifdef __TOS__
  46. /* #pragma warn -sus */
  47. #endif
  48. #include <stdio.h>
  49. #include <signal.h>
  50. #include <ctype.h>
  51. #include <conio.h>
  52. #include <time.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55.  
  56. #include "bink.h"
  57. #include "msgs.h"
  58. #include "com.h"
  59. #include "ascii.h"
  60. #include "defines.h"
  61.  
  62. void SEA_sendreq ()
  63. {
  64.        char fname[80];
  65.        char reqf[80];
  66.        char *reqtime = " 0";
  67.        char *p, *name, *pw;
  68.        char *updtime;
  69.        FILE *fp;
  70.        char *HoldName;
  71. #ifdef IOS
  72.     BOOLEAN flag;
  73. #endif
  74.  
  75.        HoldName = HoldAreaNameMunge(&called_addr);
  76.        sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&called_addr));
  77. #ifdef IOS
  78.     if(!(flag = dexists(fname)))
  79.     {
  80.         char *ext = "HOC";
  81.         while(*ext)
  82.         {
  83.             sprintf (fname, "%s%s.%cRT", HoldName, Addr36(&called_addr), *ext);
  84.             if(flag = dexists(fname))
  85.                 break;
  86.             ext++;
  87.         }
  88.     }
  89.     if(!flag)
  90. #else
  91.        /* If we have file requests, then do them */
  92.        if (!dexists (fname))
  93. #endif
  94.           status_line (msgtxt[M_NO_OUT_REQUESTS]);
  95.    else
  96.       {
  97.       status_line (msgtxt[M_OUT_REQUESTS]);
  98.       /* Open the .REQ file */
  99.       if ((fp = fopen (fname, read_ascii)) == NULL)
  100.          {
  101.          Bark_Request (CurrentNetFiles, NULL, NULL, NULL);
  102.          return;
  103.          }
  104.  
  105.       /* As long as we do not have EOF, read the request */
  106.       while ((fgets (reqf, 79, fp) != NULL) && (CARRIER))
  107.          {
  108.          /* Properly format the request */
  109.  
  110.          /* First get rid of the trailing junk */
  111.  
  112.          p = reqf + strlen (reqf) - 1;
  113.          while ((p >= reqf) && *p && (isspace (*p)))
  114.             *p-- = '\0';
  115.  
  116.          /* Now get rid of the beginning junk */
  117.  
  118.          p = reqf;
  119.          while ((*p) && (isspace (*p)))
  120.             p++;
  121.  
  122.          /* This is where the name starts */
  123.          name = p;
  124.  
  125.          /* If the first char is ; then ignore the line */
  126.          if (*name == ';')
  127.             continue;
  128.  
  129.          /* Now get to where the name ends */
  130.          while ((*p) && (!isspace (*p)))
  131.             p++;
  132.  
  133.          updtime = reqtime;             /* Default to request        */
  134.          pw = p;                        /* This is or will be a null */
  135. req_scan:
  136.          if (*p)
  137.             {
  138.             *p++ = '\0';
  139.  
  140.             while ((*p) && (*p != '!') && (*p != '-') && (*p != '+'))
  141.                p++;
  142.  
  143.             /* Check for a password */
  144.  
  145.             if (*p == '!')
  146.                {
  147.                *p = ' ';
  148.                pw = p++;
  149.  
  150.                /* Now get to where the password ends */
  151.  
  152.                while ((*p) && (!isspace (*p)))
  153.                   p++;
  154.                goto req_scan;
  155.                }
  156.  
  157.             /* Try for an update request */
  158.  
  159.             if (*p == '+')
  160.                {
  161.                *p = ' ';
  162.                updtime = p++;
  163.  
  164.                /* Now get to where the update time ends */
  165.  
  166.                while ((*p) && (!isspace (*p)))
  167.                   p++;
  168.  
  169.                *p = '\0';
  170.  
  171.                /* Request time is last thing we care about on line, so
  172.                   we just drop out of the loop after finding it.
  173.                 */
  174.                }
  175.  
  176.             /* Note: since SEAdog doesn't do "backdate" requests, all we
  177.                have to do if we see a '-' is to do a full request. Hence
  178.                we only process a '+' here.
  179.              */
  180.  
  181.             }
  182.  
  183.          if (Bark_Request (CurrentNetFiles, name, pw, updtime))
  184.             continue;
  185.          }
  186.       (void) fclose (fp);
  187.       (void) unlink (fname);
  188.       status_line (msgtxt[M_END_OUT_REQUESTS]);
  189.       }
  190.  
  191.    /* Finish the file requests off */
  192.    Bark_Request (CurrentNetFiles, NULL, NULL, NULL);
  193.  
  194. }
  195.  
  196. int cdecl SBInit (BARKARGSP, int);
  197. int cdecl SBEnd (BARKARGSP, int);
  198. int cdecl SBSendBark (BARKARGSP);
  199. int cdecl SBAskFile (BARKARGSP);
  200. int cdecl SBRcvFile (BARKARGSP);
  201. int cdecl SBNxtFile (BARKARGSP);
  202.  
  203. STATES Bark_Sender[] = {
  204.    { "SBInit", SBInit },
  205.    { "SBEnd", SBEnd },
  206.    { "SB0", SBSendBark },
  207.    { "SB1", SBAskFile },
  208.    { "SB2", SBRcvFile },
  209.    { "SB3", SBNxtFile },
  210. };
  211.  
  212. void Build_Bark_Packet (args)
  213. BARKARGSP args;
  214. {
  215.    char *p, *q;
  216.    unsigned int crc;
  217.  
  218.    p = args->barkpacket;
  219.    *p++ = ACK;
  220.    crc = 0;
  221.    q = args->filename;
  222.    while (*q)
  223.       {
  224.       *p++ = *q;
  225.       crc = xcrc (crc, (byte) (*q));
  226.       ++q;
  227.       }
  228.    q = args->barktime;
  229.    while (*q)
  230.       {
  231.       *p++ = *q;
  232.       crc = xcrc (crc, (byte) (*q));
  233.       ++q;
  234.       }
  235.    q = args->barkpw;
  236.    while (*q)
  237.       {
  238.       *p++ = *q;
  239.       crc = xcrc (crc, (byte) (*q));
  240.       ++q;
  241.       }
  242.  
  243.    *p++ = ETX;
  244.    *p++ = (char) (crc & 0xff);
  245.    *p++ = (char) (crc >> 8);
  246.  
  247.    args->barklen = (size_t) (p - args->barkpacket);
  248. }
  249.  
  250. int cdecl SBInit (args, start_state)
  251. BARKARGSP args;
  252. int start_state;
  253. {
  254.    XON_DISABLE ();
  255.    return (start_state);
  256.    /* args; */
  257. }
  258.  
  259. int cdecl SBEnd (args, cur_state)
  260. BARKARGSP args;
  261. int cur_state;
  262. {
  263.    return (cur_state);
  264.    /* args; */
  265. }
  266.  
  267. int cdecl SBSendBark (args)
  268. BARKARGSP args;
  269. {
  270.    if ((args->filename != NULL) && (args->filename[0] != '\0'))
  271.       {
  272.       status_line ("%s '%s' %s%s", msgtxt[M_MAKING_FREQ], args->filename, (*(args->barkpw)) ? "with password" : "", args->barkpw);
  273.       args->tries = 0;
  274.       Build_Bark_Packet (args);
  275.       return (SB1);
  276.       }
  277.    else
  278.       {
  279.       SENDBYTE (ETB);
  280.  
  281.       /* Delay one second */
  282.       big_pause (1);
  283.  
  284.       return (SUCCESS);
  285.       }
  286. }
  287.  
  288. int cdecl SBAskFile (args)
  289. BARKARGSP args;
  290. {
  291.    SENDCHARS (args->barkpacket, args->barklen, 1);
  292.    return (SB2);
  293. }
  294.  
  295. int cdecl SBRcvFile (args)
  296. BARKARGSP args;
  297. {
  298.    int c;
  299.    int ret;
  300.  
  301.    ret = SB2;
  302.    while (CARRIER && (ret == SB2))
  303.       {
  304.       c = TIMED_READ (10);
  305.  
  306.       if (c == ACK)
  307.          {
  308.          Batch_Receive (args->inbound);
  309.          ret = SB3;
  310.          break;
  311.          }
  312.  
  313.       if (args->tries > 5)
  314.          {
  315. /* Report transfer failed */
  316.          SENDBYTE (ETB);
  317.          ret = SENDBLOCK_ERR;
  318.          break;
  319.          }
  320.  
  321.       CLEAR_INBOUND ();
  322.       ++(args->tries);
  323.       ret = SB1;
  324.       }
  325.  
  326.    if (!CARRIER)
  327.       return (CARRIER_ERR);
  328.    else
  329.       return (ret);
  330. }
  331.  
  332. int cdecl SBNxtFile (args)
  333. BARKARGSP args;
  334. {
  335.    int c;
  336.    long SB3Timer;
  337.  
  338.    SB3Timer = timerset (4500);
  339.  
  340.    while (CARRIER && !timeup (SB3Timer))
  341.       {
  342.       if ((c = TIMED_READ (5)) == 0xffff)
  343.          {
  344.          SENDBYTE (SUB);
  345.          continue;
  346.          }
  347.  
  348.       if (c == ENQ)
  349.          return (SUCCESS);
  350.       }
  351.  
  352.    if (CARRIER)
  353.       return (CARRIER_ERR);
  354.    else
  355.       return (TIME_ERR);
  356.    /* args; */
  357. }
  358.  
  359. int Bark_Request (where, filename, pw, updtime)
  360. char *where;
  361. char *filename;
  362. char *pw;
  363. char *updtime;
  364. {
  365.    BARKARGS bark;
  366.  
  367.    bark.inbound = where;
  368.    bark.filename = filename;
  369.    bark.barkpw = pw;
  370.    bark.barktime = updtime;
  371.    return (state_machine (Bark_Sender, &bark, SB0));
  372. }
  373.  
  374.  
  375.