| 5666 | */ |
| 5667 | |
| 5668 | static int // O - 1 if distinct, 0 if duplicate |
| 5669 | with_distinct_values( |
| 5670 | cups_array_t *errors, // I - Array of errors |
| 5671 | ipp_attribute_t *attr) // I - Attribute to test |
| 5672 | { |
| 5673 | int i, // Looping var |
| 5674 | count; // Number of values |
| 5675 | ipp_tag_t value_tag; // Value syntax |
| 5676 | const char *value; // Current value |
| 5677 | char buffer[8192]; // Temporary buffer |
| 5678 | cups_array_t *values; // Array of values as strings |
| 5679 | |
| 5680 | |
| 5681 | // If there is only 1 value, it must be distinct |
| 5682 | if ((count = ippGetCount(attr)) == 1) |
| 5683 | return (1); |
| 5684 | |
| 5685 | // Only check integers, enums, rangeOfInteger, resolution, and nul-terminated |
| 5686 | // strings... |
| 5687 | switch (value_tag = ippGetValueTag(attr)) |
| 5688 | { |
| 5689 | case IPP_TAG_INTEGER : |
| 5690 | case IPP_TAG_ENUM : |
| 5691 | case IPP_TAG_RANGE : |
| 5692 | case IPP_TAG_RESOLUTION : |
| 5693 | case IPP_TAG_KEYWORD : |
| 5694 | case IPP_TAG_URISCHEME : |
| 5695 | case IPP_TAG_CHARSET : |
| 5696 | case IPP_TAG_LANGUAGE : |
| 5697 | case IPP_TAG_MIMETYPE : |
| 5698 | case IPP_TAG_BEGIN_COLLECTION : |
| 5699 | break; |
| 5700 | |
| 5701 | default : |
| 5702 | add_stringf(errors, "WITH-DISTINCT-VALUES %s not supported for 1setOf %s", ippGetName(attr), ippTagString(value_tag)); |
| 5703 | return (0); |
| 5704 | } |
| 5705 | |
| 5706 | // Collect values and determine they are all unique... |
| 5707 | values = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); |
| 5708 | |
| 5709 | for (i = 0; i < count; i ++) |
| 5710 | { |
| 5711 | switch (value_tag) |
| 5712 | { |
| 5713 | case IPP_TAG_INTEGER : |
| 5714 | case IPP_TAG_ENUM : |
| 5715 | snprintf(buffer, sizeof(buffer), "%d", ippGetInteger(attr, i)); |
| 5716 | value = buffer; |
| 5717 | break; |
| 5718 | case IPP_TAG_RANGE : |
| 5719 | { |
| 5720 | int upper, lower = ippGetRange(attr, i, &upper); |
| 5721 | // Range values |
| 5722 | |
| 5723 | snprintf(buffer, sizeof(buffer), "%d-%d", lower, upper); |
| 5724 | value = buffer; |
| 5725 | } |
no test coverage detected