home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / OUTBOUND.C < prev    next >
C/C++ Source or Header  |  1991-10-31  |  11KB  |  380 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 originally written by Bob Hartman             */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                         Outbound Manipulating                            */
  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. #include <signal.h>
  48. #include <ctype.h>
  49. #include <conio.h>
  50. #include <string.h>
  51. #include <process.h>
  52. #include <stdlib.h>
  53. #include <dos.h>
  54.  
  55. #ifdef OS_2
  56. #define INCL_DOSPROCESS
  57. #endif
  58.  
  59. #ifdef __TURBOC__
  60. #include <alloc.h>
  61. #else
  62. #include <malloc.h>
  63. #endif
  64.  
  65. #include "com.h"
  66. #include "xfer.h"
  67. #include "zmodem.h"
  68. #include "keybd.h"
  69. #include "sbuf.h"
  70. #include "sched.h"
  71. #include "externs.h"
  72. #include "prototyp.h"
  73. #include "defines.h"
  74.  
  75. static int add_request (char *, char *, char *, char *);
  76. static int add_send (char *, char *, char *);
  77. static int kill_node (char *);
  78.  
  79. int Overlay_Do_Get (p, x)
  80. SAVEP p;
  81. int x;
  82. {
  83.     REGIONP r;
  84.     char node[51];
  85.     char file[13];
  86.     char password[9];
  87.     char flavor[2];
  88.     char sure[2];
  89.  
  90.     if (p != NULL)
  91.         {
  92.         r = p->region;
  93.  
  94.         /* First fill it all with blanks */
  95.        sb_fill (r, ' ', colors.popup);
  96.  
  97.         /* Now draw the box */
  98.        sb_box (r, boxtype, colors.popup);
  99.  
  100.        sb_move (r, 0, 1);
  101.        sb_puts (r, (unsigned char *) msgtxt[M_GET_FILE]);
  102.  
  103.         /* Now do the fields */
  104.         sb_move (r, 1,2);
  105.         sb_puts (r, msgtxt[M_ADDRESS_TO_GET_FROM]);
  106.         if (!sb_input_chars (r, 1, 23, node, 36))
  107.             {
  108.             sb_move (r, 2, 2);
  109.             sb_puts (r, msgtxt[M_FILE_TO_RECEIVE]);
  110.             if (!sb_input_chars (r, 2, 23, file, 12))
  111.                 {
  112.                 sb_move (r, 3, 2);
  113.                 sb_puts (r, msgtxt[M_PASSWORD_TO_USE]);
  114.                 (void) sb_input_chars (r, 3, 23, password, 8);
  115.                 sb_move (r, 4, 2);
  116.                 sb_puts (r, "Crash, Hold, Direct, Normal (C/H/D/N)?");
  117.                 (void) sb_input_chars (r, 4, 41, flavor, 1);
  118.                 sb_move (r, 5, 2);
  119.                 sb_puts (r, msgtxt[M_ARE_YOU_SURE]);
  120.                 (void) sb_input_chars (r, 5, 23, sure, 1);
  121.                 if (sure[0] == toupper (msgtxt[M_YES][0]))
  122.                     x = add_request (node, file, password, flavor);
  123.                 }
  124.             }
  125.         }
  126.  
  127.     /* Return value is never checked, just use x so lint and -W3 don't get mad */
  128.     return (x);
  129. }
  130.  
  131. int Overlay_Do_Send (p, x)
  132. SAVEP p;
  133. int x;
  134. {
  135.     REGIONP r;
  136.     char node[51];
  137.     char file[51];
  138.     char flavor[2];
  139.     char sure[2];
  140.  
  141.     if (p != NULL)
  142.         {
  143.         r = p->region;
  144.  
  145.         /* First fill it all with blanks */
  146.        sb_fill (r, ' ', colors.popup);
  147.  
  148.         /* Now draw the box */
  149.        sb_box (r, boxtype, colors.popup);
  150.  
  151.        sb_move (r, 0, 1);
  152.        sb_puts (r, (unsigned char *) msgtxt[M_SEND_FILE]);
  153.  
  154.         /* Now do the fields */
  155.         sb_move (r, 1,2);
  156.         sb_puts (r, msgtxt[M_ADDRESS_TO_SEND_TO]);
  157.         if (!sb_input_chars (r, 1, 22, node, 47))
  158.             {
  159.             sb_move (r, 2, 2);
  160.             sb_puts (r, msgtxt[M_FILE_TO_SEND]);
  161.             if (!sb_input_chars (r, 2, 22, file, 47))
  162.                 {
  163.                 sb_move (r, 3, 2);
  164.                 sb_puts (r, "Crash, Hold, Direct, Normal (C/H/D/N)?");
  165.                 (void) sb_input_chars (r, 3, 41, flavor, 1);
  166.                 sb_move (r, 4, 2);
  167.                 sb_puts (r, msgtxt[M_ARE_YOU_SURE]);
  168.                 (void) sb_input_chars (r, 4, 22, sure, 1);
  169.                 if (sure[0] == toupper (msgtxt[M_YES][0]))
  170.                     x = add_send (node, file, flavor);
  171.                 }
  172.             }
  173.         }
  174.  
  175.     /* Return value is never checked, just use x so lint and -W3 don't get mad */
  176.     return (x);
  177. }
  178.  
  179. int Overlay_Do_Kill (p, x)
  180. SAVEP p;
  181. int x;
  182. {
  183.     REGIONP r;
  184.     char node[51];
  185.     char sure[2];
  186.  
  187.     if (p != NULL)
  188.         {
  189.         r = p->region;
  190.  
  191.         /* First fill it all with blanks */
  192.        sb_fill (r, ' ', colors.popup);
  193.  
  194.         /* Now draw the box */
  195.        sb_box (r, boxtype, colors.popup);
  196.  
  197.        sb_move (r, 0, 1);
  198.        sb_puts (r, (unsigned char *) msgtxt[M_KILL_MAIL]);
  199.  
  200.         /* Now do the fields */
  201.         sb_move (r, 1,2);
  202.         sb_puts (r, msgtxt[M_ADDRESS_TO_KILL]);
  203.         if (!sb_input_chars (r, 1, 19, node, 50))
  204.             {
  205.             sb_move (r, 2, 2);
  206.             sb_puts (r, msgtxt[M_KILL_ALL_MAIL]);
  207.          sb_puts (r, msgtxt[M_ARE_YOU_SURE]);
  208.             (void) sb_input_chars (r, 2, 38, sure, 1);
  209.             if (sure[0] == toupper (msgtxt[M_YES][0]))
  210.                 x = kill_node (node);
  211.             }
  212.         }
  213.  
  214.     /* Return value is never checked, just use x so lint and -W3 don't get mad */
  215.     return (x);
  216. }
  217.  
  218. int kill_node (node)
  219. char *node;
  220. {
  221.     ADDR addr;
  222.     char *HoldName;
  223.    char *p;
  224.     char fname[100];
  225. #ifdef OS_2
  226.    struct FILEINFO fileinfo;
  227. #else
  228.    struct find_t fileinfo;
  229. #endif
  230.  
  231.     if (find_address (node, &addr))
  232.         {
  233.       if (flag_file (TEST_AND_SET, &addr, 0))
  234.          {
  235.          return (-1);
  236.          }
  237.  
  238.        HoldName = HoldAreaNameMunge(&addr);
  239.  
  240.        (void) sprintf (fname, "%s%s.*", HoldName, Hex_Addr_Str (&addr));
  241. #ifndef OS_2
  242.       if (!_dos_findfirst (fname, 0, &fileinfo))
  243. #else
  244.       if (!dir_findfirst (fname, 0, &fileinfo))
  245. #endif
  246.          {
  247.          do
  248.             {
  249.             /* Don't delete the .bsy flags yet */
  250.             if ((p = strchr (fileinfo.name, '.')) != NULL)
  251.                {
  252.                if (strcmp (p, ".BSY") == 0)
  253.                   continue;
  254.                }
  255.             sprintf (fname, "%s%s", HoldName, fileinfo.name);
  256.             unlink (fname);
  257. #ifndef OS_2
  258.             } while (!_dos_findnext (&fileinfo));
  259. #else
  260.             } while (!dir_findnext (&fileinfo));
  261. #endif
  262.          }
  263.  
  264.       flag_file (CLEAR_FLAG, &addr, 0);
  265.         return (0);
  266.         }
  267.     else
  268.         {
  269.         return (-1);
  270.         }
  271. }
  272.  
  273. int add_request (node, file, password, flavor)
  274. char *node;
  275. char *file;
  276. char *password;
  277. char *flavor;
  278. {
  279.     ADDR addr;
  280.     char *HoldName;
  281.     char fname[100];
  282.     FILE *f;
  283.  
  284.     if (find_address (node, &addr))
  285.         {
  286.        HoldName = HoldAreaNameMunge(&addr);
  287.  
  288.        /* Now see if we should send anything back to him */
  289.        sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&addr));
  290.         if ((f = fopen (fname, "r+")) == NULL)            /* CML changed APPEND to READ -- added logic to correctly add line with CR-LF before it */
  291.             {
  292.             if ((f = fopen (fname, "w")) == NULL)
  293.                 return (-2);
  294.             }
  295.         else
  296.             {
  297.             if (!fseek(f,-1L,SEEK_END))            /* CML: check the last char */
  298.                 {
  299.                 if (fgetc(f) != '\n')
  300.                     {
  301.                     fseek(f,0L,SEEK_END);        /* seek before changing from read to write */
  302.                     fputc('\n',f);
  303.                     }
  304.                 }
  305.             else
  306.                 fseek(f,0L,SEEK_END);
  307.             }
  308.  
  309. //        sprintf (fname, "%s", Full_Addr_Str (&(alias[0])));
  310. //        fprintf (f, ";GET generated by node %s using %s\r\n", fname, ANNOUNCE);        /* CML - commented out */
  311.         fprintf (f, "%s", file);
  312.         if (password[0] != '\0')
  313.             fprintf (f, " !%s", password);
  314.         fprintf (f, "\n");
  315.  
  316.         fclose (f);
  317.  
  318.         add_send (node, "", flavor);
  319.         return (0);
  320.         }
  321.     else
  322.         {
  323.         return (-1);
  324.         }
  325. }
  326.  
  327. int add_send (node, file, flavor)
  328. char *node;
  329. char *file;
  330. char *flavor;
  331. {
  332.     ADDR addr;
  333.     char *HoldName;
  334.     char fname[100];
  335.     FILE *f;
  336.  
  337.     if ((flavor[0] != 'C') && (flavor[0] != 'H') && (flavor[0] != 'N') && (flavor[0] != 'D'))
  338.         return (-3);
  339.  
  340.     if (flavor[0] == 'N')
  341.         flavor[0] = 'F';
  342.  
  343.     if (find_address (node, &addr))
  344.         {
  345.        HoldName = HoldAreaNameMunge(&addr);
  346.         (void) sprintf (fname, "%s%s.%sLO", HoldName, Hex_Addr_Str (&addr), flavor);
  347.  
  348.         if ((f = fopen (fname, "r+")) == NULL)            /* CML changed APPEND to READ -- added logic to correctly add line with CR-LF before it */
  349.             {
  350.             if ((f = fopen (fname, "w")) == NULL)
  351.                 return (-2);
  352.             }
  353.         else
  354.             {
  355.             if (!fseek(f,-1L,SEEK_END))            /* CML: check the last char */
  356.                 {
  357.                 if (fgetc(f) != '\n')
  358.                     {
  359.                     fseek(f,0L,SEEK_END);        /* seek before changing from read to write */
  360.                     fputc('\n',f);
  361.                     }
  362.                 }
  363.             else
  364.                 fseek(f,0L,SEEK_END);
  365.             }
  366.         if (file[0] != '\0')
  367.             {
  368. //                sprintf (fname, "%s", Full_Addr_Str (&(alias[0])));
  369. //                fprintf (f, ";SEND generated by node %s using %s\r\n", fname, ANNOUNCE);        /* CML - cut that out */
  370.             fprintf (f, "%s\n", file);
  371.             }
  372.         fclose (f);
  373.         }
  374.     else
  375.         {
  376.         return (-1);
  377.         }
  378. }
  379.  
  380.