2 Punjab - multiple http interfaces to jabber.
5 from twisted.python import log
6 from twisted.application import service
9 def uriCheck(elem, uri):
11 This is a hack for older versions of twisted words, we need to get rid of it.
13 if str(elem.toXml()).find('xmlns') == -1:
16 class Service(service.Service):
18 Punjab generice service
20 def error(self, failure, body = None):
22 A Punjab error has occurred
24 # need a better way to trap this
25 if failure.getErrorMessage() != 'remote-stream-error':
26 log.msg('Punjab Error: ')
27 log.msg(failure.printBriefTraceback())
29 failure.raiseException()
32 def success(self, result, body = None):
34 If success we log it and return result
41 def makeService(config):
43 Create a punjab service to run
45 from twisted.web import server, resource, static
46 from twisted.application import service, internet
51 serviceCollection = service.MultiService()
53 if config['html_dir']:
54 r = static.File(config['html_dir'])
56 print "The html directory is needed."
59 if config['white_list']:
60 httpb.HttpbService.white_list = config['white_list'].split(',')
63 b = httpb.HttpbService(config['verbose'], config['polling'])
64 if config['httpb'] == '':
65 r.putChild('http-bind', resource.IResource(b))
67 r.putChild(config['httpb'], resource.IResource(b))
73 from twisted.internet import ssl
74 from OpenSSL import SSL
75 ssl_context = ssl.DefaultOpenSSLContextFactory(config['ssl_privkey'],
78 sm = internet.SSLServer(int(config['port']),
81 backlog = int(config['verbose']))
82 sm.setServiceParent(serviceCollection)
84 sm = internet.TCPServer(int(config['port']), site)
86 sm.setServiceParent(serviceCollection)