jookies / jasmin

Jasmin - Open source SMS gateway
http://jasminsms.com
Other
1.02k stars 550 forks source link

SMPP connection dropped, if there is '§' char in the message text #954

Closed vazir closed 3 years ago

vazir commented 3 years ago

§ char is allowed by standard, and another SMPP accepts the PDU fine, but with JASMIN I'm getting connection drop: checking easy, just submit any text containing the given char.

Here is the test code, which works with a commercial SMPP or Yate SMPP in test

#!/usr/bin/env python3
import logging
import sys

import smpplib.gsm
import smpplib.client
import smpplib.consts
from sys import argv, exit

if len(argv) < 3:
    print('Minimum src and dst required')
    exit(1)
host = argv[1]
port = argv[2]
user = argv[3]
passw = argv[4]
srcnum = argv[5]
dstnum = argv[6]

# Sequence, excluding the silly char
#text = '''£¥èéùìòÇØøÅåÆæßÉ_!"¤$%&'()*+,-./01239:;<=>?ABCYZÄÖÑÜabcxyzäöñüà{}\[~]@€'''

# Broken sequence
#text = '''£¥èéùìòÇØøÅåÆæßÉ_!"¤$%&'()*+,-./01239:;<=>?ABCYZÄÖÑܧabcxyzäöñüà{}\[~]@€'''
text = '''§'''

print(argv)
# if you want to know what's happening
logging.basicConfig(level='DEBUG')
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text)
client = smpplib.client.Client(host, int(port))
client.set_message_sent_handler(
    lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
client.set_message_received_handler(
    lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))
client.connect()
client.bind_transmitter(system_id=user, password=passw)

count = 0
for part in parts:
    count += 1
    print('Sending %s' % count)
    pdu = client.send_message(
        # source_addr_ton=smpplib.consts.SMPP_TON_INTL,
        source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,
        #source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure it is a byte string, not unicode:
        # source_addr='SENDERPHONENUM',
        source_addr=srcnum,

        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
        #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure thease two params are byte strings, not unicode:
        # destination_addr='PHONENUMBER',
        destination_addr=dstnum,
        short_message=part,

        data_coding=encoding_flag,
        esm_class=msg_type_flag,
        registered_delivery=True,
    )
    print(pdu.sequence)
    print(dir(pdu))
client.listen()

result

smpplib.exceptions.PDUError: ('(100) submit_sm_resp: ESME received Temporary App Error Code', 100)
WARNING:smpp.Client.139769953189840: was not closed
farirat commented 3 years ago

Confirmed with log:

CRITICAL 84239 Exception raised handling inbound PDU [PDU [command: CommandId.submit_sm, sequence_number: 2, command_status: CommandStatus.ESME_ROK
service_type: b''
source_addr_ton: <AddrTon.ALPHANUMERIC: 6>
source_addr_npi: <AddrNpi.UNKNOWN: 1>
source_addr: b'2'
dest_addr_ton: <AddrTon.INTERNATIONAL: 2>
dest_addr_npi: <AddrNpi.UNKNOWN: 1>
destination_addr: b'3'
esm_class: EsmClass[mode: EsmClassMode.DEFAULT, type: EsmClassType.DEFAULT, gsmFeatures: set()]
protocol_id: 0
priority_flag: <PriorityFlag.LEVEL_0: 1>
schedule_delivery_time: None
validity_period: None
registered_delivery: RegisteredDelivery[receipt: RegisteredDeliveryReceipt.SMSC_DELIVERY_RECEIPT_REQUESTED, smeOriginatedAcks: set(), intermediateNotification: False]
replace_if_present_flag: <ReplaceIfPresentFlag.DO_NOT_REPLACE: 1>
data_coding: DataCoding[scheme: DataCodingScheme.DEFAULT, schemeData: DataCodingDefault.UCS2]
sm_default_msg_id: 0
short_message: b'\x00\xa7'
]] hex[b'000000250000000400000000000000020005003200010033000000000000010008000200a7']: [Failure instance: Traceback: <class 'UnicodeDecodeError'>: 'utf-8' codec can't decode byte 0xa7 in position 1
farirat commented 3 years ago

Issue solved in 0.10.9