OpenPrinting / libcups

OpenPrinting CUPS Library Sources
https://openprinting.github.io/cups/cups3.html
Apache License 2.0
35 stars 17 forks source link

ipptool: Add support for conditional ATTR/MEMBER directives #3

Closed michaelrsweet closed 2 years ago

michaelrsweet commented 2 years ago

From @wifiprintguy, ippsample issue 254:

It would be very useful if the IF-DEFINED and IF-NOT-DEFINED predicates could be used in EXPECT and MEMBER directives so that attributes could be conditionally included in a request. For instance:

{
    SKIP-IF-NOT-DEFINED HAVE_BALING

    NAME '[BALING-2] Print requesting baling using finishings'
    OPERATION Print-Job

    GROUP operation-attributes-tag
        ATTR charset attributes-charset utf-8
        ATTR language attributes-natural-language en
        ATTR uri printer-uri $uri
        ATTR name requesting-user-name $user
        ATTR mimeMediaType document-format $filetype

    GROUP job-attributes-tag
        ATTR integer copies 1
        ATTR enum finishings 12  # bale
        ATTR integer job-pages-per-set 3 IF-DEFINED HAS_JOB_PAGES_PER_SET
        ATTR integer copies 2 IF-NOT-DEFINED HAS_JOB_PAGES_PER_SET

    FILE $filename

    STATUS successful-ok

    EXPECT job-id OF-TYPE integer IN-GROUP job-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT job-uri OF-TYPE uri IN-GROUP job-attributes-tag COUNT 1
}

These two lines:

        ATTR integer job-pages-per-set 3 IF-DEFINED HAS_JOB_PAGES_PER_SET
        ATTR integer copies 2 IF-NOT-DEFINED HAS_JOB_PAGES_PER_SET

are currently illegal. To achieve this you have to write 2+ tests that are nearly identical, which is not an optimal solution.

michaelrsweet commented 2 years ago

We need slightly different syntax:

ATTR-IF-DEFINED VARIABLE_NAME syntax name value
ATTR-IF-NOT-DEFINED VARIABLE_NAME syntax name value
michaelrsweet commented 2 years ago

[master d7f7d2aa0] Add ATTR-IF-DEFINED and ATTR-IF-NOT-DEFINED directive support (Issue #3)