|
|
ccb820 |
diff -up cups-1.4.8/backend/snmp-supplies.c.snmp-quirks cups-1.4.8/backend/snmp-supplies.c
|
|
|
ccb820 |
--- cups-1.4.8/backend/snmp-supplies.c.snmp-quirks 2011-07-06 22:27:31.000000000 +0200
|
|
|
ccb820 |
+++ cups-1.4.8/backend/snmp-supplies.c 2011-07-26 11:02:14.709121584 +0200
|
|
|
e66302 |
@@ -49,6 +49,13 @@
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
eb8e84 |
/*
|
|
Tim Waugh |
eb8e84 |
+ * Printer quirks...
|
|
Tim Waugh |
eb8e84 |
+ */
|
|
Tim Waugh |
eb8e84 |
+
|
|
Tim Waugh |
2553f6 |
+#define QUIRK_CAPACITY (1<<0)
|
|
Tim Waugh |
eb8e84 |
+
|
|
Tim Waugh |
eb8e84 |
+
|
|
Tim Waugh |
eb8e84 |
+/*
|
|
Tim Waugh |
eb8e84 |
* Local structures...
|
|
Tim Waugh |
eb8e84 |
*/
|
|
Tim Waugh |
eb8e84 |
|
|
|
e66302 |
@@ -68,6 +75,12 @@ typedef struct /**** Printer state ta
|
|
Tim Waugh |
eb8e84 |
const char *keyword; /* IPP printer-state-reasons keyword */
|
|
Tim Waugh |
eb8e84 |
} backend_state_t;
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
2553f6 |
+typedef struct /**** Quirk names table ****/
|
|
Tim Waugh |
eb8e84 |
+{
|
|
Tim Waugh |
2553f6 |
+ int bit; /* Quirk bit */
|
|
Tim Waugh |
2553f6 |
+ const char *keyword; /* cupsSNMPQuirks keyword */
|
|
Tim Waugh |
2553f6 |
+} quirk_name_t;
|
|
Tim Waugh |
eb8e84 |
+
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
eb8e84 |
/*
|
|
Tim Waugh |
eb8e84 |
* Local globals...
|
|
|
e66302 |
@@ -79,6 +92,7 @@ static int current_state = -1;
|
|
Tim Waugh |
eb8e84 |
static int charset = -1; /* Character set for supply names */
|
|
Tim Waugh |
eb8e84 |
static int num_supplies = 0;
|
|
Tim Waugh |
eb8e84 |
/* Number of supplies found */
|
|
Tim Waugh |
eb8e84 |
+static int quirks = 0; /* Printer quirks */
|
|
Tim Waugh |
eb8e84 |
static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
|
|
Tim Waugh |
eb8e84 |
/* Supply information */
|
|
|
e66302 |
static int supply_state = -1;
|
|
|
e66302 |
@@ -180,6 +194,15 @@ static const backend_state_t const suppl
|
|
|
e66302 |
{ CUPS_TONER_EMPTY, "toner-empty-warning" }
|
|
Tim Waugh |
eb8e84 |
};
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
2553f6 |
+static const quirk_name_t const quirk_names[] =
|
|
Tim Waugh |
eb8e84 |
+ {
|
|
Tim Waugh |
2553f6 |
+ /*
|
|
Tim Waugh |
2553f6 |
+ * The prtMarkerSuppliesLevel values are
|
|
Tim Waugh |
2553f6 |
+ * percentages, not levels relative to the
|
|
Tim Waugh |
2553f6 |
+ * stated capacity.
|
|
Tim Waugh |
2553f6 |
+ */
|
|
Tim Waugh |
2553f6 |
+ { QUIRK_CAPACITY, "capacity" }
|
|
Tim Waugh |
eb8e84 |
+ };
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
eb8e84 |
/*
|
|
Tim Waugh |
eb8e84 |
* Local functions...
|
|
|
e66302 |
@@ -233,6 +256,9 @@ backendSNMPSupplies(
|
|
Tim Waugh |
eb8e84 |
|
|
|
e66302 |
for (i = 0, ptr = value; i < num_supplies; i ++, ptr += strlen(ptr))
|
|
|
e66302 |
{
|
|
Tim Waugh |
2553f6 |
+ if (quirks & QUIRK_CAPACITY)
|
|
|
e66302 |
+ supplies[i].max_capacity = 100;
|
|
Tim Waugh |
eb8e84 |
+
|
|
|
ccb820 |
if (supplies[i].max_capacity > 0)
|
|
|
ccb820 |
percent = 100 * supplies[i].level / supplies[i].max_capacity;
|
|
|
ccb820 |
else
|
|
|
ccb820 |
@@ -409,6 +435,7 @@ backend_init_supplies(
|
|
Tim Waugh |
2553f6 |
http_addr_t *addr) /* I - Printer address */
|
|
Tim Waugh |
2553f6 |
{
|
|
Tim Waugh |
2553f6 |
int i, /* Looping var */
|
|
Tim Waugh |
2553f6 |
+ len, /* Quirk name length */
|
|
Tim Waugh |
2553f6 |
type; /* Current marker type */
|
|
Tim Waugh |
2553f6 |
cups_file_t *cachefile; /* Cache file */
|
|
Tim Waugh |
2553f6 |
const char *cachedir; /* CUPS_CACHEDIR value */
|
|
|
ccb820 |
@@ -470,6 +497,7 @@ backend_init_supplies(
|
|
Tim Waugh |
eb8e84 |
current_state = -1;
|
|
Tim Waugh |
eb8e84 |
num_supplies = -1;
|
|
Tim Waugh |
eb8e84 |
charset = -1;
|
|
Tim Waugh |
eb8e84 |
+ quirks = 0;
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
eb8e84 |
memset(supplies, 0, sizeof(supplies));
|
|
Tim Waugh |
eb8e84 |
|
|
|
ccb820 |
@@ -485,6 +513,34 @@ backend_init_supplies(
|
|
Tim Waugh |
2553f6 |
return;
|
|
Tim Waugh |
2553f6 |
}
|
|
Tim Waugh |
eb8e84 |
|
|
Tim Waugh |
2553f6 |
+ if (ppd &&
|
|
Tim Waugh |
2553f6 |
+ (ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL &&
|
|
Tim Waugh |
2553f6 |
+ ppdattr->value)
|
|
Tim Waugh |
eb8e84 |
+ {
|
|
Tim Waugh |
2553f6 |
+ ptr = ppdattr->value;
|
|
Tim Waugh |
2553f6 |
+ while (*ptr != '\0')
|
|
Tim Waugh |
eb8e84 |
+ {
|
|
Tim Waugh |
2553f6 |
+ /*
|
|
Tim Waugh |
2553f6 |
+ * Match keyword against quirk_names table.
|
|
Tim Waugh |
2553f6 |
+ */
|
|
Tim Waugh |
2553f6 |
+
|
|
Tim Waugh |
2553f6 |
+ for (i = 0; i < sizeof (quirk_names) / sizeof (quirk_names[0]); i++)
|
|
Tim Waugh |
2553f6 |
+ {
|
|
Tim Waugh |
2553f6 |
+ len = strlen (quirk_names[i].keyword);
|
|
Tim Waugh |
d52d3c |
+ if (!strncmp (ptr, quirk_names[i].keyword, len) &&
|
|
Tim Waugh |
d52d3c |
+ (ptr[len] == '\0' || ptr[len] == ' '))
|
|
Tim Waugh |
2553f6 |
+ quirks |= quirk_names[i].bit;
|
|
Tim Waugh |
2553f6 |
+ }
|
|
Tim Waugh |
2553f6 |
+
|
|
Tim Waugh |
2553f6 |
+ /*
|
|
Tim Waugh |
2553f6 |
+ * Advance to next keyword.
|
|
Tim Waugh |
2553f6 |
+ */
|
|
Tim Waugh |
2553f6 |
+
|
|
Tim Waugh |
2553f6 |
+ ptr += strcspn (ptr, " ");
|
|
Tim Waugh |
2553f6 |
+ ptr += strspn (ptr, " ");
|
|
Tim Waugh |
eb8e84 |
+ }
|
|
Tim Waugh |
eb8e84 |
+ }
|
|
Tim Waugh |
eb8e84 |
+
|
|
Tim Waugh |
2553f6 |
ppdClose(ppd);
|
|
Tim Waugh |
2553f6 |
|
|
Tim Waugh |
eb8e84 |
/*
|