]>
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 from tlib
import xmlw
# Provides Element, parseText, parseFile
14 # The name of the transport
15 name
= "Foo Transport"
17 # The URL of the transport's home page
18 url
= "http://foo.jabberstudio.org"
20 # The transport version
23 # XDB '@' -> '%' mangling
26 # The transport identifier (eg, aim, icq, msn)
29 # This should be set to the name space registration entries are in, in the xdb spool
30 namespace
= "jabber:iq:register"
34 """ Is called whenever settings in the config module may have changed. """
38 """ Returns True if the JID passed is a valid groupchat JID (eg, for MSN, if it does not contain '%') """
43 def formRegEntry(username
, password
, nickname
):
44 """ Returns a domish.Element representation of the data passed. This element will be written to the XDB spool file """
49 def getAttributes(base
):
50 """ This function should, given a spool domish.Element, pull the username and password
51 out of it and return them """
53 # return username, password
58 def translateAccount(legacyaccount
):
59 """ Translates the legacy account into a Jabber ID, eg, user@hotmail.com --> user%hotmail.com@msn.jabber.org """
63 def startStats(statistics
):
64 """ Fills the misciq.Statistics class with the statistics fields.
65 You must put a command_OnlineUsers and command_OnlineUsers_Desc
66 attributes into the lang classes for this to work.
67 Note that OnlineUsers is a builtin stat. You don't need to
68 reimplement it yourself. """
69 #statistics.stats["OnlineUsers"] = 0
72 def updateStats(statistics
):
73 """ This will get called regularly. Use it to update any global
77 class LegacyGroupchat(groupchat
.BaseGroupchat
):
78 """ A class to represent a groupchat on the legacy service. All the functions below
79 must be implemented to translate messages from Jabber to the legacy protocol.
80 Look in groupchat.py for available functions to call.
82 def __init__(self
, session
, resource
, ID
=None):
83 groupchat
.BaseGroupchat
.__init
__(self
, session
, resource
, ID
)
84 # Initialisation stuff for the legacy protocol goes here
87 """ Cleanly remove the the groupchat, including removing the user from the legacy room """
88 groupchat
.BaseGroupchat
.removeMe(self
)
90 def sendLegacyMessage(self
, message
):
91 """ Send this message to the legacy room """
93 def sendContactInvite(self
, contactJID
):
94 """ Invite this user to the legacy room """
99 """ A base class that must have all functions reimplemented by legacy protocol to allow
100 legacy contact list to be accessible and modifiable from Jabber """
101 def __init__(self
, session
):
102 self
.session
= session
107 def addContact(self
, jid
):
108 """ Must add this JID to the legacy list """
111 def authContact(self
, jid
):
112 """ Must authorise this JID on the legacy service """
115 def removeContact(self
, jid
):
116 """ Must remove this JID from the legacy list """
119 def deauthContact(self
, jid
):
120 """ Must deauthorise this JID on the legacy service """
124 class LegacyConnection
:
125 """ A base class that must have all functions reimplemented by legacy protocols to translate
126 from Jabber to that legacy protocol. Any incoming events from the legacy system must be
127 translated by calling the appropriate functions in the Session, JabberConnection or PyTransport classes.
128 You must also set self.session.ready = True at some point (usually when you have been connected to the
130 def __init__(self
, session
):
131 self
.session
= session
132 self
.legacyList
= LegacyList()
135 """ Called by PyTransport when the user's session is ending.
136 Must cleanly end the user's legacy protocol session and delete
139 self
.legacyList
= None
141 def resourceOffline(self
, resource
):
142 """ Called whenever one of the local user's resources goes offline """
145 def sendMessage(self
, dest
, resource
, body
, noerror
):
146 """ Called whenever PyTransport wants to send a message to a remote user """
149 def sendFile(self
, dest
, fileSend
):
150 """ Called whenever PyTransport wants to send a file to a remote user. Call accept(fileObj), or reject(). """
152 def setStatus(self
, nickname
, show
, status
):
153 """ Called whenever PyTransport needs to change the status on the legacy service
154 'nickname' is the Jabber nickname, 'show' is a Jabber status description, and status
155 is a personal message describing the user's current status/activities """
158 def updateAvatar(self
, av
=None):
159 """ Called whenever a new avatar needs to be set. Instance of avatar.Avatar is passed """
162 def userTypingNotification(self
, dest
, composing
):
163 """ Called by PyTransport whenever the Jabber user has sent typing notification to a contact """