source: ralphm-patches/c2s_example.patch

Last change on this file was 72:727b4d29c48e, checked in by Ralph Meijer <ralphm@…>, 8 years ago

Major reworking of avatars, session manager and stanza handlers.

File size: 4.3 KB
  • new file doc/examples/client_service.tac

    # HG changeset patch
    # Parent d0b90e77877631f08248efcc0d40a409e735f713
    
    diff --git a/doc/examples/client_service.tac b/doc/examples/client_service.tac
    new file mode 100644
    - +  
     1"""
     2An XMPP server that accepts client connections with static users/rosters.
     3"""
     4
     5import socket
     6
     7from twisted.application import service, strports
     8from twisted.cred.portal import Portal
     9from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
     10from twisted.words.protocols.jabber.jid import internJID as JID
     11
     12from wokkel import client, xmppim
     13from wokkel.component import Router
     14from wokkel.generic import FallbackHandler
     15from wokkel.ping import PingHandler
     16from wokkel.xmppim import SessionManager, StaticRealm, User
     17from wokkel.xmppim import InMemoryRoster, RosterItem
     18
     19# Configuration parameters
     20
     21C2S_PORT = "tcp:5222:interface=127.0.0.1"
     22DOMAIN = socket.gethostname()
     23LOG_TRAFFIC = True
     24
     25ALICE = JID('alice@'+DOMAIN)
     26BOB = JID('bob@'+DOMAIN)
     27CHARLIE = JID('charlie@'+DOMAIN)
     28
     29USERS = {
     30    ALICE: User(ALICE, roster=InMemoryRoster([
     31        RosterItem(BOB,
     32                   subscriptionTo=True,
     33                   subscriptionFrom=True,
     34                   name='Bob'),
     35        RosterItem(CHARLIE,
     36                   subscriptionTo=True,
     37                   subscriptionFrom=True,
     38                   name='Charlie',
     39                   groups=set(['Friends'])),
     40        ])),
     41    BOB: User(BOB, roster=InMemoryRoster([
     42        RosterItem(ALICE,
     43                   subscriptionTo=True,
     44                   subscriptionFrom=True,
     45                   name='Alice'),
     46        ])),
     47    }
     48
     49USER_PASSWORDS = {
     50    'alice': 'secret',
     51    'bob': 'secret',
     52    }
     53
     54
     55# Set up the Twisted application
     56
     57application = service.Application("Jabber server")
     58
     59router = Router()
     60sessionManager = SessionManager(router, DOMAIN)
     61sessionManager.setServiceParent(application)
     62
     63realm = StaticRealm(DOMAIN, USERS)
     64realm.server = sessionManager
     65
     66checkers = (
     67    InMemoryUsernamePasswordDatabaseDontUse(**USER_PASSWORDS),
     68    )
     69portal = Portal(realm, checkers)
     70portals = {JID(DOMAIN): portal}
     71
     72xmppim.AccountIQHandler(realm).setHandlerParent(sessionManager)
     73xmppim.AccountMessageHandler(realm).setHandlerParent(sessionManager)
     74xmppim.AccountPresenceHandler(realm).setHandlerParent(sessionManager)
     75FallbackHandler().setHandlerParent(sessionManager)
     76PingHandler().setHandlerParent(sessionManager)
     77
     78c2sFactory = client.XMPPC2SServerFactory(portals)
     79c2sFactory.logTraffic = LOG_TRAFFIC
     80c2sService = strports.service(C2S_PORT, c2sFactory)
     81c2sService.setServiceParent(application)
  • new file doc/examples/client_service_anonymous.tac

    diff --git a/doc/examples/client_service_anonymous.tac b/doc/examples/client_service_anonymous.tac
    new file mode 100644
    - +  
     1"""
     2An XMPP server that accepts client connections with anonymous authentication.
     3"""
     4
     5import socket
     6
     7from twisted.application import service, strports
     8from twisted.cred.portal import Portal
     9from twisted.cred.checkers import AllowAnonymousAccess
     10from twisted.words.protocols.jabber.jid import internJID as JID
     11
     12from wokkel import client, xmppim
     13from wokkel.component import Router
     14from wokkel.generic import FallbackHandler
     15from wokkel.ping import PingHandler
     16from wokkel.xmppim import SessionManager, AnonymousRealm
     17
     18# Configuration parameters
     19
     20C2S_PORT = "tcp:5222:interface=127.0.0.1"
     21DOMAIN = socket.gethostname()
     22LOG_TRAFFIC = True
     23
     24
     25# Set up the Twisted application
     26
     27application = service.Application("Jabber server")
     28
     29router = Router()
     30sessionManager = SessionManager(router, DOMAIN)
     31sessionManager.setServiceParent(application)
     32
     33realm = AnonymousRealm(DOMAIN)
     34realm.server = sessionManager
     35
     36checkers = (
     37    AllowAnonymousAccess(),
     38    )
     39portal = Portal(realm, checkers)
     40portals = {JID(DOMAIN): portal}
     41
     42xmppim.AccountIQHandler(realm).setHandlerParent(sessionManager)
     43xmppim.AccountMessageHandler(realm).setHandlerParent(sessionManager)
     44xmppim.AccountPresenceHandler(realm).setHandlerParent(sessionManager)
     45FallbackHandler().setHandlerParent(sessionManager)
     46PingHandler().setHandlerParent(sessionManager)
     47
     48c2sFactory = client.XMPPC2SServerFactory(portals)
     49c2sFactory.logTraffic = LOG_TRAFFIC
     50c2sService = strports.service(C2S_PORT, c2sFactory)
     51c2sService.setServiceParent(application)
Note: See TracBrowser for help on using the repository browser.