summaryrefslogtreecommitdiffstats
path: root/collectors/cups.plugin
diff options
context:
space:
mode:
authorSimon Nagl <simonnagl@aim.com>2019-02-11 10:40:16 +0100
committerChris Akritidis <43294513+cakrit@users.noreply.github.com>2019-02-11 10:40:16 +0100
commitd5cd94eed3c838a0f997c8a289c0f729e9da1eb7 (patch)
treef81e2852a0cc8ab91011eeb3b7f608396d3e51d6 /collectors/cups.plugin
parent63d36dd9b0cce58ee16866bea6bab4435688bf33 (diff)
cups.plugin: Support older versions (#5350)
The usage of cupsGetIntegerOption did block users using older cups versions than 2.2.4. After redistribution this method all cups versions since 1.7 can be used. httpConnect2 is now the most recently added method in cups.h.
Diffstat (limited to 'collectors/cups.plugin')
-rw-r--r--collectors/cups.plugin/README.md2
-rw-r--r--collectors/cups.plugin/cups_plugin.c34
2 files changed, 33 insertions, 3 deletions
diff --git a/collectors/cups.plugin/README.md b/collectors/cups.plugin/README.md
index 7baf885597..f04aa567f4 100644
--- a/collectors/cups.plugin/README.md
+++ b/collectors/cups.plugin/README.md
@@ -4,7 +4,7 @@
## Prerequisites
-This plugin needs a running local CUPS daemon (`cupsd`). This plugin does not need any configuration.
+This plugin needs a running local CUPS daemon (`cupsd`). This plugin does not need any configuration. Supports cups since version 1.7.
## Charts
diff --git a/collectors/cups.plugin/cups_plugin.c b/collectors/cups.plugin/cups_plugin.c
index 7fbba2c461..dc86437557 100644
--- a/collectors/cups.plugin/cups_plugin.c
+++ b/collectors/cups.plugin/cups_plugin.c
@@ -136,6 +136,37 @@ void parse_command_line(int argc, char **argv) {
}
}
+/*
+ * 'cupsGetIntegerOption()' - Get an integer option value.
+ *
+ * INT_MIN is returned when the option does not exist, is not an integer, or
+ * exceeds the range of values for the "int" type.
+ *
+ * @since CUPS 2.2.4/macOS 10.13@
+ */
+
+int /* O - Option value or @code INT_MIN@ */
+getIntegerOption(
+ const char *name, /* I - Name of option */
+ int num_options, /* I - Number of options */
+ cups_option_t *options) /* I - Options */
+{
+ const char *value = cupsGetOption(name, num_options, options);
+ /* String value of option */
+ char *ptr; /* Pointer into string value */
+ long intvalue; /* Integer value */
+
+
+ if (!value || !*value)
+ return (INT_MIN);
+
+ intvalue = strtol(value, &ptr, 10);
+ if (intvalue < INT_MIN || intvalue > INT_MAX || *ptr)
+ return (INT_MIN);
+
+ return ((int)intvalue);
+}
+
int reset_job_metrics(void *entry, void *data) {
(void)data;
@@ -303,8 +334,7 @@ int main(int argc, char **argv) {
num_dest_shared++;
}
- // TODO use cupsGetIntegerOption
- int printer_state = cupsGetIntegerOption("printer-state", curr_dest->num_options, curr_dest->options);
+ int printer_state = getIntegerOption("printer-state", curr_dest->num_options, curr_dest->options);
switch (printer_state) {
case 3:
num_dest_idle++;