def start(settings_mod=None): # Setup the configuration using a configuration file from conf import setup_environ setup_environ(settings_mod) # Setup Wave Protocol import xmpp from pyofwave.protocols import WaveProtocol server = xmpp.TCPServer(xmpp.XMPPHandler(WaveProtocol)).bind( '127.0.0.1', 5222) xmpp.start([server])
def start(data, load): db.init('demo', data, load=load, create=setup, host='localhost') auth = db.authenticator() server = xmpp.Server({ 'plugins': [QueryServer], 'auth': auth, 'jid': auth.host() }) print 'Waiting for clients...' xmpp.start([xmpp.TCPServer(server).bind('127.0.0.1', 5222)])
def setUp(self): from pyofwave.core.opdev import OperationNS as OpNS # Create operation NS = OpNS("http://pyofwave.info/test") @NS def op(*args, **kwargs): return NS.E.response(args, kwargs) # Create server import xmpp server = xmpp.TCPServer(xmpp.XMPPHandler(WaveProtocol)).bind( settings.DOMAIN, 5222) xmpp.start([server])
loop() def loop(): stream.read_until("\n", handle) loop() def talk(socket, io_loop): """A client connection handler that says hello to the echo server, waits for a response, then disconnects.""" stream = IOStream(socket, io_loop=io_loop) messages = [0] def write(data, *args): print 'C: %r' % data stream.write(data, *args) def handle(data): write('goodbye\n', stream.close) stream.read_until("\n", handle) write('hello!\n') if __name__ == '__main__': server = xmpp.TCPServer(echo).bind('127.0.0.1', '9000') client = xmpp.TCPClient(talk).connect('127.0.0.1', '9000') xmpp.start([server, client])
self.address = addr self.parser = xmpp.xml.Parser(xmpp.XMPPTarget(self)) self.stream = stream.read(self.parser.feed) self.pings = 0 print 'Waiting for some pings from %s.' % (addr[0]) def is_stanza(self, name): return name == '{jabber:client}ping' def handle_open_stream(self, attrs): self.stream.write('<stream:stream xmlns="jabber:client"' ' from="*****@*****.**" xml:lang="en"' ' xmlns:stream="http://etherx.jabber.org/streams">') def handle_stanza(self, ping): self.pings += 1 self.stream.write('<pong/>') def handle_close_stream(self): self.stream.write('</stream:stream>', self.close) def close(self): print 'Got %d ping(s) from %s.' % (self.pings, self.address[0]) self.stream.close() if __name__ == '__main__': server = xmpp.TCPServer(xmpp.XMPPHandler(Pong)).bind('127.0.0.1', 9000) xmpp.start([server])
'ask': item.get('ask') }, [g.text for g in item]) def _to_xml(self, state): (attr, groups) = state return xml.E.item( dict(i for i in attr.iteritems() if i[1] is not None), *[xml.E.group(g) for g in groups]) if __name__ == '__main__': ## Create a server application with 2 users: [email protected] and ## [email protected]. server = xmpp.Server({ 'plugins': [(ChatServer, { 'rosters': Rosters() })], 'host': 'localhost', 'users': { 'user1': 'password1', 'user2': 'password2' } ## Uncomment to use TLS: ## 'certfile': os.path.join(os.path.dirname(__file__), 'certs/self.crt'), ## 'keyfile': os.path.join(os.path.dirname(__file__), 'certs/self.key') }) SP = xmpp.TCPServer(server).bind('127.0.0.1', 5222) xmpp.start([SP])
log.exception('Unhandled stanza error %r.', xml.tostring(elem)) return if kind == 'result': name = self.iq_ident(elem) else: child = xml.child(elem) if child is None: log.exception('No child element: %r.' % xml.tostring(elem)) return self.stanza_error( elem, 'modify', 'not-acceptable', 'GET or SET must have a child element.') name = '{jabber:client}iq/%s' % child.tag ret = operation.handleOperation(self.events, elem) #TODO: Handle errors if ret != None: self.iq('result', ret) def on_stream_authorized(self, usr): self.events = operation.EventRegistry(usr, self.write) super(WaveProtocol, self).on_stream_authorized(usr) if __name__ == '__main__': from pyofwave.conf import settings server = xmpp.TCPServer(xmpp.XMPPHandler(WaveProtocol)).bind( settings.DOMAIN, 5222) xmpp.start([server])
from lxml import etree class Target(object): def __init__(self, stream): self.stream = stream def start(self, name, attr): self.stream.write('start %r %r\n' % (name, attr.items())) def data(self, data): self.stream.write('data %r\n' % data) def stop(self, name): print 'stop', name self.stream.write('stop %r\n' % name) def close(self): self.stream.close() def parse(socket, addr, io_loop): print '%r connected.' % addr[0] stream = xmpp.ReadStream(socket, io_loop) parser = etree.XMLParser(target=Target(stream)) parser.feed('') # Prime the parser. stream.read(parser.feed) if __name__ == '__main__': server = xmpp.TCPServer(parse).bind('127.0.0.1', '9000') xmpp.start([server])
try: userinfo = getpwnam('bbs') os.setuid(userinfo[2]) except: Log.error("Failed to find user 'bbs'!") sys.exit(1) Config.Config.LoadConfig() UCache.UCache.Init() Utmp.Utmp.Init() commondata.CommonData.Init() hostname = Config.Config.GetString("BBS_XMPP_HOST", 'localhost') server = xmpp.Server({ 'plugins': [(xmppserver.XMPPServer, { 'rosters': rosters.Rosters(), 'host': hostname })], 'auth': xmppauth.XMPPAuth('xmpp', hostname, 'bbs'), 'mechanisms': (sasl.Plain, bbsauth.BBSAuth), 'certfile': Config.BBS_XMPP_CERT_FILE, 'keyfile': Config.BBS_XMPP_KEY_FILE, }) SP = xmpp.TCPServer(server).bind('0.0.0.0', 5222) xmpp.start([SP])