]>
Commit | Line | Data |
---|---|---|
1f9b7ef8 KB |
1 | diff -up cups-1.5.0/cups/dest.c.cups-get-classes cups-1.5.0/cups/dest.c |
2 | --- cups-1.5.0/cups/dest.c.cups-get-classes 2011-05-20 04:49:49.000000000 +0100 | |
3 | +++ cups-1.5.0/cups/dest.c 2011-09-14 12:10:05.111635428 +0100 | |
4 | @@ -534,6 +534,7 @@ _cupsGetDests(http_t *http, /* I - | |
f92713d3 SS |
5 | char uri[1024]; /* printer-uri value */ |
6 | int num_options; /* Number of options */ | |
7 | cups_option_t *options; /* Options */ | |
8 | + int get_classes; /* Whether we need to fetch class */ | |
9 | #ifdef __APPLE__ | |
10 | char media_default[41]; /* Default paper size */ | |
11 | #endif /* __APPLE__ */ | |
1f9b7ef8 | 12 | @@ -590,6 +591,8 @@ _cupsGetDests(http_t *http, /* I - |
f92713d3 SS |
13 | * printer-uri [for IPP_GET_PRINTER_ATTRIBUTES] |
14 | */ | |
15 | ||
16 | + get_classes = (op == CUPS_GET_PRINTERS); | |
17 | + | |
18 | request = ippNewRequest(op); | |
19 | ||
20 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | |
1f9b7ef8 | 21 | @@ -647,6 +650,23 @@ _cupsGetDests(http_t *http, /* I - |
f92713d3 SS |
22 | attr->value_tag != IPP_TAG_URI) |
23 | continue; | |
24 | ||
25 | + if (get_classes && | |
26 | + | |
27 | + /* Is this a class? */ | |
28 | + ((attr->value_tag == IPP_TAG_ENUM && | |
29 | + !strcmp(attr->name, "printer-type") && | |
30 | + (attr->values[0].integer & CUPS_PRINTER_CLASS)) || | |
31 | + | |
32 | + /* Or, is this an attribute from CUPS 1.2 or later? */ | |
33 | + !strcmp(attr->name, "auth-info-required") || | |
34 | + !strncmp(attr->name, "marker-", 7) || | |
35 | + !strcmp(attr->name, "printer-commands") || | |
36 | + !strcmp(attr->name, "printer-is-shared"))) | |
37 | + /* We are talking to a recent enough CUPS server that | |
38 | + * CUPS_GET_PRINTERS returns classes as well. | |
39 | + */ | |
40 | + get_classes = 0; | |
41 | + | |
42 | if (!strcmp(attr->name, "auth-info-required") || | |
43 | !strcmp(attr->name, "device-uri") || | |
44 | !strcmp(attr->name, "marker-change-time") || | |
1f9b7ef8 | 45 | @@ -738,6 +758,28 @@ _cupsGetDests(http_t *http, /* I - |
f92713d3 SS |
46 | continue; |
47 | } | |
48 | ||
49 | + /* | |
50 | + * If we sent a CUPS_GET_CLASSES request, check whether | |
51 | + * CUPS_GET_PRINTERS already gave us this destination and exit | |
52 | + * early if so. | |
53 | + */ | |
54 | + | |
1f9b7ef8 | 55 | + if (op == CUPS_GET_CLASSES && num_dests > 0) |
f92713d3 SS |
56 | + { |
57 | + int diff; | |
58 | + cups_find_dest (printer_name, NULL, num_dests, *dests, 0, &diff); | |
59 | + if (diff == 0) | |
60 | + { | |
61 | + /* | |
62 | + * Found it. The CUPS server already gave us the classes in | |
63 | + * its CUPS_GET_PRINTERS response. | |
64 | + */ | |
65 | + | |
66 | + cupsFreeOptions(num_options, options); | |
67 | + break; | |
68 | + } | |
69 | + } | |
70 | + | |
71 | if ((dest = cups_add_dest(printer_name, NULL, &num_dests, dests)) != NULL) | |
72 | { | |
73 | dest->num_options = num_options; | |
1f9b7ef8 | 74 | @@ -754,6 +796,15 @@ _cupsGetDests(http_t *http, /* I - |
f92713d3 SS |
75 | } |
76 | ||
77 | /* | |
78 | + * If this is a CUPS_GET_PRINTERS request but we didn't see any | |
79 | + * classes we might be talking to an older CUPS server that requires | |
80 | + * CUPS_GET_CLASSES as well. | |
81 | + */ | |
82 | + | |
83 | + if (get_classes) | |
1f9b7ef8 | 84 | + num_dests = _cupsGetDests (http, CUPS_GET_CLASSES, name, dests, 0, 0); |
f92713d3 SS |
85 | + |
86 | + /* | |
87 | * Return the count... | |
88 | */ | |
89 |