komuw / naz

naz is an async SMPP client.
https://komuw.github.io/naz/
MIT License
39 stars 12 forks source link

Problem with gsm0338 codec #220

Open niksabaldun opened 2 years ago

niksabaldun commented 2 years ago

Hi,

If I try to send a message using gsm0338 codec:

msg = naz.protocol.SubmitSM(
    encoding='gsm0338',
    short_message='SMPPtest',
    log_id=request_id,
    source_addr='some_number',
    destination_addr='some_number',
    validity_period='221017095407208+'
)

it is not encoded correctly, the client receives garbage ('S&ΛJ/Oi' in this case). If I specify ucs2 encoding, then everything is fine.

It is not a server problem. I've tried sending from https://melroselabs.com/tools/smppclientproxy/ via the same server using gsm0338 and the message was encoded correctly.

niksabaldun commented 2 years ago

OK, there is probably no problem with the codec itself. I've found the following in the Apache Camel docs:

Choosing the value 0 for the alphabet selects the SMSC default alphabet, this usually means GSM 3.38 but it is not guaranteed.

This is an unbelievably loose specification. For this particular SMSC, default encoding is ascii. However, the web SMPP client I used didn't even try to use gsm0338, so I assume it had some way to detect that it should use ascii. How, I have no idea.

niksabaldun commented 2 years ago

I got this answer from SMSC vendor:

Unfortunately, unlike SMPP 3.3, where data_coding=0 was unambiguously GSM 7-bit default alphabet, for SMPP 3.4 and higher the GSM 7-bit default alphabet is missing in this list, and data_coding=0 may differ for various Short message service centers—it may be ISO-8859-1, ASCII, GSM 7-bit default alphabet, UTF-8 or even configurable per ESME.

This means that Client class should have a parameter for default encoding.