Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 285166 | Differences between
and this patch

Collapse All | Expand All

(-)cups-1.4.4.orig/backend/Makefile (-1 / +1 lines)
Lines 267-273 usb: usb.o ../cups/$(LIBCUPS) libbackend Link Here
267
	echo Linking $@...
267
	echo Linking $@...
268
	$(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \
268
	$(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \
269
		$(BACKLIBS) $(LIBS)
269
		$(BACKLIBS) $(LIBS)
270
usb.o:	usb.c usb-darwin.c usb-libusb.c usb-unix.c
270
usb.o:	usb.c usb-darwin.c usb-hybrid.c usb-libusb.c usb-unix.c
271
271
272
272
273
#
273
#
(-)cups-1.4.4.orig/backend/ieee1284.c (-2 / +13 lines)
Lines 255-260 backendGetDeviceID( Link Here
255
    cups_option_t	*values;	/* Keys and values in device ID */
255
    cups_option_t	*values;	/* Keys and values in device ID */
256
    const char		*mfg,		/* Manufacturer */
256
    const char		*mfg,		/* Manufacturer */
257
			*mdl,		/* Model */
257
			*mdl,		/* Model */
258
			*des,		/* Description */
258
			*sern;		/* Serial number */
259
			*sern;		/* Serial number */
259
    char		temp[256],	/* Temporary manufacturer string */
260
    char		temp[256],	/* Temporary manufacturer string */
260
			*tempptr;	/* Pointer into temp string */
261
			*tempptr;	/* Pointer into temp string */
Lines 285-294 backendGetDeviceID( Link Here
285
    }
286
    }
286
    else
287
    else
287
    {
288
    {
288
      strlcpy(temp, make_model, sizeof(temp));
289
      /*
290
       * No manufacturer?  Use the model string or description...
291
       */
292
293
      if (mdl)
294
	_ppdNormalizeMakeAndModel(mdl, temp, sizeof(temp));
295
      else if ((des = cupsGetOption("DESCRIPTION", num_values, values)) != NULL ||
296
	       (des = cupsGetOption("DES", num_values, values)) != NULL)
297
	_ppdNormalizeMakeAndModel(des, temp, sizeof(temp));
298
      else
299
	strlcpy(temp, "Unknown", sizeof(temp));
289
300
290
      if ((tempptr = strchr(temp, ' ')) != NULL)
301
      if ((tempptr = strchr(temp, ' ')) != NULL)
291
        *tempptr = '\0';
302
	*tempptr = '\0';
292
303
293
      mfg = temp;
304
      mfg = temp;
294
    }
305
    }
(-)cups-1.4.4.orig/backend/usb-hybrid.c (+88 lines)
Line 0 Link Here
1
/*
2
 * "Id: usb-hybrid.c 8807 2009-08-31 18:45:43Z mike "
3
 *
4
 *   USB port backend for the Common UNIX Printing System (CUPS).
5
 *
6
 *   This file is included from "usb.c" when compiled on Linux.
7
 *
8
 *   Copyright 2007-2008 by Apple Inc.
9
 *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
10
 *
11
 *   These coded instructions, statements, and computer programs are the
12
 *   property of Apple Inc. and are protected by Federal copyright
13
 *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
14
 *   "LICENSE" which should have been included with this file.  If this
15
 *   file is missing or damaged, see the license at "http://www.cups.org/".
16
 *
17
 *   This file is subject to the Apple OS-Developed Software exception.
18
 *
19
 * Contents:
20
 *
21
 *   print_device() - Print a file to a USB device.
22
 *   list_devices() - List all USB devices.
23
 */
24
25
/*
26
 * Include necessary headers.
27
 */
28
29
#include <sys/select.h>
30
31
/*
32
 * Include the two USB implementations used under Linux ...
33
 */
34
35
#define USB_HYBRID 1
36
#include "usb-libusb.c"
37
#include "usb-unix.c"
38
39
/*
40
 * 'print_device()' - Print a file to a USB device.
41
 */
42
43
int					/* O - Exit status */
44
print_device(const char *uri,		/* I - Device URI */
45
             const char *hostname,	/* I - Hostname/manufacturer */
46
             const char *resource,	/* I - Resource/modelname */
47
	     char       *options,	/* I - Device options/serial number */
48
	     int        print_fd,	/* I - File descriptor to print */
49
	     int        copies,		/* I - Copies to print */
50
	     int	argc,		/* I - Number of command-line arguments (6 or 7) */
51
	     char	*argv[])	/* I - Command-line arguments */
52
{
53
  int result;
54
  for(;;)
55
  {
56
    result = print_device_unix(uri, hostname, resource, options, print_fd,
57
			       copies, argc, argv);
58
    if (result == -1)
59
    {
60
      result = print_device_libusb(uri, hostname, resource, options, print_fd,
61
				   copies, argc, argv);
62
      if (result == -1)
63
	sleep(5);
64
      else
65
	return(result);
66
    }
67
    else
68
      return(result);
69
  }
70
}
71
72
/*
73
 * 'list_devices()' - List all USB devices.
74
 */
75
76
void
77
list_devices(void)
78
{
79
  /* Try both discovery methods, each device will appear only under one
80
     of them */
81
  list_devices_libusb();
82
  list_devices_unix();
83
}
84
85
86
/*
87
 * End of "Id: usb-hybrid.c 8807 2009-08-31 18:45:43Z mike ".
88
 */
(-)cups-1.4.4.orig/backend/usb-libusb.c (-20 / +89 lines)
Lines 13-28 Link Here
13
 *
13
 *
14
 * Contents:
14
 * Contents:
15
 *
15
 *
16
 *   list_devices()    - List the available printers.
16
 *   list_devices_libusb()    - List the available printers.
17
 *   print_device()    - Print a file to a USB device.
17
 *   print_device_libusb()    - Print a file to a USB device.
18
 *   close_device()    - Close the connection to the USB printer.
18
 *   close_device()    - Close the connection to the USB printer.
19
 *   find_device()     - Find or enumerate USB printers.
19
 *   find_device()     - Find or enumerate USB printers.
20
 *   get_device_id()   - Get the IEEE-1284 device ID for the printer.
20
 *   get_device_id()   - Get the IEEE-1284 device ID for the printer.
21
 *   list_cb()         - List USB printers for discovery.
21
 *   list_cb()         - List USB printers for discovery.
22
 *   make_device_uri() - Create a device URI for a USB printer.
22
 *   make_device_uri() - Create a device URI for a USB printer.
23
 *   open_device()     - Open a connection to the USB printer.
23
 *   open_device_libusb()     - Open a connection to the USB printer.
24
 *   print_cb()        - Find a USB printer for printing.
24
 *   print_cb()        - Find a USB printer for printing.
25
 *   side_cb()         - Handle side-channel requests.
25
 *   side_cb_libusb()         - Handle side-channel requests.
26
 */
26
 */
27
27
28
/*
28
/*
Lines 65-94 static int list_cb(usb_printer_t *print Link Here
65
static char		*make_device_uri(usb_printer_t *printer,
65
static char		*make_device_uri(usb_printer_t *printer,
66
			                 const char *device_id,
66
			                 const char *device_id,
67
					 char *uri, size_t uri_size);
67
					 char *uri, size_t uri_size);
68
static int		open_device(usb_printer_t *printer, int verbose);
68
static int		open_device_libusb(usb_printer_t *printer, int verbose);
69
static int		print_cb(usb_printer_t *printer, const char *device_uri,
69
static int		print_cb(usb_printer_t *printer, const char *device_uri,
70
			         const char *device_id, const void *data);
70
			         const char *device_id, const void *data);
71
static ssize_t		side_cb(usb_printer_t *printer, int print_fd);
71
static ssize_t		side_cb_libusb(usb_printer_t *printer, int print_fd);
72
72
73
73
74
/*
74
/*
75
 * 'list_devices()' - List the available printers.
75
 * 'list_devices_libusb()' - List the available printers.
76
 */
76
 */
77
77
78
void
78
void
79
list_devices(void)
79
list_devices_libusb(void)
80
{
80
{
81
  fputs("DEBUG: list_devices\n", stderr);
81
  fputs("DEBUG: list_devices_libusb\n", stderr);
82
  find_device(list_cb, NULL);
82
  find_device(list_cb, NULL);
83
}
83
}
84
84
85
85
86
/*
86
/*
87
 * 'print_device()' - Print a file to a USB device.
87
 * 'print_device_libusb()' - Print a file to a USB device.
88
 */
88
 */
89
89
90
int					/* O - Exit status */
90
int					/* O - Exit status */
91
print_device(const char *uri,		/* I - Device URI */
91
print_device_libusb(const char *uri,		/* I - Device URI */
92
             const char *hostname,	/* I - Hostname/manufacturer */
92
             const char *hostname,	/* I - Hostname/manufacturer */
93
             const char *resource,	/* I - Resource/modelname */
93
             const char *resource,	/* I - Resource/modelname */
94
	     char       *options,	/* I - Device options/serial number */
94
	     char       *options,	/* I - Device options/serial number */
Lines 105-123 print_device(const char *uri, /* I - De Link Here
105
  struct pollfd	pfds[2];		/* Poll descriptors */
105
  struct pollfd	pfds[2];		/* Poll descriptors */
106
106
107
107
108
  fputs("DEBUG: print_device\n", stderr);
108
  fputs("DEBUG: print_device_libusb\n", stderr);
109
109
110
 /*
110
 /*
111
  * Connect to the printer...
111
  * Connect to the printer...
112
  */
112
  */
113
113
114
#if defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
115
  if ((printer = find_device(print_cb, uri)) == NULL)
116
    return(-1);
117
#else
114
  while ((printer = find_device(print_cb, uri)) == NULL)
118
  while ((printer = find_device(print_cb, uri)) == NULL)
115
  {
119
  {
116
    _cupsLangPuts(stderr,
120
    _cupsLangPuts(stderr,
117
		  _("INFO: Waiting for printer to become available...\n"));
121
		  _("INFO: Waiting for printer to become available...\n"));
118
    sleep(5);
122
    sleep(5);
119
  }
123
  }
120
124
#endif
121
125
122
 /*
126
 /*
123
  * If we are printing data from a print driver on stdin, ignore SIGTERM
127
  * If we are printing data from a print driver on stdin, ignore SIGTERM
Lines 189-195 print_device(const char *uri, /* I - De Link Here
189
193
190
      if (pfds[1].revents & (POLLIN | POLLHUP))
194
      if (pfds[1].revents & (POLLIN | POLLHUP))
191
      {
195
      {
192
        if ((bytes = side_cb(printer, print_fd)) < 0)
196
        if ((bytes = side_cb_libusb(printer, print_fd)) < 0)
193
	  pfds[1].events = 0;		/* Filter has gone away... */
197
	  pfds[1].events = 0;		/* Filter has gone away... */
194
	else
198
	else
195
          tbytes += bytes;
199
          tbytes += bytes;
Lines 359-365 find_device(usb_cb_t cb, /* I - Callb Link Here
359
	    printer.iface  = iface;
363
	    printer.iface  = iface;
360
	    printer.handle = NULL;
364
	    printer.handle = NULL;
361
365
362
            if (!open_device(&printer, data != NULL))
366
            if (!open_device_libusb(&printer, data != NULL))
363
	    {
367
	    {
364
	      if (!get_device_id(&printer, device_id, sizeof(device_id)))
368
	      if (!get_device_id(&printer, device_id, sizeof(device_id)))
365
	      {
369
	      {
Lines 583-588 make_device_uri( Link Here
583
    mfg = tempmfg;
587
    mfg = tempmfg;
584
  }
588
  }
585
589
590
  if (!strncasecmp(mdl, mfg, strlen(mfg)))
591
  {
592
    mdl += strlen(mfg);
593
594
    while (isspace(*mdl & 255))
595
      mdl ++;
596
    }
597
586
 /*
598
 /*
587
  * Generate the device URI from the manufacturer, model, serial number,
599
  * Generate the device URI from the manufacturer, model, serial number,
588
  * and interface number...
600
  * and interface number...
Lines 611-621 make_device_uri( Link Here
611
623
612
624
613
/*
625
/*
614
 * 'open_device()' - Open a connection to the USB printer.
626
 * 'open_device_libusb()' - Open a connection to the USB printer.
615
 */
627
 */
616
628
617
static int				/* O - 0 on success, -1 on error */
629
static int				/* O - 0 on success, -1 on error */
618
open_device(usb_printer_t *printer,	/* I - Printer */
630
open_device_libusb(usb_printer_t *printer,	/* I - Printer */
619
            int           verbose)	/* I - Update connecting-to-device state? */
631
            int           verbose)	/* I - Update connecting-to-device state? */
620
{
632
{
621
  int	number;				/* Configuration/interface/altset numbers */
633
  int	number;				/* Configuration/interface/altset numbers */
Lines 733-748 print_cb(usb_printer_t *printer, /* I - Link Here
733
         const char    *device_id,	/* I - IEEE-1284 device ID */
745
         const char    *device_id,	/* I - IEEE-1284 device ID */
734
         const void    *data)		/* I - User data (make, model, S/N) */
746
         const void    *data)		/* I - User data (make, model, S/N) */
735
{
747
{
736
  return (!strcmp((char *)data, device_uri));
748
  char *uri = (char *)data,
749
       *str1,
750
       *str2,
751
       buf[255],
752
       requested_uri[1024];
753
754
  /* Work on a copy of uri */
755
  strncpy(requested_uri, uri, sizeof(requested_uri));
756
  requested_uri[sizeof(requested_uri) - 1] = '\0';
757
758
  /*
759
   * libusb-discovered URIs can have an "interface" specification and this
760
   * never happens for usblp-discovered URIs, so remove the "interface"
761
   * specification from the URI which we are checking currently. This way a
762
   * queue for a usblp-discovered printer can now be accessed via libusb
763
   */
764
  if (((str1 = strstr(requested_uri, "interface=")) == NULL) &&
765
      ((str2 = strstr(device_uri, "interface=")) != NULL))
766
  {
767
    *(str2 - 1) = '\0';
768
  }
769
770
  /*
771
   * Old URI with "serial=?". Cut this part off and consider this as
772
   * an URI without serial number
773
   */
774
  if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
775
   *(str1 - 1) = '\0';
776
777
  /*
778
   * Old URI without serial number. Match it also with URIs with serial
779
   * number
780
   */
781
  if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
782
      ((str2 = strstr(device_uri, "serial=")) != NULL))
783
    *(str2 - 1) = '\0';
784
785
  /*
786
   * libusb-discovered URIs can have a "serial" specification when the
787
   * usblp-discovered URI for the same printer does not have one, as
788
   * with libusb we can discover serial numbers also with other methods
789
   * than only via the device ID. Therefore we accept also a
790
   * usblp-discovered printer without serial number as a match. This we
791
   * do by removing the serial number from the queue's (libusb-discovered)
792
   * URI before comparing. Also warn the user because of the incapability
793
   * of the usblp-based access to distinguish printers by the serial
794
   * number.
795
   */
796
  if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
797
      ((str2 = strstr(device_uri, "serial=")) != NULL))
798
  {
799
    *(str2 - 1) = '\0';
800
    if (backendGetMakeModel(device_id, buf, sizeof(buf)) == 0)
801
      fprintf(stderr, "WARNING: If you have more than one %s printer connected to this machine, please make sure that the \"usblp\" kernel module is always unloaded (and blacklisted) and re-create the queues for these printers. Otherwise CUPS will not be able to distinguish them.\n",
802
	    buf);
803
  }
804
805
  return (!strcmp(requested_uri, device_uri));
737
}
806
}
738
807
739
808
740
/*
809
/*
741
 * 'side_cb()' - Handle side-channel requests.
810
 * 'side_cb_libusb()' - Handle side-channel requests.
742
 */
811
 */
743
812
744
static ssize_t				/* O - Number of bytes written */
813
static ssize_t				/* O - Number of bytes written */
745
side_cb(usb_printer_t *printer,		/* I - Printer */
814
side_cb_libusb(usb_printer_t *printer,		/* I - Printer */
746
        int           print_fd)		/* I - File to print */
815
        int           print_fd)		/* I - File to print */
747
{
816
{
748
  ssize_t		bytes,		/* Bytes read/written */
817
  ssize_t		bytes,		/* Bytes read/written */
(-)cups-1.4.4.orig/backend/usb-unix.c (-4 / +77 lines)
Lines 25-30 Link Here
25
 */
25
 */
26
26
27
/*
27
/*
28
 *   If USB_HYBRID is define append "_unix" to functions.
29
 */
30
#ifdef USB_HYBRID
31
# define print_device	print_device_unix
32
# define list_devices	list_devices_unix
33
# define open_device	open_device_unix
34
# define side_cb	side_cb_unix
35
#endif
36
37
/*
28
 * Include necessary headers.
38
 * Include necessary headers.
29
 */
39
 */
30
40
Lines 132-137 print_device(const char *uri, /* I - De Link Here
132
	              _("INFO: Printer busy; will retry in 10 seconds...\n"));
142
	              _("INFO: Printer busy; will retry in 10 seconds...\n"));
133
	sleep(10);
143
	sleep(10);
134
      }
144
      }
145
#ifdef HAVE_USB_H
146
      else
147
	return (-1);
148
#else
135
      else if (errno == ENXIO || errno == EIO || errno == ENOENT ||
149
      else if (errno == ENXIO || errno == EIO || errno == ENOENT ||
136
               errno == ENODEV)
150
               errno == ENODEV)
137
      {
151
      {
Lines 147-152 print_device(const char *uri, /* I - De Link Here
147
			resource, strerror(errno));
161
			resource, strerror(errno));
148
	return (CUPS_BACKEND_FAILED);
162
	return (CUPS_BACKEND_FAILED);
149
      }
163
      }
164
#endif
150
    }
165
    }
151
  }
166
  }
152
  while (device_fd < 0);
167
  while (device_fd < 0);
Lines 357-364 open_device(const char *uri, /* I - Dev Link Here
357
    char	device[255],		/* Device filename */
372
    char	device[255],		/* Device filename */
358
		device_id[1024],	/* Device ID string */
373
		device_id[1024],	/* Device ID string */
359
		make_model[1024],	/* Make and model */
374
		make_model[1024],	/* Make and model */
360
		device_uri[1024];	/* Device URI string */
375
		device_uri[1024],	/* Device URI string */
361
376
		requested_uri[1024],	/* Device URI string */
377
		*str1,
378
		*str2;
362
379
363
   /*
380
   /*
364
    * Find the correct USB device...
381
    * Find the correct USB device...
Lines 407-413 open_device(const char *uri, /* I - Dev Link Here
407
	  device_uri[0] = '\0';
424
	  device_uri[0] = '\0';
408
        }
425
        }
409
426
410
        if (!strcmp(uri, device_uri))
427
	/* Work on a copy of uri */
428
	strncpy(requested_uri, uri, sizeof(requested_uri));
429
	requested_uri[sizeof(requested_uri) - 1] = '\0';
430
431
	/*
432
	 * libusb-discovered URIs can have an "interface" specification and this
433
	 * never happens for usblp-discovered URIs, so remove the "interface"
434
	 * specification from the URI of the print queue. This way a queue for
435
	 * a libusb-discovered printer can now be accessed via the usblip kernel
436
	 * module
437
	 */
438
	if ((str1 = strstr(requested_uri, "interface=")) != NULL)
439
	  *(str1 - 1) = '\0';
440
441
	/*
442
	 * Old URI with "serial=?". Cut this part off and consider this as
443
	 * an URI without serial number
444
	 */
445
	if ((str1 = strstr(requested_uri, "serial=?")) != NULL)
446
	 *(str1 - 1) = '\0';
447
448
	/*
449
	 * Old URI without serial number. Match it also with URIs with serial
450
	 * number
451
	 */
452
	if (((str1 = strstr(requested_uri, "serial=")) == NULL) &&
453
	    ((str2 = strstr(device_uri, "serial=")) != NULL))
454
	    *(str2 - 1) = '\0';
455
456
	/*
457
	 * libusb-discovered URIs can have a "serial" specification when the
458
	 * usblp-discovered URI for the same printer does not have one, as
459
	 * with libusb we can discover serial numbers also with other methods
460
	 * than only via the device ID. Therefore we accept also a
461
	 * usblp-discovered printer without serial number as a match. This we
462
	 * do by removing the serial number from the queue's (libusb-discovered)
463
	 * URI before comparing. Also warn the user because of the incapability
464
	 * of the usblp-based access to distinguish printers by the serial
465
	 * number.
466
	 */
467
	if (((str1 = strstr(requested_uri, "serial=")) != NULL) &&
468
	    ((str2 = strstr(device_uri, "serial=")) == NULL))
469
	{
470
	  *(str1 - 1) = '\0';
471
	  fprintf(stderr, "WARNING: If you have more than one %s printer connected to this machine, please unload (and blacklist) the \"usblp\" kernel module as otherwise CUPS will not be able to distinguish your printers.\n",
472
		  make_model);
473
	}
474
475
        if (!strcmp(requested_uri, device_uri))
411
	{
476
	{
412
	 /*
477
	 /*
413
	  * Yes, return this file descriptor...
478
	  * Yes, return this file descriptor...
Lines 433-442 open_device(const char *uri, /* I - Dev Link Here
433
      */
498
      */
434
499
435
      if (busy)
500
      if (busy)
501
      {
436
	_cupsLangPuts(stderr,
502
	_cupsLangPuts(stderr,
437
	              _("INFO: Printer busy; will retry in 5 seconds...\n"));
503
	              _("INFO: Printer busy; will retry in 5 seconds...\n"));
438
504
439
      sleep(5);
505
	sleep(5);
506
      }
507
      else
508
	return -1;
440
    }
509
    }
441
  }
510
  }
442
#elif defined(__sun) && defined(ECPPIOC_GETDEVID)
511
#elif defined(__sun) && defined(ECPPIOC_GETDEVID)
Lines 625-630 side_cb(int print_fd, /* I - Pr Link Here
625
  return (cupsSideChannelWrite(command, status, data, datalen, 1.0));
694
  return (cupsSideChannelWrite(command, status, data, datalen, 1.0));
626
}
695
}
627
696
697
#undef print_device
698
#undef list_devices
699
#undef open_device
700
#undef side_cb
628
701
629
/*
702
/*
630
 * End of "$Id: usb-unix.c 8912 2009-12-08 02:13:42Z mike $".
703
 * End of "$Id: usb-unix.c 8912 2009-12-08 02:13:42Z mike $".
(-)cups-1.4.4.orig/backend/usb.c (-1 / +1 lines)
Lines 56-62 int print_device(const char *uri, const Link Here
56
 */
56
 */
57
57
58
#ifdef HAVE_USB_H
58
#ifdef HAVE_USB_H
59
#  include "usb-libusb.c"
59
#  include "usb-hybrid.c"
60
#elif defined(__APPLE__)
60
#elif defined(__APPLE__)
61
#  include "usb-darwin.c"
61
#  include "usb-darwin.c"
62
#elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
62
#elif defined(__linux) || defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)

Return to bug 285166