[5e44432] | 1 | from . import verify_operations |
---|
| 2 | from . import verify_printer_uri |
---|
| 3 | from . import verify_requesting_username |
---|
| 4 | from . import make_empty_response |
---|
| 5 | from . import make_job_attributes |
---|
| 6 | |
---|
| 7 | import logging |
---|
| 8 | logger = logging.getLogger(__name__) |
---|
| 9 | |
---|
| 10 | def verify_get_jobs_request(request): |
---|
| 11 | """RFC 2911 3.2.6.1 Get-Jobs Request |
---|
| 12 | |
---|
| 13 | The client submits the Get-Jobs request to a Printer object. |
---|
| 14 | |
---|
| 15 | The following groups of attributes are part of the Get-Jobs |
---|
| 16 | Request: |
---|
| 17 | |
---|
| 18 | Group 1: Operation Attributes |
---|
| 19 | Natural Language and Character Set: |
---|
| 20 | The 'attributes-charset' and |
---|
| 21 | 'attributes-natural-language' attributes as described |
---|
| 22 | in section 3.1.4.1. |
---|
| 23 | Target: |
---|
| 24 | The 'printer-uri' (uri) operation attribute which is |
---|
| 25 | the target for this operation as described in section |
---|
| 26 | 3.1.5. |
---|
| 27 | Requesting User Name: |
---|
| 28 | The 'requesting-user-name' (name(MAX)) attribute |
---|
| 29 | SHOULD be supplied by the client as described in |
---|
| 30 | section 8.3. |
---|
| 31 | 'limit' (integer(1:MAX)): |
---|
| 32 | The client OPTIONALLY supplies this attribute. The |
---|
| 33 | Printer object MUST support this attribute. It is an |
---|
| 34 | integer value that determines the maximum number of |
---|
| 35 | jobs that a client will receive from the Printer even |
---|
| 36 | if 'which-jobs' or 'my-jobs' constrain which jobs are |
---|
| 37 | returned. The limit is a 'stateless limit' in that if |
---|
| 38 | the value supplied by the client is 'N', then only the |
---|
| 39 | first 'N' jobs are returned in the Get-Jobs Response. |
---|
| 40 | There is no mechanism to allow for the next 'M' jobs |
---|
| 41 | after the first 'N' jobs. If the client does not |
---|
| 42 | supply this attribute, the Printer object responds |
---|
| 43 | with all applicable jobs. |
---|
| 44 | 'requested-attributes' (1setOf type2 keyword): |
---|
| 45 | The client OPTIONALLY supplies this attribute. The |
---|
| 46 | Printer object MUST support this attribute. It is a |
---|
| 47 | set of Job attribute names and/or attribute groups |
---|
| 48 | names in whose values the requester is |
---|
| 49 | interested. This set of attributes is returned for |
---|
| 50 | each Job object that is returned. The allowed |
---|
| 51 | attribute group names are the same as those defined in |
---|
| 52 | the Get-Job-Attributes operation in section 3.3.4. If |
---|
| 53 | the client does not supply this attribute, the Printer |
---|
| 54 | MUST respond as if the client had supplied this |
---|
| 55 | attribute with two values: 'job-uri' and 'job-id'. |
---|
| 56 | 'which-jobs' (type2 keyword): |
---|
| 57 | The client OPTIONALLY supplies this attribute. The |
---|
| 58 | Printer object MUST support this attribute. It |
---|
| 59 | indicates which Job objects MUST be returned by the |
---|
| 60 | Printer object. The values for this attribute are: |
---|
| 61 | - 'completed': This includes any Job object whose |
---|
| 62 | state is 'completed', 'canceled', or 'aborted'. |
---|
| 63 | - 'not-completed': This includes any Job object whose |
---|
| 64 | state is 'pending', 'processing', |
---|
| 65 | 'processing-stopped', or 'pending-held'. |
---|
| 66 | A Printer object MUST support both values. However, if |
---|
| 67 | the implementation does not keep jobs in the |
---|
| 68 | 'completed', 'canceled', and 'aborted' states, then it |
---|
| 69 | returns no jobs when the 'completed' value is |
---|
| 70 | supplied. If a client supplies some other value, the |
---|
| 71 | Printer object MUST copy the attribute and the |
---|
| 72 | unsupported value to the Unsupported Attributes |
---|
| 73 | response group, reject the request, and return the |
---|
| 74 | 'client-error-attributes-or-values-not-supported' |
---|
| 75 | status code. If the client does not supply this |
---|
| 76 | attribute, the Printer object MUST respond as if the |
---|
| 77 | client had supplied the attribute with a value of |
---|
| 78 | 'not-completed'. |
---|
| 79 | 'my-jobs' (boolean): |
---|
| 80 | The client OPTIONALLY supplies this attribute. The |
---|
| 81 | Printer object MUST support this attribute. It |
---|
| 82 | indicates whether jobs from all users or just the jobs |
---|
| 83 | submitted by the requesting user of this request MUST |
---|
| 84 | be considered as candidate jobs to be returned by the |
---|
| 85 | Printer object. If the client does not supply this |
---|
| 86 | attribute, the Printer object MUST respond as if the |
---|
| 87 | client had supplied the attribute with a value of |
---|
| 88 | 'false', i.e., jobs from all users. The means for |
---|
| 89 | authenticating the requesting user and matching the |
---|
| 90 | jobs is described in section 8. |
---|
| 91 | |
---|
| 92 | """ |
---|
| 93 | |
---|
| 94 | out = {} |
---|
| 95 | |
---|
| 96 | # generic operations verification |
---|
| 97 | attrs = verify_operations(request) |
---|
| 98 | |
---|
| 99 | # requested printer uri |
---|
| 100 | if 'printer-uri' not in attrs: |
---|
[aded2d1] | 101 | raise err.ClientErrorBadRequest("Missing 'printer-uri' attribute") |
---|
[5e44432] | 102 | out['printer-uri'] = verify_printer_uri(attrs['printer-uri']) |
---|
| 103 | |
---|
| 104 | # requesting username |
---|
| 105 | if 'requesting-user-name' not in attrs: |
---|
| 106 | logger.warning("Missing 'requesting-user-name' attribute") |
---|
| 107 | else: |
---|
| 108 | out['requesting-user-name'] = verify_requesting_username(attrs['requesting-user-name']) |
---|
| 109 | |
---|
| 110 | if 'limit' in attrs: |
---|
| 111 | out['limit'] = None # XXX |
---|
| 112 | |
---|
| 113 | if 'requested-attributes' in attrs: |
---|
| 114 | out['requested-attributes'] = None # XXX |
---|
| 115 | |
---|
| 116 | if 'which-jobs' in attrs: |
---|
| 117 | out['which-jobs'] = None # XXX |
---|
| 118 | |
---|
| 119 | if 'my-jobs' in attrs: |
---|
| 120 | out['my-jobs'] = None # XXX |
---|
| 121 | |
---|
| 122 | return out |
---|
| 123 | |
---|
| 124 | def make_get_jobs_response(jobs, request): |
---|
| 125 | """RFC 2911: 3.2.6.2 Get-Jobs Response |
---|
| 126 | |
---|
| 127 | The Printer object returns all of the Job objects up to the number |
---|
| 128 | specified by the 'limit' attribute that match the criteria as |
---|
| 129 | defined by the attribute values supplied by the client in the |
---|
| 130 | request. It is possible that no Job objects are returned since |
---|
| 131 | there may literally be no Job objects at the Printer, or there may |
---|
| 132 | be no Job objects that match the criteria supplied by the |
---|
| 133 | client. If the client requests any Job attributes at all, there is |
---|
| 134 | a set of Job Object Attributes returned for each Job object. |
---|
| 135 | |
---|
| 136 | It is not an error for the Printer to return 0 jobs. If the |
---|
| 137 | response returns 0 jobs because there are no jobs matching the |
---|
| 138 | criteria, and the request would have returned 1 or more jobs |
---|
| 139 | with a status code of 'successful-ok' if there had been jobs |
---|
| 140 | matching the criteria, then the status code for 0 jobs MUST be |
---|
| 141 | 'successful-ok'. |
---|
| 142 | |
---|
| 143 | Group 1: Operation Attributes |
---|
| 144 | Status Message: |
---|
| 145 | In addition to the REQUIRED status code returned in |
---|
| 146 | every response, the response OPTIONALLY includes a |
---|
| 147 | 'status-message' (text(255)) and/or a |
---|
| 148 | 'detailed-status-message' (text(MAX)) operation |
---|
| 149 | attribute as described in sections 13 and 3.1.6. |
---|
| 150 | Natural Language and Character Set: |
---|
| 151 | The 'attributes-charset' and |
---|
| 152 | 'attributes-natural-language' attributes as described |
---|
| 153 | in section 3.1.4.2. |
---|
| 154 | |
---|
| 155 | Group 2: Unsupported Attributes |
---|
| 156 | See section 3.1.7 for details on returning Unsupported |
---|
| 157 | Attributes. The response NEED NOT contain the |
---|
| 158 | 'requested-attributes' operation attribute with any |
---|
| 159 | supplied values (attribute keywords) that were requested |
---|
| 160 | by the client but are not supported by the IPP object. If |
---|
| 161 | the Printer object does return unsupported attributes |
---|
| 162 | referenced in the 'requested-attributes' operation |
---|
| 163 | attribute and that attribute included group names, such as |
---|
| 164 | 'all', the unsupported attributes MUST NOT include |
---|
| 165 | attributes described in the standard but not supported by |
---|
| 166 | the implementation. |
---|
| 167 | |
---|
| 168 | Groups 3 to N: Job Object Attributes |
---|
| 169 | The Printer object responds with one set of Job Object |
---|
| 170 | Attributes for each returned Job object. The Printer |
---|
| 171 | object ignores (does not respond with) any requested |
---|
| 172 | attribute or value which is not supported or which is |
---|
| 173 | restricted by the security policy in force, including |
---|
| 174 | whether the requesting user is the user that submitted the |
---|
| 175 | job (job originating user) or not (see section |
---|
| 176 | 8). However, the Printer object MUST respond with the |
---|
| 177 | 'unknown' value for any supported attribute (including all |
---|
| 178 | REQUIRED attributes) for which the Printer object does not |
---|
| 179 | know the value, unless it would violate the security |
---|
| 180 | policy. See the description of the 'out-of- band' values |
---|
| 181 | in the beginning of Section 4.1. |
---|
| 182 | |
---|
| 183 | Jobs are returned in the following order: |
---|
| 184 | - If the client requests all 'completed' Jobs (Jobs in the |
---|
| 185 | 'completed', 'aborted', or 'canceled' states), then the |
---|
| 186 | Jobs are returned newest to oldest (with respect to |
---|
| 187 | actual completion time) |
---|
| 188 | - If the client requests all 'not-completed' Jobs (Jobs in |
---|
| 189 | the 'pending', 'processing', 'pending-held', and |
---|
| 190 | 'processing- stopped' states), then Jobs are returned in |
---|
| 191 | relative chronological order of expected time to |
---|
| 192 | complete (based on whatever scheduling algorithm is |
---|
| 193 | configured for the Printer object). |
---|
| 194 | |
---|
| 195 | """ |
---|
| 196 | |
---|
| 197 | response = make_empty_response(request) |
---|
| 198 | # XXX: we need to honor the things that the request actually asks for |
---|
| 199 | for job in jobs: |
---|
| 200 | make_job_attributes(job, request, response) |
---|
| 201 | return response |
---|