home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fax-3.2.1 / cmd / faxspooler / queue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-31  |  2.8 KB  |  119 lines

  1. /*
  2.   This file is part of the NetFax system.
  3.  
  4.   (c) Copyright 1989 by David M. Siegel. 
  5.       All rights reserved.
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation.
  10.  
  11.     This program is distributed in the hope that it will be useful, 
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <dirent.h>
  23. #include <sys/param.h>
  24.  
  25. #include "../../lib/libfax/libfax.h"
  26. #include "spooler.h"
  27. #include "queue_entry.h"
  28. #include "queue.h"
  29.  
  30. /*
  31.  * This function reads in the entire queue directory, and returns a
  32.  * list of queue files.  This is used to both scan the working queue, 
  33.  * and the new queue.  It is the job of this function to keep the
  34.  * queue clean.  If malformed queue files are found, they should be
  35.  * cleaned out.
  36.  */
  37. int queue_read(q, qdir)
  38.      LIST *q;
  39.      char *qdir;
  40. {
  41.     DIR *dirp;
  42.     struct dirent *dp;
  43.     int count = 0;
  44.  
  45.     if ((dirp = opendir(qdir)) == NULL) {
  46.     log(L_EMERG, "can't open queue directory: %m");
  47.     return (-1);
  48.     }
  49.  
  50.     for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
  51.     char pathname[MAXPATHLEN];
  52.     QueueEntry *qe;
  53.  
  54.     if (dp->d_name[0] == '.')
  55.       continue;
  56.  
  57.     sprintf(pathname, "%s/%s/QF", qdir, dp->d_name);
  58.     if ((qe = queue_entry_read(pathname)) != NULL) {
  59.         list_add(q, (char *)qe);
  60.         count++;
  61.     } else
  62.       queue_entry_delete_files(dp->d_name, qdir);
  63.     }
  64.  
  65.     closedir(dirp);
  66.  
  67.     log(L_DEBUG, "read %d queue file from %s", count, qdir);
  68.  
  69.     return (0);
  70. }
  71.  
  72. /*
  73.  * This function adds a single queue entry, in the given file,
  74.  * to the current spooler queue.
  75.  */
  76. int queue_add_file(q, qdir, file)
  77.      LIST *q;
  78.      char *qdir;
  79.      char *file;
  80. {
  81.     char pathname[MAXPATHLEN];
  82.     QueueEntry *qe;
  83.  
  84.     sprintf(pathname, "%s/%s/QF", qdir, file);
  85.     if ((qe = queue_entry_read(pathname)) != NULL) {
  86.     list_add(q, (char *)qe);
  87.     return (0);
  88.     } else
  89.       queue_entry_delete_files(file, qdir);
  90.  
  91.     return (-1);
  92. }
  93.  
  94. /*
  95.  * This function deletes a single entry from the fax queue,
  96.  * simply by marking the entry as deleted.
  97.  */
  98. int queue_delete_file(q, file)
  99.      LIST *q;
  100.      char *file;
  101. {
  102.     NODE *q_node = NULL;
  103.     QueueEntry *qe;
  104.  
  105.     /*
  106.      * See if it is in the queue.
  107.      */
  108.     while ((qe = (QueueEntry *)list_next(q, &q_node)) != NULL) {
  109.     if (strcmp(file, qe->file) == 0) {
  110.         qe->flags |= QUEUE_F_DELETED;
  111.         return (0);
  112.     }
  113.     }
  114.  
  115.     log(L_INFO, "delete failed: %s", file);
  116.  
  117.     return (-1);
  118. }
  119.