Changeset 89fe6da


Ignore:
Timestamp:
Mar 5, 2011, 5:33:55 PM (13 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
574aee4
Parents:
aaa1da3
git-author:
Jessica B. Hamrick <jhamrick@…> (03/05/11 17:33:55)
git-committer:
Jessica B. Hamrick <jhamrick@…> (03/05/11 17:33:55)
Message:

Add 'length' keyword to IPPRequest constructor

Location:
server/lib
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • server/lib/ipprequest.py

    raaa1da3 r89fe6da  
    420420    # can be read from to get the request
    421421    def __init__(self, version=None, operation_id=None, request_id=None,
    422                  attribute_groups=[], data=None, request=None):
     422                 attribute_groups=[], data=None, request=None, length=sys.maxint):
    423423        """
    424424        Create an IPPRequest.  Takes either the segments of the
     
    469469            # read the version-number (two signed chars)
    470470            self.version        = struct.unpack('>bb', request.read(2))
     471            length -= 2
    471472            logger.debug("version-number : (0x%X, 0x%X)" % self.version)
    472473
     
    474475            # for a response) (signed short)
    475476            self.operation_id   = struct.unpack('>h', request.read(2))[0]
     477            length -= 2
    476478            logger.debug("operation-id : 0x%X" % self.operation_id)
    477479
    478480            # read the request-id (signed int)
    479481            self.request_id     = struct.unpack('>i', request.read(4))[0]
     482            length -= 4
    480483            logger.debug("request-id : 0x%X" % self.request_id)
    481484
     
    486489            # read in the next byte
    487490            next_byte = struct.unpack('>b', request.read(1))[0]
     491            length -=1
    488492            logger.debug("next byte : 0x%X" % next_byte)
    489493
     
    498502
    499503                next_byte = struct.unpack('>b', request.read(1))[0]
     504                length -= 1
    500505                logger.debug("next byte : 0x%X" % next_byte)
    501506
     
    508513                    # read in the length of the name (signed short)
    509514                    name_length   = struct.unpack('>h', request.read(2))[0]
     515                    length -= 2
    510516                    logger.debug("name-length : %i" % name_length)
    511517                   
     
    513519                        # read the name (a string of name_length bytes)
    514520                        name          = request.read(name_length)
     521                        length -= name_length
    515522                        logger.debug("name : %s" % name)
    516523                   
    517524                        # read in the length of the value (signed short)
    518525                        value_length  = struct.unpack('>h', request.read(2))[0]
     526                        length -= 2
    519527                        logger.debug("value-length : %i" % value_length)
    520528                   
    521529                        # read in the value (string of value_length bytes)
    522530                        value         = request.read(value_length)
    523 
     531                        length -= value_length
     532                       
    524533                        ippvalue = IPPValue(value_tag, value)
    525534                        logger.debug("value : %s" % ippvalue.value)
     
    532541                        # read in the length of the value (signed short)
    533542                        value_length  = struct.unpack('>h', request.read(2))[0]
     543                        length -= 2
    534544                        logger.debug("value-length : %i" % value_length)
    535545                   
    536546                        # read in the value (string of value_length bytes)
    537547                        value         = request.read(value_length)
     548                        length -= value_length
    538549
    539550                        ippvalue = IPPValue(value_tag, value)
     
    545556                    # read another byte
    546557                    next_byte = struct.unpack('>b', request.read(1))[0]
     558                    length -= 1
    547559
    548560                self.attribute_groups.append(IPPAttributeGroup(attribute_group_tag, attributes))
     
    550562            # once we hit the end-of-attributes tag, the only thing
    551563            # left is the data, so go ahead and read all of it
    552             self.data = request.read()
     564            assert length >= 0
     565            self.data = request.read(length)
    553566            logger.debug("data : %s" % self.data)
    554567
  • server/lib/server.py

    r478ca74 r89fe6da  
    1717
    1818    def handle_ipp(self):
    19         req = ipprequest.IPPRequest(request=self.rfile, length=self.headers.getheader('content-length', 0))
     19        req = ipprequest.IPPRequest(request=self.rfile,
     20                                    length=self.headers.getheader('content-length', 0))
    2021
    2122        self.send_response(200, "o hai")
Note: See TracChangeset for help on using the changeset viewer.