home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
-
- #include "cus.h"
- #include "defines.h"
- #include "proto.h"
-
- int exists(char *cpPath)
- {
- BPTR wpLock = NULL;
- int rc;
-
- if ((wpLock = Lock(cpPath, SHARED_LOCK)) == NULL)
- CU(FALSE);
- rc = TRUE;
-
- CUS:
- if (wpLock)
- UnLock(wpLock);
- return (rc);
- }
-
-
- #define MAXLOCKS 128
- #define LOCKBUFSIZE (MAXLOCKS * sizeof(BPTR))
-
- static unsigned short getdospath(BPTR wpLock, char *cpPath)
- {
- BPTR *wpLockbuf = NULL;
- register BPTR *wpLockbufCur;
- register short wnLocks = NULL;
- register char *cpPathCur;
- struct FileInfoBlock *fibp = NULL;
- register unsigned short rc;
-
- if (!(wpLockbuf = (BPTR *)AllocMem(LOCKBUFSIZE, MEMF_PUBLIC|MEMF_CLEAR)))
- CU(NULL);
- if (!(fibp = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC|MEMF_CLEAR)))
- CU(NULL);
-
- /* get all locks from current dir to root */
- wpLockbufCur = wpLockbuf;
- for ( *wpLockbufCur = wpLock, wnLocks = 1;
- *wpLockbufCur = ParentDir(*wpLockbufCur++);
- wnLocks++ )
- ;
-
- /* get names associated with locks in reverse order through AmigaDOS(tm)
- examinations and build up the target buffer */
-
- /* get name of root outside a loop because of last ':' char
- and right unlocking sequence */
- cpPathCur = cpPath;
- if (!(Examine(*(--wpLockbufCur), fibp)))
- CU(NULL);
- cpPathCur = stpcpy(cpPathCur, fibp->fib_FileName);
- *cpPathCur++ = ':';
-
- /* get names of subdirs within a loop */
- while (--wnLocks) {
- UnLock(*wpLockbufCur--); /* this will unlock the root lock at the first
- * entry of this loop and will _not_ unlock
- * the given 'wpLock' at the last loop! */
- if (!(Examine(*wpLockbufCur, fibp)))
- CU(NULL);
- cpPathCur = stpcpy(cpPathCur, fibp->fib_FileName);
- if (fibp->fib_DirEntryType)
- *cpPathCur++ = '/';
- }
-
- /* set null terminator and calculate the total
- length of actually written characters */
- *cpPathCur = NUL;
- rc = (unsigned short)(cpPathCur - cpPath);
-
- CUS:
- /* unlock all locks which are not already
- unlocked because an error could have been occurred */
- for ( ; wnLocks > 1; wnLocks--)
- UnLock(*wpLockbufCur--);
-
- if (fibp)
- FreeMem(fibp, sizeof(struct FileInfoBlock));
- if (wpLockbuf)
- FreeMem(wpLockbuf, LOCKBUFSIZE);
-
- return rc;
- }
-
-
- #define GETFNLRC_ERR -1
- #define GETFNLATTR_FILE 1
- #define GETFNLATTR_FILEANDDIR 2
- #define GETFNLATTR_DIR 4
-
- static int getfnlst(char *cpPath, char *cpDest, unsigned int cnDest, int wAttr)
- {
- char caPathTmp[RANGE_8BIT];
- BPTR wpLock;
- struct FileInfoBlock *fibp = NULL;
- char *cpDestCur = cpDest;
- int nFiles = 0;
- int rc;
-
- wAttr = wAttr & (GETFNLATTR_FILE | GETFNLATTR_FILEANDDIR | GETFNLATTR_DIR);
-
- if ((fibp = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock), MEMF_PUBLIC|MEMF_CLEAR)) == NULL)
- EE(NULL);
-
- if ((wpLock = Lock(cpPath, SHARED_LOCK)) == NULL)
- EE(GETFNLRC_ERR);
- if (getdospath(wpLock, caPathTmp) == 0) {
- UnLock(wpLock);
- EE(GETFNLRC_ERR);
- }
- if (strlen(caPathTmp) > cnDest-1)
- EE(GETFNLRC_ERR);
- cpDestCur = stpcpy(cpDest, caPathTmp);
- *cpDestCur++ = NUL;
-
- if (Examine(wpLock, fibp) == NULL) {
- UnLock(wpLock);
- EE(GETFNLRC_ERR);
- }
- while (ExNext(wpLock, fibp)) {
- if ( ( (fibp->fib_DirEntryType > 0 /*=DIR*/ ) && (wAttr == GETFNLATTR_FILE) )
- || ( (fibp->fib_DirEntryType < 0 /*=FILE*/) && (wAttr == GETFNLATTR_DIR) ) )
- continue;
- if ( (int)(cpDest + cnDest - cpDestCur) < strlen(fibp->fib_FileName) ) {
- UnLock(wpLock);
- EE(GETFNLRC_ERR);
- }
- cpDestCur = stpcpy(cpDestCur, fibp->fib_FileName);
- *cpDestCur++ = NUL;
- ++nFiles;
- }
- *cpDestCur++ = NUL;
- UnLock(wpLock);
- rc = nFiles;
-
- EE:
- if (fibp)
- FreeMem(fibp, sizeof(struct FileInfoBlock));
- return rc;
- }
-
- static char caSpoolfiles[RANGE_14BIT];
- static char *cpaSpoolfiles[RANGE_10BIT];
-
- int PendingWork(char *cpSpooldir, char *cpSystem, int nFiles)
- {
- int rc;
- int nSpoolfiles;
- int i;
- char caTmp[64];
- int fcnt;
-
- if (!exists(cpSpooldir))
- CU(FALSE);
-
- if ((nSpoolfiles = getfnlst(cpSpooldir, caSpoolfiles, sizeof(caSpoolfiles), 1)) == -1)
- CU(DOSRC_FAIL);
- nSpoolfiles = strbplst(cpaSpoolfiles, sizeof(cpaSpoolfiles), caSpoolfiles);
-
- fcnt = 0;
- for (i = 1; i < nSpoolfiles; i++) {
- if (cpaSpoolfiles[i][0] == 'C' && cpaSpoolfiles[i][1] == '.') {
- strcpy(caTmp, cpSystem);
- if (strlen(caTmp) > 7)
- caTmp[7] = NUL;
- if (strnicmp(caTmp, &cpaSpoolfiles[i][2], strlen(caTmp)) == 0) {
- ++fcnt;
- }
- }
- }
- if (fcnt < nFiles)
- CU(FALSE);
- else
- CU(TRUE);
-
- CUS:
- return rc;
- }
-
- #define TMPFILE "t:uupoll_tmpfile"
-
- void NotifyOnFailure(char *user, char *host, char *message)
- {
- FILE *fp = NULL;
- long t;
- struct tm *tm;
- char caTmp[64];
- char caCmnd[256];
-
- (void)time(&t);
- tm = localtime(&t);
-
- if ((fp = fopen(TMPFILE, "w")) != NULL) {
- sprintf(caTmp, "%s", asctime(tm));
- caTmp[strlen(caTmp)-1] = NUL;
- fprintf(fp, "To: %s\n"
- "Subject: %s: %s\n"
- "\n"
- "[autogenerated message]\n"
- "\n"
- "Local Time : %s\n"
- "Remote Host : %s\n"
- "Status : %s\n"
- "\n"
- "--\n"
- "UUPOLL-DAEMON\n",
- user, host, message, caTmp, host, message);
- fclose(fp);
- sprintf(caCmnd, "run <nil: >nil: sendmail <%s -f UUPOLL-DAEMON -R \"UUCP Admin Subsystem\"", TMPFILE);
- system(caCmnd);
- }
- return;
- }
-
-