home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_RSPFIL.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  11KB  |  305 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 File Request Failure Message Module              */
  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. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. void Make_Response(char *, int);         /* Build a response      */
  51.  
  52. void Make_Response (char *data, int failure)
  53. {
  54.     FILE *Template, *Response;
  55.     char *dummy_text;
  56.     char *text;
  57.     char *failure_text[10];
  58.     char resp_filename[13];
  59.     char *p, *q, *s;
  60.     struct tm *tp;
  61.     time_t ltime;
  62.     int i;
  63.  
  64.     if (Netmail_Session == 2)
  65.       {
  66.       text = strchr (data, ' ');
  67.       if (text != NULL)
  68.          *text = '\0';
  69.       }
  70.  
  71.     Template = Response = (FILE *) NULL;
  72.     dummy_text = NULL;
  73.  
  74.     for (i = 0; i < 9; i++)
  75.        failure_text[i] = NULL;
  76.  
  77.     if (((text = calloc (1, 256)) == NULL)
  78.     || ((dummy_text = calloc (1, 256)) == NULL))
  79.        goto resp_failed;
  80.  
  81.     (void) time (<ime);
  82.     tp = localtime (<ime);
  83.     
  84.     if ((Template = share_fopen (CURRENT.rq_Template, read_ascii, DENY_WRITE)) == NULL)
  85.       {
  86.       (void) got_error (MSG_TXT(M_OPEN_MSG), CURRENT.rq_Template);
  87.       goto resp_failed;
  88.       }
  89.  
  90.     if (alias[assumed].Point != 0)
  91.        (void) sprintf (resp_filename, "%08x.RSP", alias[assumed].Point);
  92.     else
  93.        (void) sprintf (resp_filename, "%s.RSP", Hex_Addr_Str (&(alias[assumed])));
  94.     if ((Response = fopen (resp_filename, write_binary)) == NULL)
  95.       {
  96.       (void) got_error (MSG_TXT(M_OPEN_MSG), resp_filename);
  97.       goto resp_failed;
  98.       }
  99.     
  100.     while (!feof (Template))
  101.        {
  102.  
  103. read_line:
  104.  
  105.        e_input[0] = '\0';
  106.        if (fgets (text, 254, Template) == NULL)
  107.           break;
  108.  
  109.        if (text[0] == '%' && text[1] == ';')
  110.           continue;                     /* Comment at start, no output */
  111.        
  112.        p = text;
  113.        q = e_input;
  114.  
  115.        while (*p)
  116.           {
  117.  
  118.           if (*p == '\n')               /* All done if newline seen    */
  119.              break;
  120.  
  121.           if (*p != '%')                /* Copy until(unless) we see % */
  122.              {
  123.              *q++ = *p++;
  124.              continue;
  125.              }
  126.              
  127.           if (*++p == ';')              /* If followed by ; just skip  */
  128.              break;
  129.  
  130.           if ((i = parse(p, rspverbs)) == -1)/* Check against arg list */
  131.              {
  132.              *q++ = '%';                /* No match, use the % literal */
  133.              continue;
  134.              }
  135.           
  136.           switch (i)
  137.           
  138.              {
  139.              
  140.              case 1:                    /* "text"                      */
  141.  
  142.              if (((i = atoi (p = skip_blanks (&p[4]))) < 1) || (i > 9))
  143.                 goto read_line; 
  144.  
  145.              if (!*(p = skip_to_blank (p)) || !*++p)
  146.                 goto read_line; 
  147.              
  148.              if (failure_text[--i] != NULL) 
  149.                 {
  150.                 free (failure_text[i]);
  151.                 failure_text[i] = NULL;
  152.                 }
  153.  
  154.              failure_text[i] = s = calloc (1, 1 + strlen (p));
  155.              if (s == NULL)
  156.                 goto read_line;
  157.              while ((*p) && (*p != '\n'))
  158.                 *s++ = *p++;
  159.              *s++ = '\0';
  160.  
  161.              goto read_line;
  162.  
  163.              case 2:                    /* "date"                      */
  164.              p += 4;
  165.              (void) sprintf (dummy_text,"%2d-%3s-%02d", tp->tm_mday, mtext[tp->tm_mon], tp->tm_year);
  166. scopy:
  167.              s = dummy_text;
  168. ccopy:
  169.              while (*s)
  170.                *q++ = *s++;
  171.              
  172.              break;
  173.              
  174.              case 3:                    /* "time"                      */
  175.              p += 4;
  176.              (void) sprintf (dummy_text, "%2d:%02d", tp->tm_hour, tp->tm_min);
  177.              goto scopy;
  178.              
  179.              case 4:                    /* "bink"                      */
  180.              p += 4;
  181.              s = ANNOUNCE;
  182.              goto ccopy;
  183.              
  184.              case 5:                    /* "mynode"                    */
  185.              p += 6;
  186.              (void) sprintf (dummy_text, "%s", Full_Addr_Str (&(alias[assumed])));
  187.              goto scopy;
  188.              
  189.              case 6:                    /* "system"                    */
  190.              p += 6;
  191.              s = system_name;
  192.              goto ccopy;
  193.              
  194.              case 7:                    /* "sysop"                     */
  195.              p += 5;
  196.              s = sysop;
  197.              goto ccopy;
  198.              
  199.              case 8:                    /* "yrnode"                    */
  200.              p += 6;
  201.              (void) sprintf (dummy_text, "%s", Full_Addr_Str (&remote_addr));
  202.              goto scopy;
  203.              
  204.              case 9:                    /* "request"                   */
  205.              p += 7;
  206.              s = data;
  207.              goto ccopy;
  208.              
  209.              case 10:                   /* "status"                    */
  210.              p += 6;
  211.              (void) strcpy (dummy_text, p);
  212.              if (failure_text [failure - 1] == NULL)
  213.                 text[0] = '\0';
  214.              else
  215.                 (void) strcpy (text, failure_text [failure - 1]);
  216.              (void) strcat (text, dummy_text);
  217.              p = text;
  218.              break;
  219.  
  220.              case 11:                   /* "abort"                     */
  221.  
  222.              if (*(p = skip_blanks (&p[5])))/* If there's an argument, */
  223.                 {
  224.                 if (failure != atoi (p))/* See if it matches failure   */
  225.                    goto read_line;      /* No, keep going.             */
  226.                 }
  227.  
  228.              (void) fclose (Response);         /* Abort things: Close file,   */
  229.              Response = NULL;           /* Keep track of closed file   */
  230.              (void) unlink (resp_filename);    /* Then delete it              */
  231.              goto resp_failed;          /* And take the failure exit   */
  232.  
  233.              case 12:                   /* "exit"                      */
  234.  
  235.              if (*(p = skip_blanks (&p[4])))/* If there's an argument, */
  236.                 {
  237.                 if (failure != atoi (p))/* See if it matches failure   */
  238.                    goto read_line;      /* No, keep going.             */
  239.                 }
  240.              goto resp_done;       /* A match, close the file     */
  241.  
  242.              case 13:                   /* "line"                      */
  243.  
  244.              if ((!(*(p = skip_blanks (&p[4]))))
  245.              || (failure != atoi (p)))  /* If argument doesn't match,  */
  246.                    goto read_line;      /* throw out line, keep going. */
  247.              if (*(p = skip_to_blank (p))) /* If there's any text,     */
  248.                 {
  249.                 (void) strcpy (text, ++p);     /* Copy rest of line down      */
  250.                 p = text;               /* Move pointer to front       */
  251.                 }
  252.              break;
  253.  
  254.              }          /* End switch                 */
  255.           }             /* End while *p               */
  256.  
  257.        *q++ = '\r';
  258.        *q++ = '\n';
  259.        *q = '\0';
  260.  
  261.        i = (int) (q - e_input);
  262.        (void) fwrite (e_input, (unsigned int) i, 1, Response);
  263.        }                /* End while !feof (Template) */
  264.  
  265. resp_done:
  266.  
  267.    (void) strcpy (data, resp_filename);
  268.  
  269.    (void) fclose (Template);
  270.    Template = NULL;
  271.  
  272.    (void) fclose (Response);
  273.    Response = NULL;
  274.    goto cleanup;
  275.  
  276. resp_failed:
  277.  
  278.    *data = '\0';
  279.  
  280.    if (Response != NULL)
  281.       (void) fclose (Response);
  282.  
  283.    if (Template != NULL)
  284.       (void) fclose (Template);
  285.  
  286. cleanup:
  287.  
  288.    for (i = 0; i < 9; i++)
  289.        {
  290.        if (failure_text[i] != NULL)
  291.           {
  292.           free(failure_text[i]);
  293.           failure_text[i] = NULL;
  294.           }
  295.        }
  296.  
  297.    if (text != NULL)
  298.       free(text);
  299.  
  300.    if (dummy_text != NULL)
  301.       free (dummy_text);
  302.  
  303.    return;
  304. }
  305.