]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/sidechannel.c
Merge changes from CUPS 1.4svn-r8639.
[thirdparty/cups.git] / cups / sidechannel.c
index 0b79f8b0132242f369d4825e63502c0a958d396d..0f51fd1bd24ee1efac096495224fb2c844a5f6b4 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Side-channel API code for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 2007-2009 by Apple Inc.
  *   Copyright 2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
 #include "sidechannel.h"
 #include "string.h"
 #include "debug.h"
-#include <unistd.h>
+#ifdef WIN32
+#  include <io.h>
+#else
+#  include <unistd.h>
+#endif /* WIN32 */
 #include <errno.h>
 #ifdef __hpux
 #  include <sys/time.h>
-#else
+#elif !defined(WIN32)
 #  include <sys/select.h>
 #endif /* __hpux */
 #ifndef WIN32
@@ -59,7 +63,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@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 cups_sc_status_t                       /* O  - Status of command */
@@ -98,7 +102,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@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on error */
@@ -121,7 +125,7 @@ cupsSideChannelRead(
 
 
   DEBUG_printf(("cupsSideChannelRead(command=%p, status=%p, data=%p, "
-                "datalen=%p(%d), timeout=%.3f)\n", command, status, data,
+                "datalen=%p(%d), timeout=%.3f)", command, status, data,
                datalen, datalen ? *datalen : -1, timeout));
 
  /*
@@ -155,7 +159,7 @@ cupsSideChannelRead(
   {
     if (select(CUPS_SC_FD + 1, &input_set, NULL, NULL, NULL) < 1)
     {
-      DEBUG_printf(("cupsSideChannelRead: Select error: %s\n", strerror(errno)));
+      DEBUG_printf(("1cupsSideChannelRead: Select error: %s", strerror(errno)));
       return (-1);
     }
   }
@@ -166,7 +170,7 @@ cupsSideChannelRead(
 
     if (select(CUPS_SC_FD + 1, &input_set, NULL, NULL, &stimeout) < 1)
     {
-      DEBUG_puts("cupsSideChannelRead: Select timeout");
+      DEBUG_puts("1cupsSideChannelRead: Select timeout");
       return (-1);
     }
   }
@@ -186,7 +190,7 @@ cupsSideChannelRead(
   while ((bytes = read(CUPS_SC_FD, buffer, sizeof(buffer))) < 0)
     if (errno != EINTR && errno != EAGAIN)
     {
-      DEBUG_printf(("cupsSideChannelRead: Read error: %s\n", strerror(errno)));
+      DEBUG_printf(("1cupsSideChannelRead: Read error: %s", strerror(errno)));
       return (-1);
     }
 
@@ -197,7 +201,7 @@ cupsSideChannelRead(
   if (buffer[0] < CUPS_SC_CMD_SOFT_RESET ||
       buffer[0] > CUPS_SC_CMD_SNMP_GET_NEXT)
   {
-    DEBUG_printf(("cupsSideChannelRead: Bad command %d!\n", buffer[0]));
+    DEBUG_printf(("1cupsSideChannelRead: Bad command %d!", buffer[0]));
     return (-1);
   }
 
@@ -240,7 +244,7 @@ cupsSideChannelRead(
     memcpy(data, buffer + 4, templen);
   }
 
-  DEBUG_printf(("cupsSideChannelRead: Returning status=%d\n", *status));
+  DEBUG_printf(("1cupsSideChannelRead: Returning status=%d", *status));
 
   return (0);
 }
@@ -266,7 +270,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@ 
+ * @since CUPS 1.4/Mac OS X 10.6
  */
 
 cups_sc_status_t                       /* O  - Query status */
@@ -284,7 +288,7 @@ cupsSideChannelSNMPGet(
 
 
   DEBUG_printf(("cupsSideChannelSNMPGet(oid=\"%s\", data=%p, datalen=%p(%d), "
-                "timeout=%.3f)\n", oid, data, datalen, datalen ? *datalen : -1,
+                "timeout=%.3f)", oid, data, datalen, datalen ? *datalen : -1,
                timeout));
 
  /*
@@ -301,7 +305,7 @@ cupsSideChannelSNMPGet(
   */
 
   if (cupsSideChannelWrite(CUPS_SC_CMD_SNMP_GET, CUPS_SC_STATUS_NONE, oid,
-                           (int)strlen(oid), timeout))
+                           (int)strlen(oid) + 1, timeout))
     return (CUPS_SC_STATUS_TIMEOUT);
 
   real_datalen = sizeof(real_data);
@@ -358,7 +362,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@ 
+ * @since CUPS 1.4/Mac OS X 10.6
  */
 
 cups_sc_status_t                       /* O - Status of first query of @code CUPS_SC_STATUS_OK@ on success */
@@ -378,7 +382,7 @@ cupsSideChannelSNMPWalk(
 
 
   DEBUG_printf(("cupsSideChannelSNMPWalk(oid=\"%s\", timeout=%.3f, cb=%p, "
-                "context=%p)\n", oid, timeout, cb, context));
+                "context=%p)", oid, timeout, cb, context));
 
  /*
   * Range check input...
@@ -401,7 +405,7 @@ cupsSideChannelSNMPWalk(
     */
 
     if (cupsSideChannelWrite(CUPS_SC_CMD_SNMP_GET_NEXT, CUPS_SC_STATUS_NONE,
-                             current_oid, (int)strlen(current_oid), timeout))
+                             current_oid, (int)strlen(current_oid) + 1, timeout))
       return (CUPS_SC_STATUS_TIMEOUT);
 
     real_datalen = sizeof(real_data);
@@ -427,6 +431,9 @@ cupsSideChannelSNMPWalk(
         return (CUPS_SC_STATUS_OK);
       }
 
+      if (real_datalen < sizeof(real_data))
+        real_data[real_datalen] = '\0';
+
       real_oidlen  = strlen(real_data) + 1;
       real_datalen -= real_oidlen;
 
@@ -455,7 +462,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@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on error */