/*
* "$Id$"
*
- * Backend test program for the Common UNIX Printing System (CUPS).
+ * Backend test program for CUPS.
*
- * Copyright 2007-2009 by Apple Inc.
- * Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2005 by Easy Software Products, all rights reserved.
*
- * 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"
- * "LICENSE" which should have been included with this file. If this
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * 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"
+ * "LICENSE" which should have been included with this file. If this
+ * 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:
- *
- * main() - Run the named backend.
- * sigterm_handler() - Flag when we get SIGTERM.
- * usage() - Show usage information.
- * walk_cb() - Show results of cupsSideChannelSNMPWalk...
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
* Include necessary headers.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
+#include <cups/string-private.h>
#include <cups/cups.h>
#include <cups/sidechannel.h>
#include <unistd.h>
#include <fcntl.h>
-#include <errno.h>
#include <sys/wait.h>
#include <signal.h>
*/
static void sigterm_handler(int sig);
-static void usage(void);
+static void usage(void) __attribute__((noreturn));
static void walk_cb(const char *oid, const char *data, int datalen,
void *context);
*
* Usage:
*
- * betest [-s] [-t] device-uri job-id user title copies options [file]
+ * testbackend [-s] [-t] device-uri job-id user title copies options [file]
*/
int /* O - Exit status */
const char *oid = ".1.3.6.1.2.1.43.10.2.1.4.1.1";
/* OID to lookup or walk */
char scheme[255], /* Scheme in URI == backend */
- backend[1024]; /* Backend path */
+ backend[1024], /* Backend path */
+ libpath[1024], /* Path for libcups */
+ *ptr; /* Pointer into path */
const char *serverbin; /* CUPS_SERVERBIN environment variable */
int fd, /* Temporary file descriptor */
back_fds[2], /* Back-channel pipe */
status; /* Exit status */
+ /*
+ * Get the current directory and point the run-time linker at the "cups"
+ * subdirectory...
+ */
+
+ if (getcwd(libpath, sizeof(libpath)) &&
+ (ptr = strrchr(libpath, '/')) != NULL && !strcmp(ptr, "/backend"))
+ {
+ strlcpy(ptr, "/cups", sizeof(libpath) - (size_t)(ptr - libpath));
+ if (!access(libpath, 0))
+ {
+#ifdef __APPLE__
+ fprintf(stderr, "Setting DYLD_LIBRARY_PATH to \"%s\".\n", libpath);
+ setenv("DYLD_LIBRARY_PATH", libpath, 1);
+#else
+ fprintf(stderr, "Setting LD_LIBRARY_PATH to \"%s\".\n", libpath);
+ setenv("LD_LIBRARY_PATH", libpath, 1);
+#endif /* __APPLE__ */
+ }
+ else
+ perror(libpath);
+ }
+
/*
* See if we have side-channel tests to do...
*/
*/
if ((bytes = cupsBackChannelRead(buffer, sizeof(buffer), 0)) > 0)
- write(2, buffer, bytes);
+ write(2, buffer, (size_t)bytes);
/*
* Throttle output to ~100hz...
*/
while ((bytes = cupsBackChannelRead(buffer, sizeof(buffer), 5.0)) > 0)
- write(2, buffer, bytes);
+ write(2, buffer, (size_t)bytes);
exit(0);
}
while ((bytes = cupsBackChannelRead(buffer, sizeof(buffer),
timeout)) > 0)
{
- write(2, buffer, bytes);
+ write(2, buffer, (size_t)bytes);
timeout = 5.0;
}
write(2, "\nDEBUG: END\n", 12);
length = sizeof(buffer);
scstatus = cupsSideChannelSNMPGet(oid, buffer, &length, 5.0);
- printf("CUPS_SC_CMD_SNMP_GET %s returned %s, %s\n", oid,
- statuses[scstatus], buffer);
+ printf("CUPS_SC_CMD_SNMP_GET %s returned %s, %d bytes (%s)\n", oid,
+ statuses[scstatus], (int)length, buffer);
length = sizeof(buffer);
scstatus = cupsSideChannelSNMPGet(oid, buffer, &length, 5.0);
- printf("CUPS_SC_CMD_SNMP_GET %s returned %s, %s\n", oid,
- statuses[scstatus], buffer);
+ printf("CUPS_SC_CMD_SNMP_GET %s returned %s, %d bytes (%s)\n", oid,
+ statuses[scstatus], (int)length, buffer);
}
length = 0;
kill(data_pid, SIGTERM);
kill(back_pid, SIGTERM);
}
-
+
while ((pid = wait(&status)) > 0)
{
if (status)
static void
usage(void)
{
- puts("Usage: testbackend [-cancel] [-d] [-ps | -pcl] [-s [-oid OID] "
+ puts("Usage: testbackend [-cancel] [-d] [-ps | -pcl] [-s [-get OID] "
"[-walk OID]] [-t] device-uri job-id user title copies options [file]");
puts("");
puts("Options:");
puts(" -cancel Simulate a canceled print job after 2 seconds.");
puts(" -d Show log messages from backend.");
- puts(" -oid OID Lookup the specified SNMP OID.");
+ puts(" -get OID Lookup the specified SNMP OID.");
puts(" (.1.3.6.1.2.1.43.10.2.1.4.1.1 is a good one for printers)");
puts(" -pcl Send PCL+PJL query and test page to backend.");
puts(" -ps Send PostScript query and test page to backend.");
int datalen, /* I - Length of data */
void *context) /* I - Context (unused) */
{
- printf("CUPS_SC_CMD_SNMP_WALK %s=%s (%d bytes)\n", oid, data, datalen);
+ char temp[80];
+
+ (void)context;
+
+ if ((size_t)datalen > (sizeof(temp) - 1))
+ {
+ memcpy(temp, data, sizeof(temp) - 1);
+ temp[sizeof(temp) - 1] = '\0';
+ }
+ else
+ {
+ memcpy(temp, data, (size_t)datalen);
+ temp[datalen] = '\0';
+ }
+
+ printf("CUPS_SC_CMD_SNMP_WALK %s, %d bytes (%s)\n", oid, datalen, temp);
}