Exemplo n.º 1
0
    def _decode(self, bytes):
        intVal = Int1Encoder()._decode(bytes)
        receiptVal = intVal & self.receiptMask
        smeOriginatedAcksVal = intVal & self.smeOriginatedAcksMask
        intermediateNotificationVal = intVal & self.intermediateNotificationMask

        if receiptVal not in constants.registered_delivery_receipt_value_map:
            raise PDUParseError(
                "Unknown registered_delivery receipt %s" % receiptVal,
                pdu_types.CommandStatus.ESME_RINVREGDLVFLG)

        receiptName = constants.registered_delivery_receipt_value_map[
            receiptVal]
        smeOriginatedAckNames = [
            constants.registered_delivery_sme_originated_acks_value_map[aVal]
            for aVal in
            constants.registered_delivery_sme_originated_acks_value_map.keys()
            if aVal & smeOriginatedAcksVal
        ]

        receipt = getattr(pdu_types.RegisteredDeliveryReceipt, receiptName)
        smeOriginatedAcks = [
            getattr(pdu_types.RegisteredDeliverySmeOriginatedAcks, aName)
            for aName in smeOriginatedAckNames
        ]
        intermediateNotification = False
        if intermediateNotificationVal:
            intermediateNotification = True

        return pdu_types.RegisteredDelivery(receipt, smeOriginatedAcks,
                                            intermediateNotification)
Exemplo n.º 2
0
    def _decode(self, bytes):
        if len(bytes) < 2:
            raise PDUParseError("Invalid subaddress size %s" % len(bytes), pdu_types.CommandStatus.ESME_RINVOPTPARAMVAL)

        typeTag = self.typeTagEncoder._decode(bytes[0])
        value = OctetStringEncoder(self.getSize() - 1)._decode(bytes[1:])
        return pdu_types.Subaddress(typeTag, value)
Exemplo n.º 3
0
 def _decode(self, bytes):
     intval = Int4Encoder()._decode(bytes)
     if intval not in constants.command_status_value_map:
         raise PDUParseError("Unknown command_status %s" % intval,
                             pdu_types.CommandStatus.ESME_RUNKNOWNERR)
     name = constants.command_status_value_map[intval]['name']
     return getattr(pdu_types.CommandStatus, name)
Exemplo n.º 4
0
    def _decode(self, bytes):
        if len(bytes) != 3:
            raise PDUParseError(
                "Invalid network_error_code size %s" % len(bytes),
                pdu_types.CommandStatus.ESME_RINVOPTPARAMVAL)

        errorCodeType = self.networkErrorCodeTypeEncoder._decode(bytes[0])
        errorCode = self.errorCodeEncoder._decode(bytes[1:])
        return pdu_types.NetworkErrorCode(errorCodeType, errorCode)
Exemplo n.º 5
0
 def _decode(self, bytes):
     if len(bytes) < 3:
         raise PDUParseError("Invalid callback_num size %s" % len(bytes), pdu_types.CommandStatus.ESME_RINVOPTPARAMVAL)
     
     digitModeIndicator = self.digitModeIndicatorEncoder._decode(bytes[0])
     ton = self.tonEncoder._decode(bytes[1])
     npi = self.npiEncoder._decode(bytes[2])
     digits = bytes[3:]
     return pdu_types.CallbackNum(digitModeIndicator, ton, npi, digits)
Exemplo n.º 6
0
 def decodeOptionalParams(self, paramList, file, optionsLength):
     optionalParams = {}
     iBefore = file.tell()
     while file.tell() - iBefore < optionsLength:
         option = self.optionEncoder.decode(file)
         optionName = str(option.tag)
         if optionName not in paramList:
             raise PDUParseError("Invalid option %s" % optionName, pdu_types.CommandStatus.ESME_ROPTPARNOTALLWD)
         optionalParams[optionName] = option.value
     return optionalParams
Exemplo n.º 7
0
 def decode(self, file):
     bytes = self._read(file)
     if self.decodeNull:
         if self.nullHex is None:
             raise NotImplementedError("No value for null")
         if self.nullHex == binascii.b2a_hex(bytes):
             return None
         if self.requireNull:
             raise PDUParseError("Field must be null", pdu_types.CommandStatus.ESME_RUNKNOWNERR)
     return self._decode(bytes)
Exemplo n.º 8
0
 def _decode(self, bytes):
     intVal = Int1Encoder()._decode(bytes)
     modeVal = intVal & self.modeMask
     typeVal = intVal & self.typeMask
     gsmFeaturesVal = intVal & self.gsmFeaturesMask
     
     if modeVal not in constants.esm_class_mode_value_map:
         raise PDUParseError("Unknown esm_class mode %s" % modeVal, pdu_types.CommandStatus.ESME_RINVESMCLASS)
     if typeVal not in constants.esm_class_type_value_map:
         raise PDUParseError("Unknown esm_class type %s" % typeVal, pdu_types.CommandStatus.ESME_RINVESMCLASS)
     
     modeName = constants.esm_class_mode_value_map[modeVal]
     typeName = constants.esm_class_type_value_map[typeVal]
     gsmFeatureNames = [constants.esm_class_gsm_features_value_map[fVal] for fVal in constants.esm_class_gsm_features_value_map.keys() if fVal & gsmFeaturesVal]
     
     mode = getattr(pdu_types.EsmClassMode, modeName)
     type = getattr(pdu_types.EsmClassType, typeName)
     gsmFeatures = [getattr(pdu_types.EsmClassGsmFeatures, fName) for fName in gsmFeatureNames]
     
     return pdu_types.EsmClass(mode, type, gsmFeatures)
Exemplo n.º 9
0
    def decode(self, file):
        # Jasmin update: bypass vendor specific tags
        tag = TagEncoder().decode(file)
        self.length = Int2Encoder().decode(file)
        if tag not in self.options:
            raise PDUParseError("Optional param %s unknown" % tag, pdu_types.CommandStatus.ESME_ROPTPARNOTALLWD)
        encoder = self.options[tag]
        iBeforeDecode = file.tell()
        value = None
        try:
            value = encoder.decode(file)
        except PDUParseError as e:
            e.status = pdu_types.CommandStatus.ESME_RINVOPTPARAMVAL
            raise e

        iAfterDecode = file.tell()
        parseLen = iAfterDecode - iBeforeDecode
        if parseLen != self.length:
            raise PDUParseError("Invalid option length: labeled [%d] but parsed [%d]" % (self.length, parseLen),
                                pdu_types.CommandStatus.ESME_RINVPARLEN)
        return pdu_types.Option(tag, value)
Exemplo n.º 10
0
 def decode(self, file):
     tag = TagEncoder().decode(file)
     self.length = Int2Encoder().decode(file)
     if tag not in self.options:
         raise PDUParseError("Optional param %s unknown" % tag, pdu_types.CommandStatus.ESME_ROPTPARNOTALLWD)
     encoder = self.options[tag]
     iBeforeDecode = file.tell()
     value = None
     try:
         value = encoder.decode(file)
     except PDUParseError, e:
         e.status = pdu_types.CommandStatus.ESME_RINVOPTPARAMVAL
         raise e
Exemplo n.º 11
0
    def decodeOptionalParams(self, paramList, file, optionsLength):
        optionalParams = {}
        iBefore = file.tell()
        while file.tell() - iBefore < optionsLength:
            option = self.optionEncoder.decode(file)
            optionName = option.tag.name

            # Jasmin update:
            # Silently drop vendor_specific_bypass optional param
            if optionName == 'vendor_specific_bypass':
                continue
            elif optionName not in paramList:
                raise PDUParseError("Invalid option %s" % optionName, pdu_types.CommandStatus.ESME_ROPTPARNOTALLWD)
            optionalParams[optionName] = option.value
        return optionalParams
Exemplo n.º 12
0
class OptionEncoder(IEncoder):
    def __init__(self):
        from smpp.pdu.pdu_types import Tag as T
        self.length = None
        self.options = {
            T.dest_addr_subunit:
            AddrSubunitEncoder(),
            T.source_addr_subunit:
            AddrSubunitEncoder(),
            T.dest_network_type:
            NetworkTypeEncoder(),
            T.source_network_type:
            NetworkTypeEncoder(),
            T.dest_bearer_type:
            BearerTypeEncoder(),
            T.source_bearer_type:
            BearerTypeEncoder(),
            T.dest_telematics_id:
            Int2Encoder(),
            T.source_telematics_id:
            Int2Encoder(),
            T.qos_time_to_live:
            Int4Encoder(),
            T.payload_type:
            PayloadTypeEncoder(),
            T.additional_status_info_text:
            COctetStringEncoder(256),
            T.receipted_message_id:
            COctetStringEncoder(65),
            # T.ms_msg_wait_facilities: TODO(),
            T.privacy_indicator:
            PrivacyIndicatorEncoder(),
            T.source_subaddress:
            SubaddressEncoder(self.getLength),
            T.dest_subaddress:
            SubaddressEncoder(self.getLength),
            T.user_message_reference:
            Int2Encoder(),
            T.user_response_code:
            Int1Encoder(),
            T.language_indicator:
            LanguageIndicatorEncoder(),
            T.source_port:
            Int2Encoder(),
            T.destination_port:
            Int2Encoder(),
            T.sar_msg_ref_num:
            Int2Encoder(),
            T.sar_total_segments:
            Int1Encoder(),
            T.sar_segment_seqnum:
            Int1Encoder(),
            T.sc_interface_version:
            Int1Encoder(),
            T.display_time:
            DisplayTimeEncoder(),
            #T.ms_validity: MsValidityEncoder(),
            #T.dpf_result: DpfResultEncoder(),
            #T.set_dpf: SetDpfEncoder(),
            T.ms_availability_status:
            MsAvailabilityStatusEncoder(),
            T.network_error_code:
            NetworkErrorCodeEncoder(self.getLength),
            T.message_payload:
            OctetStringEncoder(self.getLength),
            T.delivery_failure_reason:
            DeliveryFailureReasonEncoder(),
            T.more_messages_to_send:
            MoreMessagesToSendEncoder(),
            T.message_state:
            MessageStateEncoder(),
            T.callback_num:
            CallbackNumEncoder(self.getLength),
            #T.callback_num_pres_ind: CallbackNumPresIndEncoder(),
            # T.callback_num_atag: CallbackNumAtag(),
            T.number_of_messages:
            Int1Encoder(max=99),
            T.sms_signal:
            OctetStringEncoder(self.getLength),
            T.alert_on_message_delivery:
            EmptyEncoder(),
            #T.its_reply_type: ItsReplyTypeEncoder(),
            # T.its_session_info: ItsSessionInfoEncoder(),
            # T.ussd_service_op: UssdServiceOpEncoder(),
        }

    def getLength(self):
        return self.length

    def encode(self, option):
        if option.tag not in self.options:
            raise ValueError("Unknown option %s" % str(option))
        encoder = self.options[option.tag]
        encodedValue = encoder.encode(option.value)
        length = len(encodedValue)
        return string.join([
            TagEncoder().encode(option.tag),
            Int2Encoder().encode(length),
            encodedValue,
        ], '')

    def decode(self, file):
        tag = TagEncoder().decode(file)
        self.length = Int2Encoder().decode(file)
        if tag not in self.options:
            # Add vendor specific tag to options
            if tag.key.startswith('vendor_specific_'):
                self.options[tag] = OctetStringEncoder(self.getLength)
            else:
                # read unconsumed data
                file.read(self.length)
                return
        encoder = self.options[tag]
        iBeforeDecode = file.tell()

        value = None
        try:
            value = encoder.decode(file)
        except PDUParseError, e:
            e.status = pdu_types.CommandStatus.ESME_RINVOPTPARAMVAL
            raise e

        iAfterDecode = file.tell()
        parseLen = iAfterDecode - iBeforeDecode
        if parseLen != self.length:
            raise PDUParseError(
                "Invalid option length: labeled [%d] but parsed [%d]" %
                (self.length, parseLen),
                pdu_types.CommandStatus.ESME_RINVPARLEN)
        return pdu_types.Option(tag, value)