From 29f49b49850980253091b3ceeb6eb5f26ad2e38e Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 1 Feb 2012 10:06:20 -0500 Subject: [PATCH 2/3] Fix supply levels for enumerated prtMarkerSuppliesLevel values 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) 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. Signed-off-by: Peter Hurley --- backend/backend-private.h | 2 ++ backend/snmp-supplies.c | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/backend-private.h b/backend/backend-private.h index a94b874..5d0835c 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 b3da3cb..a6cff9a 100644 --- a/backend/snmp-supplies.c +++ b/backend/snmp-supplies.c @@ -237,17 +237,31 @@ backendSNMPSupplies( for (i = 0, ptr = value; i < num_supplies; i ++, ptr += strlen(ptr)) { - if (supplies[i].max_capacity > 0) + /* 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) percent = supplies[i].level; else percent = 100 * supplies[i].level / supplies[i].max_capacity; } - else + else if (supplies[i].level == CUPS_TC_somesupply) percent = 50; + else + percent = -1; + + if (i) + *ptr++ = ','; + + sprintf(ptr, "%d", percent); - if (percent <= 10) + if (percent >= 0 && percent <= 10) { switch (supplies[i].type) { @@ -288,14 +302,6 @@ backendSNMPSupplies( break; } } - - if (i) - *ptr++ = ','; - - if (supplies[i].max_capacity > 0) - sprintf(ptr, "%d", percent); - else - strcpy(ptr, "-1"); } fprintf(stderr, "ATTR: marker-levels=%s\n", value); -- 1.7.5.4