From e3acf4811cfec29f3479a2b7e93ccee0b8120f91 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Sun, 5 Feb 2012 11:30:20 -0500 Subject: [PATCH 2/3] Fix supply levels for enumerated prtMarkerSuppliesLevels As stated in the code comment, RFC 3805 specifies the following special values for prtMarkerSuppliesLevel: -1 other; sub-unit places no restrictions on this parameter -2 unknown -3 some supply or remaining space (depending on if supply is consumed or filled) -3 (some supply) corresponds to 'Supply ok' and reported as 50 percent. NB: Despite some code movement/simplification to accommodate the special handling, the original logic path is preserved. Originally, when .max_capacity <= 0, the percent was set to 50 (which skipped status changes) and then output "-1" as the string value. Now, when .max_capacity <= 0, the percent is set to -1 and immediately output, then the status changes are skipped because the percent is < 0. Applies to CUPS 1.5.1 Signed-off-by: Peter Hurley --- backend/backend-private.h | 2 ++ backend/snmp-supplies.c | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/backend-private.h b/backend/backend-private.h index c1d384c..d157e44 100644 --- a/backend/backend-private.h +++ b/backend/backend-private.h @@ -186,6 +186,8 @@ extern "C" { #define CUPS_TC_printing 4 #define CUPS_TC_warmup 5 +#define CUPS_TC_somesupply -3 + /* These come from the hrPrinterDetectedErrorState OCTET-STRING */ #define CUPS_TC_lowPaper 0x8000 #define CUPS_TC_noPaper 0x4000 diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c index 30864ef..3a975bb 100644 --- a/backend/snmp-supplies.c +++ b/backend/snmp-supplies.c @@ -237,6 +237,13 @@ backendSNMPSupplies( for (i = 0, ptr = value; i < num_supplies; i ++, ptr += strlen(ptr)) { + /* RFC 3805 specifies the following special values for + * prtMarkerSuppliesLevel: + * -1 other; sub-unit places no restrictions on this parameter + * -2 unknown + * -3 some supply or remaining space (depending on if supply is + * consumed or filled) + */ if (supplies[i].max_capacity > 0 && supplies[i].level >= 0) { if (supplies[i].units == CUPS_TC_percent) @@ -244,10 +251,17 @@ backendSNMPSupplies( else percent = 100 * supplies[i].level / supplies[i].max_capacity; } + else if (supplies[i].level == CUPS_TC_somesupply) + percent = 50; else - percent = 50; + percent = -1; - if (percent <= 5) + if (i) + *ptr++ = ','; + + sprintf(ptr, "%d", percent); + + if (percent >= 0 && percent <= 5) { switch (supplies[i].type) { @@ -288,14 +302,6 @@ backendSNMPSupplies( break; } } - - if (i) - *ptr++ = ','; - - if (supplies[i].max_capacity > 0 && supplies[i].level >= 0) - sprintf(ptr, "%d", percent); - else - strcpy(ptr, "-1"); } fprintf(stderr, "ATTR: marker-levels=%s\n", value); -- 1.7.5.4