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

misc: Split the SIPParams into one class per file

This commit is contained in:
Holger Hans Peter Freyther 2014-02-15 09:37:14 +01:00
parent 9ea9eafc2a
commit 13d4223a23
8 changed files with 291 additions and 197 deletions

View File

@ -1,196 +0,0 @@
"
(C) 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/>.
"
Object subclass: SIPParam [
| data |
<category: 'OsmoSIP-Param'>
asFoldedString [
<category: 'compat'>
^ data
]
nextPutAllOn: astream [
^ data nextPutAllOn: astream
]
]
SIPParam subclass: SIPVia [
| branch |
<category: 'OsmoSIP-Param'>
SIPVia class >> findBranch: aData [
<category: 'creation'>
aData do: [:each |
each second key = 'branch' ifTrue: [
^ each second value
]].
^ nil.
]
SIPVia class >> parseFrom: aParseDict [
<category: 'creation'>
^ self new
instVarNamed: #data put: aParseDict asFoldedString;
instVarNamed: #branch put: (self findBranch: (aParseDict at: 8));
yourself
]
branch [
^ branch
]
]
SIPParam subclass: SIPCSeq [
| number method |
<category: 'OsmoSIP-Param'>
SIPCSeq class >> parseFrom: aParseDict [
<category: 'creation'>
^ self new
instVarNamed: #data put: aParseDict asFoldedString;
instVarNamed: #number put: aParseDict first asInteger;
instVarNamed: #method put: aParseDict third;
yourself
]
number [
<category: 'accessing'>
^ number
]
method [
<category: 'accessing'>
^ method
]
]
Object extend [
isGenericSIPParam [
<category: '*OsmoSIP-Param'>
^ false
]
]
Object subclass: SIPGenericParam [
| key value |
<category: 'OsmoSIP-Param'>
<comment: 'I am a simple key value pair with the value being optional'>
SIPGenericParam class >> fromOptional: anArray [
"The =value is optional here"
<category: 'creation'>
^ self new
key: anArray first;
value: (anArray second isNil
ifTrue: [nil]
ifFalse: [anArray second second])
]
SIPGenericParam class >> fromMandatory: anArray [
"There must be a key and value"
<category: 'creation'>
^ self new
key: anArray first;
value: anArray third.
]
key: aKey [
<category: 'accessing'>
key := aKey.
]
value: aValue [
<category: 'accessing'>
value := aValue.
]
key [
<category: 'accessing'>
^ key
]
value [
<category: 'accessing'>
^ value
]
asFoldedString [
| str |
<category: 'helper'>
str := (WriteStream on: (String new))
nextPutAll: key;
yourself.
value isNil ifFalse: [
str
nextPut: $=;
nextPutAll: value.
].
^ str contents
]
isGenericSIPParam [
<category: 'osmo-sip-extension'>
^ true
]
]
SIPParam subclass: SIPToFromParam [
| addr params |
<category: 'OsmoSIP-Param'>
<comment: 'I represent a To/From parameter'>
SIPToFromParam class >> buildParams: aParam [
<category: 'creation'>
^ aParam inject: Dictionary new into: [:dict :each |
dict at: (each second key) put: (each second);
yourself].
]
SIPToFromParam class >> parseFrom: anArray [
<category: 'creation'>
^ self new
instVarNamed: #addr put: anArray first third;
instVarNamed: #data put: anArray asFoldedString;
instVarNamed: #params put: (self buildParams: anArray second);
yourself
]
address [
<category: 'accessing'>
^ addr
]
tag [
| res |
<category: 'accessing'>
res := params at: 'tag' ifAbsent: [^nil].
^ res value.
]
valueAt: aKey [
^ (params at: aKey) value.
]
]

View File

@ -0,0 +1,24 @@
"
(C) 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/>.
"
Object extend [
isGenericSIPParam [
<category: '*OsmoSIP-Param'>
^ false
]
]

View File

@ -0,0 +1,42 @@
"
(C) 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/>.
"
SIPParam subclass: SIPCSeq [
| number method |
<category: 'OsmoSIP-Param'>
SIPCSeq class >> parseFrom: aParseDict [
<category: 'creation'>
^ self new
instVarNamed: #data put: aParseDict asFoldedString;
instVarNamed: #number put: aParseDict first asInteger;
instVarNamed: #method put: aParseDict third;
yourself
]
number [
<category: 'accessing'>
^ number
]
method [
<category: 'accessing'>
^ method
]
]

View File

@ -0,0 +1,83 @@
"
(C) 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/>.
"
Object subclass: SIPGenericParam [
| key value |
<category: 'OsmoSIP-Param'>
<comment: 'I am a simple key value pair with the value being optional'>
SIPGenericParam class >> fromOptional: anArray [
"The =value is optional here"
<category: 'creation'>
^ self new
key: anArray first;
value: (anArray second isNil
ifTrue: [nil]
ifFalse: [anArray second second])
]
SIPGenericParam class >> fromMandatory: anArray [
"There must be a key and value"
<category: 'creation'>
^ self new
key: anArray first;
value: anArray third.
]
key: aKey [
<category: 'accessing'>
key := aKey.
]
value: aValue [
<category: 'accessing'>
value := aValue.
]
key [
<category: 'accessing'>
^ key
]
value [
<category: 'accessing'>
^ value
]
asFoldedString [
| str |
<category: 'helper'>
str := (WriteStream on: (String new))
nextPutAll: key;
yourself.
value isNil ifFalse: [
str
nextPut: $=;
nextPutAll: value.
].
^ str contents
]
isGenericSIPParam [
<category: 'osmo-sip-extension'>
^ true
]
]

View File

@ -0,0 +1,33 @@
"
(C) 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/>.
"
Object subclass: SIPParam [
| data |
<category: 'OsmoSIP-Param'>
asFoldedString [
<category: 'compat'>
^ data
]
nextPutAllOn: astream [
^ data nextPutAllOn: astream
]
]

View File

@ -0,0 +1,56 @@
"
(C) 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/>.
"
SIPParam subclass: SIPToFromParam [
| addr params |
<category: 'OsmoSIP-Param'>
<comment: 'I represent a To/From parameter'>
SIPToFromParam class >> buildParams: aParam [
<category: 'creation'>
^ aParam inject: Dictionary new into: [:dict :each |
dict at: (each second key) put: (each second);
yourself].
]
SIPToFromParam class >> parseFrom: anArray [
<category: 'creation'>
^ self new
instVarNamed: #addr put: anArray first third;
instVarNamed: #data put: anArray asFoldedString;
instVarNamed: #params put: (self buildParams: anArray second);
yourself
]
address [
<category: 'accessing'>
^ addr
]
tag [
| res |
<category: 'accessing'>
res := params at: 'tag' ifAbsent: [^nil].
^ res value.
]
valueAt: aKey [
^ (params at: aKey) value.
]
]

View File

@ -0,0 +1,44 @@
"
(C) 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/>.
"
SIPParam subclass: SIPVia [
| branch |
<category: 'OsmoSIP-Param'>
SIPVia class >> findBranch: aData [
<category: 'creation'>
aData do: [:each |
each second key = 'branch' ifTrue: [
^ each second value
]].
^ nil.
]
SIPVia class >> parseFrom: aParseDict [
<category: 'creation'>
^ self new
instVarNamed: #data put: aParseDict asFoldedString;
instVarNamed: #branch put: (self findBranch: (aParseDict at: 8));
yourself
]
branch [
^ branch
]
]

View File

@ -15,7 +15,15 @@
<filein>callagent/SIPLogArea.st</filein>
<filein>callagent/SIPDialog.st</filein>
<filein>callagent/SIPDigest.st</filein>
<filein>callagent/SIPParams.st</filein>
<filein>callagent/parameters/Extensions.st</filein>
<filein>callagent/parameters/SIPParam.st</filein>
<filein>callagent/parameters/SIPGenericParam.st</filein>
<filein>callagent/parameters/SIPCSeq.st</filein>
<filein>callagent/parameters/SIPToFromParam.st</filein>
<filein>callagent/parameters/SIPVia.st</filein>
<filein>callagent/SIPParser.st</filein>
<filein>callagent/SIPRandom.st</filein>
<filein>callagent/SIPRequests.st</filein>