]> git.ipfire.org Git - people/arne_f/ipfire-3.x.git/blob - pkgs/cups/patches/cups-snmp-quirks.patch
0308676c145011de1ad46f8c50f6d73fa028bdc2
[people/arne_f/ipfire-3.x.git] / pkgs / cups / patches / cups-snmp-quirks.patch
1 diff -up cups-1.4.3/backend/snmp-supplies.c.snmp-quirks cups-1.4.3/backend/snmp-supplies.c
2 --- cups-1.4.3/backend/snmp-supplies.c.snmp-quirks 2009-11-20 01:27:57.000000000 +0000
3 +++ cups-1.4.3/backend/snmp-supplies.c 2010-06-09 16:27:05.515019804 +0100
4 @@ -38,6 +38,13 @@
5
6
7 /*
8 + * Printer quirks...
9 + */
10 +
11 +#define QUIRK_CAPACITY (1<<0)
12 +
13 +
14 +/*
15 * Local structures...
16 */
17
18 @@ -57,6 +64,12 @@ typedef struct /**** Printer state ta
19 const char *keyword; /* IPP printer-state-reasons keyword */
20 } backend_state_t;
21
22 +typedef struct /**** Quirk names table ****/
23 +{
24 + int bit; /* Quirk bit */
25 + const char *keyword; /* cupsSNMPQuirks keyword */
26 +} quirk_name_t;
27 +
28
29 /*
30 * Local globals...
31 @@ -68,6 +81,7 @@ static int current_state = -1;
32 static int charset = -1; /* Character set for supply names */
33 static int num_supplies = 0;
34 /* Number of supplies found */
35 +static int quirks = 0; /* Printer quirks */
36 static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
37 /* Supply information */
38
39 @@ -153,6 +167,15 @@ static const backend_state_t const print
40 { CUPS_TC_outputFull, "output-area-full-warning" }
41 };
42
43 +static const quirk_name_t const quirk_names[] =
44 + {
45 + /*
46 + * The prtMarkerSuppliesLevel values are
47 + * percentages, not levels relative to the
48 + * stated capacity.
49 + */
50 + { QUIRK_CAPACITY, "capacity" }
51 + };
52
53 /*
54 * Local functions...
55 @@ -208,6 +231,9 @@ backendSNMPSupplies(
56 if (i)
57 *ptr++ = ',';
58
59 + if (quirks & QUIRK_CAPACITY)
60 + supplies[i].max_capacity = 100;
61 +
62 if (supplies[i].max_capacity > 0)
63 sprintf(ptr, "%d", 100 * supplies[i].level / supplies[i].max_capacity);
64 else
65 @@ -305,6 +331,7 @@ backend_init_supplies(
66 http_addr_t *addr) /* I - Printer address */
67 {
68 int i, /* Looping var */
69 + len, /* Quirk name length */
70 type; /* Current marker type */
71 cups_file_t *cachefile; /* Cache file */
72 const char *cachedir; /* CUPS_CACHEDIR value */
73 @@ -366,6 +393,7 @@ backend_init_supplies(
74 current_state = -1;
75 num_supplies = -1;
76 charset = -1;
77 + quirks = 0;
78
79 memset(supplies, 0, sizeof(supplies));
80
81 @@ -381,6 +409,34 @@ backend_init_supplies(
82 return;
83 }
84
85 + if (ppd &&
86 + (ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL &&
87 + ppdattr->value)
88 + {
89 + ptr = ppdattr->value;
90 + while (*ptr != '\0')
91 + {
92 + /*
93 + * Match keyword against quirk_names table.
94 + */
95 +
96 + for (i = 0; i < sizeof (quirk_names) / sizeof (quirk_names[0]); i++)
97 + {
98 + len = strlen (quirk_names[i].keyword);
99 + if (!strncmp (ptr, quirk_names[i].keyword, len) &&
100 + (ptr[len] == '\0' || ptr[len] == ' '))
101 + quirks |= quirk_names[i].bit;
102 + }
103 +
104 + /*
105 + * Advance to next keyword.
106 + */
107 +
108 + ptr += strcspn (ptr, " ");
109 + ptr += strspn (ptr, " ");
110 + }
111 + }
112 +
113 ppdClose(ppd);
114
115 /*