def encodeOptionalParams(self, optionalParams, params): result = '' for paramName in optionalParams: if paramName in params: tag = getattr(pdu_types.Tag, paramName) value = params[paramName] result += self.optionEncoder.encode(pdu_types.Option(tag, value)) return result
def encodeOptionalParams(self, optionalParams, params): # Jasmin update: # Do not encode vendor_specific_bypass parameter: if 'vendor_specific_bypass' in params: del params['vendor_specific_bypass'] result = b'' for paramName in optionalParams: if paramName in params: tag = getattr(pdu_types.Tag, paramName) value = params[paramName] result += self.optionEncoder.encode(pdu_types.Option(tag, value)) return result
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)
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)