1
from twisted.internet import reactor
2
from twisted.application.service import IService, Service
3
from twisted.cred.portal import IRealm, Portal
4
from twisted.cred.checkers import ICredentialsChecker
5
from axiom.attributes import integer, inmemory, bytes
6
from axiom.item import Item
7
from xmantissa import sip
9
class SIPConfigurationError(RuntimeError):
10
"""You specified some invalid configuration."""
13
class SIPServer(Item, Service):
14
typename = 'mantissa_sip_powerup'
16
portno = integer(default=5060)
27
def __init__(self, hostnames):
28
self.hostnames = hostnames
30
def installOn(self, other):
31
assert self.installedOn is None, "You cannot install a SIPServer on more than one thing"
32
other.powerUp(self, IService)
33
self.installedOn = other
35
def privilegedStartService(self):
36
realm = IRealm(self.store, None)
38
raise SIPConfigurationError(
40
'you need to install a userbase before using this service.')
41
chkr = ICredentialsChecker(self.store, None)
43
raise SIPConfigurationError(
45
'you need to install a userbase before using this service.')
46
portal = Portal(realm, [chkr])
47
self.proxy = sip.Proxy(portal)
49
f = sip.SIPTransport(self.proxy, self.hostnames.split(','), self.portno)
50
self.port = reactor.listenUDP(self.portno, f)