~divmod-dev/divmod.org/830343-optional-pycrypto

« back to all changes in this revision

Viewing changes to Sine/sign/sipserver.py

  • Committer: glyph
  • Date: 2005-10-29 23:28:40 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:2703
dash: I hope this doesn't screw anything up in your local checkout, but that name doesn't make any sense: Sine, like a Sine wave, related to sound...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
8
 
 
9
class SIPConfigurationError(RuntimeError):
 
10
    """You specified some invalid configuration."""
 
11
    
 
12
    
 
13
class SIPServer(Item, Service):
 
14
    typename = 'mantissa_sip_powerup'
 
15
    schemaVersion = 1
 
16
    portno = integer(default=5060)
 
17
    hostnames =  bytes()
 
18
    
 
19
    parent = inmemory()
 
20
    running = inmemory()
 
21
    name = inmemory()
 
22
 
 
23
    proxy = inmemory()
 
24
    port = inmemory()
 
25
    site = inmemory()
 
26
 
 
27
    def __init__(self, hostnames):
 
28
        self.hostnames = hostnames
 
29
        
 
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
 
34
 
 
35
    def privilegedStartService(self):
 
36
        realm = IRealm(self.store, None)
 
37
        if realm is None:
 
38
            raise SIPConfigurationError(
 
39
                'No realm: '
 
40
                'you need to install a userbase before using this service.')
 
41
        chkr = ICredentialsChecker(self.store, None)
 
42
        if chkr is None:
 
43
            raise SIPConfigurationError(
 
44
                'No checkers: '
 
45
                'you need to install a userbase before using this service.')
 
46
        portal = Portal(realm, [chkr])
 
47
        self.proxy = sip.Proxy(portal)
 
48
 
 
49
        f = sip.SIPTransport(self.proxy, self.hostnames.split(','), self.portno)
 
50
        self.port = reactor.listenUDP(self.portno, f)