Skip to content

Refactoring#27

Merged
xlab merged 6 commits intoxlab:masterfrom
digineo:refactor
Feb 20, 2022
Merged

Refactoring#27
xlab merged 6 commits intoxlab:masterfrom
digineo:refactor

Conversation

@dmke
Copy link
Copy Markdown
Contributor

@dmke dmke commented Feb 18, 2022

I've refactored some bits:

Split code

I've split the sms/sms.go file in multiple units, as 1000-lines files start to get unwieldy.

For the same reason, I've split the switch statements in (*sms.Message).PDU() and (*sms.Message).ReadFrom() in separate methods.

Add a resolver for TP-ST values

I've imported the names for TP-ST values from 3GPP TS 23.040 v16.0.0, section 9.2.3.15 (PDF). This allows to easier act on SMS-STATUS-REPORT PDUs:

var m sms.Message
_, _ = m.ReadFrom(utils.MustBytes(statusReportPDU))

switch m.Status.Category() {
case sms.StatusCategories.Complete:
    // Short message transaction completed
case sms.StatusCategories.TemporaryError:
    // Temporary error, SC still trying to transfer SM
case sms.StatusCategories.PermanentError:
    // Permanent error, SC is not making any more transfer attempts
case sms.StatusCategories.FinalError:
    // Temporary error, SC is not making any more transfer attempts
case sms.StatusCategories.Unknown:
    // Status code is either reserved or SC-specific
}

I'm not sure about the Status field names: TS 23.040 reuses some names for different bytes (which either carry the information that the SC will or will not retry delivery, or whether the status is temporary or permanent). Hence the names of sms.StatusCodes are prefixed with on of:

  • "Completed" (like CompletedReceived) for codes in category Complete,
  • "Temporary" (like TemporaryBusy or TemporaryQualityOfServiceNotAvailable) for codes in category TemporaryError,
  • "Permanent" (like PermanentQualityOfServiceNotAvailable) for codes in category PermanentError, and
  • "Final" (like FinalBusy or FinalQualityOfServiceNotAvailable) for codes in category FinalError.

Add type-of-address and numbering-plan-indentification for PhoneNumber

I've imported values for type-of-address and numbering-plan-identification bits from 3GPP TS 23.040, section 9.1.2.5.

The code does not make much use of it (as it only supports national/international E164 numbers for PDU-encoding and additionally alphanumeric numbers for parsing), but I guess this is the best place to put those constants.

Small fixes related to time zone

In (Timestamp).PDU(), generating the time zone octet accidentally used integer arithmetic to calculate the GMT offset. This causes problems for time zones like +08:15, which resulted in an offset of 8 hours (and not 8.25 hours).

In (*Timestamp).ReadFrom(), the wrong bit was used to identify negative time zones: Negative time zones are actually indicated by bit 3 (the fourth bit, 0x08, 0b0000_1000) set to one, this code previously looked at bit 2 (0x04, 0b0000_0100). This also surfaced an issue with the test fixture for TestSmsDeliverReadFromGsm7_2() where the correct time zone is GMT-03:00 (Moscow time, which matches the TP-UD payload contained in that message).

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #27 (9462a3e) into master (853be59) will increase coverage by 2.48%.
The diff coverage is 60.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
+ Coverage   35.44%   37.93%   +2.48%     
==========================================
  Files           8       17       +9     
  Lines        1560     1558       -2     
==========================================
+ Hits          553      591      +38     
+ Misses        915      884      -31     
+ Partials       92       83       -9     
Impacted Files Coverage Δ
sms/user_data_header.go 0.00% <0.00%> (ø)
sms/ussd.go 0.00% <0.00%> (ø)
sms/validity_period.go 33.33% <33.33%> (ø)
sms/sms_status_report.go 35.15% <35.15%> (ø)
sms/sms_submit.go 46.87% <46.87%> (ø)
sms/sms_deliver.go 51.16% <51.16%> (ø)
sms/phone_number.go 74.41% <74.41%> (ø)
sms/sms.go 71.16% <79.29%> (+18.11%) ⬆️
pdu/7bit.go 88.80% <80.00%> (-1.96%) ⬇️
sms/status.go 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 853be59...9462a3e. Read the comment docs.

@dmke dmke changed the title add resolver for status values [WIP] add resolver for status values Feb 18, 2022
@dmke dmke marked this pull request as draft February 18, 2022 14:14
dmke added 6 commits February 19, 2022 23:31
Move case body in separate methods:

- (*Message).PDU() → (*Message).encodeXXX
- (*Message).ReadFrom() → (*Message).decodeXXX

Also extract User-Data decoding to reduce code duplication.
This method can help in input validation. Since Encode7Bit
auto-substitutes unknown characters with '?', we cannot
simply check whether decode(encode(input)) == input.
This fixes two small bugs related to parsing timestamp PDUs:

In (Timestamp).PDU(), generating the time zone octet accidentally
used integer arithmetic to calculate the GMT offset. This causes
problems for time zones like +08:15, which resulted in an offset
of 8 hours (and not 8.25 hours).

In (*Timestamp).ReadFrom(), the wrong bit was used to identify
negative time zones: Negative time zones are actually indicated
by bit 3 (the fourth bit, 0x08, 0b0000_1000) set to one, this code
previously looked at bit 2 (0x04, 0b0000_0100). This also surfaced
an issue with the test fixture for TestSmsDeliverReadFromGsm7_2()
where the correct time zone is GMT-03:00 (Moskow time, which
matches the TP-UD payload contained in that message).
@dmke dmke changed the title [WIP] add resolver for status values Refactoring Feb 20, 2022
@dmke
Copy link
Copy Markdown
Contributor Author

dmke commented Feb 20, 2022

This is now ready for review. I've updated the cover letter.

@dmke dmke marked this pull request as ready for review February 20, 2022 15:05
@xlab
Copy link
Copy Markdown
Owner

xlab commented Feb 20, 2022

where the correct time zone is GMT-03:00 (Moscow time, which matches the TP-UD payload contained in that message).

It's GMT+03 by the way, but I believe that the wrong bit could be used to detect that. I didn't have a chance to test with other zones with real data.

Thanks!

@xlab xlab merged commit 3be8905 into xlab:master Feb 20, 2022
@dmke dmke deleted the refactor branch February 20, 2022 16:28
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