Example #1
0
    def decode(self, file):
        iBeforeDecode = file.tell()
        headerParams = self.decodeHeader(file)
        pduKlass = operations.getPDUClass(headerParams['command_id'])
        pdu = pduKlass(headerParams['sequence_number'],
                       headerParams['command_status'])
        self.decodeBody(file, pdu,
                        headerParams['command_length'] - self.HEADER_LEN)

        iAfterDecode = file.tell()
        parsedLen = iAfterDecode - iBeforeDecode
        # Jasmin update:
        # Related to #124, don't error if parsedLen is greater than command_length,
        # there can be some padding in PDUs, this is a fix to be confirmed for stability
        if headerParams['command_length'] > parsedLen:
            padBytes = file.read(headerParams['command_length'] - parsedLen)
            if len(padBytes) != headerParams['command_length'] - parsedLen:
                raise PDUCorruptError(
                    "Invalid command length: expected %d, parsed %d, padding bytes not found"
                    % (headerParams['command_length'], parsedLen),
                    pdu_types.CommandStatus.ESME_RINVCMDLEN)
        elif parsedLen < headerParams['command_length']:
            raise PDUCorruptError(
                "Invalid command length: expected %d, parsed %d" %
                (headerParams['command_length'], parsedLen),
                pdu_types.CommandStatus.ESME_RINVCMDLEN)

        return pdu
Example #2
0
 def read(self, file, size):
     bytesRead = file.read(size)
     length = len(bytesRead)
     if length == 0:
         raise PDUCorruptError("Unexpected EOF", pdu_types.CommandStatus.ESME_RINVMSGLEN)
     if length != size:
         raise PDUCorruptError("Length mismatch. Expecting %d bytes. Read %d" % (size, length), pdu_types.CommandStatus.ESME_RINVMSGLEN)
     return bytesRead
Example #3
0
 def decodeHeader(self, file):
     headerParams = self.decodeRequiredParams(self.HeaderParams,
                                              self.HeaderEncoders, file)
     if headerParams['command_length'] < self.HEADER_LEN:
         raise PDUCorruptError(
             "Invalid command_length %d" % headerParams['command_length'],
             pdu_types.CommandStatus.ESME_RINVCMDLEN)
     return headerParams
Example #4
0
    def decode(self, file):
        iBeforeDecode = file.tell()
        headerParams = self.decodeHeader(file)
        pduKlass = operations.getPDUClass(headerParams['command_id'])
        pdu = pduKlass(headerParams['sequence_number'],
                       headerParams['command_status'])
        self.decodeBody(file, pdu,
                        headerParams['command_length'] - self.HEADER_LEN)

        iAfterDecode = file.tell()
        parsedLen = iAfterDecode - iBeforeDecode
        if parsedLen != headerParams['command_length']:
            raise PDUCorruptError(
                "Invalid command length: expected %d, parsed %d" %
                (headerParams['command_length'], parsedLen),
                pdu_types.CommandStatus.ESME_RINVCMDLEN)

        return pdu