komuw / naz

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

Bug: data_coding should not be applied to all fields that are C-Octet Strings #188

Closed Slavix72 closed 4 years ago

Slavix72 commented 4 years ago

Python 3.8 Ubuntu 18.04 Naz 0.7.4 I want to send short message (or long short message = message payload) with message_encoding= 8. I set client.codec_class.encoding eqaul 'ucs2' before client.submit_sm() call. Naz creates smpp packet: 00 00 00 41 00 00 00 04 00 00 00 00 00 00 00 05 00 00 01 00 32 00 30 00 32 00 01 01 00 37 00 39 00 30 00 38 00 36 00 33 00 31 00 31 00 31 00 33 00 30 00 00 00 00 00 00 00 00 00 00 04 00 37 00 37 Naz encode text='77' to ucs2_codes = 0037 0037. But it encodes src_addr and dst_addr too. SMSC can not receive such packet. Packet with correct src_addr and dst_addr is 00 00 00 31 00 00 00 04 00 00 00 00 00 00 00 05 00 00 01 32 30 32 00 01 01 37 39 30 38 36 33 31 31 31 33 30 00 00 00 00 00 00 00 00 00 00 02 37 37 How to encode short_message only to ucs2_codes?

Slavix72 commented 4 years ago

I think that data_coding field is property of short_message, not client

komuw commented 4 years ago

Hi @Slavix72
Thanks for reporting this. I can confirm that with the following;

client = naz.Client(
    smsc_host="127.0.0.1",
    smsc_port=2775,
    system_id="smppclient1",
    password="password",
    codec_class=naz.nazcodec.SimpleNazCodec(encoding="ucs2"),
)

I'm able to reproduce this. Smpp server logs;

2019.12.03 12:56:24 895 WARNING 19 Bind failed authentication check.
INFO    19 : BIND_TRANSCEIVER_RESP:
INFO    19 Hex dump (16) bytes:
INFO    19 00000010:80000009:0000000F:00000006:
INFO    19 
INFO    19 cmd_len=16,cmd_id=-2147483639,cmd_status=15,seq_no=6,system_id=SMPPSim

and naz logs;

{
    "timestamp": "2019-12-03 15:56:20,891",
    "event": "naz.Client.command_handlers",
    "smpp_command": "bind_transceiver_resp",
    "command_status": 15,
    "state": "Invalid System ID",
    "smsc_host": "127.0.0.1",
    "system_id": "smppclient1",
}

This is because of; https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/client.py#L798

komuw commented 4 years ago

note to self: although nazcodec allows any python standard encoding[1]; https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/nazcodec.py#L276 naz.Client._find_data_coding does not play nice; https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/client.py#L671-L676

  1. https://docs.python.org/3/library/codecs.html#standard-encodings
komuw commented 4 years ago

@Slavix72 I'll prepare a fix for this.

komuw commented 4 years ago

note to self: although nazcodec allows any python standard encoding[1];

https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/nazcodec.py#L276

naz.Client._find_data_coding does not play nice; https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/client.py#L671-L676

  1. https://docs.python.org/3/library/codecs.html#standard-encodings

Actually we cant use all python standard encodings, only the ones defined in SMPP spec;

  1. https://github.com/komuw/naz/blob/c47f5030b720f3bac400dd6bd457b4415b0d5b7b/naz/state.py#L328
  2. Also see section 5.2.19 of SMPP spec
komuw commented 4 years ago

@Slavix72 this should now be fixed.

Try version https://pypi.org/project/naz/0.7.5/

Also please read the changelog: https://github.com/komuw/naz/blob/master/CHANGELOG.md#version-v075
there are a few other items that changed.

komuw commented 4 years ago

this client should now work okay;

client = naz.Client(
    ...
    codec=naz.codec.SimpleCodec(encoding="ucs2"),
)
komuw commented 4 years ago

I think that data_coding field is property of short_message, not client

@Slavix72 This has now been implemented: https://github.com/komuw/naz/pull/201