source: server/lib/gutenbach/ipp/operations.py @ 6ed9d7a

no-cups
Last change on this file since 6ed9d7a was 6ed9d7a, checked in by Jessica B. Hamrick <jhamrick@…>, 12 years ago

Add make_get_jobs_response to ipp/operations, add documentation to server/requests

  • Property mode set to 100644
File size: 11.7 KB
Line 
1from .value import Value
2from .attribute import Attribute
3from .attributegroup import AttributeGroup
4from .request import Request
5from .constants import AttributeTags, Tags
6import exceptions as err
7
8from collections import OrderedDictionary as odict
9
10def verify_operations(request):
11    """Pretty much all requests have the first attribute group for
12    operation attributes, and these all have 'attributes-charset' and
13    'attributes-natural-language' as the first two attributes.  This
14    method just generically verifies that these attributes are there.
15
16    """
17
18    # check operation attributes tag
19    op_attrs = request.attribute_groups[0]
20    if op_attrs.tag != AttributeTags.OPERATION:
21        raise err.BadRequest(
22            "Attribute group does not have OPERATION tag: 0x%x" % op_attrs.tag)
23
24    # check charset attribute
25    charset_attr = op_attrs.attributes[0]
26    if charset_attr.name != 'attributes-charset':
27        raise err.BadRequest(
28            "Attribute is not attributes-charset: %s" % charset_attr.name)
29    if len(charset_attr.values) != 1:
30        raise err.BadRequest(
31            "Too many values for attributes-charset: %d" % len(charset_attr.values))
32
33    # check charset value
34    charset_value = charset_attr.values[0]
35    if charset_value.tag != Tags.CHARSET:
36        raise err.BadRequest(
37            "Charset value does not have CHARSET tag: 0x%x" % charset_value.tag)
38    if charset_value.value != 'utf-8':
39        raise err.Charset(
40            "Invalid charset value: %s" % charset_value.value)
41
42    # check for attributes-natural-language
43    natlang_attr = op_attrs.attributes[1]
44    if natlang_attr.name != 'attributes-natural-language':
45        raise err.BadRequest(
46            "Attribute is not attributes-natural-language: %s" % natlang_attr.name)
47    if len(charset_attr.values) != 1:
48        raise err.BadRequest(
49            "Too many values for attributes-natural-language: %s" % len(natlang_attr.values))
50
51    # check natural language value
52    natlang_value = natlang_attr.values[0]
53    if natlang_value.tag != Tags.NATURAL_LANGUAGE:
54        raise err.BadRequest(
55            "Natural language value does not have NATURAL_LANGUAGE tag: 0x%x" natlang_value.tag)
56    if natlang_value.value != 'en-us':
57        raise err.Attributes(
58            "Invalid natural language value: %s" % natlang_value.value, [natlang_attr])
59
60def verify_requesting_username(requser_attr):
61    if requser_attr.tag != Tags.NAME_WITHOUT_LANGUAGE:
62        raise err.BadRequest(
63            "Requesting user name attribute tag is not NAME_WITHOUT_LANGUAGE: 0x%x" % \
64            requser_attr.tag)
65    if len(requser_attr.values) != 1:
66        raise err.BadRequest(
67            "Requesting user name attribute has too many values: %d" % len(requser_attr.values))
68    requser_value = requser_attr.values[0]
69    if requser_value.tag != Tags.NAME_WITHOUT_LANGUAGE:
70        raise err.BadRequest(
71            "Requesting user name value tag is not NAME_WITHOUT_LANGUAGE: 0x%x" % \
72            requser_value.tag)
73    return requser_value.value
74
75def verify_get_jobs_request(request):
76    """RFC 2911 3.2.6.1 Get-Jobs Request
77
78    The client submits the Get-Jobs request to a Printer object.
79   
80    The following groups of attributes are part of the Get-Jobs
81    Request:
82
83    Group 1: Operation Attributes
84        Natural Language and Character Set:
85            The 'attributes-charset' and
86            'attributes-natural-language' attributes as described
87            in section 3.1.4.1.
88        Target:
89            The 'printer-uri' (uri) operation attribute which is
90            the target for this operation as described in section
91            3.1.5.
92        Requesting User Name:
93            The 'requesting-user-name' (name(MAX)) attribute
94            SHOULD be supplied by the client as described in
95            section 8.3.
96        'limit' (integer(1:MAX)):
97            The client OPTIONALLY supplies this attribute. The
98            Printer object MUST support this attribute. It is an
99            integer value that determines the maximum number of
100            jobs that a client will receive from the Printer even
101            if 'which-jobs' or 'my-jobs' constrain which jobs are
102            returned. The limit is a 'stateless limit' in that if
103            the value supplied by the client is ’N’, then only the
104            first ’N’ jobs are returned in the Get-Jobs Response.
105            There is no mechanism to allow for the next ’M’ jobs
106            after the first ’N’ jobs. If the client does not
107            supply this attribute, the Printer object responds
108            with all applicable jobs.
109        'requested-attributes' (1setOf type2 keyword):
110            The client OPTIONALLY supplies this attribute. The
111            Printer object MUST support this attribute. It is a
112            set of Job attribute names and/or attribute groups
113            names in whose values the requester is
114            interested. This set of attributes is returned for
115            each Job object that is returned. The allowed
116            attribute group names are the same as those defined in
117            the Get-Job-Attributes operation in section 3.3.4. If
118            the client does not supply this attribute, the Printer
119            MUST respond as if the client had supplied this
120            attribute with two values: ’job-uri’ and ’job-id’.
121        'which-jobs' (type2 keyword):
122            The client OPTIONALLY supplies this attribute. The
123            Printer object MUST support this attribute. It
124            indicates which Job objects MUST be returned by the
125            Printer object. The values for this attribute are:
126             - ’completed’: This includes any Job object whose
127               state is ’completed’, ’canceled’, or ’aborted’.
128             - ’not-completed’: This includes any Job object whose
129               state is ’pending’, ’processing’,
130               ’processing-stopped’, or ’pending-held’.
131            A Printer object MUST support both values. However, if
132            the implementation does not keep jobs in the
133            ’completed’, ’canceled’, and ’aborted’ states, then it
134            returns no jobs when the ’completed’ value is
135            supplied.  If a client supplies some other value, the
136            Printer object MUST copy the attribute and the
137            unsupported value to the Unsupported Attributes
138            response group, reject the request, and return the
139            ’client-error-attributes-or-values-not-supported’
140            status code.  If the client does not supply this
141            attribute, the Printer object MUST respond as if the
142            client had supplied the attribute with a value of
143            ’not-completed’.
144        'my-jobs' (boolean):
145            The client OPTIONALLY supplies this attribute. The
146            Printer object MUST support this attribute. It
147            indicates whether jobs from all users or just the jobs
148            submitted by the requesting user of this request MUST
149            be considered as candidate jobs to be returned by the
150            Printer object. If the client does not supply this
151            attribute, the Printer object MUST respond as if the
152            client had supplied the attribute with a value of
153            ’false’, i.e., jobs from all users. The means for
154            authenticating the requesting user and matching the
155            jobs is described in section 8.
156
157    """
158
159    # generic operations verification
160    verify_operations(request)
161
162    # requesting username
163    requser = verify_requesting_username(request.attributes[2])
164    out = {'requesting-user-name': requser}
165
166    # make the rest of the attributes into a dictionary
167    attrs = dict([(attr.name, attr.values) for attr in request.attributes[3:]])
168   
169    if 'limit' in attrs:
170        out['limit'] = None # XXX
171
172    if 'requested-attributes' in attrs:
173        out['requested-attributes'] = None # XXX
174
175    if 'which-jobs' in attrs:
176        out['which-jobs'] = None # XXX
177
178    if 'my-jobs' in attrs:
179        out['my-jobs'] = None # XXX
180
181    return out
182
183def make_get_jobs_response(self, request):
184    """3.2.6.2 Get-Jobs Response
185       
186    The Printer object returns all of the Job objects up to the number
187    specified by the 'limit' attribute that match the criteria as
188    defined by the attribute values supplied by the client in the
189    request. It is possible that no Job objects are returned since
190    there may literally be no Job objects at the Printer, or there may
191    be no Job objects that match the criteria supplied by the
192    client. If the client requests any Job attributes at all, there is
193    a set of Job Object Attributes returned for each Job object.
194
195    It is not an error for the Printer to return 0 jobs. If the
196    response returns 0 jobs because there are no jobs matching the
197    criteria, and the request would have returned 1 or more jobs
198    with a status code of ’successful-ok’ if there had been jobs
199    matching the criteria, then the status code for 0 jobs MUST be
200    ’successful-ok’.
201
202    Group 1: Operation Attributes
203        Status Message:
204            In addition to the REQUIRED status code returned in
205            every response, the response OPTIONALLY includes a
206            'status-message' (text(255)) and/or a
207            'detailed-status-message' (text(MAX)) operation
208            attribute as described in sections 13 and 3.1.6.
209        Natural Language and Character Set:
210            The 'attributes-charset' and
211            'attributes-natural-language' attributes as described
212            in section 3.1.4.2.
213
214    Group 2: Unsupported Attributes
215        See section 3.1.7 for details on returning Unsupported
216        Attributes.  The response NEED NOT contain the
217        'requested-attributes' operation attribute with any
218        supplied values (attribute keywords) that were requested
219        by the client but are not supported by the IPP object.  If
220        the Printer object does return unsupported attributes
221        referenced in the 'requested-attributes' operation
222        attribute and that attribute included group names, such as
223        ’all’, the unsupported attributes MUST NOT include
224        attributes described in the standard but not supported by
225        the implementation.
226
227    Groups 3 to N: Job Object Attributes
228        The Printer object responds with one set of Job Object
229        Attributes for each returned Job object. The Printer
230        object ignores (does not respond with) any requested
231        attribute or value which is not supported or which is
232        restricted by the security policy in force, including
233        whether the requesting user is the user that submitted the
234        job (job originating user) or not (see section
235        8). However, the Printer object MUST respond with the
236        ’unknown’ value for any supported attribute (including all
237        REQUIRED attributes) for which the Printer object does not
238        know the value, unless it would violate the security
239        policy. See the description of the 'out-of- band' values
240        in the beginning of Section 4.1.
241
242        Jobs are returned in the following order:
243        - If the client requests all ’completed’ Jobs (Jobs in the
244          ’completed’, ’aborted’, or ’canceled’ states), then the
245          Jobs are returned newest to oldest (with respect to
246          actual completion time)
247        - If the client requests all ’not-completed’ Jobs (Jobs in
248          the ’pending’, ’processing’, ’pending-held’, and
249          ’processing- stopped’ states), then Jobs are returned in
250          relative chronological order of expected time to
251          complete (based on whatever scheduling algorithm is
252          configured for the Printer object).
253
254    """
255
256    pass
Note: See TracBrowser for help on using the repository browser.