/*
- * "$Id: statbuf.c 5447 2006-04-21 20:07:51Z mike $"
+ * "$Id$"
*
- * Status buffer routines for the Common UNIX Printing System (CUPS)
- * scheduler.
+ * Status buffer routines for the CUPS scheduler.
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2014 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
- *
- * Contents:
- *
- * cupsdStatBufNew() - Create a new status buffer.
- * cupsdStatBufDelete() - Destroy a status buffer.
- * cupsdStatBufUpdate() - Update the status buffer.
+ * These coded instructions, statements, and computer programs are the
+ * 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/".
*/
/*
#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 */
{
}
-/*
- * '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 */
* No, read more data...
*/
- if ((bytes = read(sb->fd, sb->buffer + sb->bufused,
- CUPSD_SB_BUFFER_SIZE - sb->bufused - 1)) > 0)
+ if ((bytes = read(sb->fd, sb->buffer + sb->bufused, (size_t)(CUPSD_SB_BUFFER_SIZE - sb->bufused - 1))) > 0)
{
sb->bufused += bytes;
sb->buffer[sb->bufused] = '\0';
lineptr = NULL;
}
- if (lineptr == NULL)
+ if (!lineptr)
{
/*
* End of file...
*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_DEBUG;
* 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...
/*
- * End of "$Id: statbuf.c 5447 2006-04-21 20:07:51Z mike $".
+ * End of "$Id$".
*/