|
|
a5bc511 |
diff -up cups-1.4.2/backend/snmp-supplies.c.snmp-quirks cups-1.4.2/backend/snmp-supplies.c
|
|
|
a5bc511 |
--- cups-1.4.2/backend/snmp-supplies.c.snmp-quirks 2010-06-09 15:55:05.320019839 +0100
|
|
|
a5bc511 |
+++ cups-1.4.2/backend/snmp-supplies.c 2010-06-09 15:55:15.638146234 +0100
|
|
|
a5bc511 |
@@ -38,6 +38,13 @@
|
|
|
a5bc511 |
|
|
|
a5bc511 |
|
|
|
a5bc511 |
/*
|
|
|
a5bc511 |
+ * Printer quirks...
|
|
|
a5bc511 |
+ */
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
+#define QUIRK_CAPACITY (1<<0)
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
+/*
|
|
|
a5bc511 |
* Local structures...
|
|
|
a5bc511 |
*/
|
|
|
a5bc511 |
|
|
|
a5bc511 |
@@ -57,6 +64,12 @@ typedef struct /**** Printer state ta
|
|
|
a5bc511 |
const char *keyword; /* IPP printer-state-reasons keyword */
|
|
|
a5bc511 |
} backend_state_t;
|
|
|
a5bc511 |
|
|
|
a5bc511 |
+typedef struct /**** Quirk names table ****/
|
|
|
a5bc511 |
+{
|
|
|
a5bc511 |
+ int bit; /* Quirk bit */
|
|
|
a5bc511 |
+ const char *keyword; /* cupsSNMPQuirks keyword */
|
|
|
a5bc511 |
+} quirk_name_t;
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
|
|
|
a5bc511 |
/*
|
|
|
a5bc511 |
* Local globals...
|
|
|
a5bc511 |
@@ -68,6 +81,7 @@ static int current_state = -1;
|
|
|
a5bc511 |
static int charset = -1; /* Character set for supply names */
|
|
|
a5bc511 |
static int num_supplies = 0;
|
|
|
a5bc511 |
/* Number of supplies found */
|
|
|
a5bc511 |
+static int quirks = 0; /* Printer quirks */
|
|
|
a5bc511 |
static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
|
|
|
a5bc511 |
/* Supply information */
|
|
|
a5bc511 |
|
|
|
a5bc511 |
@@ -153,6 +167,15 @@ static const backend_state_t const print
|
|
|
a5bc511 |
{ CUPS_TC_outputFull, "output-area-full-warning" }
|
|
|
a5bc511 |
};
|
|
|
a5bc511 |
|
|
|
a5bc511 |
+static const quirk_name_t const quirk_names[] =
|
|
|
a5bc511 |
+ {
|
|
|
a5bc511 |
+ /*
|
|
|
a5bc511 |
+ * The prtMarkerSuppliesLevel values are
|
|
|
a5bc511 |
+ * percentages, not levels relative to the
|
|
|
a5bc511 |
+ * stated capacity.
|
|
|
a5bc511 |
+ */
|
|
|
a5bc511 |
+ { QUIRK_CAPACITY, "capacity" }
|
|
|
a5bc511 |
+ };
|
|
|
a5bc511 |
|
|
|
a5bc511 |
/*
|
|
|
a5bc511 |
* Local functions...
|
|
|
a5bc511 |
@@ -208,6 +231,9 @@ backendSNMPSupplies(
|
|
|
a5bc511 |
if (i)
|
|
|
a5bc511 |
*ptr++ = ',';
|
|
|
a5bc511 |
|
|
|
a5bc511 |
+ if (quirks & QUIRK_CAPACITY)
|
|
|
a5bc511 |
+ supplies[i].max_capacity = 100;
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
if (supplies[i].max_capacity > 0)
|
|
|
a5bc511 |
sprintf(ptr, "%d", 100 * supplies[i].level / supplies[i].max_capacity);
|
|
|
a5bc511 |
else
|
|
|
a5bc511 |
@@ -305,6 +331,7 @@ backend_init_supplies(
|
|
|
a5bc511 |
http_addr_t *addr) /* I - Printer address */
|
|
|
a5bc511 |
{
|
|
|
a5bc511 |
int i, /* Looping var */
|
|
|
a5bc511 |
+ len, /* Quirk name length */
|
|
|
a5bc511 |
type; /* Current marker type */
|
|
|
a5bc511 |
cups_file_t *cachefile; /* Cache file */
|
|
|
a5bc511 |
const char *cachedir; /* CUPS_CACHEDIR value */
|
|
|
a5bc511 |
@@ -366,6 +393,7 @@ backend_init_supplies(
|
|
|
a5bc511 |
current_state = -1;
|
|
|
a5bc511 |
num_supplies = -1;
|
|
|
a5bc511 |
charset = -1;
|
|
|
a5bc511 |
+ quirks = 0;
|
|
|
a5bc511 |
|
|
|
a5bc511 |
memset(supplies, 0, sizeof(supplies));
|
|
|
a5bc511 |
|
|
|
a5bc511 |
@@ -381,6 +409,34 @@ backend_init_supplies(
|
|
|
a5bc511 |
return;
|
|
|
a5bc511 |
}
|
|
|
a5bc511 |
|
|
|
a5bc511 |
+ if (ppd &&
|
|
|
a5bc511 |
+ (ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL &&
|
|
|
a5bc511 |
+ ppdattr->value)
|
|
|
a5bc511 |
+ {
|
|
|
a5bc511 |
+ ptr = ppdattr->value;
|
|
|
a5bc511 |
+ while (*ptr != '\0')
|
|
|
a5bc511 |
+ {
|
|
|
a5bc511 |
+ /*
|
|
|
a5bc511 |
+ * Match keyword against quirk_names table.
|
|
|
a5bc511 |
+ */
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
+ for (i = 0; i < sizeof (quirk_names) / sizeof (quirk_names[0]); i++)
|
|
|
a5bc511 |
+ {
|
|
|
a5bc511 |
+ len = strlen (quirk_names[i].keyword);
|
|
|
a5bc511 |
+ if (!strncmp (value, quirk_names[i].keyword, len) &&
|
|
|
a5bc511 |
+ (value[len] == '\0' || value[len] == ' '))
|
|
|
a5bc511 |
+ quirks |= quirk_names[i].bit;
|
|
|
a5bc511 |
+ }
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
+ /*
|
|
|
a5bc511 |
+ * Advance to next keyword.
|
|
|
a5bc511 |
+ */
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
+ ptr += strcspn (ptr, " ");
|
|
|
a5bc511 |
+ ptr += strspn (ptr, " ");
|
|
|
a5bc511 |
+ }
|
|
|
a5bc511 |
+ }
|
|
|
a5bc511 |
+
|
|
|
a5bc511 |
ppdClose(ppd);
|
|
|
a5bc511 |
|
|
|
a5bc511 |
/*
|