home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / LharcUUCP0_22.lha / LharcUUCP / source / RCS / LharcUUCP.c,v < prev    next >
Encoding:
Text File  |  1993-12-18  |  46.7 KB  |  1,761 lines

  1. head    0.25;
  2. access;
  3. symbols;
  4. locks
  5.     simons:0.25; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 0.25
  10. date    93.12.18.21.43.11;    author simons;    state Exp;
  11. branches;
  12. next    0.24;
  13.  
  14. 0.24
  15. date    93.12.14.22.04.24;    author simons;    state Exp;
  16. branches;
  17. next    0.23;
  18.  
  19. 0.23
  20. date    93.12.14.21.52.37;    author simons;    state Exp;
  21. branches;
  22. next    0.22;
  23.  
  24. 0.22
  25. date    93.12.14.21.25.45;    author simons;    state Exp;
  26. branches;
  27. next    0.21;
  28.  
  29. 0.21
  30. date    93.12.14.17.59.16;    author simons;    state Exp;
  31. branches;
  32. next    0.20;
  33.  
  34. 0.20
  35. date    93.12.14.16.42.41;    author simons;    state Exp;
  36. branches;
  37. next    0.19;
  38.  
  39. 0.19
  40. date    93.12.14.15.21.36;    author simons;    state Exp;
  41. branches;
  42. next    0.18;
  43.  
  44. 0.18
  45. date    93.12.14.15.05.36;    author simons;    state Exp;
  46. branches;
  47. next    0.17;
  48.  
  49. 0.17
  50. date    93.12.11.14.31.46;    author simons;    state Exp;
  51. branches;
  52. next    0.16;
  53.  
  54. 0.16
  55. date    93.12.10.22.26.14;    author simons;    state Exp;
  56. branches;
  57. next    0.15;
  58.  
  59. 0.15
  60. date    93.12.08.17.11.03;    author simons;    state Exp;
  61. branches;
  62. next    0.14;
  63.  
  64. 0.14
  65. date    93.12.07.02.22.48;    author simons;    state Exp;
  66. branches;
  67. next    0.13;
  68.  
  69. 0.13
  70. date    93.12.07.02.15.50;    author simons;    state Exp;
  71. branches;
  72. next    0.12;
  73.  
  74. 0.12
  75. date    93.12.05.16.11.39;    author simons;    state Exp;
  76. branches;
  77. next    0.11;
  78.  
  79. 0.11
  80. date    93.12.05.15.46.13;    author simons;    state Exp;
  81. branches;
  82. next    0.10;
  83.  
  84. 0.10
  85. date    93.12.05.13.32.37;    author simons;    state Exp;
  86. branches;
  87. next    0.9;
  88.  
  89. 0.9
  90. date    93.12.05.13.19.28;    author simons;    state Exp;
  91. branches;
  92. next    0.8;
  93.  
  94. 0.8
  95. date    93.12.05.00.35.28;    author simons;    state Exp;
  96. branches;
  97. next    0.7;
  98.  
  99. 0.7
  100. date    93.12.05.00.29.29;    author simons;    state Exp;
  101. branches;
  102. next    0.6;
  103.  
  104. 0.6
  105. date    93.12.04.22.34.33;    author simons;    state Exp;
  106. branches;
  107. next    0.5;
  108.  
  109. 0.5
  110. date    93.12.04.22.30.44;    author simons;    state Exp;
  111. branches;
  112. next    0.4;
  113.  
  114. 0.4
  115. date    93.12.04.20.44.35;    author simons;    state Exp;
  116. branches;
  117. next    0.3;
  118.  
  119. 0.3
  120. date    93.12.04.18.05.00;    author simons;    state Exp;
  121. branches;
  122. next    0.2;
  123.  
  124. 0.2
  125. date    93.12.04.17.13.04;    author simons;    state Exp;
  126. branches;
  127. next    0.1;
  128.  
  129. 0.1
  130. date    93.12.04.13.45.54;    author simons;    state Exp;
  131. branches;
  132. next    ;
  133.  
  134.  
  135. desc
  136. @This program converts all queued UUCP jobs in the format required by
  137. the receiver and archives them into one archive file, using lharc or
  138. a similar archiver.
  139. Then it generates the appropiate C.* file to make UUCico transfer the
  140. archive.
  141. Additionally, a modified UUXqt which understands the 'rlharc' type is
  142. required--but that patch is trivial.
  143. @
  144.  
  145.  
  146. 0.25
  147. log
  148. @Added the myGetConfigEntry() routine to make accessing configuration
  149. easier.
  150. Added config-keywords allowing to specify a batchonlygrade per system.
  151. The name of the keyword is "BatchOnlyGrade_<systemname>". If this
  152. entry can't be found or is invalid, the global default is used.
  153. @
  154. text
  155. @/*
  156.  *      $Filename: LharcUUCP.c $
  157.  *      $Revision: 0.24 $
  158.  *      $Date: 1993/12/14 22:04:24 $
  159.  *
  160.  *      Copyright (C) 1993 by Peter Simons <simons@@peti.GUN.de>
  161.  *
  162.  *      This program is free software; you can redistribute it and/or
  163.  *      modify it under the terms of the GNU General Public License as
  164.  *      published by the Free Software Foundation; either version 2 of
  165.  *      the License, or (at your option) any later version.
  166.  *
  167.  *      This program is distributed in the hope that it will be useful,
  168.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  169.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  170.  *      General Public License for more details.
  171.  *
  172.  *      You should have received a copy of the GNU General Public License
  173.  *      along with this program; if not, write to the Free Software
  174.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  175.  *
  176.  *      $Id: LharcUUCP.c,v 0.24 1993/12/14 22:04:24 simons Exp simons $
  177.  *
  178.  * ------------------------------ log history ----------------------------
  179.  * $Log: LharcUUCP.c,v $
  180.  * Revision 0.24  1993/12/14  22:04:24  simons
  181.  * Added check, wether the specified grade is a valid alpha-numeric
  182.  * character or not.
  183.  *
  184.  * Revision 0.23  1993/12/14  21:52:37  simons
  185.  * Added a comment describing IsPath().
  186.  *
  187.  * Revision 0.22  1993/12/14  21:25:45  simons
  188.  * Changed the main loop in LharcJob() to free the C.* file as soon as
  189.  * possible, right after the renames, so that an eventually waiting uucico
  190.  * doesn't get blocked.
  191.  *
  192.  * Revision 0.21  1993/12/14  17:59:16  simons
  193.  * Remved the tests in the routines handling with grades. Now we just need
  194.  * one central test in LharcUUCPJob(), right after the configfile is read.
  195.  * Changed the arraysize for the filenames in jobs to 256 byte.
  196.  * Changed GoNextLine() to work with a following feof().
  197.  * Added IsPath() to determine the validity of the requests.
  198.  * Changed the way, IsValidJob() recognizes 'unbatchable' UUCP requests. The
  199.  * last version just counted the number of lines (If that's no hack, what
  200.  * else? :->), while this version recognizes the paths.
  201.  * Added a missing comment in the history (for 0.18).
  202.  * Added a few comments.
  203.  *
  204.  * Revision 0.20  1993/12/14  16:42:41  simons
  205.  * Adedd a DOS version string using C='s bumprev tool.
  206.  * Changes usage-output.
  207.  *
  208.  * Revision 0.19  1993/12/14  15:21:36  simons
  209.  * Added a variable 'LharcBatchGrade' determining the batch-grade of our
  210.  * own job. This defaults to 'A'. Currently, this is only global for the
  211.  * whole system.
  212.  *
  213.  * Revision 0.18  1993/12/14  15:05:36  simons
  214.  * Added a grade-check into IsValidJob(). This required two more parameters:
  215.  * systemname and grade. Currently, the grade is only global, but I'll add
  216.  * some local way.
  217.  * Changed the order of checks in IsValidJob(). Now, the check requiring
  218.  * fileaccess is the last one.
  219.  *
  220.  * Revision 0.17  1993/12/11  14:31:46  simons
  221.  * LharcUUCP is now able to parse the UUCP main config file and determine
  222.  * the sitename from the appropiate entry there. However, HOSTNAME is tested
  223.  * before parsing the file and still has priority. Local vars aren't
  224.  * supported.
  225.  *
  226.  * Revision 0.16  1993/12/10  22:26:14  simons
  227.  * Added the command ("m") in the LHARC-define.
  228.  * LharcUUCP() now terminates, when the current C.* file is already locked,
  229.  * because this usually means, that uucico is currently working on this job
  230.  * and our batch would fail anyway, so we better process the next job.
  231.  * Then LharcUUCP() used to unlock the C.* file before deleting it. This
  232.  * has been fixed.
  233.  * Now, we're locking the full archive name (<system>.LHARCPOSTFIX), to
  234.  * avoid problems with uucico, trying to transfer our archive while we're
  235.  * working on it.
  236.  *
  237.  * Revision 0.15  1993/12/08  17:11:03  simons
  238.  * Changed the call to InitDirScan() to match the new routines.
  239.  *
  240.  * Revision 0.14  1993/12/07  02:22:48  simons
  241.  * Changed the spool directory finding routine again.
  242.  *
  243.  * Revision 0.13  1993/12/07  02:15:50  simons
  244.  * Now checking for a spooldirectory with a truncated systemname, too.
  245.  *
  246.  * Revision 0.12  1993/12/05  16:11:39  simons
  247.  * IsValidJob() didn't free the locked files.
  248.  *
  249.  * Revision 0.11  1993/12/05  15:46:13  simons
  250.  * Added IsValidJob() which determines if we should process this job.
  251.  * Currently, only mail and news are processed--UUCP commands and our
  252.  * own archive-copy is skipped. Since this check is now in a seperate
  253.  * routine, LharcJob() has become a little bit easier and more straight.
  254.  *
  255.  * Revision 0.10  1993/12/05  13:32:37  simons
  256.  * PostArchive() is now called only, when actually a job has been processed.
  257.  * Additionally, it's called after the process is finished, not every time
  258.  * the archive changed. I'm not completely sure if this is the better
  259.  * way--will need some thought.
  260.  *
  261.  * Revision 0.9  1993/12/05  13:19:28  simons
  262.  * HOMESYSTEM is not determined at startup from the related enviroment
  263.  * variable, maybe I'll add configfile parsing some day.
  264.  * Change the order of the tests in main(): Now the commandline is checked
  265.  * first.
  266.  * Added TruncName(), which makes the handling of the 7-char-maximum
  267.  * systemnames easier.
  268.  * Changed commentblock style.
  269.  *
  270.  * Revision 0.8  1993/12/05  00:35:28  simons
  271.  * The history in the sourcefile was broken.
  272.  * Also I didn't mention the seq-routines, I took from Dillon UUCP.
  273.  * Known bug: LharcUUCP packs it's self-generated Archive job. :-) It
  274.  *            doesn't really matter, but I'll find a way around this.
  275.  *
  276.  * Revision 0.7  1993/12/05  00:29:29  simons
  277.  * Added PostArchive(), a small and neat routine to create the X.* and
  278.  * the C.* file for the archive.
  279.  *
  280.  * Revision 0.6  1993/12/04  22:34:33  simons
  281.  * The outgoing-archive is now locked while the archiver runs. Actually,
  282.  * only the systemname is used to lock the archive, not the complete name,
  283.  * like "peti.lha" or something similar. So, the mechanism will work with
  284.  * different archivers than LhA on the Amiga platform.
  285.  *
  286.  * Revision 0.5  1993/12/04  22:30:44  simons
  287.  * Now actually starting the archiver, creating a file names <system>.lha,
  288.  * located in the appropiate outgoing directory.
  289.  *
  290.  * Revision 0.4  1993/12/04  20:44:35  simons
  291.  * Moved the directory scanning routine into an extra module, since this
  292.  * is the only routine that is really system-dependant.
  293.  *
  294.  * Revision 0.3  1993/12/04  18:05:00  simons
  295.  * LharcJob() now reads the C.* files and renames the D.* and X.* file to
  296.  * the names they shall have on the remote system, so they can be easily
  297.  * packed.
  298.  * Non-send-jobs are recognized.
  299.  * UUCP jobs (which are send-jobs in fact) are merely recognized, although
  300.  * the current method (UUCP-jobs have only one line!) is a hack. I'll
  301.  * change that soon.
  302.  * Also some problems with the directory scanning routine occur. I will
  303.  * have to re-write GetFileName() soon, too.
  304.  *
  305.  * Revision 0.2  1993/12/04  17:13:04 simons
  306.  * Added commandline parsing, calling PackSpoolJobs() for every provided
  307.  * system.
  308.  * Added GetFileName() which is able to scan a directory for files,
  309.  * matching a certain pattern.
  310.  * Added a basic LharcJob() call, which just locks and opens the file
  311.  * until now.
  312.  *
  313.  * Revision 0.1 1993/12/04 13:45:54 simons
  314.  * This program is released under the GNU General Public License.
  315.  */
  316.  
  317.  
  318. /************************************* includes ***********/
  319. #include <stdio.h>
  320. #include <stdlib.h>
  321. #include <string.h>
  322. #include <ctype.h>
  323. #include <dos.h>
  324. #include <proto/dos.h>
  325.  
  326. #include "LharcUUCP_rev.h"
  327.  
  328. /************************************* defines ************/
  329. #define BUFFERSIZE 128
  330. #define UUSPOOL "UUSpool:"
  331. #define SEQ "UULib:Seq"
  332. #define LHARC "LhA m"           /* archiver command, moving enabled */
  333. #define LHARCPOSTFIX ".lha"
  334.  
  335. #define USAGE VERS " -- written by Peter Simons <simons@@peti.GUN.de>\n" \
  336.               "Usage: LharcUUCP system [[system] [...]]\n"
  337.  
  338. /************************************* prototypes *********/
  339. void PackSpoolJobs(char *systemname);
  340. char *GetFileName(char *pattern, int reset);
  341. void LharcJob(char *systemname, char *cfile, char grade);
  342. void PostArchive(char *systemname, char *postfix, char grade);
  343. char *TruncName(char *string);
  344. int IsValidJob(char *cfilename, char *systemname, char grade);
  345. int GoNextLine(FILE *fh);
  346. unsigned int GetSequence(unsigned int);
  347. char *SeqToName(unsigned int);
  348. int IsPath(char *filename);
  349. char *myGetConfigEntry(char *keyword, char *def);
  350.  
  351. void LockFile(char *);
  352. int FileIsLocked(char *);
  353. void UnLockFile(char *);
  354. void UnLockFiles(void);
  355.  
  356. int InitDirScan(char *);
  357. char *ScanNextFile(void);
  358. void EndDirScan(void);
  359.  
  360. char *GetConfigEntry(char *, char *, char *);
  361.  
  362. /************************************* global variables ***/
  363. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.24 1993/12/14 22:04:24 simons Exp simons $";
  364. static const char __DOSVer[] = VERSTAG;
  365. char *homesystem;
  366. int processed_flag;
  367.  
  368. /************************************* program ************/
  369.  
  370. int main(int argc, char **argv)
  371. {
  372.         char currentdir[512];
  373.  
  374.         if (argc < 2) {
  375.                 fprintf(stderr, USAGE);
  376.                 return 10;
  377.         }
  378.  
  379.         if (!(homesystem = getenv("HOSTNAME")))
  380.                 if (!(homesystem = GetConfigEntry(NULL, "NodeName", NULL))) {
  381.                         fprintf(stderr, "LharcUUCP: Can't determine the name of this machine!\n");
  382.                         return 10;
  383.                 }
  384.  
  385.         if (getcd(0, currentdir))
  386.                 return 10;
  387.  
  388.         while (--argc)
  389.                 PackSpoolJobs(argv[argc]);
  390.  
  391.         chdir(currentdir);
  392.  
  393.         return 0;
  394. }
  395.  
  396.  
  397. /************************************* subroutines ********/
  398. void PostArchive(char *systemname, char *postfix, char grade)
  399. {
  400.         FILE *cfh, *xfh;
  401.         char cfilename[64], xfilename[64], *trunc_sysname;
  402.         char dremote[64];
  403.  
  404.         trunc_sysname = TruncName(systemname);
  405.  
  406.         sprintf(cfilename, "C.%s%c0000", trunc_sysname, grade);
  407.         LockFile(cfilename);
  408.         if (!(cfh = fopen(cfilename, "r"))) {
  409.                 fclose(cfh);
  410.  
  411.                 /*
  412.                  * When the fopen() call succedes, does the file already
  413.                  * exist and we're finished.
  414.                  */
  415.  
  416.                 sprintf(xfilename, "D.%sX%s", trunc_sysname, SeqToName(GetSequence(1)));
  417.                 sprintf(dremote, "%s%s", TruncName(homesystem), SeqToName(GetSequence(1)));
  418.  
  419.                 if (cfh = fopen(cfilename, "w")) {
  420.                         fprintf(cfh, "S %s%s D.%s lharc-uucp-daemon - %s%s 0666\n",
  421.                                 systemname, postfix, dremote, systemname, postfix);
  422.                         fprintf(cfh, "S %s X.%s%s lharc-uucp-daemon - %s 0666\n",
  423.                                 xfilename, TruncName(homesystem), SeqToName(GetSequence(1)), xfilename);
  424.                         fclose(cfh);
  425.                 }
  426.  
  427.                 LockFile(xfilename);
  428.                 if (xfh = fopen(xfilename, "w")) {
  429.                         fprintf(xfh, "U lharc-uucp-daemon %s\nF D.%s\nC rlharc\n", homesystem, dremote);
  430.                         fclose(xfh);
  431.                 }
  432.                 else
  433.                         remove(cfilename);
  434.                 UnLockFile(xfilename);
  435.         }
  436.         else
  437.                 fclose(cfh);
  438.  
  439.         UnLockFile(cfilename);
  440. }
  441.  
  442.  
  443. void PackSpoolJobs(char *systemname)
  444. {
  445.         char currentdir[BUFFERSIZE], *cfile;
  446.         int success;
  447.         char owngrade, grade;
  448.  
  449.         processed_flag = 0;
  450.  
  451.         if (strlen(systemname)+strlen(UUSPOOL)+1 > BUFFERSIZE) {
  452.                 fprintf(stderr, "LharcUUCP: Directoryname is too long for internal buffer.\n");
  453.                 return;         /* Buffer overflow! */
  454.         }
  455.  
  456.         printf("Processing queued jobs for >%s<.\n", systemname);
  457.  
  458.  
  459.         /*
  460.          * Change into the appropiate directory, holding the spool jobs
  461.          * for the specified system.
  462.          */
  463.  
  464.         sprintf(currentdir, "%s%s", UUSPOOL, systemname);
  465.         if (chdir(currentdir)) {
  466.                 sprintf(currentdir, "%s%s", UUSPOOL, TruncName(systemname));
  467.                 if (chdir(currentdir)) {
  468.                         fprintf(stderr, "LharcUUCP: System >%s< has no spool directory?\n", systemname);
  469.                         strcpy(currentdir, UUSPOOL);
  470.                         if (chdir(currentdir)) {
  471.                                 fprintf(stderr, "LharcUUCP: Cd to >%s< failed.\n", UUSPOOL);
  472.                                 return;
  473.                         }
  474.                 }
  475.         }
  476.  
  477.  
  478.         /*
  479.          * Determine the configured grades for our process.
  480.          */
  481.  
  482.         {
  483.                 char *string, buf[80];
  484.  
  485.                 string = myGetConfigEntry("BatchOnlyGrade", NULL);
  486.                 grade = (string && isalnum(string[0])) ? string[0] : 'z';
  487.  
  488.                 sprintf(buf, "%s_%s", "BatchOnlyGrade", systemname);
  489.                 string = myGetConfigEntry(buf, NULL);
  490.                 grade = (string && isalnum(string[0])) ? string[0] : grade;
  491.  
  492.                 string = myGetConfigEntry("LharcBatchGrade", NULL);
  493.                 owngrade = (string && isalnum(string[0])) ? string[0] : 'A';
  494.         }
  495.  
  496.  
  497.         /*
  498.          * Build a pattern matching 'C.system*', with the systemname
  499.          * truncated to 7 characters and scan the spooldirectory for
  500.          * queued jobs we can pack.
  501.          */
  502.  
  503.         {
  504.                 char pattern[64];
  505.                 sprintf(pattern, "C.%s#?", TruncName(systemname));
  506.                 success = InitDirScan(pattern);
  507.         }
  508.  
  509.         if (success)
  510.                 while (cfile = ScanNextFile())
  511.                         LharcJob(systemname, cfile, grade);
  512.         else
  513.                 fprintf(stderr, "LharcUUCP: Directory scan for >%s< failed!\n", currentdir);
  514.  
  515.         EndDirScan();
  516.  
  517.         if (processed_flag)
  518.                 PostArchive(systemname, LHARCPOSTFIX, owngrade);
  519. }
  520.  
  521.  
  522. void LharcJob(char *systemname, char *cfilename, char grade)
  523. {
  524.         FILE *cfilehandle;
  525.         char command[2], from[256], to[256], from2[256], to2[256];
  526.         char cmdbuf[256], archivename[64];
  527.         int success = 0;
  528.  
  529.         printf("LharcUUCP: processing <%s>\n", cfilename);
  530.  
  531.         if (FileIsLocked(cfilename))
  532.                 return;         /* uucico is processing this job right now,
  533.                                  * so we better leave it alone.
  534.                                  */
  535.         LockFile(cfilename);
  536.  
  537.         if(!IsValidJob(cfilename, systemname, grade)) {
  538.                 UnLockFile(cfilename);
  539.                 return;
  540.         }
  541.  
  542.         if (cfilehandle = fopen(cfilename, "r")) {
  543.                 fscanf(cfilehandle, "%s%s%s", command, from, to);
  544.                 if (GoNextLine(cfilehandle) != EOF) {
  545.                         fscanf(cfilehandle, "%s%s%s", command, from2, to2);
  546.  
  547.                         LockFile(from);
  548.                         LockFile(to);
  549.                         LockFile(from2);
  550.                         LockFile(to2);
  551.                         if (!(rename(from, to)))
  552.                                 if (!(rename(from2, to2))) {
  553.                                         success = 1;
  554.                                         processed_flag = 1;
  555.  
  556.  
  557.                                         /* Free unused files a soon as
  558.                                          * possible.
  559.                                          */
  560.  
  561.                                         fclose(cfilehandle);
  562.                                         remove(cfilename);
  563.                                         UnLockFile(from);
  564.                                         UnLockFile(from2);
  565.                                         UnLockFile(cfilename);
  566.  
  567.  
  568.                                         /* Batch the processed files.
  569.                                          */
  570.  
  571.                                         sprintf(cmdbuf, "%s %s %s %s", LHARC, systemname, to, to2);
  572.                                         printf("%s\n", cmdbuf);
  573.                                         sprintf(archivename, "%s%s", systemname, LHARCPOSTFIX);
  574.                                         LockFile(archivename);
  575.                                         system(cmdbuf);
  576.                                         UnLockFile(archivename);
  577.                                 }
  578.                                 else
  579.                                         rename(to, from);
  580.  
  581.  
  582.                         /* When one of the 'renames' failed, we still
  583.                          * have to close and unlock the files.
  584.                          */
  585.  
  586.                         if (!success) {
  587.                                 UnLockFile(from);
  588.                                 UnLockFile(from2);
  589.                                 fclose(cfilehandle);
  590.                                 UnLockFile(cfilename);
  591.                         }
  592.  
  593.                         UnLockFile(to);         /* These must be freed */
  594.                         UnLockFile(to2);        /* in any case.        */
  595.                 }
  596.         }
  597. }
  598.  
  599.  
  600.  /*
  601.   * IsValidJob() checks the provided C.* file and tests if this job may
  602.   * may be processed by LharcUUCP. Currently, we only process mail and
  603.   * news. UUCP- and lharc-jobs are left alone.
  604.   */
  605.  
  606. int IsValidJob(char *cfilename, char *systemname, char grade)
  607. {
  608.  
  609.         /*
  610.          * Test if the grade of the commandfile is lower or the same as
  611.          * our max. grade.
  612.          */
  613.  
  614.         if (cfilename[strlen(TruncName(systemname)) + 2] > grade)
  615.                 return 0;
  616.  
  617.  
  618.         /*
  619.          * Check the number part of the filename. C.*0000 are the C.*
  620.          * files for the processed archives and won't be touched.
  621.          */
  622.  
  623.         if (!strncmp(&cfilename[strlen(cfilename) - 4], "0000", 4))
  624.                 return 0;
  625.  
  626.  
  627.         /*
  628.          * Check the contents of the file. Neither target nor source file
  629.          * may contain paths and we can't batch read-requests of course.
  630.          */
  631.  
  632.         {
  633.                 FILE *fh;
  634.                 int success = 0;
  635.                 char from[256], to[256];
  636.  
  637.                 if (fh = fopen(cfilename, "r")) {
  638.                         while (1) {
  639.                                 if (fgetc(fh) == 'S') {
  640.                                         fscanf(fh, "%s%s", from, to);
  641.                                         if (IsPath(from) || IsPath(to))
  642.                                                 break;
  643.                                         GoNextLine(fh);
  644.                                         if (feof(fh)) {
  645.                                                 success = 1;
  646.                                                 break;
  647.                                         }
  648.                                 }
  649.                                 else
  650.                                         break;
  651.                         }
  652.                         fclose(fh);
  653.                 }
  654.                 if (!success)
  655.                         return 0;
  656.         }
  657.  
  658.         return 1;
  659. }
  660.  
  661.  
  662.  
  663. unsigned int GetSequence(unsigned int bump)
  664. {
  665.         FILE *fh;
  666.         unsigned int seq = 0;
  667.  
  668.         LockFile(SEQ);
  669.         if (fh = fopen(SEQ, "r")) {
  670.                 fscanf(fh, "%u", &seq);
  671.                 fclose(fh);
  672.         }
  673.         else {
  674.                 fprintf(stderr, "LharcUUCP: Can't open seq file!\n");
  675.         }
  676.  
  677.         if (bump && seq >= 0) {
  678.                 if (bump + seq > 0xFFFFF)
  679.                         seq = 1;
  680.  
  681. endlessloop:
  682.                 if (fh = fopen(SEQ, "w")) {
  683.                         fprintf(fh, "%u", seq + bump);
  684.                         fclose(fh);
  685.                 }
  686.                 else {
  687.                         fprintf(stderr, "LharcUUCP: Can't update seq file!\n");
  688.                         Delay(5*50);
  689.                         goto endlessloop;
  690.                 }
  691.         }
  692.         UnLockFile(SEQ);
  693.         return seq;
  694. }
  695.  
  696.  
  697.  /*
  698.   * Convert a sequence number into a numeric/character combination. Names
  699.   * are unique and case-insensitive. The sequence number 0-0xFFFFF will be
  700.   * converted to a 4 character string each position containing 0-9 a-z,
  701.   * or base 36 (total of 1.6 million combinations)
  702.   */
  703.  
  704. char *SeqToName(unsigned int seqNo)
  705. {
  706.         static char Buf[5];
  707.         short i;
  708.  
  709.         seqNo &= 0xFFFFF;
  710.  
  711.         for (i = 3; i >= 0; --i) {
  712.                 short n = seqNo % 36;
  713.  
  714.                 if (n < 10)
  715.                         Buf[i] = n + '0';
  716.                 else
  717.                         Buf[i] = n - 10 + 'a';
  718.                 seqNo /= 36;
  719.         }
  720.         Buf[4] = '\0';
  721.         return (Buf);
  722. }
  723.  
  724.  
  725.  /*
  726.   * TruncName() duplicates the given string and truncates it to 7
  727.   * characters, which is required by a number of tasks in the UUCP
  728.   * enviroment.
  729.   */
  730.  
  731. char *TruncName(char *string)
  732. {
  733.         static char buffer[8];
  734.  
  735.         strncpy(buffer, string, 7);
  736.         buffer[7] = '\0';
  737.  
  738.         return buffer;
  739. }
  740.  
  741.  
  742.  /*
  743.   * GoNextLine() reads from the provided filehandle until either end-
  744.   * of-file or an end-of-line ('\n') occurs.
  745.   */
  746.  
  747. int GoNextLine(FILE *fh)
  748. {
  749.         int c;
  750.  
  751.         while ((c = fgetc(fh)) != EOF && c != '\n')
  752.                 ;
  753.  
  754.         if ((c = fgetc(fh)) != EOF)     /* Read next character to make */
  755.                 ungetc(c, fh);          /* feof() work.                */
  756.  
  757.         return c;
  758. }
  759.  
  760.  
  761.  /*
  762.   * This small routine returns a flag indicating wether the provided
  763.   * string was a filepath or just a filename! This is important, because
  764.   * filerequests containing paths can't be processed with LharcUUCP.
  765.   * This routine has to be customized for other systems.
  766.   */
  767.  
  768. int IsPath(char *filename)
  769. {
  770.         if (strchr(filename, '/') || strchr(filename, ':'))
  771.                 return 1;
  772.         else
  773.                 return 0;
  774. }
  775.  
  776.  
  777. char *myGetConfigEntry(char *keyword, char *def)
  778. {
  779.         char *string;
  780.  
  781.         if (string = getenv(keyword))
  782.                 return string;
  783.  
  784.         return GetConfigEntry(NULL, keyword, def);
  785. }
  786.  
  787. @
  788.  
  789.  
  790. 0.24
  791. log
  792. @Added check, wether the specified grade is a valid alpha-numeric
  793. character or not.
  794. @
  795. text
  796. @d3 2
  797. a4 2
  798.  *      $Revision: 0.23 $
  799.  *      $Date: 1993/12/14 21:52:37 $
  800. d22 1
  801. a22 1
  802.  *      $Id: LharcUUCP.c,v 0.23 1993/12/14 21:52:37 simons Exp simons $
  803. d26 4
  804. d195 1
  805. d209 1
  806. a209 1
  807. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.23 1993/12/14 21:52:37 simons Exp simons $";
  808. d329 1
  809. a329 1
  810.                 char *string;
  811. d331 1
  812. a331 3
  813.                 if (!(string = getenv("BatchOnlyGrade"))) {
  814.                         string = GetConfigEntry(NULL, "BatchOnlyGrade", NULL);
  815.                 }
  816. d334 5
  817. a338 3
  818.                 if (!(string = getenv("LharcBatchGrade"))) {
  819.                         string = GetConfigEntry(NULL, "LharcBatchGrade", NULL);
  820.                 }
  821. d620 11
  822. @
  823.  
  824.  
  825. 0.23
  826. log
  827. @Added a comment describing IsPath().
  828. @
  829. text
  830. @d3 2
  831. a4 2
  832.  *      $Revision: 0.22 $
  833.  *      $Date: 1993/12/14 21:25:45 $
  834. d22 1
  835. a22 1
  836.  *      $Id: LharcUUCP.c,v 0.22 1993/12/14 21:25:45 simons Exp simons $
  837. d26 3
  838. d164 1
  839. d204 1
  840. a204 1
  841. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.22 1993/12/14 21:25:45 simons Exp simons $";
  842. d329 1
  843. a329 1
  844.                 grade = (string) ? string[0] : 'z';
  845. d334 1
  846. a334 1
  847.                 owngrade = (string) ? string[0] : 'A';
  848. @
  849.  
  850.  
  851. 0.22
  852. log
  853. @Changed the main loop in LharcJob() to free the C.* file as soon as
  854. possible, right after the renames, so that an eventually waiting uucico
  855. doesn't get blocked.
  856. @
  857. text
  858. @d3 2
  859. a4 2
  860.  *      $Revision: 0.21 $
  861.  *      $Date: 1993/12/14 17:59:16 $
  862. d22 1
  863. a22 1
  864.  *      $Id: LharcUUCP.c,v 0.21 1993/12/14 17:59:16 simons Exp simons $
  865. d26 5
  866. d200 1
  867. a200 1
  868. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.21 1993/12/14 17:59:16 simons Exp simons $";
  869. d598 7
  870. d612 1
  871. @
  872.  
  873.  
  874. 0.21
  875. log
  876. @Remved the tests in the routines handling with grades. Now we just need
  877. one central test in LharcUUCPJob(), right after the configfile is read.
  878. Changed the arraysize for the filenames in jobs to 256 byte.
  879. Changed GoNextLine() to work with a following feof().
  880. Added IsPath() to determine the validity of the requests.
  881. Changed the way, IsValidJob() recognizes 'unbatchable' UUCP requests. The
  882. last version just counted the number of lines (If that's no hack, what
  883. else? :->), while this version recognizes the paths.
  884. Added a missing comment in the history (for 0.18).
  885. Added a few comments.
  886. @
  887. text
  888. @d3 2
  889. a4 2
  890.  *      $Revision: 0.20 $
  891.  *      $Date: 1993/12/14 16:42:41 $
  892. d22 1
  893. a22 1
  894.  *      $Id: LharcUUCP.c,v 0.20 1993/12/14 16:42:41 simons Exp simons $
  895. d26 12
  896. d195 1
  897. a195 1
  898. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.20 1993/12/14 16:42:41 simons Exp simons $";
  899. d358 1
  900. d384 1
  901. a384 1
  902.                                 if (!(rename(from2, to2)))
  903. d386 24
  904. a411 2
  905.                         UnLockFile(from);
  906.                         UnLockFile(from2);
  907. a412 2
  908.                         {
  909.                                 char cmdbuf[256], archivename[64];
  910. d414 9
  911. a422 6
  912.                                 sprintf(cmdbuf, "%s %s %s %s", LHARC, systemname, to, to2);
  913.                                 printf("%s\n", cmdbuf);
  914.                                 sprintf(archivename, "%s%s", systemname, LHARCPOSTFIX);
  915.                                 LockFile(archivename);
  916.                                 system(cmdbuf);
  917.                                 UnLockFile(archivename);
  918. d425 2
  919. a426 2
  920.                         UnLockFile(to);
  921.                         UnLockFile(to2);
  922. a427 6
  923.                 fclose(cfilehandle);
  924.                 if(success) {
  925.                         remove(cfilename);
  926.                         processed_flag = 1;
  927.                 }
  928.                 UnLockFile(cfilename);
  929. @
  930.  
  931.  
  932. 0.20
  933. log
  934. @Adedd a DOS version string using C='s bumprev tool.
  935. Changes usage-output.
  936. @
  937. text
  938. @d3 2
  939. a4 2
  940.  *      $Revision: 0.19 $
  941.  *      $Date: 1993/12/14 15:21:36 $
  942. d22 1
  943. a22 1
  944.  *      $Id: LharcUUCP.c,v 0.19 1993/12/14 15:21:36 simons Exp simons $
  945. d26 4
  946. d35 7
  947. d169 1
  948. d183 1
  949. a183 1
  950. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.19 1993/12/14 15:21:36 simons Exp simons $";
  951. a225 3
  952.         if (!grade)
  953.                 grade = 'A';    /* Default: Grade 'A' */
  954.  
  955. d308 1
  956. a308 1
  957.                 grade = (string) ? string[0] : NULL;
  958. d313 1
  959. a313 1
  960.                 owngrade = (string) ? string[0] : NULL;
  961. d345 1
  962. a345 1
  963.         char command[2], from[32], to[32], from2[32], to2[32];
  964. d430 2
  965. a431 3
  966.          * Check if the provided file is a send request and wether it
  967.          * consists of two files or not. One-file requests are usually
  968.          * UUCP jobs and are not handled by this version.
  969. d437 1
  970. a438 1
  971.                 LockFile(cfilename);
  972. d440 7
  973. a446 3
  974.                         if (getc(fh) == 'S')
  975.                                 if (GoNextLine(fh) != EOF)
  976.                                         if (getc(fh) == 'S')
  977. d448 6
  978. a455 1
  979.                 UnLockFile(cfilename);
  980. d498 1
  981. d544 5
  982. d553 1
  983. a553 1
  984.         while ((c = getc(fh)) != EOF && c != '\n')
  985. d556 3
  986. d562 8
  987. @
  988.  
  989.  
  990. 0.19
  991. log
  992. @Added a variable 'LharcBatchGrade' determining the batch-grade of our
  993. own job. This defaults to 'A'. Currently, this is only global for the
  994. whole system.
  995. @
  996. text
  997. @d3 2
  998. a4 2
  999.  *      $Revision: 0.17 $
  1000.  *      $Date: 1993/12/11 14:31:46 $
  1001. d22 1
  1002. a22 1
  1003.  *      $Id: LharcUUCP.c,v 0.17 1993/12/11 14:31:46 simons Exp simons $
  1004. d26 5
  1005. d134 1
  1006. d136 1
  1007. a136 1
  1008. #include <proto/dos.h>
  1009. d145 2
  1010. a146 2
  1011. #define USAGE "Usage: LharcUUCP system [[system] [...]]\n" \
  1012.               "written by Peter Simons <simons@@peti.GUN.de>\n"
  1013. d171 2
  1014. a172 1
  1015. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.17 1993/12/11 14:31:46 simons Exp simons $";
  1016. @
  1017.  
  1018.  
  1019. 0.18
  1020. log
  1021. @Added a grade-check into IsValidJob(). This required two more parameters:
  1022. systemname and grade. Currently, the grade is only global, but I'll add
  1023. some local way.
  1024. Changed the order of checks in IsValidJob(). Now, the check requiring
  1025. fileaccess is the last one.
  1026. @
  1027. text
  1028. @d146 1
  1029. a146 1
  1030. void PostArchive(char *systemname, char *postfix);
  1031. d199 1
  1032. a199 1
  1033. void PostArchive(char *systemname, char *postfix)
  1034. d207 4
  1035. a210 1
  1036.         sprintf(cfilename, "C.%sA0000", trunc_sysname);
  1037. d251 1
  1038. a251 1
  1039.         char grade;
  1040. d283 1
  1041. a283 1
  1042.          * Determine the configured grade for our process.
  1043. d293 5
  1044. d322 1
  1045. a322 1
  1046.                 PostArchive(systemname, LHARCPOSTFIX);
  1047. @
  1048.  
  1049.  
  1050. 0.17
  1051. log
  1052. @LharcUUCP is now able to parse the UUCP main config file and determine
  1053. the sitename from the appropiate entry there. However, HOSTNAME is tested
  1054. before parsing the file and still has priority. Local vars aren't
  1055. supported.
  1056. @
  1057. text
  1058. @d3 2
  1059. a4 2
  1060.  *      $Revision: 0.16 $
  1061.  *      $Date: 1993/12/10 22:26:14 $
  1062. d22 1
  1063. a22 1
  1064.  *      $Id: LharcUUCP.c,v 0.16 1993/12/10 22:26:14 simons Exp simons $
  1065. d26 6
  1066. d145 1
  1067. a145 1
  1068. void LharcJob(char *systemname, char *cfile);
  1069. d148 1
  1070. a148 1
  1071. int IsValidJob(char *cfilename);
  1072. d165 1
  1073. a165 1
  1074. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.16 1993/12/10 22:26:14 simons Exp simons $";
  1075. d248 1
  1076. d280 14
  1077. d307 1
  1078. a307 1
  1079.                         LharcJob(systemname, cfile);
  1080. d318 1
  1081. a318 1
  1082. void LharcJob(char *systemname, char *cfilename)
  1083. d332 1
  1084. a332 1
  1085.         if(!IsValidJob(cfilename)) {
  1086. d384 1
  1087. a384 1
  1088. int IsValidJob(char *cfilename)
  1089. a385 2
  1090.         FILE *fh;
  1091.         int success = 0;
  1092. d388 2
  1093. a389 3
  1094.          * Check if the provided file is a send request and wether it
  1095.          * consists of two files or not. One-file requests are usually
  1096.          * UUCP jobs and are not handled by this version.
  1097. d392 1
  1098. a392 10
  1099.         LockFile(cfilename);
  1100.         if (fh = fopen(cfilename, "r")) {
  1101.                 if (getc(fh) == 'S')
  1102.                         if (GoNextLine(fh) != EOF)
  1103.                                 if (getc(fh) == 'S')
  1104.                                         success = 1;
  1105.                 fclose(fh);
  1106.         }
  1107.         UnLockFile(cfilename);
  1108.         if (!success)
  1109. d395 1
  1110. d401 1
  1111. a401 2
  1112.         cfilename += strlen(cfilename) - 4;
  1113.         if (!strncmp(cfilename, "0000", 4))
  1114. d403 24
  1115. @
  1116.  
  1117.  
  1118. 0.16
  1119. log
  1120. @Added the command ("m") in the LHARC-define.
  1121. LharcUUCP() now terminates, when the current C.* file is already locked,
  1122. because this usually means, that uucico is currently working on this job
  1123. and our batch would fail anyway, so we better process the next job.
  1124. Then LharcUUCP() used to unlock the C.* file before deleting it. This
  1125. has been fixed.
  1126. Now, we're locking the full archive name (<system>.LHARCPOSTFIX), to
  1127. avoid problems with uucico, trying to transfer our archive while we're
  1128. working on it.
  1129. @
  1130. text
  1131. @d3 2
  1132. a4 2
  1133.  *      $Revision: 0.15 $
  1134.  *      $Date: 1993/12/08 17:11:03 $
  1135. d22 1
  1136. a22 1
  1137.  *      $Id: LharcUUCP.c,v 0.15 1993/12/08 17:11:03 simons Exp simons $
  1138. d26 11
  1139. d144 2
  1140. d156 1
  1141. a156 2
  1142. unsigned int GetSequence(unsigned int);
  1143. char *SeqToName(unsigned int);
  1144. d159 2
  1145. a160 2
  1146. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.15 1993/12/08 17:11:03 simons Exp simons $";
  1147. char *HOMESYSTEM;
  1148. d174 5
  1149. a178 4
  1150.         if (!(HOMESYSTEM = getenv("HOSTNAME"))) {
  1151.                 fprintf(stderr, "LharcUUCP: >HOSTNAME< variable required!\n");
  1152.                 return 10;
  1153.         }
  1154. d212 1
  1155. a212 1
  1156.                 sprintf(dremote, "%s%s", TruncName(HOMESYSTEM), SeqToName(GetSequence(1)));
  1157. d218 1
  1158. a218 1
  1159.                                 xfilename, TruncName(HOMESYSTEM), SeqToName(GetSequence(1)), xfilename);
  1160. d224 1
  1161. a224 1
  1162.                         fprintf(xfh, "U lharc-uucp-daemon %s\nF D.%s\nC rlharc\n", HOMESYSTEM, dremote);
  1163. d487 1
  1164. @
  1165.  
  1166.  
  1167. 0.15
  1168. log
  1169. @Changed the call to InitDirScan() to match the new routines.
  1170. @
  1171. text
  1172. @d3 2
  1173. a4 2
  1174.  *      $Revision: 0.14 $
  1175.  *      $Date: 1993/12/07 02:22:48 $
  1176. d22 1
  1177. a22 1
  1178.  *      $Id: LharcUUCP.c,v 0.14 1993/12/07 02:22:48 simons Exp simons $
  1179. d26 3
  1180. d119 1
  1181. a119 1
  1182. #define LHARC "LhA"
  1183. d147 1
  1184. a147 1
  1185. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.14 1993/12/07 02:22:48 simons Exp simons $";
  1186. d292 8
  1187. a299 1
  1188.         if(!IsValidJob(cfilename))
  1189. d301 1
  1190. a302 1
  1191.         LockFile(cfilename);
  1192. d321 1
  1193. a321 1
  1194.                                 char cmdbuf[256];
  1195. d323 1
  1196. a323 1
  1197.                                 sprintf(cmdbuf, "%s m %s %s %s", LHARC, systemname, to, to2);
  1198. d325 2
  1199. a326 1
  1200.                                 LockFile(systemname);
  1201. d328 1
  1202. a328 1
  1203.                                 UnLockFile(systemname);
  1204. a334 1
  1205.                 UnLockFile(cfilename);
  1206. d339 1
  1207. @
  1208.  
  1209.  
  1210. 0.14
  1211. log
  1212. @Changed the spool directory finding routine again.
  1213. @
  1214. text
  1215. @d3 2
  1216. a4 2
  1217.  *      $Revision: 0.13 $
  1218.  *      $Date: 1993/12/07 02:15:50 $
  1219. d22 1
  1220. a22 1
  1221.  *      $Id: LharcUUCP.c,v 0.13 1993/12/07 02:15:50 simons Exp simons $
  1222. d26 3
  1223. d136 1
  1224. a136 1
  1225. int InitDirScan(char *, char *);
  1226. d144 1
  1227. a144 1
  1228. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.13 1993/12/07 02:15:50 simons Exp simons $";
  1229. d265 1
  1230. a265 1
  1231.                 success = InitDirScan(currentdir, pattern);
  1232. @
  1233.  
  1234.  
  1235. 0.13
  1236. log
  1237. @Now checking for a spooldirectory with a truncated systemname, too.
  1238. @
  1239. text
  1240. @d3 2
  1241. a4 2
  1242.  *      $Revision: 0.12 $
  1243.  *      $Date: 1993/12/05 16:11:39 $
  1244. d22 1
  1245. a22 1
  1246.  *      $Id: LharcUUCP.c,v 0.12 1993/12/05 16:11:39 simons Exp simons $
  1247. d26 3
  1248. d141 1
  1249. a141 1
  1250. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.12 1993/12/05 16:11:39 simons Exp simons $";
  1251. d239 1
  1252. a239 1
  1253.         sprintf("%s%s", currentdir, UUSPOOL, systemname);
  1254. d241 4
  1255. a244 2
  1256.                 if(strlen(systemname) > 7) {
  1257.                         sprintf("%s%s", currentdir, UUSPOOL, TruncName(systemname));
  1258. d246 2
  1259. a247 6
  1260.                                 fprintf(stderr, "LharcUUCP: System >%s< has no spool directory?\n", systemname);
  1261.                                 strcpy(currentdir, UUSPOOL);
  1262.                                 if (chdir(currentdir)) {
  1263.                                         fprintf(stderr, "LharcUUCP: Cd to >%s< failed.\n", UUSPOOL);
  1264.                                         return;
  1265.                                 }
  1266. @
  1267.  
  1268.  
  1269. 0.12
  1270. log
  1271. @IsValidJob() didn't free the locked files.
  1272. @
  1273. text
  1274. @d3 2
  1275. a4 2
  1276.  *      $Revision: 0.11 $
  1277.  *      $Date: 1993/12/05 15:46:13 $
  1278. d22 1
  1279. a22 1
  1280.  *      $Id: LharcUUCP.c,v 0.11 1993/12/05 15:46:13 simons Exp simons $
  1281. d26 3
  1282. d138 1
  1283. a138 1
  1284. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.11 1993/12/05 15:46:13 simons Exp simons $";
  1285. d236 1
  1286. a236 2
  1287.         strcpy(currentdir, UUSPOOL);
  1288.         strcat(currentdir, systemname);
  1289. d238 10
  1290. a247 5
  1291.                 fprintf(stderr, "LharcUUCP: System >%s< has no spool directory?\n", systemname);
  1292.                 strcpy(currentdir, UUSPOOL);
  1293.                 if (chdir(currentdir)) {
  1294.                         fprintf(stderr, "LharcUUCP: Cd to >%s< failed.\n", UUSPOOL);
  1295.                         return;
  1296. @
  1297.  
  1298.  
  1299. 0.11
  1300. log
  1301. @Added IsValidJob() which determines if we should process this job.
  1302. Currently, only mail and news are processed--UUCP commands and our
  1303. own archive-copy is skipped. Since this check is now in a seperate
  1304. routine, LharcJob() has become a little bit easier and more straight.
  1305. @
  1306. text
  1307. @d3 2
  1308. a4 2
  1309.  *      $Revision: 0.10 $
  1310.  *      $Date: 1993/12/05 13:32:37 $
  1311. d22 1
  1312. a22 1
  1313.  *      $Id: LharcUUCP.c,v 0.10 1993/12/05 13:32:37 simons Exp simons $
  1314. d26 6
  1315. d135 1
  1316. a135 1
  1317. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.10 1993/12/05 13:32:37 simons Exp simons $";
  1318. d331 1
  1319. a331 1
  1320.         int c, success = 0;
  1321. d347 1
  1322. @
  1323.  
  1324.  
  1325. 0.10
  1326. log
  1327. @PostArchive() is now called only, when actually a job has been processed.
  1328. Additionally, it's called after the process is finished, not every time
  1329. the archive changed. I'm not completely sure if this is the better
  1330. way--will need some thought.
  1331. @
  1332. text
  1333. @d3 2
  1334. a4 2
  1335.  *      $Revision: 0.9 $
  1336.  *      $Date: 1993/12/05 13:19:28 $
  1337. d22 1
  1338. a22 1
  1339.  *      $Id: LharcUUCP.c,v 0.9 1993/12/05 13:19:28 simons Exp simons $
  1340. d26 6
  1341. d113 2
  1342. d129 1
  1343. a129 1
  1344. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.9 1993/12/05 13:19:28 simons Exp simons $";
  1345. d193 1
  1346. a193 1
  1347.                         fprintf(xfh, "U lharc-uucp-daemon %s\nF D.%s\nC rlharc\n", TruncName(HOMESYSTEM), dremote);
  1348. d267 1
  1349. a267 1
  1350.         char command[5], from[32], to[32], from2[32], to2[32];
  1351. d272 3
  1352. d277 25
  1353. a301 30
  1354.                 fscanf(cfilehandle, "%s", command);
  1355.                 if (!stricmp(command, "S")) {
  1356.                         fscanf(cfilehandle, "%s%s", from, to);
  1357.                         while ((success = getc(cfilehandle)) != '\n' && success != EOF)
  1358.                                 ;
  1359.                         if (success != EOF) {
  1360.                                 fscanf(cfilehandle, "%s%s%s", command, from2, to2);
  1361.  
  1362.                                 LockFile(from);
  1363.                                 LockFile(to);
  1364.                                 LockFile(from2);
  1365.                                 LockFile(to2);
  1366.                                 success = 0;
  1367.                                 if (!(rename(from, to)))
  1368.                                         if (!(rename(from2, to2)))
  1369.                                                 success = 1;
  1370.                                         else
  1371.                                                 rename(to, from);
  1372.                                 UnLockFile(from);
  1373.                                 UnLockFile(from2);
  1374.  
  1375.                                 {
  1376.                                         char cmdbuf[256];
  1377.  
  1378.                                         sprintf(cmdbuf, "%s m %s %s %s", LHARC, systemname, to, to2);
  1379.                                         printf("%s\n", cmdbuf);
  1380.                                         LockFile(systemname);
  1381.                                         system(cmdbuf);
  1382.                                         UnLockFile(systemname);
  1383.                                 }
  1384. d303 2
  1385. a304 5
  1386.                                 UnLockFile(to);
  1387.                                 UnLockFile(to2);
  1388.                         }
  1389.                         else
  1390.                                 success = 0;
  1391. d316 42
  1392. a390 1
  1393.  
  1394. d435 10
  1395. @
  1396.  
  1397.  
  1398. 0.9
  1399. log
  1400. @HOMESYSTEM is not determined at startup from the related enviroment
  1401. variable, maybe I'll add configfile parsing some day.
  1402. Change the order of the tests in main(): Now the commandline is checked
  1403. first.
  1404. Added TruncName(), which makes the handling of the 7-char-maximum
  1405. systemnames easier.
  1406. Changed commentblock style.
  1407. @
  1408. text
  1409. @d3 2
  1410. a4 2
  1411.  *      $Revision: 0.8 $
  1412.  *      $Date: 1993/12/05 00:35:28 $
  1413. d22 1
  1414. a22 1
  1415.  *      $Id: LharcUUCP.c,v 0.8 1993/12/05 00:35:28 simons Exp simons $
  1416. d26 9
  1417. d121 1
  1418. a121 1
  1419. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.8 1993/12/05 00:35:28 simons Exp simons $";
  1420. d123 1
  1421. d204 2
  1422. d250 3
  1423. d305 1
  1424. a305 1
  1425.                 if(success)
  1426. d307 2
  1427. a309 1
  1428.         PostArchive(systemname, LHARCPOSTFIX);
  1429. @
  1430.  
  1431.  
  1432. 0.8
  1433. log
  1434. @The history in the sourcefile was broken.
  1435. Also I didn't mention the seq-routines, I took from Dillon UUCP.
  1436. Known bug: LharcUUCP packs it's self-generated Archive job. :-) It
  1437.            doesn't really matter, but I'll find a way around this.
  1438. @
  1439. text
  1440. @d3 2
  1441. a4 2
  1442.  *      $Revision: 0.7 $
  1443.  *      $Date: 1993/12/05 00:29:29 $
  1444. d22 1
  1445. a22 1
  1446.  *      $Id: LharcUUCP.c,v 0.7 1993/12/05 00:29:29 simons Exp simons $
  1447. d26 6
  1448. a87 1
  1449. #define HOMESYSTEM "peti"
  1450. d97 1
  1451. d112 2
  1452. a113 1
  1453. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.7 1993/12/05 00:29:29 simons Exp simons $";
  1454. d121 10
  1455. a133 3
  1456.         if (argc < 2)
  1457.                 fprintf(stderr, USAGE);
  1458.  
  1459. d147 1
  1460. a147 1
  1461.         char cfilename[64], xfilename[64], trunc_sysname[8];
  1462. d150 1
  1463. a150 2
  1464.         strncpy(trunc_sysname, systemname, 7);
  1465.         trunc_sysname[7] = '\0';
  1466. d157 2
  1467. a158 1
  1468.                 /* When the fopen() call succedes, does the file already
  1469. d163 1
  1470. a163 1
  1471.                 sprintf(dremote, "%s%s", HOMESYSTEM, SeqToName(GetSequence(1)));
  1472. d169 1
  1473. a169 1
  1474.                                 xfilename, HOMESYSTEM, SeqToName(GetSequence(1)), xfilename);
  1475. d175 1
  1476. a175 1
  1477.                         fprintf(xfh, "U lharc-uucp-daemon %s\nF D.%s\nC rlharc\n", HOMESYSTEM, dremote);
  1478. d202 2
  1479. a203 1
  1480.         /* Change into the appropiate directory, holding the spool jobs
  1481. d219 2
  1482. a220 1
  1483.         /* Build a pattern matching 'C.system*', with the systemname
  1484. d226 2
  1485. a227 4
  1486.                 char tmp[8], pattern[64];
  1487.                 memset(tmp, 0, 8);
  1488.                 strncpy(tmp, systemname, 7);
  1489.                 sprintf(pattern, "C.%s#?", tmp);
  1490. d331 6
  1491. a336 6
  1492. /*
  1493.  *  Convert a sequence number into a numeric/character combination.  Names
  1494.  *  are unique and case-insensitive.  The sequence number 0-0xFFFFF will be
  1495.  *  converted to a 4 character string each position containing 0-9 a-z,
  1496.  *  or base 36 (total of 1.6 million combinations)
  1497.  */
  1498. d357 18
  1499. @
  1500.  
  1501.  
  1502. 0.7
  1503. log
  1504. @Added PostArchive(), a small and neat routine to create the X.* and
  1505. the C.* file for the archive.
  1506. @
  1507. text
  1508. @d3 2
  1509. a4 2
  1510.  *      $Revision: 0.5 $
  1511.  *      $Date: 1993/12/04 22:30:44 $
  1512. d22 1
  1513. a22 1
  1514.  *      $Id: LharcUUCP.c,v 0.5 1993/12/04 22:30:44 simons Exp simons $
  1515. d26 10
  1516. d106 1
  1517. a106 1
  1518. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.5 1993/12/04 22:30:44 simons Exp simons $";
  1519. a342 1
  1520.  
  1521. @
  1522.  
  1523.  
  1524. 0.6
  1525. log
  1526. @The outgoing-archive is now locked while the archiver runs. Actually,
  1527. only the systemname is used to lock the archive, not the complete name,
  1528. like "peti.lha" or something similar. So, the mechanism will work with
  1529. different archivers than LhA on the Amiga platform.
  1530. @
  1531. text
  1532. @d64 2
  1533. d67 1
  1534. d69 1
  1535. a69 1
  1536. #define BUFFERSIZE 128
  1537. d71 2
  1538. d81 1
  1539. d92 3
  1540. a97 1
  1541.  
  1542. d120 45
  1543. a213 1
  1544.  
  1545. d269 63
  1546. @
  1547.  
  1548.  
  1549. 0.5
  1550. log
  1551. @Now actually starting the archiver, creating a file names <system>.lha,
  1552. located in the appropiate outgoing directory.
  1553. @
  1554. text
  1555. @d3 2
  1556. a4 2
  1557.  *      $Revision: 0.4 $
  1558.  *      $Date: 1993/12/04 20:44:35 $
  1559. d22 1
  1560. a22 1
  1561.  *      $Id: LharcUUCP.c,v 0.4 1993/12/04 20:44:35 simons Exp simons $
  1562. d26 4
  1563. d87 1
  1564. a87 1
  1565. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.4 1993/12/04 20:44:35 simons Exp simons $";
  1566. d201 1
  1567. d203 1
  1568. @
  1569.  
  1570.  
  1571. 0.4
  1572. log
  1573. @Moved the directory scanning routine into an extra module, since this
  1574. is the only routine that is really system-dependant.
  1575. @
  1576. text
  1577. @d3 2
  1578. a4 2
  1579.  *      $Revision: 0.3 $
  1580.  *      $Date: 1993/12/04 18:05:00 $
  1581. d22 1
  1582. a22 1
  1583.  *      $Id: LharcUUCP.c,v 0.3 1993/12/04 18:05:00 simons Exp simons $
  1584. d26 4
  1585. d62 2
  1586. a63 1
  1587. #define BUFFERSIZE 1024
  1588. d78 4
  1589. d83 1
  1590. a83 1
  1591. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.3 1993/12/04 18:05:00 simons Exp simons $";
  1592. d110 2
  1593. a111 1
  1594.         char buffer[BUFFERSIZE], *cfile;
  1595. d125 3
  1596. a127 3
  1597.         strcpy(buffer, UUSPOOL);
  1598.         strcat(buffer, systemname);
  1599.         if (chdir(buffer)) {
  1600. d129 2
  1601. a130 1
  1602.                 if (chdir(UUSPOOL)) {
  1603. d143 1
  1604. a143 1
  1605.                 char tmp[8];
  1606. d146 2
  1607. a147 1
  1608.                 sprintf(buffer, "C.%s#?", tmp);
  1609. d150 8
  1610. a157 5
  1611. /*        if (GetFileName(buffer, 1)) {
  1612.  *               while (cfile = GetFileName(buffer, 0))
  1613.  *                       LharcJob(systemname, cfile);
  1614.  *       }
  1615.  */
  1616. d190 10
  1617. a200 1
  1618.                                 UnLockFile(from2);
  1619. @
  1620.  
  1621.  
  1622. 0.3
  1623. log
  1624. @LharcJob() now reads the C.* files and renames the D.* and X.* file to
  1625. the names they shall have on the remote system, so they can be easily
  1626. packed.
  1627. Non-send-jobs are recognized.
  1628. UUCP jobs (which are send-jobs in fact) are merely recognized, although
  1629. the current method (UUCP-jobs have only one line!) is a hack. I'll
  1630. change that soon.
  1631. Also some problems with the directory scanning routine occur. I will
  1632. have to re-write GetFileName() soon, too.
  1633. @
  1634. text
  1635. @d3 2
  1636. a4 2
  1637.  *      $Revision: 0.1 $
  1638.  *      $Date: 1993/12/04 13:45:54 $
  1639. d22 1
  1640. a22 1
  1641.  *      $Id: LharcUUCP.c,v 0.1 1993/12/04 13:45:54 simons Exp simons $
  1642. d26 20
  1643. a45 1
  1644.  * Revision 0.1  1993/12/04  13:45:54  simons
  1645. a55 3
  1646. #include <dos/dos.h>
  1647. #include <proto/dos.h>
  1648.  
  1649. d74 1
  1650. a74 3
  1651.  
  1652. static const char __RCSId[] = "$Id: LharcUUCP.c,v 0.1 1993/12/04 13:45:54 simons Exp simons $";
  1653.  
  1654. d138 5
  1655. a142 4
  1656.         if (GetFileName(buffer, 1)) {
  1657.                 while (cfile = GetFileName(buffer, 0))
  1658.                         LharcJob(systemname, cfile);
  1659.         }
  1660. a188 45
  1661.  
  1662.  
  1663. /*
  1664.  * GetFileName() returns the first file, matching the provided pattern in
  1665.  * the current directory. If no file matched, NULL is returned.
  1666.  *
  1667.  * Every time you're scanning a new directory, you have to set the reset
  1668.  * parameter != 0 and check the returncode.
  1669.  *
  1670.  * Please take note, that GetFileName() saves the 'position' of the
  1671.  * first hit and continues after that file when called again, unless the
  1672.  * reset parameter is set again.
  1673.  */
  1674.  
  1675. char *GetFileName(char *pattern, int reset)
  1676. {
  1677. #ifdef AMIGA
  1678.         static struct FileInfoBlock __aligned fib;
  1679.         BPTR lock;
  1680.         char *filename = NULL, token[128];
  1681.  
  1682.         if (reset) {
  1683.                 if (lock = Lock("", ACCESS_READ)) {
  1684.                         if (!(Examine(lock, &fib)))
  1685.                                 reset = 0;
  1686.                         UnLock(lock);
  1687.                 }
  1688.                 return ((char *) reset);
  1689.         }
  1690.  
  1691.         if (ParsePatternNoCase(pattern, token, 128) == 1)
  1692.                 if (lock = Lock("", ACCESS_READ)) {
  1693.                         do {
  1694.                                 if (ExNext(lock, &fib))
  1695.                                         filename = fib.fib_FileName;
  1696.                                 else
  1697.                                         filename = NULL;
  1698.                         } while (filename && !MatchPatternNoCase(token, filename));
  1699.                         UnLock(lock);
  1700.                 }
  1701.         return filename;
  1702. #else
  1703.         return NULL;
  1704. #endif
  1705. }
  1706. @
  1707.  
  1708.  
  1709. 0.2
  1710. log
  1711. @Added commandline parsing, calling PackSpoolJobs() for every provided
  1712. system.
  1713. Added GetFileName() which is able to scan a directory for files,
  1714. matching a certain pattern.
  1715. Added a basic LharcJob() call, which just locks and opens the file
  1716. until now.
  1717. @
  1718. text
  1719. @d134 2
  1720. a135 1
  1721.         char buffer[256];
  1722. d141 25
  1723. a165 3
  1724.                 fscanf(cfilehandle, "%s", buffer);
  1725.                 if (!stricmp(buffer, "S")) {
  1726.                         ;
  1727. d168 3
  1728. d180 3
  1729. d185 1
  1730. a185 1
  1731.  * reset-parameter is != 0.
  1732. @
  1733.  
  1734.  
  1735. 0.1
  1736. log
  1737. @This program is released under the GNU General Public License.
  1738. @
  1739. text
  1740. @d3 2
  1741. a4 2
  1742.  *      $Revision$
  1743.  *      $Date$
  1744. d22 1
  1745. a22 1
  1746.  *      $Id$
  1747. d25 3
  1748. a27 1
  1749.  * $Log$
  1750. d32 4
  1751. d37 3
  1752. d41 5
  1753. d48 8
  1754. d59 2
  1755. a60 1
  1756. static const char __RCSId[] = "$Id$";
  1757. d67 10
  1758. d78 2
  1759. d81 108
  1760. @
  1761.