smalltalk
/
osmo-st-smpp
Archived
1
0
Fork 0

codec: Implement parsing trx bind resp and fix optional parsing

This commit is contained in:
Holger Hans Peter Freyther 2014-06-17 19:21:34 +02:00
parent 2008f19ac1
commit de471382a4
5 changed files with 71 additions and 7 deletions

View File

@ -0,0 +1,41 @@
"
(C) 2014 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"
SMPPBodyBase subclass: SMPPBindTransceiverResponse [
| system_id sc_interface_version |
<category: 'SMPP-Codec'>
<comment: 'I represent a response and there should be a intermediate
class just like with the SMPPBindTransmitter'>
SMPPBindTransceiverResponse class >> messageType [
^self bindTransceiverResp
]
SMPPBindTransceiverResponse class >> tlvDescription [
^OrderedCollection new
add: SMPPSystemId tlvDescription;
add: (SMPPValueHolder for: #sc_interface_version tag: 16r0210);
yourself
]
systemId [
^system_id
]
]

View File

@ -168,17 +168,20 @@ sub-classes will provide the specific bodies.'>
] ]
readFrom: aStream [ readFrom: aStream [
| description | | description tag |
description := self class tlvDescription. description := self class tlvDescription.
description do: [:attribute | description do: [:attribute |
attribute isMandatory attribute isMandatory
ifTrue: [self doParse: attribute stream: aStream]. ifTrue: [self doParse: attribute stream: aStream].
attribute isOptional attribute isOptional
ifTrue: [ ifTrue: [
| tag | "Read the tag if we have not done so far. We can not
tag := aStream peek. peek for more than one character."
(tag isNil and: [aStream atEnd not]) ifTrue:
[tag := ((aStream next: 2) shortAt: 1) swap16].
tag = attribute tag ifTrue: [ tag = attribute tag ifTrue: [
aStream next. tag := nil.
self doParse: attribute stream: aStream]]. self doParse: attribute stream: aStream]].
]. ].
@ -197,7 +200,7 @@ sub-classes will provide the specific bodies.'>
"Now write it" "Now write it"
val isNil ifFalse: [ val isNil ifFalse: [
attr needsTag attr needsTag
ifTrue: [aMsg putByte: attr tag]. ifTrue: [aMsg putLen16: attr tag].
attr parseClass write: val on: aMsg with: attr. attr parseClass write: val on: aMsg with: attr.
]. ].
] ]

View File

@ -23,6 +23,7 @@ Object subclass: SMPPValueHolder [
SMPPValueHolder class >> for: aString tag: aTag [ SMPPValueHolder class >> for: aString tag: aTag [
^Osmo.TLVDescription new ^Osmo.TLVDescription new
instVarName: aString; instVarName: aString;
parseClass: self;
tag: aTag; tag: aTag;
beOptional; beOptional;
beTLV; beTLV;
@ -31,13 +32,13 @@ Object subclass: SMPPValueHolder [
SMPPValueHolder class >> readFrom: aStream with: anAttribute [ SMPPValueHolder class >> readFrom: aStream with: anAttribute [
| len | | len |
len := aStream next. len := ((aStream next: 2) shortAt: 1) swap16.
^(aStream next: len) ^(aStream next: len)
] ]
SMPPValueHolder class >> write: aValue on: aMsg with: anAttribute [ SMPPValueHolder class >> write: aValue on: aMsg with: anAttribute [
aMsg aMsg
putByte: aValue size; putLen16: aValue size;
putByteArray: aValue asByteArray. putByteArray: aValue asByteArray.
] ]
] ]

View File

@ -8,6 +8,7 @@
<filein>codec/SMPPBodyBase.st</filein> <filein>codec/SMPPBodyBase.st</filein>
<filein>codec/SMPPBindTransmitterBody.st</filein> <filein>codec/SMPPBindTransmitterBody.st</filein>
<filein>codec/SMPPBindTransceiver.st</filein> <filein>codec/SMPPBindTransceiver.st</filein>
<filein>codec/SMPPBindTransceiverResponse.st</filein>
<filein>codec/SMPPEnquireLink.st</filein> <filein>codec/SMPPEnquireLink.st</filein>
<filein>codec/SMPPGenericNack.st</filein> <filein>codec/SMPPGenericNack.st</filein>
<filein>codec/SMPPUnbind.st</filein> <filein>codec/SMPPUnbind.st</filein>

View File

@ -68,6 +68,13 @@ TestCase subclass: SMPPMessageTest [
16r32] 16r32]
] ]
exampleBindResponse [
^#[16r00 16r00 16r00 16r1D 16r80 16r00 16r00 16r09
16r00 16r00 16r00 16r00 16r00 16r00 16r00 16r00
16r53 16r4D 16r50 16r50 16r4D 16r41 16r50 16r00
16r02 16r10 16r00 16r01 16r34]
]
testReadMessage [ testReadMessage [
| msg | | msg |
msg := SMPPMessage readFrom: self examplePdu readStream. msg := SMPPMessage readFrom: self examplePdu readStream.
@ -141,4 +148,15 @@ TestCase subclass: SMPPMessageTest [
res := msg toMessage asByteArray. res := msg toMessage asByteArray.
self assert: res equals: self exampleSubmitSM. self assert: res equals: self exampleSubmitSM.
] ]
testBindResponse [
| msg res |
msg := SMPPMessage readFrom: self exampleBindResponse readStream.
self assert: msg body class equals: SMPPBindTransceiverResponse.
self assert: msg body systemId equals: 'SMPPMAP'.
"Do round trip test"
res := msg toMessage asByteArray.
self assert: res equals: self exampleBindResponse.
]
] ]