Handle SNMP supply level quirks #3551

Closed
michaelrsweet opened this Issue Apr 13, 2010 · 23 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Apr 13, 2010

Version: 1.6-feature
CUPS.org User: twaugh.redhat

This patch adds a quirks table indexed by hrDeviceDescr, with a single
quirk: that the supply levels are given by the printer as percentages
rather than as units relative to the reported maximum capacity. This
is seen on at least one HP printer -- there are apparently many more.

Original bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=581825

Collaborator

michaelrsweet commented Apr 13, 2010

CUPS.org User: mike

I really don't want to chase workarounds for obviously-broken SNMP implementations - SNMP has been around for a long time and there is no excuse for doing a broken implementation.

I would consider adding support for an additional PPD keyword (we already support a SNMP "kill switch" with the cupsSNMP keyword) to describe SNMP capabilities - at least then the "quirk" table will be managed by the driver/device developers and not us.

Collaborator

michaelrsweet commented Apr 13, 2010

CUPS.org User: mike

Also pushing this to 1.5 as a feature request...

Collaborator

michaelrsweet commented Apr 13, 2010

CUPS.org User: twaugh.redhat

New patch posted to look for a PPD attribute to enable handling of this quirk.

What do you think?

Collaborator

michaelrsweet commented Apr 13, 2010

CUPS.org User: mike

Looks like the patch still contains some of the old code...

In general I think this a better approach, although I'd like to make the keyword more generic, with the value containing the quirk names, e.g.:

*cupsSNMPQuirks: "capacity"

Then we can just add additional names to the one keyword...

Collaborator

michaelrsweet commented Apr 14, 2010

CUPS.org User: twaugh.redhat

Yes, good idea. New patch attached to do that. (and old code removed...)

Collaborator

michaelrsweet commented Jun 8, 2010

CUPS.org User: twaugh.redhat

Is this new approach OK?

Collaborator

michaelrsweet commented Jun 8, 2010

CUPS.org User: mike

Yes, although we can keep the quirks keyword code simpler for now since we only define one...

Collaborator

michaelrsweet commented Jun 8, 2010

CUPS.org User: twaugh.redhat

Yes, great.

So if 'cupsSNMPQuirks' is an acceptable PPD attribute name I'll start adding it to relevant PPDs.

Collaborator

michaelrsweet commented Aug 23, 2010

CUPS.org User: twaugh.redhat

(Fixed patch attached.)

We only define one quirk currently, yes. However, there are plenty more to add. :-(

One example:
https://bugzilla.redhat.com/show_bug.cgi?id=624479

in which an HP LaserJet M1522nf MFP reported incorrect printer error bits in response to hrPrinterDetectedErrorState.

Collaborator

michaelrsweet commented May 6, 2011

CUPS.org User: mike

Pushing out pending licensing...

Collaborator

michaelrsweet commented Feb 1, 2012

CUPS.org User: peter.hurleysoftware

It may be that this quirk patch is unnecessary. As Apple Technical Note TN2144 (http://developer.apple.com/library/mac/#technotes/tn2144/_index.html) enumerates, this printer may have specified the 'prtMarkerSuppliesSupplyUnit' = 19 (ie., percent), which would mean that the prtMarkerSuppliesLevel values are correct (just already expressed as percentages). Unfortunately, the original bug report did not include an snmpwalk of the complete printmib (or even just the prtMarkerSuppliesEntry).

A patch to backendSNMPSupplies() would still necessary to handle this.

Collaborator

michaelrsweet commented Mar 5, 2012

CUPS.org User: mike

Tim, try the attached patch - instead of introducing a cupsSNMPQuirks keyword I updated the supply code to look at the units and default MaxCapacity to 100.

Collaborator

michaelrsweet commented Mar 6, 2012

CUPS.org User: twaugh.redhat

Thanks, this looks like it might be the right solution. I don't have access to the hardware myself but I will try to get that to someone who does.

Collaborator

michaelrsweet commented Mar 8, 2012

CUPS.org User: twaugh.redhat

I'm afraid this still fails with an HP OfficeJet Pro 8500. Investigation with snmpwalk shows that it claims the units are tenths of millilitres but the values are actually percentages (confirmed by comparing with level reports on printer console).

Collaborator

michaelrsweet commented Mar 8, 2012

CUPS.org User: mike

Tim, can you provide snmpwalk output or debug CUPS error_log for this printer? I'd like to see exactly what you are getting...

Collaborator

michaelrsweet commented Mar 9, 2012

CUPS.org User: twaugh.redhat

STATE: +connecting-to-device
DEBUG: Looking up "***"...
DEBUG2: hrDeviceDesc="Officejet Pro 8500 A909a"
DEBUG2: prtGeneralCurrentLocalization=1
DEBUG2: prtLocalizationCharacterSet=2004
DEBUG2: prtMarkerSuppliesColorantIndex.1.1 = 0
DEBUG2: prtMarkerSuppliesColorantIndex.1.2 = 0
DEBUG2: prtMarkerSuppliesColorantIndex.1.3 = 0
DEBUG2: prtMarkerSuppliesColorantIndex.1.4 = 0
DEBUG2: prtMarkerSuppliesType.1.1 = 5
DEBUG2: prtMarkerSuppliesType.1.2 = 5
DEBUG2: prtMarkerSuppliesType.1.3 = 5
DEBUG2: prtMarkerSuppliesType.1.4 = 5
DEBUG2: prtMarkerSuppliesDescription.1.1 = "black ink C4906A"
DEBUG2: prtMarkerSuppliesDescription.1.2 = "yellow ink C4909S"
DEBUG2: prtMarkerSuppliesDescription.1.3 = "magenta ink C4908S"
DEBUG2: prtMarkerSuppliesDescription.1.4 = "cyan ink C4907S"
DEBUG2: prtMarkerSuppliesSupplyUnit.1.1 = 15
DEBUG2: prtMarkerSuppliesSupplyUnit.1.2 = 15
DEBUG2: prtMarkerSuppliesSupplyUnit.1.3 = 15
DEBUG2: prtMarkerSuppliesSupplyUnit.1.4 = 15
DEBUG2: prtMarkerSuppliesMaxCapacity.1.1 = 607
DEBUG2: prtMarkerSuppliesMaxCapacity.1.2 = 162
DEBUG2: prtMarkerSuppliesMaxCapacity.1.3 = 155
DEBUG2: prtMarkerSuppliesMaxCapacity.1.4 = 152
DEBUG2: prtMarkerSuppliesLevel.1.1 = 87
DEBUG2: prtMarkerSuppliesLevel.1.2 = 27
DEBUG2: prtMarkerSuppliesLevel.1.3 = 41
DEBUG2: prtMarkerSuppliesLevel.1.4 = 39
ATTR: marker-colors=none,none,none,none
ATTR: marker-names="black ink C4906A","yellow ink C4909S","magenta ink C4908S","cyan ink C4907S"
ATTR: marker-types=ink,ink,ink,ink
ATTR: marker-levels=14,16,26,25
DEBUG: new_supply_state=0, change_state=ffff
STATE: -developer-low-report
STATE: -developer-empty-warning
STATE: -marker-supply-low-report
STATE: -marker-supply-empty-warning
STATE: -opc-near-eol-report
STATE: -opc-life-over-warning
STATE: -toner-low-report
STATE: -toner-empty-warning
DEBUG: new_state=0, change_state=ffff
STATE: -media-low-report
STATE: -media-empty-warning
STATE: -door-open-report
STATE: -media-jam-warning
STATE: -input-tray-missing-warning
STATE: -output-tray-missing-warning
STATE: -marker-supply-missing-warning
STATE: -output-area-almost-full-report
STATE: -output-area-full-warning

So the SNMP responses say the black ink is at 14%, but in reality it is nearly full.

Collaborator

michaelrsweet commented May 21, 2012

CUPS.org User: mike

Fixed in Subversion repository.

Collaborator

michaelrsweet commented May 21, 2012

"0001-Add-SNMP-quirks-for-levels-being-reported-as-percent.patch":

From 407aefdc239e47f7782b1b75b2b9314ac35a60f8 Mon Sep 17 00:00:00 2001
From: Tim Waugh twaugh@redhat.com
Date: Tue, 13 Apr 2010 11:53:18 +0100
Subject: [PATCH] Add SNMP quirks for levels being reported as percentages (bug #581825).

This patch adds a quirks table indexed by hrDeviceDescr, with a single
quirk: that the supply levels are given by the printer as percentages
rather than as units relative to the reported maximum capacity. This

is seen on at least one HP printer -- there are apparently many more.

backend/snmp-supplies.c | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c
index 8ee031d..4edfd25 100644
--- a/backend/snmp-supplies.c
+++ b/backend/snmp-supplies.c
@@ -38,6 +38,15 @@

/*

  • * Printer quirks...
  • /
    +
    +/
    The prtMarkerSuppliesLevel values are percentages, not levels
  • * relative to the stated capacity. /
    +#define QUIRK_LEVEL_IS_PERCENTAGE (1<<0)
    +
    +
    +/
    • Local structures...
      */

@@ -57,6 +66,12 @@ typedef struct /**** Printer state table ***/
const char *keyword; /
IPP printer-state-reasons keyword */
} backend_state_t;

+typedef struct /**** Printer quirk table ****/
+{

  • const char description; / hrDeviceDescr */
  • int quirks; /* quirks (bitmask) */
    +} printer_quirk_t;

/*

  • Local globals...
    @@ -68,6 +83,7 @@ static int current_state = -1;
    static int charset = -1; /* Character set for supply names /
    static int num_supplies = 0;
    /
    Number of supplies found /
    +static int quirks = 0; /
    Printer quirks /
    static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
    /
    Supply information */

@@ -153,6 +169,11 @@ static const backend_state_t const printer_states[] =
{ CUPS_TC_outputFull, "output-area-full-warning" }
};

+static const printer_quirk_t const printer_quirks[] =

  •       {
    
  •         { "Officejet Pro 8500 A909g", QUIRK_LEVEL_IS_PERCENTAGE }
    
  •       };
    

    /*

    • Local functions...
      @@ -208,6 +229,9 @@ backendSNMPSupplies(
      if (i)
      *ptr++ = ',';
  •  if (quirks & QUIRK_LEVEL_IS_PERCENTAGE)
    
  • supplies[i].max_capacity = 100;

  • if (supplies[i].max_capacity > 0)
    sprintf(ptr, "%d", 100 * supplies[i].level / supplies[i].max_capacity);
    else
    @@ -366,6 +390,7 @@ backend_init_supplies(
    current_state = -1;
    num_supplies = -1;
    charset = -1;
  • quirks = 0;

memset(supplies, 0, sizeof(supplies));

@@ -404,6 +429,15 @@ backend_init_supplies(

fprintf(stderr, "DEBUG2: hrDeviceDesc="%s"\n", description);

  • for (i = 0; i < sizeof (printer_quirks) / sizeof (printer_quirks[0]); i++)
  • {
  • if (!strcmp (description, printer_quirks[i].description))
  • {
  •  quirks = printer_quirks[i].quirks;
    
  •  break;
    
  • }
  • }

/*

  • See if we have already queried this device...
    */

    1.6.5.2
Collaborator

michaelrsweet commented May 21, 2012

"0001-Add-SNMP-quirks-for-levels-being-reported-as-percent_v2.patch":

From 7391b96d1c79bdef9d4cabe6639b2e0f8a629e5b Mon Sep 17 00:00:00 2001
From: Tim Waugh twaugh@redhat.com
Date: Tue, 13 Apr 2010 11:53:18 +0100
Subject: [PATCH] Add SNMP quirks for levels being reported as percentages (bug #581825).

This patch adds support for an SNMP quirk, enabled via the PPD file:
that the supply levels are given by the printer as percentages
rather than as units relative to the reported maximum capacity. This

is seen on at least one HP printer -- there are apparently many more.

backend/snmp-supplies.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c
index 8ee031d..8570943 100644
--- a/backend/snmp-supplies.c
+++ b/backend/snmp-supplies.c
@@ -38,6 +38,15 @@

/*

  • * Printer quirks...
  • /
    +
    +/
    The prtMarkerSuppliesLevel values are percentages, not levels
  • * relative to the stated capacity. /
    +#define QUIRK_LEVEL_IS_PERCENTAGE (1<<0)
    +
    +
    +/
    • Local structures...
      */

@@ -68,6 +77,7 @@ static int current_state = -1;
static int charset = -1; /* Character set for supply names /
static int num_supplies = 0;
/
Number of supplies found /
+static int quirks = 0; /
Printer quirks /
static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
/
Supply information */

@@ -208,6 +218,9 @@ backendSNMPSupplies(
if (i)
*ptr++ = ',';

  •  if (quirks & QUIRK_LEVEL_IS_PERCENTAGE)
    
  • supplies[i].max_capacity = 100;
  • if (supplies[i].max_capacity > 0)
    sprintf(ptr, "%d", 100 * supplies[i].level / supplies[i].max_capacity);
    else
    @@ -366,6 +379,7 @@ backend_init_supplies(
    current_state = -1;
    num_supplies = -1;
    charset = -1;
  • quirks = 0;

memset(supplies, 0, sizeof(supplies));

@@ -381,6 +395,14 @@ backend_init_supplies(
return;
}

  • if (ppd &&
  •  ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirkLevelIsPercentage",
    
  •           NULL) != NULL &&
    
  •  ppdattr->value && !strcasecmp(ppdattr->value, "true"))
    
  • {
  • quirks |= QUIRK_LEVEL_IS_PERCENTAGE;
  • }

ppdClose(ppd);

/*
@@ -404,6 +426,15 @@ backend_init_supplies(

fprintf(stderr, "DEBUG2: hrDeviceDesc="%s"\n", description);

  • for (i = 0; i < sizeof (printer_quirks) / sizeof (printer_quirks[0]); i++)
  • {
  • if (!strcmp (description, printer_quirks[i].description))
  • {
  •  quirks = printer_quirks[i].quirks;
    
  •  break;
    
  • }
  • }

/*

  • See if we have already queried this device...
    */

    1.6.5.2
Collaborator

michaelrsweet commented May 21, 2012

"0001-Add-SNMP-quirks-for-levels-being-reported-as-percent_v3.patch":

From 3c80a2bd835fcd7835fc6734efcb1c4264912581 Mon Sep 17 00:00:00 2001
From: Tim Waugh twaugh@redhat.com
Date: Tue, 13 Apr 2010 11:53:18 +0100
Subject: [PATCH] Add SNMP quirks for levels being reported as percentages (bug #581825).

This patch adds support for an SNMP quirk, enabled via the PPD file:
that the supply levels are given by the printer as percentages
rather than as units relative to the reported maximum capacity. This

is seen on at least one HP printer -- there are apparently many more.

backend/snmp-supplies.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c
index 8ee031d..a504cdc 100644
--- a/backend/snmp-supplies.c
+++ b/backend/snmp-supplies.c
@@ -38,6 +38,13 @@

/*

  • * Printer quirks...
  • /
    +
    +#define QUIRK_CAPACITY (1<<0)
    +
    +
    +/
    • Local structures...
      */

@@ -57,6 +64,12 @@ typedef struct /**** Printer state table ***/
const char *keyword; /
IPP printer-state-reasons keyword */
} backend_state_t;

+typedef struct /**** Quirk names table ****/
+{

  • int bit; /* Quirk bit */
  • const char keyword; / cupsSNMPQuirks keyword */
    +} quirk_name_t;

/*

  • Local globals...
    @@ -68,6 +81,7 @@ static int current_state = -1;
    static int charset = -1; /* Character set for supply names /
    static int num_supplies = 0;
    /
    Number of supplies found /
    +static int quirks = 0; /
    Printer quirks /
    static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
    /
    Supply information */

@@ -153,6 +167,15 @@ static const backend_state_t const printer_states[] =
{ CUPS_TC_outputFull, "output-area-full-warning" }
};

+static const quirk_name_t const quirk_names[] =

  •       {
    
  •        /*
    
  •         \* The prtMarkerSuppliesLevel values are
    
  •         \* percentages, not levels relative to the
    
  •         \* stated capacity.
    
  •         */
    
  •         { QUIRK_CAPACITY, "capacity" }
    
  •       };
    

    /*

    • Local functions...
      @@ -208,6 +231,9 @@ backendSNMPSupplies(
      if (i)
      *ptr++ = ',';
  •  if (quirks & QUIRK_CAPACITY)
    
  • supplies[i].max_capacity = 100;

  • if (supplies[i].max_capacity > 0)
    sprintf(ptr, "%d", 100 * supplies[i].level / supplies[i].max_capacity);
    else
    @@ -305,6 +331,7 @@ backend_init_supplies(
    http_addr_t addr) / I - Printer address /
    {
    int i, /
    Looping var */
  •   len,            /\* Quirk name length _/
    type;           /_ Current marker type _/
    
    cups_file_t *cachefile; /_ Cache file /
    const char *cachedir; /
    CUPS_CACHEDIR value */
    @@ -366,6 +393,7 @@ backend_init_supplies(
    current_state = -1;
    num_supplies = -1;
    charset = -1;
  • quirks = 0;

memset(supplies, 0, sizeof(supplies));

@@ -381,6 +409,34 @@ backend_init_supplies(
return;
}

  • if (ppd &&
  •  (ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL &&
    
  •  ppdattr->value)
    
  • {
  • ptr = ppdattr->value;
  • while (*ptr != '\0')
  • {
  • /*
    
  •  \* Match keyword against quirk_names table.
    
  •  */
    
  •  for (i = 0; i < sizeof (quirk_names) / sizeof (quirk_names[0]); i++)
    
  •  {
    
  • len = strlen (quirk_names[i].keyword);
  • if (!strncmp (value, quirk_names[i].keyword, len) &&
  •   (value[len] == '\0' || value[len] == ' '))
    
  • quirks |= quirk_names[i].bit;
    
  •  }
    
  • /*
    
  •  \* Advance to next keyword.
    
  •  */
    
  •  ptr += strcspn (ptr, " ");
    
  •  ptr += strspn (ptr, " ");
    
  • }
  • }

ppdClose(ppd);

/*

1.6.5.2

Collaborator

michaelrsweet commented May 21, 2012

"0001-Add-SNMP-quirks-for-levels-being-reported-as-percent_v4.patch":

From 114c9f9c8e6de0ff393261db2757d08aa432277b Mon Sep 17 00:00:00 2001
From: Tim Waugh twaugh@redhat.com
Date: Tue, 13 Apr 2010 11:53:18 +0100
Subject: [PATCH] Add SNMP quirks for levels being reported as percentages (bug #581825).

This patch adds support for an SNMP quirk, enabled via the PPD file:
that the supply levels are given by the printer as percentages
rather than as units relative to the reported maximum capacity. This

is seen on at least one HP printer -- there are apparently many more.

backend/snmp-supplies.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c
index 8ee031d..a34d54e 100644
--- a/backend/snmp-supplies.c
+++ b/backend/snmp-supplies.c
@@ -38,6 +38,13 @@

/*

  • * Printer quirks...
  • /
    +
    +#define QUIRK_CAPACITY (1<<0)
    +
    +
    +/
    • Local structures...
      */

@@ -57,6 +64,12 @@ typedef struct /**** Printer state table ***/
const char *keyword; /
IPP printer-state-reasons keyword */
} backend_state_t;

+typedef struct /**** Quirk names table ****/
+{

  • int bit; /* Quirk bit */
  • const char keyword; / cupsSNMPQuirks keyword */
    +} quirk_name_t;

/*

  • Local globals...
    @@ -68,6 +81,7 @@ static int current_state = -1;
    static int charset = -1; /* Character set for supply names /
    static int num_supplies = 0;
    /
    Number of supplies found /
    +static int quirks = 0; /
    Printer quirks /
    static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
    /
    Supply information */

@@ -153,6 +167,15 @@ static const backend_state_t const printer_states[] =
{ CUPS_TC_outputFull, "output-area-full-warning" }
};

+static const quirk_name_t const quirk_names[] =

  •       {
    
  •        /*
    
  •         \* The prtMarkerSuppliesLevel values are
    
  •         \* percentages, not levels relative to the
    
  •         \* stated capacity.
    
  •         */
    
  •         { QUIRK_CAPACITY, "capacity" }
    
  •       };
    

    /*

    • Local functions...
      @@ -208,6 +231,9 @@ backendSNMPSupplies(
      if (i)
      *ptr++ = ',';
  •  if (quirks & QUIRK_CAPACITY)
    
  • supplies[i].max_capacity = 100;

  • if (supplies[i].max_capacity > 0)
    sprintf(ptr, "%d", 100 * supplies[i].level / supplies[i].max_capacity);
    else
    @@ -305,6 +331,7 @@ backend_init_supplies(
    http_addr_t addr) / I - Printer address /
    {
    int i, /
    Looping var */
  •   len,            /\* Quirk name length _/
    type;           /_ Current marker type _/
    
    cups_file_t *cachefile; /_ Cache file /
    const char *cachedir; /
    CUPS_CACHEDIR value */
    @@ -366,6 +393,7 @@ backend_init_supplies(
    current_state = -1;
    num_supplies = -1;
    charset = -1;
  • quirks = 0;

memset(supplies, 0, sizeof(supplies));

@@ -381,6 +409,34 @@ backend_init_supplies(
return;
}

  • if (ppd &&
  •  (ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL &&
    
  •  ppdattr->value)
    
  • {
  • ptr = ppdattr->value;
  • while (*ptr != '\0')
  • {
  • /*
    
  •  \* Match keyword against quirk_names table.
    
  •  */
    
  •  for (i = 0; i < sizeof (quirk_names) / sizeof (quirk_names[0]); i++)
    
  •  {
    
  • len = strlen (quirk_names[i].keyword);
  • if (!strncmp (ptr, quirk_names[i].keyword, len) &&
  •   (ptr[len] == '\0' || ptr[len] == ' '))
    
  • quirks |= quirk_names[i].bit;
    
  •  }
    
  • /*
    
  •  \* Advance to next keyword.
    
  •  */
    
  •  ptr += strcspn (ptr, " ");
    
  •  ptr += strspn (ptr, " ");
    
  • }
  • }

ppdClose(ppd);

/*

1.7.1

Collaborator

michaelrsweet commented May 21, 2012

"str3551.patch":

Index: backend/backend-private.h

--- backend/backend-private.h (revision 10328)
+++ backend/backend-private.h (working copy)
@@ -3,7 +3,7 @@
*

  • Backend support definitions for CUPS.
  • * Copyright 2007-2011 by Apple Inc.
  • * Copyright 2007-2012 by Apple Inc.
  • Copyright 1997-2007 by Easy Software Products, all rights reserved.
  • These coded instructions, statements, and computer programs are the
    @@ -259,6 +259,20 @@
    #define CUPS_TC_inserts 33
    #define CUPS_TC_covers 34

+#define CUPS_TC_tenThousandthsOfInches 3
+#define CUPS_TC_micrometers 4
+#define CUPS_TC_impressions 7
+#define CUPS_TC_sheets 8
+#define CUPS_TC_hours 11
+#define CUPS_TC_thousandthsOfOunces 12
+#define CUPS_TC_tenthsOfGrams 13
+#define CUPS_TC_hundrethsOfFluidOunces 14
+#define CUPS_TC_tenthsOfMilliliters 15
+#define CUPS_TC_feet 16
+#define CUPS_TC_meters 17
+#define CUPS_TC_items 18
+#define CUPS_TC_percent 19
+
/* These come from RFC 3808 to define character sets we support /
/
Also see http://www.iana.org/assignments/character-sets */
#define CUPS_TC_csASCII 3

Index: backend/snmp-supplies.c

--- backend/snmp-supplies.c (revision 10328)
+++ backend/snmp-supplies.c (working copy)
@@ -150,6 +150,13 @@
(sizeof(prtMarkerSuppliesType) /
sizeof(prtMarkerSuppliesType[0]));
/* Offset to supply index */
+static const int prtMarkerSuppliesSupplyUnit[] =

  •       { CUPS_OID_prtMarkerSuppliesSupplyUnit, -1 },
    
  •               /\* Units OID */
    
  •       prtMarkerSuppliesSupplyUnitOffset =
    
  •       (sizeof(prtMarkerSuppliesSupplyUnit) /
    
  •        sizeof(prtMarkerSuppliesSupplyUnit[0]));
    
  •               /* Offset to supply index */
    

    static const backend_state_t const printer_states[] =
    {
    @@ -942,7 +949,9 @@
    if (i > num_supplies)
    num_supplies = i;

  • supplies[i - 1].max_capacity = packet->object_value.integer;

  • if (supplies[i - 1].max_capacity == 0 &&

  •    packet->object_value.integer > 0)
    
  •  supplies[i - 1].max_capacity = packet->object_value.integer;
    

    }
    else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesType))
    {
    @@ -963,6 +972,26 @@

    supplies[i - 1].type = packet->object_value.integer;
    }

  • else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesSupplyUnit))

  • {

  • /*

  • * Get units for capacity...

  • */

  • i = packet->object_name[prtMarkerSuppliesSupplyUnitOffset];
  • if (i < 1 || i > CUPS_MAX_SUPPLIES ||
  •    packet->object_type != CUPS_ASN1_INTEGER)
    
  •  return;
    
  • fprintf(stderr, "DEBUG2: prtMarkerSuppliesSupplyUnit.1.%d = %d\n", i,
  •        packet->object_value.integer);
    
  • if (i > num_supplies)
  •  num_supplies = i;
    
  • if (packet->object_value.integer == CUPS_TC_percent)
  •  supplies[i - 1].max_capacity = 100;
    
  • }
    }
Collaborator

michaelrsweet commented May 21, 2012

"str3551p2.patch":

Index: backend/snmp-supplies.c

--- backend/snmp-supplies.c (revision 10492)
+++ backend/snmp-supplies.c (working copy)
@@ -49,7 +49,10 @@
#define CUPS_CLEANER_NEAR_EOL 0x0400 /* Proposed JPS3 /
#define CUPS_CLEANER_LIFE_OVER 0x0800 /
Proposed JPS3 */

+#define CUPS_SNMP_NONE 0x0000
+#define CUPS_SNMP_CAPACITY 0x0001 /* Supply levels reported as percentages */

/*

  • Local structures...
    /
    @@ -79,6 +82,8 @@
    static int current_state = -1;
    /
    Current device state bits /
    static int charset = -1; /
    Character set for supply names */
    +static unsigned quirks = CUPS_SNMP_NONE;
    •               /\* Quirks we have to work around _/
      
      static int num_supplies = 0;
      /_ Number of supplies found */
      static backend_supplies_t supplies[CUPS_MAX_SUPPLIES];
      @@ -246,6 +251,9 @@
      {
      if (supplies[i].max_capacity > 0 && supplies[i].level >= 0)
      percent = 100 * supplies[i].level / supplies[i].max_capacity;
    •  else if (supplies[i].level >= 0 && supplies[i].level <= 100 &&
      
    •           (quirks & CUPS_SNMP_CAPACITY))
      
    •    percent = supplies[i].level;
      
      else
      percent = 50;

@@ -308,7 +316,8 @@
if (i)
*ptr++ = ',';

  •  if (supplies[i].max_capacity > 0 && supplies[i].level >= 0)
    
  •  if ((supplies[i].max_capacity > 0 || (quirks & CUPS_SNMP_CAPACITY)) &&
    
  •      supplies[i].level >= 0)
     sprintf(ptr, "%d", percent);
    

    else
    strcpy(ptr, "-1");
    @@ -506,6 +515,12 @@
    return;
    }

  • if ((ppdattr = ppdFindAttr(ppd, "cupsSNMPQuirks", NULL)) != NULL)

  • {

  • if (!_cups_strcasecmp(ppdattr->value, "capacity"))

  •  quirks |= CUPS_SNMP_CAPACITY;
    
  • }

ppdClose(ppd);

/*
@@ -932,7 +947,8 @@

supplies[i - 1].level = packet->object_value.integer;
}

  • else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesMaxCapacity))
  • else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesMaxCapacity) &&
  •       !(quirks & CUPS_SNMP_CAPACITY))
    
    {
    /*
    • Get max capacity...

michaelrsweet added this to the Stable milestone Mar 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment