diff --git a/package.xml b/package.xml
index 15aef0b..2fb857b 100644
--- a/package.xml
+++ b/package.xml
@@ -7,6 +7,8 @@
OsmoSIP
src/Logging.st
+ src/sip/SIPIdentityManager.st
+ src/sip/MSCSIPIdentity.st
src/VLR.st
src/HLR.st
src/BSCConfig.st
@@ -35,6 +37,7 @@
OsmoMSC.BSCIPAConnectionTest
OsmoMSC.AuthTestNull
OsmoMSC.AuthTestIdentity
+ OsmoMSC.SIPIdentityManagerTest
tests/HLRDummyResolver.st
tests/BSCConfigTest.st
tests/BSCIPAConnectionTest.st
@@ -48,5 +51,7 @@
tests/GSMProcessorMockForAuthCheat.st
tests/GSMProcessorMockForAuthIMSI.st
tests/GSMProcessorMockForAuthTimeout.st
+ tests/MockSIPUserAgent.st
+ tests/SIPIdentityManagerTest.st
diff --git a/src/Logging.st b/src/Logging.st
index afb648c..a1f3dcc 100644
--- a/src/Logging.st
+++ b/src/Logging.st
@@ -63,3 +63,16 @@ Osmo.LogArea subclass: LogAreaMSC [
enabled: true; minLevel: Osmo.LogLevel debug; yourself.
]
]
+
+Osmo.LogArea subclass: LogAreaMSCSIP [
+
+
+ LogAreaMSCSIP class >> areaName [^ #mscSIP]
+ LogAreaMSCSIP class >> areaDescription [^'MSC SIP']
+ LogAreaMSCSIP class >> default [
+ ^self new
+ enabled: true;
+ minLevel: Osmo.LogLevel debug;
+ yourself
+ ]
+]
diff --git a/src/sip/MSCSIPIdentity.st b/src/sip/MSCSIPIdentity.st
new file mode 100644
index 0000000..e8b8bbc
--- /dev/null
+++ b/src/sip/MSCSIPIdentity.st
@@ -0,0 +1,84 @@
+"
+ (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 .
+"
+
+Osmo.SIPIdentity subclass: MSCSIPIdentity [
+ | available manager registerTimer |
+
+
+
+ MSCSIPIdentity class >> new [
+ ^super new
+ initialize;
+ yourself
+ ]
+
+ initialize [
+ available := false.
+ ]
+
+ manager: aManager [
+ manager := aManager
+ ]
+
+ startRegistration [
+ | register dialog |
+ dialog := (Osmo.SIPDialog fromUser: 'sip:', username host: hostname port: 5060)
+ identity: self;
+ yourself.
+ register := (Osmo.SIPRegisterTransaction createWith: dialog on: manager useragent cseq: 1)
+ destination: 'sip:', hostname;
+ onTimeout: [self registrationTimedOut];
+ onFailure: [:response :dialog | self registrationFailed];
+ onSuccess: [:response :dialog | self registrationSuccess];
+ yourself.
+ register start.
+ ]
+
+ registrationTimedOut [
+ self logNotice: 'SIPIdentity(%1@%2) registration timed-out' % {username. hostname}
+ area: #mscSIP.
+ available := false.
+ self reRegisterIn: 10.
+ ]
+
+ registrationFailed [
+ self logNotice: 'SIPIdentity(%1@%2) registration timed-out' % {username. hostname}
+ area: #mscSIP.
+ available := false.
+ self reRegisterIn: 10.
+ ]
+
+ registrationSuccess [
+ self logNotice: 'SIPIdentity(%1@%2) registered' % {username. hostname}
+ area: #mscSIP.
+ available := true.
+ self reRegisterIn: 3590.
+ ]
+
+ reRegisterIn: seconds [
+ "Re-register the identity..."
+ registerTimer ifNotNil: [registerTimer cancel].
+ registerTimer := (Osmo.TimerScheduler instance)
+ scheduleInSeconds: seconds block: [self startRegistration].
+ ]
+
+ isAvailable [
+ ^available
+ ]
+]
diff --git a/src/sip/SIPIdentityManager.st b/src/sip/SIPIdentityManager.st
new file mode 100644
index 0000000..d7021bf
--- /dev/null
+++ b/src/sip/SIPIdentityManager.st
@@ -0,0 +1,62 @@
+"
+ (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 .
+"
+
+Object subclass: SIPIdentityManager [
+ | identities useragent |
+
+
+
+
+ SIPIdentityManager class >> new [
+ ^super new
+ initialize;
+ yourself
+ ]
+
+ SIPIdentityManager class >> initWith: aUseragent [
+ ^self new
+ useragent: aUseragent;
+ yourself
+ ]
+
+ initialize [
+ identities := OrderedCollection new.
+ ]
+
+ useragent [
+ ^useragent
+ ]
+
+ useragent: aUseragent [
+ useragent := aUseragent
+ ]
+
+ addIdentity: anIdentity [
+ identities add: anIdentity.
+ anIdentity
+ manager: self;
+ startRegistration.
+ ]
+
+ available [
+ ^identities select: [:each | each isAvailable]
+ ]
+]
diff --git a/tests/MockSIPUserAgent.st b/tests/MockSIPUserAgent.st
new file mode 100644
index 0000000..287bb4c
--- /dev/null
+++ b/tests/MockSIPUserAgent.st
@@ -0,0 +1,38 @@
+"
+ (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 .
+"
+
+Object subclass: MockSIPUserAgent [
+ MockSIPUserAgent class >> generateBranch [
+ ^'z9hG4bK776asdhds'
+ ]
+
+ generateVia: aBranch [
+ ^'SIP/2.0/UDP pc33.atlanta.com;branch=', aBranch
+ ]
+
+ addTransaction: aTransaction [
+ ]
+
+ injectDefaults: aRequest [
+ aRequest addParameter: 'Max-Forwards' value: '70'.
+ aRequest addParameter: 'User-Agent' value: 'mock'.
+ ]
+
+ queueData: aData dialog: aDialog [
+ ]
+]
diff --git a/tests/SIPIdentityManagerTest.st b/tests/SIPIdentityManagerTest.st
new file mode 100644
index 0000000..77dff4d
--- /dev/null
+++ b/tests/SIPIdentityManagerTest.st
@@ -0,0 +1,35 @@
+"
+ (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: SIPIdentityManagerTest [
+ testEmpty [
+ | manager |
+ manager := SIPIdentityManager new.
+ self assert: manager available isEmpty.
+ ]
+
+ testAvailable [
+ | manager |
+ manager := SIPIdentityManager initWith: MockSIPUserAgent new.
+ manager addIdentity: (MSCSIPIdentity new
+ username: 'user';
+ hostname: 'localhost';
+ yourself).
+ self assert: manager available isEmpty.
+ ]
+]