From 3779496a4a8f0d3892411eef4bfec5dfe9bda16a Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 3 Apr 2014 11:05:08 +0200 Subject: [PATCH] identity: Make the SIPSession work based on identity --- callagent/SIPIdentity.st | 27 ++++++++++++++++++++++++++- callagent/session/SIPCall.st | 18 ++++++++++++++---- callagent/session/SIPSessionBase.st | 9 +++++++-- callagent/tests/SIPIdentityTest.st | 29 +++++++++++++++++++++++++++++ package.xml | 2 ++ 5 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 callagent/tests/SIPIdentityTest.st diff --git a/callagent/SIPIdentity.st b/callagent/SIPIdentity.st index 8e2d432..415a2ce 100644 --- a/callagent/SIPIdentity.st +++ b/callagent/SIPIdentity.st @@ -17,12 +17,21 @@ " Object subclass: SIPIdentity [ - | username password proxyUsername proxyPassword | + | hostname username password proxyUsername proxyPassword | + SIPIdentity class >> fromUserString: aString [ + | split | + split := aString subStrings: '@'. + ^self new + username: split first; + hostname: split second; + yourself + ] + username: aUsername [ username := aUsername ] @@ -31,6 +40,10 @@ Object subclass: SIPIdentity [ password := aPassword ] + hostname: aHostname [ + hostname := aHostname + ] + proxyUsername: aUsername [ proxyUsername := aUsername ] @@ -47,6 +60,10 @@ Object subclass: SIPIdentity [ ^password ] + hostname [ + ^hostname + ] + proxyUsername [ ^proxyUsername ifNil: [username] ] @@ -54,4 +71,12 @@ Object subclass: SIPIdentity [ proxyPassword [ ^proxyPassword ifNil: [password] ] + + userString [ + ^(WriteStream on: String new) + nextPutAll: username; + nextPut: $@; + nextPutAll: hostname; + contents + ] ] diff --git a/callagent/session/SIPCall.st b/callagent/session/SIPCall.st index 895ed52..974abb6 100644 --- a/callagent/session/SIPCall.st +++ b/callagent/session/SIPCall.st @@ -51,11 +51,21 @@ will simply ignore everything but the first dialog.'> ] ] - SIPCall class >> fromUser: aUser host: aHost port: aPort to: aTo on: aUseragent [ - + SIPCall class >> fromIdenity: anIdentity host: aHost port: aPort to: aTo on: aUseragent [ ^ self - on: ((SIPDialog fromUser: aUser host: aHost port: aPort) - to: aTo; yourself) useragent: aUseragent + on: ((SIPDialog fromUser: anIdentity userString host: aHost port: aPort) + to: aTo; yourself) useragent: aUseragent identity: anIdentity + ] + + SIPCall class >> fromUser: aUser host: aHost port: aPort to: aTo on: aUseragent [ + | identity array | + + array := aUser subStrings: '@'. + identity := SIPIdentity new + username: array first; + hostname: array second; + yourself. + ^self fromIdenity: identity host: aHost port: aPort to: aTo on: aUseragent ] state [ diff --git a/callagent/session/SIPSessionBase.st b/callagent/session/SIPSessionBase.st index 2cadbad..1de7ed2 100644 --- a/callagent/session/SIPSessionBase.st +++ b/callagent/session/SIPSessionBase.st @@ -25,15 +25,20 @@ as this is what we are really interested in. So this is not really a session as of the RFC... but at some stage in the exchange we will be a proper session.'> - SIPSessionBase class >> on: aDialog useragent: aUseragent [ + SIPSessionBase class >> on: aDialog useragent: aUseragent identity: anIdentity [ ^ self new useragent: aUseragent; - identity: aUseragent mainIdentity; + identity: anIdentity; initialDialog: aDialog; yourself ] + SIPSessionBase class >> on: aDialog useragent: aUseragent [ + + ^self on: aDialog useragent: aUseragent identity: aUseragent mainIdentity + ] + initialDialog: aDialog [ initial_dialog := aDialog. diff --git a/callagent/tests/SIPIdentityTest.st b/callagent/tests/SIPIdentityTest.st new file mode 100644 index 0000000..fedc6ce --- /dev/null +++ b/callagent/tests/SIPIdentityTest.st @@ -0,0 +1,29 @@ +" + (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 . +" + +TestCase subclass: SIPIdentityTest [ + + + + testFromUserString [ + | res | + res := SIPIdentity fromUserString: '1234@10.23.24.1'. + self assert: res username equals: '1234'. + self assert: res hostname equals: '10.23.24.1'. + ] +] diff --git a/package.xml b/package.xml index 69fd77b..3e55e49 100644 --- a/package.xml +++ b/package.xml @@ -68,6 +68,7 @@ Osmo.SIPCallAgentTest Osmo.SIPDigestTest Osmo.SIPRegisterTransactionTest + Osmo.SIPIdentityTest grammar/SIPGrammarTest.st callagent/tests/SIPParserTest.st callagent/tests/Tests.st @@ -75,5 +76,6 @@ callagent/tests/SIPDigestTest.st callagent/tests/SIPTransportMock.st callagent/tests/SIPRegisterTransactionTest.st + callagent/tests/SIPIdentityTest.st