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

callagent: Introduce the SIPRequests class

Inspired by the MGCPCommands it can create simple requests and
add parameters to the mix...
This commit is contained in:
Holger Hans Peter Freyther 2011-06-12 00:58:06 +02:00
parent 3ff782e8c3
commit 217c529b94
1 changed files with 98 additions and 0 deletions

98
callagent/SIPRequests.st Normal file
View File

@ -0,0 +1,98 @@
"
(C) 2010-2011 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/>.
"
"TODO: Compare with MGCPCommands and share code..."
Object subclass: SIPRequest [
| addr parameters sdp |
<comment: 'I should share a parent with MGCPCommand'>
<category: 'SIP-Callagent'>
sipAddr: anAddr [
<category: 'accessing'>
addr := anAddr
]
sipAddr [
<category: 'accessing'>
^ addr
]
parameters [
<category: 'accessing'>
^ parameters ifNil: [parameters := OrderedCollection new]
]
sdp: aSDP [
<category: 'accessing'>
sdp := aSDP
]
addParameter: name value: aValue [
<category: 'accessing'>
self parameters add: '%1: %2' % {name. aValue}
]
asDatagram [
| out |
out := WriteStream on: (String new).
out
nextPutAll: '%1 %2 SIP/2.0' % {self class verb. self sipAddr};
cr; nl.
self parameters do: [:each |
out nextPutAll: each; cr; nl
].
out cr; nl.
sdp ifNotNil: [
out nextPutAll: sdp
].
^ out contents
]
]
SIPRequest subclass: SIPInviteCommand [
<category: 'SIP-Callagent'>
SIPInviteCommand class >> verb [
<category: 'verb'>
^ 'INVITE'
]
]
SIPRequest subclass: SIPCancelCommand [
<category: 'SIP-Callagent'>
SIPCancelCommand class >> verb [
<category: 'verb'>
^ 'CANCEL'
]
]
SIPRequest subclass: SIPByeCommand [
<category: 'SIP-Callagent'>
SIPByeCommand class >> verb [
<category: 'verb'>
^ 'BYE'
]
]