]>
code.delx.au - pymsnt/blob - src/baseproto/glue.py
1 # Copyright 2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
5 if(utils
.checkTwisted()):
6 from twisted
.xish
.domish
import Element
8 from tlib
.domish
import Element
16 # The name of the transport
17 name
= "Foo Transport"
19 # The URL of the transport's home page
20 url
= "http://foo.jabberstudio.org"
22 # The transport version
25 # XDB '@' -> '%' mangling
28 # The transport identifier (eg, aim, icq, msn)
31 # This should be set to the name space registration entries are in, in the xdb spool
32 namespace
= "jabber:iq:register"
37 """ Returns True if the JID passed is a valid groupchat JID (eg, for MSN, if it does not contain '%') """
42 def formRegEntry(username
, password
, nickname
):
43 """ Returns a domish.Element representation of the data passed. This element will be written to the XDB spool file """
48 def getAttributes(base
):
49 """ This function should, given a spool domish.Element, pull the username and password
50 out of it and return them """
52 # return username, password
57 def translateAccount(legacyaccount
):
58 """ Translates the legacy account into a Jabber ID, eg, user@hotmail.com --> user%hotmail.com@msn.jabber.org """
62 def startStats(statistics
):
63 """ Fills the misciq.Statistics class with the statistics fields.
64 You must put a command_OnlineUsers and command_OnlineUsers_Desc
65 attributes into the lang classes for this to work.
66 Note that OnlineUsers is a builtin stat. You don't need to
67 reimplement it yourself. """
68 #statistics.stats["OnlineUsers"] = 0
71 def updateStats(statistics
):
72 """ This will get called regularly. Use it to update any global
76 class LegacyGroupchat(groupchat
.BaseGroupchat
):
77 """ A class to represent a groupchat on the legacy service. All the functions below
78 must be implemented to translate messages from Jabber to the legacy protocol.
79 Look in groupchat.py for available functions to call.
81 def __init__(self
, session
, resource
, ID
=None):
82 groupchat
.BaseGroupchat
.__init
__(self
, session
, resource
, ID
)
83 # Initialisation stuff for the legacy protocol goes here
86 """ Cleanly remove the the groupchat, including removing the user from the legacy room """
87 groupchat
.BaseGroupchat
.removeMe(self
)
89 def sendLegacyMessage(self
, message
):
90 """ Send this message to the legacy room """
92 def sendContactInvite(self
, contactJID
):
93 """ Invite this user to the legacy room """
98 """ A base class that must have all functions reimplemented by legacy protocol to allow
99 legacy contact list to be accessible and modifiable from Jabber """
100 def __init__(self
, session
):
101 self
.session
= session
106 def addContact(self
, jid
):
107 """ Must add this JID to the legacy list """
110 def authContact(self
, jid
):
111 """ Must authorise this JID on the legacy service """
114 def removeContact(self
, jid
):
115 """ Must remove this JID from the legacy list """
118 def deauthContact(self
, jid
):
119 """ Must deauthorise this JID on the legacy service """
123 class LegacyConnection
:
124 """ A base class that must have all functions reimplemented by legacy protocols to translate
125 from Jabber to that legacy protocol. Any incoming events from the legacy system must be
126 translated by calling the appropriate functions in the Session, JabberConnection or PyTransport classes.
127 You must also set self.session.ready = True at some point (usually when you have been connected to the
129 def __init__(self
, session
):
130 self
.session
= session
131 self
.legacyList
= LegacyList()
134 """ Called by PyTransport when the user's session is ending.
135 Must cleanly end the user's legacy protocol session and delete
138 self
.legacyList
= None
140 def resourceOffline(self
, resource
):
141 """ Called whenever one of the local user's resources goes offline """
144 def sendMessage(self
, dest
, resource
, body
, noerror
):
145 """ Called whenever PyTransport wants to send a message to a remote user """
148 def setStatus(self
, nickname
, show
, status
):
149 """ Called whenever PyTransport needs to change the status on the legacy service
150 'nickname' is the Jabber nickname, 'show' is a Jabber status description, and status
151 is a personal message describing the user's current status/activities """
154 def updateAvatar(self
, av
=None):
155 """ Called whenever a new avatar needs to be set. Instance of avatar.Avatar is passed """
158 def userTypingNotification(self
, dest
, composing
):
159 """ Called by PyTransport whenever the Jabber user has sent typing notification to a contact """