home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OS2OMAIL.ZIP / OMAIL.C < prev    next >
Text File  |  1989-05-21  |  23KB  |  858 lines

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