Changeset cad7502


Ignore:
Timestamp:
Dec 20, 2011, 2:19:43 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
ef8df33
Parents:
6effd50
git-author:
Jessica B. Hamrick <jhamrick@…> (12/20/11 14:19:43)
git-committer:
Jessica B. Hamrick <jhamrick@…> (12/20/11 14:19:43)
Message:

Fix bugs; can now again do 'lpq' and get back a reasonable response

Location:
server/lib/gutenbach
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/ipp/attribute.py

    rf6c6897 rcad7502  
    9393                name_length = 0
    9494
    95             # get the value length and binary value
     95            logger.debug("dumping name : %s" % self.name)
     96            logger.debug("dumping name_length : %i" % name_length)
     97            logger.debug("value tag : 0x%x" % v.tag)
     98
     99            # get the binary value
    96100            value_bin = v.packed_value
     101            # get the value length
    97102            value_length = len(value_bin)
    98103
    99             logger.debug("dumping name_length : %i" % name_length)
    100             logger.debug("dumping name : %s" % self.name)
     104            logger.debug("dumping value : %s" % v.value)
    101105            logger.debug("dumping value_length : %i" % value_length)
    102             logger.debug("dumping value (0x%x): %s" % (v.tag, v.value))
    103106
    104107            # the value tag in binary
  • server/lib/gutenbach/ipp/operations.py

    rf6c6897 rcad7502  
    55from .constants import AttributeTags, StatusCodes, operations_attribute_value_tags
    66import exceptions as err
     7import logging
     8
     9logger = logging.getLogger(__name__)
    710
    811def verify_operations(request):
     
    1417    """
    1518
     19    # XXX: check version
     20    if False:
     21        raise err.VersionNotSupported(str(request.version))
     22
     23    # check operation id
     24    if False:
     25        raise err.OperationNotSupported(str(request.operation_id))
     26
    1627    # check operation attributes tag
    1728    op_attrs = request.attribute_groups[0]
     
    2031            "Attribute group does not have OPERATION tag: 0x%x" % op_attrs.tag)
    2132
    22     # XXX: check version
    23     if False:
    24         raise err.VersionNotSupported(str(request.version))
    25 
    26     # check operation id
    27     if False:
    28         raise err.OperationNotSupported(str(request.operation_id))
    29 
    3033    # # check compression
    3134    # if False:
     
    4851        raise err.BadRequest(
    4952            "Too many values for attributes-charset: %d" % len(charset_attr.values))
    50 
    5153    # check charset value
    5254    charset_value = charset_attr.values[0]
     
    6567        raise err.BadRequest(
    6668            "Too many values for attributes-natural-language: %s" % len(natlang_attr.values))
    67 
    6869    # check natural language value
    6970    natlang_value = natlang_attr.values[0]
     
    7576            "Invalid natural language value: %s" % natlang_value.value, [natlang_attr])
    7677
    77 def verify_printer_uri(uri_attr):
    78     if uri_attr.name != 'printer-uri':
    79         raise err.BadRequest(
    80             "Unexpected name for attribute 'printer-uri': %s" % uri_attr.name)
    81     if len(uri_attr.values) != 1:
    82         raise err.BadRequest(
    83             "Requesting printer uri attribute has too many values: %d" % len(uri_attr.values))
    84     printer_name_value = uri_attr.values[0]
    85     if printer_name_value.tag != operations_attribute_value_tags['printer-uri']:
    86         raise err.BadRequest(
    87             "Bad value tag (expected URI): 0x%x" % printer_name_value_tag)
     78    return dict([(attr.name, attr.values) for attr in op_attrs.attributes])
     79
     80def verify_printer_uri(values):
     81    if len(values) != 1:
     82        raise err.BadRequest(
     83            "Requesting printer uri attribute has too many values: %d" % len(values))
     84    uri_value = values[0]
     85    if uri_value.tag != operations_attribute_value_tags['printer-uri']:
     86        raise err.BadRequest(
     87            "Bad value tag (expected URI): 0x%x" % uri_value_tag)
    8888   
    8989    # actually get the printer name
    90     printer_name_value = printer_name_attr.values[0].value
    9190    # XXX: hack -- CUPS will strip the port from the request, so
    9291    # we can't do an exact comparison (also the hostname might be
    9392    # different, depending on the CNAME or whether it's localhost)
    94     printer_name = printer_name_value.split("/")[-1]
    95     return printer_name
    96 
    97 def verify_requesting_username(requser_attr):
    98     if requser_attr.name != 'requesting-user-name':
    99         raise err.BadRequest(
    100             "Unexpected name for attribute 'requesting-user-name': %s" % requser_attr.name)
    101     if len(requser_attr.values) != 1:
    102         raise err.BadRequest(
    103             "Requesting user name attribute has too many values: %d" % len(requser_attr.values))
    104     requser_value = requser_attr.values[0]
     93    uri = uri_value.value.split("/")[-1]
     94    return uri
     95
     96def verify_requesting_username(values):
     97    if len(values) != 1:
     98        raise err.BadRequest(
     99            "Requesting user name attribute has too many values: %d" % len(values))
     100    requser_value = values[0]
    105101    if requser_value.tag != operations_attribute_value_tags['requesting-user-name']:
    106102        raise err.BadRequest(
     
    221217    """
    222218
     219    out = {}
    223220
    224221    # generic operations verification
    225     verify_operations(request)
     222    attrs = verify_operations(request)
     223
    226224    # requested printer uri
    227     printeruri = verify_printer_uri(request.attribute_groups[0].attributes[2])
     225    if 'printer-uri' not in attrs:
     226        raise err.BadRequest("Missing 'printer-uri' attribute")
     227    out['printer-uri'] = verify_printer_uri(attrs['printer-uri'])
     228   
    228229    # requesting username
    229     requser = verify_requesting_username(request.attribute_groups[0].attributes[3])
    230     # make the rest of the attributes into a dictionary
    231     attrs = dict([(attr.name, attr.values) for attr in request.attributes[4:]])
    232    
    233     out = {
    234         'printer-uri': printeruri,
    235         'requesting-user-name': requser
    236         }
     230    if 'requesting-user-name' not in attrs:
     231        logger.warning("Missing 'requesting-user-name' attribute")
     232    else:
     233        out['requesting-user-name'] = verify_requesting_username(attrs['requesting-user-name'])
    237234
    238235    if 'limit' in attrs:
     
    324321
    325322    pass
     323
     324## GET-PRINTER-ATTRIBUTES
     325
     326def verify_get_printer_attributes_request(request):
     327    """RFC 2911: 3.2.5.1 Get-Printer-Attributes Request
     328
     329    The following sets of attributes are part of the Get-Printer-
     330    Attributes Request:
     331
     332    Group 1: Operation Attributes
     333        Natural Language and Character Set:
     334            The 'attributes-charset' and 'attributes-natural-language'
     335            attributes as described in section 3.1.4.1.
     336        Target:
     337            The 'printer-uri' (uri) operation attribute which is the
     338            target for this operation as described in section 3.1.5.
     339        Requesting User Name:
     340            The 'requesting-user-name' (name(MAX)) attribute SHOULD be
     341            supplied by the client as described in section 8.3.
     342        'requested-attributes' (1setOf keyword):
     343            The client OPTIONALLY supplies a set of attribute names
     344            and/or attribute group names in whose values the requester
     345            is interested. The Printer object MUST support this
     346            attribute.  If the client omits this attribute, the
     347            Printer MUST respond as if this attribute had been
     348            supplied with a value of 'all'.
     349        'document-format' (mimeMediaType):
     350            The client OPTIONALLY supplies this attribute. The Printer
     351            object MUST support this attribute. This attribute is
     352            useful for a Printer object to determine the set of
     353            supported attribute values that relate to the requested
     354            document format.  The Printer object MUST return the
     355            attributes and values that it uses to validate a job on a
     356            create or Validate-Job operation in which this document
     357            format is supplied. The Printer object SHOULD return only
     358            (1) those attributes that are supported for the specified
     359            format and (2) the attribute values that are supported for
     360            the specified document format. By specifying the document
     361            format, the client can get the Printer object to eliminate
     362            the attributes and values that are not supported for a
     363            specific document format. For example, a Printer object
     364            might have multiple interpreters to support both
     365            'application/postscript' (for PostScript) and 'text/plain'
     366            (for text) documents. However, for only one of those
     367            interpreters might the Printer object be able to support
     368            'number-up' with values of '1', '2', and '4'. For the
     369            other interpreter it might be able to only support
     370            'number-up' with a value of '1'.  Thus a client can use
     371            the Get-Printer-Attributes operation to obtain the
     372            attributes and values that will be used to accept/reject a
     373            create job operation.
     374
     375            If the Printer object does not distinguish between
     376            different sets of supported values for each different
     377            document format when validating jobs in the create and
     378            Validate-Job operations, it MUST NOT distinguish between
     379            different document formats in the Get-Printer-Attributes
     380            operation. If the Printer object does distinguish between
     381            different sets of supported values for each different
     382            document format specified by the client, this
     383            specialization applies only to the following Printer
     384            object attributes:
     385
     386            - Printer attributes that are Job Template attributes
     387              ('xxx- default' 'xxx-supported', and 'xxx-ready' in the
     388              Table in Section 4.2),
     389
     390            - 'pdl-override-supported',
     391            - 'compression-supported',
     392            - 'job-k-octets-supported',
     393            - 'job-impressions-supported',
     394            - 'job-media-sheets-supported',
     395            - 'printer-driver-installer',
     396            - 'color-supported', and
     397            - 'reference-uri-schemes-supported'
     398
     399            The values of all other Printer object attributes
     400            (including 'document-format-supported') remain invariant
     401            with respect to the client supplied document format
     402            (except for new Printer description attribute as
     403            registered according to section 6.2).
     404
     405            If the client omits this 'document-format' operation
     406            attribute, the Printer object MUST respond as if the
     407            attribute had been supplied with the value of the Printer
     408            object's 'document-format- default' attribute. It is
     409            RECOMMENDED that the client always supply a value for
     410            'document-format', since the Printer object's
     411            'document-format-default' may be
     412            'application/octet-stream', in which case the returned
     413            attributes and values are for the union of the document
     414            formats that the Printer can automatically sense.  For
     415            more details, see the description of the 'mimeMediaType'
     416            attribute syntax in section 4.1.9.
     417
     418            If the client supplies a value for the 'document-format'
     419            Operation attribute that is not supported by the Printer,
     420            i.e., is not among the values of the Printer object's
     421            'document-format-supported' attribute, the Printer object
     422            MUST reject the operation and return the
     423            'client-error-document-format-not-supported' status code.
     424
     425    """
     426
     427    out = {}
     428
     429    # generic operations verification
     430    attrs = verify_operations(request)
     431
     432    # requested printer uri
     433    if 'printer-uri' not in attrs:
     434        raise err.BadRequest("Missing 'printer-uri' attribute")
     435    out['printer-uri']  = verify_printer_uri(attrs['printer-uri'])
     436
     437    # requesting username
     438    if 'requesting-user-name' not in attrs:
     439        logger.warning("Missing 'requesting-user-name' attribute")
     440    else:
     441        out['requesting-user-name'] = verify_requesting_username(attrs['requesting-user-name'])
     442
     443    if 'requested-attributes' in attrs:
     444        out['requested-attributes'] = None # XXX
     445
     446    if 'document-format' in attrs:
     447        out['document-format'] = None # XXX
     448
     449    return out
     450
     451
     452def make_get_printer_attributes_response(self, request):
     453    """3.2.5.2 Get-Printer-Attributes Response
     454
     455    The Printer object returns the following sets of attributes as
     456    part of the Get-Printer-Attributes Response:
     457
     458    Group 1: Operation Attributes
     459        Status Message:
     460            In addition to the REQUIRED status code returned in every
     461            response, the response OPTIONALLY includes a
     462            'status-message' (text(255)) and/or a
     463            'detailed-status-message' (text(MAX)) operation attribute
     464            as described in sections 13 and 3.1.6.
     465        Natural Language and Character Set:
     466            The 'attributes-charset' and 'attributes-natural-language'
     467            attributes as described in section 3.1.4.2.
     468
     469    Group 2: Unsupported Attributes
     470        See section 3.1.7 for details on returning Unsupported
     471        Attributes.  The response NEED NOT contain the
     472        'requested-attributes' operation attribute with any supplied
     473        values (attribute keywords) that were requested by the client
     474        but are not supported by the IPP object.  If the Printer
     475        object does return unsupported attributes referenced in the
     476        'requested-attributes' operation attribute and that attribute
     477        included group names, such as 'all', the unsupported
     478        attributes MUST NOT include attributes described in the
     479        standard but not supported by the implementation.
     480
     481    Group 3: Printer Object Attributes
     482        This is the set of requested attributes and their current
     483        values.  The Printer object ignores (does not respond with)
     484        any requested attribute which is not supported. The Printer
     485        object MAY respond with a subset of the supported attributes
     486        and values, depending on the security policy in
     487        force. However, the Printer object MUST respond with the
     488        'unknown' value for any supported attribute (including all
     489        REQUIRED attributes) for which the Printer object does not
     490        know the value. Also the Printer object MUST respond with the
     491        'no-value' for any supported attribute (including all REQUIRED
     492        attributes) for which the system administrator has not
     493        configured a value. See the description of the 'out-of-band'
     494        values in the beginning of Section 4.1.
     495
     496    """
     497    pass
  • server/lib/gutenbach/server/printer.py

    r6effd50 rcad7502  
    9393    @property
    9494    def printer_state(self):
    95         return self.state
     95        return 3 # idle
    9696
    9797    @property
     
    106106    @property
    107107    def operations_supported(self):
    108         return "get-jobs"
     108        return 0xa # get-jobs
    109109
    110110    @property
  • server/lib/gutenbach/server/requests.py

    r6effd50 rcad7502  
    125125    @handler_for(const.Operations.GET_PRINTER_ATTRIBUTES)
    126126    def get_printer_attributes(self, request, response):
     127        """RFC 2911: 3.2.5 Get-Printer-Attributes Operation
     128
     129        This REQUIRED operation allows a client to request the values
     130        of the attributes of a Printer object.
     131       
     132        In the request, the client supplies the set of Printer
     133        attribute names and/or attribute group names in which the
     134        requester is interested. In the response, the Printer object
     135        returns a corresponding attribute set with the appropriate
     136        attribute values filled in.
     137
     138        For Printer objects, the possible names of attribute groups are:
     139       
     140        - 'job-template': the subset of the Job Template attributes
     141          that apply to a Printer object (the last two columns of the
     142          table in Section 4.2) that the implementation supports for
     143          Printer objects.
     144
     145        - 'printer-description': the subset of the attributes
     146          specified in Section 4.4 that the implementation supports
     147          for Printer objects.
     148
     149        - 'all': the special group 'all' that includes all attributes
     150          that the implementation supports for Printer objects.
     151       
     152        Since a client MAY request specific attributes or named
     153        groups, there is a potential that there is some overlap. For
     154        example, if a client requests, 'printer-name' and 'all', the
     155        client is actually requesting the 'printer-name' attribute
     156        twice: once by naming it explicitly, and once by inclusion in
     157        the 'all' group. In such cases, the Printer object NEED NOT
     158        return each attribute only once in the response even if it is
     159        requested multiple times. The client SHOULD NOT request the
     160        same attribute in multiple ways.
     161
     162        It is NOT REQUIRED that a Printer object support all
     163        attributes belonging to a group (since some attributes are
     164        OPTIONAL). However, it is REQUIRED that each Printer object
     165        support all group names.
     166
     167        """
     168
    127169        # this is just like cups_get_default, except the printer name
    128170        # is given
Note: See TracChangeset for help on using the changeset viewer.