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

callagent: Create a class to handle OPTIONS

Linphone insists on sending it and the RFC says that handling
is mandatory. Start with being able to parse the message.
This commit is contained in:
Holger Hans Peter Freyther 2012-08-05 16:43:34 +02:00
parent b5c4ac5631
commit 5b870389f0
3 changed files with 80 additions and 2 deletions

View File

@ -62,8 +62,29 @@ PP.PPCompositeParserTest subclass: SIPParserTest [
nextPutAll: 'Reason: Q.850;cause=16;text="NORMAL_CLEARING"'; cr; nl;
nextPutAll: 'Content-Length: 0'; cr; nl;
cr; nl; contents
]
testOPTIONSRequestData [
^ (WriteStream on: String new)
nextPutAll: 'OPTIONS sip:127.0.0.1:5061 SIP/2.0'; cr; nl;
nextPutAll: 'Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK1492385841'; cr; nl;
nextPutAll: 'Route: "123456" <sip:123456@127.0.0.1>;tag=oxivb'; cr; nl;
nextPutAll: 'From: <sip:%60123456@127.0.0.1>;tag=70812965'; cr; nl;
nextPutAll: 'To: "123456" <sip:123456@127.0.0.1>;tag=oxivb'; cr; nl;
nextPutAll: 'Call-ID: 486321292'; cr; nl;
nextPutAll: 'CSeq: 20 OPTIONS'; cr; nl;
nextPutAll: 'Accept: application/sdp'; cr; nl;
nextPutAll: 'Max-Forwards: 70'; cr; nl;
nextPutAll: 'User-Agent: Linphone/3.4.3 (eXosip2/3.6.0)'; cr; nl;
nextPutAll: 'Content-Length: 0'; cr; nl;
cr; nl; contents
]
testOPTIONSRequest [
| res |
res := self parse: self testOPTIONSRequestData.
self assert: res asDatagram = self testOPTIONSRequestData.
]
testResponse [

View File

@ -1,5 +1,5 @@
"
(C) 2010-2011 by Holger Hans Peter Freyther
(C) 2010-2012 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
@ -141,6 +141,8 @@ SIPRequest subclass: SIPInviteRequest [
addDefaults: out [
super addDefaults: out.
dialog isNil ifTrue:[^self].
self parameter: 'Contact' ifAbsent: [
out nextPutAll: 'Contact: <%1>' % {dialog contact};
cr; nl.
@ -174,3 +176,26 @@ SIPRequest subclass: SIPByeRequest [
^ 'BYE'
]
]
SIPRequest subclass: SIPOptionsRequest [
<category: 'SIP-Callagent'>
SIPOptionsRequest class >> verb [
<category: 'verb'>
^ 'OPTIONS'
]
addDefaults: out [
super addDefaults: out.
"Add a contact if we have a dialog"
dialog isNil ifFalse:[
self parameter: 'Contact' ifAbsent: [
out nextPutAll: 'Contact: <%1>' % {dialog contact};
cr; nl.]].
self parameter: 'Accept' ifAbsent: [
out nextPutAll: 'Accept: application/sdp'; cr; nl.
].
]
]

View File

@ -1,5 +1,5 @@
"
(C) 2011 by Holger Hans Peter Freyther
(C) 2011-2012 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
@ -37,4 +37,36 @@ TestCase subclass: SIPRequestTest [
self assert: req asDatagram = out.
]
testOPTIONS [
| dialog req out |
dialog := SIPDialog fromUser: 'sip:1000@on-foo.com' host: '192.168.0.106' port: 5060.
dialog fromTag: 'MzQ4NjQ4MTg0Mjc0MzAzODU5NA__'.
dialog to: 'sip:9198@192.168.0.106'.
req := SIPOptionsRequest from: dialog.
out := (WriteStream on: String new)
nextPutAll: 'OPTIONS sip:9198@192.168.0.106 SIP/2.0'; cr; nl;
nextPutAll: 'To: <sip:9198@192.168.0.106>'; cr; nl;
nextPutAll: 'From: <sip:1000@on-foo.com>;tag=MzQ4NjQ4MTg0Mjc0MzAzODU5NA__'; cr; nl;
nextPutAll: 'Contact: <sip:1000@on-foo.com>'; cr; nl;
nextPutAll: 'Accept: application/sdp'; cr; nl;
cr; nl; contents.
self assertSame: req asDatagram and: out.
]
assertSame: got and: want [
<category: 'tests'>
got = want
ifTrue: [self assert: true]
ifFalse: [
Transcript
nextPutAll: 'Got: "';
nextPutAll: got displayString;
nextPut: $"; nl.
self assert: false].
]
]