]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Implement cupsAddIntegerOption and cupsGetIntegerOption functions (Issue #4992)
authorMichael R Sweet <michaelrsweet@gmail.com>
Mon, 1 May 2017 20:52:23 +0000 (16:52 -0400)
committerMichael R Sweet <michaelrsweet@gmail.com>
Mon, 1 May 2017 20:52:23 +0000 (16:52 -0400)
CHANGES.txt
cups/cups.h
cups/options.c
cups/versioning.h

index 3edf65ded11d3b2bd74481c7952c59fd1fb6e6a3..898434bf8ed855b7a028bbcf9d8cfb978f3cf76d 100644 (file)
@@ -1,4 +1,4 @@
-CHANGES.txt - 2.2.4 - 2017-04-24
+CHANGES.txt - 2.2.4 - 2017-05-01
 --------------------------------
 
 CHANGES IN CUPS V2.2.4
@@ -7,6 +7,10 @@ CHANGES IN CUPS V2.2.4
        - cupsEnumDests did not return early when all printers had been
          discovered (Issue #4989)
        - The CUPS build system now supports cross-compilation (Issue #4897)
+       - Added a new CUPS Programming Manual to replace the aging API
+         documentation.
+       - Added the cupsAddIntegerOption and cupsGetIntegerOption functions
+         (Issue #4992)
 
 
 CHANGES IN CUPS V2.2.3
index b2419f1b5a3cd685eba755178901e17613f78078..22d4be3e14a7897665fe9e05fd9faf5c4fd86bbd 100644 (file)
@@ -600,6 +600,10 @@ extern int         cupsSetServerCredentials(const char *path, const char *common_name,
 /* New in CUPS 2.2/macOS 10.12 */
 extern ssize_t         cupsHashData(const char *algorithm, const void *data, size_t datalen, unsigned char *hash, size_t hashsize) _CUPS_API_2_2;
 
+/* New in CUPS 2.2.4 */
+extern int             cupsAddIntegerOption(const char *name, int value, int num_options, cups_option_t **options) _CUPS_API_2_2_4;
+extern int             cupsGetIntegerOption(const char *name, int num_options, cups_option_t *options) _CUPS_API_2_2_4;
+
 #  ifdef __cplusplus
 }
 #  endif /* __cplusplus */
index aa70992853a15059c7d7862a2ccea917f48a1f9e..901c75df3c33232a652025023acfa28975871300 100644 (file)
@@ -29,6 +29,31 @@ static int   cups_find_option(const char *name, int num_options,
                                 cups_option_t *option, int prev, int *rdiff);
 
 
+/*
+ * 'cupsAddIntegerOption()' - Add an integer option to an option array.
+ *
+ * New option arrays can be initialized simply by passing 0 for the
+ * "num_options" parameter.
+ *
+ * @since CUPS 2.2.4@
+ */
+
+int                                    /* O  - Number of options */
+cupsAddIntegerOption(
+    const char    *name,               /* I  - Name of option */
+    int           value,               /* I  - Value of option */
+    int           num_options,         /* I  - Number of options */
+    cups_option_t **options)           /* IO - Pointer to options */
+{
+  char strvalue[32];                   /* String value */
+
+
+  snprintf(strvalue, sizeof(strvalue), "%d", value);
+
+  return (cupsAddOption(name, strvalue, num_options, options));
+}
+
+
 /*
  * 'cupsAddOption()' - Add an option to an option array.
  *
@@ -154,6 +179,38 @@ cupsFreeOptions(
 }
 
 
+/*
+ * '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 2.2.4@
+ */
+
+int                                    /* O - Option value or @code INT_MIN@ */
+cupsGetIntegerOption(
+    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);
+}
+
+
 /*
  * 'cupsGetOption()' - Get an option value.
  */
index 2e92e6ba45fabd933bec9cff22798e183ec0ba47..5a000c050c1df7c5c7cdeb1b5ac698ae2182d1d3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * API versioning definitions for CUPS.
  *
- * Copyright 2007-2016 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
 
 /*
  * This header defines several constants - _CUPS_DEPRECATED,
- * _CUPS_DEPRECATED_MSG, _CUPS_INTERNAL_MSG, _CUPS_API_1_1, _CUPS_API_1_1_19,
- * _CUPS_API_1_1_20, _CUPS_API_1_1_21, _CUPS_API_1_2, _CUPS_API_1_3,
- * _CUPS_API_1_4, _CUPS_API_1_5, _CUPS_API_1_6, _CUPS_API_1_7, and
- * _CUPS_API_2_0 - which add compiler-specific attributes that flag functions
- * that are deprecated, added in particular releases, or internal to CUPS.
+ * _CUPS_DEPRECATED_MSG, _CUPS_INTERNAL_MSG, _CUPS_API_major_minor, and
+ * _CUPS_API_major_minor_patch - which add compiler-specific attributes that
+ * flag functions that are deprecated, added in particular releases, or internal
+ * to CUPS.
  *
  * On macOS, the _CUPS_API_* constants are defined based on the values of
  * the MAC_OS_X_VERSION_MIN_ALLOWED and MAC_OS_X_VERSION_MAX_ALLOWED constants
@@ -57,6 +56,9 @@
 #    ifndef AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER
 #      define AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER __attribute__((unavailable))
 #    endif /* !AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER */
+#    ifndef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER
+#      define AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER __attribute__((unavailable))
+#    endif /* !AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER */
 #    define _CUPS_API_1_1_19 AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
 #    define _CUPS_API_1_1_20 AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
 #    define _CUPS_API_1_1_21 AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER
@@ -68,6 +70,7 @@
 #    define _CUPS_API_1_7 AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER
 #    define _CUPS_API_2_0 AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER
 #    define _CUPS_API_2_2 AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER
+#    define _CUPS_API_2_2_4 AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER
 #  else
 #    define _CUPS_API_1_1_19
 #    define _CUPS_API_1_1_20
@@ -80,6 +83,7 @@
 #    define _CUPS_API_1_7
 #    define _CUPS_API_2_0
 #    define _CUPS_API_2_2
+#    define _CUPS_API_2_2_4
 #  endif /* __APPLE__ && !_CUPS_SOURCE */
 
 /*