]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/sidechannel.c
Move debug printfs to internal usage only.
[thirdparty/cups.git] / cups / sidechannel.c
index da2f77a2be4df4ff5dac9c86c4217eda81fb947f..b43123a8c37bfe7896dabf69156fa8db61cde7f0 100644 (file)
@@ -1,27 +1,10 @@
 /*
- * "$Id: sidechannel.c 7720 2008-07-11 22:46:21Z mike $"
+ * Side-channel API code for CUPS.
  *
- *   Side-channel API code for CUPS.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2006 by Easy Software Products.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 2006 by Easy Software Products.
- *
- *   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/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   cupsSideChannelDoRequest() - Send a side-channel command to a backend and
- *                                wait for a response.
- *   cupsSideChannelRead()      - Read a side-channel message.
- *   cupsSideChannelSNMPGet()   - Query a SNMP OID's value.
- *   cupsSideChannelSNMPWalk()  - Query multiple SNMP OID values.
- *   cupsSideChannelWrite()     - Write a side-channel message.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
 
 #include "sidechannel.h"
 #include "cups-private.h"
-#ifdef WIN32
+#include "debug-internal.h"
+#ifdef _WIN32
 #  include <io.h>
 #else
 #  include <unistd.h>
-#endif /* WIN32 */
-#ifdef __hpux
-#  include <sys/time.h>
-#elif !defined(WIN32)
 #  include <sys/select.h>
-#endif /* __hpux */
-#ifndef WIN32
 #  include <sys/time.h>
-#endif /* !WIN32 */
+#endif /* _WIN32 */
 #ifdef HAVE_POLL
 #  include <poll.h>
 #endif /* HAVE_POLL */
@@ -69,7 +47,7 @@
  * pointed to by the "data" parameter.  cupsSideChannelDoRequest() will
  * update the value to contain the number of data bytes in the buffer.
  *
- * @since CUPS 1.3/Mac OS X 10.5@
+ * @since CUPS 1.3/macOS 10.5@
  */
 
 cups_sc_status_t                       /* O  - Status of command */
@@ -108,7 +86,7 @@ cupsSideChannelDoRequest(
  * pointed to by the "data" parameter.  cupsSideChannelDoRequest() will
  * update the value to contain the number of data bytes in the buffer.
  *
- * @since CUPS 1.3/Mac OS X 10.5@
+ * @since CUPS 1.3/macOS 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on error */
@@ -120,7 +98,7 @@ cupsSideChannelRead(
     double            timeout)         /* I  - Timeout in seconds */
 {
   char         *buffer;                /* Message buffer */
-  int          bytes;                  /* Bytes read */
+  ssize_t      bytes;                  /* Bytes read */
   int          templen;                /* Data length from message */
   int          nfds;                   /* Number of file descriptors */
 #ifdef HAVE_POLL
@@ -150,8 +128,8 @@ cupsSideChannelRead(
   pfd.fd     = CUPS_SC_FD;
   pfd.events = POLLIN;
 
-  while ((nfds = poll(&pfd, 1, 
-                     timeout < 0.0 ? -1 : (long)(timeout * 1000))) < 0 &&
+  while ((nfds = poll(&pfd, 1,
+                     timeout < 0.0 ? -1 : (int)(timeout * 1000))) < 0 &&
         (errno == EINTR || errno == EAGAIN))
     ;
 
@@ -162,14 +140,14 @@ cupsSideChannelRead(
   stimeout.tv_sec  = (int)timeout;
   stimeout.tv_usec = (int)(timeout * 1000000) % 1000000;
 
-  while ((nfds = select(CUPS_SC_FD + 1, &input_set, NULL, NULL, 
+  while ((nfds = select(CUPS_SC_FD + 1, &input_set, NULL, NULL,
                        timeout < 0.0 ? NULL : &stimeout)) < 0 &&
         (errno == EINTR || errno == EAGAIN))
     ;
 
 #endif /* HAVE_POLL */
 
-  if  (nfds < 1)
+  if (nfds < 1)
   {
     *command = CUPS_SC_CMD_NONE;
     *status  = nfds==0 ? CUPS_SC_STATUS_TIMEOUT : CUPS_SC_STATUS_IO_ERROR;
@@ -214,7 +192,7 @@ cupsSideChannelRead(
 
   if (bytes < 4)
   {
-    DEBUG_printf(("1cupsSideChannelRead: Short read of %d bytes", bytes));
+    DEBUG_printf(("1cupsSideChannelRead: Short read of " CUPS_LLFMT " bytes", CUPS_LLCAST bytes));
 
     _cupsBufferRelease(buffer);
 
@@ -277,7 +255,7 @@ cupsSideChannelRead(
     *status  = (cups_sc_status_t)buffer[1];
     *datalen = templen;
 
-    memcpy(data, buffer + 4, templen);
+    memcpy(data, buffer + 4, (size_t)templen);
   }
 
   _cupsBufferRelease(buffer);
@@ -308,7 +286,7 @@ cupsSideChannelRead(
  * support SNMP queries.  @code CUPS_SC_STATUS_NO_RESPONSE@ is returned when
  * the printer does not respond to the SNMP query.
  *
- * @since CUPS 1.4/Mac OS X 10.6@ 
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 cups_sc_status_t                       /* O  - Query status */
@@ -368,7 +346,7 @@ cupsSideChannelSNMPGet(
     * Parse the response of the form "oid\0value"...
     */
 
-    real_oidlen  = strlen(real_data) + 1;
+    real_oidlen  = (int)strlen(real_data) + 1;
     real_datalen -= real_oidlen;
 
     if ((real_datalen + 1) > *datalen)
@@ -377,7 +355,7 @@ cupsSideChannelSNMPGet(
       return (CUPS_SC_STATUS_TOO_BIG);
     }
 
-    memcpy(data, real_data + real_oidlen, real_datalen);
+    memcpy(data, real_data + real_oidlen, (size_t)real_datalen);
     data[real_datalen] = '\0';
 
     *datalen = real_datalen;
@@ -414,7 +392,7 @@ cupsSideChannelSNMPGet(
  * support SNMP queries.  @code CUPS_SC_STATUS_NO_RESPONSE@ is returned when
  * the printer does not respond to the first SNMP query.
  *
- * @since CUPS 1.4/Mac OS X 10.6@ 
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 cups_sc_status_t                       /* O - Status of first query of @code CUPS_SC_STATUS_OK@ on success */
@@ -427,8 +405,8 @@ cupsSideChannelSNMPWalk(
   cups_sc_status_t     status;         /* Status of command */
   cups_sc_command_t    rcommand;       /* Response command */
   char                 *real_data;     /* Real data buffer for response */
-  int                  real_datalen,   /* Real length of data buffer */
-                       real_oidlen,    /* Length of returned OID string */
+  int                  real_datalen;   /* Real length of data buffer */
+  size_t               real_oidlen,    /* Length of returned OID string */
                        oidlen;         /* Length of first OID */
   const char           *current_oid;   /* Current OID */
   char                 last_oid[2048]; /* Last OID */
@@ -452,7 +430,7 @@ cupsSideChannelSNMPWalk(
   */
 
   current_oid = oid;
-  oidlen      = (int)strlen(oid);
+  oidlen      = strlen(oid);
   last_oid[0] = '\0';
 
   do
@@ -499,17 +477,17 @@ cupsSideChannelSNMPWalk(
         return (CUPS_SC_STATUS_OK);
       }
 
-      if (real_datalen < sizeof(real_data))
+      if ((size_t)real_datalen < sizeof(real_data))
         real_data[real_datalen] = '\0';
 
       real_oidlen  = strlen(real_data) + 1;
-      real_datalen -= real_oidlen;
+      real_datalen -= (int)real_oidlen;
 
      /*
       * Call the callback with the OID and data...
       */
 
-      (*cb)(real_data, real_data + real_oidlen, real_datalen, context); 
+      (*cb)(real_data, real_data + real_oidlen, real_datalen, context);
 
      /*
       * Update the current OID...
@@ -533,7 +511,7 @@ cupsSideChannelSNMPWalk(
  * This function is normally only called by backend programs to send
  * responses to a filter, driver, or port monitor program.
  *
- * @since CUPS 1.3/Mac OS X 10.5@
+ * @since CUPS 1.3/macOS 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on error */
@@ -545,7 +523,7 @@ cupsSideChannelWrite(
     double            timeout)         /* I - Timeout in seconds */
 {
   char         *buffer;                /* Message buffer */
-  int          bytes;                  /* Bytes written */
+  ssize_t      bytes;                  /* Bytes written */
 #ifdef HAVE_POLL
   struct pollfd        pfd;                    /* Poll structure for poll() */
 #else /* select() */
@@ -575,7 +553,7 @@ cupsSideChannelWrite(
     if (poll(&pfd, 1, -1) < 1)
       return (-1);
   }
-  else if (poll(&pfd, 1, (long)(timeout * 1000)) < 1)
+  else if (poll(&pfd, 1, (int)(timeout * 1000)) < 1)
     return (-1);
 
 #else /* select() */
@@ -608,23 +586,23 @@ cupsSideChannelWrite(
   * 4-N      Data
   */
 
-  if ((buffer = _cupsBufferGet(datalen + 4)) == NULL)
+  if ((buffer = _cupsBufferGet((size_t)datalen + 4)) == NULL)
     return (-1);
 
   buffer[0] = command;
   buffer[1] = status;
-  buffer[2] = datalen >> 8;
-  buffer[3] = datalen & 255;
+  buffer[2] = (char)(datalen >> 8);
+  buffer[3] = (char)(datalen & 255);
 
   bytes = 4;
 
   if (datalen > 0)
   {
-    memcpy(buffer + 4, data, datalen);
+    memcpy(buffer + 4, data, (size_t)datalen);
     bytes += datalen;
   }
 
-  while (write(CUPS_SC_FD, buffer, bytes) < 0)
+  while (write(CUPS_SC_FD, buffer, (size_t)bytes) < 0)
     if (errno != EINTR && errno != EAGAIN)
     {
       _cupsBufferRelease(buffer);
@@ -635,8 +613,3 @@ cupsSideChannelWrite(
 
   return (0);
 }
-
-
-/*
- * End of "$Id: sidechannel.c 7720 2008-07-11 22:46:21Z mike $".
- */