]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/statbuf.c
Import CUPS v1.7.1
[thirdparty/cups.git] / scheduler / statbuf.c
index a4875b1c227207182810d04ced9274c92687dd7a..a3f32f09d3b08af2067afe96f1e51907b9ff4593 100644 (file)
@@ -1,31 +1,21 @@
 /*
- * "$Id: statbuf.c 5073 2006-02-04 17:39:51Z mike $"
+ * "$Id: statbuf.c 10996 2013-05-29 11:51:34Z msweet $"
  *
- *   Status buffer routines for the Common UNIX Printing System (CUPS)
- *   scheduler.
+ *   Status buffer routines for the CUPS scheduler.
  *
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
- *   cupsdStatBufNew()    - Create a new status buffer.
  *   cupsdStatBufDelete() - Destroy a status buffer.
+ *   cupsdStatBufNew()    - Create a new status buffer.
  *   cupsdStatBufUpdate() - Update the status buffer.
  */
 
 #include <stdarg.h>
 
 
+/*
+ * 'cupsdStatBufDelete()' - Destroy a status buffer.
+ */
+
+void
+cupsdStatBufDelete(cupsd_statbuf_t *sb)        /* I - Status buffer */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!sb)
+    return;
+
+ /*
+  * Close the status pipe and free memory used...
+  */
+
+  close(sb->fd);
+
+  free(sb);
+}
+
+
 /*
  * 'cupsdStatBufNew()' - Create a new status buffer.
  */
 
 cupsd_statbuf_t        *                       /* O - New status buffer */
-cupsdStatBufNew(int fd,                        /* I - File descriptor of pipe */
+cupsdStatBufNew(int        fd,         /* I - File descriptor of pipe */
                 const char *prefix,    /* I - Printf-style prefix string */
                ...)                    /* I - Additional args as needed */
 {
@@ -98,42 +112,16 @@ cupsdStatBufNew(int fd,                    /* I - File descriptor of pipe */
 }
 
 
-/*
- * 'cupsdStatBufDelete()' - Destroy a status buffer.
- */
-
-void
-cupsdStatBufDelete(cupsd_statbuf_t *sb)        /* I - Status buffer */
-{
- /*
-  * Range check input...
-  */
-
-  if (!sb)
-    return;
-
- /*
-  * Close the status pipe and free memory used...
-  */
-
-  close(sb->fd);
-
-  free(sb);
-}
-
-
 /*
  * 'cupsdStatBufUpdate()' - Update the status buffer.
  */
 
 char *                                 /* O - Line from buffer, "", or NULL */
-cupsdStatBufUpdate(cupsd_statbuf_t *sb,        /* I - Status buffer */
-                   int             *loglevel,
-                                       /* O - Log level */ 
-                   char            *line,
-                                       /* I - Line buffer */
-                   int             linelen)
-                                       /* I - Size of line buffer */
+cupsdStatBufUpdate(
+    cupsd_statbuf_t *sb,               /* I - Status buffer */
+    int             *loglevel,         /* O - Log level */
+    char            *line,             /* I - Line buffer */
+    int             linelen)           /* I - Size of line buffer */
 {
   int          bytes;                  /* Number of bytes read */
   char         *lineptr,               /* Pointer to end of line in buffer */
@@ -193,7 +181,7 @@ cupsdStatBufUpdate(cupsd_statbuf_t *sb,     /* I - Status buffer */
       lineptr = NULL;
   }
 
-  if (lineptr == NULL)
+  if (!lineptr)
   {
    /*
     * End of file...
@@ -270,14 +258,24 @@ cupsdStatBufUpdate(cupsd_statbuf_t *sb,   /* I - Status buffer */
     *loglevel = CUPSD_LOG_STATE;
     message   = sb->buffer + 6;
   }
+  else if (!strncmp(sb->buffer, "JOBSTATE:", 9))
+  {
+    *loglevel = CUPSD_LOG_JOBSTATE;
+    message   = sb->buffer + 9;
+  }
   else if (!strncmp(sb->buffer, "ATTR:", 5))
   {
     *loglevel = CUPSD_LOG_ATTR;
     message   = sb->buffer + 5;
   }
+  else if (!strncmp(sb->buffer, "PPD:", 4))
+  {
+    *loglevel = CUPSD_LOG_PPD;
+    message   = sb->buffer + 4;
+  }
   else
   {
-    *loglevel = CUPSD_LOG_ERROR;
+    *loglevel = CUPSD_LOG_DEBUG;
     message   = sb->buffer;
   }
 
@@ -292,20 +290,23 @@ cupsdStatBufUpdate(cupsd_statbuf_t *sb,   /* I - Status buffer */
   * Send it to the log file as needed...
   */
 
-  if (*loglevel > CUPSD_LOG_NONE &&
-      (*loglevel != CUPSD_LOG_INFO || LogLevel == CUPSD_LOG_DEBUG2))
+  if (sb->prefix[0])
   {
-   /*
-    * General status message; send it to the error_log file...
-    */
+    if (*loglevel > CUPSD_LOG_NONE &&
+       (*loglevel != CUPSD_LOG_INFO || LogLevel >= CUPSD_LOG_DEBUG))
+    {
+     /*
+      * General status message; send it to the error_log file...
+      */
 
-    if (message[0] == '[')
-      cupsdLogMessage(*loglevel, "%s", message);
-    else
-      cupsdLogMessage(*loglevel, "%s %s", sb->prefix, message);
+      if (message[0] == '[')
+       cupsdLogMessage(*loglevel, "%s", message);
+      else
+       cupsdLogMessage(*loglevel, "%s %s", sb->prefix, message);
+    }
+    else if (*loglevel < CUPSD_LOG_NONE && LogLevel >= CUPSD_LOG_DEBUG)
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "%s %s", sb->prefix, sb->buffer);
   }
-  else if (*loglevel < CUPSD_LOG_NONE && LogLevel == CUPSD_LOG_DEBUG2)
-    cupsdLogMessage(CUPSD_LOG_DEBUG2, "%s %s", sb->prefix, sb->buffer);
 
  /*
   * Copy the message to the line buffer...
@@ -317,7 +318,9 @@ cupsdStatBufUpdate(cupsd_statbuf_t *sb,     /* I - Status buffer */
   * Copy over the buffer data we've used up...
   */
 
-  _cups_strcpy(sb->buffer, lineptr);
+  if (lineptr < sb->buffer + sb->bufused)
+    _cups_strcpy(sb->buffer, lineptr);
+
   sb->bufused -= lineptr - sb->buffer;
 
   if (sb->bufused < 0)
@@ -328,5 +331,5 @@ cupsdStatBufUpdate(cupsd_statbuf_t *sb,     /* I - Status buffer */
 
 
 /*
- * End of "$Id: statbuf.c 5073 2006-02-04 17:39:51Z mike $".
+ * End of "$Id: statbuf.c 10996 2013-05-29 11:51:34Z msweet $".
  */