/*
- * "$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 */
{
}
-/*
- * '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 */
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_ERROR;
+ *loglevel = CUPSD_LOG_DEBUG;
message = sb->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...
* 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)
/*
- * 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 $".
*/