~ubuntu-branches/ubuntu/utopic/cups/utopic

« back to all changes in this revision

Viewing changes to backend/snmp-supplies.c

  • Committer: Package Import Robot
  • Author(s): Didier Raboud, Till Kamppeter, Steve Langasek, Didier Raboud
  • Date: 2014-01-03 18:42:39 UTC
  • mfrom: (1.3.2)
  • mto: This revision was merged to the branch mainline in revision 142.
  • Revision ID: package-import@ubuntu.com-20140103184239-juzq32ckr7ra49b3
* New 1.7.0 upstream release

[ Till Kamppeter ]
* Refresh most patches with quilt
* Removed usb-backend-do-not-crash-if-usb-disabled-in-bios and
  cupsd-no-crash-on-avahi-threaded-poll-shutdown patches as they got
  applied upstream
* Removed drop-arch-specifics-from-doc patch as it is not needed
  anymore
* Updated drop_unnecessary_dependencies, manpage-hyphen-minus,
  manpage-translations and ppd-poll-with-client-conf patches manually
  to apply to the new CUPS version
* Added error counting exception from
  usb-backend-do-not-crash-if-usb-disabled-in-bios to
  tests-ignore-warnings
* Install the newly added ippfind utility and its manpage in
  cups-client
* Added pwg.h to libcups2-dev package
* Call dh_auto_clean only if the file Makedefs is present, to avoid a
  FTBFS
* Added color management extensions from Joe Simon's GSoC 2013
  project.
* Patch cups-files.conf to activate CUPS daemon syncing of files when
  closing, so that config files (like printers.conf) do not
  mysteriously disappear (LP: #1157972)
* In the AppArmor profile, allow execution of programs in
  /etc/cups/interfaces/, needed to make CUPS working with queues based
  on System V interface scripts, especially PPD-less queues
  auto-generated by cups-browsed from cups-filters 1.0.41 on.
* Silenced AppArmor noise from udev.conf in syslog (LP: #1229766)

[ Steve Langasek ]
* Add cups-filters (>= 1.0.42) as alternative to foomatic-filters
  (which is deprecated) in package relationships

[ Didier Raboud ]
* Remove Roger Leigh from uploaders on his request with thanks for his
  past work!
* Switch avahi LSB Should-Start dependency to be avahi-daemon; also
  bump package relationship to >= 0.6.31-3~ (Closes: #731608)
* Refresh the manpage translation files
* Move the USB backend quirk rules file to cups-server-common
* Add 38 new 1.7.0 libcups2 symbols
* Mark one C++ libcupsppdc1 symbol as optional as it isn't exported in
  1.7.0 anymore
* Import Fedora patches:
  - to avoid sign-extending CRCs in gz decompression
  - to build with full read-only relocations
  - to fix job history logging (upstream patch)
  - to set the internal default for SyncOnClose to Yes, instead of
    only configuring it to Yes
  - to fix a stringpool corruption issue
  - to prevent USB timeouts causing incorrect print output
* Import Fedora patch updates:
  - to dont-use-dbus-from-two-threads patch so it removes a call to
    avahi_threaded_poll_stop()
  - to avoid_stale_lockfile_in_dbus_notifier patch to call _exit when
    handling SIGTERM
* Move manpage-translations patch at the very end of the patch series
  to have it include all our patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * "$Id: snmp-supplies.c 11173 2013-07-23 12:31:34Z msweet $"
 
2
 * "$Id: snmp-supplies.c 11319 2013-09-27 16:18:26Z msweet $"
3
3
 *
4
4
 *   SNMP supplies functions for CUPS.
5
5
 *
62
62
  char  name[CUPS_SNMP_MAX_STRING],     /* Name of supply */
63
63
        color[8];                       /* Color: "#RRGGBB" or "none" */
64
64
  int   colorant,                       /* Colorant index */
 
65
        sclass,                         /* Supply class */
65
66
        type,                           /* Supply type */
66
67
        max_capacity,                   /* Maximum capacity */
67
68
        level;                          /* Current level value */
148
149
                        (sizeof(prtMarkerSuppliesMaxCapacity) /
149
150
                         sizeof(prtMarkerSuppliesMaxCapacity[0]));
150
151
                                        /* Offset to supply index */
 
152
static const int        prtMarkerSuppliesClass[] =
 
153
                        { CUPS_OID_prtMarkerSuppliesClass, -1 },
 
154
                                        /* Class OID */
 
155
                        prtMarkerSuppliesClassOffset =
 
156
                        (sizeof(prtMarkerSuppliesClass) /
 
157
                         sizeof(prtMarkerSuppliesClass[0]));
 
158
                                        /* Offset to supply index */
151
159
static const int        prtMarkerSuppliesType[] =
152
160
                        { CUPS_OID_prtMarkerSuppliesType, -1 },
153
161
                                        /* Type OID */
257
265
      else
258
266
        percent = 50;
259
267
 
 
268
      if (supplies[i].sclass == CUPS_TC_receptacleThatIsFilled)
 
269
        percent = 100 - percent;
 
270
 
260
271
      if (percent <= 5)
261
272
      {
262
273
        switch (supplies[i].type)
318
329
 
319
330
      if ((supplies[i].max_capacity > 0 || (quirks & CUPS_SNMP_CAPACITY)) &&
320
331
          supplies[i].level >= 0)
321
 
        sprintf(ptr, "%d", percent);
 
332
        snprintf(ptr, sizeof(value) - (ptr - value), "%d", percent);
322
333
      else
323
 
        strcpy(ptr, "-1");
 
334
        strlcpy(ptr, "-1", sizeof(value) - (ptr - value));
324
335
    }
325
336
 
326
337
    fprintf(stderr, "ATTR: marker-levels=%s\n", value);
458
469
                  "other",
459
470
                  "unknown",
460
471
                  "toner",
461
 
                  "wasteToner",
 
472
                  "waste-toner",
462
473
                  "ink",
463
 
                  "inkCartridge",
464
 
                  "inkRibbon",
465
 
                  "wasteInk",
 
474
                  "ink-cartridge",
 
475
                  "ink-ribbon",
 
476
                  "waste-ink",
466
477
                  "opc",
467
478
                  "developer",
468
 
                  "fuserOil",
469
 
                  "solidWax",
470
 
                  "ribbonWax",
471
 
                  "wasteWax",
 
479
                  "fuser-oil",
 
480
                  "solid-wax",
 
481
                  "ribbon-wax",
 
482
                  "waste-wax",
472
483
                  "fuser",
473
 
                  "coronaWire",
474
 
                  "fuserOilWick",
475
 
                  "cleanerUnit",
476
 
                  "fuserCleaningPad",
477
 
                  "transferUnit",
478
 
                  "tonerCartridge",
479
 
                  "fuserOiler",
 
484
                  "corona-wire",
 
485
                  "fuser-oil-wick",
 
486
                  "cleaner-unit",
 
487
                  "fuser-cleaning-pad",
 
488
                  "transfer-unit",
 
489
                  "toner-cartridge",
 
490
                  "fuser-oiler",
480
491
                  "water",
481
 
                  "wasteWater",
482
 
                  "glueWaterAdditive",
483
 
                  "wastePaper",
484
 
                  "bindingSupply",
485
 
                  "bandingSupply",
486
 
                  "stitchingWire",
487
 
                  "shrinkWrap",
488
 
                  "paperWrap",
 
492
                  "waste-water",
 
493
                  "glue-water-additive",
 
494
                  "waste-paper",
 
495
                  "binding-supply",
 
496
                  "banding-supply",
 
497
                  "stitching-wire",
 
498
                  "shrink-wrap",
 
499
                  "paper-wrap",
489
500
                  "staples",
490
501
                  "inserts",
491
502
                  "covers"
561
572
   /*
562
573
    * Yes, read the cache file:
563
574
    *
564
 
    *     2 num_supplies charset
 
575
    *     3 num_supplies charset
565
576
    *     device description
566
577
    *     supply structures...
567
578
    */
568
579
 
569
580
    if (cupsFileGets(cachefile, value, sizeof(value)))
570
581
    {
571
 
      if (sscanf(value, "2 %d%d", &num_supplies, &charset) == 2 &&
 
582
      if (sscanf(value, "3 %d%d", &num_supplies, &charset) == 2 &&
572
583
          num_supplies <= CUPS_MAX_SUPPLIES &&
573
584
          cupsFileGets(cachefile, value, sizeof(value)))
574
585
      {
664
675
 
665
676
  if ((cachefile = cupsFileOpen(cachefilename, "w")) != NULL)
666
677
  {
667
 
    cupsFilePrintf(cachefile, "2 %d %d\n", num_supplies, charset);
 
678
    cupsFilePrintf(cachefile, "3 %d %d\n", num_supplies, charset);
668
679
    cupsFilePrintf(cachefile, "%s\n", description);
669
680
 
670
681
    if (num_supplies > 0)
682
693
  */
683
694
 
684
695
  for (i = 0; i < num_supplies; i ++)
685
 
    strcpy(supplies[i].color, "none");
 
696
    strlcpy(supplies[i].color, "none", sizeof(supplies[i].color));
686
697
 
687
698
  _cupsSNMPWalk(snmp_fd, &current_addr, CUPS_SNMP_VERSION_1,
688
699
                _cupsSNMPDefaultCommunity(), prtMarkerColorantValue,
697
708
    if (i)
698
709
      *ptr++ = ',';
699
710
 
700
 
    strcpy(ptr, supplies[i].color);
 
711
    strlcpy(ptr, supplies[i].color, sizeof(value) - (ptr - value));
701
712
  }
702
713
 
703
714
  fprintf(stderr, "ATTR: marker-colors=%s\n", value);
745
756
    type = supplies[i].type;
746
757
 
747
758
    if (type < CUPS_TC_other || type > CUPS_TC_covers)
748
 
      strcpy(ptr, "unknown");
 
759
      strlcpy(ptr, "unknown", sizeof(value) - (ptr - value));
749
760
    else
750
 
      strcpy(ptr, types[type - CUPS_TC_other]);
 
761
      strlcpy(ptr, types[type - CUPS_TC_other], sizeof(value) - (ptr - value));
751
762
  }
752
763
 
753
764
  fprintf(stderr, "ATTR: marker-types=%s\n", value);
814
825
          if (!_cups_strcasecmp(colors[k][0],
815
826
                                (char *)packet->object_value.string.bytes))
816
827
          {
817
 
            strcpy(supplies[j].color, colors[k][1]);
 
828
            strlcpy(supplies[j].color, colors[k][1], sizeof(supplies[j].color));
818
829
            break;
819
830
          }
820
831
      }
969
980
        packet->object_value.integer > 0)
970
981
      supplies[i - 1].max_capacity = packet->object_value.integer;
971
982
  }
 
983
  else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesClass))
 
984
  {
 
985
   /*
 
986
    * Get marker class...
 
987
    */
 
988
 
 
989
    i = packet->object_name[prtMarkerSuppliesClassOffset];
 
990
    if (i < 1 || i > CUPS_MAX_SUPPLIES ||
 
991
        packet->object_type != CUPS_ASN1_INTEGER)
 
992
      return;
 
993
 
 
994
    fprintf(stderr, "DEBUG2: prtMarkerSuppliesClass.1.%d = %d\n", i,
 
995
            packet->object_value.integer);
 
996
 
 
997
    if (i > num_supplies)
 
998
      num_supplies = i;
 
999
 
 
1000
    supplies[i - 1].sclass = packet->object_value.integer;
 
1001
  }
972
1002
  else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesType))
973
1003
  {
974
1004
   /*
1073
1103
 
1074
1104
 
1075
1105
/*
1076
 
 * End of "$Id: snmp-supplies.c 11173 2013-07-23 12:31:34Z msweet $".
 
1106
 * End of "$Id: snmp-supplies.c 11319 2013-09-27 16:18:26Z msweet $".
1077
1107
 */