diff --git a/callagent/SIPParserTest.st b/callagent/SIPParserTest.st index 96f7d3c..be43d0e 100644 --- a/callagent/SIPParserTest.st +++ b/callagent/SIPParserTest.st @@ -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" ;tag=oxivb'; cr; nl; + nextPutAll: 'From: ;tag=70812965'; cr; nl; + nextPutAll: 'To: "123456" ;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 [ diff --git a/callagent/SIPRequests.st b/callagent/SIPRequests.st index 88d9df9..d491b78 100644 --- a/callagent/SIPRequests.st +++ b/callagent/SIPRequests.st @@ -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 [ + + + SIPOptionsRequest class >> 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. + ]. + ] +] diff --git a/callagent/Tests.st b/callagent/Tests.st index f53c83d..8ef9c16 100644 --- a/callagent/Tests.st +++ b/callagent/Tests.st @@ -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: '; cr; nl; + nextPutAll: 'From: ;tag=MzQ4NjQ4MTg0Mjc0MzAzODU5NA__'; cr; nl; + nextPutAll: 'Contact: '; cr; nl; + nextPutAll: 'Accept: application/sdp'; cr; nl; + cr; nl; contents. + self assertSame: req asDatagram and: out. + ] + + assertSame: got and: want [ + + + got = want + ifTrue: [self assert: true] + ifFalse: [ + Transcript + nextPutAll: 'Got: "'; + nextPutAll: got displayString; + nextPut: $"; nl. + self assert: false]. + ] ]