home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / bbs_opus / omail_41.arj / OMAIL.C next >
C/C++ Source or Header  |  1991-02-06  |  34KB  |  1,077 lines

  1. #define VER    5
  2. /*--------------------------------------------------------------------------*/
  3. /* Usual Legal BS goes here. Copyright 1988, 1989, Doug Boone               */
  4. /*                                                                          */
  5. /* You're free to use and modify this program however you want, so long as  */
  6. /* 1: Keep it free, you probably didn't pay me for it.                      */
  7. /* 2: Keep it friendly, don't abuse the power of FidoNet mail and requests  */
  8. /* 3: Keep it legal.                                                        */
  9. /*                                                                          */
  10. /* MSC 5.1:     cl /Ox omail.c  (gives you an EXE file)                     */
  11. /* TurboC 2.0:  tcc -f- -mt -v- -lt -K -G -Z -d omail.c                     */
  12. /*              (gives you OMAIL.COM, leave out -lt for OMAIL.EXE)          */
  13. /*                                                                          */
  14. /*  For Opus 1.10 Gamma VI:                                                 */
  15. /* MSC 5.1:     cl /Ox /DPOLL110 omail.c  (gives you an EXE file)           */
  16. /* TurboC 2.0:  tcc -f- -mt -lt -K -G -Z -d -v- -DPOLL110 omail.c           */
  17. /*              (gives you OMAIL.COM, leave out -lt for OMAIL.EXE)          */
  18. /*                                                                          */
  19. /* Doug Boone   (916) 893-9019 data (FidoNet 119/5)                         */
  20. /*              (916) 891-0748 voice (Pacific Standard Time)                */
  21. /*                                                                          */
  22. /* Thanks to Steve Antonoff who added the code to send to nodes in the same */
  23. /* net and Steve Barnes who suggested the QLO change (although I don't know */
  24. /* what it does.)                                                           */
  25. /*                                                                          */
  26. /* "Don't rip me off!"  -- Tom Jennings (buried in the Fido 11 code)        */
  27. /* (tabs are at 4)                                                          */
  28. /*--------------------------------------------------------------------------*/
  29.  
  30. #include     <stdio.h>
  31. #include     <string.h>
  32. #include    <time.h>
  33. #include    <dos.h>
  34. #include    <fcntl.h>
  35. #include     <ctype.h>
  36. #include   <conio.h>
  37. #include   <stdlib.h>
  38. #ifndef  __TURBOC__
  39. #include    <malloc.h>
  40. #include    <sys\types.h>
  41. #else
  42. #include    <dir.h>
  43. #include    <alloc.h>
  44. #endif
  45. #include    <sys\stat.h>
  46. #include   <io.h>
  47. #include     "opus.h"
  48.  
  49. #define    PROD_CODE    9
  50. #define MAX_PATH    80
  51.                
  52. #define    POLL        0x0001        /* Polling an address */
  53. #define    REQUEST        0x0002        /* WaZoo request */
  54. #define    SEND        0x0004        /* File Attach */
  55. #define    TRUNC       0x0104        /* (08+04) File Attach, Truncate after send */
  56. #define    KILL_SEND    0x0204      /* (0f+04) File Attach, Kill after send */
  57. #define    UPDATE      0x0102        /* Ask for an update for file */
  58. #define    HOLD        0x0010        /* Change outbound mail to Hold */
  59. #define    CRASH        0x0020        /* Change outbound mail to Crash */
  60. #define    DIRECT        0x0040        /* Change outbound mail to Direct */
  61. #define    STOP        0x0080        /* Mark these nodes as nocalls */
  62.  
  63. #ifdef POLL110
  64. #define    POLL_110    0x1000        /* Temporary 1.10 poll with DUT file */
  65. #endif
  66.  
  67. void    do_append(unsigned int);
  68. void    change(char);
  69. void    noaddr(void);
  70. void    usage(void);
  71. void    oops(char *,char *,int);
  72. int        get_node(char *,int,int);
  73. void    do_req(char *);
  74. void    get_names(char *);
  75. void    do_Rpolls(void);
  76. void    do_polls(void);
  77. void    do_stops(void);
  78. int        check(char *);
  79. #ifdef POLL110
  80. void    poll_110(int,int,char *);
  81. #endif
  82.  
  83.     struct    onecatch {
  84.         int     zone;
  85.         int        net;
  86.         int        node;
  87.         char    firstchar;
  88.         };
  89.  
  90.     struct    onecatch    address[25];
  91.     int                action = 0;
  92.     char            pwd[9];
  93.     int             add_count=0;
  94.     char            *def_path ="C:\\Outbound";
  95.     char            *fill1 ="*****************************";
  96.    int             ver = VER;
  97.    int             myzone = 1;
  98. #ifdef POLL110
  99. #ifdef ME
  100.     int             o_net = 119;        /* Originating Net */
  101.     int             o_node = 5;        /* Originating Node */
  102. #else
  103.     int             o_net = 0x1234;        /* Originating Net */
  104.     int             o_node = 0x5678;        /* Originating Node */
  105. #endif
  106. #endif
  107.     char            matrix_path[MAX_PATH];
  108.     char            in_path[MAX_PATH];
  109.     char            out_path[MAX_PATH];
  110.  
  111.  
  112. main(argc,argv)
  113. char    *argv[];
  114. int     argc;
  115.  
  116. {
  117. /*    int     k; */
  118.     int        i;
  119.     char    *files[30];
  120.     char    *sptr;
  121.     int     fcount = 0;
  122.  
  123. /* Process the "-" switches   */
  124.  
  125.     memset(pwd,0,9);
  126.  
  127.     if (argc<3)
  128.         usage();
  129.  
  130.     action = check(argv[1]);
  131.    errno = 0;
  132.     if (action == 0) {
  133.        oops("No action given",NULL,__LINE__);
  134.        }
  135.     strcpy(matrix_path,def_path);
  136.  
  137.     for (i=2; i<argc; i++) {
  138.         sptr = argv[i];
  139.         if (*sptr == '!') strcpy(pwd,argv[i]);
  140.         else if((*sptr == '-') ||
  141.             (*sptr == '/')) {
  142.             switch(*(sptr+1)){
  143.  
  144. #ifdef POLL110
  145.                 case 'O' :
  146.                 case 'o' :  sptr++;
  147.                             o_net = atoi(++sptr);
  148.                             sptr = strchr(sptr,'/');
  149.                             o_node = atoi(++sptr);
  150.                             break;
  151. #endif
  152.  
  153.  
  154.                 case '$' :
  155.                 case 'S' :
  156.                 case 's' :  if (strlen(sptr)>2)
  157.                                 add_count+=get_node(sptr+2,add_count,'$');
  158.                             else
  159.                                 noaddr();
  160.                             break;
  161.  
  162.                 case 'H' :
  163.                 case 'h' :  if (strlen(sptr)>2)
  164.                                add_count+=get_node(sptr+2,add_count,'H');
  165.                             else
  166.                                 noaddr();
  167.                             break;
  168.  
  169.                 case 'Q' :
  170.                 case 'q' :  if (strlen(sptr)>2)
  171.                                add_count+=get_node(sptr+2,add_count,'Q');
  172.                             else
  173.                                 noaddr();
  174.                             break;
  175.  
  176.                 case 'D' :
  177.                 case 'd' :
  178. #ifndef POLL110
  179.                 case 'O' :
  180.                 case 'o' :
  181. #endif
  182.                 case 'N' :
  183.                 case 'n' :  if (strlen(sptr)>2)
  184.                                 add_count+=get_node(sptr+2,add_count,'D');
  185.                             else
  186.                                 noaddr();
  187.                             break;
  188.  
  189.                 case 'C' :
  190.                 case 'c' :  if (strlen(sptr)>2)
  191.                                 add_count+=get_node(sptr+2,add_count,'C');
  192.                             else
  193.                                 noaddr();
  194.                             break;
  195.  
  196.                 case 'P'  :
  197.                 case 'p'  : strcpy(matrix_path,sptr+2);
  198.                             if (matrix_path[strlen(matrix_path)-1] == '\\')
  199.                                 matrix_path[strlen(matrix_path)-1]='\0';
  200.                             break;
  201.  
  202.  
  203.                 default   : cprintf("I don't understand '%s' skipping it.\r\n",sptr);
  204.                             break;
  205.                 }
  206.             }
  207.  
  208.         else {
  209.             if (((strchr(sptr,'/')) != NULL) &&
  210.                 (atoi(sptr) != 0)) {
  211.                 switch(action) {
  212.                     case STOP    :  add_count += get_node(sptr,add_count,'$');     break;
  213.                     case SEND    :    add_count += get_node(sptr,add_count,'D'); break;
  214.                     case REQUEST:    add_count += get_node(sptr,add_count,'D'); break;
  215.                     case UPDATE :    add_count += get_node(sptr,add_count,'D'); break;
  216.                     case POLL    :    add_count += get_node(sptr,add_count,'D'); break;
  217.                     case HOLD    :    add_count += get_node(sptr,add_count,'H'); break;
  218.                     case DIRECT    :    add_count += get_node(sptr,add_count,'D'); break;
  219.                     case CRASH    :    add_count += get_node(sptr,add_count,'C'); break;
  220.                     case TRUNC    :    add_count += get_node(sptr,add_count,'D'); break;
  221.                     case KILL_SEND:    add_count += get_node(sptr,add_count,'D'); break;
  222.                     }
  223.                 }
  224.             else {
  225.                 files[fcount] = (char *) malloc(1 + strlen(argv[i]));
  226.                 strcpy(files[fcount],strupr(argv[i]));
  227.                 if (fcount <30)
  228.                     fcount++;
  229.                 }
  230.             }
  231.         }
  232.  
  233.     if (action & REQUEST || action & SEND) {
  234.         for (i = 0;i < fcount;i++) {
  235.             if (action & REQUEST)
  236.                 do_req(files[i]);
  237.             else if (action & SEND)
  238.                 get_names(files[i]);
  239.             }
  240.         }
  241.     else if (action == STOP)
  242.             do_stops();
  243.     else if (action == POLL)
  244.         do_polls();
  245.     else {
  246.         switch(action) {
  247.             case HOLD   :   change('H');
  248.                             break;
  249.             case DIRECT :   change('D');
  250.                             break;
  251.             case CRASH  :   change('C');
  252.                             break;
  253.             }
  254.         }
  255.     exit(0);
  256. }
  257.  
  258. int    check(char *what) {
  259.     if (stricmp(what,"poll")==0)
  260.         return(POLL);
  261.     if (stricmp(what,"get")==0)
  262.         return(REQUEST);
  263.     if (stricmp(what,"send")==0)
  264.         return(SEND);
  265.     if (stricmp(what,"stop")==0)
  266.         return(STOP);
  267.     if (stricmp(what,"hold")==0)
  268.         return(HOLD);
  269.     if (stricmp(what,"crash")==0)
  270.         return(CRASH);
  271.     if (strnicmp(what,"norm",4)==0)
  272.         return(DIRECT);
  273.     if (strnicmp(what,"dir",3)==0)
  274.         return(DIRECT);
  275.     if (strnicmp(what,"trunc",5)==0)
  276.         return(TRUNC);
  277.     if (strnicmp(what,"kill",4)==0)
  278.         return(KILL_SEND);
  279.     if (strnicmp(what,"update",4)==0)
  280.         return(UPDATE);
  281.     return(0);
  282. }
  283.  
  284. void    do_stops(void) {
  285.    int      send;
  286.    int      done;
  287.    char     stop[MAX_PATH];
  288.    FILE        *fp;
  289.  
  290. #ifndef __TURBOC__
  291.    struct   find_t  find;
  292. #else
  293.    struct   ffblk   find;
  294. #endif
  295.  
  296.     for (send=0;send<add_count;send++){
  297.         if (address[send].zone == myzone)
  298.             sprintf(stop,"%s\\%04X%04X.$$?",
  299.                 matrix_path,address[send].net,address[send].node);
  300.         else
  301.             sprintf(stop,"%s.%03X\\%04X%04X.$$?",
  302.                 matrix_path,address[send].zone,address[send].net,address[send].node);
  303.  
  304. #ifndef __TURBOC__
  305.         done = _dos_findfirst(stop,_A_NORMAL,&find);
  306. #else
  307.         done = findfirst(stop,&find,0);
  308. #endif
  309.         if (done == 0) {
  310. #ifndef __TURBOC__
  311.         if (address[send].zone == myzone)
  312.             sprintf(stop,"%s\\%s", matrix_path,find.name);
  313.         else
  314.             sprintf(stop,"%s.%03X\\%s",
  315.                 matrix_path,address[send].zone,find.name);
  316. #else
  317.         if (address[send].zone == myzone)
  318.             sprintf(stop,"%s\\%s", matrix_path,find.ff_name);
  319.         else
  320.             sprintf(stop,"%s.%03X\\%s",
  321.                 matrix_path,address[send].zone,find.ff_name);
  322. #endif
  323.             unlink(stop);
  324.             }
  325.         if (address[send].zone == myzone)
  326.             sprintf(stop,"%s\\%04X%04X.$$5",
  327.                 matrix_path,address[send].net,address[send].node);
  328.         else
  329.             sprintf(stop,"%s.%03X\\%04X%04X.$$5",
  330.                 matrix_path,address[send].zone,address[send].net,address[send].node);
  331.         printf("Marking %d:%d/%d  as a no-send!\n",
  332.             address[send].zone,address[send].net,address[send].node);
  333.         errno = 0;
  334.         if ((fp = fopen(stop,"at")) == NULL)
  335.            oops("Can't open $$5 file ",stop,__LINE__);
  336.         fclose(fp);
  337.         }
  338.     return;
  339. }
  340.  
  341.  
  342.  
  343. void    do_polls(void) {
  344.         int     send;
  345.         char    path_out[64];
  346.         FILE    *outbound;
  347.  
  348.         for (send=0;send<add_count;send++) {
  349.  
  350. #ifdef POLL110
  351.           if (myzone == address[send].zone)
  352.               sprintf(path_out,"%s\\%04X%04X.%cUT",
  353.                   matrix_path,address[send].net,address[send].node,address[send].firstchar);
  354.            else
  355.                 sprintf(path_out,"%s.%03X\\%04X%04X.%cUT",
  356.                     matrix_path,address[send].zone,address[send].net,address[send].node,address[send].firstchar);
  357.             poll_110(address[send].net,address[send].node,path_out);
  358. #else
  359.           if (myzone == address[send].zone)
  360.               sprintf(path_out,"%s\\%04X%04X.%cLO",
  361.                   matrix_path,address[send].net,address[send].node,address[send].firstchar);
  362.            else
  363.                 sprintf(path_out,"%s.%03X\\%04X%04X.%cLO",
  364.                     matrix_path,address[send].zone,address[send].net,address[send].node,address[send].firstchar);
  365.           errno=0;
  366.           if ((outbound=fopen(path_out,"at")) != NULL) {
  367.              fclose(outbound);
  368.              printf("Creating %cLO file for %d:%d/%d\n",
  369.                address[send].firstchar,address[send].zone,
  370.                 address[send].net,address[send].node);
  371.                }
  372.           else 
  373.               oops("Can't create Poll",NULL,__LINE__);
  374. #endif
  375.       }
  376. }
  377.  
  378.  
  379. void    do_Rpolls(void) {
  380.         int     send;
  381.         char    path_out[64];
  382.         FILE    *outbound;
  383.  
  384.         for (send=0;send<add_count;send++) {
  385.  
  386. #ifdef POLL110
  387.           if (myzone == address[send].zone)
  388.               sprintf(path_out,"%s\\%04X%04X.%cRT",
  389.                   matrix_path,address[send].net,address[send].node,address[send].firstchar);
  390.            else
  391.                 sprintf(path_out,"%s.%03X\\%04X%04X.%cRT",
  392.                     matrix_path,address[send].zone,address[send].net,address[send].node,address[send].firstchar);
  393.             poll_110(address[send].net,address[send].node,path_out);
  394. #else
  395.           if (myzone == address[send].zone)
  396.               sprintf(path_out,"%s\\%04X%04X.%cRO",
  397.                   matrix_path,address[send].net,address[send].node,address[send].firstchar);
  398.            else
  399.                 sprintf(path_out,"%s.%03X\\%04X%04X.%cRO",
  400.                     matrix_path,address[send].zone,address[send].net,address[send].node,address[send].firstchar);
  401.           errno=0;
  402.           if ((outbound = fopen(path_out,"at")) != NULL) {
  403.              fclose(outbound);
  404.              printf("Creating %cRO file for %d:%d/%d\n",
  405.                address[send].firstchar,address[send].zone,
  406.                 address[send].net,address[send].node);
  407.                }
  408.           else 
  409.            oops("No action given",path_out,__LINE__);
  410. #endif
  411.       }
  412. }
  413.  
  414.  
  415.  
  416. void    get_names(char *local) {
  417.  
  418. #ifndef __TURBOC__
  419.         struct  find_t  c_file;
  420. #else
  421.         struct    ffblk    c_file;
  422. #endif
  423.         char    path1[64];
  424.         char    names[31][13];
  425.         char    *tmp;
  426.         FILE    *fp;
  427.         int        i;
  428.         int        done;
  429.         int        send;
  430.         int        file_count;
  431.         char    path_out[MAX_PATH];
  432.  
  433.         strcpy(path1,local);
  434.         if ((tmp = strrchr(path1,'\\')) != NULL) {
  435.             tmp++;
  436.             *tmp = 0x00;
  437.             }
  438.         else if ((tmp = strchr(path1,':')) != NULL) {
  439.             tmp++;
  440.             *tmp = 0x00;
  441.             }
  442.         else         /* if no path specified, make one */
  443.             getcwd(path1,MAX_PATH);
  444.  
  445.         if (path1[strlen(path1)-1] != '\\')
  446.             strcat(path1,"\\");
  447.         file_count=0;
  448. #ifndef __TURBOC__
  449.         done=_dos_findfirst(local,_A_NORMAL,&c_file);
  450. #else
  451.         done = findfirst(local,&c_file,0);
  452. #endif
  453.         while (!done && file_count < 30) {
  454. #ifndef __TURBOC__
  455.             strcpy(names[file_count],c_file.name);
  456. #else
  457.             strcpy(names[file_count],c_file.ff_name);
  458. #endif
  459.             file_count++;
  460. #ifndef __TURBOC__
  461.             done = _dos_findnext(&c_file);
  462. #else
  463.             done = findnext(&c_file);
  464. #endif
  465.             }
  466.  
  467.         if (file_count==0)
  468.             cprintf("No files: '%s' \n\n",local);
  469.  
  470.         if (file_count>0){
  471.             for (send=0;send<add_count;send++){
  472.                 if (myzone == address[send].zone)
  473.                     sprintf(path_out,"%s\\%04X%04X.%cLO",
  474.                         matrix_path, address[send].net, address[send].node,
  475.                             address[send].firstchar);
  476.                 else
  477.                     sprintf(path_out,"%s.%03X\\%04X%04X.%cLO",
  478.                         matrix_path, address[send].zone,
  479.                             address[send].net, address[send].node,
  480.                                 address[send].firstchar);
  481.                 errno = 0;
  482.                 if ((fp = fopen(path_out,"at")) == NULL)
  483.                    oops("Can't open FLO file ",path_out,__LINE__);
  484.                 for (i=0;i<file_count;i++){
  485.                     if (action == TRUNC)
  486.                         fprintf(fp,"#%s%s\n",path1,names[i]);
  487.                     else if (action == KILL_SEND)
  488.                         fprintf(fp,"^%s%s\n",path1,names[i]);
  489.                     else
  490.                         fprintf(fp,"%s%s\n",path1,names[i]);
  491.                     printf("%s%s to %d:%d/%d\n", path1, names[i],
  492.                         address[send].zone, address[send].net, address[send].node);
  493.                    if ((errno) && (errno != 2)){
  494.                        oops("Error writing ",path_out,__LINE__);
  495.                         }
  496.                     }
  497.                 fclose(fp);
  498.                 }
  499.             }
  500.         return;
  501. }
  502.  
  503. void    do_req(char *local) {
  504.  
  505.     int    send;
  506.     FILE    *fp;
  507.     char    path_out[MAX_PATH];
  508.     char    *tcheck;
  509.     int     done;
  510. #ifndef __TURBOC__
  511.     struct  find_t  c_file;
  512. #else
  513.     struct    ffblk    c_file;
  514. #endif
  515.     long    filetime = 0L;
  516.     struct  stat    *buf;
  517.     char    *npath;
  518.     char    *ch;
  519.  
  520.     do_Rpolls();
  521.  
  522.     buf = (struct stat *) malloc(sizeof(struct stat));
  523.     npath = (char *) malloc(80);
  524.  
  525.     for (send=0;send<add_count;send++)
  526.     {
  527.  
  528.       /*--------------------------------------------------------------------*/
  529.       /* Create or append the REQ file                                      */
  530.       /*--------------------------------------------------------------------*/
  531.  
  532.             if (myzone == address[send].zone)
  533.                 sprintf(path_out,"%s\\%04x%04x.REQ", matrix_path,
  534.                     address[send].net, address[send].node);
  535.             else
  536.                 sprintf(path_out,"%s.%03X\\%04x%04x.REQ", matrix_path,
  537.                     address[send].zone,address[send].net, address[send].node);
  538.             fp    = fopen(path_out,"at");
  539.               if (fp==NULL) oops("Unable to open the Request file",NULL,__LINE__);
  540.  
  541.       /*--------------------------------------------------------------------*/
  542.       /* Write the file names to the REQ file                               */
  543.       /*--------------------------------------------------------------------*/
  544.         if (action == UPDATE) {
  545.             tzset();
  546.             strcpy(npath,local);
  547.             if ((ch = strrchr(npath,'\\')) != NULL)
  548.                 ++ch;
  549.             else if ((ch = strrchr(npath,':')) != NULL)
  550.                 ++ch;
  551.             else
  552.                 ch = npath;
  553.  
  554. #ifndef __TURBOC__
  555.             done=_dos_findfirst(local,_A_NORMAL,&c_file);
  556. #else
  557.             done = findfirst(local,&c_file,0);
  558. #endif
  559.             while (done == 0) {
  560. #ifndef __TURBOC__
  561.                 strcpy(ch,c_file.name);
  562. #else
  563.                 strcpy(ch,c_file.ff_name);
  564. #endif
  565.                 stat(npath,buf);
  566.                 buf->st_atime -= timezone;
  567.                 if (filetime < buf->st_atime)
  568.                     filetime = buf->st_atime;
  569. #ifndef __TURBOC__
  570.                 done = _dos_findnext(&c_file);
  571. #else
  572.                 done = findnext(&c_file);
  573. #endif
  574.                 };        /* end of while loop */
  575.             if ((tcheck = strrchr(local,'\\')) == NULL) {
  576.                 if ((tcheck = strrchr(local,':')) == NULL)
  577.                     tcheck = local;
  578.                 else
  579.                     tcheck++;
  580.                 }
  581.             else
  582.                 tcheck++;
  583.  
  584.             if (strlen(pwd) > 0)
  585.                 fprintf(fp,"%s %s +%09ld\n",tcheck,pwd,filetime);
  586.             else
  587.                 fprintf(fp,"%s +%09ld\n",tcheck,filetime);
  588.             fclose(fp);
  589.             }        /* End of file update checking */
  590.         else {
  591.             if (strlen(pwd) > 0)
  592.                 fprintf(fp,"%s %s\n",local,pwd);
  593.             else
  594.                 fprintf(fp,"%s\n",local);
  595.             fclose(fp);
  596.             }
  597.          } /* for */
  598.     free(buf);
  599.     free(npath);
  600.     return;
  601. }
  602.  
  603.  
  604.  
  605. int get_node(char *arg,int addcount,int prefix)
  606. {
  607.     address[addcount].firstchar = prefix;
  608.  
  609.     address[addcount].zone = myzone;
  610.  
  611.     if (strchr(arg,':'))
  612.         sscanf(arg,"%d:%d/%d",
  613.             &address[addcount].zone,&address[addcount].net,
  614.             &address[addcount].node);
  615.     else if (strchr(arg,'/'))
  616.         sscanf(arg,"%d/%d",&address[addcount].net,&address[addcount].node);
  617.     else {
  618.         if (addcount) {
  619.             address[addcount].zone = address[addcount -1].zone;
  620.             address[addcount].net = address[addcount -1].net;
  621.             address[addcount].node = atoi(arg);
  622.         }
  623.         else {
  624.             printf("Must supply NET for first destination - %s ignored\n",
  625.                 arg);
  626.             return(0);
  627.             }
  628.         }
  629.     return(1);
  630. }
  631.  
  632.  
  633. void    oops(char *message,char *argument,int line)
  634. {
  635.       cprintf( "\r\n\nERR: %d %s", line, message );
  636.       if (argument) cprintf(" (%s)",argument);
  637.       cputs("\r\n\n");
  638.       usage();
  639. }
  640.  
  641.  
  642. /* -----------------------------------------------
  643.         USAGE
  644.    ----------------------------------------------- */
  645.  
  646. void    usage(void) {
  647.  
  648. printf("\n\n\n\tUSAGE: \n\n");
  649. printf("Omail [POLL][GET][SEND][STOP] [FILE(s)] -[S][C][H][D]Net/Node [!Password]\n");
  650. printf("           [-POutbound\\Path\\]\n\n");
  651. printf("The first arguement must be one of these.\n\n");
  652. printf("POLL ....... Generate a Null *.?LO file for each Net/Node listed\n");
  653. printf("GET ........ WaZoo Request File(s) from Net/Node (may need !Password) \n");
  654. printf("UPDATE ..... Ask for a file update. Give your file's FULL PATH!!\n");
  655. printf("SEND ....... Send File(s) to Net/Node\n");
  656. printf("TRUNC ...... Send File(s) to Net/Node, and then set it to 0 length\n");
  657. printf("KILL ....... Send File(s) to Net/Node, and then delete it (Binkley!!)\n");
  658. printf("STOP ....... Create a *.$$5 file to stop outbound calls.\n");
  659. printf("HOLD ....... Change any mail for the boards on the command line to hold.\n");
  660. printf("CRASH ...... Change any mail for the boards on the command line to crash.\n");
  661. printf("DIRECT ..... Change any mail for the boards on the command line to direct.\n");
  662. printf("You may Poll/Send/Get to/from multiple boards and files, but each Net/Node \n");
  663. printf("MUST begin with the -[c][h][d] where:\n\n");
  664. printf("\tC ........ Continuous Mail packet is created.\n");
  665. printf("\tH ........ Hold Mail packet is created.\n");
  666. printf("\tD ........ Direct Mail packet is created.\n");
  667. printf("\tS ........ Used only to stop calls to a board\n");
  668. printf("\tQ ........ Used with Binkley >2.10 to generate turn-around list\n");
  669. printf("\tP ........ Change the outbound path from the default C:\\OUTBOUND\n");
  670. printf("\t           to match whatever you use.\n\n");
  671. printf("You can operate on multiple boards, but you can carry on one TYPE of \n");
  672. printf("transaction each run.  If you need to use a password with a file-request\n");
  673. printf("then only the LAST password entered will have any effect. Be careful!\n");
  674. printf("Some of these commands may not work with your mailer!\n\t\t\t\t\t\tDoug Boone 119/5 \n");
  675.  
  676. if (errno)
  677.    perror("Error was: ");
  678.         exit(1);
  679. }
  680.  
  681. void noaddr(void) {
  682.  
  683.     printf("\n No address listed, skipping\n");
  684. }
  685.  
  686. #ifdef POLL110
  687. void    poll_110(int d_net,int d_node,char *path_out) {
  688.  
  689.     int     outfp;
  690.     int        i;
  691.     struct  tm  *tm_now;
  692.     time_t  now;
  693.     struct  _pkthdr *header;
  694.     char    *fixup;
  695.  
  696.     if (access(path_out,0) == 0)
  697.         return;
  698.  
  699.     header = (struct _pkthdr *) malloc(sizeof(struct _pkthdr)+1);
  700.  
  701.     time(&now);
  702.     tm_now = gmtime(&now);
  703.     outfp = open(path_out,O_BINARY|O_RDWR|O_CREAT,S_IREAD|S_IWRITE);
  704.  
  705. /* Update the packet header to reflect that its been messed with */
  706.  
  707.     header->orig_node = o_node;
  708.     header->dest_node = d_node;
  709.     header->year = tm_now->tm_year + 1900;
  710.     header->month = tm_now->tm_mon + 1;
  711.     header->day = tm_now->tm_mday;
  712.  
  713.     header->hour = tm_now->tm_hour;
  714.     header->minute = tm_now->tm_min;
  715.     header->second = tm_now->tm_sec;
  716.     header->rate = 0;
  717.     header->ver = 2;
  718.     header->orig_net = o_net;
  719.     header->dest_net = d_net;
  720.     header->product = PROD_CODE;
  721.     header->x1 = 0x00;
  722.     for (i=0;i<6;i++)
  723.         header->pktpwd[i] = 0x00;
  724.     for (i=0;i<2;i++)
  725.         header->B_fill1[i] = 0x00;
  726.     header->Orig_Zone = 0x00;
  727.     header->Dest_Zone = 0x00;
  728.     for (i=0;i<16;i++)
  729.         header->B_fill2[i] = 0x00;
  730.     header->B_fill3 = 0L;
  731.     i = write(outfp,header,sizeof(struct _pkthdr));
  732.     if (i<60) {
  733.         i = 60 - i;
  734.         fixup = (char *) malloc(i+1);
  735.         memset(fixup,0x00,i);
  736.         write(outfp,fixup,i);
  737.         free(fixup);
  738.         }
  739.     close(outfp);
  740.     printf("Creating %s for %d/%d\n", path_out,d_net,d_node);
  741.     free(header);
  742.     return;
  743. }
  744. #endif
  745.  
  746. void    change(char act) {
  747.  
  748.     int     i;
  749.     char    temp_path[MAX_PATH];
  750.     char    *temp_buffer;
  751.     int     done;
  752.     unsigned    int        tcheck;
  753.     unsigned    int        written;
  754.     int     buff_size;
  755.     char    *result;
  756.     char    name[13];
  757.     int     inhandle,outhandle;
  758.  
  759. #ifdef  __TURBOC__
  760.     struct  ffblk   find;
  761. #else
  762.     struct  find_t  find;
  763. #endif
  764.  
  765.     for (i=0;i < add_count;i++) {
  766.         if (myzone == address[i].zone) {
  767.             sprintf(temp_path,"%s\\%04X%04X.?LO",
  768.                 matrix_path,address[i].net,address[i].node);
  769.             sprintf(out_path,"%s\\%04X%04X.%cLO",
  770.                 matrix_path,address[i].net,address[i].node,act);
  771.             }
  772.         else {
  773.             sprintf(temp_path,"%s.%03X\\%04X%04X.?LO",
  774.                 matrix_path,address[i].zone,address[i].net,address[i].node);
  775.             sprintf(out_path,"%s.%03X\\%04X%04X.%cLO",
  776.                 matrix_path,address[i].zone,address[i].net,address[i].node,act);
  777.             }
  778.  
  779. #ifdef  __TURBOC__
  780.         done = findfirst(temp_path,&find,0);
  781. #else
  782.         done = _dos_findfirst(temp_path,_A_NORMAL,&find);
  783. #endif
  784.  
  785.         while (done == 0) {
  786.  
  787. #ifdef  __TURBOC__
  788.             strcpy(name,find.ff_name);
  789.             buff_size = find.ff_fsize;
  790. #else
  791.             strcpy(name,find.name);
  792.             buff_size = find.size;
  793. #endif
  794.             strupr(name);
  795.             result = strchr(name,'.');
  796.             result++;
  797.             if (*result != act) {
  798.                 if (myzone == address[i].zone)
  799.                     sprintf(in_path,"%s\\%s",matrix_path,name);
  800.                 else
  801.                     sprintf(in_path,"%s.%03X\\%s",
  802.                         matrix_path,address[i].zone,name);
  803.                 if ((rename(in_path,out_path)) != 0) {
  804.                     temp_buffer = (char *) malloc(buff_size+1);
  805.                     inhandle = open(in_path,O_RDONLY|O_BINARY);
  806.                     outhandle = open(out_path,O_APPEND|O_BINARY|O_WRONLY);
  807.                     printf("Appending: %s\nTo:        %s\n",in_path,out_path);
  808.                     do {
  809.                         tcheck = read(inhandle,temp_buffer,buff_size);
  810.                         if (tcheck)
  811.                             written = write(outhandle,temp_buffer,tcheck);
  812.                         } while (tcheck > 0);
  813.                     close(inhandle);
  814.                     close(outhandle);
  815.                     if (written != 0xfffe)
  816.                         unlink(in_path);
  817.                     free(temp_buffer);
  818.                     }        /* Done copying FLO if rename failed */
  819.                 else
  820.                     printf("Renaming:  %s\nTo:        %s\n",in_path,out_path);
  821.                 }        /* Done with rename/copy file to new name */
  822.  
  823. #ifdef  __TURBOC__
  824.             done = findnext(&find);
  825. #else
  826.             done = _dos_findnext(&find);
  827. #endif
  828.             }        /* Done with *.?LO Files Go do *.?UT files */
  829.  
  830. /*--------------------------------------------------------------------------*/
  831. /* Done with *.?LO, on to *.?RO                                             */
  832. /*--------------------------------------------------------------------------*/
  833.         if (myzone == address[i].zone) {
  834.             sprintf(temp_path,"%s\\%04X%04X.?RO",
  835.                 matrix_path,address[i].net,address[i].node);
  836.             sprintf(out_path,"%s\\%04X%04X.%cRO",
  837.                 matrix_path,address[i].net,address[i].node,act);
  838.             }
  839.         else {
  840.             sprintf(temp_path,"%s.%03X\\%04X%04X.?RO",
  841.                 matrix_path,address[i].zone,address[i].net,address[i].node);
  842.             sprintf(out_path,"%s.%03X\\%04X%04X.%cRO",
  843.                 matrix_path,address[i].zone,address[i].net,address[i].node,act);
  844.             }
  845.  
  846. #ifdef  __TURBOC__
  847.         done = findfirst(temp_path,&find,0);
  848. #else
  849.         done = _dos_findfirst(temp_path,_A_NORMAL,&find);
  850. #endif
  851.  
  852.         while (done == 0) {
  853.  
  854. #ifdef  __TURBOC__
  855.             strcpy(name,find.ff_name);
  856.             buff_size = find.ff_fsize;
  857. #else
  858.             strcpy(name,find.name);
  859.             buff_size = find.size;
  860. #endif
  861.             strupr(name);
  862.             result = strchr(name,'.');
  863.             result++;
  864.             if (*result != act) {
  865.                 if (myzone == address[i].zone)
  866.                     sprintf(in_path,"%s\\%s",matrix_path,name);
  867.                 else
  868.                     sprintf(in_path,"%s.%03X\\%s",
  869.                         matrix_path,address[i].zone,name);
  870.                 if ((rename(in_path,out_path)) != 0) {
  871.                     temp_buffer = (char *) malloc(buff_size+1);
  872.                     inhandle = open(in_path,O_RDONLY|O_BINARY);
  873.                     outhandle = open(out_path,O_APPEND|O_BINARY|O_WRONLY);
  874.                     printf("Appending: %s\nTo:        %s\n",in_path,out_path);
  875.                     do {
  876.                         tcheck = read(inhandle,temp_buffer,buff_size);
  877.                         if (tcheck)
  878.                             written = write(outhandle,temp_buffer,tcheck);
  879.                         } while (tcheck > 0);
  880.                     close(inhandle);
  881.                     close(outhandle);
  882.                     if (written != 0xfffe)
  883.                         unlink(in_path);
  884.                     free(temp_buffer);
  885.                     }        /* Done copying FLO if rename failed */
  886.                 else
  887.                     printf("Renaming:  %s\nTo:        %s\n",in_path,out_path);
  888.                 }        /* Done with rename/copy file to new name */
  889.  
  890. #ifdef  __TURBOC__
  891.             done = findnext(&find);
  892. #else
  893.             done = _dos_findnext(&find);
  894. #endif
  895.             }        /* Done with *.?LO Files Go do *.?UT files */
  896.  
  897. /*--------------------------------------------------------------------------*/
  898. /* Now handle *.?UT files                                                   */
  899. /*--------------------------------------------------------------------------*/
  900.         if (myzone == address[i].zone) {
  901.             sprintf(temp_path,"%s\\%04X%04X.?UT",
  902.                 matrix_path,address[i].net,address[i].node);
  903.             sprintf(out_path,"%s\\%04X%04X.%cUT",
  904.                 matrix_path,address[i].net,address[i].node,act);
  905.             }
  906.         else {
  907.             sprintf(temp_path,"%s.%03X\\%04X%04X.?UT",
  908.                 matrix_path,address[i].zone,address[i].net,address[i].node);
  909.             sprintf(out_path,"%s.%03X\\%04X%04X.%cUT",
  910.                 matrix_path,address[i].zone,address[i].net,address[i].node,act);
  911.             }
  912.  
  913. #ifdef  __TURBOC__
  914.         done = findfirst(temp_path,&find,0);
  915. #else
  916.         done = _dos_findfirst(temp_path,_A_NORMAL,&find);
  917. #endif
  918.  
  919.         while (done == 0) {
  920.  
  921. #ifdef  __TURBOC__
  922.             strcpy(name,find.ff_name);
  923.             buff_size = find.ff_fsize;
  924. #else
  925.             strcpy(name,find.name);
  926.             buff_size = find.size;
  927. #endif
  928.             strupr(name);
  929.             result = strchr(name,'.');
  930.             result++;
  931.             if (*result != act) {
  932.                 if (myzone == address[i].zone)
  933.                     sprintf(in_path,"%s\\%s",matrix_path,name);
  934.                 else
  935.                     sprintf(in_path,"%s.%03X\\%s",
  936.                     matrix_path,address[i].zone,name);
  937.                 if ((rename(in_path,out_path)) != 0) {
  938.                     if (buff_size > 60)
  939.                         do_append(buff_size);
  940.                     }        /* Done copying FLO if rename failed */
  941.                 else
  942.                     printf("Renaming:  %s\nTo:        %s\n",in_path,out_path);
  943.                 }        /* Done with rename/copy file to new name */
  944.  
  945. #ifdef  __TURBOC__
  946.             done = findnext(&find);
  947. #else
  948.             done = _dos_findnext(&find);
  949. #endif
  950.             }        /* Done handling *.?UT files */
  951. /*--------------------------------------------------------------------------*/
  952. /* And finally *.?RT files                                                  */
  953. /*--------------------------------------------------------------------------*/
  954. /*--------------------------------------------------------------------------*/
  955. /* Now handle *.?UT files                                                   */
  956. /*--------------------------------------------------------------------------*/
  957.         if (myzone == address[i].zone) {
  958.             sprintf(temp_path,"%s\\%04X%04X.?RT",
  959.                 matrix_path,address[i].net,address[i].node);
  960.             sprintf(out_path,"%s\\%04X%04X.%cRT",
  961.                 matrix_path,address[i].net,address[i].node,act);
  962.             }
  963.         else {
  964.             sprintf(temp_path,"%s.%03X\\%04X%04X.?RT",
  965.                 matrix_path,address[i].zone,address[i].net,address[i].node);
  966.             sprintf(out_path,"%s.%03X\\%04X%04X.%cRT",
  967.                 matrix_path,address[i].zone,address[i].net,address[i].node,act);
  968.             }
  969.  
  970. #ifdef  __TURBOC__
  971.         done = findfirst(temp_path,&find,0);
  972. #else
  973.         done = _dos_findfirst(temp_path,_A_NORMAL,&find);
  974. #endif
  975.  
  976.         while (done == 0) {
  977.  
  978. #ifdef  __TURBOC__
  979.             strcpy(name,find.ff_name);
  980.             buff_size = find.ff_fsize;
  981. #else
  982.             strcpy(name,find.name);
  983.             buff_size = find.size;
  984. #endif
  985.             strupr(name);
  986.             result = strchr(name,'.');
  987.             result++;
  988.             if (*result != act) {
  989.                 if (myzone == address[i].zone)
  990.                     sprintf(in_path,"%s\\%s",matrix_path,name);
  991.                 else
  992.                     sprintf(in_path,"%s.%03X\\%s",
  993.                     matrix_path,address[i].zone,name);
  994.                 if ((rename(in_path,out_path)) != 0) {
  995.                     if (buff_size > 60)
  996.                         do_append(buff_size);
  997.                     }        /* Done copying FLO if rename failed */
  998.                 else
  999.                     printf("Renaming:  %s\nTo:        %s\n",in_path,out_path);
  1000.                 }        /* Done with rename/copy file to new name */
  1001.  
  1002. #ifdef  __TURBOC__
  1003.             done = findnext(&find);
  1004. #else
  1005.             done = _dos_findnext(&find);
  1006. #endif
  1007.             }        /* Done handling *.?RT files */
  1008. /*--------------------------------------------------------------------------*/
  1009.         }        /* End of main for(;;) loop */
  1010.     return;
  1011. }
  1012.  
  1013.  
  1014. void    do_append(unsigned int size) {
  1015.  
  1016.     int     infp,outfp;
  1017.     struct  tm  *tm_now;
  1018.     time_t    now;
  1019.     struct  _pkthdr *header;
  1020.     char    *copy;
  1021.     unsigned    int     buff_size;
  1022.     unsigned    int        go;
  1023.  
  1024.     printf("Appending: %s\nTo:        %s\n", in_path,out_path);
  1025.  
  1026.     header = (struct _pkthdr *) malloc(sizeof(struct _pkthdr)+1);
  1027.  
  1028.     time(&now);
  1029.     tm_now = localtime(&now);
  1030.     outfp = open(out_path,O_BINARY|O_RDWR);
  1031.     infp = open(in_path,O_BINARY|O_RDONLY);
  1032.  
  1033.     go = read(outfp,header,sizeof(struct _pkthdr));
  1034.     lseek(outfp,0L,SEEK_SET);
  1035.  
  1036. /* Update the packet header to reflect that its been messed with */
  1037.  
  1038.     header->year = tm_now->tm_year + 1900;
  1039.     header->month = tm_now->tm_mon + 1;
  1040.     header->day = tm_now->tm_mday;
  1041.  
  1042.     header->hour = tm_now->tm_hour;
  1043.     header->minute = tm_now->tm_min;
  1044.     header->second = tm_now->tm_sec;
  1045.     header->product = PROD_CODE;
  1046.  
  1047.     go = write(outfp,header,sizeof(struct _pkthdr));
  1048.     free(header);
  1049.  
  1050.     lseek(outfp,-2L,SEEK_END);
  1051.     lseek(infp,((long)sizeof(struct _pkthdr)),SEEK_SET);
  1052.     size -= sizeof(struct _pkthdr);
  1053.     buff_size = size;
  1054.     if ((copy = (char *) malloc(buff_size)) == NULL) {
  1055.         do {
  1056.             buff_size = (buff_size/10) * 9;
  1057.             copy = (char *) malloc(buff_size);
  1058.             } while (copy == NULL);
  1059.         }
  1060.     do {
  1061.         go = read(infp,copy,buff_size);
  1062.         go = write(outfp,copy,go);
  1063.         size -= buff_size;
  1064.         if (buff_size > size)
  1065.             buff_size = size;
  1066.         } while (size > 0);
  1067.     free(copy);
  1068.     close(infp);
  1069.     close(outfp);
  1070.     if (go > 0)
  1071.         unlink(in_path);
  1072.     else
  1073.         printf("\nError appending %s to %s\n\n",in_path,out_path);
  1074.     return;
  1075. }
  1076.  
  1077.