[72] | 1 | # HG changeset patch |
---|
| 2 | # Parent d0b90e77877631f08248efcc0d40a409e735f713 |
---|
| 3 | |
---|
| 4 | diff --git a/doc/examples/client_service.tac b/doc/examples/client_service.tac |
---|
| 5 | new file mode 100644 |
---|
| 6 | --- /dev/null |
---|
| 7 | +++ b/doc/examples/client_service.tac |
---|
| 8 | @@ -0,0 +1,81 @@ |
---|
| 9 | +""" |
---|
| 10 | +An XMPP server that accepts client connections with static users/rosters. |
---|
| 11 | +""" |
---|
| 12 | + |
---|
| 13 | +import socket |
---|
| 14 | + |
---|
| 15 | +from twisted.application import service, strports |
---|
| 16 | +from twisted.cred.portal import Portal |
---|
| 17 | +from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse |
---|
| 18 | +from twisted.words.protocols.jabber.jid import internJID as JID |
---|
| 19 | + |
---|
| 20 | +from wokkel import client, xmppim |
---|
| 21 | +from wokkel.component import Router |
---|
| 22 | +from wokkel.generic import FallbackHandler |
---|
| 23 | +from wokkel.ping import PingHandler |
---|
| 24 | +from wokkel.xmppim import SessionManager, StaticRealm, User |
---|
| 25 | +from wokkel.xmppim import InMemoryRoster, RosterItem |
---|
| 26 | + |
---|
| 27 | +# Configuration parameters |
---|
| 28 | + |
---|
| 29 | +C2S_PORT = "tcp:5222:interface=127.0.0.1" |
---|
| 30 | +DOMAIN = socket.gethostname() |
---|
| 31 | +LOG_TRAFFIC = True |
---|
| 32 | + |
---|
| 33 | +ALICE = JID('alice@'+DOMAIN) |
---|
| 34 | +BOB = JID('bob@'+DOMAIN) |
---|
| 35 | +CHARLIE = JID('charlie@'+DOMAIN) |
---|
| 36 | + |
---|
| 37 | +USERS = { |
---|
| 38 | + ALICE: User(ALICE, roster=InMemoryRoster([ |
---|
| 39 | + RosterItem(BOB, |
---|
| 40 | + subscriptionTo=True, |
---|
| 41 | + subscriptionFrom=True, |
---|
| 42 | + name='Bob'), |
---|
| 43 | + RosterItem(CHARLIE, |
---|
| 44 | + subscriptionTo=True, |
---|
| 45 | + subscriptionFrom=True, |
---|
| 46 | + name='Charlie', |
---|
| 47 | + groups=set(['Friends'])), |
---|
| 48 | + ])), |
---|
| 49 | + BOB: User(BOB, roster=InMemoryRoster([ |
---|
| 50 | + RosterItem(ALICE, |
---|
| 51 | + subscriptionTo=True, |
---|
| 52 | + subscriptionFrom=True, |
---|
| 53 | + name='Alice'), |
---|
| 54 | + ])), |
---|
| 55 | + } |
---|
| 56 | + |
---|
| 57 | +USER_PASSWORDS = { |
---|
| 58 | + 'alice': 'secret', |
---|
| 59 | + 'bob': 'secret', |
---|
| 60 | + } |
---|
| 61 | + |
---|
| 62 | + |
---|
| 63 | +# Set up the Twisted application |
---|
| 64 | + |
---|
| 65 | +application = service.Application("Jabber server") |
---|
| 66 | + |
---|
| 67 | +router = Router() |
---|
| 68 | +sessionManager = SessionManager(router, DOMAIN) |
---|
| 69 | +sessionManager.setServiceParent(application) |
---|
| 70 | + |
---|
| 71 | +realm = StaticRealm(DOMAIN, USERS) |
---|
| 72 | +realm.server = sessionManager |
---|
| 73 | + |
---|
| 74 | +checkers = ( |
---|
| 75 | + InMemoryUsernamePasswordDatabaseDontUse(**USER_PASSWORDS), |
---|
| 76 | + ) |
---|
| 77 | +portal = Portal(realm, checkers) |
---|
| 78 | +portals = {JID(DOMAIN): portal} |
---|
| 79 | + |
---|
| 80 | +xmppim.AccountIQHandler(realm).setHandlerParent(sessionManager) |
---|
| 81 | +xmppim.AccountMessageHandler(realm).setHandlerParent(sessionManager) |
---|
| 82 | +xmppim.AccountPresenceHandler(realm).setHandlerParent(sessionManager) |
---|
| 83 | +FallbackHandler().setHandlerParent(sessionManager) |
---|
| 84 | +PingHandler().setHandlerParent(sessionManager) |
---|
| 85 | + |
---|
| 86 | +c2sFactory = client.XMPPC2SServerFactory(portals) |
---|
| 87 | +c2sFactory.logTraffic = LOG_TRAFFIC |
---|
| 88 | +c2sService = strports.service(C2S_PORT, c2sFactory) |
---|
| 89 | +c2sService.setServiceParent(application) |
---|
| 90 | diff --git a/doc/examples/client_service_anonymous.tac b/doc/examples/client_service_anonymous.tac |
---|
| 91 | new file mode 100644 |
---|
| 92 | --- /dev/null |
---|
| 93 | +++ b/doc/examples/client_service_anonymous.tac |
---|
| 94 | @@ -0,0 +1,51 @@ |
---|
| 95 | +""" |
---|
| 96 | +An XMPP server that accepts client connections with anonymous authentication. |
---|
| 97 | +""" |
---|
| 98 | + |
---|
| 99 | +import socket |
---|
| 100 | + |
---|
| 101 | +from twisted.application import service, strports |
---|
| 102 | +from twisted.cred.portal import Portal |
---|
| 103 | +from twisted.cred.checkers import AllowAnonymousAccess |
---|
| 104 | +from twisted.words.protocols.jabber.jid import internJID as JID |
---|
| 105 | + |
---|
| 106 | +from wokkel import client, xmppim |
---|
| 107 | +from wokkel.component import Router |
---|
| 108 | +from wokkel.generic import FallbackHandler |
---|
| 109 | +from wokkel.ping import PingHandler |
---|
| 110 | +from wokkel.xmppim import SessionManager, AnonymousRealm |
---|
| 111 | + |
---|
| 112 | +# Configuration parameters |
---|
| 113 | + |
---|
| 114 | +C2S_PORT = "tcp:5222:interface=127.0.0.1" |
---|
| 115 | +DOMAIN = socket.gethostname() |
---|
| 116 | +LOG_TRAFFIC = True |
---|
| 117 | + |
---|
| 118 | + |
---|
| 119 | +# Set up the Twisted application |
---|
| 120 | + |
---|
| 121 | +application = service.Application("Jabber server") |
---|
| 122 | + |
---|
| 123 | +router = Router() |
---|
| 124 | +sessionManager = SessionManager(router, DOMAIN) |
---|
| 125 | +sessionManager.setServiceParent(application) |
---|
| 126 | + |
---|
| 127 | +realm = AnonymousRealm(DOMAIN) |
---|
| 128 | +realm.server = sessionManager |
---|
| 129 | + |
---|
| 130 | +checkers = ( |
---|
| 131 | + AllowAnonymousAccess(), |
---|
| 132 | + ) |
---|
| 133 | +portal = Portal(realm, checkers) |
---|
| 134 | +portals = {JID(DOMAIN): portal} |
---|
| 135 | + |
---|
| 136 | +xmppim.AccountIQHandler(realm).setHandlerParent(sessionManager) |
---|
| 137 | +xmppim.AccountMessageHandler(realm).setHandlerParent(sessionManager) |
---|
| 138 | +xmppim.AccountPresenceHandler(realm).setHandlerParent(sessionManager) |
---|
| 139 | +FallbackHandler().setHandlerParent(sessionManager) |
---|
| 140 | +PingHandler().setHandlerParent(sessionManager) |
---|
| 141 | + |
---|
| 142 | +c2sFactory = client.XMPPC2SServerFactory(portals) |
---|
| 143 | +c2sFactory.logTraffic = LOG_TRAFFIC |
---|
| 144 | +c2sService = strports.service(C2S_PORT, c2sFactory) |
---|
| 145 | +c2sService.setServiceParent(application) |
---|