[Utopia] hal patch to cups
- From: Jeffrey Stedfast <fejj novell com>
- To: utopia-list gnome org
- Subject: [Utopia] hal patch to cups
- Date: Mon, 11 Jul 2005 15:01:18 -0400
I've updated and attached Joe Shaw's patch from about a year ago to work
with recent dbus/HAL versions.
Afaict, no one is actually using Joe's original patch in their packages,
is there any reason for this? (Seeing as how J5 did followup to Joe's
original patch with some fixes for it, we assumed Red Hat was using it
in their packages but I've found no evidence of this at all?). Is it
just because it doesn't work with current HAL? :)
--
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
fejj ximian com - www.novell.com
diff -urN cups-1.1.23.orig/backend/hal.c cups-1.1.23/backend/hal.c
--- cups-1.1.23.orig/backend/hal.c 1969-12-31 19:00:00.000000000 -0500
+++ cups-1.1.23/backend/hal.c 2005-07-08 15:42:53.000000000 -0400
@@ -0,0 +1,391 @@
+/*
+ * "$Id: usb.c,v 1.49 2003/09/02 20:19:17 mike Exp $"
+ *
+ * HAL backend for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright 1997-2003 by Easy Software Products, all rights reserved.
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * 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" 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-3111 USA
+ *
+ * Voice: (301) 373-9603
+ * EMail: cups-info cups org
+ * WWW: http://www.cups.org
+ *
+ * This file is subject to the Apple OS-Developed Software exception.
+ *
+ * Contents:
+ *
+ * main() - Send a file to the specified HAL device.
+ * list_devices() - List all HAL printer devices.
+ */
+
+/*
+ * Include necessary headers.
+ */
+
+#include <cups/cups.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <cups/string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+
+#include <libhal.h>
+
+
+static LibHalContext *
+get_hal_ctx (void)
+{
+ DBusConnection *connection;
+ LibHalContext *hal_ctx;
+ DBusError error;
+
+ if (!(hal_ctx = libhal_ctx_new ())) {
+ fprintf (stderr, "ERROR: Unable to create HAL context\n");
+ return NULL;
+ }
+
+ dbus_error_init (&error);
+ if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
+ fprintf (stderr, "ERROR: Unable to connect to DBUS: %s\n", error.message);
+ libhal_ctx_free (hal_ctx);
+ dbus_error_free (&error);
+ return NULL;
+ }
+
+ libhal_ctx_set_dbus_connection (hal_ctx, connection);
+
+ if (!libhal_ctx_init (hal_ctx, &error)) {
+ fprintf (stderr, "ERROR: Unable to init HAL context: %s\n", error.message);
+ libhal_ctx_free (hal_ctx);
+ dbus_error_free (&error);
+ return NULL;
+ }
+
+ return hal_ctx;
+}
+
+
+/*
+ * 'list_devices()' - List all HAL printer devices.
+ */
+
+static void
+list_devices (void)
+{
+ LibHalContext *hal_ctx;
+ char **printers;
+ int i, n;
+
+ if (!(hal_ctx = get_hal_ctx ()))
+ return;
+
+ printers = libhal_find_device_by_capability (hal_ctx, "printer", &n, NULL);
+
+ if (n == 0)
+ printf("direct hal \"Unknown\" \"Hal printing backend\"\n");
+
+ for (i = 0; i < n; i++) {
+ char *vendor, *product, *description;
+ char make_model[1024];
+
+ /* We only want printers that have device nodes */
+ if (!libhal_device_property_exists (hal_ctx, printers[i], "printer.device", NULL))
+ continue;
+
+ vendor = libhal_device_get_property_string (hal_ctx, printers[i], "printer.vendor", NULL);
+ product = libhal_device_get_property_string (hal_ctx, printers[i], "printer.product", NULL);
+ description = libhal_device_get_property_string (hal_ctx, printers[i], "printer.description", NULL);
+
+ /* Try our hardest to get a good name */
+ if (product != NULL) {
+ if (vendor != NULL) {
+ snprintf (make_model, sizeof (make_model), "%s %s", vendor, product);
+ } else {
+ strncpy (make_model, product, sizeof (make_model));
+ }
+ } else if (description != NULL) {
+ strncpy (make_model, description, sizeof (make_model));
+ } else if (vendor != NULL) {
+ snprintf (make_model, sizeof (make_model), "%s printer", vendor);
+ } else {
+ strncpy (make_model, "Unknown", sizeof (make_model));
+ }
+
+ printf ("direct hal://%s \"%s\" \"%s\"\n", printers[i], make_model,
+ description != NULL ? description : make_model);
+
+ libhal_free_string (vendor);
+ libhal_free_string (product);
+ libhal_free_string (description);
+ }
+
+ libhal_ctx_shutdown (hal_ctx, NULL);
+ libhal_ctx_free (hal_ctx);
+}
+
+/*
+ * 'get_device_file()' - Get a device file from a HAL device UDI
+ */
+static char *
+get_device_file (const char *uri)
+{
+ LibHalContext *hal_ctx;
+ const char *udi;
+ char *device;
+
+ if (strncmp (uri, "hal://", 6) != 0)
+ return NULL;
+
+ if (!(hal_ctx = get_hal_ctx ()))
+ return NULL;
+
+ udi = uri + 6;
+
+ device = libhal_device_get_property_string (hal_ctx, udi, "printer.device", NULL);
+
+ libhal_ctx_shutdown (hal_ctx, NULL);
+ libhal_ctx_free (hal_ctx);
+
+ return device;
+}
+
+/*
+ * 'main()' - Send a file to the specified HAL printer device.
+ *
+ * Usage:
+ *
+ * printer-uri job-id user title copies options [file]
+ */
+
+int
+main (int argc, char *argv[])
+{
+ int fp; /* Print file */
+ int copies; /* Number of copies to print */
+ char *device; /* Device file to open */
+ int fd; /* Device file descriptor */
+ int wbytes; /* Number of bytes written */
+ size_t nbytes; /* Number of bytes read */
+ size_t tbytes; /* Total number of bytes written */
+ char buffer[8192]; /* Output buffer */
+ char *bufptr; /* Pointer into buffer */
+ struct termios opts; /* Parallel port options */
+#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
+ struct sigaction action; /* Actions for POSIX signals */
+#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
+#if defined(__linux) && defined(LP_POUTPA)
+ unsigned char status; /* Port status (off-line, out-of-paper, etc.) */
+#endif /* __linux */
+
+
+ /*
+ * Make sure status messages are not buffered...
+ */
+
+ setbuf (stderr, NULL);
+
+ /*
+ * Ignore SIGPIPE signals...
+ */
+
+#ifdef HAVE_SIGSET
+ sigset (SIGPIPE, SIG_IGN);
+#elif defined(HAVE_SIGACTION)
+ memset (&action, 0, sizeof (action));
+ action.sa_handler = SIG_IGN;
+ sigaction (SIGPIPE, &action, NULL);
+#else
+ signal (SIGPIPE, SIG_IGN);
+#endif /* HAVE_SIGSET */
+
+ /*
+ * Check command-line...
+ */
+
+ if (argc == 1) {
+ list_devices ();
+ return 0;
+ } else if (argc < 6 || argc > 7) {
+ fputs ("Usage: URI job-id user title copies options [file]\n", stderr);
+ return 1;
+ }
+
+ /*
+ * If we have 7 arguments, print the file named on the command-line.
+ * Otherwise, send stdin instead...
+ */
+
+ if (argc == 6) {
+ fp = 0;
+ copies = 1;
+ } else {
+ /*
+ * Try to open the print file...
+ */
+
+ if ((fp = open (argv[6], O_RDONLY)) == -1) {
+ perror ("ERROR: unable to open print file");
+ return 1;
+ }
+
+ copies = atoi (argv[4]);
+ }
+
+ if (!(device = get_device_file (argv[0]))) {
+ fprintf (stderr, "ERROR: Unable to open HAL device \"%s\"\n", argv[0]);
+ return 1;
+ }
+
+ /*
+ * Open the port device...
+ */
+
+ do {
+ if ((fd = open (device, O_RDWR | O_EXCL)) == -1) {
+ if (errno == EBUSY) {
+ fputs ("INFO: Device busy; will retry in 30 seconds...\n", stderr);
+ sleep (30);
+ } else if (errno == ENXIO || errno == EIO || errno == ENOENT) {
+ fputs ("INFO: Printer not connected; will retry in 30 seconds...\n", stderr);
+ sleep (30);
+ } else {
+ fprintf (stderr, "ERROR: Unable to open device \"%s\": %s\n",
+ argv[0], strerror (errno));
+ return 1;
+ }
+ }
+ } while (fd == -1);
+
+ libhal_free_string (device);
+
+ /*
+ * Set any options provided...
+ */
+
+ tcgetattr (fd, &opts);
+
+ opts.c_lflag &= ~(ICANON | ECHO | ISIG); /* Raw mode */
+
+ /**** No options supported yet ****/
+
+ tcsetattr (fd, TCSANOW, &opts);
+
+ /*
+ * Now that we are "connected" to the port, ignore SIGTERM so that we
+ * can finish out any page data the driver sends (e.g. to eject the
+ * current page... Only ignore SIGTERM if we are printing data from
+ * stdin (otherwise you can't cancel raw jobs...)
+ */
+
+ if (argc < 7) {
+#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
+ sigset (SIGTERM, SIG_IGN);
+#elif defined(HAVE_SIGACTION)
+ memset (&action, 0, sizeof (action));
+
+ sigemptyset (&action.sa_mask);
+ action.sa_handler = SIG_IGN;
+ sigaction (SIGTERM, &action, NULL);
+#else
+ signal (SIGTERM, SIG_IGN);
+#endif /* HAVE_SIGSET */
+ }
+
+#if defined(__linux) && defined(LP_POUTPA)
+ /*
+ * Show the printer status before we send the file; normally, we'd
+ * do this while we write data to the printer, however at least some
+ * Linux kernels have buggy USB drivers which don't like to be
+ * queried while sending data to the printer...
+ *
+ * Also, we're using the 8255 constants instead of the ones that are
+ * supposed to be used, as it appears that the USB driver also doesn't
+ * follow standards...
+ */
+
+ if (ioctl (fd, LPGETSTATUS, &status) == 0) {
+ fprintf (stderr, "DEBUG: LPGETSTATUS returned a port status of %02X...\n", status);
+
+ if (!(status & LP_POUTPA))
+ fputs ("WARNING: Media tray empty!\n", stderr);
+ else if (!(status & LP_PERRORP))
+ fputs ("WARNING: Printer fault!\n", stderr);
+ else if (!(status & LP_PSELECD))
+ fputs ("WARNING: Printer off-line.\n", stderr);
+ }
+#endif /* __linux && LP_POUTPA */
+
+ /*
+ * Finally, send the print file...
+ */
+
+ while (copies > 0) {
+ copies--;
+
+ if (fp != 0) {
+ fputs ("PAGE: 1 1\n", stderr);
+ lseek (fp, 0, SEEK_SET);
+ }
+
+ tbytes = 0;
+ while ((nbytes = read (fp, buffer, sizeof (buffer))) > 0) {
+ /*
+ * Write the print data to the printer...
+ */
+
+ tbytes += nbytes;
+ bufptr = buffer;
+
+ while (nbytes > 0) {
+ if ((wbytes = write (fd, bufptr, nbytes)) == -1)
+ if (errno == ENOTTY)
+ wbytes = write (fd, bufptr, nbytes);
+
+ if (wbytes == -1) {
+ perror ("ERROR: Unable to send print file to printer");
+ break;
+ }
+
+ nbytes -= wbytes;
+ bufptr += wbytes;
+ }
+
+ if (wbytes == -1)
+ break;
+
+ if (argc > 6)
+ fprintf (stderr, "INFO: Sending print file, %lu bytes...\n", (unsigned long) tbytes);
+ }
+ }
+
+ /*
+ * Close the socket connection and input file and return...
+ */
+
+ close (fd);
+ if (fp != 0)
+ close (fp);
+
+ fputs ("INFO: Ready to print.\n", stderr);
+
+ return 0;
+}
+
+/*
+ * End of "$Id: usb.c,v 1.49 2003/09/02 20:19:17 mike Exp $".
+ */
diff -urN cups-1.1.23.orig/backend/Makefile cups-1.1.23/backend/Makefile
--- cups-1.1.23.orig/backend/Makefile 2005-01-03 14:29:44.000000000 -0500
+++ cups-1.1.23/backend/Makefile 2005-07-08 15:42:45.000000000 -0400
@@ -26,9 +26,9 @@
include ../Makedefs
-BACKENDS = ipp lpd parallel scsi serial socket usb
+BACKENDS = ipp lpd parallel scsi serial socket usb hal
TARGETS = betest $(BACKENDS)
-OBJS = betest.o ipp.o lpd.o parallel.o scsi.o serial.o socket.o usb.o
+OBJS = betest.o ipp.o lpd.o parallel.o scsi.o serial.o socket.o usb.o hal.o
#
@@ -145,6 +145,15 @@
#
+# hal
+#
+
+hal: hal.o ../cups/$(LIBCUPS)
+ echo Linking $
+ $(CC) $(LDFLAGS) -o hal hal.o $(BACKLIBS) $(LIBS) -Wl,-Bstatic $(HALLIBS) -Wl,-Bdynamic
+
+
+#
# Dependencies...
#
diff -urN cups-1.1.23.orig/config-scripts/cups-hal.m4 cups-1.1.23/config-scripts/cups-hal.m4
--- cups-1.1.23.orig/config-scripts/cups-hal.m4 1969-12-31 19:00:00.000000000 -0500
+++ cups-1.1.23/config-scripts/cups-hal.m4 2005-07-08 15:42:45.000000000 -0400
@@ -0,0 +1,82 @@
+dnl
+dnl "$Id: cups-openssl.m4,v 1.14 2003/09/17 19:35:22 mike Exp $"
+dnl
+dnl HAL config stuff; pkg-config stuff lifted from pkg.m4
+dnl
+dnl Copyright (C) 2004 Novell, Inc.
+dnl
+
+dnl pkg-config stuff
+
+dnl PKG_CHECK_MODULES(GSTUFF, gtk-2.0 >= 1.3 glib = 1.3.4, action-if, action-not)
+dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
+dnl also defines GSTUFF_PKG_ERRORS on error
+AC_DEFUN([PKG_CHECK_MODULES], [
+ succeeded=no
+
+ if test -z "$PKG_CONFIG"; then
+ AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+ fi
+
+ if test "$PKG_CONFIG" = "no" ; then
+ echo "*** The pkg-config script could not be found. Make sure it is"
+ echo "*** in your path, or set the PKG_CONFIG environment variable"
+ echo "*** to the full path to pkg-config."
+ echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
+ else
+ PKG_CONFIG_MIN_VERSION=0.9.0
+ if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
+ AC_MSG_CHECKING(for $2)
+
+ if $PKG_CONFIG --exists "$2" ; then
+ AC_MSG_RESULT(yes)
+ succeeded=yes
+
+ AC_MSG_CHECKING($1_CFLAGS)
+ $1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
+ AC_MSG_RESULT($$1_CFLAGS)
+
+ AC_MSG_CHECKING($1_LIBS)
+ $1_LIBS=`$PKG_CONFIG --libs "$2"`
+ AC_MSG_RESULT($$1_LIBS)
+ else
+ $1_CFLAGS=""
+ $1_LIBS=""
+ ## If we have a custom action on failure, don't print errors, but
+ ## do set a variable so people can do so.
+ $1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
+ ifelse([$4], ,echo $$1_PKG_ERRORS,)
+ fi
+
+ AC_SUBST($1_CFLAGS)
+ AC_SUBST($1_LIBS)
+ else
+ echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
+ echo "*** See http://www.freedesktop.org/software/pkgconfig";
+ fi
+ fi
+
+ if test $succeeded = yes; then
+ ifelse([$3], , :, [$3])
+ else
+ ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4])
+ fi
+])
+
+dnl hal stuff
+
+AC_ARG_ENABLE(hal, [ --enable-hal build the HAL backend],enable_hal=$enableval,enable_hal=no)
+
+if test x$enable_hal = xyes; then
+ PKG_CHECK_MODULES(HAL, hal)
+else
+ HAL_CFLAGS=""
+ HAL_LIBS=""
+fi
+
+AC_SUBST(HAL_CFLAGS)
+AC_SUBST(HAL_LIBS)
+
+dnl
+dnl End of "$Id: cups-openssl.m4,v 1.14 2003/09/17 19:35:22 mike Exp $".
+dnl
diff -urN cups-1.1.23.orig/configure.in cups-1.1.23/configure.in
--- cups-1.1.23.orig/configure.in 2005-01-03 14:29:44.000000000 -0500
+++ cups-1.1.23/configure.in 2005-07-08 15:42:45.000000000 -0400
@@ -38,6 +38,7 @@
sinclude(config-scripts/cups-openslp.m4)
sinclude(config-scripts/cups-openssl.m4)
sinclude(config-scripts/cups-pam.m4)
+sinclude(config-scripts/cups-hal.m4)
sinclude(config-scripts/cups-scripting.m4)
diff -urN cups-1.1.23.orig/Makedefs.in cups-1.1.23/Makedefs.in
--- cups-1.1.23.orig/Makedefs.in 2005-01-03 14:29:44.000000000 -0500
+++ cups-1.1.23/Makedefs.in 2005-07-08 15:42:45.000000000 -0400
@@ -85,7 +85,7 @@
ARFLAGS = @ARFLAGS@
BACKLIBS = @BACKLIBS@
-CFLAGS = $(RC_CFLAGS) $(SSLFLAGS) @CPPFLAGS@ @CFLAGS@ -I.. $(OPTIONS)
+CFLAGS = $(RC_CFLAGS) $(SSLFLAGS) $(HALFLAGS) @CPPFLAGS@ @CFLAGS@ -I.. $(OPTIONS)
COMMONLIBS = @COMMONLIBS@
CXXFLAGS = $(RC_CFLAGS) @CPPFLAGS@ @CXXFLAGS@ -I.. $(OPTIONS)
CXXLIBS = @CXXLIBS@
@@ -102,6 +102,8 @@
PAMLIBS = @PAMLIBS@
SSLFLAGS = @SSLFLAGS@
SSLLIBS = @SSLLIBS@
+HALFLAGS = @HAL_CFLAGS@
+HALLIBS = @HAL_LIBS@
#
# Directories...
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]