Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSM7BITPACKED] Fixes around Split/ShouldSplit #136

Merged
merged 9 commits into from
Jun 10, 2024

Conversation

krstdmr
Copy link
Contributor

@krstdmr krstdmr commented Feb 7, 2024

  1. GSM7BITPACKED - Changes about adding a padding bit to the beginning of the septets just after UDH during EncodeSplit
    Ref1: https://www.etsi.org/deliver/etsi_ts/123000_123099/123040/16.00.00_60/ts_123040v160000p.pdf Page 74
    Ref2: https://help.goacoustic.com/hc/en-us/articles/360043843154--How-character-encoding-affects-SMS-message-length Pls. ref. to the note "..It is added as padding so that the actual 7-bit encoding data begins on a septet boundary—the 50th bit."
    Ref3: https://en.wikipedia.org/wiki/Concatenated_SMS "..This means up to 6 bits of zeros need to be inserted at the start of the [message]."

  2. Handling escape chars during Split/ShouldSplit
    Esacpe characters occupy 2 octets/septets
    Ref1: https://en.wikipedia.org/wiki/GSM_03.38
    Ref2: https://www.developershome.com/sms/gsmAlphabet.asp

  3. Fix for UCS2-> ShouldSplit where the first segment should be split just after 70 UCS2 chars (rune check, pls see unit tests), but the next after 67 chars.

  4. Fix for EsmClass when Split returns a single part

@krstdmr krstdmr mentioned this pull request Feb 7, 2024
@krstdmr
Copy link
Contributor Author

krstdmr commented Feb 7, 2024

PR review from any of you is appreciated. @linxGnu || @goten4 || @laduchesneau.
Thanks in advance.

krstdmr referenced this pull request Feb 7, 2024
@laduchesneau
Copy link
Collaborator

laduchesneau commented Feb 7, 2024

Ive reviewed the changes, all looks good. I will also run test on my end.

To be honest, packed GSM never worked for me with gosmpp, even thou my SMSC supports it. So ill test these changes today and get back to you.

@krstdmr
Copy link
Contributor Author

krstdmr commented Feb 7, 2024

@laduchesneau Thanks. I have just pushed one minor fix more. Please see the ref. below;
Ref : https://en.wikipedia.org/wiki/GSM_03.38
"When there are 1 to 6 spare bits in the last octet of a message, these bits are set to zero (these bits do not count as a character but only as a filler). When there are 7 spare bits in the last octet of a message, these bits are set to the 7-bit code of the CR control (also used as a padding filler) instead of being set to zero (where they would be confused with the 7-bit code of an '@' character)."

@@ -66,6 +66,17 @@ func (c *ShortMessage) SetMessageWithEncoding(message string, enc data.Encoding)
c.message = message
c.enc = enc
}

Copy link
Collaborator

@laduchesneau laduchesneau Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this added code block be better placed inside the Encode func for GSM in codings.go ?

I'm just asking.....

Copy link
Contributor Author

@krstdmr krstdmr Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @laduchesneau. Actually I tried to move the logic there into the (c *gsm7bit) Encode(str string) method. But the problem is that, this tail cleaning operation is dependent on multi-part / single part type of a message. If Encode() is triggered from a single message then calculation is based on (nSeptet+1) % 8 == 0, because we do not shift the bits left when UDH is not present in a message stream, meaning for a single part message. If Encode() is triggered from a multi-part message (pls see EncodeSplit->shiftBitsLeftOne), then the calculation needs to be based on nSeptet%8 == 0 . Since Encode() is a method that implements the EncDec interface like others, we can not parameterize it. For this reason, I though it can be placed in the SetMessageWithEncoding method. I am not super happy with the placement, but couldn't find any other alternative :) What do you think? Any other place suggestion to move or violate Encode() interface implementation or leave it as it is?

@laduchesneau
Copy link
Collaborator

LGTM (mostly)

I opened a comment/question for the code block added in Shortmessage.go

@krstdmr
Copy link
Contributor Author

krstdmr commented Feb 13, 2024

Hi @laduchesneau. Have you had chance to test your SMSC? We had to active 7-bit coding in SMSC before using it.

@laduchesneau
Copy link
Collaborator

Hi, I did test and it did not work....but its not the library, its the SMSC, its currently configured for 8bit GSM.

That said, I did test your code with our old internal tool using cloudhopper-commons and the bytes match.

I cant test the split function, we don't use it, but the encoders work.

@krstdmr
Copy link
Contributor Author

krstdmr commented Feb 19, 2024

Yeah, makes sense. As I said, that was something configurable in our SMSC, worked after we activated. Great that you verified with cloudhopper-commons.

@linxGnu
Copy link
Owner

linxGnu commented Mar 21, 2024

@laduchesneau
I don't have the SMSC here to test 7bitpacked too. Since it work for @krstdmr with his SMSC, I think its good enough to merge this PR. HDYT?

@linxGnu
Copy link
Owner

linxGnu commented Mar 21, 2024

@krstdmr

the PR also breaks gsm7bit none-packed. Could you please revert the change, only update packed part.

Something like this:

  • Create a new type coding instead of using just *gsm7bit
  • We can remove gsm7bit's packed field in another PR

In this way, it's easy to review + keep working version of gsm7bit non-packed

@krstdmr
Copy link
Contributor Author

krstdmr commented Mar 21, 2024

Hi @linxGnu . Sure, I can try to change as you suggested in the beginning of the next week. But could you please point the place where it breaks, or any hints about what happens so that it might be easier for me to understand the problem?

@krstdmr
Copy link
Contributor Author

krstdmr commented Mar 25, 2024

@linxGnu Hi again. I have pushed the changes as you requested. (Introduced gsm7bitPacked type instead). I appreciate if any of you review the PR when you have time.

Copy link
Collaborator

@laduchesneau laduchesneau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a full review of this PR. This PR has fixes for two issue I recently had:

  • When calling ShouldSplit(), if the message is a single segment, the old code would set the UDH bit in EsmClass even thou there is a single segment with no UDH. The fix proposes in this PR is exactly what I implemented in my production code.

  • This PR allows me to maximize the number of character I can send in latin-1. I convert the payload into 7bit packed and call should split. Than I decode each segment back into utf-8 and than encode into latin-1. This allow me to send towards SMSCs with DCS3/8 only binds. SMSC will convert the payload into GSM with extended characters, all while the payload is 140 bytes and wont be rejected for MSG_LENGTH_INVALID.

I do believe it bring value to the library.

@linxGnu
Copy link
Owner

linxGnu commented Jun 10, 2024

It's great to hear that @laduchesneau

For SMPP, battle test in PROD is the best trustable source.

@linxGnu linxGnu merged commit 1c3b3e5 into linxGnu:master Jun 10, 2024
@linxGnu
Copy link
Owner

linxGnu commented Jun 10, 2024

Thank you for great contribution @krstdmr @laduchesneau

@linxGnu linxGnu changed the title GSM7BITPACKED related changes and some other fixes around Split/ShouldSplit [GSM7BITPACKED] Fixes around Split/ShouldSplit Jun 10, 2024
@krstdmr
Copy link
Contributor Author

krstdmr commented Jun 11, 2024

Great to see the changes er merged. Thanks for a nice collaboration @laduchesneau @linxGnu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants