]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Mirror 1.1.x changes.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sun, 30 Mar 2003 20:01:49 +0000 (20:01 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sun, 30 Mar 2003 20:01:49 +0000 (20:01 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3537 7a7537e8-13f0-0310-91df-b6672ffda945

14 files changed:
scheduler/auth.c
scheduler/cert.c
scheduler/classes.c
scheduler/client.c
scheduler/conf.c
scheduler/conf.h
scheduler/file.c
scheduler/file.h
scheduler/ipp.c
scheduler/log.c
scheduler/main.c
scheduler/ppds.c
scheduler/printers.c
scheduler/server.c

index 453a06773e16ee56daa2b04a55e2839f4cdd6f24..9fc25daf8ef087bcfa3a76ef06057e355281f9b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: auth.c,v 1.41.2.20 2003/01/31 17:48:38 mike Exp $"
+ * "$Id: auth.c,v 1.41.2.21 2003/03/30 20:01:41 mike Exp $"
  *
  *   Authorization routines for the Common UNIX Printing System (CUPS).
  *
@@ -822,24 +822,24 @@ GetMD5Passwd(const char *username,        /* I - Username */
              const char *group,                /* I - Group */
              char       passwd[33])    /* O - MD5 password string */
 {
-  FILE *fp;                            /* passwd.md5 file */
-  char filename[1024],                 /* passwd.md5 filename */
-       line[256],                      /* Line from file */
-       tempuser[33],                   /* User from file */
-       tempgroup[33];                  /* Group from file */
+  cups_file_t  *fp;                    /* passwd.md5 file */
+  char         filename[1024],         /* passwd.md5 filename */
+               line[256],              /* Line from file */
+               tempuser[33],           /* User from file */
+               tempgroup[33];          /* Group from file */
 
 
   LogMessage(L_DEBUG2, "GetMD5Passwd(username=\"%s\", group=\"%s\", passwd=%p)",
              username, group ? group : "(null)", passwd);
 
   snprintf(filename, sizeof(filename), "%s/passwd.md5", ServerRoot);
-  if ((fp = fopen(filename, "r")) == NULL)
+  if ((fp = cupsFileOpen(filename, "r")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to open %s - %s", filename, strerror(errno));
     return (NULL);
   }
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     if (sscanf(line, "%32[^:]:%32[^:]:%32s", tempuser, tempgroup, passwd) != 3)
     {
@@ -857,7 +857,7 @@ GetMD5Passwd(const char *username,  /* I - Username */
       LogMessage(L_DEBUG2, "Found MD5 user %s, group %s...", username,
                  tempgroup);
 
-      fclose(fp);
+      cupsFileClose(fp);
       return (passwd);
     }
   }
@@ -866,7 +866,7 @@ GetMD5Passwd(const char *username,  /* I - Username */
   * Didn't find a password entry - return NULL!
   */
 
-  fclose(fp);
+  cupsFileClose(fp);
   return (NULL);
 }
 
@@ -1746,5 +1746,5 @@ to64(char          *s,    /* O - Output string */
 
 
 /*
- * End of "$Id: auth.c,v 1.41.2.20 2003/01/31 17:48:38 mike Exp $".
+ * End of "$Id: auth.c,v 1.41.2.21 2003/03/30 20:01:41 mike Exp $".
  */
index 2516458ee0b826212deb5512bc511fa91d9e4efc..1f7d3dc083d425821a2d62569eb1f45ad076b5b4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cert.c,v 1.7.2.9 2003/01/24 20:45:18 mike Exp $"
+ * "$Id: cert.c,v 1.7.2.10 2003/03/30 20:01:41 mike Exp $"
  *
  *   Authentication certificate routines for the Common UNIX
  *   Printing System (CUPS).
@@ -247,7 +247,7 @@ FindCert(const char *certificate)   /* I - Certificate */
 void
 InitCerts(void)
 {
-  FILE         *fp;                    /* /dev/random file */
+  cups_file_t  *fp;                    /* /dev/random file */
   unsigned     seed;                   /* Seed for random number generator */
   struct timeval tod;                  /* Time of day */
 
@@ -257,7 +257,7 @@ InitCerts(void)
   * the current time, as available...
   */
 
-  if ((fp = fopen("/dev/urandom", "rb")) == NULL)
+  if ((fp = cupsFileOpen("/dev/urandom", "rb")) == NULL)
   {
    /*
     * Get the time in usecs and use it as the initial seed...
@@ -274,12 +274,12 @@ InitCerts(void)
     * them as the seed...
     */
 
-    seed = getc(fp);
-    seed = (seed << 8) | getc(fp);
-    seed = (seed << 8) | getc(fp);
-    seed = (seed << 8) | getc(fp);
+    seed = cupsFileGetChar(fp);
+    seed = (seed << 8) | cupsFileGetChar(fp);
+    seed = (seed << 8) | cupsFileGetChar(fp);
+    seed = (seed << 8) | cupsFileGetChar(fp);
 
-    fclose(fp);
+    cupsFileClose(fp);
   }
 
   srandom(seed);
@@ -293,5 +293,5 @@ InitCerts(void)
 
 
 /*
- * End of "$Id: cert.c,v 1.7.2.9 2003/01/24 20:45:18 mike Exp $".
+ * End of "$Id: cert.c,v 1.7.2.10 2003/03/30 20:01:41 mike Exp $".
  */
index 64ac7c05400e4a4d5154b6e984cb4d0ef5cfce32..3ce66836591e489435eb70f7e16408ea43328fa9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: classes.c,v 1.34.2.12 2003/03/10 19:28:23 mike Exp $"
+ * "$Id: classes.c,v 1.34.2.13 2003/03/30 20:01:42 mike Exp $"
  *
  *   Printer class routines for the Common UNIX Printing System (CUPS).
  *
@@ -320,7 +320,7 @@ FindClass(const char *name) /* I - Name of class */
 void
 LoadAllClasses(void)
 {
-  FILE         *fp;                    /* classes.conf file */
+  cups_file_t  *fp;                    /* classes.conf file */
   int          linenum;                /* Current line number */
   int          len;                    /* Length of line */
   char         line[1024],             /* Line from file */
@@ -337,7 +337,7 @@ LoadAllClasses(void)
   */
 
   snprintf(line, sizeof(line), "%s/classes.conf", ServerRoot);
-  if ((fp = fopen(line, "r")) == NULL)
+  if ((fp = cupsFileOpen(line, "r")) == NULL)
   {
     LogMessage(L_ERROR, "LoadAllClasses: Unable to open %s - %s", line,
                strerror(errno));
@@ -351,7 +351,7 @@ LoadAllClasses(void)
   linenum = 0;
   p       = NULL;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -563,7 +563,7 @@ LoadAllClasses(void)
     }
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -574,7 +574,7 @@ LoadAllClasses(void)
 void
 SaveAllClasses(void)
 {
-  FILE         *fp;                    /* classes.conf file */
+  cups_file_t  *fp;                    /* classes.conf file */
   char         temp[1024];             /* Temporary string */
   printer_t    *pclass;                /* Current printer class */
   int          i;                      /* Looping var */
@@ -587,7 +587,7 @@ SaveAllClasses(void)
   */
 
   snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
-  if ((fp = fopen(temp, "w")) == NULL)
+  if ((fp = cupsFileOpen(temp, "w")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to save classes.conf - %s", strerror(errno));
     return;
@@ -599,8 +599,8 @@ SaveAllClasses(void)
   * Restrict access to the file...
   */
 
-  fchown(fileno(fp), User, Group);
-  fchmod(fileno(fp), 0600);
+  fchown(cupsFileNumber(fp), User, Group);
+  fchmod(cupsFileNumber(fp), 0600);
 
  /*
   * Write a small header to the file...
@@ -610,8 +610,8 @@ SaveAllClasses(void)
   curdate = gmtime(&curtime);
   strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
 
-  fputs("# Class configuration file for " CUPS_SVERSION "\n", fp);
-  fprintf(fp, "# Written by cupsd on %s\n", temp);
+  cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
+  cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
 
  /*
   * Write each local class known to the system...
@@ -633,47 +633,47 @@ SaveAllClasses(void)
     */
 
     if (pclass == DefaultPrinter)
-      fprintf(fp, "<DefaultClass %s>\n", pclass->name);
+      cupsFilePrintf(fp, "<DefaultClass %s>\n", pclass->name);
     else
-      fprintf(fp, "<Class %s>\n", pclass->name);
+      cupsFilePrintf(fp, "<Class %s>\n", pclass->name);
 
     if (pclass->info)
-      fprintf(fp, "Info %s\n", pclass->info);
+      cupsFilePrintf(fp, "Info %s\n", pclass->info);
 
     if (pclass->location)
-      fprintf(fp, "Location %s\n", pclass->location);
+      cupsFilePrintf(fp, "Location %s\n", pclass->location);
 
     if (pclass->state == IPP_PRINTER_STOPPED)
     {
-      fputs("State Stopped\n", fp);
-      fprintf(fp, "StateMessage %s\n", pclass->state_message);
+      cupsFilePuts(fp, "State Stopped\n");
+      cupsFilePrintf(fp, "StateMessage %s\n", pclass->state_message);
     }
     else
-      fputs("State Idle\n", fp);
+      cupsFilePuts(fp, "State Idle\n");
 
     if (pclass->accepting)
-      fputs("Accepting Yes\n", fp);
+      cupsFilePuts(fp, "Accepting Yes\n");
     else
-      fputs("Accepting No\n", fp);
+      cupsFilePuts(fp, "Accepting No\n");
 
     for (i = 0; i < pclass->num_printers; i ++)
-      fprintf(fp, "Printer %s\n", pclass->printers[i]->name);
+      cupsFilePrintf(fp, "Printer %s\n", pclass->printers[i]->name);
 
-    fprintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
-    fprintf(fp, "PageLimit %d\n", pclass->page_limit);
-    fprintf(fp, "KLimit %d\n", pclass->k_limit);
+    cupsFilePrintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
+    cupsFilePrintf(fp, "PageLimit %d\n", pclass->page_limit);
+    cupsFilePrintf(fp, "KLimit %d\n", pclass->k_limit);
 
     for (i = 0; i < pclass->num_users; i ++)
-      fprintf(fp, "%sUser %s\n", pclass->deny_users ? "Deny" : "Allow",
-              pclass->users[i]);
+      cupsFilePrintf(fp, "%sUser %s\n", pclass->deny_users ? "Deny" : "Allow",
+                    pclass->users[i]);
 
-    fputs("</Class>\n", fp);
+    cupsFilePuts(fp, "</Class>\n");
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
 /*
- * End of "$Id: classes.c,v 1.34.2.12 2003/03/10 19:28:23 mike Exp $".
+ * End of "$Id: classes.c,v 1.34.2.13 2003/03/30 20:01:42 mike Exp $".
  */
index 935b86940d59e00d5a321d0834fe43070a1ff0b5..0c1a9960b9d07df39ece8f27929db25acf345ee4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.c,v 1.91.2.54 2003/03/28 22:29:47 mike Exp $"
+ * "$Id: client.c,v 1.91.2.55 2003/03/30 20:01:42 mike Exp $"
  *
  *   Client routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -2747,7 +2747,7 @@ get_file(client_t    *con,        /* I  - Client connection */
 static http_status_t                   /* O - Status */
 install_conf_file(client_t *con)       /* I - Connection */
 {
-  FILE         *in,                    /* Input file */
+  cups_file_t  *in,                    /* Input file */
                *out;                   /* Output file */
   char         buffer[1024];           /* Copy buffer */
   int          bytes;                  /* Number of bytes */
@@ -2784,36 +2784,36 @@ install_conf_file(client_t *con)        /* I - Connection */
   * Open the request file and new config file...
   */
 
-  if ((in = fopen(con->filename, "rb")) == NULL)
+  if ((in = cupsFileOpen(con->filename, "rb")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to open request file \"%s\" - %s",
                con->filename, strerror(errno));
     return (HTTP_SERVER_ERROR);
   }
 
-  if ((out = fopen(newfile, "wb")) == NULL)
+  if ((out = cupsFileOpen(newfile, "wb")) == NULL)
   {
-    fclose(in);
+    cupsFileClose(in);
     LogMessage(L_ERROR, "Unable to open config file \"%s\" - %s",
                newfile, strerror(errno));
     return (HTTP_SERVER_ERROR);
   }
 
-  fchmod(fileno(out), confinfo.st_mode);
-  fchown(fileno(out), confinfo.st_uid, confinfo.st_gid);
+  fchmod(cupsFileNumber(out), confinfo.st_mode);
+  fchown(cupsFileNumber(out), confinfo.st_uid, confinfo.st_gid);
 
  /*
   * Copy from the request to the new config file...
   */
 
-  while ((bytes = fread(buffer, 1, sizeof(buffer), in)) > 0)
-    if (fwrite(buffer, 1, bytes, out) < bytes)
+  while ((bytes = cupsFileRead(in, buffer, sizeof(buffer))) > 0)
+    if (cupsFileWrite(out, buffer, bytes) < bytes)
     {
       LogMessage(L_ERROR, "Unable to copy to config file \"%s\" - %s",
                 newfile, strerror(errno));
 
-      fclose(in);
-      fclose(out);
+      cupsFileClose(in);
+      cupsFileClose(out);
       unlink(newfile);
 
       return (HTTP_SERVER_ERROR);
@@ -2823,8 +2823,8 @@ install_conf_file(client_t *con)  /* I - Connection */
   * Close the files...
   */
 
-  fclose(in);
-  if (fclose(out))
+  cupsFileClose(in);
+  if (cupsFileClose(out))
   {
     LogMessage(L_ERROR, "Error file closing config file \"%s\" - %s",
                newfile, strerror(errno));
@@ -3330,5 +3330,5 @@ CDSAWriteFunc(SSLConnectionRef connection,        /* I  - SSL/TLS connection */
 
 
 /*
- * End of "$Id: client.c,v 1.91.2.54 2003/03/28 22:29:47 mike Exp $".
+ * End of "$Id: client.c,v 1.91.2.55 2003/03/30 20:01:42 mike Exp $".
  */
index 733864d5a491cc3545ae9c562167f2f06ef70c8d..9486dc5180a6521021c548d17091506b4a275897 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.c,v 1.77.2.33 2003/03/19 06:07:40 mike Exp $"
+ * "$Id: conf.c,v 1.77.2.34 2003/03/30 20:01:43 mike Exp $"
  *
  *   Configuration routines for the Common UNIX Printing System (CUPS).
  *
@@ -189,8 +189,8 @@ static CFArrayRef CDSAGetServerCerts();
  * Local functions...
  */
 
-static int     read_configuration(FILE *fp);
-static int     read_location(FILE *fp, char *name, int linenum);
+static int     read_configuration(cups_file_t *fp);
+static int     read_location(cups_file_t *fp, char *name, int linenum);
 static int     get_address(const char *value, unsigned defaddress, int defport,
                            int deffamily, http_addr_t *address);
 static int     get_addr_and_mask(const char *value, unsigned *ip,
@@ -205,7 +205,7 @@ int                                 /* O - 1 on success, 0 otherwise */
 ReadConfiguration(void)
 {
   int          i;                      /* Looping var */
-  FILE         *fp;                    /* Configuration file */
+  cups_file_t  *fp;                    /* Configuration file */
   int          status;                 /* Return status */
   char         temp[1024],             /* Temporary buffer */
                *slash;                 /* Directory separator */
@@ -422,12 +422,12 @@ ReadConfiguration(void)
   * Read the configuration file...
   */
 
-  if ((fp = fopen(ConfigurationFile, "r")) == NULL)
+  if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL)
     return (0);
 
   status = read_configuration(fp);
 
-  fclose(fp);
+  cupsFileClose(fp);
 
   if (!status)
     return (0);
@@ -689,7 +689,7 @@ ReadConfiguration(void)
  */
 
 static int                             /* O - 1 on success, 0 on failure */
-read_configuration(FILE *fp)           /* I - File to read from */
+read_configuration(cups_file_t *fp)    /* I - File to read from */
 {
   int          i;                      /* Looping var */
   int          linenum;                /* Current line number */
@@ -706,7 +706,7 @@ read_configuration(FILE *fp)                /* I - File to read from */
   dirsvc_poll_t        *poll;                  /* Polling data */
   http_addr_t  polladdr;               /* Polling address */
   location_t   *location;              /* Browse location */
-  FILE         *incfile;               /* Include file */
+  cups_file_t  *incfile;               /* Include file */
   char         incname[1024];          /* Include filename */
 
 
@@ -716,7 +716,7 @@ read_configuration(FILE *fp)                /* I - File to read from */
 
   linenum = 0;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -771,13 +771,13 @@ read_configuration(FILE *fp)              /* I - File to read from */
       else
         snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value);
 
-      if ((incfile = fopen(incname, "rb")) == NULL)
+      if ((incfile = cupsFileOpen(incname, "rb")) == NULL)
         LogMessage(L_ERROR, "Unable to include config file \"%s\" - %s",
                   incname, strerror(errno));
       else
       {
         read_configuration(incfile);
-       fclose(incfile);
+       cupsFileClose(incfile);
       }
     }
     else if (strcasecmp(name, "<Location") == 0)
@@ -1479,10 +1479,10 @@ read_configuration(FILE *fp)            /* I - File to read from */
  * 'read_location()' - Read a <Location path> definition.
  */
 
-static int                     /* O - New line number or 0 on error */
-read_location(FILE *fp,                /* I - Configuration file */
-              char *location,  /* I - Location name/path */
-             int  linenum)     /* I - Current line number */
+static int                             /* O - New line number or 0 on error */
+read_location(cups_file_t *fp,         /* I - Configuration file */
+              char        *location,   /* I - Location name/path */
+             int         linenum)      /* I - Current line number */
 {
   int          i;                      /* Looping var */
   location_t   *loc,                   /* New location */
@@ -1503,7 +1503,7 @@ read_location(FILE *fp,           /* I - Configuration file */
   parent->limit = AUTH_LIMIT_ALL;
   loc           = parent;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -2198,5 +2198,5 @@ CDSAGetServerCerts(void)
 
 
 /*
- * End of "$Id: conf.c,v 1.77.2.33 2003/03/19 06:07:40 mike Exp $".
+ * End of "$Id: conf.c,v 1.77.2.34 2003/03/30 20:01:43 mike Exp $".
  */
index b636d9aeb0ac70079836a3f4d1b998b37d2110f1..6dc460b509cde1b7379f6b17284662c4286ab0b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.h,v 1.36.2.16 2003/03/19 06:07:42 mike Exp $"
+ * "$Id: conf.h,v 1.36.2.17 2003/03/30 20:01:44 mike Exp $"
  *
  *   Configuration file definitions for the Common UNIX Printing System (CUPS)
  *   scheduler.
@@ -150,7 +150,7 @@ VAR int                     ClassifyOverride        VALUE(0),
                                        /* Run as unpriviledged user? */
                        PrintcapFormat          VALUE(PRINTCAP_BSD);
                                        /* Format of printcap file? */
-VAR FILE               *AccessFile             VALUE(NULL),
+VAR cups_file_t                *AccessFile             VALUE(NULL),
                                        /* Access log file */
                        *ErrorFile              VALUE(NULL),
                                        /* Error log file */
@@ -192,5 +192,5 @@ extern int  LogPage(job_t *job, const char *page);
 
 
 /*
- * End of "$Id: conf.h,v 1.36.2.16 2003/03/19 06:07:42 mike Exp $".
+ * End of "$Id: conf.h,v 1.36.2.17 2003/03/30 20:01:44 mike Exp $".
  */
index eee2c238eaaa762654acd58a650839fb16f6a284..7a40c3263bc5bb5cb4cc2ece00f2d33340e5838d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: file.c,v 1.1.2.1 2003/03/29 21:42:13 mike Exp $"
+ * "$Id: file.c,v 1.1.2.2 2003/03/30 20:01:44 mike Exp $"
  *
  *   File functions for the Common UNIX Printing System (CUPS).
  *
  * Contents:
  *
  *   cupsFileClose()   - Close a CUPS file.
+ *   cupsFileFlush()   - Flush pending output.
  *   cupsFileGetChar() - Get a single character from a file.
  *   cupsFileGets()    - Get a CR and/or LF-terminated line.
  *   cupsFileOpen()    - Open a CUPS file.
  *   cupsFilePrintf()  - Write a formatted string.
+ *   cupsFilePutChar() - Write a character.
  *   cupsFilePuts()    - Write a string.
+ *   cupsFileRead()    - Read from a file.
+ *   cupsFileSeek()    - Seek in a file.
+ *   cupsFileWrite()   - Write to a file.
  *   cups_fill()       - Fill the input buffer...
  *   cups_read()       - Read from a file descriptor.
  *   cups_write()      - Write to a file descriptor.
@@ -94,6 +99,9 @@ cupsFileClose(cups_file_t *fp)                /* I - CUPS file */
     inflateEnd(&fp->stream);
 #endif /* HAVE_LIBZ */
 
+  if (fp->mode == 'w')
+    cupsFileFlush(fp);
+
  /*
   * Save the file descriptor we used and free memory...
   */
@@ -110,6 +118,37 @@ cupsFileClose(cups_file_t *fp)             /* I - CUPS file */
 }
 
 
+/*
+ * 'cupsFileFlush()' - Flush pending output.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsFileFlush(cups_file_t *fp)         /* I - CUPS file */
+{
+  int  bytes;                          /* Bytes to write */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (!fp || fp->mode != 'w')
+    return (-1);
+
+  bytes = fp->ptr - fp->buf;
+
+  if (bytes > 0)
+  {
+    if (cups_write(fp->fd, fp->buf, bytes) < bytes)
+      return (-1);
+
+    fp->ptr = fp->buf;
+  }
+   
+  return (0);
+}
+
+
 /*
  * 'cupsFileGetChar()' - Get a single character from a file.
  */
@@ -227,7 +266,7 @@ cupsFileOpen(const char *filename,  /* I - Name of file */
   * Range check input...
   */
 
-  if (!filename || !mode || (*mode != 'r' && *mode != 'w'))
+  if (!filename || !mode || (*mode != 'r' && *mode != 'w' && *mode != 'a'))
     return (NULL);
 
  /*
@@ -241,10 +280,23 @@ cupsFileOpen(const char *filename,        /* I - Name of file */
   * Open the file...
   */
 
-  if (*mode == 'r')
-    o = O_RDONLY;
-  else
-    o = O_WRONLY | O_TRUNC | O_CREAT;
+  switch (*mode)
+  {
+    case 'a' :
+        o = O_RDWR | O_CREAT;
+       fp->mode = 'w';
+        break;
+
+    case 'r' :
+       o        = O_RDONLY;
+       fp->mode = 'r';
+       break;
+
+    case 'w' :
+        o = O_WRONLY | O_TRUNC | O_CREAT;
+       fp->mode = 'w';
+        break;
+  }
 
   if ((fp->fd = open(filename, o, 0644)) < 0)
   {
@@ -256,7 +308,16 @@ cupsFileOpen(const char *filename, /* I - Name of file */
     return (NULL);
   }
 
-  fp->mode = *mode;
+  if (*mode == 'a')
+    fp->pos = lseek(fp->fd, 0, SEEK_END);
+  else
+    fp->pos = 0;
+
+  if (*mode != 'r')
+  {
+    fp->ptr = fp->buf;
+    fp->end = fp->buf + sizeof(fp->buf);
+  }
 
   return (fp);
 }
@@ -273,16 +334,60 @@ cupsFilePrintf(cups_file_t *fp,           /* I - CUPS file */
 {
   va_list      ap;                     /* Argument list */
   int          bytes;                  /* Formatted size */
+  char         buf[2048];              /* Formatted text */
 
 
   if (!fp || !format || fp->mode != 'w')
     return (-1);
 
   va_start(ap, format);
-  bytes = vsnprintf(fp->buf, sizeof(fp->buf), format, ap);
+  bytes = vsnprintf(buf, sizeof(buf), format, ap);
   va_end(ap);
 
-  return (cups_write(fp->fd, fp->buf, bytes));
+  if ((fp->ptr + bytes) > fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  fp->pos += bytes;
+
+  if (bytes > sizeof(fp->buf))
+    return (cups_write(fp->fd, buf, bytes));
+  else
+  {
+    memcpy(fp->ptr, buf, bytes);
+    fp->ptr += bytes;
+    return (bytes);
+  }
+}
+
+
+/*
+ * 'cupsFilePutChar()' - Write a character.
+ */
+
+int                                    /* O - 0 on success, -1 on error */
+cupsFilePutChar(cups_file_t *fp,       /* I - CUPS file */
+                int         c)         /* I - Character to write */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!fp || fp->mode != 'w')
+    return (-1);
+
+ /*
+  * Buffer it up...
+  */
+
+  if (fp->ptr >= fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  *(fp->ptr) ++ = c;
+  fp->pos ++;
+
+  return (0);
 }
 
 
@@ -294,6 +399,9 @@ int                                 /* O - Number of bytes written or -1 */
 cupsFilePuts(cups_file_t *fp,          /* I - CUPS file */
              const char  *s)           /* I - String to write */
 {
+  int  bytes;                          /* Bytes to write */
+
+
  /*
   * Range check input...
   */
@@ -305,7 +413,22 @@ cupsFilePuts(cups_file_t *fp,              /* I - CUPS file */
   * Write the string...
   */
 
-  return (cups_write(fp->fd, s, strlen(s)));
+  bytes = strlen(s);
+
+  if ((fp->ptr + bytes) > fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  fp->pos += bytes;
+
+  if (bytes > sizeof(fp->buf))
+    return (cups_write(fp->fd, s, bytes));
+  else
+  {
+    memcpy(fp->ptr, s, bytes);
+    fp->ptr += bytes;
+    return (bytes);
+  }
 }
 
 
@@ -465,6 +588,43 @@ cupsFileSeek(cups_file_t *fp,              /* I - CUPS file */
 }
 
 
+/*
+ * 'cupsFileWrite()' - Write to a file.
+ */
+
+int                                    /* O - Number of bytes written */
+cupsFileWrite(cups_file_t *fp,         /* I - CUPS file */
+              const char  *buf,                /* I - Buffer */
+             int         bytes)        /* I - Number of bytes to write */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!fp || !buf || bytes <= 0 || fp->mode != 'w')
+    return (-1);
+
+ /*
+  * Write the buffer...
+  */
+
+  if ((fp->ptr + bytes) > fp->end)
+    if (cupsFileFlush(fp))
+      return (-1);
+
+  fp->pos += bytes;
+
+  if (bytes > sizeof(fp->buf))
+    return (cups_write(fp->fd, buf, bytes));
+  else
+  {
+    memcpy(fp->ptr, buf, bytes);
+    fp->ptr += bytes;
+    return (bytes);
+  }
+}
+
+
 /*
  * 'cups_fill()' - Fill the input buffer...
  */
@@ -806,5 +966,5 @@ cups_write(int        fd,           /* I - File descriptor */
 
 
 /*
- * End of "$Id: file.c,v 1.1.2.1 2003/03/29 21:42:13 mike Exp $".
+ * End of "$Id: file.c,v 1.1.2.2 2003/03/30 20:01:44 mike Exp $".
  */
index 5a04c006b0fec6f9763a8bbb136e068e255afeb2..280488ec64baaa78f86ed7419c9c00229fe8af95 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: file.h,v 1.1.2.1 2003/03/29 21:42:13 mike Exp $"
+ * "$Id: file.h,v 1.1.2.2 2003/03/30 20:01:44 mike Exp $"
  *
  *   File definitions for the Common UNIX Printing System (CUPS).
  *
@@ -75,13 +75,19 @@ typedef struct
  */
 
 extern int             cupsFileClose(cups_file_t *fp);
+#define                        cupsFileCompressed(fp) (fp)->compressed
+extern int             cupsFileFlush(cups_file_t *fp);
 extern int             cupsFileGetChar(cups_file_t *fp);
 extern char            *cupsFileGets(cups_file_t *fp, char *buf, int buflen);
+#define                        cupsFileNumber(fp) (fp)->fd
 extern cups_file_t     *cupsFileOpen(const char *filename, const char *mode);
 extern int             cupsFilePrintf(cups_file_t *fp, const char *format, ...);
+extern int             cupsFilePutChar(cups_file_t *fp, int c);
 extern int             cupsFilePuts(cups_file_t *fp, const char *s);
 extern int             cupsFileRead(cups_file_t *fp, char *buf, int bytes);
 extern int             cupsFileSeek(cups_file_t *fp, int pos);
+#define                        cupsFileTell(fp) (fp)->pos
+extern int             cupsFileWrite(cups_file_t *fp, const char *buf, int bytes);
 
 
 #  ifdef _cplusplus
@@ -90,5 +96,5 @@ extern int            cupsFileSeek(cups_file_t *fp, int pos);
 #endif /* !_CUPS_FILE_H_ */
 
 /*
- * End of "$Id: file.h,v 1.1.2.1 2003/03/29 21:42:13 mike Exp $".
+ * End of "$Id: file.h,v 1.1.2.2 2003/03/30 20:01:44 mike Exp $".
  */
index 2524d6c39b6a9c95182fca4f1af404b77e4079e6..736af043ef4269057affd0eb89ae83aefe1a0eba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c,v 1.127.2.54 2003/03/28 17:32:44 mike Exp $"
+ * "$Id: ipp.c,v 1.127.2.55 2003/03/30 20:01:44 mike Exp $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -972,11 +972,7 @@ add_printer(client_t        *con,  /* I - Client connection */
   int                  port;           /* Port portion of URI */
   printer_t            *printer;       /* Printer/class */
   ipp_attribute_t      *attr;          /* Printer attribute */
-#ifdef HAVE_LIBZ
-  gzFile               fp;             /* Script/PPD file */
-#else
-  FILE                 *fp;            /* Script/PPD file */
-#endif /* HAVE_LIBZ */
+  cups_file_t          *fp;            /* Script/PPD file */
   char                 line[1024];     /* Line from file... */
   char                 srcfile[1024],  /* Source Script/PPD file */
                        dstfile[1024];  /* Destination Script/PPD file */
@@ -1291,24 +1287,15 @@ add_printer(client_t        *con,       /* I - Client connection */
              printer->name);
     unlink(dstfile);
   }
-#ifdef HAVE_LIBZ
-  else if (srcfile[0] && (fp = gzopen(srcfile, "rb")) != NULL)
-#else
-  else if (srcfile[0] && (fp = fopen(srcfile, "rb")) != NULL)
-#endif /* HAVE_LIBZ */
+  else if (srcfile[0] && (fp = cupsFileOpen(srcfile, "rb")) != NULL)
   {
    /*
     * Yes; get the first line from it...
     */
 
     line[0] = '\0';
-#ifdef HAVE_LIBZ
-    gzgets(fp, line, sizeof(line));
-    gzclose(fp);
-#else
-    fgets(line, sizeof(line), fp);
-    fclose(fp);
-#endif /* HAVE_LIBZ */
+    cupsFileGets(fp, line, sizeof(line));
+    cupsFileClose(fp);
 
    /*
     * Then see what kind of file it is...
@@ -2599,8 +2586,8 @@ copy_banner(client_t   *con,      /* I - Client connection */
   int          kbytes;         /* Size of banner file in kbytes */
   char         filename[1024]; /* Job filename */
   banner_t     *banner;        /* Pointer to banner */
-  FILE         *in;            /* Input file */
-  FILE         *out;           /* Output file */
+  cups_file_t  *in;            /* Input file */
+  cups_file_t  *out;           /* Output file */
   int          ch;             /* Character from file */
   char         attrname[255],  /* Name of attribute */
                *s;             /* Pointer into name */
@@ -2631,7 +2618,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
 
   snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
            job->num_files);
-  if ((out = fopen(filename, "w")) == NULL)
+  if ((out = cupsFileOpen(filename, "w")) == NULL)
   {
     LogMessage(L_ERROR, "copy_banner: Unable to create banner job file %s - %s",
                filename, strerror(errno));
@@ -2639,8 +2626,8 @@ copy_banner(client_t   *con,      /* I - Client connection */
     return (0);
   }
 
-  fchmod(fileno(out), 0640);
-  fchown(fileno(out), User, Group);
+  fchmod(cupsFileNumber(out), 0640);
+  fchown(cupsFileNumber(out), User, Group);
 
   if (con->language)
   {
@@ -2684,9 +2671,9 @@ copy_banner(client_t   *con,      /* I - Client connection */
     snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);
   }
 
-  if ((in = fopen(filename, "r")) == NULL)
+  if ((in = cupsFileOpen(filename, "r")) == NULL)
   {
-    fclose(out);
+    cupsFileClose(out);
     unlink(filename);
     LogMessage(L_ERROR, "copy_banner: Unable to open banner template file %s - %s",
                filename, strerror(errno));
@@ -2698,14 +2685,14 @@ copy_banner(client_t   *con,    /* I - Client connection */
   * Parse the file to the end...
   */
 
-  while ((ch = getc(in)) != EOF)
+  while ((ch = cupsFileGetChar(in)) != EOF)
     if (ch == '{')
     {
      /*
       * Get an attribute name...
       */
 
-      for (s = attrname; (ch = getc(in)) != EOF;)
+      for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;)
         if (!isalpha(ch) && ch != '-' && ch != '?')
           break;
        else if (s < (attrname + sizeof(attrname) - 1))
@@ -2721,9 +2708,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
         * Ignore { followed by stuff that is not an attribute name...
        */
 
-        putc('{', out);
-       fputs(attrname, out);
-       putc(ch, out);
+        cupsFilePrintf(out, "{%s}", attrname);
        continue;
       }
 
@@ -2738,7 +2723,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
 
       if (strcmp(s, "printer-name") == 0)
       {
-        fputs(job->dest, out);
+        cupsFilePuts(out, job->dest);
        continue;
       }
       else if ((attr = ippFindAttribute(job->attrs, s, IPP_TAG_ZERO)) == NULL)
@@ -2753,9 +2738,7 @@ copy_banner(client_t   *con,      /* I - Client connection */
           * Nope, write to file as-is; probably a PostScript procedure...
          */
 
-         putc('{', out);
-         fputs(attrname, out);
-         putc('}', out);
+         cupsFilePrintf(out, "{%s}", attrname);
         }
 
         continue;
@@ -2768,33 +2751,33 @@ copy_banner(client_t   *con,    /* I - Client connection */
       for (i = 0; i < attr->num_values; i ++)
       {
        if (i)
-         putc(',', out);
+         cupsFilePutChar(out, ',');
 
        switch (attr->value_tag)
        {
          case IPP_TAG_INTEGER :
          case IPP_TAG_ENUM :
              if (strncmp(s, "time-at-", 8) == 0)
-               fputs(GetDateTime(attr->values[i].integer), out);
+               cupsFilePuts(out, GetDateTime(attr->values[i].integer));
              else
-               fprintf(out, "%d", attr->values[i].integer);
+               cupsFilePrintf(out, "%d", attr->values[i].integer);
              break;
 
          case IPP_TAG_BOOLEAN :
-             fprintf(out, "%d", attr->values[i].boolean);
+             cupsFilePrintf(out, "%d", attr->values[i].boolean);
              break;
 
          case IPP_TAG_NOVALUE :
-             fputs("novalue", out);
+             cupsFilePuts(out, "novalue");
              break;
 
          case IPP_TAG_RANGE :
-             fprintf(out, "%d-%d", attr->values[i].range.lower,
+             cupsFilePrintf(out, "%d-%d", attr->values[i].range.lower,
                      attr->values[i].range.upper);
              break;
 
          case IPP_TAG_RESOLUTION :
-             fprintf(out, "%dx%d%s", attr->values[i].resolution.xres,
+             cupsFilePrintf(out, "%dx%d%s", attr->values[i].resolution.xres,
                      attr->values[i].resolution.yres,
                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
                          "dpi" : "dpc");
@@ -2819,17 +2802,17 @@ copy_banner(client_t   *con,    /* I - Client connection */
                {
                  if (*p == '(' || *p == ')' || *p == '\\')
                  {
-                   putc('\\', out);
-                   putc(*p, out);
+                   cupsFilePutChar(out, '\\');
+                   cupsFilePutChar(out, *p);
                  }
                  else if (*p < 32 || *p > 126)
-                   fprintf(out, "\\%03o", *p);
+                   cupsFilePrintf(out, "\\%03o", *p);
                  else
-                   putc(*p, out);
+                   cupsFilePutChar(out, *p);
                }
              }
              else
-               fputs(attr->values[i].string.text, out);
+               cupsFilePuts(out, attr->values[i].string.text);
              break;
 
           default :
@@ -2839,24 +2822,24 @@ copy_banner(client_t   *con,    /* I - Client connection */
     }
     else if (ch == '\\')       /* Quoted char */
     {
-      ch = getc(in);
+      ch = cupsFileGetChar(in);
 
       if (ch != '{')           /* Only do special handling for \{ */
-        putc('\\', out);
+        cupsFilePutChar(out, '\\');
 
-      putc(ch, out);
+      cupsFilePutChar(out, ch);
     }
     else
-      putc(ch, out);
+      cupsFilePutChar(out, ch);
 
-  fclose(in);
+  cupsFileClose(in);
 
-  kbytes = (ftell(out) + 1023) / 1024;
+  kbytes = (cupsFileTell(out) + 1023) / 1024;
 
   if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
     attr->values[0].integer += kbytes;
 
-  fclose(out);
+  cupsFileClose(out);
 
   return (kbytes);
 }
@@ -6353,5 +6336,5 @@ validate_user(client_t   *con,            /* I - Client connection */
 
 
 /*
- * End of "$Id: ipp.c,v 1.127.2.54 2003/03/28 17:32:44 mike Exp $".
+ * End of "$Id: ipp.c,v 1.127.2.55 2003/03/30 20:01:44 mike Exp $".
  */
index 0b975e230b3e2ef8ddf5088600fd8d53d61da5de..9ef867b41e1eca54f802c3447efa34a6cbf51d6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: log.c,v 1.19.2.10 2003/03/10 15:05:54 mike Exp $"
+ * "$Id: log.c,v 1.19.2.11 2003/03/30 20:01:47 mike Exp $"
  *
  *   Log file routines for the Common UNIX Printing System (CUPS).
  *
@@ -46,7 +46,7 @@
  * Local functions...
  */
 
-static int     check_log_file(FILE **, const char *);
+static int     check_log_file(cups_file_t **, const char *);
 
 
 /*
@@ -187,7 +187,7 @@ LogMessage(int        level,        /* I - Log level */
   * Print the log level and date/time...
   */
 
-  fprintf(ErrorFile, "%c %s ", levels[level], GetDateTime(time(NULL)));
+  cupsFilePrintf(ErrorFile, "%c %s ", levels[level], GetDateTime(time(NULL)));
 
  /*
   * Then the log message...
@@ -201,11 +201,12 @@ LogMessage(int        level,      /* I - Log level */
   * Then a newline...
   */
 
-  fputs(line, ErrorFile);
   if (len > 0 && line[len - 1] != '\n')
-    putc('\n', ErrorFile);
+    cupsFilePrintf(ErrorFile, "%s\n", line);
+  else
+    cupsFilePuts(ErrorFile, line);
 
-  fflush(ErrorFile);
+  cupsFileFlush(ErrorFile);
 
   ReleaseSignals();
 
@@ -267,12 +268,12 @@ LogPage(job_t       *job, /* I - Job being printed */
   *        billing hostname
   */
 
-  fprintf(PageFile, "%s %s %d %s %s %s %s\n", job->printer->name,
-          job->username ? job->username : "-",
-          job->id, GetDateTime(time(NULL)), page,
-         billing ? billing->values[0].string.text : "-",
-          hostname->values[0].string.text);
-  fflush(PageFile);
+  cupsFilePrintf(PageFile, "%s %s %d %s %s %s %s\n", job->printer->name,
+                job->username ? job->username : "-",
+                job->id, GetDateTime(time(NULL)), page,
+                billing ? billing->values[0].string.text : "-",
+                hostname->values[0].string.text);
+  cupsFileFlush(PageFile);
 
   ReleaseSignals();
 
@@ -343,12 +344,12 @@ LogRequest(client_t      *con,    /* I - Request to log */
   * Write a log of the request in "common log format"...
   */
 
-  fprintf(AccessFile, "%s - %s %s \"%s %s HTTP/%d.%d\" %d %d\n",
-          con->http.hostname, con->username[0] != '\0' ? con->username : "-",
-         GetDateTime(con->start), states[con->operation], con->uri,
-         con->http.version / 100, con->http.version % 100,
-         code, con->bytes);
-  fflush(AccessFile);
+  cupsFilePrintf(AccessFile, "%s - %s %s \"%s %s HTTP/%d.%d\" %d %d\n",
+                con->http.hostname, con->username[0] != '\0' ? con->username : "-",
+                GetDateTime(con->start), states[con->operation], con->uri,
+                con->http.version / 100, con->http.version % 100,
+                code, con->bytes);
+  cupsFileFlush(AccessFile);
 
   ReleaseSignals();
 
@@ -361,8 +362,8 @@ LogRequest(client_t      *con,      /* I - Request to log */
  */
 
 static int                             /* O  - 1 if log file open */
-check_log_file(FILE       **log,       /* IO - Log file */
-              const char *logname)     /* I  - Log filename */
+check_log_file(cups_file_t **log,      /* IO - Log file */
+              const char  *logname)    /* I  - Log filename */
 {
   char backname[1024],                 /* Backup log filename */
        filename[1024],                 /* Formatted log filename */
@@ -381,7 +382,7 @@ check_log_file(FILE       **log,    /* IO - Log file */
   */
 
   if (*log == NULL ||
-      (ftell(*log) > MaxLogSize && MaxLogSize > 0))
+      (cupsFileTell(*log) > MaxLogSize && MaxLogSize > 0))
   {
    /*
     * Handle format strings...
@@ -441,24 +442,24 @@ check_log_file(FILE       **log,  /* IO - Log file */
     * Nope, open the log file...
     */
 
-    if ((*log = fopen(filename, "a")) == NULL)
+    if ((*log = cupsFileOpen(filename, "a")) == NULL)
       return (0);
 
-    fchown(fileno(*log), User, Group);
-    fchmod(fileno(*log), LogFilePerm);
+    fchown(cupsFileNumber(*log), User, Group);
+    fchmod(cupsFileNumber(*log), LogFilePerm);
   }
 
  /*
   * Do we need to rotate the log?
   */
 
-  if (ftell(*log) > MaxLogSize && MaxLogSize > 0)
+  if (cupsFileTell(*log) > MaxLogSize && MaxLogSize > 0)
   {
    /*
     * Rotate log file...
     */
 
-    fclose(*log);
+    cupsFileClose(*log);
 
     strcpy(backname, filename);
     strlcat(backname, ".O", sizeof(backname));
@@ -466,11 +467,11 @@ check_log_file(FILE       **log,  /* IO - Log file */
     unlink(backname);
     rename(filename, backname);
 
-    if ((*log = fopen(filename, "a")) == NULL)
+    if ((*log = cupsFileOpen(filename, "a")) == NULL)
       return (0);
 
-    fchown(fileno(*log), User, Group);
-    fchmod(fileno(*log), LogFilePerm);
+    fchown(cupsFileNumber(*log), User, Group);
+    fchmod(cupsFileNumber(*log), LogFilePerm);
   }
 
   return (1);
@@ -478,5 +479,5 @@ check_log_file(FILE       **log,    /* IO - Log file */
 
 
 /*
- * End of "$Id: log.c,v 1.19.2.10 2003/03/10 15:05:54 mike Exp $".
+ * End of "$Id: log.c,v 1.19.2.11 2003/03/30 20:01:47 mike Exp $".
  */
index b639c06770b66ca6fffc0cb3638e75941d84d917..0059f5365330b4800cae0a15e1a962a115eef7be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c,v 1.57.2.40 2003/03/21 15:09:47 mike Exp $"
+ * "$Id: main.c,v 1.57.2.41 2003/03/30 20:01:48 mike Exp $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -100,7 +100,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   struct sigaction     action;         /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
 #ifdef __sgi
-  FILE                 *fp;            /* Fake lpsched lock file */
+  cups_file_t          *fp;            /* Fake lpsched lock file */
 #endif /* __sgi */
 
 
@@ -350,7 +350,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   * printing...
   */
 
-  if ((fp = fopen("/var/spool/lp/SCHEDLOCK", "a")) == NULL)
+  if ((fp = cupsFileOpen("/var/spool/lp/SCHEDLOCK", "w")) == NULL)
   {
     syslog(LOG_LPR, "Unable to create fake lpsched lock file "
                     "\"/var/spool/lp/SCHEDLOCK\"\' - %s!",
@@ -358,10 +358,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
   }
   else
   {
-    fclose(fp);
+    fchmod(cupsFileNumber(fp), 0644);
+    fchown(cupsFileNumber(fp), User, Group);
 
-    chmod("/var/spool/lp/SCHEDLOCK", 0644);
-    chown("/var/spool/lp/SCHEDLOCK", User, Group);
+    cupsFileClose(fp);
   }
 #endif /* __sgi */
 
@@ -1037,13 +1037,13 @@ sigterm_handler(int sig)                /* I - Signal */
   FreeAllJobs();
 
   if (AccessFile != NULL)
-    fclose(AccessFile);
+    cupsFileClose(AccessFile);
 
   if (ErrorFile != NULL)
-    fclose(ErrorFile);
+    cupsFileClose(ErrorFile);
 
   if (PageFile != NULL)
-    fclose(PageFile);
+    cupsFileClose(PageFile);
 
   DeleteAllLocations();
 
@@ -1100,5 +1100,5 @@ usage(void)
 
 
 /*
- * End of "$Id: main.c,v 1.57.2.40 2003/03/21 15:09:47 mike Exp $".
+ * End of "$Id: main.c,v 1.57.2.41 2003/03/30 20:01:48 mike Exp $".
  */
index 7099f57397ef99be21b4f6f18f2653616c669b04..eef9a00aa257d878d3edf5ebf6a9da87508e8760 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppds.c,v 1.14.2.9 2003/01/07 18:27:26 mike Exp $"
+ * "$Id: ppds.c,v 1.14.2.10 2003/03/30 20:01:48 mike Exp $"
  *
  *   PPD scanning routines for the Common UNIX Printing System (CUPS).
  *
 #include "cupsd.h"
 #include <ctype.h>
 
-#ifdef HAVE_LIBZ
-#  include <zlib.h>
-#else
-#  define gzFile       FILE *
-#  define gzclose      fclose
-#  define gzread(f,b,l)        fread((b), 1, (l), (f))
-#  define gzopen       fopen
-#endif /* HAVE_LIBZ */
-
 
 /*
  * PPD information structures...
@@ -71,19 +62,6 @@ typedef struct
 } ppd_info_t;
 
 
-/*
- * Buffered file structure...
- */
-
-typedef struct
-{
-  gzFile       fp;                     /* Pointer to file */
-  char         *ptr,                   /* Pointer in buffer */
-               *end,                   /* End of buffer */
-               buf[1024];              /* Buffer */
-} buf_t;
-
-
 /*
  * Local globals...
  */
@@ -98,11 +76,9 @@ static int           changed_ppd;    /* Did we change the PPD database? */
  * Local functions...
  */
 
-static int     buf_read(buf_t *fp);
 static int     compare_names(const ppd_info_t *p0, const ppd_info_t *p1);
 static int     compare_ppds(const ppd_info_t *p0, const ppd_info_t *p1);
 static void    load_ppds(const char *d, const char *p);
-static char    *ppd_gets(buf_t *fp, char *buf, int buflen);
 
 
 /*
@@ -110,13 +86,13 @@ static char        *ppd_gets(buf_t *fp, char *buf, int buflen);
  */
 
 void
-LoadPPDs(const char *d)                /* I - Directory to scan... */
+LoadPPDs(const char *d)                        /* I - Directory to scan... */
 {
-  int          i;              /* Looping var */
-  ppd_info_t   *ppd;           /* Current PPD file */
-  FILE         *fp;            /* ppds.dat file */
-  struct stat  fileinfo;       /* ppds.dat information */
-  char         filename[1024]; /* ppds.dat filename */
+  int          i;                      /* Looping var */
+  ppd_info_t   *ppd;                   /* Current PPD file */
+  cups_file_t  *fp;                    /* ppds.dat file */
+  struct stat  fileinfo;               /* ppds.dat information */
+  char         filename[1024];         /* ppds.dat filename */
 
 
  /*
@@ -145,15 +121,15 @@ LoadPPDs(const char *d)           /* I - Directory to scan... */
       num_ppds   = 0;
       alloc_ppds = 0;
     }
-    else if ((fp = fopen(filename, "rb")) != NULL)
+    else if ((fp = cupsFileOpen(filename, "rb")) != NULL)
     {
       for (i = num_ppds, ppd = ppds; i > 0; i --, ppd ++)
       {
-        fread(&(ppd->record), 1, sizeof(ppd_rec_t), fp);
+        cupsFileRead(fp, (char *)&(ppd->record), sizeof(ppd_rec_t));
        ppd->found = 0;
       }
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       LogMessage(L_INFO, "LoadPPDs: Read \"%s\", %d PPDs...", filename,
                  num_ppds);
@@ -212,12 +188,12 @@ LoadPPDs(const char *d)           /* I - Directory to scan... */
 
   if (changed_ppd)
   {
-    if ((fp = fopen(filename, "wb")) != NULL)
+    if ((fp = cupsFileOpen(filename, "wb")) != NULL)
     {
       for (i = num_ppds, ppd = ppds; i > 0; i --, ppd ++)
-       fwrite(&(ppd->record), 1, sizeof(ppd_rec_t), fp);
+       cupsFileWrite(fp, (char *)&(ppd->record), sizeof(ppd_rec_t));
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       LogMessage(L_INFO, "LoadPPDs: Wrote \"%s\", %d PPDs...", filename,
                 num_ppds);
@@ -278,31 +254,6 @@ LoadPPDs(const char *d)            /* I - Directory to scan... */
 }
 
 
-/*
- * 'buf_read()' - Read a buffer of data into memory...
- */
-
-static int                     /* O - Number of bytes read */
-buf_read(buf_t *fp)            /* I - File to read from */
-{
-  int  count;                  /* Number of bytes read */
-
-
-  if ((count = gzread(fp->fp, fp->buf, sizeof(fp->buf))) > 0)
-  {
-    fp->ptr = fp->buf;
-    fp->end = fp->buf + count;
-  }
-  else
-  {
-    fp->ptr = NULL;
-    fp->end = NULL;
-  }
-
-  return (count);
-}
-
-
 /*
  * 'compare_names()' - Compare PPD filenames for sorting.
  */
@@ -452,7 +403,7 @@ load_ppds(const char *d,            /* I - Actual directory */
           const char *p)               /* I - Virtual path in name */
 {
   int          i;                      /* Looping var */
-  buf_t                fp;                     /* Pointer to file */
+  cups_file_t  *fp;                    /* Pointer to file */
   DIR          *dir;                   /* Directory pointer */
   DIRENT       *dent;                  /* Directory entry */
   struct stat  fileinfo;               /* File information */
@@ -562,17 +513,15 @@ load_ppds(const char *d,          /* I - Actual directory */
     * No, file is new/changed, so re-scan it...
     */
 
-    if ((fp.fp = gzopen(filename, "rb")) == NULL)
+    if ((fp = cupsFileOpen(filename, "rb")) == NULL)
       continue;
 
-    fp.ptr = fp.end = NULL;
-
    /*
     * Now see if this is a PPD file...
     */
 
     line[0] = '\0';
-    ppd_gets(&fp, line, sizeof(line));
+    cupsFileGets(fp, line, sizeof(line));
 
     if (strncmp(line, "*PPD-Adobe:", 11) != 0)
     {
@@ -580,7 +529,7 @@ load_ppds(const char *d,            /* I - Actual directory */
       * Nope, close the file and continue...
       */
 
-      gzclose(fp.fp);
+      cupsFileClose(fp);
 
       continue;
     }
@@ -594,7 +543,7 @@ load_ppds(const char *d,            /* I - Actual directory */
     manufacturer[0] = '\0';
     strcpy(language, "en");
 
-    while (ppd_gets(&fp, line, sizeof(line)) != NULL)
+    while (cupsFileGets(fp, line, sizeof(line)) != NULL)
     {
       if (strncmp(line, "*Manufacturer:", 14) == 0)
        sscanf(line, "%*[^\"]\"%255[^\"]", manufacturer);
@@ -628,7 +577,7 @@ load_ppds(const char *d,            /* I - Actual directory */
     * Close the file...
     */
 
-    gzclose(fp.fp);
+    cupsFileClose(fp);
 
    /*
     * See if we got all of the required info...
@@ -832,66 +781,5 @@ load_ppds(const char *d,           /* I - Actual directory */
 
 
 /*
- * 'ppd_gets()' - Read a line from a PPD file.
- */
-
-static char *                  /* O - Line from file or NULL on EOF */
-ppd_gets(buf_t *fp,            /* I - File to read from */
-         char  *buf,           /* I - Line buffer */
-        int   buflen)          /* I - Length of buffer */
-{
-  int          ch;             /* Character from file */
-  char         *ptr,           /* Current position in line buffer */
-               *end;           /* End of line buffer */
-
- /*
-  * Range check everything...
-  */
-
-  if (fp == NULL || buf == NULL || buflen < 2)
-    return (NULL);
-
- /*
-  * Now loop until we have a valid line...
-  */
-
-  ptr = buf;
-  end = buf + buflen - 1;
-
-  for (;;)
-  {
-    if (fp->ptr >= fp->end)
-      if (buf_read(fp) <= 0)
-        break;
-
-    ch = *(fp->ptr)++;
-
-    if (ch == '\r' || ch == '\n')
-    {
-     /*
-      * Line feed or carriage return...
-      */
-
-      if (ptr == buf)          /* Skip blank lines */
-        continue;
-
-      break;
-    }
-    else if (ptr < end)
-      *ptr++ = ch;
-  }
-
-  if (ptr > buf)
-  {
-    *ptr = '\0';
-
-    return (buf);
-  }
-  else
-    return (NULL);
-}
-
-
-/*
- * End of "$Id: ppds.c,v 1.14.2.9 2003/01/07 18:27:26 mike Exp $".
+ * End of "$Id: ppds.c,v 1.14.2.10 2003/03/30 20:01:48 mike Exp $".
  */
index d3aa9a92a74b11b549e2132ea20685caedf146ec..6175ac61f8d12484051f89349fbe6e4269dcdb6a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: printers.c,v 1.93.2.43 2003/03/28 17:32:47 mike Exp $"
+ * "$Id: printers.c,v 1.93.2.44 2003/03/30 20:01:48 mike Exp $"
  *
  *   Printer routines for the Common UNIX Printing System (CUPS).
  *
@@ -574,7 +574,7 @@ FreePrinterUsers(printer_t *p)      /* I - Printer */
 void
 LoadAllPrinters(void)
 {
-  FILE         *fp;                    /* printers.conf file */
+  cups_file_t  *fp;                    /* printers.conf file */
   int          linenum;                /* Current line number */
   int          len;                    /* Length of line */
   char         line[1024],             /* Line from file */
@@ -590,7 +590,7 @@ LoadAllPrinters(void)
   */
 
   snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
-  if ((fp = fopen(line, "r")) == NULL)
+  if ((fp = cupsFileOpen(line, "r")) == NULL)
   {
     LogMessage(L_ERROR, "LoadAllPrinters: Unable to open %s - %s", line,
                strerror(errno));
@@ -604,7 +604,7 @@ LoadAllPrinters(void)
   linenum = 0;
   p       = NULL;
 
-  while (fgets(line, sizeof(line), fp) != NULL)
+  while (cupsFileGets(fp, line, sizeof(line)) != NULL)
   {
     linenum ++;
 
@@ -796,7 +796,7 @@ LoadAllPrinters(void)
     }
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -809,7 +809,7 @@ void
 SaveAllPrinters(void)
 {
   int          i;                      /* Looping var */
-  FILE         *fp;                    /* printers.conf file */
+  cups_file_t  *fp;                    /* printers.conf file */
   char         temp[1024];             /* Temporary string */
   char         backup[1024];           /* printers.conf.O file */
   printer_t    *printer;               /* Current printer class */
@@ -827,7 +827,7 @@ SaveAllPrinters(void)
   if (rename(temp, backup))
     LogMessage(L_ERROR, "Unable to backup printers.conf - %s", strerror(errno));
 
-  if ((fp = fopen(temp, "w")) == NULL)
+  if ((fp = cupsFileOpen(temp, "w")) == NULL)
   {
     LogMessage(L_ERROR, "Unable to save printers.conf - %s", strerror(errno));
 
@@ -842,8 +842,8 @@ SaveAllPrinters(void)
   * Restrict access to the file...
   */
 
-  fchown(fileno(fp), User, Group);
-  fchmod(fileno(fp), 0600);
+  fchown(cupsFileNumber(fp), User, Group);
+  fchmod(cupsFileNumber(fp), 0600);
 
  /*
   * Write a small header to the file...
@@ -853,8 +853,8 @@ SaveAllPrinters(void)
   curdate = gmtime(&curtime);
   strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
 
-  fputs("# Printer configuration file for " CUPS_SVERSION "\n", fp);
-  fprintf(fp, "# Written by cupsd on %s\n", temp);
+  cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
+  cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
 
  /*
   * Write each local printer known to the system...
@@ -876,44 +876,44 @@ SaveAllPrinters(void)
     */
 
     if (printer == DefaultPrinter)
-      fprintf(fp, "<DefaultPrinter %s>\n", printer->name);
+      cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
     else
-      fprintf(fp, "<Printer %s>\n", printer->name);
+      cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
 
     if (printer->info)
-      fprintf(fp, "Info %s\n", printer->info);
+      cupsFilePrintf(fp, "Info %s\n", printer->info);
 
     if (printer->location)
-      fprintf(fp, "Location %s\n", printer->location);
+      cupsFilePrintf(fp, "Location %s\n", printer->location);
 
     if (printer->device_uri)
-      fprintf(fp, "DeviceURI %s\n", printer->device_uri);
+      cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
 
     if (printer->state == IPP_PRINTER_STOPPED)
     {
-      fputs("State Stopped\n", fp);
-      fprintf(fp, "StateMessage %s\n", printer->state_message);
+      cupsFilePuts(fp, "State Stopped\n");
+      cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
     }
     else
-      fputs("State Idle\n", fp);
+      cupsFilePuts(fp, "State Idle\n");
 
     if (printer->accepting)
-      fputs("Accepting Yes\n", fp);
+      cupsFilePuts(fp, "Accepting Yes\n");
     else
-      fputs("Accepting No\n", fp);
+      cupsFilePuts(fp, "Accepting No\n");
 
-    fprintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
+    cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
             printer->job_sheets[1]);
 
-    fprintf(fp, "QuotaPeriod %d\n", printer->quota_period);
-    fprintf(fp, "PageLimit %d\n", printer->page_limit);
-    fprintf(fp, "KLimit %d\n", printer->k_limit);
+    cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
+    cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
+    cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
 
     for (i = 0; i < printer->num_users; i ++)
-      fprintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
+      cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
               printer->users[i]);
 
-    fputs("</Printer>\n", fp);
+    cupsFilePuts(fp, "</Printer>\n");
 
 #ifdef __sgi
     /*
@@ -924,7 +924,7 @@ SaveAllPrinters(void)
 #endif /* __sgi */
   }
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -1044,7 +1044,7 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
                  "separate-documents-collated-copies"
                };
 #ifdef __sgi
-  FILE         *fp;            /* Interface script file */
+  cups_file_t  *fp;            /* Interface script file */
 #endif /* __sgi */
 
 
@@ -1994,7 +1994,7 @@ ValidateDest(const char   *hostname,      /* I - Host name */
 void
 WritePrintcap(void)
 {
-  FILE         *fp;            /* printcap file */
+  cups_file_t  *fp;            /* printcap file */
   printer_t    *p;             /* Current printer */
 
 
@@ -2019,7 +2019,7 @@ WritePrintcap(void)
   * Open the printcap file...
   */
 
-  if ((fp = fopen(Printcap, "w")) == NULL)
+  if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
     return;
 
  /*
@@ -2027,10 +2027,10 @@ WritePrintcap(void)
   * data has come from...
   */
 
-  fputs("# This file was automatically generated by cupsd(8) from the\n", fp);
-  fprintf(fp, "# %s/printers.conf file.  All changes to this file\n",
+  cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");
+  cupsFilePrintf(fp, "# %s/printers.conf file.  All changes to this file\n",
           ServerRoot);
-  fputs("# will be lost.\n", fp);
+  cupsFilePuts(fp, "# will be lost.\n");
 
  /*
   * Write a new printcap with the current list of printers.
@@ -2050,12 +2050,12 @@ WritePrintcap(void)
        */
 
         if (DefaultPrinter)
-         fprintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
+         cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
                  DefaultPrinter->info, ServerName, DefaultPrinter->name);
 
        for (p = Printers; p != NULL; p = p->next)
          if (p != DefaultPrinter)
-           fprintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
+           cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
                    ServerName, p->name);
         break;
 
@@ -2080,15 +2080,15 @@ WritePrintcap(void)
        *            :description=Description:
        */
 
-        fputs("_all:all=", fp);
+        cupsFilePuts(fp, "_all:all=");
        for (p = Printers; p != NULL; p = p->next)
-         fprintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
+         cupsFilePrintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
 
         if (DefaultPrinter)
-         fprintf(fp, "_default:use=%s\n", DefaultPrinter->name);
+         cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
 
        for (p = Printers; p != NULL; p = p->next)
-         fprintf(fp, "%s:\\\n"
+         cupsFilePrintf(fp, "%s:\\\n"
                      "\t:bsdaddr=%s,%s:\\\n"
                      "\t:description=%s:\n",
                  p->name, ServerName, p->name, p->info ? p->info : "");
@@ -2099,7 +2099,7 @@ WritePrintcap(void)
   * Close the file...
   */
 
-  fclose(fp);
+  cupsFileClose(fp);
 }
 
 
@@ -2110,11 +2110,11 @@ WritePrintcap(void)
  */
 
 static void
-write_irix_config(printer_t *p)        /* I - Printer to update */
+write_irix_config(printer_t *p)                /* I - Printer to update */
 {
-  char filename[1024];         /* Interface script filename */
-  FILE *fp;                    /* Interface script file */
-  int  tag;                    /* Status tag value */
+  char         filename[1024];         /* Interface script filename */
+  cups_file_t  *fp;                    /* Interface script file */
+  int          tag;                    /* Status tag value */
 
 
 
@@ -2128,27 +2128,27 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fputs("#!/bin/sh\n", fp);
+    cupsFilePuts(fp, "#!/bin/sh\n");
 
     if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
                                  IPP_TAG_TEXT)) != NULL)
-      fprintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
+      cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
     else if (p->type & CUPS_PRINTER_CLASS)
-      fputs("NAME=\"Printer Class\"\n", fp);
+      cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
     else
-      fputs("NAME=\"Remote Destination\"\n", fp);
+      cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
 
     if (p->type & CUPS_PRINTER_COLOR)
-      fputs("TYPE=ColorPostScript\n", fp);
+      cupsFilePuts(fp, "TYPE=ColorPostScript\n");
     else
-      fputs("TYPE=MonoPostScript\n", fp);
+      cupsFilePuts(fp, "TYPE=MonoPostScript\n");
 
-    fprintf(fp, "HOSTNAME=%s\n", ServerName);
-    fprintf(fp, "HOSTPRINTER=%s\n", p->name);
+    cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
+    cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0755);
     chown(filename, User, Group);
@@ -2164,11 +2164,11 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fputs("/dev/null\n", fp);
+    cupsFilePuts(fp, "/dev/null\n");
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0644);
     chown(filename, User, Group);
@@ -2190,12 +2190,12 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fputs("#!/bin/sh\n", fp);
-    fprintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
+    cupsFilePuts(fp, "#!/bin/sh\n");
+    cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0755);
     chown(filename, User, Group);
@@ -2210,19 +2210,19 @@ write_irix_config(printer_t *p) /* I - Printer to update */
 
   if (p->type & CUPS_PRINTER_CLASS)
     unlink(filename);
-  else if ((fp = fopen(filename, "w")) != NULL)
+  else if ((fp = cupsFileOpen(filename, "w")) != NULL)
   {
-    fprintf(fp, "Printer Class      | %s\n",
+    cupsFilePrintf(fp, "Printer Class      | %s\n",
             (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
-    fprintf(fp, "Printer Model      | %s\n", p->make_model ? p->make_model : "");
-    fprintf(fp, "Location Code      | %s\n", p->location ? p->location : "");
-    fprintf(fp, "Physical Location  | %s\n", p->info ? p->info : "");
-    fprintf(fp, "Port Path          | %s\n", p->device_uri ? p->device_uri : "");
-    fprintf(fp, "Config Path        | /var/spool/lp/pod/%s.config\n", p->name);
-    fprintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
-    fputs("Status Update Wait | 10 seconds\n", fp);
+    cupsFilePrintf(fp, "Printer Model      | %s\n", p->make_model ? p->make_model : "");
+    cupsFilePrintf(fp, "Location Code      | %s\n", p->location ? p->location : "");
+    cupsFilePrintf(fp, "Physical Location  | %s\n", p->info ? p->info : "");
+    cupsFilePrintf(fp, "Port Path          | %s\n", p->device_uri ? p->device_uri : "");
+    cupsFilePrintf(fp, "Config Path        | /var/spool/lp/pod/%s.config\n", p->name);
+    cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
+    cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
 
-    fclose(fp);
+    cupsFileClose(fp);
 
     chmod(filename, 0664);
     chown(filename, User, Group);
@@ -2235,11 +2235,11 @@ write_irix_config(printer_t *p) /* I - Printer to update */
  */
 
 static void
-write_irix_state(printer_t *p) /* I - Printer to update */
+write_irix_state(printer_t *p)         /* I - Printer to update */
 {
-  char filename[1024];         /* Interface script filename */
-  FILE *fp;                    /* Interface script file */
-  int  tag;                    /* Status tag value */
+  char         filename[1024];         /* Interface script filename */
+  cups_file_t  *fp;                    /* Interface script file */
+  int          tag;                    /* Status tag value */
 
 
   if (p)
@@ -2253,20 +2253,20 @@ write_irix_state(printer_t *p)  /* I - Printer to update */
 
     if (p->type & CUPS_PRINTER_CLASS)
       unlink(filename);
-    else if ((fp = fopen(filename, "w")) != NULL)
+    else if ((fp = cupsFileOpen(filename, "w")) != NULL)
     {
-      fprintf(fp, "Operational Status | %s\n",
+      cupsFilePrintf(fp, "Operational Status | %s\n",
               (p->state == IPP_PRINTER_IDLE)       ? "Idle" :
               (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
                                                      "Faulted");
-      fprintf(fp, "Information        | 01 00 00 | %s\n", CUPS_SVERSION);
-      fprintf(fp, "Information        | 02 00 00 | Device URI: %s\n",
+      cupsFilePrintf(fp, "Information        | 01 00 00 | %s\n", CUPS_SVERSION);
+      cupsFilePrintf(fp, "Information        | 02 00 00 | Device URI: %s\n",
               p->device_uri ? p->device_uri : "");
-      fprintf(fp, "Information        | 03 00 00 | %s jobs\n",
+      cupsFilePrintf(fp, "Information        | 03 00 00 | %s jobs\n",
               p->accepting ? "Accepting" : "Not accepting");
-      fprintf(fp, "Information        | 04 00 00 | %s\n", p->state_message);
+      cupsFilePrintf(fp, "Information        | 04 00 00 | %s\n", p->state_message);
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       chmod(filename, 0664);
       chown(filename, User, Group);
@@ -2307,7 +2307,7 @@ write_irix_state(printer_t *p)    /* I - Printer to update */
 
     if (p->type & CUPS_PRINTER_CLASS)
       unlink(filename);
-    else if ((fp = fopen(filename, "w")) != NULL)
+    else if ((fp = cupsFileOpen(filename, "w")) != NULL)
     {
       if (p->type & CUPS_PRINTER_COLOR)
        tag = 66240;
@@ -2323,10 +2323,10 @@ write_irix_state(printer_t *p)  /* I - Printer to update */
       else if (p->state == IPP_PRINTER_STOPPED)
        tag |= 2;
 
-      fputs("#!/bin/sh\n", fp);
-      fprintf(fp, "#Tag %d\n", tag);
+      cupsFilePuts(fp, "#!/bin/sh\n");
+      cupsFilePrintf(fp, "#Tag %d\n", tag);
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       chmod(filename, 0755);
       chown(filename, User, Group);
@@ -2342,11 +2342,11 @@ write_irix_state(printer_t *p)  /* I - Printer to update */
 
   if (DefaultPrinter != NULL)
   {
-    if ((fp = fopen(filename, "w")) != NULL)
+    if ((fp = cupsFileOpen(filename, "w")) != NULL)
     {
-      fprintf(fp, "%s\n", DefaultPrinter->name);
+      cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
 
-      fclose(fp);
+      cupsFileClose(fp);
 
       chmod(filename, 0644);
       chown(filename, User, Group);
@@ -2359,5 +2359,5 @@ write_irix_state(printer_t *p)    /* I - Printer to update */
 
 
 /*
- * End of "$Id: printers.c,v 1.93.2.43 2003/03/28 17:32:47 mike Exp $".
+ * End of "$Id: printers.c,v 1.93.2.44 2003/03/30 20:01:48 mike Exp $".
  */
index a281bb8221dbe5c1fdcad6dce7b96da85ce6f255..3e895884fdc8d827333f528b627e5759fccbe75d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: server.c,v 1.2.2.10 2003/03/28 22:29:49 mike Exp $"
+ * "$Id: server.c,v 1.2.2.11 2003/03/30 20:01:49 mike Exp $"
  *
  *   Server start/stop routines for the Common UNIX Printing System (CUPS).
  *
@@ -141,21 +141,21 @@ StopServer(void)
 
   if (AccessFile != NULL)
   {
-    fclose(AccessFile);
+    cupsFileClose(AccessFile);
 
     AccessFile = NULL;
   }
 
   if (ErrorFile != NULL)
   {
-    fclose(ErrorFile);
+    cupsFileClose(ErrorFile);
 
     ErrorFile = NULL;
   }
 
   if (PageFile != NULL)
   {
-    fclose(PageFile);
+    cupsFileClose(PageFile);
 
     PageFile = NULL;
   }
@@ -170,5 +170,5 @@ StopServer(void)
 
 
 /*
- * End of "$Id: server.c,v 1.2.2.10 2003/03/28 22:29:49 mike Exp $".
+ * End of "$Id: server.c,v 1.2.2.11 2003/03/30 20:01:49 mike Exp $".
  */